修改交易统计

This commit is contained in:
luofei 2024-06-07 17:55:40 +08:00
parent d238d6b238
commit 695a47e8c5

View File

@ -77,12 +77,43 @@ class WorkbenchLogic extends BaseLogic
$timeRange = [1, (int)date('n')];
$field = 'from_unixtime(pay_time,"%Y-%m") as pay_time,sum(pay_price) as pay_price';
}
$data['order_list'] = StoreOrder::field($field)
$orderList = StoreOrder::field($field)
->where('store_id', $params['store_id'])
->where('paid', 1)
->whereBetweenTime('pay_time', $startTime, $endTime)
->group($group)
->select();
->select()
->toArray();
$userList = StoreOrder::field($field . ',count(uid) as user_num')
->where('store_id', $params['store_id'])
->where('paid', 1)
->whereBetweenTime('pay_time', $startTime, $endTime)
->group($group . ',uid')
->select()
->toArray();
$orderList = reset_index($orderList, 'pay_time');
$userList = reset_index($userList, 'pay_time');
$orderListTmp = [];
$userListTmp = [];
for ($i = $timeRange[0]; $i <= $timeRange[1]; $i++) {
if (!isset($orderList[$i])) {
$orderListTmp[$i] = ['pay_time' => $i, 'pay_price' => 0];
} else {
$orderListTmp[$i] = ['pay_time' => $i, 'pay_price' => $orderList[$i]['pay_price']];
}
if (!isset($userList[$i])) {
$userListTmp[$i] = ['pay_time' => $i, 'user_num' => 0];
} else {
$userListTmp[$i] = ['pay_time' => $i, 'user_num' => $userList[$i]['user_num']];
}
}
$data['statistics'] = [
'range' => array_column($orderListTmp, 'pay_time'),
'data' => [
array_values($orderListTmp),
array_values($userListTmp)
]
];
return $data;
}