| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- layui.use(['form', 'mhttp', 'jquery', 'table'], function () {
- let form = layui.form;
- let http = layui.mhttp;
- let table = layui.table;
- let $ = layui.jquery;
- let loading = layer.msg('加载数据中...', {icon: 16, time: 0, shade: 0.3, shadeClose: false});
- let agent_uid = GetQueryString('agent_uid');
- let postData = {uid: agent_uid};
- // 查询应用
- let appRet = http.ajax({
- url: '/app/all'
- });
- appRet.then((data) => {
- if (data.code === 200) {
- let html = '';
- for (let i in data.data) {
- html += '<input type="checkbox" value="' + data.data[i].uid + '" class="che_' + data.data[i].uid + '" name="own_app_uids" title="' + data.data[i].name + '">';
- }
- $('.own_app_uids').html(html);
- form.render();
- // 执行完app请求在执行查询信息,避免回显选择问题
- let ret = http.ajax({
- url: '/agent/detail',
- data: postData
- });
- ret.then((data) => {
- layer.close(loading);
- // 成功显示数据
- if (data.code === 200) {
- $('.uid').val(data.data.uid);
- $('.nick').val(data.data.nick);
- $('.username').val(data.data.username);
- $('.commission_ratio').val(data.data.commission_ratio);
- $('.preferential_order').val(data.data.preferential_order);
- $('.cpa_price').val(data.data.cpa_price);
- $('.cpa_deduction_rule').val(data.data.cpa_deduction_rule);
- // withdraw_amount: data.field.withdraw_amount,
- // withdraw_usdt: data.field.withdraw_usdt,
- if (data.data.withdraw_amount !==0){
- $('.withdraw_amount').val(data.data.withdraw_amount);
- }
- if (data.data.withdraw_usdt !==0){
- $('.withdraw_usdt').val(data.data.withdraw_usdt);
- }
- // 银行卡
- if (data.data.bank_info.length > 0) {
- for (let i in data.data.bank_info){
- let item = data.data.bank_info[i];
- if(item.type === 1){
- // 银行卡
- $('#type_1 .bank_card').html(item.bank_card);
- $('#type_1 .bank_account').text(item.bank_account);
- $('#type_1 .bank_mark').text(item.bank_mark);
- $('#type_1 .type').text(item.type_name);
- $('#type_1 .bank_edit').attr('uid',item.uid);
- $('#type_1 .bank_edit').html('<a>删除</a>');
- $('#type_1').css('display','revert');
- }else if (item.type === 2){
- // usdt
- $('#type_2 .bank_mark').html(item.ustd_network);
- $('#type_2 .bank_account').text(item.ustd_account);
- $('#type_2 .type').text(item.type_name);
- $('#type_2 .bank_edit').attr('uid',item.uid);
- $('#type_2 .bank_edit').html('<a>删除</a>');
- $('#type_2').css('display','revert');
- }else if (item.type === 3){
- $('#type_3 .bank_card').html(item.alipay_username);
- $('#type_3 .bank_account').text(item.alipay_account);
- $('#type_3 .type').text(item.type_name);
- $('#type_3 .bank_edit').attr('uid',item.uid);
- $('#type_3 .bank_edit').html('<a>删除</a>');
- $('#type_3').css('display','revert');
- }
- }
- }
- if (data.data.status === 1) {
- $('.status').attr('checked', 'checked')
- }
- switch (data.data.deduction_switch) {
- case 0:
- $('#deductionSwitch0').prop("checked", true);
- break;
- case 1:
- $('#deductionSwitch1').prop("checked", true);
- break;
- case 2:
- $('#deductionSwitch2').prop("checked", true);
- break;
- case 3:
- $('#deductionSwitch3').prop("checked", true);
- break;
- }
- jdata = JSON.parse(data.data.jdata);
- let deduction_price_obg = jdata.deduction_price;
- let deduction_number_obg = jdata.deduction_number;
- if (typeof(deduction_price_obg) != 'undefined') {
- if (deduction_price_obg.length > 0) {
- let priceHtml = '';
- for (let i in deduction_price_obg) {
- if (i == 0) {
- priceHtml = deduction_price_obg[i].min_price + '-' + deduction_price_obg[i].max_price;
- } else {
- priceHtml += ',' + deduction_price_obg[i].min_price + '-' + deduction_price_obg[i].max_price;
- }
- }
- $('.deduction_price').val(priceHtml);
- }
- if (deduction_number_obg.length > 0) {
- let numberHtml = '';
- for (let i in deduction_number_obg) {
- if (i == 0) {
- numberHtml = deduction_number_obg[i].number + '-' + deduction_number_obg[i].deduction;
- } else {
- numberHtml += ',' + deduction_number_obg[i].number + '-' + deduction_number_obg[i].deduction;
- }
- }
- $('.deduction_number').val(numberHtml);
- }
- }
- form.render();
- // app选中处理
- let app_uids = data.data.own_app_uids.split(',');
- for (let index in app_uids) {
- $('.own_app_uids .che_' + app_uids[index]).attr('checked', 'checked');
- }
- form.render();
- } else {
- layer.msg(data.message, {
- // 失败关闭父窗口
- icon: 2,
- time: 1000
- }, function () {
- let index = parent.layer.getFrameIndex(window.name);
- parent.layer.close(index);
- });
- }
- });
- } else {
- $('.own_app_uids').append('<span class="app-error">获取应用失败,刷新重试!</span>');
- }
- });
- $('#back_info').on('click','.bank_edit',function () {
- let uid = $(this).attr('uid');
- if (uid) {
- let msg = layer.confirm('确定要删除该提现方式?', {
- icon: 3,
- title: '请确认'
- }, function () {
- let load = layer.msg('删除中请稍等!');
- let postData = {
- uid: uid
- };
- let ret = http.ajax({
- url: '/finance/withdraw/bank/del',
- data: postData,
- });
- ret.then((data) => {
- layer.close(load);
- if (data.code === 200) {
- layer.msg(data.message, {icon: 1, time: 1000});
- $(this).parent('tr').remove()
- layer.msg(data.message, {
- icon: 1,
- time: 1000
- }, function () {
- let index = parent.layer.getFrameIndex(window.name);
- parent.layer.close(index);
- });
- } else {
- layer.msg(data.message, {icon: 2, time: 1000});
- }
- });
- });
- }
- });
- form.on('submit(agent-save)', function (data) {
- if (data.field.password || data.field.rePassword) {
- if (data.field.password !== data.field.rePassword) {
- layer.msg('两次密码不一致 !');
- return false;
- }
- if (data.field.password < 6) {
- layer.msg('密码长度在6位以上 !');
- return false;
- }
- }
- if (data.field.withdraw_pwd) {
- if (data.field.withdraw_pwd < 6) {
- layer.msg('提现密码长度在6位以上 !');
- return false;
- }
- }
- let commission_ratio = parseInt(data.field.commission_ratio);
- if (commission_ratio > 100 || commission_ratio < 0) {
- layer.msg('分成比例在0-100!');
- return false;
- }
- let own_app_uids = '';
- $('.own_app_uids input:checked').each(function (index) {
- if (index === 0) {
- own_app_uids = $(this).val();
- } else {
- own_app_uids += ',' + $(this).val();
- }
- });
- if (own_app_uids.length <= 0) {
- layer.msg('应用必须选择一个!');
- return false;
- }
- let deduction_switch = data.field.deduction_switch;
- if (deduction_switch == 1) {
- if (!data.field.deduction_price || !data.field.deduction_number) {
- layer.msg('请核对扣量价格和扣量数量!');
- return false;
- } else {
- if (data.field.deduction_price.search(',') != -1) {
- layer.confirm('检测到扣量价格有","是否替换为以","分隔?', {
- icon: 3,
- title: '提示'
- }, function (index) {
- layer.close(index);
- $('.deduction_price').val(data.field.deduction_price.replace(/,/g, ","));
- layer.msg('已替换请再次确认!');
- });
- return false;
- }
- if (data.field.deduction_number.search(',') != -1) {
- layer.confirm('检测扣量数量格有","是否替换为以","分隔?', {
- icon: 3,
- title: '提示'
- }, function (index) {
- layer.close(index);
- $('.deduction_number').val(data.field.deduction_price.replace(/,/g, ","));
- layer.msg('已替换请再次确认!');
- });
- return false;
- }
- }
- }
- if (deduction_switch == 2 && (!data.field.cpa_deduction_rule || !data.field.cpa_price)) {
- layer.msg('选择cpa类型后,请填写对应的cpa扣量规则和cpa单价价格!');
- return false;
- }
- let deductionPriceObg = [];
- if (data.field.deduction_price) {
- let priceArray = data.field.deduction_price.split(',');
- for (let i in priceArray) {
- let priceArrayItem = priceArray[i].split('-');
- deductionPriceObg.push({
- min_price: priceArrayItem[0],
- max_price: priceArrayItem[1],
- })
- }
- }
- let deductionNumberObg = [];
- if (data.field.deduction_number) {
- let numberArray = data.field.deduction_number.split(',');
- for (let i in numberArray) {
- let numberArrayItem = numberArray[i].split('-');
- deductionNumberObg.push({
- number: numberArrayItem[0],
- deduction: numberArrayItem[1],
- })
- }
- }
- if (deductionPriceObg.length !== deductionNumberObg.length) {
- layer.msg('扣量价格与扣量数量对映不上!');
- return false;
- }
- let createLoading = layer.load();
- let postData = {
- uid: data.field.uid,
- username: data.field.username,
- nick: data.field.nick,
- preferential_order: data.field.preferential_order,
- withdraw_pwd: data.field.withdraw_pwd,
- role_id: 1,
- status: data.field.status === 'on' ? 1 : 2,
- deduction_switch: deduction_switch,
- deduction_price: JSON.stringify(deductionPriceObg),
- deduction_number: JSON.stringify(deductionNumberObg),
- jdata:JSON.stringify({deduction_price:deductionPriceObg,deduction_number:deductionNumberObg}),
- own_app_uids: own_app_uids,
- commission_ratio: parseInt(data.field.commission_ratio),
- password: data.field.password,
- cpa_price:data.field.cpa_price,
- cpa_deduction_rule:data.field.cpa_deduction_rule,
- withdraw_amount: data.field.withdraw_amount,
- withdraw_usdt: data.field.withdraw_usdt,
- };
- let ret = http.ajax({
- url: '/agent/modify',
- data: postData
- });
- ret.then((data) => {
- layer.close(createLoading);
- if (data.code === 200) {
- layer.msg(data.message, {icon: 1, time: 1000}, function () {
- // 成功刷父页面
- // window.parent.location.reload();
- // 成功关闭父窗口
- let index = parent.layer.getFrameIndex(window.name);
- parent.layer.close(index);
- parent.layui.table.reload("agent-table");
- });
- } else {
- layer.msg(data.message, {icon: 2, time: 1000});
- }
- });
- return false;
- });
- });
|