| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- layui.use(['form', 'jquery', 'layer', 'mhttp'], function () {
- let form = layui.form;
- let $ = layui.jquery;
- let http = layui.mhttp;
- let layer = layui.layer;
- // 查询应用
- let ret = http.ajax({
- url: '/app/all'
- });
- ret.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();
- } else {
- $('.own_app_uids').append('<span class="app-error">获取应用失败,刷新重试!</span>');
- }
- });
- $('.username').focus(function () {
- $('.checkUsername').html('');
- });
- $('.username').blur(function () {
- let username = $(this).val();
- if (username.length < 6) {
- $('.checkUsername').html('<span class="help">账号长度在6位以上</span>');
- return false;
- }
- let ret1 = http.ajax({
- url: 'agent/check/username',
- data: {username: username}
- });
- ret1.then((data) => {
- let html = '';
- if (data.code === 200) {
- html = '<span class="check">' + data.message + '</span>';
- } else {
- html = '<span class="help">' + data.message + '</span>';
- }
- $('.checkUsername').html(html);
- });
- });
- form.on('submit(agent-save)', function (data) {
- if (data.field.password !== data.field.rePassword) {
- layer.msg('两次密码不一致 !');
- return false;
- }
- if (data.field.username.length < 6) {
- layer.msg('账号长度在6位以上 !');
- return false;
- }
- if (data.field.password.length < 6) {
- layer.msg('密码长度在6位以上 !');
- return false;
- }
- if (data.field.withdraw_pwd) {
- if (data.field.withdraw_pwd.length < 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 = {
- username: data.field.username,
- nick: data.field.nick,
- withdraw_pwd: data.field.withdraw_pwd,
- preferential_order: data.field.preferential_order,
- role_id: 1,
- status: data.field.status === 'on' ? 1 : 2,
- own_app_uids: own_app_uids,
- deduction_switch: deduction_switch,
- deduction_price: JSON.stringify(deductionPriceObg),
- deduction_number: JSON.stringify(deductionNumberObg),
- jdata:JSON.stringify({deduction_price:deductionPriceObg,deduction_number:deductionNumberObg}),
- commission_ratio: parseInt(data.field.commission_ratio),
- cpa_price:data.field.cpa_price,
- cpa_deduction_rule:data.field.cpa_deduction_rule,
- password: data.field.password,
- withdraw_amount: data.field.withdraw_amount,
- withdraw_usdt: data.field.withdraw_usdt,
- };
- let ret = http.ajax({
- url: '/agent/create',
- 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;
- });
- })
|