layui.use(['table', 'jquery', 'madmin', 'mhttp', 'layer', 'form', 'common', 'laydate'], function () { let table = layui.table; let $ = layui.jquery; let admin = layui.madmin; let layer = layui.layer; let form = layui.form; let laydate = layui.laydate; admin.getConfig(); let authInfo = JSON.parse(localStorage.getItem(window._AUTH_INFO_)); let authInfoDeductionSwitch = authInfo.detail.deduction_switch; laydate.render({ elem: '#start_date', type: 'datetime', format: "yyyy-MM-dd HH:mm:ss" }); laydate.render({ elem: '#end_date', type: 'datetime', format: "yyyy-MM-dd HH:mm:ss" }); let beginTime = null; if (GetQueryString('start_date')) { beginTime = GetQueryString('start_date'); } let endTime = null; if (GetQueryString('end_date')) { endTime = GetQueryString('end_date'); } let mom_app_uid = null; if (GetQueryString('mom_app_uid')) { mom_app_uid = GetQueryString('mom_app_uid'); } let agent_uid = null; if (GetQueryString('agent_uid')) { agent_uid = GetQueryString('agent_uid'); } form.on('submit(search-query)', function (data) { if (data.field.start_date !== '' || data.field.end_date !== '') { if (!data.field.start_date || !data.field.end_date) { layer.msg('请核对开始时间与结束时间!'); return false; } let beginTime = new Date(data.field.start_date); let endTime = new Date(data.field.end_date); if (beginTime > endTime) { layer.msg('开始时间不能大于结束时间!'); return false; } } }); // 查询数据 if (beginTime) { beginTime = beginTime.replace('+', ' '); } if (endTime) { endTime = endTime.replace('+', ' '); } $('#start_date').val(beginTime); $('#end_date').val(endTime); let getUrl = ''; let cols = []; let search = {}; if (authInfoDeductionSwitch === 2) { // cpa search = httpRequestPostData({ start_date: beginTime, end_date: endTime, mom_app_uid: mom_app_uid, agent_uid: agent_uid, }); cols = [ [ { title: '代理名称', field: 'agent_nick', align: 'center', }, { title: '代理UID', field: 'agent_uid', align: 'center', }, { title: '应用名称', field: 'app_name', align: 'center', }, { title: '下载量', field: 'total', align: 'center', }, { title: '代理等级', field: 'total', align: 'center', templet: function (d) { if (authInfo.detail.agent_level === d.agent_level) { return '本级代理'; } return '子级代理'; } }, { title: '记录时间', field: 'created_at', align: 'center' } ] ]; getUrl = '/total/cpa/lists'; } else { // 其他的 search = httpRequestPostData({ start_date: beginTime, end_date: endTime }); getUrl = '/total/lists'; cols = [ [ { title: '日期', field: 'td_date', align: 'center' }, { title: '用户抽成', field: 'user_commission_money', align: 'center' }, { title: '下级抽成', field: 'child_commission_money', align: 'center' }, { title: '下载量', field: 'users_deduction', align: 'center' }, { title: '合计抽成', field: 'total_commission_money', align: 'center' } ] ]; } // cpa添加的搜索 function cpaSearch(data) { let html = '
'; // 代理 html += '
'; $('#searchAdd').append(html); form.render(); } table.render({ elem: '#total-table', method: 'POST', request: { pageName: 'page', limitName: 'page_size' }, where: search, async: false, headers: { "AUTH-TOKEN": localStorage.getItem('XSRF-TOKEN') }, contentType: 'application/json', url: getMyApiUrl(getUrl), limit: 20, limits: [20, 30, 40, 50, 80, 100], parseData: function (res) { serviceLink = res.data.service_link; data_list = res.data.data_list; // cpa 数据处理 if (authInfoDeductionSwitch === 2) { // cpa 要的搜索 cpaSearch(res.data); let total = 0; if (res.data.total) { total = res.data.total; } return { "code": res.code, "msg": res.message, "data": res.data.data_list, "count": total }; } else { return httpRequestPagesParseData(res); } }, response: { "statusCode": 200, }, done: function (data, page, total) { var intCode = parseInt(data.code); if (intCode === 403) { cbRespnseRedirectLogin(data); } else if (intCode === 401) { // 仅仅是过期了,这里可以有其他逻辑补偿. // 暂时跳到登陆页面 cbRespnse401(data); } onloadRender(); }, error: function (obj, message) { cbRespnseReloadPage(obj, message); }, page: true, cols: cols, skin: 'line', toolbar: '#total-toolbar' }); $('.reset').click(function () { if (mom_app_uid) { $('.app_' + mom_app_uid).removeAttr('selected') } if (agent_uid) { $('.agent_' + agent_uid).removeAttr('selected') } form.render(); }); });