dataview 订单排行

This commit is contained in:
chenbo 2023-12-02 13:57:38 +08:00
parent 285c3d5bcd
commit f9553c87ac

View File

@ -127,7 +127,8 @@ class Order extends BaseController
$type = $this->request->get('type',2); // 1今日 2总计
$townList = Db::name('geo_street')->field('street_code,street_name')->where('area_code', $this->areaCode)->select()->toArray(); // 镇/街道列表
$orderCount = 0;
foreach ($townList as &$town) {
$townOrderList = [];
foreach ($townList as $town) {
// 查询订单数
$orderCountQuery = Db::name('product_order_log')->where('street_code', $town['street_code'])->where('status', 1);
if ($type == 1) {
@ -136,8 +137,8 @@ class Order extends BaseController
$tempOrderCount = $orderCountQuery->count();
$town['order_count'] = $tempOrderCount;
$orderCount += $tempOrderCount;
$townOrderList[] = $town;
}
unset($town);
// $orderRankingQuery = Db::name('product_order_log')->alias('op')
// ->leftJoin('geo_street s','op.street_code = s.street_code')
// ->field('op.street_code,COUNT(op.order_id) AS order_count,s.street_name')
@ -149,8 +150,8 @@ class Order extends BaseController
// }
// $orderRankingList = $orderRankingQuery->group('op.street_code')->order('order_count desc')->select();
$orderCountArr = array_column($townList, 'order_count');
array_multisort($orderCountArr, SORT_DESC, $townList);
return app('json')->success(compact('orderCount', 'townList'));
$orderCountArr = array_column($townOrderList, 'order_count');
array_multisort($orderCountArr, SORT_DESC, $townOrderList);
return app('json')->success(compact('orderCount', 'townOrderList'));
}
}