提交带啊吗
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,30 +677,98 @@ 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'];
|
||||
|
|
@ -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]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -427,3 +427,5 @@ 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_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>
|
||||
|
|
@ -164,9 +179,10 @@
|
|||
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 = {
|
||||
|
|
@ -195,67 +211,85 @@
|
|||
};
|
||||
},
|
||||
cols: [[
|
||||
{field: 'id', title: '盒子ID', width: 80, sort: true, fixed: 'left'},
|
||||
{field: 'title', title: '盒子名称', width: 180},
|
||||
{templet: function(d) {
|
||||
{ field: 'id', title: '盒子ID', width: 80, sort: true, fixed: 'left' },
|
||||
{ field: 'title', title: '盒子名称', width: 200 },
|
||||
{
|
||||
templet: function (d) {
|
||||
var statusHtml = '';
|
||||
if(d.status == 1) {
|
||||
if (d.status == 1) {
|
||||
statusHtml = '<span class="layui-badge layui-bg-green">上架</span>';
|
||||
} else if(d.status == 2) {
|
||||
} else if (d.status == 2) {
|
||||
statusHtml = '<span class="layui-badge layui-bg-gray">下架</span>';
|
||||
} else if(d.status == 3) {
|
||||
} 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) {
|
||||
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>';
|
||||
}},
|
||||
{field: 'use_money', title: '收入', width: 110, templet: function(d) {
|
||||
}
|
||||
},
|
||||
{
|
||||
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>';
|
||||
}},
|
||||
{field: 'sc_money', title: '出货价值', width: 110, templet: function(d) {
|
||||
}
|
||||
},
|
||||
{
|
||||
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>';
|
||||
}},
|
||||
{field: 're_money', title: '兑换价值', width: 110, templet: function(d) {
|
||||
}
|
||||
},
|
||||
{
|
||||
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>';
|
||||
}},
|
||||
{field: 'fh_money', title: '发货价值', width: 110, templet: function(d) {
|
||||
}
|
||||
},
|
||||
{
|
||||
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>';
|
||||
}},
|
||||
{field: 'profit', title: '利润', width: 110, templet: function(d) {
|
||||
}
|
||||
},
|
||||
{
|
||||
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>';
|
||||
}},
|
||||
{field: 'profit_rate', title: '利润率', width: 100, templet: function(d) {
|
||||
}
|
||||
},
|
||||
{
|
||||
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;
|
||||
|
|
@ -268,11 +302,34 @@
|
|||
}
|
||||
}
|
||||
|
||||
// 开始加载统计数据
|
||||
// 加载汇总数据
|
||||
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;
|
||||
|
|
@ -287,7 +344,7 @@
|
|||
requests++;
|
||||
activeRequests++;
|
||||
|
||||
loadBoxStatistics(item, function() {
|
||||
loadBoxStatistics(item, function () {
|
||||
activeRequests--;
|
||||
if (activeRequests === 0) {
|
||||
isLoading = false;
|
||||
|
|
@ -302,13 +359,13 @@
|
|||
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;
|
||||
|
||||
|
|
@ -316,6 +373,7 @@
|
|||
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;
|
||||
|
|
@ -326,37 +384,36 @@
|
|||
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);
|
||||
|
||||
// 直接更新单元格内容,不重新渲染表格
|
||||
var tr = $('#profitTable').next().find('tr[data-index="' + i + '"]');
|
||||
if (tr.length > 0) {
|
||||
// 设置背景色
|
||||
if (data.is_negative) {
|
||||
$('tr[data-index="' + i + '"]').css('background-color', '#ffebee');
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
|
@ -393,17 +450,21 @@
|
|||
}
|
||||
|
||||
// 搜索按钮点击事件
|
||||
$('#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') {
|
||||
// 查看出货概览
|
||||
|
|
@ -419,10 +480,26 @@
|
|||
});
|
||||
|
||||
// 页面加载完成后执行
|
||||
$(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