add 数据之眼-订单统计信息

This commit is contained in:
chenbo 2023-12-06 10:08:21 +08:00
parent 9c4ddb7b99
commit 256e93b4ab
3 changed files with 41 additions and 1 deletions

View File

@ -339,4 +339,41 @@ class Order extends BaseController
$doneOrderCount = $doneOrderCountQuery->count();
return compact('hourOrderCount', 'pendingOrderCount', 'undeliveredOrderCount', 'doneOrderCount');
}
// 订单数据统计
public function orderStatistics()
{
$list = [];
// 该地区下所有乡镇
$geoStreetList = Db::name('geo_street')->field('street_name, street_code')->where('area_code',$this->areaCode)->select()->toArray();
foreach ($geoStreetList as $k=>$street) {
$dayOrderquery = Db::name('store_order')->alias('o')
->field(['o.order_sn', 'o.real_name', 'o.user_phone', 'o.user_address', 'o.user_address_code', 'p.store_name', 'm.mer_name', 'o.create_time', 'o.status'])
->leftJoin('product_order_log og', 'o.order_id = og.order_id')
->where('o.paid', 1)
->whereNotNull('o.pay_time')
->whereDay('o.create_time', 'today')
->where('og.street_code', $street['street_code']);
$monthOrderquery = Db::name('store_order')->alias('o')
->field(['o.order_sn', 'o.real_name', 'o.user_phone', 'o.user_address', 'o.user_address_code', 'p.store_name', 'm.mer_name', 'o.create_time', 'o.status'])
->leftJoin('product_order_log og', 'o.order_id = og.order_id')
->where('o.paid', 1)
->whereNotNull('o.pay_time')
->whereMonth('o.create_time', 'this month')
->where('og.street_code', $street['street_code']);
// 日订单数
$street['dayOrderCount'] = $dayOrderquery->count();
// 日订单金额
$street['dayOrderAmount'] = $dayOrderquery->sum('o.total_price');
// 月订单数
$street['monthOrderCount'] = $monthOrderquery->count();
// 月订单金额
$street['monthOrderAmount'] = $monthOrderquery->sum('o.total_price');
$list[$k] = $street;
}
unset($street);
return \app('json')->success(compact('list'));
}
}

View File

@ -62,13 +62,15 @@ class User extends BaseController
$geoStreetList = Db::name('geo_street')->where('area_code',$this->areaCode)->select()->toArray();
// 遍历统计每个乡镇的店铺数
$merchantTotalCount = 0;
foreach ($geoStreetList as $street) {
$temp['street_name'] = $street['street_name'];
$temp['merchant_count'] = Db::name('merchant')->where('street_id', $street['street_code'])->count();
$merchantTotalCount += $temp['merchant_count'];
$merchatCountList[] = $temp;
unset($temp);
}
return app('json')->success(compact('userCountlist', 'merchatCountList'));
return app('json')->success(compact('merchantTotalCount' ,'userCountlist', 'merchatCountList'));
}
public function getTimeRangeUserCount($timeRange=[])
{

View File

@ -732,6 +732,7 @@ Route::group('api/', function () {
/**---------------------数据之眼可视化大屏api------------------- start */
Route::get('user_merchat_count', 'User/userMerchantCount');
Route::get('order_statistics', 'Order/orderStatistics');
/**---------------------数据之眼可视化大屏api-------------------- end */