layui.use(['layer', 'echarts', 'element', 'count', 'laydate', 'form', 'mhttp'], function () {
var laydate = layui.laydate;
var $ = layui.jquery,
layer = layui.layer,
element = layui.element,
count = layui.count,
form = layui.form;
let http = layui.mhttp;
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');
}
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;
}
}
});
let loading = layer.msg('加载数据中...', {icon: 16, time: 0, shade: 0.3, shadeClose: false});
// 查询数据
if (beginTime) {
beginTime = beginTime.replace('+', ' ');
}
if (endTime) {
endTime = endTime.replace('+', ' ');
}
$('#start_date').val(beginTime);
$('#end_date').val(endTime);
let search = httpRequestPostData({
start_date: beginTime,
end_date: endTime
});
let ret = http.ajax({
url: '/total/home',
data: search
});
ret.then((data) => {
layer.close(loading);
if (data.code === 401) {
cbRespnse401(data);
return;
}
if (data.code === 200) {
if (data.data.announce.length > 0) {
html = '';
for (let i in data.data.announce) {
let item = data.data.announce[i];
html += '
(' + (parseInt(i) + 1) + ') ' + item.content + '
';
}
$('#announce').append(html);
$('#announce').css('display', 'block')
}
// cpa
if (authInfoDeductionSwitch === 2 || authInfoDeductionSwitch === 3) {
$('#cpa-box').css('display', 'block');
count.up("cpa_td_users_deduction", {
time: 1000,
num: data.data.td_users_deduction,
regulator: 50
});
count.up("cpa_users_deduction", {
time: 1000,
num: data.data.users_deduction,
regulator: 50
});
count.up("cpa_yesterday_users_total", {
time: 1000,
num: data.data.yesterday_users_total,
regulator: 50
});
let array = [];
if (data.data.links.length > 0) {
for (let i in data.data.links) {
let list = data.data.links[i];
array.push(list);
}
}
var desc = function (x, y) {
return (x['sort'] < y['sort']) ? 1 : -1;
};
array.sort(desc);
for (const descKey in array) {
let row = array[descKey];
let url_link = row.url;
if (row.status === 1) {
row.status = '推广中';
if (row.url.indexOf('?') !== -1) {
url_link = row.url + '&channel_code=' + row.channel_uid;
} else {
url_link = row.url + '?channel_code=' + row.channel_uid;
}// 首次出现的位置
if (url_link.substr(url_link.indexOf('?') - 1, 1) !== '/') {
// 添加 /
url_link = url_link.substr(0, url_link.indexOf('?')) + '/' + url_link.substr(url_link.indexOf('?'));
}
let pack_btn = '';
if(row.app.android_enable !== 1){
pack_btn = '渠道包未开放!';
}else{
if (row.pack) {
if (row.pack.status === 1) {
// 成功
if (row.pack.mom_app_version !== row.app.android_version){
pack_btn = '';
}else{
pack_btn = '';
}
} else if (row.pack.status === 2) {
// 失败
pack_btn = '';
} else if (row.pack.status === 3){
// 计算时间
time1 = (new Date(row.pack.updated_at)).getTime();
time2 = (new Date()).getTime();
var cha = time1 > time2 ? time1 - time2 : time2 - time1;
var day = Math.floor(cha / (24 * 3600 * 1000));
var hours = Math.floor(cha % (24 * 3600 * 1000) / (3600 * 1000));
var minutes = Math.floor(cha % (24 * 3600 * 1000) % (3600 * 1000) / (60 * 1000));
// 10 分钟有效
if (day >=1 || hours >= 1 || minutes >= 10){
pack_btn = '';
}else{
pack_btn = '渠道包生成中(2分钟后刷新查看!)';
}
}
}else{
// 未打包
pack_btn = '';
}
}
let html = '\n' +
'
\n' +
'
\n' +
'
' + row.app_name + '
\n' +
'
' + row.status + '
\n' +
'
\n' +
'
总推广用户:' + row.users + '
\n' +
'
\n' +
'

\n' +
'
\n' +
'
' + row.title + '
\n' +
'
\n' +
'
推广文案:' + row.note + '
' +
'
渠道包:' + pack_btn + '
\n' +
'
\n' +
'
';
$('#links-box').prepend(html);
} else {
row.status = "";
let html = '\n' +
'
\n' +
'
\n' +
'
' + row.app_name + '
\n' +
'
' + row.status + '
\n' +
'
\n' +
'
总推广用户:' + row.users + '
\n' +
'
\n' +
'

\n' +
'
\n' +
'
' + row.title + '
\n' +
'
\n' +
'
推广文案:' + row.note + '
' +
'
渠道包:请联系开线负责人开启!
\n' +
'
\n' +
'
';
$('#links-box').append(html);
}
}
$(".btn-nd").click(function () {
layer.alert('请联系开线负责人开启!', {
icon: 3,
title: '提示'
});
});
} else if (authInfoDeductionSwitch === 1) {
//cps
$('#cps-box').css('display', 'block');
count.up("cps_td_users_deduction", {
time: 1000,
num: data.data.td_users_deduction,
regulator: 50
});
count.up("cps_users_deduction", {
time: 1000,
num: data.data.users_deduction,
regulator: 50
});
count.up("cps_commission_ratio", {
time: 1000,
num: data.data.commission_ratio,
regulator: 50
});
count.up("cps_all_income", {
time: 1000,
num: data.data.all_income,
regulator: 50
});
count.up("cps_td_income", {
time: 1000,
num: data.data.td_profit,
regulator: 50
});
count.up("cps_withdraw", {
time: 1000,
num: data.data.cps_withdraw,
regulator: 50
});
let array = [];
if (data.data.links.length > 0) {
for (let i in data.data.links) {
let list = data.data.links[i];
array.push(list);
}
}
var desc = function (x, y) {
return (x['sort'] < y['sort']) ? 1 : -1;
};
array.sort(desc);
for (const descKey in array) {
let row = array[descKey];
let url_link = row.url;
if (row.status === 1) {
row.status = '推广中';
if (row.url.indexOf('?') !== -1) {
url_link = row.url + '&channel_code=' + row.channel_uid;
} else {
url_link = row.url + '?channel_code=' + row.channel_uid;
}// 首次出现的位置
if (url_link.substr(url_link.indexOf('?') - 1, 1) !== '/') {
// 添加 /
url_link = url_link.substr(0, url_link.indexOf('?')) + '/' + url_link.substr(url_link.indexOf('?'));
}
let pack_btn = '';
if(row.app.android_enable !== 1){
pack_btn = '渠道包未开放!';
}else{
if (row.pack) {
if (row.pack.status === 1) {
// 成功
if (row.pack.mom_app_version !== row.app.android_version){
pack_btn = '';
}else{
pack_btn = '';
}
} else if (row.pack.status === 2) {
// 失败
pack_btn = '';
} else if (row.pack.status === 3){
// 计算时间
time1 = (new Date(row.pack.updated_at)).getTime();
time2 = (new Date()).getTime();
var cha = time1 > time2 ? time1 - time2 : time2 - time1;
var day = Math.floor(cha / (24 * 3600 * 1000));
var hours = Math.floor(cha % (24 * 3600 * 1000) / (3600 * 1000));
var minutes = Math.floor(cha % (24 * 3600 * 1000) % (3600 * 1000) / (60 * 1000));
// 10 分钟有效
if (day >=1 || hours >= 1 || minutes >= 10){
pack_btn = '';
}else{
pack_btn = '渠道包生成中(2分钟后刷新查看!)';
}
}
}else{
// 未打包
pack_btn = '';
}
}
let html = '\n' +
'
\n' +
'
\n' +
'
' + row.app_name + '
\n' +
'
' + row.status + '
\n' +
'
\n' +
'
总推广用户:' + row.users + '
\n' +
'
\n' +
'

\n' +
'
\n' +
'
' + row.title + '
\n' +
'
\n' +
'
推广文案:' + row.note + '
' +
'
渠道包:' + pack_btn + '
\n' +
'
\n' +
'
';
$('#cps-links-box').prepend(html);
} else {
row.status = "";
let html = '\n' +
'
\n' +
'
\n' +
'
' + row.app_name + '
\n' +
'
' + row.status + '
\n' +
'
\n' +
'
总推广用户:' + row.users + '
\n' +
'
\n' +
'

\n' +
'
\n' +
'
' + row.title + '
\n' +
'
\n' +
'
推广文案:' + row.note + '
' +
'
渠道包:请联系开线负责人开启!
\n' +
'
\n' +
'
';
$('#cps-links-box').append(html);
}
}
$("#cps-links-box .btn-nd").click(function () {
layer.alert('请联系开线负责人开启!', {
icon: 3,
title: '提示'
});
});
} else {
// 其他的
$('#abnormal').css('display', 'block');
count.up("td_users_deduction", {
time: 1000,
num: data.data.td_users_deduction,
regulator: 50
});
count.up("users_deduction", {
time: 1000,
num: data.data.users_deduction,
regulator: 50
});
count.up("td_add_agent", {
time: 1000,
num: data.data.td_add_agent,
regulator: 50
});
count.up("total_agent", {
time: 1000,
num: data.data.total_agent,
regulator: 50
});
count.up("td_down_commission_money", {
time: 1000,
num: data.data.td_down_commission_money,
regulator: 50
});
count.up("down_commission_money", {
time: 1000,
num: data.data.down_commission_money,
bit: 2,
regulator: 50
});
count.up("td_commission_money", {
time: 1000,
num: data.data.td_commission_money,
regulator: 50
});
count.up("td_profit", {
time: 1000,
num: data.data.td_profit,
regulator: 50
});
count.up("total_profit", {
time: 1000,
num: data.data.total_profit,
regulator: 50
});
count.up("commission_ratio", {
time: 1000,
num: data.data.commission_ratio,
regulator: 50
});
count.up("commission_money", {
time: 1000,
num: parseInt(data.data.commission_money),
regulator: 50
});
count.up("td_deduction_success_money", {
time: 1000,
num: parseInt(data.data.td_deduction_success_money),
regulator: 50
});
}
// 打包
$(".btn-pack").click(function () {
// channel_code
let uid = $(this).attr('channel_code');
console.debug(uid);
let createLoading = layer.load();
// 打包
let ret = http.ajax({
url: '/app/pack',
data: {uid:uid}
});
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);
});
} else {
layer.msg(data.message, {icon: 2, time: 1000});
}
});
return false;
});
// 渠道包链接
$(".btn-xz").click(function () {
layer.open({
id: 'qrcode',
type: 2,
title: '获取链接',
shade: 0.1,
offset: '200px',
area: ['400px', '200px'],
maxWidth: 500,
maxHeight: 500,
scrollbar: true,
content: '../sponsored_links/copy_link.html?|||' + $(this).attr('url'),
});
});
} else {
layer.msg('数据加载出错!');
}
});
// 获取链接
$(document).on('click', '.cpa-cps-cont .link-link a', function () {
console.debug();
let url_link = $(this).text();
layer.open({
id: 'qrcode',
type: 2,
title: '获取链接',
shade: 0.1,
offset: '200px',
area: ['400px', '200px'],
maxWidth: 500,
maxHeight: 500,
scrollbar: true,
content: '/view/sponsored_links/copy_link.html?|||' + url_link,
});
});
});