提交带啊吗
This commit is contained in:
parent
35275bbc8c
commit
426d6dd943
|
|
@ -664,9 +664,11 @@ class Statistics extends Base
|
|||
}
|
||||
|
||||
// 解析时间范围
|
||||
$hasTimeRange = false;
|
||||
$startTime = 0;
|
||||
$endTime = time();
|
||||
if ($addtime) {
|
||||
$endTime = 0;
|
||||
if (!empty($addtime)) {
|
||||
$hasTimeRange = true;
|
||||
$times = explode(' - ', $addtime);
|
||||
$startTime = strtotime($times[0]);
|
||||
$endTime = strtotime($times[1]);
|
||||
|
|
@ -675,31 +677,99 @@ class Statistics extends Base
|
|||
// 获取测试用户ID
|
||||
$testUsers = User::where('istest', '>', 0)->column('id');
|
||||
$testUserIds = empty($testUsers) ? [0] : $testUsers;
|
||||
$testUserIdsStr = implode(',', $testUserIds);
|
||||
|
||||
// 查询单个盒子的统计数据
|
||||
$data = Db::name('goods')->alias('goods')
|
||||
->field([
|
||||
'goods.id',
|
||||
'(SELECT COALESCE(sum(use_money), 0) + COALESCE(sum(price), 0) FROM `order` WHERE status=1 AND (price>0 OR use_money>0) AND pay_time > ' . $startTime . ' and pay_time < ' . $endTime . ' AND goods_id=goods.id AND status=1 AND user_id NOT IN (' . $testUserIdsStr . ')) AS use_money',
|
||||
'(SELECT COALESCE(sum(goodslist_money), 0) FROM `order_list` WHERE goods_id=goods.id AND user_id NOT IN (' . $testUserIdsStr . ') AND addtime > ' . $startTime . ' and addtime < ' . $endTime . ') AS sc_money',
|
||||
'(SELECT COALESCE(sum(goodslist_money), 0) FROM `order_list` WHERE goods_id=goods.id AND LENGTH(recovery_num)>0 AND user_id NOT IN (' . $testUserIdsStr . ') AND addtime > ' . $startTime . ' and addtime < ' . $endTime . ') AS re_money',
|
||||
'(SELECT COALESCE(sum(goodslist_money), 0) FROM `order_list` WHERE goods_id=goods.id AND LENGTH(send_num)>0 AND user_id NOT IN (' . $testUserIdsStr . ') AND addtime > ' . $startTime . ' and addtime < ' . $endTime . ') AS fh_money',
|
||||
'(SELECT count(1) FROM `order_list` WHERE goods_id=goods.id AND user_id NOT IN (' . $testUserIdsStr . ') AND addtime > ' . $startTime . ' and addtime < ' . $endTime . ' and parent_goods_list_id=0 ) AS cj_count'
|
||||
])
|
||||
->where('goods.id', '=', $goodId)
|
||||
// 获取盒子基本信息
|
||||
$goodsInfo = Db::name('goods')
|
||||
->where('id', '=', $goodId)
|
||||
->field('id')
|
||||
->find();
|
||||
|
||||
if (!$data) {
|
||||
|
||||
if (!$goodsInfo) {
|
||||
return json(['code' => 1, 'msg' => '盒子不存在']);
|
||||
}
|
||||
|
||||
// 处理数值,确保为浮点型
|
||||
$data['use_money'] = floatval($data['use_money']);
|
||||
$data['sc_money'] = floatval($data['sc_money']);
|
||||
$data['re_money'] = floatval($data['re_money']);
|
||||
$data['fh_money'] = floatval($data['fh_money']);
|
||||
|
||||
// 查询1:获取充值金额和余额消费总和
|
||||
$orderQuery = Db::name('order')
|
||||
->where('status', '=', 1)
|
||||
->where(function ($query) {
|
||||
$query->where('price', '>', 0)
|
||||
->whereOr('use_money', '>', 0);
|
||||
})
|
||||
->where('goods_id', '=', $goodId)
|
||||
->where('user_id', 'not in', $testUserIds);
|
||||
|
||||
// 只有在有时间范围时才添加时间条件
|
||||
if ($hasTimeRange) {
|
||||
$orderQuery->where('pay_time', '>', $startTime)
|
||||
->where('pay_time', '<', $endTime);
|
||||
}
|
||||
|
||||
// 分别获取price和use_money的总和后相加
|
||||
$priceSum = $orderQuery->sum('price');
|
||||
$useMoneySum = $orderQuery->sum('use_money');
|
||||
$useMoney = floatval($priceSum) + floatval($useMoneySum);
|
||||
|
||||
// 查询2:获取出货成本
|
||||
$scMoneyQuery = Db::name('order_list')
|
||||
->where('goods_id', '=', $goodId)
|
||||
->where('user_id', 'not in', $testUserIds);
|
||||
|
||||
if ($hasTimeRange) {
|
||||
$scMoneyQuery->where('addtime', '>', $startTime)
|
||||
->where('addtime', '<', $endTime);
|
||||
}
|
||||
|
||||
$scMoney = $scMoneyQuery->sum('goodslist_money');
|
||||
|
||||
// 查询3:获取兑换成本
|
||||
$reMoneyQuery = Db::name('order_list')
|
||||
->where('goods_id', '=', $goodId)
|
||||
->where('LENGTH(recovery_num)', '>', 0)
|
||||
->where('user_id', 'not in', $testUserIds);
|
||||
|
||||
if ($hasTimeRange) {
|
||||
$reMoneyQuery->where('addtime', '>', $startTime)
|
||||
->where('addtime', '<', $endTime);
|
||||
}
|
||||
|
||||
$reMoney = $reMoneyQuery->sum('goodslist_money');
|
||||
|
||||
// 查询4:获取发货成本
|
||||
$fhMoneyQuery = Db::name('order_list')
|
||||
->where('goods_id', '=', $goodId)
|
||||
->where('LENGTH(send_num)', '>', 0)
|
||||
->where('user_id', 'not in', $testUserIds);
|
||||
|
||||
if ($hasTimeRange) {
|
||||
$fhMoneyQuery->where('addtime', '>', $startTime)
|
||||
->where('addtime', '<', $endTime);
|
||||
}
|
||||
|
||||
$fhMoney = $fhMoneyQuery->sum('goodslist_money');
|
||||
|
||||
// 查询5:获取抽奖次数
|
||||
$cjCountQuery = Db::name('order_list')
|
||||
->where('goods_id', '=', $goodId)
|
||||
->where('user_id', 'not in', $testUserIds)
|
||||
->where('parent_goods_list_id', '=', 0);
|
||||
|
||||
if ($hasTimeRange) {
|
||||
$cjCountQuery->where('addtime', '>', $startTime)
|
||||
->where('addtime', '<', $endTime);
|
||||
}
|
||||
|
||||
$cjCount = $cjCountQuery->count();
|
||||
|
||||
// 组合数据
|
||||
$data = [
|
||||
'id' => $goodId,
|
||||
'use_money' => floatval($useMoney),
|
||||
'sc_money' => floatval($scMoney),
|
||||
're_money' => floatval($reMoney),
|
||||
'fh_money' => floatval($fhMoney),
|
||||
'cj_count' => intval($cjCount)
|
||||
];
|
||||
|
||||
// 计算利润和利润率
|
||||
$data['profit'] = $data['use_money'] - $data['sc_money'];
|
||||
$data['profit_rate'] = $data['use_money'] > 0 ? round(($data['profit'] / $data['use_money']) * 100, 2) : 0;
|
||||
|
|
@ -708,4 +778,140 @@ class Statistics extends Base
|
|||
return json(['code' => 0, 'msg' => '获取成功', 'data' => $data]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有盒子的统计数据汇总
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getSummaryStatistics(Request $request)
|
||||
{
|
||||
$goodId = trim(input('get.goodId'));
|
||||
$title = trim(input('get.title'));
|
||||
$status = trim(input('get.status'));
|
||||
$type = trim(input('get.type'));
|
||||
$addtime = trim(input('get.addtime'));
|
||||
|
||||
// 解析时间范围
|
||||
$hasTimeRange = false;
|
||||
$startTime = 0;
|
||||
$endTime = 0;
|
||||
if (!empty($addtime)) {
|
||||
$hasTimeRange = true;
|
||||
$times = explode(' - ', $addtime);
|
||||
$startTime = strtotime($times[0]);
|
||||
$endTime = strtotime($times[1]);
|
||||
}
|
||||
|
||||
// 构建查询条件
|
||||
$goodsWhere = [['delete_time', '=', null]];
|
||||
if ($goodId) {
|
||||
$goodsWhere[] = ['id', '=', $goodId];
|
||||
}
|
||||
if ($title) {
|
||||
$goodsWhere[] = ['title', 'like', '%' . $title . '%'];
|
||||
}
|
||||
if ($status) {
|
||||
$goodsWhere[] = ['status', '=', $status];
|
||||
}
|
||||
if ($type) {
|
||||
$goodsWhere[] = ['type', '=', $type];
|
||||
}
|
||||
|
||||
// 获取符合条件的盒子ID列表
|
||||
$goodsIds = Db::name('goods')
|
||||
->where($goodsWhere)
|
||||
->column('id');
|
||||
|
||||
if (empty($goodsIds)) {
|
||||
return json([
|
||||
'code' => 0,
|
||||
'msg' => '没有找到符合条件的盒子',
|
||||
'data' => [
|
||||
'totalIncome' => 0,
|
||||
'totalCost' => 0,
|
||||
'totalProfit' => 0,
|
||||
'totalReMoney' => 0,
|
||||
'totalFhMoney' => 0
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
// 获取测试用户ID
|
||||
$testUsers = User::where('istest', '>', 0)->column('id');
|
||||
$testUserIds = empty($testUsers) ? [0] : $testUsers;
|
||||
|
||||
// 查询1:获取充值金额和余额消费总和
|
||||
$orderQuery = Db::name('order')
|
||||
->where('status', '=', 1)
|
||||
->where(function ($query) {
|
||||
$query->where('price', '>', 0)
|
||||
->whereOr('use_money', '>', 0);
|
||||
})
|
||||
->where('goods_id', 'in', $goodsIds)
|
||||
->where('user_id', 'not in', $testUserIds);
|
||||
|
||||
// 只有在有时间范围时才添加时间条件
|
||||
if ($hasTimeRange) {
|
||||
$orderQuery->where('pay_time', '>', $startTime)
|
||||
->where('pay_time', '<', $endTime);
|
||||
}
|
||||
|
||||
// 分别获取price和use_money的总和后相加
|
||||
$priceSum = $orderQuery->sum('price');
|
||||
$useMoneySum = $orderQuery->sum('use_money');
|
||||
$totalIncome = floatval($priceSum) + floatval($useMoneySum);
|
||||
|
||||
// 查询2:获取出货成本
|
||||
$scMoneyQuery = Db::name('order_list')
|
||||
->where('goods_id', 'in', $goodsIds)
|
||||
->where('user_id', 'not in', $testUserIds);
|
||||
|
||||
if ($hasTimeRange) {
|
||||
$scMoneyQuery->where('addtime', '>', $startTime)
|
||||
->where('addtime', '<', $endTime);
|
||||
}
|
||||
|
||||
$totalCost = floatval($scMoneyQuery->sum('goodslist_money'));
|
||||
|
||||
// 查询3:获取兑换成本
|
||||
$reMoneyQuery = Db::name('order_list')
|
||||
->where('goods_id', 'in', $goodsIds)
|
||||
->where('LENGTH(recovery_num)', '>', 0)
|
||||
->where('user_id', 'not in', $testUserIds);
|
||||
|
||||
if ($hasTimeRange) {
|
||||
$reMoneyQuery->where('addtime', '>', $startTime)
|
||||
->where('addtime', '<', $endTime);
|
||||
}
|
||||
|
||||
$totalReMoney = floatval($reMoneyQuery->sum('goodslist_money'));
|
||||
|
||||
// 查询4:获取发货成本
|
||||
$fhMoneyQuery = Db::name('order_list')
|
||||
->where('goods_id', 'in', $goodsIds)
|
||||
->where('LENGTH(send_num)', '>', 0)
|
||||
->where('user_id', 'not in', $testUserIds);
|
||||
|
||||
if ($hasTimeRange) {
|
||||
$fhMoneyQuery->where('addtime', '>', $startTime)
|
||||
->where('addtime', '<', $endTime);
|
||||
}
|
||||
|
||||
$totalFhMoney = floatval($fhMoneyQuery->sum('goodslist_money'));
|
||||
|
||||
// 计算总利润
|
||||
$totalProfit = $totalIncome - $totalCost;
|
||||
|
||||
// 返回汇总数据
|
||||
$data = [
|
||||
'totalIncome' => $totalIncome,
|
||||
'totalCost' => $totalCost,
|
||||
'totalProfit' => $totalProfit,
|
||||
'totalReMoney' => $totalReMoney,
|
||||
'totalFhMoney' => $totalFhMoney
|
||||
];
|
||||
|
||||
return json(['code' => 0, 'msg' => '获取成功', 'data' => $data]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -426,4 +426,6 @@ Route::rule('statistics_order', 'Statistics/orderList', 'GET');
|
|||
Route::rule('statistics_orderList', 'Statistics/goodsList', 'GET');
|
||||
Route::rule('statistics_exchangeList', 'Statistics/exchangeList', 'GET');
|
||||
Route::rule('statistics_shipmentList', 'Statistics/shipmentList', 'GET');
|
||||
Route::rule('statistics_productsOverview', 'Statistics/productsOverview', 'GET');
|
||||
Route::rule('statistics_productsOverview', 'Statistics/productsOverview', 'GET');
|
||||
Route::rule('statistics_getBoxStatistics', 'Statistics/getBoxStatistics', 'GET');
|
||||
Route::rule('statistics_getSummaryStatistics', 'Statistics/getSummaryStatistics', 'GET');
|
||||
|
|
@ -1,19 +1,21 @@
|
|||
{include file="Public:header3"/}
|
||||
|
||||
<body>
|
||||
<div class="layui-fluid">
|
||||
<div class="layui-fluid" style="padding: 0px;">
|
||||
<div class="layui-card">
|
||||
<!-- 搜索条件区域 -->
|
||||
<form class="layui-form layui-card-header layuiadmin-card-header-auto">
|
||||
<form class="layui-form layui-card-header layuiadmin-card-header-auto" style="padding-top: 15px;">
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-inline">
|
||||
<div class="layui-input-inline" style="width:150px;margin-left: 0px">
|
||||
<input type="text" name="goodId" id="goodId" placeholder="请输入盒子Id" autocomplete="off" class="layui-input">
|
||||
<input type="text" name="goodId" id="goodId" placeholder="请输入盒子Id" autocomplete="off"
|
||||
class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
<div class="layui-input-inline" style="width:150px;margin-left: 0px">
|
||||
<input type="text" name="title" id="title" placeholder="请输入盒子名称" autocomplete="off" class="layui-input">
|
||||
<input type="text" name="title" id="title" placeholder="请输入盒子名称" autocomplete="off"
|
||||
class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
|
|
@ -35,7 +37,8 @@
|
|||
</div>
|
||||
<div class="layui-inline">
|
||||
<div class="layui-input-inline" style="width:300px;margin-left: 0px">
|
||||
<input type="text" id="addtime" name="addtime" class="layui-input" placeholder="选择时间" autocomplete="off">
|
||||
<input type="text" id="addtime" name="addtime" class="layui-input" placeholder="选择时间"
|
||||
autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -52,7 +55,11 @@
|
|||
<div class="layui-row layui-col-space15" id="statisticsSummary">
|
||||
<div class="layui-col-md3">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header">总收入</div>
|
||||
<div class="layui-card-header">
|
||||
总收入
|
||||
<i class="layui-icon layui-icon-about" style="font-size: 14px; color: #1E9FFF;"
|
||||
title="收入 = 微信支付 + 钻石支付"></i>
|
||||
</div>
|
||||
<div class="layui-card-body" style="font-size: 24px; color: #01AAED;">
|
||||
¥ <span id="totalIncome">0.00</span>
|
||||
</div>
|
||||
|
|
@ -60,7 +67,11 @@
|
|||
</div>
|
||||
<div class="layui-col-md3">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header">总出货价值</div>
|
||||
<div class="layui-card-header">
|
||||
总出货价值
|
||||
<i class="layui-icon layui-icon-about" style="font-size: 14px; color: #FFB800;"
|
||||
title="出货价值 = 奖品的兑换价格"></i>
|
||||
</div>
|
||||
<div class="layui-card-body" style="font-size: 24px; color: #FFB800;">
|
||||
¥ <span id="totalCost">0.00</span>
|
||||
</div>
|
||||
|
|
@ -68,7 +79,11 @@
|
|||
</div>
|
||||
<div class="layui-col-md3">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header">总利润</div>
|
||||
<div class="layui-card-header">
|
||||
总利润
|
||||
<i class="layui-icon layui-icon-about" style="font-size: 14px; color: #5FB878;"
|
||||
title="利润 = 收入 - 出货价值"></i>
|
||||
</div>
|
||||
<div class="layui-card-body" style="font-size: 24px;">
|
||||
¥ <span id="totalProfit" class="profit-value">0.00</span>
|
||||
</div>
|
||||
|
|
@ -78,28 +93,28 @@
|
|||
<div class="layui-card">
|
||||
<div class="layui-card-header">总兑换/发货价值</div>
|
||||
<div class="layui-card-body" style="font-size: 24px;">
|
||||
<span style="color: #FF9800;">¥ <span id="totalReMoney">0.00</span></span> /
|
||||
<span style="color: #FF9800;">¥ <span id="totalReMoney">0.00</span></span> /
|
||||
<span style="color: #673AB7;">¥ <span id="totalFhMoney">0.00</span></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- 数据表格区域 -->
|
||||
<table id="profitTable" lay-filter="profitTable"></table>
|
||||
|
||||
|
||||
<!-- 表格操作栏模板 -->
|
||||
<script type="text/html" id="operationTpl">
|
||||
<button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="viewProductsOverview">出货概览</button>
|
||||
</script>
|
||||
|
||||
|
||||
<!-- 利润和利润率模板 -->
|
||||
<script type="text/html" id="profitTpl">
|
||||
<span class="layui-badge {{d.profit >= 0 ? 'layui-bg-green' : 'layui-bg-red'}}">
|
||||
¥ {{d.profit.toFixed(2)}}
|
||||
</span>
|
||||
</script>
|
||||
|
||||
|
||||
<script type="text/html" id="profitRateTpl">
|
||||
<span class="layui-badge {{d.profit_rate >= 0 ? 'layui-bg-green' : 'layui-bg-red'}}">
|
||||
{{d.profit_rate.toFixed(2)}}%
|
||||
|
|
@ -123,7 +138,7 @@
|
|||
type: 'datetime',
|
||||
range: true
|
||||
});
|
||||
|
||||
|
||||
// 加载盒子类型数据
|
||||
function loadGoodsTypes() {
|
||||
$.ajax({
|
||||
|
|
@ -133,7 +148,7 @@
|
|||
if (res.code === 0) {
|
||||
// 更新下拉框
|
||||
var html = '<option value="">--盒子类型--</option>';
|
||||
|
||||
|
||||
$.each(res.data, function (index, item) {
|
||||
html += '<option value="' + item.value + '" title="' + item.remark + '">' + item.fl_name + '</option>';
|
||||
});
|
||||
|
|
@ -143,7 +158,7 @@
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 全局变量,存储汇总数据
|
||||
var summaryData = {
|
||||
totalIncome: 0,
|
||||
|
|
@ -152,21 +167,22 @@
|
|||
totalReMoney: 0,
|
||||
totalFhMoney: 0
|
||||
};
|
||||
|
||||
|
||||
// 全局变量,用于控制异步加载
|
||||
var loadingQueue = [];
|
||||
var isLoading = false;
|
||||
var maxConcurrentRequests = 3; // 最大并发请求数
|
||||
|
||||
|
||||
// 初始化表格
|
||||
var profitTable = table.render({
|
||||
elem: '#profitTable',
|
||||
url: '{:url("/admin/statistics/profitData")}',
|
||||
method: 'get',
|
||||
page: true,
|
||||
limit: 20,
|
||||
height:'full-180',
|
||||
limit: 50,
|
||||
where: getSearchParams(),
|
||||
parseData: function(res) {
|
||||
parseData: function (res) {
|
||||
if (res.code === 0) {
|
||||
// 清空汇总数据
|
||||
summaryData = {
|
||||
|
|
@ -176,10 +192,10 @@
|
|||
totalReMoney: 0,
|
||||
totalFhMoney: 0
|
||||
};
|
||||
|
||||
|
||||
// 更新统计摘要数据为0
|
||||
updateStatisticsSummary(summaryData);
|
||||
|
||||
|
||||
return {
|
||||
"code": 0,
|
||||
"msg": res.msg,
|
||||
|
|
@ -195,71 +211,89 @@
|
|||
};
|
||||
},
|
||||
cols: [[
|
||||
{field: 'id', title: '盒子ID', width: 80, sort: true, fixed: 'left'},
|
||||
{field: 'title', title: '盒子名称', width: 180},
|
||||
{templet: function(d) {
|
||||
var statusHtml = '';
|
||||
if(d.status == 1) {
|
||||
statusHtml = '<span class="layui-badge layui-bg-green">上架</span>';
|
||||
} else if(d.status == 2) {
|
||||
statusHtml = '<span class="layui-badge layui-bg-gray">下架</span>';
|
||||
} else if(d.status == 3) {
|
||||
statusHtml = '<span class="layui-badge layui-bg-orange">售罄</span>';
|
||||
{ field: 'id', title: '盒子ID', width: 80, sort: true, fixed: 'left' },
|
||||
{ field: 'title', title: '盒子名称', width: 200 },
|
||||
{
|
||||
templet: function (d) {
|
||||
var statusHtml = '';
|
||||
if (d.status == 1) {
|
||||
statusHtml = '<span class="layui-badge layui-bg-green">上架</span>';
|
||||
} else if (d.status == 2) {
|
||||
statusHtml = '<span class="layui-badge layui-bg-gray">下架</span>';
|
||||
} else if (d.status == 3) {
|
||||
statusHtml = '<span class="layui-badge layui-bg-orange">售罄</span>';
|
||||
} else {
|
||||
statusHtml = '<span class="layui-badge layui-bg-orange">自动下架</span>';
|
||||
}
|
||||
return '<div><button class="layui-btn layui-btn-normal layui-btn-radius layui-btn-xs type-btn" data-type="' + d.type + '">' + d.type_name + '</button> / ' + statusHtml + '</div>';
|
||||
}, title: '盒子类型/状态', width: 160
|
||||
},
|
||||
{ field: 'price', title: '盒子单价', width: 100, templet: '<div>¥ {{d.price}}</div>' },
|
||||
{
|
||||
field: 'cj_count', title: '抽奖次数', width: 100, templet: function (d) {
|
||||
if (!d.loaded) {
|
||||
return '<div><i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i></div>';
|
||||
}
|
||||
return '<div>' + d.cj_count + '</div>';
|
||||
}
|
||||
return '<div><button class="layui-btn layui-btn-normal layui-btn-radius layui-btn-xs type-btn" data-type="'+d.type+'">'+d.type_name+'</button> / ' + statusHtml + '</div>';
|
||||
}, title: '盒子类型/状态', width: 160},
|
||||
{field: 'price', title: '盒子单价', width: 100, templet: '<div>¥ {{d.price}}</div>'},
|
||||
{field: 'cj_count', title: '抽奖次数', width: 100, templet: function(d) {
|
||||
if (!d.loaded) {
|
||||
return '<div><i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i></div>';
|
||||
},
|
||||
{
|
||||
field: 'use_money', title: '收入 <i class="layui-icon layui-icon-about" title="微信支付+钻石支付"></i>', width: 150, templet: function (d) {
|
||||
if (!d.loaded) {
|
||||
return '<div><i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i></div>';
|
||||
}
|
||||
return '<div><span class="layui-badge layui-bg-blue">¥ ' + d.use_money.toFixed(2) + '</span></div>';
|
||||
}
|
||||
return '<div>' + d.cj_count + '</div>';
|
||||
}},
|
||||
{field: 'use_money', title: '收入', width: 110, templet: function(d) {
|
||||
if (!d.loaded) {
|
||||
return '<div><i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i></div>';
|
||||
},
|
||||
{
|
||||
field: 'sc_money', title: '出货价值 <i class="layui-icon layui-icon-about" title="奖品的兑换价格"></i>', width: 150, templet: function (d) {
|
||||
if (!d.loaded) {
|
||||
return '<div><i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i></div>';
|
||||
}
|
||||
return '<div><span class="layui-badge layui-bg-orange">¥ ' + d.sc_money.toFixed(2) + '</span></div>';
|
||||
}
|
||||
return '<div><span class="layui-badge layui-bg-blue">¥ ' + d.use_money.toFixed(2) + '</span></div>';
|
||||
}},
|
||||
{field: 'sc_money', title: '出货价值', width: 110, templet: function(d) {
|
||||
if (!d.loaded) {
|
||||
return '<div><i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i></div>';
|
||||
},
|
||||
{
|
||||
field: 're_money', title: '已兑换达达卷', width: 150, templet: function (d) {
|
||||
if (!d.loaded) {
|
||||
return '<div><i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i></div>';
|
||||
}
|
||||
return '<div><span class="layui-badge" style="background-color: #FF9800;">¥ ' + d.re_money.toFixed(2) + '</span></div>';
|
||||
}
|
||||
return '<div><span class="layui-badge layui-bg-orange">¥ ' + d.sc_money.toFixed(2) + '</span></div>';
|
||||
}},
|
||||
{field: 're_money', title: '兑换价值', width: 110, templet: function(d) {
|
||||
if (!d.loaded) {
|
||||
return '<div><i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i></div>';
|
||||
},
|
||||
{
|
||||
field: 'fh_money', title: '已申请发货', width: 110, templet: function (d) {
|
||||
if (!d.loaded) {
|
||||
return '<div><i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i></div>';
|
||||
}
|
||||
return '<div><span class="layui-badge" style="background-color: #673AB7;">¥ ' + d.fh_money.toFixed(2) + '</span></div>';
|
||||
}
|
||||
return '<div><span class="layui-badge" style="background-color: #FF9800;">¥ ' + d.re_money.toFixed(2) + '</span></div>';
|
||||
}},
|
||||
{field: 'fh_money', title: '发货价值', width: 110, templet: function(d) {
|
||||
if (!d.loaded) {
|
||||
return '<div><i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i></div>';
|
||||
},
|
||||
{
|
||||
field: 'profit', title: '利润 <i class="layui-icon layui-icon-about" title="收入-出货价值"></i>', width: 110, templet: function (d) {
|
||||
if (!d.loaded) {
|
||||
return '<div><i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i></div>';
|
||||
}
|
||||
var colorClass = d.profit >= 0 ? 'layui-bg-green' : 'layui-bg-red';
|
||||
return '<div><span class="layui-badge ' + colorClass + '">¥ ' + d.profit.toFixed(2) + '</span></div>';
|
||||
}
|
||||
return '<div><span class="layui-badge" style="background-color: #673AB7;">¥ ' + d.fh_money.toFixed(2) + '</span></div>';
|
||||
}},
|
||||
{field: 'profit', title: '利润', width: 110, templet: function(d) {
|
||||
if (!d.loaded) {
|
||||
return '<div><i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i></div>';
|
||||
},
|
||||
{
|
||||
field: 'profit_rate', title: '利润率', width: 100, templet: function (d) {
|
||||
if (!d.loaded) {
|
||||
return '<div><i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i></div>';
|
||||
}
|
||||
var colorClass = d.profit_rate >= 0 ? 'layui-bg-green' : 'layui-bg-red';
|
||||
return '<div><span class="layui-badge ' + colorClass + '">' + d.profit_rate.toFixed(2) + '%</span></div>';
|
||||
}
|
||||
var colorClass = d.profit >= 0 ? 'layui-bg-green' : 'layui-bg-red';
|
||||
return '<div><span class="layui-badge ' + colorClass + '">¥ ' + d.profit.toFixed(2) + '</span></div>';
|
||||
}},
|
||||
{field: 'profit_rate', title: '利润率', width: 100, templet: function(d) {
|
||||
if (!d.loaded) {
|
||||
return '<div><i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i></div>';
|
||||
}
|
||||
var colorClass = d.profit_rate >= 0 ? 'layui-bg-green' : 'layui-bg-red';
|
||||
return '<div><span class="layui-badge ' + colorClass + '">' + d.profit_rate.toFixed(2) + '%</span></div>';
|
||||
}},
|
||||
{title: '操作', width: 110, toolbar: '#operationTpl', fixed: 'right'}
|
||||
},
|
||||
{ title: '操作', width: 110, toolbar: '#operationTpl', fixed: 'right' }
|
||||
]],
|
||||
done: function(res) {
|
||||
done: function (res) {
|
||||
// 清空加载队列
|
||||
loadingQueue = [];
|
||||
isLoading = false;
|
||||
|
||||
|
||||
// 将所有数据项添加到加载队列中
|
||||
var tableData = table.cache.profitTable || [];
|
||||
for (var i = 0; i < tableData.length; i++) {
|
||||
|
|
@ -267,27 +301,50 @@
|
|||
loadingQueue.push(tableData[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// 开始加载统计数据
|
||||
|
||||
// 加载汇总数据
|
||||
loadSummaryStatistics();
|
||||
|
||||
// 开始加载详细统计数据
|
||||
processLoadingQueue();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 加载汇总统计数据
|
||||
function loadSummaryStatistics() {
|
||||
var params = getSearchParams();
|
||||
|
||||
$.ajax({
|
||||
url: '{:url("/admin/statistics_getSummaryStatistics")}',
|
||||
type: 'GET',
|
||||
data: params,
|
||||
success: function (res) {
|
||||
if (res.code === 0) {
|
||||
// 更新汇总数据
|
||||
summaryData = res.data;
|
||||
|
||||
// 更新统计摘要显示
|
||||
updateStatisticsSummary(summaryData);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 处理加载队列
|
||||
function processLoadingQueue() {
|
||||
if (isLoading || loadingQueue.length === 0) return;
|
||||
|
||||
|
||||
isLoading = true;
|
||||
var requests = 0;
|
||||
var activeRequests = 0;
|
||||
|
||||
|
||||
// 获取当前需要处理的项目
|
||||
while (requests < maxConcurrentRequests && loadingQueue.length > 0) {
|
||||
var item = loadingQueue.shift();
|
||||
requests++;
|
||||
activeRequests++;
|
||||
|
||||
loadBoxStatistics(item, function() {
|
||||
|
||||
loadBoxStatistics(item, function () {
|
||||
activeRequests--;
|
||||
if (activeRequests === 0) {
|
||||
isLoading = false;
|
||||
|
|
@ -296,26 +353,27 @@
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 加载单个盒子的统计数据
|
||||
function loadBoxStatistics(item, callback) {
|
||||
var params = getSearchParams();
|
||||
|
||||
|
||||
$.ajax({
|
||||
url: '{:url("/admin/statistics/getBoxStatistics")}',
|
||||
url: '{:url("/admin/statistics_getBoxStatistics")}',
|
||||
type: 'GET',
|
||||
data: {
|
||||
goods_id: item.id,
|
||||
addtime: params.addtime
|
||||
},
|
||||
success: function(res) {
|
||||
success: function (res) {
|
||||
if (res.code === 0) {
|
||||
var data = res.data;
|
||||
|
||||
|
||||
// 更新表格中的数据
|
||||
var tableData = table.cache.profitTable;
|
||||
for (var i = 0; i < tableData.length; i++) {
|
||||
if (tableData[i].id === item.id) {
|
||||
// 更新数据
|
||||
tableData[i].use_money = data.use_money;
|
||||
tableData[i].sc_money = data.sc_money;
|
||||
tableData[i].re_money = data.re_money;
|
||||
|
|
@ -325,53 +383,52 @@
|
|||
tableData[i].profit_rate = data.profit_rate;
|
||||
tableData[i].is_negative = data.is_negative;
|
||||
tableData[i].loaded = true;
|
||||
|
||||
// 更新汇总数据
|
||||
summaryData.totalIncome += data.use_money;
|
||||
summaryData.totalCost += data.sc_money;
|
||||
summaryData.totalReMoney += data.re_money;
|
||||
summaryData.totalFhMoney += data.fh_money;
|
||||
summaryData.totalProfit = summaryData.totalIncome - summaryData.totalCost;
|
||||
|
||||
// 更新统计摘要
|
||||
updateStatisticsSummary(summaryData);
|
||||
|
||||
// 设置背景色
|
||||
if (data.is_negative) {
|
||||
$('tr[data-index="' + i + '"]').css('background-color', '#ffebee');
|
||||
|
||||
// 直接更新单元格内容,不重新渲染表格
|
||||
var tr = $('#profitTable').next().find('tr[data-index="' + i + '"]');
|
||||
if (tr.length > 0) {
|
||||
// 设置背景色
|
||||
if (data.is_negative) {
|
||||
tr.css('background-color', '#ffebee');
|
||||
}
|
||||
|
||||
// 更新单元格内容
|
||||
tr.find('td[data-field="use_money"] div').html('<span class="layui-badge layui-bg-blue">¥ ' + data.use_money.toFixed(2) + '</span>');
|
||||
tr.find('td[data-field="sc_money"] div').html('<span class="layui-badge layui-bg-orange">¥ ' + data.sc_money.toFixed(2) + '</span>');
|
||||
tr.find('td[data-field="re_money"] div').html('<span class="layui-badge" style="background-color: #FF9800;">¥ ' + data.re_money.toFixed(2) + '</span>');
|
||||
tr.find('td[data-field="fh_money"] div').html('<span class="layui-badge" style="background-color: #673AB7;">¥ ' + data.fh_money.toFixed(2) + '</span>');
|
||||
tr.find('td[data-field="cj_count"] div').html(data.cj_count);
|
||||
|
||||
var profitColorClass = data.profit >= 0 ? 'layui-bg-green' : 'layui-bg-red';
|
||||
tr.find('td[data-field="profit"] div').html('<span class="layui-badge ' + profitColorClass + '">¥ ' + data.profit.toFixed(2) + '</span>');
|
||||
|
||||
var rateColorClass = data.profit_rate >= 0 ? 'layui-bg-green' : 'layui-bg-red';
|
||||
tr.find('td[data-field="profit_rate"] div').html('<span class="layui-badge ' + rateColorClass + '">' + data.profit_rate.toFixed(2) + '%</span>');
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 重新渲染表格
|
||||
table.render({
|
||||
elem: '#profitTable',
|
||||
data: tableData,
|
||||
page: false,
|
||||
cols: profitTable.config.cols
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (callback) callback();
|
||||
},
|
||||
error: function() {
|
||||
error: function () {
|
||||
if (callback) callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 更新统计摘要
|
||||
function updateStatisticsSummary(summary) {
|
||||
if (!summary) return;
|
||||
|
||||
|
||||
$('#totalIncome').text(summary.totalIncome.toFixed(2));
|
||||
$('#totalCost').text(summary.totalCost.toFixed(2));
|
||||
$('#totalProfit').text(summary.totalProfit.toFixed(2));
|
||||
$('#totalReMoney').text(summary.totalReMoney.toFixed(2));
|
||||
$('#totalFhMoney').text(summary.totalFhMoney.toFixed(2));
|
||||
|
||||
|
||||
// 设置利润颜色
|
||||
var profitElem = $('#totalProfit');
|
||||
if (summary.totalProfit >= 0) {
|
||||
|
|
@ -380,7 +437,7 @@
|
|||
profitElem.parent().css('color', '#FF5722');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 获取搜索参数
|
||||
function getSearchParams() {
|
||||
return {
|
||||
|
|
@ -391,19 +448,23 @@
|
|||
addtime: $('#addtime').val()
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// 搜索按钮点击事件
|
||||
$('#searchBtn').on('click', function() {
|
||||
$('#searchBtn').on('click', function () {
|
||||
// 重新加载表格数据
|
||||
profitTable.reload({
|
||||
where: getSearchParams(),
|
||||
page: {
|
||||
curr: 1
|
||||
}
|
||||
});
|
||||
|
||||
// 重新加载汇总数据
|
||||
loadSummaryStatistics();
|
||||
});
|
||||
|
||||
|
||||
// 监听表格工具条事件
|
||||
table.on('tool(profitTable)', function(obj) {
|
||||
table.on('tool(profitTable)', function (obj) {
|
||||
var data = obj.data;
|
||||
if (obj.event === 'viewProductsOverview') {
|
||||
// 查看出货概览
|
||||
|
|
@ -417,12 +478,28 @@
|
|||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 页面加载完成后执行
|
||||
$(function() {
|
||||
$(function () {
|
||||
loadGoodsTypes();
|
||||
|
||||
// 初始化提示图标
|
||||
initTips();
|
||||
});
|
||||
|
||||
// 初始化提示信息
|
||||
function initTips() {
|
||||
// 为提示图标添加鼠标悬停事件
|
||||
$('.layui-icon-about').on('mouseenter', function () {
|
||||
var that = this;
|
||||
layer.tips($(that).attr('title'), that, {
|
||||
tips: [1, '#3595CC'],
|
||||
time: 4000
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loading…
Reference in New Issue
Block a user