提交代码

This commit is contained in:
youda 2025-04-25 19:30:06 +08:00
parent d3ce04c2d1
commit 6575bafa99
3 changed files with 38 additions and 20 deletions

View File

@ -775,7 +775,7 @@ class Statistics extends Base
];
// 计算利润和利润率
$data['profit'] = $data['use_money'] - $data['sc_money'];
$data['profit'] = $data['use_money'] - ($data['sc_money'] - $data['re_money']);
$data['profit_rate'] = $data['use_money'] > 0 ? round(($data['profit'] / $data['use_money']) * 100, 2) : 0;
$data['is_negative'] = $data['profit'] < 0;
@ -904,7 +904,7 @@ class Statistics extends Base
$totalFhMoney = floatval($fhMoneyQuery->sum('goodslist_money'));
// 计算总利润
$totalProfit = $totalIncome - $totalCost;
$totalProfit = $totalIncome - ($totalCost - $totalReMoney);
// 返回汇总数据
$data = [
@ -1339,7 +1339,7 @@ class Statistics extends Base
$totalFhMoney = floatval($fhMoneyQuery->sum('goodslist_money'));
// 计算总利润
$totalProfit = $totalIncome - $totalCost;
$totalProfit = $totalIncome - ($totalCost - $totalReMoney);
// 返回汇总数据
return [

View File

@ -87,10 +87,10 @@
<div class="layui-card-header">
总利润
<i class="layui-icon layui-icon-about" style="font-size: 14px; color: #5FB878;"
title="利润 = 收入 - 出货价值"></i>
title="利润 = 收入 - (出货价值 - 兑换成本)"></i>
</div>
<div class="layui-card-body" style="font-size: 24px;">
¥ <span id="totalProfit" class="profit-value">0.00</span>
¥ <span id="totalProfit" class="profit-value profit-detail">0.00</span>
</div>
</div>
</div>
@ -299,12 +299,14 @@
}
},
{
field: 'profit', title: '利润 <i class="layui-icon layui-icon-about" title="收入-出货价值"></i>', 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>';
// 构建详细计算公式展示
var detailCalc = d.use_money.toFixed(2) + ' - (' + d.sc_money.toFixed(2) + ' - ' + d.re_money.toFixed(2) + ') = ' + d.profit.toFixed(2);
return '<div><span class="layui-badge ' + colorClass + ' profit-detail" data-calculation="' + detailCalc + '">¥ ' + d.profit.toFixed(2) + '</span></div>';
}
},
{
@ -440,7 +442,7 @@
tr.find('td[data-field="single_box_profit_rate"] div').html('<span class="layui-badge ' + singleBoxColorClass + '">' + singleBoxProfitRate.toFixed(2) + '%</span>');
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>');
tr.find('td[data-field="profit"] div').html('<span class="layui-badge ' + profitColorClass + ' profit-detail" data-calculation="' + data.use_money.toFixed(2) + ' - (' + data.sc_money.toFixed(2) + ' - ' + data.re_money.toFixed(2) + ') = ' + data.profit.toFixed(2) + '">¥ ' + 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>');
@ -469,6 +471,10 @@
$('#totalReMoney').text(summary.totalReMoney.toFixed(2));
$('#totalFhMoney').text(summary.totalFhMoney.toFixed(2));
// 设置总利润的计算详情
var calcDetail = summary.totalIncome.toFixed(2) + ' - (' + summary.totalCost.toFixed(2) + ' - ' + summary.totalReMoney.toFixed(2) + ') = ' + summary.totalProfit.toFixed(2);
$('#totalProfit').attr('data-calculation', calcDetail);
// 设置利润颜色
var profitElem = $('#totalProfit');
if (summary.totalProfit >= 0) {
@ -577,6 +583,18 @@
time: 4000
});
});
// 为利润详情添加鼠标悬停事件(使用事件委托,处理动态加载的元素)
$(document).on('mouseenter', '.profit-detail', function () {
var that = this;
var calculation = $(that).data('calculation');
if (calculation) {
layer.tips(calculation, that, {
tips: [1, '#FF5722'],
time: 4000
});
}
});
}
});
</script>

View File

@ -42,15 +42,15 @@ class GoodsExtend extends Base
*/
public static function getGoodsExtendByGoodsId($goodsId, $goods_type)
{
// 生成缓存键
$redis = (new \app\common\server\RedisHelper())->getRedis();
$cache_key = "goods_extend:{$goodsId}:{$goods_type}";
// // 生成缓存键
// $redis = (new \app\common\server\RedisHelper())->getRedis();
// $cache_key = "goods_extend:{$goodsId}:{$goods_type}";
// 尝试从缓存获取数据
$cached_data = $redis->get($cache_key);
if ($cached_data) {
return json_decode($cached_data, true);
}
// // 尝试从缓存获取数据
// $cached_data = $redis->get($cache_key);
// if ($cached_data) {
// return json_decode($cached_data, true);
// }
$goods_extend = self::where('goods_id', $goodsId)->find();
if (!$goods_extend) {
@ -74,10 +74,10 @@ class GoodsExtend extends Base
}
}
// 将数据存入缓存设置5分钟过期时间
if ($goods_extend) {
$redis->set($cache_key, json_encode($goods_extend), 300);
}
// // 将数据存入缓存设置5分钟过期时间
// if ($goods_extend) {
// $redis->set($cache_key, json_encode($goods_extend), 300);
// }
return $goods_extend;
}