diff --git a/app/Controller/Admin/DepotController.php b/app/Controller/Admin/DepotController.php index 2027e08..d11d654 100644 --- a/app/Controller/Admin/DepotController.php +++ b/app/Controller/Admin/DepotController.php @@ -181,6 +181,18 @@ class DepotController return (new DepotService)->saleList(); } + /** + * 统计销售额 + * @param DepotRequest $request + * @return array + */ + #[RequestMapping(path: "sale_statistics", methods: "GET")] + #[Scene(scene: "sale_statistics")] + public function saleStatistics(DepotRequest $request): array + { + return (new DepotService)->saleStatistics(); + } + /** * 回收 * @param DepotRequest $request diff --git a/app/Request/Admin/DepotRequest.php b/app/Request/Admin/DepotRequest.php index d66caab..e42ed58 100644 --- a/app/Request/Admin/DepotRequest.php +++ b/app/Request/Admin/DepotRequest.php @@ -54,6 +54,7 @@ class DepotRequest extends FormRequest 'sale_update' => ['id','number'], 'sale_delete' => ['id'], 'sale_list' => ['limit','query_id','query_kitchen_id'], + 'sale_statistics' => ['city_id'], 'recycle' =>['material_id','supplier_id','number','sale_id','city_id','kitchen_id'], 'recycle_update' => ['id','number'], 'recycle_delete' => ['id'], diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index c6a9f9f..a8722a3 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -307,7 +307,7 @@ class DepotService extends BaseService{ $todayPurchase = $this->DepotPurchaseModel ->where('is_del',DepotCode::IS_NO_DEL) ->where('type',1) - ->where('status',1) + ->where('status',DepotCode::INPUT) ->where('city_id',$cityId) ->whereBetween('create_time',[$todayStartDate,$todayEndDate]) ->sum('sum_price'); @@ -318,7 +318,7 @@ class DepotService extends BaseService{ $yesterdayPurchase = $this->DepotPurchaseModel ->where('is_del',DepotCode::IS_NO_DEL) ->where('type',1) - ->where('status',1) + ->where('status',DepotCode::INPUT) ->where('city_id',$cityId) ->whereBetween('create_time',[$yesterdayStartDate,$yesterdayEndDate]) ->sum('sum_price'); @@ -328,7 +328,7 @@ class DepotService extends BaseService{ $monthPurchase = $this->DepotPurchaseModel ->where('is_del',DepotCode::IS_NO_DEL) ->where('type',1) - ->where('status',1) + ->where('status',DepotCode::INPUT) ->where('city_id',$cityId) ->whereBetween('create_time',[$currentMonthStartDate,$todayEndDate]) ->sum('sum_price'); @@ -338,7 +338,7 @@ class DepotService extends BaseService{ $yearPurchase = $this->DepotPurchaseModel ->where('is_del',DepotCode::IS_NO_DEL) ->where('type',1) - ->where('status',1) + ->where('status',DepotCode::INPUT) ->where('city_id',$cityId) ->whereBetween('create_time',[$currentYearStartDate,$todayEndDate]) ->sum('sum_price'); @@ -501,6 +501,48 @@ class DepotService extends BaseService{ return $this->return->success('success',$list); } + public function saleStatistics():array + { + $cityId = (int)$this->request->input('city_id'); + + //今日销售额 + $todayStartDate = DateUtil::getTodayStartDate(); + $todayEndDate = DateUtil::getTodayEndDate(); + $todaySale = $this->DepotSaleModel + ->where('is_del',DepotCode::IS_NO_DEL) + ->where('city_id',$cityId) + ->whereBetween('create_time',[$todayStartDate,$todayEndDate]) + ->sum('sum_price'); + + //昨天销售额 + $yesterdayStartDate = DateUtil::getStartDate(); + $yesterdayEndDate = DateUtil::getEndDate(); + $yesterdaySale = $this->DepotPurchaseModel + ->where('is_del',DepotCode::IS_NO_DEL) + ->where('city_id',$cityId) + ->whereBetween('create_time',[$yesterdayStartDate,$yesterdayEndDate]) + ->sum('sum_price'); + + //本月销售额 + $currentMonthStartDate = date("Y-m-01 00:00:00"); + $monthSale = $this->DepotSaleModel + ->where('is_del',DepotCode::IS_NO_DEL) + ->where('city_id',$cityId) + ->whereBetween('create_time',[$currentMonthStartDate,$todayEndDate]) + ->sum('sum_price'); + + //今年销售额 + $currentYearStartDate = date("Y-01-01 00:00:00"); + $yearSale = $this->DepotSaleModel + ->where('is_del',DepotCode::IS_NO_DEL) + ->where('city_id',$cityId) + ->whereBetween('create_time',[$currentYearStartDate,$todayEndDate]) + ->sum('sum_price'); + + return $this->return->success('success',["todaySale"=>$todaySale,"yesterdaySale"=>$yesterdaySale, + "monthSale"=>$monthSale,"yearSale"=>$yearSale]); + } + public function recycle():array { $materialId = (int)$this->request->input('material_id');