统计图表修改逻辑

This commit is contained in:
liu 2024-06-25 18:16:52 +08:00
parent b7218e96e6
commit 5433c2fbde

View File

@ -101,6 +101,7 @@ class WorkbenchLogic extends BaseLogic
$i++;
}
$field = 'from_unixtime(pay_time,"%H") as pay_time,sum(pay_price) as pay_price';
$recharge_field = 'from_unixtime(pay_time,"%H") as pay_time,sum(price) as pay_price';
} elseif ($dateDiff->days <= 31) {
$group = 'DAY(pay_time)';
$i = 0;
@ -109,6 +110,7 @@ class WorkbenchLogic extends BaseLogic
$i++;
}
$field = 'from_unixtime(pay_time,"%m-%d") as pay_time,sum(pay_price) as pay_price';
$recharge_field = 'from_unixtime(pay_time,"%m-%d") as pay_time,sum(price) as pay_price';
} else {
$group = 'MONTH(pay_time)';
$i = 0;
@ -127,7 +129,27 @@ class WorkbenchLogic extends BaseLogic
$i++;
}
$field = 'from_unixtime(pay_time,"%Y-%m") as pay_time,sum(pay_price) as pay_price';
$recharge_field = 'from_unixtime(pay_time,"%Y-%m") as pay_time,sum(price) as pay_price';
}
$data['order_list'] = StoreOrder::with('user')->where($where)
->whereBetweenTime('pay_time', $startTime, $endTime)
->order('pay_time', 'desc')
->limit(6)
->select()->each(function($item){
$item->pay_time=$item->pay_time>0?date('Y-m-d H:i:s',$item->pay_time):'';
})
->toArray();
//取消单个店铺搜索
unset($where['store_id']);
$rechargeList = UserRecharge::field($recharge_field)
->where(['paid'=>1])
->whereBetweenTime('pay_time', $startTime, $endTime)
->group($group)
->select()
->toArray();
$orderList = StoreOrder::field($field)
->where($where)
->whereBetweenTime('pay_time', $startTime, $endTime)
@ -145,6 +167,7 @@ class WorkbenchLogic extends BaseLogic
$orderListTmp = [];
$userListTmp = [];
$range = [];
$mergedListTmp = [];
foreach ($timeRange as $item) {
$range[] = $item;
if (!isset($orderList[$item])) {
@ -157,22 +180,29 @@ class WorkbenchLogic extends BaseLogic
} else {
$userListTmp[$item] = $userList[$item]['user_num'];
}
// 处理 $rechargeList 和 $orderList 的相加
$mergedListTmp[$item] = 0;
foreach ($rechargeList as $recharge) {
if ($recharge['pay_time'] == $item) {
$mergedListTmp[$item] += $recharge['pay_price'];
}
}
foreach ($orderList as $order) {
if ($order['pay_time'] == $item) {
$mergedListTmp[$item] += $order['pay_price'];
}
}
}
$data['statistics'] = [
'range' => $range,
'data' => [
'order_amount' => array_values($orderListTmp),
'user_number' => array_values($userListTmp)
// 'order_amount' => array_values($orderListTmp),
'user_number' => array_values($userListTmp),
'order_amount' => array_values($mergedListTmp)
]
];
$data['order_list'] = StoreOrder::with('user')->where($where)
->whereBetweenTime('pay_time', $startTime, $endTime)
->order('pay_time', 'desc')
->limit(6)
->select()->each(function($item){
$item->pay_time=$item->pay_time>0?date('Y-m-d H:i:s',$item->pay_time):'';
})
->toArray();
$data['pay_type'] = [
['name' => '线上收银订单', 'value' => bcsub($data['order_amount'], bcadd($data['verify_amount'], $data['cash_amount'], 2), 2)],
['name' => '核销订单', 'value' => $data['verify_amount']],