From f5667baa6e194f060763d41b3ea34e5668de52ad Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Fri, 7 Feb 2025 15:09:03 +0800 Subject: [PATCH] feat:depot_sale --- app/Controller/Admin/DepotController.php | 26 +++++++ app/Model/DepotSale.php | 45 ++++++++++++ app/Request/Admin/DepotRequest.php | 2 + app/Service/Admin/Depot/DepotService.php | 88 ++++++++++++++++++++++++ 4 files changed, 161 insertions(+) create mode 100644 app/Model/DepotSale.php diff --git a/app/Controller/Admin/DepotController.php b/app/Controller/Admin/DepotController.php index 5eb5366..370cc9d 100644 --- a/app/Controller/Admin/DepotController.php +++ b/app/Controller/Admin/DepotController.php @@ -117,4 +117,30 @@ class DepotController { return (new DepotService)->purchaseList(); } + + /** + * 销售出库 + * @param DepotRequest $request + * @return array + * @throws Exception + */ + #[RequestMapping(path: "depot_sale", methods: "POST")] + #[Scene(scene: "depot_sale")] + public function depotSale(DepotRequest $request): array + { + return (new DepotService)->depotSale(); + } + + /** + * 销售出库数量修改 + * @param DepotRequest $request + * @return array + * @throws Exception + */ + #[RequestMapping(path: "depot_sale_update", methods: "POST")] + #[Scene(scene: "sale_update")] + public function saleUpdate(DepotRequest $request): array + { + return (new DepotService)->saleUpdate(); + } } diff --git a/app/Model/DepotSale.php b/app/Model/DepotSale.php new file mode 100644 index 0000000..fbd5671 --- /dev/null +++ b/app/Model/DepotSale.php @@ -0,0 +1,45 @@ + 'integer', 'depot_id' => 'integer', 'material_id' => 'integer', 'dish_id' => 'integer', 'application_id' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'operator_id' => 'integer', 'is_del' => 'integer']; + + const string CREATED_AT = 'create_time'; + + const string UPDATED_AT = 'update_time'; +} diff --git a/app/Request/Admin/DepotRequest.php b/app/Request/Admin/DepotRequest.php index ea3ddb0..336e14e 100644 --- a/app/Request/Admin/DepotRequest.php +++ b/app/Request/Admin/DepotRequest.php @@ -43,5 +43,7 @@ class DepotRequest extends FormRequest 'purchase_update' => ['id','number'], 'purchase_back' => ['id'], 'purchase_list' => ['limit','query_id','query_kitchen_id','type'], + 'sale' => ['depot_id','material_id','dish_id','number','application_id','city_id','kitchen_id'], + 'sale_update' => ['id','number'], ]; } diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index dd9a32d..73a6af2 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -5,10 +5,13 @@ declare(strict_types=1); namespace App\Service\Admin\Depot; use App\Constants\Admin\DepotCode; +use App\Constants\Common\MaterialCode; use App\Exception\ErrException; use App\Model\Depot; use App\Model\DepotPurchase; +use App\Model\DepotSale; use App\Model\Material; +use App\Model\MaterialApplication; use App\Model\MaterialStock; use App\Model\Supplier; use App\Service\Admin\BaseService; @@ -34,6 +37,12 @@ class DepotService extends BaseService{ #[Inject] protected DepotPurchase $DepotPurchaseModel; + #[Inject] + protected DepotSale $DepotSaleModel; + + #[inject] + protected MaterialApplication $MaterialApplicationModel; + public function handle() { @@ -287,4 +296,83 @@ class DepotService extends BaseService{ return $this->return->success('success',$list); } + public function depotSale():array + { + $depotId = (int)$this->request->input('depot_id'); + $materialId = (int)$this->request->input('material_id'); + $supplierId = (int)$this->request->input('supplier_id'); + $number = (double)$this->request->input('number'); + $applicationId = (int)$this->request->input('application_id'); + $cityId = (int)$this->request->input('city_id'); + $kitchenId = (int)$this->request->input('kitchen_id'); + + $applicationInfo = $this->MaterialApplicationModel + ->where('application_id',$applicationId) + ->first(); + + $materialStock = $this->MaterialStockModel + ->where('depot_id',$depotId) + ->where('material_id',$materialId) + ->where('supplier_id',$supplierId) + ->first(); + + $depotSale = new DepotSale(); + $depotSale->depot_id = $depotId; + $depotSale->dish_id = $applicationInfo->dish_id; + $depotSale->material_id = $materialId; + $depotSale->sale_price = $materialStock->unit_price; + $depotSale->number = $number; + $depotSale->sum_price = $depotSale->sale_price * $number; + $depotSale->city_id = $cityId; + $depotSale->kitchen_id = $kitchenId; + $depotSale->operator_id = $this->adminId; + + //库存减少 + $materialStock->current_stock = $materialStock->current_stock - $number; + +// $numberList = $this->DepotSaleModel +// ->where('application_id',$applicationId) +// ->where('is_del',DepotCode::IS_NO_DEL) + + + if ($number < $applicationInfo->num) + $applicationInfo->status = MaterialCode::PART_OUT; + else if ($number > $applicationInfo->num) + + if (!$depotSale->save() || !$materialStock->save()) throw new ErrException('商品出库异常'); + + return $this->return->success(); + + } + + public function saleUpdate():array + { + $id = (int)$this->request->input('id'); + $info = $this->DepotSaleModel + ->where('id',$id) + ->first(); + + $old_number = $info->number; + + $number = (double)$this->request->input('number'); + $sum_price = $info->purchase_price * $number; + + $info->number = $number; + $info->sum_price = $sum_price; + + $materialStock = $this->MaterialStockModel + ->where('depot_id',$info->depot_id) + ->where('material_id',$info->material_id) + ->where('supplier_id',$info->supplier_id) + ->first(); + + $materialStock->current_stock = $materialStock->current_stock + $old_number - $number; + + if (!$info->save() || !$materialStock->save()) throw new ErrException('商品出库数量修改失败'); + + return $this->return->success(); + } + + + } \ No newline at end of file