dataview 订单排行

This commit is contained in:
chenbo 2023-12-02 13:53:21 +08:00
parent 2542a96919
commit de459e01d2

View File

@ -126,14 +126,16 @@ class Order extends BaseController
$type = $this->request->get('type',2); // 1今日 2总计 $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(); // 镇/街道列表 $townList = Db::name('geo_street')->field('street_code,street_name')->where('area_code', $this->areaCode)->select()->toArray(); // 镇/街道列表
$orderCount = 0;
foreach ($townList as &$town) { foreach ($townList as &$town) {
// 查询订单数 // 查询订单数
$orderCountQuery = Db::name('product_order_log')->where('street_code', $town['street_code'])->where('status', 1); $orderCountQuery = Db::name('product_order_log')->where('street_code', $town['street_code'])->where('status', 1);
if ($type == 1) { if ($type == 1) {
$orderCountQuery->whereDay('create_time', 'today'); $orderCountQuery->whereDay('create_time', 'today');
} }
$orderCount = $orderCountQuery->count(); $tempOrderCount = $orderCountQuery->count();
$town['order_count'] = $orderCount; $town['order_count'] = $tempOrderCount;
$orderCount += $tempOrderCount;
} }
unset($town); unset($town);
// $orderRankingQuery = Db::name('product_order_log')->alias('op') // $orderRankingQuery = Db::name('product_order_log')->alias('op')
@ -149,6 +151,6 @@ class Order extends BaseController
$orderCountArr = array_column($townList, 'order_count'); $orderCountArr = array_column($townList, 'order_count');
array_multisort($orderCountArr, SORT_DESC, $townList); array_multisort($orderCountArr, SORT_DESC, $townList);
return app('json')->success($townList); return app('json')->success(compact('orderCount', 'townList'));
} }
} }