From ba3dbdb202989a52eb5f2ae9606305259fc0d639 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Tue, 18 Feb 2025 15:48:31 +0800 Subject: [PATCH] feat:depot_purchase --- app/Controller/Admin/DepotController.php | 12 ++++++ app/Request/Admin/DepotRequest.php | 3 +- app/Service/Admin/Depot/DepotService.php | 51 ++++++++++++++++++++++++ sync/http/admin/auth.http | 5 +++ 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/app/Controller/Admin/DepotController.php b/app/Controller/Admin/DepotController.php index 6aaddb3..2027e08 100644 --- a/app/Controller/Admin/DepotController.php +++ b/app/Controller/Admin/DepotController.php @@ -118,6 +118,18 @@ class DepotController return (new DepotService)->purchaseList(); } + /** + * 统计采购额 + * @param DepotRequest $request + * @return array + */ + #[RequestMapping(path: "purchase_statistics", methods: "GET")] + #[Scene(scene: "purchase_statistics")] + public function purchaseStatistics(DepotRequest $request): array + { + return (new DepotService)->purchaseStatistics(); + } + /** * 销售出库 * @param DepotRequest $request diff --git a/app/Request/Admin/DepotRequest.php b/app/Request/Admin/DepotRequest.php index f4efc51..d66caab 100644 --- a/app/Request/Admin/DepotRequest.php +++ b/app/Request/Admin/DepotRequest.php @@ -24,7 +24,7 @@ class DepotRequest extends FormRequest return [ 'limit' => 'required|integer', 'query_id' => 'sometimes|integer', - 'query_kitchen_id' => 'sometimes|integer', + 'query_kitchen_id' => 'sometimes|integer|exists:kitchen,id', 'name' => 'required|string', 'city_id' => 'required|integer|exists:system_city,id', 'kitchen_id' => 'required|integer|exists:kitchen,id', @@ -49,6 +49,7 @@ class DepotRequest extends FormRequest 'purchase_update' => ['id','number'], 'purchase_back' => ['id'], 'purchase_list' => ['limit','query_id','query_kitchen_id','type'], + 'purchase_statistics' => ['city_id'], 'sale' => ['depot_id','material_id','supplier_id','number','application_id','city_id','kitchen_id'], 'sale_update' => ['id','number'], 'sale_delete' => ['id'], diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index 19f75cd..0f0daae 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -8,6 +8,7 @@ use App\Constants\Admin\DepotCode; use App\Constants\Common\MaterialCode; use App\Constants\Common\RoleCode; use App\Exception\ErrException; +use App\Extend\DateUtil; use App\Model\Depot; use App\Model\DepotPurchase; use App\Model\DepotRecycle; @@ -306,6 +307,56 @@ class DepotService extends BaseService{ return $this->return->success('success',$list); } + public function purchaseStatistics():array + { + $cityId = (int)$this->request->input('city_id'); + + //今日采购额 + $todayStartDate = DateUtil::getTodayStartDate(); + $todayEndDate = DateUtil::getTodayEndDate(); + $todayPurchase = $this->DepotPurchaseModel + ->where('is_del',DepotCode::IS_NO_DEL) + ->where('type',1) + ->where('status',1) + ->where('city_id',$cityId) + ->whereBetween('create_time',[$todayStartDate,$todayEndDate]) + ->sum('sum_price'); + + //昨天采购额 + $yesterdayStartDate = DateUtil::getStartDate(); + $yesterdayEndDate = DateUtil::getEndDate(); + $yesterdayPurchase = $this->DepotPurchaseModel + ->where('is_del',DepotCode::IS_NO_DEL) + ->where('type',1) + ->where('status',1) + ->where('city_id',$cityId) + ->whereBetween('create_time',[$yesterdayStartDate,$yesterdayEndDate]) + ->sum('sum_price'); + + //本月采购额 + $currentMonthStartDate = date("Y-m-01 00:00:00"); + $monthPurchase = $this->DepotPurchaseModel + ->where('is_del',DepotCode::IS_NO_DEL) + ->where('type',1) + ->where('status',1) + ->where('city_id',$cityId) + ->whereBetween('create_time',[$currentMonthStartDate,$todayEndDate]) + ->sum('sum_price'); + + //今年采购额 + $currentYearStartDate = date("Y-01-01 00:00:00"); + $yearPurchase = $this->DepotPurchaseModel + ->where('is_del',DepotCode::IS_NO_DEL) + ->where('type',1) + ->where('status',1) + ->where('city_id',$cityId) + ->whereBetween('create_time',[$currentYearStartDate,$todayEndDate]) + ->sum('sum_price'); + + return $this->return->success('success',["todayPurchase"=>$todayPurchase,"yesterdayPurchase"=>$yesterdayPurchase, + "monthPurchase"=>$monthPurchase,"yearPurchase"=>$yearPurchase]); + } + public function depotSale():array { $depotId = (int)$this->request->input('depot_id'); diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 521feec..5db909a 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -394,6 +394,11 @@ POST {{host}}/admin/depot/depot_purchase_back?id=1 Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{admin_token}} +### 采购统计 +GET {{host}}/admin/depot/purchase_statistics?city_id=1 +content-type: application/json +Authorization: Bearer {{admin_token}} + ### 排菜列表 GET {{host}}/admin/dish/list?limit=10 content-type: application/json