From 695a47e8c511611fbad447db72b47eb95200abb9 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Fri, 7 Jun 2024 17:55:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=A4=E6=98=93=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/store/logic/WorkbenchLogic.php | 35 ++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/app/store/logic/WorkbenchLogic.php b/app/store/logic/WorkbenchLogic.php index aa879310c..a843a1852 100644 --- a/app/store/logic/WorkbenchLogic.php +++ b/app/store/logic/WorkbenchLogic.php @@ -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; }