From 6b38a6b73201b54096582280129f897fbdb79b12 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Tue, 14 Jan 2025 17:04:48 +0800 Subject: [PATCH 01/54] feat:dish depot --- app/Constants/Admin/DepotCode.php | 17 ++++ app/Constants/Common/DishCode.php | 13 +++ app/Controller/Admin/DepotController.php | 69 ++++++++++++++ app/Controller/Admin/DishController.php | 33 +++++++ app/Model/Depot.php | 59 ++++++++++++ app/Model/Dish.php | 46 +++++++++ app/Request/Admin/DepotRequest.php | 41 ++++++++ app/Request/Admin/DishRequest.php | 39 ++++++++ app/Service/Admin/Depot/DepotService.php | 114 +++++++++++++++++++++++ app/Service/Admin/Good/DishService.php | 64 +++++++++++++ sync/http/admin/auth.http | 28 ++++++ 11 files changed, 523 insertions(+) create mode 100644 app/Constants/Admin/DepotCode.php create mode 100644 app/Constants/Common/DishCode.php create mode 100644 app/Controller/Admin/DepotController.php create mode 100644 app/Controller/Admin/DishController.php create mode 100644 app/Model/Depot.php create mode 100644 app/Model/Dish.php create mode 100644 app/Request/Admin/DepotRequest.php create mode 100644 app/Request/Admin/DishRequest.php create mode 100644 app/Service/Admin/Depot/DepotService.php create mode 100644 app/Service/Admin/Good/DishService.php diff --git a/app/Constants/Admin/DepotCode.php b/app/Constants/Admin/DepotCode.php new file mode 100644 index 0000000..e986136 --- /dev/null +++ b/app/Constants/Admin/DepotCode.php @@ -0,0 +1,17 @@ +depotList(); + } + + /** + * 添加仓库 + * @param DepotRequest $request + * @return array + * @throws Exception + */ + #[RequestMapping(path: "depot_add", methods: "POST")] + #[Scene(scene: "depot_add")] + public function add(DepotRequest $request): array + { + return (new DepotService)->add(); + } + + /** + * 修改仓库 + * @return array + */ + #[RequestMapping(path: "depot_edit", methods: "POST")] + #[Scene(scene: "depot_edit")] + public function edit(DepotRequest $request): array + { + return (new DepotService)->edit(); + } + + /** + * 删除仓库 + * @return array + */ + #[RequestMapping(path: "depot_delete", methods: "GET")] + #[Scene(scene: "depot_delete")] + public function delete(DepotRequest $request): array + { + return (new DepotService)->delete(); + } +} diff --git a/app/Controller/Admin/DishController.php b/app/Controller/Admin/DishController.php new file mode 100644 index 0000000..7dca1ca --- /dev/null +++ b/app/Controller/Admin/DishController.php @@ -0,0 +1,33 @@ +dishList(); + } + + +} diff --git a/app/Model/Depot.php b/app/Model/Depot.php new file mode 100644 index 0000000..54af478 --- /dev/null +++ b/app/Model/Depot.php @@ -0,0 +1,59 @@ + 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'is_del' => 'integer']; + + const CREATED_AT = 'create_time'; + + const UPDATED_AT = 'update_time'; + + /** + * @param int $id + * @return \Hyperf\Database\Model\Model|Builder|null + */ + public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null + { + return $this->where('id',$id)->where('is_del',DepotCode::IS_NO_DEL)->first(); + } + + /** + * @param string $name + * @param int $kitchen_id + * @return \Hyperf\Database\Model\Model|Builder|null + */ + public function getInfoByName(string $name,int $kitchen_id): \Hyperf\Database\Model\Model|Builder|null + { + return $this->where('name', $name)->where('kitchen_id',$kitchen_id)->where('is_del',DepotCode::IS_NO_DEL)->first(); + } +} diff --git a/app/Model/Dish.php b/app/Model/Dish.php new file mode 100644 index 0000000..4cb19d5 --- /dev/null +++ b/app/Model/Dish.php @@ -0,0 +1,46 @@ + 'integer', 'pre_quantity' => 'integer', 'cycle_id' => 'integer', 'status' => 'integer', 'city_id' => 'integer','kitchen_id' => 'integer', 'chef_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 new file mode 100644 index 0000000..2561503 --- /dev/null +++ b/app/Request/Admin/DepotRequest.php @@ -0,0 +1,41 @@ + 'required|integer', + 'query_id' => 'sometimes|integer', + 'query_kitchen_id' => 'sometimes|integer', + 'name' => 'required|string', + 'city_id' => 'required|integer|exists:system_city,id', + 'kitchen_id' => 'required|integer|exists:kitchen,id', + 'id' => 'required|integer', + ]; + } + + protected array $scenes = [ + 'depot_list' => ['limit','query_id','query_kitchen_id'], + 'depot_add' => ['name','city_id','kitchen_id'], + 'depot_edit' => ['id','name','city_id','kitchen_id'], + 'depot_delete' => ['id'], + ]; +} diff --git a/app/Request/Admin/DishRequest.php b/app/Request/Admin/DishRequest.php new file mode 100644 index 0000000..6d6e918 --- /dev/null +++ b/app/Request/Admin/DishRequest.php @@ -0,0 +1,39 @@ + 'required|integer', + 'query_id' => 'sometimes|integer', + 'query_dish_name' => 'sometimes|string', + 'query_city_id' => 'sometimes|integer|exists:system_city,id', + 'query_date_id' => 'sometimes|integer|exists:cycle,id', + 'query_status' => 'sometimes|integer', + 'query_chef_id' => 'sometimes|integer', + + ]; + } + + protected array $scenes = [ + 'list' => ['limit','query_id','query_dish_name','query_city_id','query_date_id','query_status','query_chef_id'], + ]; +} diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php new file mode 100644 index 0000000..533e924 --- /dev/null +++ b/app/Service/Admin/Depot/DepotService.php @@ -0,0 +1,114 @@ +request->input('limit', 10); + $id = (int)$this->request->input('query_id'); + $kitchenId = (int)$this->request->input('query_kitchen_id'); + + $list = $this->DepotModel + ->where('is_del',DepotCode::IS_NO_DEL) + ->when($id,function ($query) use ($id) { + $query->where('id',$id); + }) + ->when($kitchenId,function ($query) use ($kitchenId) { + $query->where('kitchen_id',$kitchenId); + }) + ->paginate($limit)->toArray(); + + return $this->return->success('success',$list); + + } + + /** + * @return array + */ + public function add():array + { + $name = $this->request->input('name'); + $kitchen_id = (int)$this->request->input('kitchen_id'); + $info = $this->DepotModel->getInfoByName($name,$kitchen_id); + if (!empty($info)) throw new ErrException('仓库已存在'); + + $depot = new Depot(); + $depot->name = $name; + $depot->city_id = $this->request->input('city_id'); + $depot->kitchen_id = $kitchen_id; + + if (!$depot->save()) throw new ErrException('仓库添加失败'); + + return $this->return->success(); + } + + /** + * @return array + */ + public function edit(): array + { + $id = (int)$this->request->input('id'); + $depotName = $this->request->input('name'); + $kitchen_id = (int)$this->request->input('kitchen_id'); + + $info = $this->DepotModel->getInfoById($id); + if (empty($info)) throw new ErrException('数据不存在'); + + $name = $this->DepotModel->getInfoByName($depotName,$kitchen_id); + if (!empty($name)){ + if ($name->id != $info->id && $info->kitchen_id == $kitchen_id) + throw new ErrException('仓库已存在'); + } + + $info->name = $depotName; + $info->city_id = (int)$this->request->input('city_id'); + $info->kitchen_id = $kitchen_id; + + if (!$info->save()) throw new ErrException('仓库修改失败'); + + return $this->return->success(); + } + + /** + * @return array + */ + public function delete(): array + { + $id = (int)$this->request->input('id'); + + $info = $this->DepotModel->getInfoById($id); + if (empty($info)) throw new ErrException('仓库不存在'); + + $info->is_del = DepotCode::IS_DEL; + + if (!$info->save()) throw new ErrException('删除失败'); + + return $this->return->success(); + } + + +} \ No newline at end of file diff --git a/app/Service/Admin/Good/DishService.php b/app/Service/Admin/Good/DishService.php new file mode 100644 index 0000000..cf6b9f4 --- /dev/null +++ b/app/Service/Admin/Good/DishService.php @@ -0,0 +1,64 @@ +request->input('limit', 10); + $id = (int)$this->request->input('query_id'); + $cityId = (int)$this->request->input('query_city_id',0); + $dishName = $this->request->input('query_dish_name'); + $dateId = (int)$this->request->input('query_date_id'); + $status = (int)$this->request->input('query_status'); + $chefId = (int)$this->request->input('query_chef_id',0); + + $list = $this->DishModel + ->where('is_del',DishCode::IS_NO_DEL) + ->when($id > 0, function ($query) use ($id) { + $query->where('id', $id); + }) + ->when($cityId > 0, function ($query) use ($cityId) { + $query->where('city_id', $cityId); + }) + ->when($dishName, function ($query) use ($dishName) { + $query->where('dish', 'like', "$dishName%"); + }) + ->when($dateId, function ($query) use ($dateId) { + $query->where('cycle_id', $dateId); + }) + ->when($status, function ($query) use ($status) { + $query->where('status', $status); + }) + ->when($chefId, function ($query) use ($chefId) { + $query->where('chef_id', $chefId); + }) + ->paginate($limit)->toArray(); + + return $this->return->success('success',$list); + } + +} \ No newline at end of file diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 4f3cf55..65c30c1 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -276,3 +276,31 @@ GET {{host}}/admin/member/list?limit=10 content-type: application/json Authorization: Bearer {{admin_token}} +### 排菜列表 +GET {{host}}/admin/dish/list?limit=10 +content-type: application/json +Authorization: Bearer {{admin_token}} + +### 仓库列表 +GET {{host}}/admin/depot/depot_list?limit=10 +content-type: application/json +Authorization: Bearer {{admin_token}} + +### 仓库添加 +POST {{host}}/admin/depot/depot_add +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +name=蔬菜仓库&city_id=1&kitchen_id=1 + +### 仓库修改信息 +POST {{host}}/admin/depot/depot_edit +content-type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +id=2&name=冻品仓库&city_id=1&kitchen_id=1 + +### 仓库删除 +GET {{host}}/admin/depot/depot_delete?id=2 +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} \ No newline at end of file From 9eebcd008fabba19c18228b0eac2c8d0885f1a25 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Tue, 21 Jan 2025 17:16:37 +0800 Subject: [PATCH 02/54] feat:material material_category --- app/Constants/Admin/MaterialCode.php | 29 +++++ .../Admin/MaterialCategoryController.php | 81 ++++++++++++ app/Controller/Admin/MaterialController.php | 69 +++++++++++ app/Model/Material.php | 54 ++++++++ app/Model/MaterialCategory.php | 59 +++++++++ app/Request/Admin/MaterialCategoryRequest.php | 41 +++++++ app/Request/Admin/MaterialRequest.php | 44 +++++++ .../Material/MaterialCategoryService.php | 116 ++++++++++++++++++ .../Admin/Material/MaterialService.php | 102 +++++++++++++++ sync/http/admin/auth.http | 51 +++++++- 10 files changed, 645 insertions(+), 1 deletion(-) create mode 100644 app/Constants/Admin/MaterialCode.php create mode 100644 app/Controller/Admin/MaterialCategoryController.php create mode 100644 app/Controller/Admin/MaterialController.php create mode 100644 app/Model/Material.php create mode 100644 app/Model/MaterialCategory.php create mode 100644 app/Request/Admin/MaterialCategoryRequest.php create mode 100644 app/Request/Admin/MaterialRequest.php create mode 100644 app/Service/Admin/Material/MaterialCategoryService.php create mode 100644 app/Service/Admin/Material/MaterialService.php diff --git a/app/Constants/Admin/MaterialCode.php b/app/Constants/Admin/MaterialCode.php new file mode 100644 index 0000000..6e590be --- /dev/null +++ b/app/Constants/Admin/MaterialCode.php @@ -0,0 +1,29 @@ +add(); + } + + /** + * 修改材料分类信息 + * @param MaterialCategoryRequest $request + * @return array + */ + #[RequestMapping(path: "edit", methods: "POST")] + #[Scene(scene: "edit")] + public function edit(MaterialCategoryRequest $request): array + { + return (new MaterialCategoryService())->edit(); + } + + /** + * 删除材料分类信息 + * @param MaterialCategoryRequest $request + * @return array + */ + #[RequestMapping(path: "delete", methods: "GET")] + #[Scene(scene: "delete")] + public function delete(MaterialCategoryRequest $request): array + { + return (new MaterialCategoryService())->delete(); + } + + /** + * 根据id查询材料种类 + * @param MaterialCategoryRequest $request + * @return array + */ + #[RequestMapping(path: "findById", methods: "GET")] + #[Scene(scene: "material_category_info")] + public function findById(MaterialCategoryRequest $request) + { + return (new MaterialCategoryService)->findById(); + } + + /** + * 材料钟类列表 + * @param MaterialCategoryRequest $request + * @return array + */ + #[RequestMapping(path: "list", methods: "GET")] + #[Scene(scene: "list")] + public function getList(MaterialCategoryRequest $request) + { + return (new MaterialCategoryService)->list(); + } +} diff --git a/app/Controller/Admin/MaterialController.php b/app/Controller/Admin/MaterialController.php new file mode 100644 index 0000000..1296fa5 --- /dev/null +++ b/app/Controller/Admin/MaterialController.php @@ -0,0 +1,69 @@ +materialList(); + } + + /** + * 添加材料信息 + * @param MaterialRequest $request + * @return array + */ + #[RequestMapping(path: "add", methods: "POST")] + #[Scene(scene: "add")] + public function add(MaterialRequest $request): array + { + return (new MaterialService)->add(); + } + + /** + * 删除材料信息 + * @param MaterialRequest $request + * @return array + */ + #[RequestMapping(path: "delete", methods: "GET")] + #[Scene(scene: "delete")] + public function delete(MaterialRequest $request): array + { + return (new MaterialService())->delete(); + } + + /** + * 修改材料信息 + * @param MaterialRequest $request + * @return array + */ + #[RequestMapping(path: "edit", methods: "POST")] + #[Scene(scene: "edit")] + public function edit(MaterialRequest $request): array + { + return (new MaterialService())->edit(); + } + +} diff --git a/app/Model/Material.php b/app/Model/Material.php new file mode 100644 index 0000000..4de7a8c --- /dev/null +++ b/app/Model/Material.php @@ -0,0 +1,54 @@ + 'integer', 'category_id' => 'integer', 'status' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'is_del' => 'integer']; + + const CREATED_AT = 'create_time'; + + const UPDATED_AT = 'update_time'; + + /** + * @param int $id + * @return \Hyperf\Database\Model\Model|Builder|null + */ + public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null + { + return $this->where('is_del',MaterialCode::IS_NO_DEL)->where('id',$id)->first(); + } +} diff --git a/app/Model/MaterialCategory.php b/app/Model/MaterialCategory.php new file mode 100644 index 0000000..d66f725 --- /dev/null +++ b/app/Model/MaterialCategory.php @@ -0,0 +1,59 @@ + 'integer', 'parent_id' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'is_del' => 'integer']; + + const CREATED_AT = 'create_time'; + + const UPDATED_AT = 'update_time'; + + /** + * @param int $id + * @return \Hyperf\Database\Model\Model|Builder|null + */ + public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null + { + return $this->where('is_del',MaterialCode::IS_NO_DEL)->where('id',$id)->first(); + } + + /** + * @param int $id + * @return \Hyperf\Database\Model\Model|Builder|null + */ + public function getInfoByPId(int $id): \Hyperf\Database\Model\Model|Builder|null + { + return $this->where('is_del',MaterialCode::IS_NO_DEL)->where('parent_id',$id)->first(); + } +} diff --git a/app/Request/Admin/MaterialCategoryRequest.php b/app/Request/Admin/MaterialCategoryRequest.php new file mode 100644 index 0000000..f4d441a --- /dev/null +++ b/app/Request/Admin/MaterialCategoryRequest.php @@ -0,0 +1,41 @@ +'required|integer|exists:material_category,id', + 'id' =>'required|integer', + 'name' =>'required|string', + 'parent_id' =>'sometimes|integer|exists:material_category,id', + 'city_id' =>'required|integer|exists:system_city,id', + 'kitchen_id' =>'required|integer|exists:kitchen,id', + + ]; + } + + protected array $scenes = [ + 'material_category_info' => ['query_id'], + 'add' => ['name', 'parent_id', 'city_id', 'kitchen_id'], + 'edit' => ['id','name', 'parent_id', 'city_id', 'kitchen_id'], + 'delete' => ['id'], + ]; +} diff --git a/app/Request/Admin/MaterialRequest.php b/app/Request/Admin/MaterialRequest.php new file mode 100644 index 0000000..75d284c --- /dev/null +++ b/app/Request/Admin/MaterialRequest.php @@ -0,0 +1,44 @@ + 'required|integer', + 'query_name' =>'sometimes|string', + 'id' =>'required|integer', + 'category_id' =>'required|integer|exists:material_category,id', + 'name' =>'required|string', + 'standard' =>'string', + 'unit' =>'required|string', + 'bar_code' =>'string', + 'city_id' =>'required|integer|exists:system_city,id', + 'kitchen_id' =>'required|integer|exists:kitchen,id', + ]; + } + + protected array $scenes = [ + 'list' => ['limit','query_name'], + 'add' => ['category_id', 'name', 'standard', 'unit', 'bar_code', 'city_id', 'kitchen_id'], + 'edit' => ['id','category_id', 'name', 'standard', 'unit', 'bar_code','status'], + 'delete' => ['id'], + ]; +} diff --git a/app/Service/Admin/Material/MaterialCategoryService.php b/app/Service/Admin/Material/MaterialCategoryService.php new file mode 100644 index 0000000..c18b684 --- /dev/null +++ b/app/Service/Admin/Material/MaterialCategoryService.php @@ -0,0 +1,116 @@ +request->input('parent_id',0); + if ($pid > 0){ +// $pidInfo = $this->MaterialCategoryModel->getInfoById($pid); + $model->parent_id = $pid; + } + + $model->name = $this->request->input('name'); + $model->city_id = (int)$this->request->input('city_id',0); + $model->kitchen_id = (int)$this->request->input('kitchen_id',0); + + if (!$model->save()) throw new ErrException('添加失败'); + + return $this->return->success(); + } + + /** + * @return array + */ + public function edit(): array + { + $id = (int)$this->request->input('id'); + + $info = $this->MaterialCategoryModel->getInfoById($id); + if (empty($info)) + throw new ErrException('数据不存在'); + + $info->name = $this->request->input('name'); + + $pid = (int)$this->request->input('parent_id',0); + if ($pid == $id) + throw new ErrException('上级数据不能为自身'); + + $pidInfo = $this->MaterialCategoryModel->getInfoById($pid); + if (empty($pidInfo)) + throw new ErrException('该上级数据不存在'); + + $info->parent_id = $pid; + + $info->city_id = (int)$this->request->input('city_id'); + $info->kitchen_id = (int)$this->request->input('kitchen_id'); + + if (!$info->save()) throw new ErrException('修改失败'); + + return $this->return->success(); + } + + public function delete(): array + { + $id = (int)$this->request->input('id'); + + $info = $this->MaterialCategoryModel->getInfoById($id); + if (empty($info)) throw new ErrException('数据不存在'); + + $children = $this->MaterialCategoryModel->getInfoByPId($id); + if (!empty($children)) throw new ErrException('请先删除下级数据'); + + $info->is_del = MaterialCode::IS_DEL; + if (!$info->save()) throw new ErrException('删除失败'); + + return $this->return->success(); + } + + /** + * @return array + */ + public function findById():array + { + $id = (int)$this->request->input('query_id'); + $info = $this->MaterialCategoryModel->getInfoById($id)->toArray(); + if (empty($info)) throw new ErrException('数据不存在'); + return $this->return->success('success',$info); + + } + + /** + * @return array + */ + public function list(): array + { + $list = $this->MaterialCategoryModel + ->where('is_del',MaterialCode::IS_NO_DEL)->get(); + + return $this->return->success('success',['list' => $list->toArray()]); + } +} \ No newline at end of file diff --git a/app/Service/Admin/Material/MaterialService.php b/app/Service/Admin/Material/MaterialService.php new file mode 100644 index 0000000..4e2ecba --- /dev/null +++ b/app/Service/Admin/Material/MaterialService.php @@ -0,0 +1,102 @@ +request->input('limit', 10); + $name = $this->request->input('query_name'); + + $list = $this + ->MaterialModel + ->where('is_del',MaterialCode::IS_NO_DEL) + ->where('status',MaterialCode::ENABLE) + ->when(!empty($name), function ($query) use ($name) { + $query->where('name', 'like', "$name%"); + }) + ->paginate($limit)->toArray(); + + return $this->return->success('success',$list); + } + + public function add(): array + { + $material = new Material(); + $material->name = $this->request->input('name'); + $material->category_id = (int)$this->request->input('category_id'); + + $material->standard = $this->request->input('standard'); + $material->unit = $this->request->input('unit'); + $material->bar_code = $this->request->input('bar_code'); + $material->city_id = (int)$this->request->input('city_id',0); + $material->kitchen_id = (int)$this->request->input('kitchen_id',0); + + if (!$material->save()) throw new ErrException('添加失败'); + + return $this->return->success(); + } + + public function delete(): array + { + $id = (int)$this->request->input('id'); + + $info = $this->MaterialModel->getInfoById($id); + if (empty($info)) throw new ErrException('数据不存在'); + + $info->is_del = MaterialCode::IS_DEL; + if (!$info->save()) throw new ErrException('删除失败'); + + return $this->return->success(); + } + + /** + * @return array + */ + public function edit(): array + { + $id = (int)$this->request->input('id'); + + $info = $this->MaterialModel->getInfoById($id); + if (empty($info)) + throw new ErrException('数据不存在'); + + $category_id = (int)$this->request->input('category_id'); + $name = $this->request->input('name'); + $standard = $this->request->input('standard'); + $unit = $this->request->input('unit'); + $bar_code = $this->request->input('bar_code'); + $status = (int)$this->request->input('status'); + + if (!empty($category_id)) $info->category_id = $category_id; + if (!empty($name)) $info->name = $name; + if (!empty($standard)) $info->standard = $standard; + if (!empty($unit)) $info->unit = $unit; + if (!empty($bar_code)) $info->bar_code = $bar_code; + if (!empty($status)) $info->status = $status; + + if (!$info->save()) throw new ErrException('修改失败'); + + return $this->return->success(); + } +} \ No newline at end of file diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 65c30c1..21c7c81 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -303,4 +303,53 @@ id=2&name=冻品仓库&city_id=1&kitchen_id=1 ### 仓库删除 GET {{host}}/admin/depot/depot_delete?id=2 Content-Type: application/x-www-form-urlencoded -Authorization: Bearer {{admin_token}} \ No newline at end of file +Authorization: Bearer {{admin_token}} + +### 材料种类添加 +POST {{host}}/admin/material_category/add +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +name=猪肉&city_id=1&kitchen_id=1 + +### 材料种类修改 +POST {{host}}/admin/material_category/edit +content-type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +id=2&name=猪肉&city_id=1&kitchen_id=1&parent_id=1 + +### 材料种类删除 +GET {{host}}/admin/material_category/delete?id=3 +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +### 根据id查询材料种类 +GET {{host}}/admin/material_category/findById?query_id=1 +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +### 材料列表 +GET {{host}}/admin/material/list?limit=10 +content-type: application/json +Authorization: Bearer {{admin_token}} + +### 材料添加 +POST {{host}}/admin/material/add +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +category_id=2&name=冻猪肉&unit=斤&bar_code=1003&city_id=1&kitchen_id=1 + +### 材料删除 +GET {{host}}/admin/material/delete?id=1 +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +### 材料修改 +POST {{host}}/admin/material/edit +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +id=1&category_id=2&name=冻猪肉&standard=2斤/包&unit=包&bar_code=1003&status=1 + From 1ea38806306f21c91dcf61dec5264c36a2ac8374 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Wed, 22 Jan 2025 09:43:21 +0800 Subject: [PATCH 03/54] fix:material --- app/Request/Admin/MaterialRequest.php | 6 +++--- app/Service/Admin/Material/MaterialService.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Request/Admin/MaterialRequest.php b/app/Request/Admin/MaterialRequest.php index 75d284c..e81dcf2 100644 --- a/app/Request/Admin/MaterialRequest.php +++ b/app/Request/Admin/MaterialRequest.php @@ -25,10 +25,10 @@ class MaterialRequest extends FormRequest 'limit' => 'required|integer', 'query_name' =>'sometimes|string', 'id' =>'required|integer', - 'category_id' =>'required|integer|exists:material_category,id', - 'name' =>'required|string', + 'category_id' =>'integer|exists:material_category,id', + 'name' =>'string', 'standard' =>'string', - 'unit' =>'required|string', + 'unit' =>'string', 'bar_code' =>'string', 'city_id' =>'required|integer|exists:system_city,id', 'kitchen_id' =>'required|integer|exists:kitchen,id', diff --git a/app/Service/Admin/Material/MaterialService.php b/app/Service/Admin/Material/MaterialService.php index 4e2ecba..62564b9 100644 --- a/app/Service/Admin/Material/MaterialService.php +++ b/app/Service/Admin/Material/MaterialService.php @@ -31,7 +31,7 @@ class MaterialService extends BaseService{ $list = $this ->MaterialModel ->where('is_del',MaterialCode::IS_NO_DEL) - ->where('status',MaterialCode::ENABLE) +// ->where('status',MaterialCode::ENABLE) ->when(!empty($name), function ($query) use ($name) { $query->where('name', 'like', "$name%"); }) From 63c3574c5fcb40451ef2a191aa9d7d18c8decc6b Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Wed, 22 Jan 2025 11:19:10 +0800 Subject: [PATCH 04/54] feat:material --- .../{Admin => Common}/MaterialCode.php | 2 +- app/Controller/Admin/MaterialController.php | 8 ++-- app/Controller/Api/MaterialController.php | 34 ++++++++++++++ app/Model/Material.php | 2 +- app/Model/MaterialCategory.php | 2 +- app/Request/Admin/MaterialRequest.php | 8 ++-- app/Request/Api/MaterialRequest.php | 33 ++++++++++++++ .../Material/MaterialCategoryService.php | 2 +- .../Admin/Material/MaterialService.php | 2 +- app/Service/Api/Material/MaterialService.php | 44 +++++++++++++++++++ 10 files changed, 124 insertions(+), 13 deletions(-) rename app/Constants/{Admin => Common}/MaterialCode.php (92%) create mode 100644 app/Controller/Api/MaterialController.php create mode 100644 app/Request/Api/MaterialRequest.php create mode 100644 app/Service/Api/Material/MaterialService.php diff --git a/app/Constants/Admin/MaterialCode.php b/app/Constants/Common/MaterialCode.php similarity index 92% rename from app/Constants/Admin/MaterialCode.php rename to app/Constants/Common/MaterialCode.php index 6e590be..19f519c 100644 --- a/app/Constants/Admin/MaterialCode.php +++ b/app/Constants/Common/MaterialCode.php @@ -1,6 +1,6 @@ materialList(); @@ -36,7 +36,7 @@ class MaterialController * @return array */ #[RequestMapping(path: "add", methods: "POST")] - #[Scene(scene: "add")] + #[Scene(scene: "material_add")] public function add(MaterialRequest $request): array { return (new MaterialService)->add(); @@ -48,7 +48,7 @@ class MaterialController * @return array */ #[RequestMapping(path: "delete", methods: "GET")] - #[Scene(scene: "delete")] + #[Scene(scene: "material_delete")] public function delete(MaterialRequest $request): array { return (new MaterialService())->delete(); @@ -60,7 +60,7 @@ class MaterialController * @return array */ #[RequestMapping(path: "edit", methods: "POST")] - #[Scene(scene: "edit")] + #[Scene(scene: "material_edit")] public function edit(MaterialRequest $request): array { return (new MaterialService())->edit(); diff --git a/app/Controller/Api/MaterialController.php b/app/Controller/Api/MaterialController.php new file mode 100644 index 0000000..7e96aba --- /dev/null +++ b/app/Controller/Api/MaterialController.php @@ -0,0 +1,34 @@ +materialList(); + } + + +} diff --git a/app/Model/Material.php b/app/Model/Material.php index 4de7a8c..2c687fa 100644 --- a/app/Model/Material.php +++ b/app/Model/Material.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace App\Model; -use App\Constants\Admin\MaterialCode; +use App\Constants\Common\MaterialCode; use Hyperf\Database\Model\Builder; use Hyperf\DbConnection\Model\Model; diff --git a/app/Model/MaterialCategory.php b/app/Model/MaterialCategory.php index d66f725..b68aa0d 100644 --- a/app/Model/MaterialCategory.php +++ b/app/Model/MaterialCategory.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace App\Model; -use App\Constants\Admin\MaterialCode; +use App\Constants\Common\MaterialCode; use Hyperf\Database\Model\Builder; use Hyperf\DbConnection\Model\Model; diff --git a/app/Request/Admin/MaterialRequest.php b/app/Request/Admin/MaterialRequest.php index e81dcf2..b3ef04c 100644 --- a/app/Request/Admin/MaterialRequest.php +++ b/app/Request/Admin/MaterialRequest.php @@ -36,9 +36,9 @@ class MaterialRequest extends FormRequest } protected array $scenes = [ - 'list' => ['limit','query_name'], - 'add' => ['category_id', 'name', 'standard', 'unit', 'bar_code', 'city_id', 'kitchen_id'], - 'edit' => ['id','category_id', 'name', 'standard', 'unit', 'bar_code','status'], - 'delete' => ['id'], + 'material_list' => ['limit','query_name'], + 'material_add' => ['category_id', 'name', 'standard', 'unit', 'bar_code', 'city_id', 'kitchen_id'], + 'material_edit' => ['id','category_id', 'name', 'standard', 'unit', 'bar_code','status'], + 'material_delete' => ['id'], ]; } diff --git a/app/Request/Api/MaterialRequest.php b/app/Request/Api/MaterialRequest.php new file mode 100644 index 0000000..124b738 --- /dev/null +++ b/app/Request/Api/MaterialRequest.php @@ -0,0 +1,33 @@ + 'required|integer', + 'query_name' =>'sometimes|string', + ]; + } + + protected array $scenes = [ + 'material_list' => ['limit','query_name'], + ]; +} diff --git a/app/Service/Admin/Material/MaterialCategoryService.php b/app/Service/Admin/Material/MaterialCategoryService.php index c18b684..09271f3 100644 --- a/app/Service/Admin/Material/MaterialCategoryService.php +++ b/app/Service/Admin/Material/MaterialCategoryService.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace App\Service\Admin\Material; -use App\Constants\Admin\MaterialCode; +use App\Constants\Common\MaterialCode; use App\Exception\ErrException; use App\Model\MaterialCategory; use App\Service\Admin\BaseService; diff --git a/app/Service/Admin/Material/MaterialService.php b/app/Service/Admin/Material/MaterialService.php index 62564b9..fc19240 100644 --- a/app/Service/Admin/Material/MaterialService.php +++ b/app/Service/Admin/Material/MaterialService.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace App\Service\Admin\Material; -use App\Constants\Admin\MaterialCode; +use App\Constants\Common\MaterialCode; use App\Exception\ErrException; use App\Model\Material; use App\Service\Admin\BaseService; diff --git a/app/Service/Api/Material/MaterialService.php b/app/Service/Api/Material/MaterialService.php new file mode 100644 index 0000000..d550abe --- /dev/null +++ b/app/Service/Api/Material/MaterialService.php @@ -0,0 +1,44 @@ +request->input('limit', 10); + $name = $this->request->input('query_name'); + + $list = $this + ->MaterialModel + ->where('is_del',MaterialCode::IS_NO_DEL) + ->where('status',MaterialCode::ENABLE) + ->when(!empty($name), function ($query) use ($name) { + $query->where('name', 'like', "$name%"); + }) + ->paginate($limit)->toArray(); + + return $this->return->success('success',$list); + } + + + +} \ No newline at end of file From d231f343d3eafb823e9478b5169ee8bf9a548fd9 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Wed, 22 Jan 2025 17:15:50 +0800 Subject: [PATCH 05/54] fix:depot materialCategory --- app/Controller/Admin/DepotController.php | 13 +++++++++++++ app/Request/Admin/DepotRequest.php | 3 ++- app/Request/Admin/MaterialCategoryRequest.php | 2 +- app/Service/Admin/Depot/DepotService.php | 6 ++++-- .../Admin/Material/MaterialCategoryService.php | 3 --- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/Controller/Admin/DepotController.php b/app/Controller/Admin/DepotController.php index 34b414a..69bfd3e 100644 --- a/app/Controller/Admin/DepotController.php +++ b/app/Controller/Admin/DepotController.php @@ -66,4 +66,17 @@ class DepotController { return (new DepotService)->delete(); } + + /** + * 采购入库 + * @param DepotRequest $request + * @return array + * @throws Exception + */ + #[RequestMapping(path: "depot_purchase", methods: "POST")] + #[Scene(scene: "purchase")] + public function purchase(DepotRequest $request): array + { + return (new DepotService)->purchase(); + } } diff --git a/app/Request/Admin/DepotRequest.php b/app/Request/Admin/DepotRequest.php index 2561503..a4b5212 100644 --- a/app/Request/Admin/DepotRequest.php +++ b/app/Request/Admin/DepotRequest.php @@ -35,7 +35,8 @@ class DepotRequest extends FormRequest protected array $scenes = [ 'depot_list' => ['limit','query_id','query_kitchen_id'], 'depot_add' => ['name','city_id','kitchen_id'], - 'depot_edit' => ['id','name','city_id','kitchen_id'], + 'depot_edit' => ['id','name'], 'depot_delete' => ['id'], + 'purchase' => ['depot_id','material_id','supplier_id','type','purchase_price','number','city_id','kitchen_id'], ]; } diff --git a/app/Request/Admin/MaterialCategoryRequest.php b/app/Request/Admin/MaterialCategoryRequest.php index f4d441a..6fa0414 100644 --- a/app/Request/Admin/MaterialCategoryRequest.php +++ b/app/Request/Admin/MaterialCategoryRequest.php @@ -35,7 +35,7 @@ class MaterialCategoryRequest extends FormRequest protected array $scenes = [ 'material_category_info' => ['query_id'], 'add' => ['name', 'parent_id', 'city_id', 'kitchen_id'], - 'edit' => ['id','name', 'parent_id', 'city_id', 'kitchen_id'], + 'edit' => ['id','name', 'parent_id'], 'delete' => ['id'], ]; } diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index 533e924..fef279f 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -7,6 +7,7 @@ namespace App\Service\Admin\Depot; use App\Constants\Admin\DepotCode; use App\Exception\ErrException; use App\Model\Depot; +use App\Model\DepotPurchase; use App\Service\Admin\BaseService; use Hyperf\Di\Annotation\Inject; @@ -18,6 +19,9 @@ class DepotService extends BaseService{ #[Inject] protected Depot $DepotModel; + #[Inject] + protected DepotPurchase $DepotPurchaseModel; + public function handle() { @@ -85,8 +89,6 @@ class DepotService extends BaseService{ } $info->name = $depotName; - $info->city_id = (int)$this->request->input('city_id'); - $info->kitchen_id = $kitchen_id; if (!$info->save()) throw new ErrException('仓库修改失败'); diff --git a/app/Service/Admin/Material/MaterialCategoryService.php b/app/Service/Admin/Material/MaterialCategoryService.php index 09271f3..c64ebb4 100644 --- a/app/Service/Admin/Material/MaterialCategoryService.php +++ b/app/Service/Admin/Material/MaterialCategoryService.php @@ -67,9 +67,6 @@ class MaterialCategoryService extends BaseService{ $info->parent_id = $pid; - $info->city_id = (int)$this->request->input('city_id'); - $info->kitchen_id = (int)$this->request->input('kitchen_id'); - if (!$info->save()) throw new ErrException('修改失败'); return $this->return->success(); From 4e11fbaec8d7a108c6008990d8a5d9f57131fbce Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Wed, 22 Jan 2025 17:53:00 +0800 Subject: [PATCH 06/54] feat:supplier --- app/Controller/Admin/SupplierController.php | 66 +++++++++++ app/Model/Supplier.php | 50 +++++++++ app/Request/Admin/SupplierRequest.php | 39 +++++++ .../Admin/Material/SupplierService.php | 105 ++++++++++++++++++ sync/http/admin/auth.http | 24 ++++ 5 files changed, 284 insertions(+) create mode 100644 app/Controller/Admin/SupplierController.php create mode 100644 app/Model/Supplier.php create mode 100644 app/Request/Admin/SupplierRequest.php create mode 100644 app/Service/Admin/Material/SupplierService.php diff --git a/app/Controller/Admin/SupplierController.php b/app/Controller/Admin/SupplierController.php new file mode 100644 index 0000000..d7241e8 --- /dev/null +++ b/app/Controller/Admin/SupplierController.php @@ -0,0 +1,66 @@ +list(); + } + + /** + * 添加供应商 + * @param SupplierRequest $request + * @return array + */ + #[RequestMapping(path: "add", methods: "POST")] + #[Scene(scene: "add")] + public function add(SupplierRequest $request): array + { + return (new SupplierService)->add(); + } + + /** + * 修改供应商 + * @return array + */ + #[RequestMapping(path: "edit", methods: "POST")] + #[Scene(scene: "edit")] + public function edit(SupplierRequest $request): array + { + return (new SupplierService)->edit(); + } + + /** + * 删除供应商 + * @return array + */ + #[RequestMapping(path: "delete", methods: "GET")] + #[Scene(scene: "delete")] + public function delete(SupplierRequest $request): array + { + return (new SupplierService)->delete(); + } +} diff --git a/app/Model/Supplier.php b/app/Model/Supplier.php new file mode 100644 index 0000000..1395a06 --- /dev/null +++ b/app/Model/Supplier.php @@ -0,0 +1,50 @@ + 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'is_del' => 'integer']; + + const CREATED_AT = 'create_time'; + + const UPDATED_AT = 'update_time'; + + /** + * @param int $id + * @return \Hyperf\Database\Model\Model|Builder|null + */ + public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null + { + return $this->where('id',$id)->where('is_del',1)->first(); + } +} diff --git a/app/Request/Admin/SupplierRequest.php b/app/Request/Admin/SupplierRequest.php new file mode 100644 index 0000000..6103cab --- /dev/null +++ b/app/Request/Admin/SupplierRequest.php @@ -0,0 +1,39 @@ + 'required|integer', + 'query_name' => 'sometimes|string', + 'mobile' => 'digits:11', + 'city_id' => 'required|integer|exists:system_city,id', + 'kitchen_id' => 'required|integer|exists:kitchen,id', + ]; + } + + protected array $scenes = [ + 'list' => ['limit','query_name'], + 'add' => ['name','mobile','address','city_id','kitchen_id'], + 'edit' => ['id','name','mobile','address'], + 'delete' => ['id'], + ]; +} diff --git a/app/Service/Admin/Material/SupplierService.php b/app/Service/Admin/Material/SupplierService.php new file mode 100644 index 0000000..dcc0bcd --- /dev/null +++ b/app/Service/Admin/Material/SupplierService.php @@ -0,0 +1,105 @@ +request->input('limit', 10); + $name = (int)$this->request->input('query_name'); + + $list = $this->SupplierModel + ->leftJoin('system_city','system_city.id','supplier.city_id') + ->leftJoin('kitchen','kitchen.id','supplier.kitchen_id') + ->where('supplier.is_del',1) + ->when(!empty($name), function ($query) use ($name) { + $query->where('supplier.name', 'like', "$name%"); + }) + ->paginate($limit,['supplier.*','system_city.title as city_name','kitchen.name as kitchen_name']) + ->toArray(); + + return $this->return->success('success',$list); + + } + + /** + * @return array + */ + public function add():array + { + $name = $this->request->input('name'); + $mobile = $this->request->input('mobile'); + $address = $this->request->input('address'); + $city_id = (int)$this->request->input('city_id'); + $kitchen_id = (int)$this->request->input('kitchen_id'); + + $supplier = new Supplier(); + $supplier->name = $name; + $supplier->mobile = $mobile; + $supplier->address = $address; + $supplier->city_id = $city_id; + $supplier->kitchen_id = $kitchen_id; + + if (!$supplier->save()) throw new ErrException('供应商添加失败'); + + return $this->return->success(); + } + + public function edit():array + { + $id = (int)$this->request->input('id'); + $name = $this->request->input('name'); + $mobile = $this->request->input('mobile'); + $address = $this->request->input('address'); + + $info = $this->SupplierModel->getInfoById($id); + if (empty($info)) throw new ErrException('数据不存在'); + + if(!empty($name)) $info->name = $name; + if(!empty($mobile)) $info->mobile = $mobile; + if(!empty($address)) $info->address = $address; + + if (!$info->save()) throw new ErrException('供应商修改失败'); + + return $this->return->success(); + } + + /** + * @return array + */ + public function delete(): array + { + $id = (int)$this->request->input('id'); + + $info = $this->SupplierModel->getInfoById($id); + if (empty($info)) throw new ErrException('供应商不存在'); + + $info->is_del = 2; + + if (!$info->save()) throw new ErrException('删除失败'); + + return $this->return->success(); + } +} \ No newline at end of file diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 21c7c81..1314783 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -353,3 +353,27 @@ Authorization: Bearer {{admin_token}} id=1&category_id=2&name=冻猪肉&standard=2斤/包&unit=包&bar_code=1003&status=1 +### 供应商列表 +GET {{host}}/admin/supplier/list?limit=10 +content-type: application/json +Authorization: Bearer {{admin_token}} + +### 供应商添加 +POST {{host}}/admin/supplier/add +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +name=1号&mobile=15864359431&address=深圳市南山区&city_id=1&kitchen_id=1 + +### 供应商修改 +POST {{host}}/admin/supplier/edit +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +id=1&name=1号供应商&mobile=15864359431&address=广东省深圳市南山区 + +### 供应商删除 +GET {{host}}/admin/supplier/delete?id=1 +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + From d58b773dc8ecdc99f1c609caee2419aadb200b31 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Thu, 23 Jan 2025 17:55:14 +0800 Subject: [PATCH 07/54] feat:depotPurchase --- app/Model/DepotPurchase.php | 46 ++++++++++++++ app/Model/Dish.php | 11 ++++ app/Model/MaterialStock.php | 48 +++++++++++++++ app/Service/Admin/Depot/DepotService.php | 78 +++++++++++++++++++++++- 4 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 app/Model/DepotPurchase.php create mode 100644 app/Model/MaterialStock.php diff --git a/app/Model/DepotPurchase.php b/app/Model/DepotPurchase.php new file mode 100644 index 0000000..b823caf --- /dev/null +++ b/app/Model/DepotPurchase.php @@ -0,0 +1,46 @@ + 'integer', 'depot_id' => 'integer', 'material_id' => 'integer', 'supplier_id' => 'integer', 'type' => 'integer', 'status' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'operator_id' => 'integer', 'is_del' => 'integer']; + + const CREATED_AT = 'create_time'; + + const UPDATED_AT = 'update_time'; +} diff --git a/app/Model/Dish.php b/app/Model/Dish.php index 4cb19d5..3a7b4b2 100644 --- a/app/Model/Dish.php +++ b/app/Model/Dish.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace App\Model; +use App\Constants\Common\DishCode; +use Hyperf\Database\Model\Builder; use Hyperf\DbConnection\Model\Model; /** @@ -43,4 +45,13 @@ class Dish extends Model const string CREATED_AT = 'create_time'; const string UPDATED_AT = 'update_time'; + + /** + * @param int $id + * @return \Hyperf\Database\Model\Model|Builder|null + */ + public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null + { + return $this->where('id',$id)->where('is_del',DishCode::IS_NO_DEL)->first(); + } } diff --git a/app/Model/MaterialStock.php b/app/Model/MaterialStock.php new file mode 100644 index 0000000..e6a64c5 --- /dev/null +++ b/app/Model/MaterialStock.php @@ -0,0 +1,48 @@ + 'integer', 'material_id' => 'integer', 'depot_id' => 'integer', 'supplier_id' => 'integer', 'is_del' => 'integer']; + + public function getMaterial(int $material_id,int $depot_id,int $supplier_id): \Hyperf\Database\Model\Model|Builder|null + { + return $this->where('is_del',MaterialCode::IS_NO_DEL) + ->where('material_id',$material_id) + ->where('depot_id',$depot_id) + ->where('supplier_id',$supplier_id) + ->where('is_del',MaterialCode::IS_NO_DEL) + ->first(); + } +} diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index fef279f..6be8f5d 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -8,6 +8,9 @@ use App\Constants\Admin\DepotCode; use App\Exception\ErrException; use App\Model\Depot; use App\Model\DepotPurchase; +use App\Model\Material; +use App\Model\MaterialStock; +use App\Model\Supplier; use App\Service\Admin\BaseService; use Hyperf\Di\Annotation\Inject; @@ -20,7 +23,13 @@ class DepotService extends BaseService{ protected Depot $DepotModel; #[Inject] - protected DepotPurchase $DepotPurchaseModel; + protected Material $MaterialModel; + + #[Inject] + protected Supplier $SupplierModel; + + #[Inject] + protected MaterialStock $MaterialStockModel; public function handle() { @@ -112,5 +121,72 @@ class DepotService extends BaseService{ return $this->return->success(); } + public function purchase():array + { + $depotId = (int)$this->request->input('depot_id'); + $depotInfo = $this->DepotModel->getInfoById($depotId); + if (empty($depotInfo)) throw new ErrException('仓库不存在'); + + $materialId = (int)$this->request->input('material_id'); + $materialInfo = $this->MaterialModel->getInfoById($materialId); + if (empty($materialInfo)) throw new ErrException("材料不存在"); + + $supplierId = (int)$this->request->input('supplier_id'); + $supplierInfo = $this->SupplierModel->getInfoById($supplierId); + if (empty($supplierInfo)) throw new ErrException('供应商不存在'); + + $type = (int)$this->request->input('type'); + $purchase_price = (double)$this->request->input('purchase_price'); + $number = (double)$this->request->input('number'); + + if (!empty($purchase_price) && !empty($number)){ + $sum_price = $purchase_price * $number; + } + + $cityId = (int)$this->request->input('city_id'); + $kitchenId = (int)$this->request->input('kitchen_id'); + + $depotPurchase = new DepotPurchase(); + $depotPurchase->depot_id = $depotId; + $depotPurchase->material_id = $materialId; + $depotPurchase->supplier_id = $supplierId; + $depotPurchase->type = $type; + $depotPurchase->purchase_price = $purchase_price; + $depotPurchase->number = $number; + $depotPurchase->sum_price = $sum_price; + $depotPurchase->city_id = $cityId; + $depotPurchase->kitchen_id = $kitchenId; + $depotPurchase->operator_id = $this->adminId; + + + $materialStock = $this->MaterialStockModel + ->where('depot_id',$depotId) + ->where('material_id',$materialId) + ->where('supplier_id',$supplierId) + ->first(); + if (empty($materialStock)){ + $materialStock = new MaterialStock(); + $materialStock->depot_id = $depotId; + $materialStock->material_id = $materialId; + $materialStock->supplier_id = $supplierId; + $materialStock->current_stock = $number; + $materialStock->unit_price = $purchase_price; + } + else{ + //采购入库 + if ($depotPurchase->type == 1){ + $materialStock->current_stock = $materialStock->current_stock + $number; + } + //采购退货 + else + $materialStock->current_stock = $materialStock->current_stock - $number; + + } + + if (!$depotPurchase->save() || !$materialStock->save()) throw new ErrException('采购添加失败'); + + return $this->return->success(); + + } } \ No newline at end of file From ec15f9b13dc6db2372b4d178c6bd1f7bdf256c24 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Fri, 24 Jan 2025 10:08:07 +0800 Subject: [PATCH 08/54] feat:depotPurchase --- app/Controller/Admin/DepotController.php | 14 ++++++++++++- app/Request/Admin/DepotRequest.php | 1 + app/Service/Admin/Depot/DepotService.php | 26 ++++++++++++++++++++++++ sync/http/admin/auth.http | 5 +++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/app/Controller/Admin/DepotController.php b/app/Controller/Admin/DepotController.php index 69bfd3e..52e5ac8 100644 --- a/app/Controller/Admin/DepotController.php +++ b/app/Controller/Admin/DepotController.php @@ -68,7 +68,7 @@ class DepotController } /** - * 采购入库 + * 采购 * @param DepotRequest $request * @return array * @throws Exception @@ -79,4 +79,16 @@ class DepotController { return (new DepotService)->purchase(); } + + /** + * 采购列表 + * @param DepotRequest $request + * @return array + */ + #[RequestMapping(path: "purchase_list", methods: "GET")] + #[Scene(scene: "purchase_list")] + public function purchaseList(DepotRequest $request): array + { + return (new DepotService)->purchaseList(); + } } diff --git a/app/Request/Admin/DepotRequest.php b/app/Request/Admin/DepotRequest.php index a4b5212..0b59b9b 100644 --- a/app/Request/Admin/DepotRequest.php +++ b/app/Request/Admin/DepotRequest.php @@ -38,5 +38,6 @@ class DepotRequest extends FormRequest 'depot_edit' => ['id','name'], 'depot_delete' => ['id'], 'purchase' => ['depot_id','material_id','supplier_id','type','purchase_price','number','city_id','kitchen_id'], + 'purchase_list' => ['limit','query_id','query_kitchen_id'], ]; } diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index 6be8f5d..e68376d 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -31,6 +31,9 @@ class DepotService extends BaseService{ #[Inject] protected MaterialStock $MaterialStockModel; + #[Inject] + protected DepotPurchase $DepotPurchaseModel; + public function handle() { @@ -189,4 +192,27 @@ class DepotService extends BaseService{ } + public function purchaseList():array + { + $limit = (int)$this->request->input('limit', 10); + $id = (int)$this->request->input('query_id'); + $kitchenId = (int)$this->request->input('query_kitchen_id'); + + $list = $this->DepotPurchaseModel + ->leftJoin('material','depot_purchase.material_id','=','material.id') + ->leftJoin('supplier','depot_purchase.supplier_id','=','supplier.id') + ->leftJoin('depot','depot_purchase.depot_id','=','depot.id') + ->where('depot_purchase.is_del',DepotCode::IS_NO_DEL) + ->when($id,function ($query) use ($id) { + $query->where('depot_purchase.id',$id); + }) + ->when($kitchenId,function ($query) use ($kitchenId) { + $query->where('depot_purchase.kitchen_id',$kitchenId); + }) + ->paginate($limit,['depot_purchase.*','material.name as material_name','supplier.name as supplier_name','depot.name as depot_name']) + ->toArray(); + + return $this->return->success('success',$list); + } + } \ No newline at end of file diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 1314783..2e22a85 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -377,3 +377,8 @@ GET {{host}}/admin/supplier/delete?id=1 Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{admin_token}} +### 采购列表 +GET {{host}}/admin/depot/purchase_list?limit=10 +content-type: application/json +Authorization: Bearer {{admin_token}} + From 3f7d8f5cad31d9a6111892bcf9bb4196dc2bfe15 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Wed, 5 Feb 2025 16:11:00 +0800 Subject: [PATCH 09/54] feat:depotPurchase --- app/Controller/Admin/DepotController.php | 15 +++++- app/Model/DepotPurchase.php | 11 ++-- app/Model/MaterialStock.php | 5 +- app/Request/Admin/DepotRequest.php | 3 +- app/Service/Admin/Depot/DepotService.php | 64 +++++++++++++++++++----- sync/http/admin/auth.http | 14 ++++++ 6 files changed, 94 insertions(+), 18 deletions(-) diff --git a/app/Controller/Admin/DepotController.php b/app/Controller/Admin/DepotController.php index 52e5ac8..7e0f843 100644 --- a/app/Controller/Admin/DepotController.php +++ b/app/Controller/Admin/DepotController.php @@ -68,7 +68,7 @@ class DepotController } /** - * 采购 + * 采购入库 * @param DepotRequest $request * @return array * @throws Exception @@ -80,6 +80,19 @@ class DepotController return (new DepotService)->purchase(); } + /** + * 采购退货 + * @param DepotRequest $request + * @return array + * @throws Exception + */ + #[RequestMapping(path: "depot_purchase_back", methods: "POST")] + #[Scene(scene: "purchase_back")] + public function purchaseBack(DepotRequest $request): array + { + return (new DepotService)->purchaseBack(); + } + /** * 采购列表 * @param DepotRequest $request diff --git a/app/Model/DepotPurchase.php b/app/Model/DepotPurchase.php index b823caf..c943923 100644 --- a/app/Model/DepotPurchase.php +++ b/app/Model/DepotPurchase.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Model; +use Hyperf\Database\Model\Builder; use Hyperf\DbConnection\Model\Model; /** @@ -14,8 +15,7 @@ use Hyperf\DbConnection\Model\Model; * @property int $type * @property string $purchase_price * @property string $number - * @property string $sum_price - * @property int $status + * @property string $sum_price * @property int $city_id * @property int $kitchen_id * @property int $operator_id @@ -38,9 +38,14 @@ class DepotPurchase extends Model /** * The attributes that should be cast to native types. */ - protected array $casts = ['id' => 'integer', 'depot_id' => 'integer', 'material_id' => 'integer', 'supplier_id' => 'integer', 'type' => 'integer', 'status' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'operator_id' => 'integer', 'is_del' => 'integer']; + protected array $casts = ['id' => 'integer', 'depot_id' => 'integer', 'material_id' => 'integer', 'supplier_id' => 'integer', 'type' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'operator_id' => 'integer', 'is_del' => 'integer']; const CREATED_AT = 'create_time'; const UPDATED_AT = 'update_time'; + + public function getDepotPurchase(int $id): \Hyperf\Database\Model\Model|Builder|null + { + return $this->where('id',$id)->first(); + } } diff --git a/app/Model/MaterialStock.php b/app/Model/MaterialStock.php index e6a64c5..634d05a 100644 --- a/app/Model/MaterialStock.php +++ b/app/Model/MaterialStock.php @@ -36,13 +36,16 @@ class MaterialStock extends Model */ protected array $casts = ['id' => 'integer', 'material_id' => 'integer', 'depot_id' => 'integer', 'supplier_id' => 'integer', 'is_del' => 'integer']; + const CREATED_AT = 'create_time'; + + const UPDATED_AT = 'update_time'; + public function getMaterial(int $material_id,int $depot_id,int $supplier_id): \Hyperf\Database\Model\Model|Builder|null { return $this->where('is_del',MaterialCode::IS_NO_DEL) ->where('material_id',$material_id) ->where('depot_id',$depot_id) ->where('supplier_id',$supplier_id) - ->where('is_del',MaterialCode::IS_NO_DEL) ->first(); } } diff --git a/app/Request/Admin/DepotRequest.php b/app/Request/Admin/DepotRequest.php index 0b59b9b..869188e 100644 --- a/app/Request/Admin/DepotRequest.php +++ b/app/Request/Admin/DepotRequest.php @@ -37,7 +37,8 @@ class DepotRequest extends FormRequest 'depot_add' => ['name','city_id','kitchen_id'], 'depot_edit' => ['id','name'], 'depot_delete' => ['id'], - 'purchase' => ['depot_id','material_id','supplier_id','type','purchase_price','number','city_id','kitchen_id'], + 'purchase' => ['depot_id','material_id','supplier_id','purchase_price','number','city_id','kitchen_id'], + 'purchase_back' => ['id','number'], 'purchase_list' => ['limit','query_id','query_kitchen_id'], ]; } diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index e68376d..c97a230 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -135,10 +135,11 @@ class DepotService extends BaseService{ if (empty($materialInfo)) throw new ErrException("材料不存在"); $supplierId = (int)$this->request->input('supplier_id'); - $supplierInfo = $this->SupplierModel->getInfoById($supplierId); - if (empty($supplierInfo)) throw new ErrException('供应商不存在'); + if (!empty($supplierId)){ + $supplierInfo = $this->SupplierModel->getInfoById($supplierId); + if (empty($supplierInfo)) throw new ErrException('供应商不存在'); + } - $type = (int)$this->request->input('type'); $purchase_price = (double)$this->request->input('purchase_price'); $number = (double)$this->request->input('number'); @@ -153,7 +154,7 @@ class DepotService extends BaseService{ $depotPurchase->depot_id = $depotId; $depotPurchase->material_id = $materialId; $depotPurchase->supplier_id = $supplierId; - $depotPurchase->type = $type; + $depotPurchase->type = 1; $depotPurchase->purchase_price = $purchase_price; $depotPurchase->number = $number; $depotPurchase->sum_price = $sum_price; @@ -176,14 +177,8 @@ class DepotService extends BaseService{ $materialStock->unit_price = $purchase_price; } else{ - //采购入库 - if ($depotPurchase->type == 1){ - $materialStock->current_stock = $materialStock->current_stock + $number; - } - //采购退货 - else - $materialStock->current_stock = $materialStock->current_stock - $number; - + //库存增加 + $materialStock->current_stock = $materialStock->current_stock + $number; } if (!$depotPurchase->save() || !$materialStock->save()) throw new ErrException('采购添加失败'); @@ -192,6 +187,51 @@ class DepotService extends BaseService{ } + public function purchaseBack():array + { + $id = (int)$this->request->input('id'); + $number = (double)$this->request->input('number'); + $info = $this->DepotPurchaseModel->getDepotPurchase($id); + if (!empty($info)){ + $depotPurchase = new DepotPurchase(); + $depotPurchase->depot_id = $info->depot_id; + $depotPurchase->material_id = $info->material_id; + $depotPurchase->supplier_id = $info->supplier_id; + $depotPurchase->type = 2; + $depotPurchase->purchase_price = $info->purchase_price; + if (empty($number)){ + $depotPurchase->number = $info->number; + } + else{ + if ($info->number >= $number) + $depotPurchase->number = $number; + else + throw new ErrException('采购退货数量不能大于进货数量'); + } + + $depotPurchase->sum_price = $depotPurchase->purchase_price * $depotPurchase->number; + $depotPurchase->city_id = $info->city_id; + $depotPurchase->kitchen_id = $info->kitchen_id; + $depotPurchase->operator_id = $this->adminId; + } + + $materialStock = $this->MaterialStockModel + ->where('depot_id',$depotPurchase->depot_id) + ->where('material_id',$depotPurchase->material_id) + ->where('supplier_id',$depotPurchase->supplier_id) + ->first(); + if (empty($materialStock)) + throw new ErrException('库存更改异常'); + else{ + //库存减少 + $materialStock->current_stock = $materialStock->current_stock - $depotPurchase->number; + } + + if (!$depotPurchase->save() || !$materialStock->save()) throw new ErrException('采购退货失败'); + + return $this->return->success(); + } + public function purchaseList():array { $limit = (int)$this->request->input('limit', 10); diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 2e22a85..b760d82 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -382,3 +382,17 @@ GET {{host}}/admin/depot/purchase_list?limit=10 content-type: application/json Authorization: Bearer {{admin_token}} +### 采购入库 +POST {{host}}/admin/depot/depot_purchase +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +depot_id=1&material_id=1&supplier_id=1&purchase_price=60&number=2&city_id=1&kitchen_id=1 + +### 采购退货 +POST {{host}}/admin/depot/depot_purchase_back +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +id=6&number=2 + From 6cd9294db31d7cfe5c724a5d75e5305d9ff10b78 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Wed, 5 Feb 2025 16:40:55 +0800 Subject: [PATCH 10/54] fix:depotPurchase --- app/Request/Admin/DepotRequest.php | 2 +- app/Service/Admin/Depot/DepotService.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Request/Admin/DepotRequest.php b/app/Request/Admin/DepotRequest.php index 869188e..703d217 100644 --- a/app/Request/Admin/DepotRequest.php +++ b/app/Request/Admin/DepotRequest.php @@ -39,6 +39,6 @@ class DepotRequest extends FormRequest 'depot_delete' => ['id'], 'purchase' => ['depot_id','material_id','supplier_id','purchase_price','number','city_id','kitchen_id'], 'purchase_back' => ['id','number'], - 'purchase_list' => ['limit','query_id','query_kitchen_id'], + 'purchase_list' => ['limit','query_id','query_kitchen_id','type'], ]; } diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index c97a230..000eb68 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -236,6 +236,7 @@ class DepotService extends BaseService{ { $limit = (int)$this->request->input('limit', 10); $id = (int)$this->request->input('query_id'); + $type = (int)$this->request->input('type'); $kitchenId = (int)$this->request->input('query_kitchen_id'); $list = $this->DepotPurchaseModel @@ -246,6 +247,9 @@ class DepotService extends BaseService{ ->when($id,function ($query) use ($id) { $query->where('depot_purchase.id',$id); }) + ->when(!empty($type), function ($query) use ($type) { + $query->where('type', $type); + }) ->when($kitchenId,function ($query) use ($kitchenId) { $query->where('depot_purchase.kitchen_id',$kitchenId); }) From 4fd5bb66ce212316e48ec4c46f723a3199f65a49 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Wed, 5 Feb 2025 17:03:22 +0800 Subject: [PATCH 11/54] fix:depotPurchase --- app/Request/Admin/DepotRequest.php | 2 +- app/Service/Admin/Depot/DepotService.php | 18 +++++++++--------- sync/http/admin/auth.http | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/Request/Admin/DepotRequest.php b/app/Request/Admin/DepotRequest.php index 703d217..6a64519 100644 --- a/app/Request/Admin/DepotRequest.php +++ b/app/Request/Admin/DepotRequest.php @@ -38,7 +38,7 @@ class DepotRequest extends FormRequest 'depot_edit' => ['id','name'], 'depot_delete' => ['id'], 'purchase' => ['depot_id','material_id','supplier_id','purchase_price','number','city_id','kitchen_id'], - 'purchase_back' => ['id','number'], + 'purchase_back' => ['id'], 'purchase_list' => ['limit','query_id','query_kitchen_id','type'], ]; } diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index 000eb68..9165d76 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -190,7 +190,7 @@ class DepotService extends BaseService{ public function purchaseBack():array { $id = (int)$this->request->input('id'); - $number = (double)$this->request->input('number'); +// $number = (double)$this->request->input('number'); $info = $this->DepotPurchaseModel->getDepotPurchase($id); if (!empty($info)){ $depotPurchase = new DepotPurchase(); @@ -199,15 +199,15 @@ class DepotService extends BaseService{ $depotPurchase->supplier_id = $info->supplier_id; $depotPurchase->type = 2; $depotPurchase->purchase_price = $info->purchase_price; - if (empty($number)){ +// if (empty($number)){ $depotPurchase->number = $info->number; - } - else{ - if ($info->number >= $number) - $depotPurchase->number = $number; - else - throw new ErrException('采购退货数量不能大于进货数量'); - } +// } +// else{ +// if ($info->number >= $number) +// $depotPurchase->number = $number; +// else +// throw new ErrException('采购退货数量不能大于进货数量'); +// } $depotPurchase->sum_price = $depotPurchase->purchase_price * $depotPurchase->number; $depotPurchase->city_id = $info->city_id; diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index b760d82..1b2bb05 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -394,5 +394,5 @@ POST {{host}}/admin/depot/depot_purchase_back Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{admin_token}} -id=6&number=2 +id=6 From c0b032d7062af12815baecd98192b3c1e5381f20 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Thu, 6 Feb 2025 14:20:38 +0800 Subject: [PATCH 12/54] feat:depotPurchase --- app/Controller/Admin/DepotController.php | 13 +++++++++++ app/Request/Admin/DepotRequest.php | 3 +++ app/Service/Admin/Depot/DepotService.php | 28 ++++++++++++++++++++++++ sync/http/admin/auth.http | 6 ++--- 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/app/Controller/Admin/DepotController.php b/app/Controller/Admin/DepotController.php index 7e0f843..5eb5366 100644 --- a/app/Controller/Admin/DepotController.php +++ b/app/Controller/Admin/DepotController.php @@ -80,6 +80,19 @@ class DepotController return (new DepotService)->purchase(); } + /** + * 采购修改 + * @param DepotRequest $request + * @return array + * @throws Exception + */ + #[RequestMapping(path: "depot_purchase_update", methods: "POST")] + #[Scene(scene: "purchase_update")] + public function purchaseUpdate(DepotRequest $request): array + { + return (new DepotService)->purchaseUpdate(); + } + /** * 采购退货 * @param DepotRequest $request diff --git a/app/Request/Admin/DepotRequest.php b/app/Request/Admin/DepotRequest.php index 6a64519..ea3ddb0 100644 --- a/app/Request/Admin/DepotRequest.php +++ b/app/Request/Admin/DepotRequest.php @@ -29,6 +29,8 @@ class DepotRequest extends FormRequest 'city_id' => 'required|integer|exists:system_city,id', 'kitchen_id' => 'required|integer|exists:kitchen,id', 'id' => 'required|integer', + 'purchase_price' => 'required', + 'number' => 'required', ]; } @@ -38,6 +40,7 @@ class DepotRequest extends FormRequest 'depot_edit' => ['id','name'], 'depot_delete' => ['id'], 'purchase' => ['depot_id','material_id','supplier_id','purchase_price','number','city_id','kitchen_id'], + 'purchase_update' => ['id','number'], 'purchase_back' => ['id'], 'purchase_list' => ['limit','query_id','query_kitchen_id','type'], ]; diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index 9165d76..dd9a32d 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -187,6 +187,32 @@ class DepotService extends BaseService{ } + public function purchaseUpdate():array + { + $id = (int)$this->request->input('id'); + $info = $this->DepotPurchaseModel->getDepotPurchase($id); + $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 + $number - $old_number; + + if (!$info->save() || !$materialStock->save()) throw new ErrException('采购数量修改失败'); + + return $this->return->success(); + + } + public function purchaseBack():array { $id = (int)$this->request->input('id'); @@ -223,6 +249,8 @@ class DepotService extends BaseService{ if (empty($materialStock)) throw new ErrException('库存更改异常'); else{ + if ($materialStock->current_stock < $depotPurchase->number) + throw new ErrException('库存数量小于退货数量'); //库存减少 $materialStock->current_stock = $materialStock->current_stock - $depotPurchase->number; } diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 1b2bb05..90422da 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -389,10 +389,10 @@ Authorization: Bearer {{admin_token}} depot_id=1&material_id=1&supplier_id=1&purchase_price=60&number=2&city_id=1&kitchen_id=1 -### 采购退货 -POST {{host}}/admin/depot/depot_purchase_back +### 采购数量修改 +POST {{host}}/admin/depot/depot_purchase_update Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{admin_token}} -id=6 +id=1&number=8 From c0dffe3dc7033afdffa92579a2299b866b8c096e Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Thu, 6 Feb 2025 15:30:15 +0800 Subject: [PATCH 13/54] feat:dish --- app/Controller/Api/DishController.php | 56 ++++++++++++ app/Model/Dish.php | 3 +- app/Request/Api/DishRequest.php | 40 +++++++++ app/Service/Api/Material/DishService.php | 107 +++++++++++++++++++++++ sync/http/admin/auth.http | 30 +++++-- 5 files changed, 228 insertions(+), 8 deletions(-) create mode 100644 app/Controller/Api/DishController.php create mode 100644 app/Request/Api/DishRequest.php create mode 100644 app/Service/Api/Material/DishService.php diff --git a/app/Controller/Api/DishController.php b/app/Controller/Api/DishController.php new file mode 100644 index 0000000..4606df6 --- /dev/null +++ b/app/Controller/Api/DishController.php @@ -0,0 +1,56 @@ +add(); + } + + /** + * 菜品修改 + * @param DishRequest $request + * @return array + */ + #[RequestMapping(path: "edit", methods: "POST")] + #[Scene(scene: "edit")] + public function dishEdit(dishRequest $request): array + { + return (new DishService())->edit(); + } + + /** + * 菜品列表 + * @param DishRequest $request + * @return array + */ + #[RequestMapping(path: "list", methods: "GET")] + #[Scene(scene: "list")] + public function dishList(dishRequest $request): array + { + return (new DishService())->list(); + } +} diff --git a/app/Model/Dish.php b/app/Model/Dish.php index 3a7b4b2..92d2a2d 100644 --- a/app/Model/Dish.php +++ b/app/Model/Dish.php @@ -17,7 +17,6 @@ use Hyperf\DbConnection\Model\Model; * @property string $side_dish * @property string $flavor * @property int $cycle_id - * @property int $status * @property int $city_id * @property int $kitchen_id * @property int $chef_id @@ -40,7 +39,7 @@ class Dish extends Model /** * The attributes that should be cast to native types. */ - protected array $casts = ['id' => 'integer', 'pre_quantity' => 'integer', 'cycle_id' => 'integer', 'status' => 'integer', 'city_id' => 'integer','kitchen_id' => 'integer', 'chef_id' => 'integer', 'is_del' => 'integer']; + protected array $casts = ['id' => 'integer', 'pre_quantity' => 'integer', 'cycle_id' => 'integer', 'city_id' => 'integer','kitchen_id' => 'integer', 'chef_id' => 'integer', 'is_del' => 'integer']; const string CREATED_AT = 'create_time'; diff --git a/app/Request/Api/DishRequest.php b/app/Request/Api/DishRequest.php new file mode 100644 index 0000000..3ec2dff --- /dev/null +++ b/app/Request/Api/DishRequest.php @@ -0,0 +1,40 @@ + 'required|integer', + 'dish_name' => 'sometimes|string', + 'cycle_id' => 'sometimes|integer|exists:cycle,id', + 'city_id' => 'sometimes|integer|exists:system_city,id', + 'kitchen_id' => 'sometimes|integer|exists:kitchen,id', + + ]; + } + + protected array $scenes = [ + 'add' => ['dish_name','profile','pre_quantity','price','side_dish','flavor','cycle_id','city_id','kitchen_id'], + 'edit' => ['id','dish_name','profile','pre_quantity','price','side_dish','flavor'], + 'list' =>['limit'] + + ]; +} diff --git a/app/Service/Api/Material/DishService.php b/app/Service/Api/Material/DishService.php new file mode 100644 index 0000000..a2d094a --- /dev/null +++ b/app/Service/Api/Material/DishService.php @@ -0,0 +1,107 @@ +request->input('dish_name'); + $profile = $this->request->input('profile'); + $pre_quantity = (int)$this->request->input('pre_quantity'); + $price = (double)$this->request->input('price'); + $side_dish = $this->request->input('side_dish'); + $flavor = $this->request->input('flavor'); + $cycle_id = (int)$this->request->input('cycle_id'); + $city_id = (int)$this->request->input('city_id'); + $kitchen_id = (int)$this->request->input('kitchen_id'); + $chef_id = $this->userId; + + $dish = new Dish(); + $dish ->dish = $dish_name; + $dish ->profile = $profile; + $dish ->pre_quantity = $pre_quantity; + $dish ->price = $price; + $dish ->side_dish = $side_dish; + $dish ->flavor = $flavor; + $dish ->cycle_id = $cycle_id; + $dish ->city_id = $city_id; + $dish ->kitchen_id = $kitchen_id; + $dish ->chef_id = $chef_id; + + if (!$dish->save()) throw new ErrException('菜品添加失败'); + + return $this->return->success('success'); + } + + public function edit(): array + { + $dish_id = (int)$this->request->input('id'); + $dish_name = $this->request->input('dish_name'); + $profile = $this->request->input('profile'); + $pre_quantity = (int)$this->request->input('pre_quantity'); + $price = (double)$this->request->input('price'); + $side_dish = $this->request->input('side_dish'); + $flavor = $this->request->input('flavor'); + + $info = $this->DishModel->getInfoById($dish_id); + if (empty($info)) throw new ErrException('数据不存在'); + + if (!empty($dish_name)) { + $info->dish = $dish_name; + } + if (!empty($profile)) { + $info->profile = $profile; + } + if (!empty($pre_quantity)) { + $info->pre_quantity = $pre_quantity; + } + if (!empty($price)) { + $info->price = $price; + } + if (!empty($side_dish)) { + $info->side_dish = $side_dish; + } + if (!empty($flavor)) { + $info->flavor = $flavor; + } + if (!$info->save()) throw new ErrException('菜品修改失败'); + + return $this->return->success(); + } + + public function list(): array + { + $limit = (int)$this->request->input('limit'); + $chef_id = $this->userId; + $list = $this->DishModel + ->where('chef_id', $chef_id) + ->paginate($limit)->toArray(); + + return $this->return->success('success',$list); + } + +} \ No newline at end of file diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 90422da..10b301e 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -276,11 +276,6 @@ GET {{host}}/admin/member/list?limit=10 content-type: application/json Authorization: Bearer {{admin_token}} -### 排菜列表 -GET {{host}}/admin/dish/list?limit=10 -content-type: application/json -Authorization: Bearer {{admin_token}} - ### 仓库列表 GET {{host}}/admin/depot/depot_list?limit=10 content-type: application/json @@ -394,5 +389,28 @@ POST {{host}}/admin/depot/depot_purchase_update Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{admin_token}} -id=1&number=8 +id=1&number=9 +### 排菜列表 +GET {{host}}/admin/dish/list?limit=10 +content-type: application/json +Authorization: Bearer {{admin_token}} + +### 厨师添加菜品 +POST {{host}}/api/dish/add +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +dish_name=排骨饭&profile=加水&pre_quantity=500&price=15&side_dish=33333&flavor=清淡&cycle_id=1&city_id=1&kitchen_id=1 + +### 厨师修改菜品 +POST {{host}}/api/dish/edit +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +id=1&pre_quantity=300&price=12 + +### 厨师查看排菜 +GET {{host}}/api/dish/list?limit=10 +content-type: application/json +Authorization: Bearer {{admin_token}} \ No newline at end of file From 575fe86aa67d655228e276f38b54a5a9b767f143 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Thu, 6 Feb 2025 18:13:20 +0800 Subject: [PATCH 14/54] feat:material_application --- app/Constants/Common/MaterialCode.php | 10 +++ app/Controller/Api/MaterialController.php | 48 ++++++++++++ app/Model/MaterialApplication.php | 49 ++++++++++++ app/Request/Api/MaterialRequest.php | 4 + app/Service/Api/Material/MaterialService.php | 79 ++++++++++++++++++++ sync/http/admin/auth.http | 24 ++++++ 6 files changed, 214 insertions(+) create mode 100644 app/Model/MaterialApplication.php diff --git a/app/Constants/Common/MaterialCode.php b/app/Constants/Common/MaterialCode.php index 19f519c..d9a769b 100644 --- a/app/Constants/Common/MaterialCode.php +++ b/app/Constants/Common/MaterialCode.php @@ -26,4 +26,14 @@ class MaterialCode extends AbstractConstants */ const int DISABLE = 2; + const int UN_AUDIT = 1; + const int AUDITED = 2; + + const int AUDIT_REFUSE = 3; + + const int PART_OUT = 4; + + const int ALL_OUT = 5; + + } \ No newline at end of file diff --git a/app/Controller/Api/MaterialController.php b/app/Controller/Api/MaterialController.php index 7e96aba..28fa4a7 100644 --- a/app/Controller/Api/MaterialController.php +++ b/app/Controller/Api/MaterialController.php @@ -30,5 +30,53 @@ class MaterialController return (new MaterialService())->materialList(); } + /** + * 申请材料 + * @param MaterialRequest $request + * @return array + */ + #[RequestMapping(path: "application", methods: "POST")] + #[Scene(scene: "material_application")] + public function materialApplication(MaterialRequest $request): array + { + return (new MaterialService())->materialApplication(); + } + + /** + * 修改申请材料 + * @param MaterialRequest $request + * @return array + */ + #[RequestMapping(path: "application_edit", methods: "POST")] + #[Scene(scene: "application_edit")] + public function materialApplicationEdit(MaterialRequest $request): array + { + return (new MaterialService())->applicationEdit(); + } + + /** + * 删除申请材料 + * @param MaterialRequest $request + * @return array + */ + #[RequestMapping(path: "application_delete", methods: "POST")] + #[Scene(scene: "application_delete")] + public function materialApplicationDelete(MaterialRequest $request): array + { + return (new MaterialService())->applicationDelete(); + } + + /** + * 个人申请材料列表 + * @param MaterialRequest $request + * @return array + */ + #[RequestMapping(path: "application_list", methods: "GET")] + #[Scene(scene: "application_list")] + public function applicationList(MaterialRequest $request): array + { + return (new MaterialService())->applicationList(); + } + } diff --git a/app/Model/MaterialApplication.php b/app/Model/MaterialApplication.php new file mode 100644 index 0000000..b962adc --- /dev/null +++ b/app/Model/MaterialApplication.php @@ -0,0 +1,49 @@ + 'integer', 'material_id' => 'integer', 'dish_id' => 'integer', 'num' => 'integer', 'status' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'operator_id' => 'integer', 'is_del' => 'integer']; + + const CREATED_AT = 'create_time'; + + const UPDATED_AT = 'update_time'; + + public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null + { + return $this->where('id', $id)->first(); + } +} diff --git a/app/Request/Api/MaterialRequest.php b/app/Request/Api/MaterialRequest.php index 124b738..ea0147f 100644 --- a/app/Request/Api/MaterialRequest.php +++ b/app/Request/Api/MaterialRequest.php @@ -29,5 +29,9 @@ class MaterialRequest extends FormRequest protected array $scenes = [ 'material_list' => ['limit','query_name'], + 'material_application' => ['material_id','dish_id','number','processing','city_id','kitchen_id'], + 'application_edit' => ['id','material_id','dish_id','number','processing'], + 'application_delete' => ['id'], + 'application_list' => ['limit'], ]; } diff --git a/app/Service/Api/Material/MaterialService.php b/app/Service/Api/Material/MaterialService.php index d550abe..91bcbff 100644 --- a/app/Service/Api/Material/MaterialService.php +++ b/app/Service/Api/Material/MaterialService.php @@ -5,7 +5,9 @@ declare(strict_types=1); namespace App\Service\Api\Material; use App\Constants\Common\MaterialCode; +use App\Exception\ErrException; use App\Model\Material; +use App\Model\MaterialApplication; use App\Service\Api\BaseService; use Hyperf\Di\Annotation\Inject; @@ -17,6 +19,9 @@ class MaterialService extends BaseService{ #[Inject] protected Material $MaterialModel; + #[Inject] + protected MaterialApplication $MaterialApplication; + public function handle() { @@ -39,6 +44,80 @@ class MaterialService extends BaseService{ return $this->return->success('success',$list); } + public function materialApplication(): array + { + $material_id = (int)$this->request->input('material_id'); + $dish_id = (int)$this->request->input('dish_id'); + $number = (int)$this->request->input('number'); + $processing = $this->request->input('processing'); + $status = MaterialCode::UN_AUDIT; + $city_id = (int)$this->request->input('city_id'); + $kitchen_id = (int)$this->request->input('kitchen_id'); + $materialApplication = new MaterialApplication(); + $materialApplication->material_id = $material_id; + $materialApplication->dish_id = $dish_id; + $materialApplication->num = $number; + $materialApplication->processing = $processing; + $materialApplication->status = $status; + $materialApplication->city_id = $city_id; + $materialApplication->kitchen_id = $kitchen_id; + $materialApplication->operator_id = $this->userId; + + if (!$materialApplication->save()) + throw new ErrException('申请失败'); + + return $this->return->success(); + } + + public function applicationEdit(): array + { + $id = (int)$this->request->input('id'); + $material_id = (int)$this->request->input('material_id'); + $dish_id = (int)$this->request->input('dish_id'); + $number = (int)$this->request->input('number'); + $processing = $this->request->input('processing'); + + $info = $this->MaterialApplication->getInfoById($id); + + if (!empty($material_id)){ + $info->material_id = $material_id; + } + if (!empty($dish_id)){ + $info->dish_id = $dish_id; + } + if (!empty($number)){ + $info->num = $number; + } + if (!empty($processing)){ + $info->processing = $processing; + } + $info->operator_id = $this->userId; + + if (!$info->save()) throw new ErrException('申请修改失败'); + + return $this->return->success(); + } + + public function applicationDelete(): array + { + $id = (int)$this->request->input('id'); + $info = $this->MaterialApplication->getInfoById($id); + $info->is_del = 2; + if ($info->status == MaterialCode::ALL_OUT) throw new ErrException("已全部出库"); + if (!$info->save()) throw new ErrException('申请删除失败'); + return $this->return->success(); + } + + public function applicationList(): array + { + $limit = (int)$this->request->input('limit', 10); + $list = $this->MaterialApplication + ->where('is_del',MaterialCode::IS_NO_DEL) + ->where('id', $this->userId) + ->paginate($limit)->toArray(); + + return $this->return->success('success',$list); + } } \ No newline at end of file diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 10b301e..7a4c8d8 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -413,4 +413,28 @@ id=1&pre_quantity=300&price=12 ### 厨师查看排菜 GET {{host}}/api/dish/list?limit=10 content-type: application/json +Authorization: Bearer {{admin_token}} + +### 厨师申请材料 +POST {{host}}/api/material/application +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +material_id=1&dish_id=1&number=50&city_id=1&kitchen_id=1 + +### 厨师修改申请材料 +POST {{host}}/api/material/application_edit +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +id=1&material_id=1&dish_id=1&number=50&processing=切碎 + +### 厨师删除申请材料 +POST {{host}}/api/material/application_delete?id=1 +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +### 个人申请材料列表 +GET {{host}}/api/material/application_list?limit=10 +content-type: application/json Authorization: Bearer {{admin_token}} \ No newline at end of file From fe8eb1d175f1648fd25a6beb4c9abe9ab7b74292 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Fri, 7 Feb 2025 09:17:39 +0800 Subject: [PATCH 15/54] fix:material_application --- app/Service/Api/Material/MaterialService.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Service/Api/Material/MaterialService.php b/app/Service/Api/Material/MaterialService.php index 91bcbff..dc46d29 100644 --- a/app/Service/Api/Material/MaterialService.php +++ b/app/Service/Api/Material/MaterialService.php @@ -113,9 +113,13 @@ class MaterialService extends BaseService{ { $limit = (int)$this->request->input('limit', 10); $list = $this->MaterialApplication - ->where('is_del',MaterialCode::IS_NO_DEL) - ->where('id', $this->userId) - ->paginate($limit)->toArray(); + ->leftJoin('material', 'material.id', '=', 'material_id') + ->leftJoin('dish', 'dish.id', '=', 'dish_id') + ->leftJoin('admin_user', 'admin_user.id', '=', 'operator_id') + ->where('material_application.is_del',MaterialCode::IS_NO_DEL) + ->where('material_application.operator_id', $this->userId) + ->paginate($limit,['material_application.*','material.name as material_name','dish.dish as dish_name','admin_user.chinese_name as operator_name']) + ->toArray(); return $this->return->success('success',$list); } From cc6f530c8e4321840ab04d66f14d23d2a3475660 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Fri, 7 Feb 2025 09:54:26 +0800 Subject: [PATCH 16/54] feat:material_application dish --- app/Controller/Api/DishController.php | 12 +++++++++++ app/Request/Api/DishRequest.php | 3 ++- app/Service/Api/Material/DishService.php | 21 ++++++++++++++++++++ app/Service/Api/Material/MaterialService.php | 5 ++++- sync/http/admin/auth.http | 8 +++++++- 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/app/Controller/Api/DishController.php b/app/Controller/Api/DishController.php index 4606df6..ca1ce84 100644 --- a/app/Controller/Api/DishController.php +++ b/app/Controller/Api/DishController.php @@ -53,4 +53,16 @@ class DishController { return (new DishService())->list(); } + + /** + * 菜品删除 + * @param DishRequest $request + * @return array + */ + #[RequestMapping(path: "delete", methods: "POST")] + #[Scene(scene: "delete")] + public function dishDelete(dishRequest $request): array + { + return (new DishService())->delete(); + } } diff --git a/app/Request/Api/DishRequest.php b/app/Request/Api/DishRequest.php index 3ec2dff..800c289 100644 --- a/app/Request/Api/DishRequest.php +++ b/app/Request/Api/DishRequest.php @@ -34,7 +34,8 @@ class DishRequest extends FormRequest protected array $scenes = [ 'add' => ['dish_name','profile','pre_quantity','price','side_dish','flavor','cycle_id','city_id','kitchen_id'], 'edit' => ['id','dish_name','profile','pre_quantity','price','side_dish','flavor'], - 'list' =>['limit'] + 'list' =>['limit'], + 'delete' =>['id'], ]; } diff --git a/app/Service/Api/Material/DishService.php b/app/Service/Api/Material/DishService.php index a2d094a..2d929aa 100644 --- a/app/Service/Api/Material/DishService.php +++ b/app/Service/Api/Material/DishService.php @@ -7,6 +7,7 @@ namespace App\Service\Api\Material; use App\Constants\Common\DishCode; use App\Exception\ErrException; use App\Model\Dish; +use App\Model\MaterialApplication; use App\Service\Api\BaseService; use Hyperf\Di\Annotation\Inject; @@ -19,6 +20,9 @@ class DishService extends BaseService #[Inject] protected Dish $DishModel; + #[Inject] + protected MaterialApplication $MaterialApplication; + public function handle() { @@ -93,6 +97,23 @@ class DishService extends BaseService return $this->return->success(); } + public function delete(): array + { + $id = (int)$this->request->input('id'); + $info = $this->DishModel->getInfoById($id); + $application = $this->MaterialApplication + ->where('dish_id', $id) + ->where('is_del', DishCode::IS_NO_DEL) + ->first(); + if (!empty($application)) throw new ErrException('该菜品存在申请材料'); + + $info->is_del = DishCode::IS_DELETE; + + if (!$info->save()) throw new ErrException('菜品删除失败'); + return $this->return->success(); + + } + public function list(): array { $limit = (int)$this->request->input('limit'); diff --git a/app/Service/Api/Material/MaterialService.php b/app/Service/Api/Material/MaterialService.php index dc46d29..7bbc089 100644 --- a/app/Service/Api/Material/MaterialService.php +++ b/app/Service/Api/Material/MaterialService.php @@ -92,6 +92,9 @@ class MaterialService extends BaseService{ if (!empty($processing)){ $info->processing = $processing; } + if($info->status == MaterialCode::AUDIT_REFUSE){ + $info->status = MaterialCode::UN_AUDIT; + } $info->operator_id = $this->userId; if (!$info->save()) throw new ErrException('申请修改失败'); @@ -104,7 +107,7 @@ class MaterialService extends BaseService{ $id = (int)$this->request->input('id'); $info = $this->MaterialApplication->getInfoById($id); $info->is_del = 2; - if ($info->status == MaterialCode::ALL_OUT) throw new ErrException("已全部出库"); + if ($info->status == MaterialCode::ALL_OUT || $info->status == MaterialCode::PART_OUT) throw new ErrException("已进行出库"); if (!$info->save()) throw new ErrException('申请删除失败'); return $this->return->success(); } diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 7a4c8d8..880d8e9 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -410,6 +410,11 @@ Authorization: Bearer {{admin_token}} id=1&pre_quantity=300&price=12 +### 厨师删除菜品 +POST {{host}}/api/dish/delete?id=1 +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + ### 厨师查看排菜 GET {{host}}/api/dish/list?limit=10 content-type: application/json @@ -437,4 +442,5 @@ Authorization: Bearer {{admin_token}} ### 个人申请材料列表 GET {{host}}/api/material/application_list?limit=10 content-type: application/json -Authorization: Bearer {{admin_token}} \ No newline at end of file +Authorization: Bearer {{admin_token}} + 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 17/54] 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 From 33595961d8e1434fbb984b07fd121d5bba4102a9 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Fri, 7 Feb 2025 15:29:56 +0800 Subject: [PATCH 18/54] feat:material_application --- app/Model/MaterialApplication.php | 5 +++-- app/Request/Api/MaterialRequest.php | 2 +- app/Service/Api/Material/MaterialService.php | 17 ++++++----------- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/app/Model/MaterialApplication.php b/app/Model/MaterialApplication.php index b962adc..71d7990 100644 --- a/app/Model/MaterialApplication.php +++ b/app/Model/MaterialApplication.php @@ -11,7 +11,8 @@ use Hyperf\DbConnection\Model\Model; * @property int $id * @property int $material_id * @property int $dish_id - * @property int $num + * @property string $number + * @property string $al_number * @property string $processing * @property int $status * @property int $city_id @@ -36,7 +37,7 @@ class MaterialApplication extends Model /** * The attributes that should be cast to native types. */ - protected array $casts = ['id' => 'integer', 'material_id' => 'integer', 'dish_id' => 'integer', 'num' => 'integer', 'status' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'operator_id' => 'integer', 'is_del' => 'integer']; + protected array $casts = ['id' => 'integer', 'material_id' => 'integer', 'dish_id' => 'integer', 'status' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'operator_id' => 'integer', 'is_del' => 'integer']; const CREATED_AT = 'create_time'; diff --git a/app/Request/Api/MaterialRequest.php b/app/Request/Api/MaterialRequest.php index ea0147f..93cc127 100644 --- a/app/Request/Api/MaterialRequest.php +++ b/app/Request/Api/MaterialRequest.php @@ -30,7 +30,7 @@ class MaterialRequest extends FormRequest protected array $scenes = [ 'material_list' => ['limit','query_name'], 'material_application' => ['material_id','dish_id','number','processing','city_id','kitchen_id'], - 'application_edit' => ['id','material_id','dish_id','number','processing'], + 'application_edit' => ['id','number','processing'], 'application_delete' => ['id'], 'application_list' => ['limit'], ]; diff --git a/app/Service/Api/Material/MaterialService.php b/app/Service/Api/Material/MaterialService.php index 7bbc089..e360e8e 100644 --- a/app/Service/Api/Material/MaterialService.php +++ b/app/Service/Api/Material/MaterialService.php @@ -48,7 +48,7 @@ class MaterialService extends BaseService{ { $material_id = (int)$this->request->input('material_id'); $dish_id = (int)$this->request->input('dish_id'); - $number = (int)$this->request->input('number'); + $number = (double)$this->request->input('number'); $processing = $this->request->input('processing'); $status = MaterialCode::UN_AUDIT; $city_id = (int)$this->request->input('city_id'); @@ -57,7 +57,7 @@ class MaterialService extends BaseService{ $materialApplication = new MaterialApplication(); $materialApplication->material_id = $material_id; $materialApplication->dish_id = $dish_id; - $materialApplication->num = $number; + $materialApplication->number = $number; $materialApplication->processing = $processing; $materialApplication->status = $status; $materialApplication->city_id = $city_id; @@ -73,21 +73,16 @@ class MaterialService extends BaseService{ public function applicationEdit(): array { $id = (int)$this->request->input('id'); - $material_id = (int)$this->request->input('material_id'); - $dish_id = (int)$this->request->input('dish_id'); $number = (int)$this->request->input('number'); $processing = $this->request->input('processing'); $info = $this->MaterialApplication->getInfoById($id); - if (!empty($material_id)){ - $info->material_id = $material_id; - } - if (!empty($dish_id)){ - $info->dish_id = $dish_id; - } if (!empty($number)){ - $info->num = $number; + $info->number = $number; + if($number <= $info->al_number){ + $info->status = MaterialCode::ALL_OUT; + } } if (!empty($processing)){ $info->processing = $processing; From 0c34080d922aeb4af8e970444968ab1c9fc584db Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Fri, 7 Feb 2025 18:07:05 +0800 Subject: [PATCH 19/54] feat:depot_sale --- app/Controller/Admin/DepotController.php | 29 +++++++- app/Model/DepotSale.php | 5 +- app/Request/Admin/DepotRequest.php | 4 +- app/Service/Admin/Depot/DepotService.php | 87 +++++++++++++++++++++--- sync/http/admin/auth.http | 26 +++++++ 5 files changed, 135 insertions(+), 16 deletions(-) diff --git a/app/Controller/Admin/DepotController.php b/app/Controller/Admin/DepotController.php index 370cc9d..7678407 100644 --- a/app/Controller/Admin/DepotController.php +++ b/app/Controller/Admin/DepotController.php @@ -125,7 +125,7 @@ class DepotController * @throws Exception */ #[RequestMapping(path: "depot_sale", methods: "POST")] - #[Scene(scene: "depot_sale")] + #[Scene(scene: "sale")] public function depotSale(DepotRequest $request): array { return (new DepotService)->depotSale(); @@ -137,10 +137,35 @@ class DepotController * @return array * @throws Exception */ - #[RequestMapping(path: "depot_sale_update", methods: "POST")] + #[RequestMapping(path: "sale_update", methods: "POST")] #[Scene(scene: "sale_update")] public function saleUpdate(DepotRequest $request): array { return (new DepotService)->saleUpdate(); } + + /** + * 销售出库删除 + * @param DepotRequest $request + * @return array + * @throws Exception + */ + #[RequestMapping(path: "sale_delete", methods: "POST")] + #[Scene(scene: "sale_delete")] + public function saleDelete(DepotRequest $request): array + { + return (new DepotService)->saleDelete(); + } + + /** + * 出库列表 + * @param DepotRequest $request + * @return array + */ + #[RequestMapping(path: "sale_list", methods: "GET")] + #[Scene(scene: "sale_list")] + public function saleList(DepotRequest $request): array + { + return (new DepotService)->saleList(); + } } diff --git a/app/Model/DepotSale.php b/app/Model/DepotSale.php index fbd5671..9a6328f 100644 --- a/app/Model/DepotSale.php +++ b/app/Model/DepotSale.php @@ -9,7 +9,8 @@ use Hyperf\DbConnection\Model\Model; /** * @property int $id * @property int $depot_id - * @property int $material_id + * @property int $material_id + * @property int $supplier_id * @property int $dish_id * @property string $sale_price * @property string $number @@ -37,7 +38,7 @@ class DepotSale extends Model /** * The attributes that should be cast to native types. */ - protected array $casts = ['id' => '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']; + protected array $casts = ['id' => 'integer', 'depot_id' => 'integer', 'material_id' => 'integer', 'supplier_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'; diff --git a/app/Request/Admin/DepotRequest.php b/app/Request/Admin/DepotRequest.php index 336e14e..4f690ea 100644 --- a/app/Request/Admin/DepotRequest.php +++ b/app/Request/Admin/DepotRequest.php @@ -43,7 +43,9 @@ 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' => ['depot_id','material_id','supplier_id','number','application_id','city_id','kitchen_id'], 'sale_update' => ['id','number'], + 'sale_delete' => ['id'], + 'sale_list' => ['limit','query_id','query_kitchen_id'], ]; } diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index 73a6af2..7705547 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -307,7 +307,7 @@ class DepotService extends BaseService{ $kitchenId = (int)$this->request->input('kitchen_id'); $applicationInfo = $this->MaterialApplicationModel - ->where('application_id',$applicationId) + ->where('id',$applicationId) ->first(); $materialStock = $this->MaterialStockModel @@ -320,9 +320,11 @@ class DepotService extends BaseService{ $depotSale->depot_id = $depotId; $depotSale->dish_id = $applicationInfo->dish_id; $depotSale->material_id = $materialId; + $depotSale->supplier_id = $supplierId; $depotSale->sale_price = $materialStock->unit_price; $depotSale->number = $number; $depotSale->sum_price = $depotSale->sale_price * $number; + $depotSale->application_id = $applicationId; $depotSale->city_id = $cityId; $depotSale->kitchen_id = $kitchenId; $depotSale->operator_id = $this->adminId; @@ -330,16 +332,13 @@ class DepotService extends BaseService{ //库存减少 $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->al_number = $number + $applicationInfo->al_number; + if ($applicationInfo->al_number < $applicationInfo->number) $applicationInfo->status = MaterialCode::PART_OUT; - else if ($number > $applicationInfo->num) + else + $applicationInfo->status = MaterialCode::ALL_OUT; - if (!$depotSale->save() || !$materialStock->save()) throw new ErrException('商品出库异常'); + if (!$depotSale->save() || !$materialStock->save() ||!$applicationInfo->save()) throw new ErrException('商品出库异常'); return $this->return->success(); @@ -351,11 +350,14 @@ class DepotService extends BaseService{ $info = $this->DepotSaleModel ->where('id',$id) ->first(); + $applicationInfo = $this->MaterialApplicationModel + ->where('id',$info->application_id) + ->first(); $old_number = $info->number; $number = (double)$this->request->input('number'); - $sum_price = $info->purchase_price * $number; + $sum_price = $info->sale_price * $number; $info->number = $number; $info->sum_price = $sum_price; @@ -368,11 +370,74 @@ class DepotService extends BaseService{ $materialStock->current_stock = $materialStock->current_stock + $old_number - $number; - if (!$info->save() || !$materialStock->save()) throw new ErrException('商品出库数量修改失败'); + $applicationInfo->al_number = $applicationInfo->al_number + $number - $old_number; + if ($applicationInfo->al_number < $applicationInfo->number) + $applicationInfo->status = MaterialCode::PART_OUT; + else + $applicationInfo->status = MaterialCode::ALL_OUT; + + if (!$info->save() || !$materialStock->save() || !$applicationInfo->save()) throw new ErrException('商品出库数量修改失败'); return $this->return->success(); } + public function saleDelete():array + { + $id = (int)$this->request->input('id'); + $info = $this->DepotSaleModel + ->where('is_del',MaterialCode::IS_NO_DEL) + ->where('id',$id) + ->first(); + + $applicationInfo = $this->MaterialApplicationModel + ->where('id',$info->application_id) + ->first(); + + $applicationInfo->al_number = $applicationInfo->al_number - $info->number; + if ($applicationInfo->al_number < $applicationInfo->number) + $applicationInfo->status = MaterialCode::PART_OUT; + else if ($applicationInfo->al_number == 0.00) + $applicationInfo->status = MaterialCode::AUDITED; + + $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 + $info->number; + + $info->is_del = MaterialCode::IS_DEL; + + if (!$applicationInfo->save() || !$materialStock->save() || !$info->save()) throw new ErrException('商品出库数量删除失败'); + + return $this->return->success(); + } + + public function saleList():array + { + $limit = (int)$this->request->input('limit', 10); + $id = (int)$this->request->input('query_id'); + $kitchenId = (int)$this->request->input('query_kitchen_id'); + + $list = $this->DepotSaleModel + ->leftJoin('material','depot_sale.material_id','=','material.id') + ->leftJoin('supplier','depot_sale.supplier_id','=','supplier.id') + ->leftJoin('dish','depot_sale.dish_id','=','dish.id') + ->leftJoin('depot','depot_sale.depot_id','=','depot.id') + ->leftJoin('admin_user','depot_sale.operator_id','=','admin_user.id') + ->where('depot_sale.is_del',MaterialCode::IS_NO_DEL) + ->when($id,function ($query) use ($id) { + $query->where('depot_sale.id',$id); + }) + ->when($kitchenId,function ($query) use ($kitchenId) { + $query->where('depot_sale.kitchen_id',$kitchenId); + }) + ->paginate($limit,['depot_sale.*','material.name as material_name','supplier.name as supplier_name','dish.dish as dish_name','admin_user.chinese_name as operator_name','depot.name as depot_name']) + ->toArray(); + + return $this->return->success('success',$list); + } } \ No newline at end of file diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 880d8e9..68b1563 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -444,3 +444,29 @@ GET {{host}}/api/material/application_list?limit=10 content-type: application/json Authorization: Bearer {{admin_token}} +### 商品销售出库 +POST {{host}}/admin/depot/depot_sale +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +depot_id=1&material_id=1&supplier_id=1&number=8&application_id=1&city_id=1&kitchen_id=1 + +### 商品销售出库修改数量 +POST {{host}}/admin/depot/sale_update +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +id=1&number=3 + +### 商品销售出库删除 +POST {{host}}/admin/depot/sale_delete +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +id=2 + +### 商品销售出库列表 +GET {{host}}/admin/depot/sale_list?limit=10&query_kitchen_id=1 +content-type: application/json +Authorization: Bearer {{admin_token}} + From 22dd46625427bfda5074b91b04aaa0fe27224ce9 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Sat, 8 Feb 2025 17:57:37 +0800 Subject: [PATCH 20/54] feat:depot_recycle --- app/Constants/Common/RoleCode.php | 1 + app/Controller/Admin/DepotController.php | 51 +++++++ app/Model/DepotRecycle.php | 46 ++++++ app/Model/DepotSale.php | 3 +- app/Request/Admin/DepotRequest.php | 9 ++ app/Service/Admin/Depot/DepotService.php | 170 ++++++++++++++++++++++- sync/http/admin/auth.http | 24 ++++ 7 files changed, 300 insertions(+), 4 deletions(-) create mode 100644 app/Model/DepotRecycle.php diff --git a/app/Constants/Common/RoleCode.php b/app/Constants/Common/RoleCode.php index d62956c..7fb8ab7 100644 --- a/app/Constants/Common/RoleCode.php +++ b/app/Constants/Common/RoleCode.php @@ -14,4 +14,5 @@ class RoleCode const int MARKETPLACE = 6; const int CHEF = 7; const int DRIVER = 8; + const int WAREHOUSE = 9; } \ No newline at end of file diff --git a/app/Controller/Admin/DepotController.php b/app/Controller/Admin/DepotController.php index 7678407..354923c 100644 --- a/app/Controller/Admin/DepotController.php +++ b/app/Controller/Admin/DepotController.php @@ -168,4 +168,55 @@ class DepotController { return (new DepotService)->saleList(); } + + /** + * 回收 + * @param DepotRequest $request + * @return array + * @throws Exception + */ + #[RequestMapping(path: "depot_recycle", methods: "POST")] + #[Scene(scene: "recycle")] + public function depotRecycle(DepotRequest $request): array + { + return (new DepotService)->recycle(); + } + + /** + * 回收修改数量 + * @param DepotRequest $request + * @return array + * @throws Exception + */ + #[RequestMapping(path: "recycle_update", methods: "POST")] + #[Scene(scene: "recycle_update")] + public function recycleUpdate(DepotRequest $request): array + { + return (new DepotService)->recycleUpdate(); + } + + /** + * 回收删除 + * @param DepotRequest $request + * @return array + * @throws Exception + */ + #[RequestMapping(path: "recycle_delete", methods: "POST")] + #[Scene(scene: "recycle_delete")] + public function recycleDelete(DepotRequest $request): array + { + return (new DepotService)->recycleDelete(); + } + + /** + * 回收列表 + * @param DepotRequest $request + * @return array + */ + #[RequestMapping(path: "recycle_list", methods: "GET")] + #[Scene(scene: "recycle_list")] + public function recycleList(DepotRequest $request): array + { + return (new DepotService)->recycleList(); + } } diff --git a/app/Model/DepotRecycle.php b/app/Model/DepotRecycle.php new file mode 100644 index 0000000..b58e8e7 --- /dev/null +++ b/app/Model/DepotRecycle.php @@ -0,0 +1,46 @@ + 'integer', 'depot_id' => 'integer', 'material_id' => 'integer', 'supplier_id' => 'integer', 'sale_id' => 'integer', 'status' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'operator_id' => 'integer', 'is_del' => 'integer', 'create_time' => 'datetime', 'update_time' => 'datetime']; + + const string CREATED_AT = 'create_time'; + + const string UPDATED_AT = 'update_time'; +} diff --git a/app/Model/DepotSale.php b/app/Model/DepotSale.php index 9a6328f..79e9e31 100644 --- a/app/Model/DepotSale.php +++ b/app/Model/DepotSale.php @@ -13,7 +13,8 @@ use Hyperf\DbConnection\Model\Model; * @property int $supplier_id * @property int $dish_id * @property string $sale_price - * @property string $number + * @property string $number + * @property string $back_number * @property string $sum_price * @property int $application_id * @property int $city_id diff --git a/app/Request/Admin/DepotRequest.php b/app/Request/Admin/DepotRequest.php index 4f690ea..830aa9d 100644 --- a/app/Request/Admin/DepotRequest.php +++ b/app/Request/Admin/DepotRequest.php @@ -31,6 +31,11 @@ class DepotRequest extends FormRequest 'id' => 'required|integer', 'purchase_price' => 'required', 'number' => 'required', + 'depot_id' => 'required|integer|exists:depot,id', + 'material_id' => 'required|integer|exists:material,id', + 'supplier_id' => 'required|integer|exists:supplier,id', + 'application_id' => 'required|integer|exists:material_application,id', + 'sale_id' => 'required|integer|exists:depot_sale,id', ]; } @@ -47,5 +52,9 @@ class DepotRequest extends FormRequest 'sale_update' => ['id','number'], 'sale_delete' => ['id'], 'sale_list' => ['limit','query_id','query_kitchen_id'], + 'recycle' =>['material_id','supplier_id','number','sale_id','city_id','kitchen_id'], + 'recycle_update' => ['id','number'], + 'recycle_delete' => ['id'], + 'recycle_list' => ['limit','query_id','query_kitchen_id'], ]; } diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index 7705547..3bad9dd 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -6,9 +6,11 @@ namespace App\Service\Admin\Depot; use App\Constants\Admin\DepotCode; use App\Constants\Common\MaterialCode; +use App\Constants\Common\RoleCode; use App\Exception\ErrException; use App\Model\Depot; use App\Model\DepotPurchase; +use App\Model\DepotRecycle; use App\Model\DepotSale; use App\Model\Material; use App\Model\MaterialApplication; @@ -40,6 +42,10 @@ class DepotService extends BaseService{ #[Inject] protected DepotSale $DepotSaleModel; + + #[Inject] + protected DepotRecycle $DepotRecycleModel; + #[inject] protected MaterialApplication $MaterialApplicationModel; @@ -306,6 +312,9 @@ class DepotService extends BaseService{ $cityId = (int)$this->request->input('city_id'); $kitchenId = (int)$this->request->input('kitchen_id'); + if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) + throw new ErrException('该角色没有权限'); + $applicationInfo = $this->MaterialApplicationModel ->where('id',$applicationId) ->first(); @@ -347,6 +356,10 @@ class DepotService extends BaseService{ public function saleUpdate():array { $id = (int)$this->request->input('id'); + + if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) + throw new ErrException('该角色没有权限'); + $info = $this->DepotSaleModel ->where('id',$id) ->first(); @@ -384,6 +397,10 @@ class DepotService extends BaseService{ public function saleDelete():array { $id = (int)$this->request->input('id'); + + if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) + throw new ErrException('该角色没有权限'); + $info = $this->DepotSaleModel ->where('is_del',MaterialCode::IS_NO_DEL) ->where('id',$id) @@ -394,10 +411,10 @@ class DepotService extends BaseService{ ->first(); $applicationInfo->al_number = $applicationInfo->al_number - $info->number; - if ($applicationInfo->al_number < $applicationInfo->number) - $applicationInfo->status = MaterialCode::PART_OUT; - else if ($applicationInfo->al_number == 0.00) + if ($applicationInfo->al_number <= 0) $applicationInfo->status = MaterialCode::AUDITED; + else if ($applicationInfo->al_number < $applicationInfo->number) + $applicationInfo->status = MaterialCode::PART_OUT; $materialStock = $this->MaterialStockModel ->where('depot_id',$info->depot_id) @@ -439,5 +456,152 @@ class DepotService extends BaseService{ return $this->return->success('success',$list); } + public function recycle():array + { + $materialId = (int)$this->request->input('material_id'); + $supplierId = (int)$this->request->input('supplier_id'); + $number = (double)$this->request->input('number'); + $saleId = (int)$this->request->input('sale_id'); + $cityId = (int)$this->request->input('city_id'); + $kitchenId = (int)$this->request->input('kitchen_id'); + $depotInfo = $this->DepotModel + ->getInfoByName('回收仓库',$kitchenId); + if (empty($depotInfo)) + throw new ErrException('未创建回收仓库'); + else + $depotId = $depotInfo->id; + + if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) + throw new ErrException('该角色没有权限'); + + $saleInfo = $this->DepotSaleModel + ->where('is_del',MaterialCode::IS_NO_DEL) + ->where('id',$saleId) + ->first(); + + $saleInfo->back_number = $saleInfo->back_number + $number; + if ($saleInfo->back_number > $saleInfo->number) + throw new ErrException('回收数量不能大于出库数量'); + + $materialStock = $this->MaterialStockModel + ->getMaterial($materialId,$depotId,$supplierId); + + $depotRecycle = new DepotRecycle(); + $depotRecycle->depot_id = $depotId; + $depotRecycle->material_id = $materialId; + $depotRecycle->supplier_id = $supplierId; + $depotRecycle->recycle_price = $saleInfo->sale_price; + $depotRecycle->number = $number; + $depotRecycle->sum_price = $saleInfo->sale_price * $number; + $depotRecycle->sale_id = $saleId; + $depotRecycle->status = MaterialCode::AUDITED; + $depotRecycle->city_id = $cityId; + $depotRecycle->kitchen_id = $kitchenId; + $depotRecycle->operator_id = $this->adminId; + + if (empty($materialStock)){ + $materialStock = new MaterialStock(); + $materialStock->depot_id = $depotId; + $materialStock->material_id = $materialId; + $materialStock->supplier_id = $supplierId; + $materialStock->current_stock = $number; + $materialStock->unit_price = $depotRecycle->recycle_price; + } + else + $materialStock->current_stock = $materialStock->current_stock + $number; + + if (!$saleInfo->save() || !$depotRecycle->save() || !$materialStock->save()) throw new ErrException('回收发生异常'); + + return $this->return->success(); + + } + + public function recycleUpdate():array + { + $id = (int)$this->request->input('id'); + $number = (double)$this->request->input('number'); + + if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) + throw new ErrException('该角色没有权限'); + + $info = $this->DepotRecycleModel + ->where('id',$id) + ->first(); + + $old_number = $info->number; + $sum_price = $info->recycle_price * $number; + $info->number = $number; + $info->sum_price = $sum_price; + + $materialStock = $this->MaterialStockModel + ->getMaterial($info->material_id,$info->depot_id,$info->supplier_id); + + $materialStock->current_stock = $materialStock->current_stock + $number - $old_number; + + $saleInfo = $this->DepotSaleModel + ->where('id',$info->sale_id) + ->first(); + + $saleInfo->back_number = $saleInfo->back_number + $number - $old_number; + + if (!$info->save() || !$materialStock->save() || !$saleInfo->save()) throw new ErrException('商品回收数量修改失败'); + + return $this->return->success(); + + } + + public function recycleDelete():array + { + $id = (int)$this->request->input('id'); + + if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) + throw new ErrException('该角色没有权限'); + + $info = $this->DepotRecycleModel + ->where('id',$id) + ->first(); + + $info->is_del = MaterialCode::IS_DEL; + + $materialStock = $this->MaterialStockModel + ->getMaterial($info->material_id,$info->depot_id,$info->supplier_id); + + $materialStock->current_stock = $materialStock->current_stock - $info->number; + + $saleInfo = $this->DepotSaleModel + ->where('id',$info->sale_id) + ->first(); + + $saleInfo->back_number = $saleInfo->back_number - $info->number; + + if (!$info->save() || !$materialStock->save() || !$saleInfo->save()) + throw new ErrException('商品回收删除失败'); + + return $this->return->success(); + } + + public function recycleList():array{ + + $limit = (int)$this->request->input('limit', 10); + $id = (int)$this->request->input('query_id'); + $kitchenId = (int)$this->request->input('query_kitchen_id'); + + $list = $this->DepotRecycleModel + ->leftJoin('depot','depot_recycle.depot_id','=','depot.id') + ->leftJoin('material','depot_recycle.material_id','=','material.id') + ->leftJoin('supplier','depot_recycle.supplier_id','=','supplier.id') + ->leftJoin('admin_user','depot_recycle.operator_id','=','admin_user.id') + ->where('depot_recycle.is_del',MaterialCode::IS_NO_DEL) + ->when($id,function ($query) use ($id) { + $query->where('depot_recycle.id',$id); + }) + ->when($kitchenId > 0,function($query) use($kitchenId){ + $query->where('depot_recycle.kitchen_id',$kitchenId); + }) + ->paginate($limit,['depot_recycle.*','material.name as material_name','supplier.name as supplier_name','admin_user.chinese_name as operator_name','depot.name as depot_name']) + ->toArray(); + + return $this->return->success('success',$list); + } } \ No newline at end of file diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 68b1563..8f25209 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -470,3 +470,27 @@ GET {{host}}/admin/depot/sale_list?limit=10&query_kitchen_id=1 content-type: application/json Authorization: Bearer {{admin_token}} +### 管理员回收商品 +POST {{host}}/admin/depot/depot_recycle +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +material_id=1&supplier_id=1&number=1&sale_id=2&city_id=1&kitchen_id=1 + +### 管理员修改回收数量 +POST {{host}}/admin/depot/recycle_update +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +id=2&number=2 + +### 管理员删除回收 +POST {{host}}/admin/depot/recycle_delete?id=2 +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +### 管理员查看回收列表 +GET {{host}}/admin/depot/recycle_list?limit=10&query_kitchen_id=1 +content-type: application/json +Authorization: Bearer {{admin_token}} + From 3f61e1e766179ebe51c1b8c4a86002f4501e4e94 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Mon, 10 Feb 2025 16:11:26 +0800 Subject: [PATCH 21/54] feat:depot_recycle --- app/Controller/Admin/DepotController.php | 12 ++ app/Controller/Api/DepotController.php | 73 ++++++++++++ app/Model/DepotRecycle.php | 6 + app/Model/DepotSale.php | 6 + app/Request/Admin/DepotRequest.php | 2 + app/Service/Admin/Depot/DepotService.php | 94 ++++++++++++++- app/Service/Api/Depot/DepotService.php | 139 +++++++++++++++++++++++ sync/http/admin/auth.http | 33 +++++- 8 files changed, 361 insertions(+), 4 deletions(-) create mode 100644 app/Controller/Api/DepotController.php create mode 100644 app/Service/Api/Depot/DepotService.php diff --git a/app/Controller/Admin/DepotController.php b/app/Controller/Admin/DepotController.php index 354923c..6aaddb3 100644 --- a/app/Controller/Admin/DepotController.php +++ b/app/Controller/Admin/DepotController.php @@ -219,4 +219,16 @@ class DepotController { return (new DepotService)->recycleList(); } + + /** + * 回收审核 + * @param DepotRequest $request + * @return array + */ + #[RequestMapping(path: "recycle_audit", methods: "POST")] + #[Scene(scene: "recycle_audit")] + public function recycleAudit(DepotRequest $request): array + { + return (new DepotService)->recycleAudit(); + } } diff --git a/app/Controller/Api/DepotController.php b/app/Controller/Api/DepotController.php new file mode 100644 index 0000000..6989e53 --- /dev/null +++ b/app/Controller/Api/DepotController.php @@ -0,0 +1,73 @@ +recycle(); + } + + /** + * 回收修改数量 + * @param DepotRequest $request + * @return array + * @throws Exception + */ + #[RequestMapping(path: "recycle_update", methods: "POST")] + #[Scene(scene: "recycle_update")] + public function recycleUpdate(DepotRequest $request): array + { + return (new DepotService)->recycleUpdate(); + } + + /** + * 回收删除 + * @param DepotRequest $request + * @return array + * @throws Exception + */ + #[RequestMapping(path: "recycle_delete", methods: "POST")] + #[Scene(scene: "recycle_delete")] + public function recycleDelete(DepotRequest $request): array + { + return (new DepotService)->recycleDelete(); + } + + /** + * 回收列表 + * @param DepotRequest $request + * @return array + */ + #[RequestMapping(path: "recycle_list", methods: "GET")] + #[Scene(scene: "recycle_list")] + public function recycleList(DepotRequest $request): array + { + return (new DepotService)->recycleList(); + } + +} diff --git a/app/Model/DepotRecycle.php b/app/Model/DepotRecycle.php index b58e8e7..c87f561 100644 --- a/app/Model/DepotRecycle.php +++ b/app/Model/DepotRecycle.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Model; +use Hyperf\Database\Model\Builder; use Hyperf\DbConnection\Model\Model; /** @@ -43,4 +44,9 @@ class DepotRecycle extends Model const string CREATED_AT = 'create_time'; const string UPDATED_AT = 'update_time'; + + public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null + { + return $this->where('id', $id)->first(); + } } diff --git a/app/Model/DepotSale.php b/app/Model/DepotSale.php index 79e9e31..350a6db 100644 --- a/app/Model/DepotSale.php +++ b/app/Model/DepotSale.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Model; +use Hyperf\Database\Model\Builder; use Hyperf\DbConnection\Model\Model; /** @@ -44,4 +45,9 @@ class DepotSale extends Model const string CREATED_AT = 'create_time'; const string UPDATED_AT = 'update_time'; + + public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null + { + return $this->where('id', $id)->first(); + } } diff --git a/app/Request/Admin/DepotRequest.php b/app/Request/Admin/DepotRequest.php index 830aa9d..f4efc51 100644 --- a/app/Request/Admin/DepotRequest.php +++ b/app/Request/Admin/DepotRequest.php @@ -36,6 +36,7 @@ class DepotRequest extends FormRequest 'supplier_id' => 'required|integer|exists:supplier,id', 'application_id' => 'required|integer|exists:material_application,id', 'sale_id' => 'required|integer|exists:depot_sale,id', + 'status' => 'required|integer', ]; } @@ -56,5 +57,6 @@ class DepotRequest extends FormRequest 'recycle_update' => ['id','number'], 'recycle_delete' => ['id'], 'recycle_list' => ['limit','query_id','query_kitchen_id'], + 'recycle_audit' => ['id','status'], ]; } diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index 3bad9dd..440c420 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -484,7 +484,10 @@ class DepotService extends BaseService{ throw new ErrException('回收数量不能大于出库数量'); $materialStock = $this->MaterialStockModel - ->getMaterial($materialId,$depotId,$supplierId); + ->where('material_id',$materialId) + ->where('depot_id',$depotId) + ->where('supplier_id',$supplierId) + ->first(); $depotRecycle = new DepotRecycle(); $depotRecycle->depot_id = $depotId; @@ -534,7 +537,10 @@ class DepotService extends BaseService{ $info->sum_price = $sum_price; $materialStock = $this->MaterialStockModel - ->getMaterial($info->material_id,$info->depot_id,$info->supplier_id); + ->where('material_id',$info->material_id) + ->where('depot_id',$info->depot_id) + ->where('supplier_id',$info->supplier_id) + ->first(); $materialStock->current_stock = $materialStock->current_stock + $number - $old_number; @@ -543,6 +549,8 @@ class DepotService extends BaseService{ ->first(); $saleInfo->back_number = $saleInfo->back_number + $number - $old_number; + if ($saleInfo->back_number > $saleInfo->number) + throw new ErrException('回收数量不能大于出库数量'); if (!$info->save() || !$materialStock->save() || !$saleInfo->save()) throw new ErrException('商品回收数量修改失败'); @@ -564,7 +572,10 @@ class DepotService extends BaseService{ $info->is_del = MaterialCode::IS_DEL; $materialStock = $this->MaterialStockModel - ->getMaterial($info->material_id,$info->depot_id,$info->supplier_id); + ->where('material_id',$info->material_id) + ->where('depot_id',$info->depot_id) + ->where('supplier_id',$info->supplier_id) + ->first(); $materialStock->current_stock = $materialStock->current_stock - $info->number; @@ -586,6 +597,9 @@ class DepotService extends BaseService{ $id = (int)$this->request->input('query_id'); $kitchenId = (int)$this->request->input('query_kitchen_id'); + if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) + throw new ErrException('该角色没有权限'); + $list = $this->DepotRecycleModel ->leftJoin('depot','depot_recycle.depot_id','=','depot.id') ->leftJoin('material','depot_recycle.material_id','=','material.id') @@ -604,4 +618,78 @@ class DepotService extends BaseService{ return $this->return->success('success',$list); } + public function recycleAudit():array + { + $id = (int)$this->request->input('id'); + $status = (int)$this->request->input('status'); + + if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) + throw new ErrException('该角色没有权限'); + + $info = $this->DepotRecycleModel + ->where('id',$id) + ->first(); + + if ($info->status != MaterialCode::AUDITED){ + if ($status == MaterialCode::AUDITED){ + $saleInfo = $this->DepotSaleModel + ->where('is_del',MaterialCode::IS_NO_DEL) + ->where('id',$info->sale_id) + ->first(); + + if (empty($saleInfo)){ + throw new ErrException('无出库记录'); + } + + $saleInfo->back_number = $saleInfo->back_number + $info->number; + + $materialStock = $this->MaterialStockModel + ->where('material_id',$info->material_id) + ->where('depot_id',$info->depot_id) + ->where('supplier_id',$info->supplier_id) + ->first(); + + if (empty($materialStock)){ + $materialStock = new MaterialStock(); + $materialStock->depot_id = $info->depotId; + $materialStock->material_id = $info->materialId; + $materialStock->supplier_id = $info->supplierId; + $materialStock->current_stock = $info->number; + $materialStock->unit_price = $info->recycle_price; + } + else + $materialStock->current_stock = $materialStock->current_stock + $info->number; + + if (!$materialStock->save() || !$saleInfo->save()) throw new ErrException('回收审核异常'); + + } + } + if ($info->status == MaterialCode::AUDITED){ + if ($status == MaterialCode::UN_AUDIT || $status == MaterialCode::AUDIT_REFUSE){ + $materialStock = $this->MaterialStockModel + ->where('is_del',MaterialCode::IS_NO_DEL) + ->where('material_id',$info->material_id) + ->where('depot_id',$info->depot_id) + ->where('supplier_id',$info->supplier_id) + ->first(); + + $materialStock->current_stock = $materialStock->current_stock - $info->number; + + $saleInfo = $this->DepotSaleModel + ->where('id',$info->sale_id) + ->first(); + + $saleInfo->back_number = $saleInfo->back_number - $info->number; + + if (!$materialStock->save() || !$saleInfo->save()) throw new ErrException('回收审核异常'); + } + } + + $info->status = $status; + + if (!$info->save()) throw new ErrException('回收审核异常'); + + return $this->return->success(); + + } } \ No newline at end of file diff --git a/app/Service/Api/Depot/DepotService.php b/app/Service/Api/Depot/DepotService.php new file mode 100644 index 0000000..7170251 --- /dev/null +++ b/app/Service/Api/Depot/DepotService.php @@ -0,0 +1,139 @@ +request->input('material_id'); + $supplierId = (int)$this->request->input('supplier_id'); + $number = (double)$this->request->input('number'); + $saleId = (int)$this->request->input('sale_id'); + $cityId = (int)$this->request->input('city_id'); + $kitchenId = (int)$this->request->input('kitchen_id'); + $depotInfo = $this->DepotModel + ->getInfoByName('回收仓库',$kitchenId); + if (empty($depotInfo)) + throw new ErrException('未创建回收仓库'); + else + $depotId = $depotInfo->id; + + $saleInfo = $this->DepotSaleModel->getInfoById($saleId); + + $saleInfo->back_number = $saleInfo->back_number + $number; + if ($saleInfo->back_number > $saleInfo->number) + throw new ErrException('回收数量不能大于出库数量'); + + $depotRecycle = new DepotRecycle(); + $depotRecycle->depot_id = $depotId; + $depotRecycle->material_id = $materialId; + $depotRecycle->supplier_id = $supplierId; + $depotRecycle->recycle_price = $saleInfo->sale_price; + $depotRecycle->number = $number; + $depotRecycle->sum_price = $saleInfo->sale_price * $number; + $depotRecycle->sale_id = $saleId; + $depotRecycle->status = MaterialCode::UN_AUDIT; + $depotRecycle->city_id = $cityId; + $depotRecycle->kitchen_id = $kitchenId; + $depotRecycle->operator_id = $this->userId; + + if (!$depotRecycle->save()) throw new ErrException('回收发生异常'); + + return $this->return->success(); + + } + + public function recycleUpdate():array + { + $id = (int)$this->request->input('id'); + $number = (double)$this->request->input('number'); + + $info = $this->DepotRecycleModel->getInfoById($id); + + if ($info->status == MaterialCode::AUDITED) throw new ErrException('记录已审核通过'); + + $old_number = $info->number; + $sum_price = $info->recycle_price * $number; + $info->number = $number; + $info->sum_price = $sum_price; + $info->status = MaterialCode::UN_AUDIT; + + $saleInfo = $this->DepotSaleModel->getInfoById($info->sale_id); + + $saleInfo->back_number = $saleInfo->back_number + $number - $old_number; + if ($saleInfo->back_number > $saleInfo->number) throw new ErrException('回收数量不能大于出库数量'); + + if (!$info->save()) throw new ErrException('商品回收数量修改失败'); + + return $this->return->success(); + + } + + public function recycleDelete():array + { + $id = (int)$this->request->input('id'); + + $info = $this->DepotRecycleModel->getInfoById($id); + if ($info->status == MaterialCode::AUDITED) throw new ErrException('该记录已审核通过'); + + $info->is_del = MaterialCode::IS_DEL; + + if (!$info->save()) + throw new ErrException('回收删除失败'); + + return $this->return->success(); + } + + public function recycleList():array + { + $limit = (int)$this->request->input('limit', 10); + $id = (int)$this->request->input('query_id'); + $kitchenId = (int)$this->request->input('query_kitchen_id'); + + $list = $this->DepotRecycleModel + ->leftJoin('depot','depot_recycle.depot_id','=','depot.id') + ->leftJoin('material','depot_recycle.material_id','=','material.id') + ->leftJoin('supplier','depot_recycle.supplier_id','=','supplier.id') + ->leftJoin('admin_user','depot_recycle.operator_id','=','admin_user.id') + ->where('depot_recycle.is_del',MaterialCode::IS_NO_DEL) + ->where('depot_recycle.operator_id',$this->userId) + ->when($id,function ($query) use ($id) { + $query->where('depot_recycle.id',$id); + }) + ->when($kitchenId > 0,function($query) use($kitchenId){ + $query->where('depot_recycle.kitchen_id',$kitchenId); + }) + ->paginate($limit,['depot_recycle.*','material.name as material_name','supplier.name as supplier_name','admin_user.chinese_name as operator_name','depot.name as depot_name']) + ->toArray(); + + return $this->return->success('success',$list); + } + +} \ No newline at end of file diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 8f25209..b3214a3 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -485,7 +485,7 @@ Authorization: Bearer {{admin_token}} id=2&number=2 ### 管理员删除回收 -POST {{host}}/admin/depot/recycle_delete?id=2 +POST {{host}}/admin/depot/recycle_delete?id=3 Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{admin_token}} @@ -494,3 +494,34 @@ GET {{host}}/admin/depot/recycle_list?limit=10&query_kitchen_id=1 content-type: application/json Authorization: Bearer {{admin_token}} +### 管理员审核回收 +POST {{host}}/admin/depot/recycle_audit +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +id=3&status=2 + +### 厨师回收商品 +POST {{host}}/api/depot/depot_recycle +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +material_id=1&supplier_id=1&number=3&sale_id=2&city_id=1&kitchen_id=1 + +### 厨师修改回收数量 +POST {{host}}/api/depot/recycle_update +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +id=3&number=3 + +### 厨师删除回收 +POST {{host}}/api/depot/recycle_delete?id=3 +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +### 厨师查看回收列表 +GET {{host}}/api/depot/recycle_list?limit=10&query_kitchen_id=1 +content-type: application/json +Authorization: Bearer {{admin_token}} + From 6fd4f1b455ea06dae33dc72addf85d8b49853650 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Tue, 11 Feb 2025 10:13:15 +0800 Subject: [PATCH 22/54] feat:material --- app/Controller/Admin/MaterialController.php | 13 ++++++++ app/Request/Admin/MaterialRequest.php | 1 + .../Admin/Material/MaterialService.php | 31 +++++++++++++++++++ app/Service/Admin/System/ChefService.php | 19 +++++++----- app/Service/Api/Material/MaterialService.php | 1 - 5 files changed, 57 insertions(+), 8 deletions(-) diff --git a/app/Controller/Admin/MaterialController.php b/app/Controller/Admin/MaterialController.php index 3edb9e0..faa82da 100644 --- a/app/Controller/Admin/MaterialController.php +++ b/app/Controller/Admin/MaterialController.php @@ -66,4 +66,17 @@ class MaterialController return (new MaterialService())->edit(); } + /** + * 材料库存列表 + * @param MaterialRequest $request + * @return array + */ + #[RequestMapping(path: "materialStock_list", methods: "GET")] + #[Scene(scene: "materialStock_list")] + public function materialStockList(MaterialRequest $request): array + { + return (new MaterialService())->materialStockList(); + } + + } diff --git a/app/Request/Admin/MaterialRequest.php b/app/Request/Admin/MaterialRequest.php index b3ef04c..5f8d5e7 100644 --- a/app/Request/Admin/MaterialRequest.php +++ b/app/Request/Admin/MaterialRequest.php @@ -40,5 +40,6 @@ class MaterialRequest extends FormRequest 'material_add' => ['category_id', 'name', 'standard', 'unit', 'bar_code', 'city_id', 'kitchen_id'], 'material_edit' => ['id','category_id', 'name', 'standard', 'unit', 'bar_code','status'], 'material_delete' => ['id'], + 'materialStock_list' => ['limit','query_name','query_depotId','query_supplierId'], ]; } diff --git a/app/Service/Admin/Material/MaterialService.php b/app/Service/Admin/Material/MaterialService.php index fc19240..37b1f7a 100644 --- a/app/Service/Admin/Material/MaterialService.php +++ b/app/Service/Admin/Material/MaterialService.php @@ -7,6 +7,7 @@ namespace App\Service\Admin\Material; use App\Constants\Common\MaterialCode; use App\Exception\ErrException; use App\Model\Material; +use App\Model\MaterialStock; use App\Service\Admin\BaseService; use Hyperf\Di\Annotation\Inject; @@ -18,6 +19,9 @@ class MaterialService extends BaseService{ #[Inject] protected Material $MaterialModel; + #[Inject] + protected MaterialStock $MaterialStockModel; + public function handle() { @@ -99,4 +103,31 @@ class MaterialService extends BaseService{ return $this->return->success(); } + + public function materialStockList(): array + { + $limit = (int)$this->request->input('limit', 10); + $name = $this->request->input('query_name'); + $depotId = (int)$this->request->input('query_depotId'); + $supplierId = (int)$this->request->input('query_supplierId'); + $list = $this->MaterialStockModel + ->leftJoin('material', 'material_stock.material_id', '=', 'material.id') + ->leftJoin('supplier', 'material_stock.supplier_id', '=', 'supplier.id') + ->leftJoin('depot', 'material_stock.depot_id', '=', 'depot.id') + ->where('material_stock.is_del',MaterialCode::IS_NO_DEL) + ->when(!empty($name), function ($query) use ($name) { + $query->where('material.name', 'like', "$name%"); + }) + ->when(!empty($depotId), function ($query) use ($depotId) { + $query->where('material_stock.depot_id', $depotId); + }) + ->when(!empty($supplierId), function ($query) use ($supplierId) { + $query->where('material_stock.supplier_id', $supplierId); + }) + ->paginate($limit,['material_stock.*','material.name as material_name','supplier.name as supplier_name','depot.name as depot_name']) + ->toArray(); + + return $this->return->success('success',$list); + } + } \ No newline at end of file diff --git a/app/Service/Admin/System/ChefService.php b/app/Service/Admin/System/ChefService.php index fe975b2..ea873b9 100644 --- a/app/Service/Admin/System/ChefService.php +++ b/app/Service/Admin/System/ChefService.php @@ -53,22 +53,27 @@ class ChefService extends BaseService public function chefDetailList(): array { - $chefId = (int)$this->request->input('chef_id'); + $limit = (int)$this->request->input('limit', 10); + $cityId = (int)$this->request->input('query_city_id'); + $name = $this->request->input('query_chef_name'); $list = $this - ->adminUserModel - ->leftJoin('chef', 'admin_user.id', '=', 'chef.user_id') + ->chefModel + ->leftJoin('admin_user', 'admin_user.id', '=', 'chef.user_id') ->where('admin_user.is_del',UserCode::IS_NO_DEL) ->where('admin_user.status',UserCode::ENABLE) ->where('admin_user.role_id',RoleCode::CHEF) - ->when(!empty($chefId), function ($query) use ($chefId) { - $query->where('admin_user.id', $chefId); + ->when(!empty($cityId), function ($query) use ($cityId) { + $query->where('admin_user.city_id', $cityId); }) - ->get(['admin_user.id','admin_user.avatar','admin_user.chinese_name','chef.profile','chef.specialties']); + ->when(!empty($name), function ($query) use ($name) { + $query->where('admin_user.chinese_name', 'like', "$name%"); + }) + ->paginate($limit,['chef.id','admin_user.avatar','admin_user.chinese_name','chef.profile','chef.specialties'])->toArray(); if (empty($list)) return $this->return->success('success',['list' => []]); - return $this->return->success('success',['list' => $list->toArray()]); + return $this->return->success('success',['list' => $list]); } /** diff --git a/app/Service/Api/Material/MaterialService.php b/app/Service/Api/Material/MaterialService.php index e360e8e..6ee1d5f 100644 --- a/app/Service/Api/Material/MaterialService.php +++ b/app/Service/Api/Material/MaterialService.php @@ -90,7 +90,6 @@ class MaterialService extends BaseService{ if($info->status == MaterialCode::AUDIT_REFUSE){ $info->status = MaterialCode::UN_AUDIT; } - $info->operator_id = $this->userId; if (!$info->save()) throw new ErrException('申请修改失败'); From f0cab985d484b0b4ce1504690e8840c556ea989c Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Tue, 11 Feb 2025 14:18:51 +0800 Subject: [PATCH 23/54] feat:chef --- app/Model/Chef.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Model/Chef.php b/app/Model/Chef.php index 761f072..a04a59e 100644 --- a/app/Model/Chef.php +++ b/app/Model/Chef.php @@ -12,7 +12,8 @@ use Hyperf\DbConnection\Model\Model; * @property int $id * @property int $user_id * @property string $profile - * @property string $specialties + * @property string $specialties + * @property int $kitchen_id * @property int $is_del * @property string $create_time * @property string $update_time @@ -32,7 +33,7 @@ class Chef extends Model /** * The attributes that should be cast to native types. */ - protected array $casts = ['id' => 'integer', 'user_id' => 'integer', 'is_del' => 'integer']; + protected array $casts = ['id' => 'integer', 'user_id' => 'integer', 'kitchen_id' => 'integer', 'is_del' => 'integer']; const string CREATED_AT = 'create_time'; From 8321940169c7bded2384065cc92dcecead1ca2ea Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Tue, 11 Feb 2025 14:47:53 +0800 Subject: [PATCH 24/54] feat:material --- app/Request/Admin/MaterialRequest.php | 4 ++-- app/Request/Api/MaterialRequest.php | 2 ++ app/Service/Admin/Material/MaterialService.php | 8 ++++++++ sync/http/admin/auth.http | 5 +++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/Request/Admin/MaterialRequest.php b/app/Request/Admin/MaterialRequest.php index 5f8d5e7..8a19766 100644 --- a/app/Request/Admin/MaterialRequest.php +++ b/app/Request/Admin/MaterialRequest.php @@ -36,10 +36,10 @@ class MaterialRequest extends FormRequest } protected array $scenes = [ - 'material_list' => ['limit','query_name'], + 'material_list' => ['limit','query_name','query_kitchenId'], 'material_add' => ['category_id', 'name', 'standard', 'unit', 'bar_code', 'city_id', 'kitchen_id'], 'material_edit' => ['id','category_id', 'name', 'standard', 'unit', 'bar_code','status'], 'material_delete' => ['id'], - 'materialStock_list' => ['limit','query_name','query_depotId','query_supplierId'], + 'materialStock_list' => ['limit','query_name','query_depotId','query_supplierId','query_kitchenId'], ]; } diff --git a/app/Request/Api/MaterialRequest.php b/app/Request/Api/MaterialRequest.php index 93cc127..cdff404 100644 --- a/app/Request/Api/MaterialRequest.php +++ b/app/Request/Api/MaterialRequest.php @@ -24,6 +24,8 @@ class MaterialRequest extends FormRequest return [ 'limit' => 'required|integer', 'query_name' =>'sometimes|string', + 'city_id' => 'sometimes|integer|exists:system_city,id', + 'kitchen_id' => 'sometimes|integer|exists:kitchen,id', ]; } diff --git a/app/Service/Admin/Material/MaterialService.php b/app/Service/Admin/Material/MaterialService.php index 37b1f7a..80bf21a 100644 --- a/app/Service/Admin/Material/MaterialService.php +++ b/app/Service/Admin/Material/MaterialService.php @@ -31,6 +31,7 @@ class MaterialService extends BaseService{ { $limit = (int)$this->request->input('limit', 10); $name = $this->request->input('query_name'); + $kitchenId = $this->request->input('query_kitchen_id'); $list = $this ->MaterialModel @@ -39,6 +40,9 @@ class MaterialService extends BaseService{ ->when(!empty($name), function ($query) use ($name) { $query->where('name', 'like', "$name%"); }) + ->when(!empty($kitchenId), function ($query) use ($kitchenId) { + $query->where('kitchen_id', $kitchenId); + }) ->paginate($limit)->toArray(); return $this->return->success('success',$list); @@ -110,6 +114,7 @@ class MaterialService extends BaseService{ $name = $this->request->input('query_name'); $depotId = (int)$this->request->input('query_depotId'); $supplierId = (int)$this->request->input('query_supplierId'); + $kitchenId = (int)$this->request->input('query_kitchenId'); $list = $this->MaterialStockModel ->leftJoin('material', 'material_stock.material_id', '=', 'material.id') ->leftJoin('supplier', 'material_stock.supplier_id', '=', 'supplier.id') @@ -124,6 +129,9 @@ class MaterialService extends BaseService{ ->when(!empty($supplierId), function ($query) use ($supplierId) { $query->where('material_stock.supplier_id', $supplierId); }) + ->when(!empty($kitchenId), function ($query) use ($kitchenId) { + $query->where('material.kitchen_id', $kitchenId); + }) ->paginate($limit,['material_stock.*','material.name as material_name','supplier.name as supplier_name','depot.name as depot_name']) ->toArray(); diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index b3214a3..642e931 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -348,6 +348,11 @@ Authorization: Bearer {{admin_token}} id=1&category_id=2&name=冻猪肉&standard=2斤/包&unit=包&bar_code=1003&status=1 +### 材料库存列表 +GET {{host}}/admin/material/materialStock_list?limit=10 +content-type: application/json +Authorization: Bearer {{admin_token}} + ### 供应商列表 GET {{host}}/admin/supplier/list?limit=10 content-type: application/json From c96ecc259477bc60d265478439498cfd32e1e8f5 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Tue, 11 Feb 2025 17:54:00 +0800 Subject: [PATCH 25/54] feat:warehouseKeeper --- .../Admin/WarehouseKeeperController.php | 45 +++++++++++ app/Model/WarehouseKeeper.php | 48 ++++++++++++ app/Request/Admin/ChefRequest.php | 5 +- app/Request/Admin/WarehouseKeeperRequest.php | 44 +++++++++++ app/Service/Admin/System/WarehouseService.php | 75 +++++++++++++++++++ app/Service/Admin/User/EmployeeService.php | 11 +++ 6 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 app/Controller/Admin/WarehouseKeeperController.php create mode 100644 app/Model/WarehouseKeeper.php create mode 100644 app/Request/Admin/WarehouseKeeperRequest.php create mode 100644 app/Service/Admin/System/WarehouseService.php diff --git a/app/Controller/Admin/WarehouseKeeperController.php b/app/Controller/Admin/WarehouseKeeperController.php new file mode 100644 index 0000000..0cc0bf2 --- /dev/null +++ b/app/Controller/Admin/WarehouseKeeperController.php @@ -0,0 +1,45 @@ +warehouseList(); + } + + /** + * 设置仓管数据 + * @param WarehouseKeeperRequest $request + * @return array + */ + #[RequestMapping(path: "setting_warehouse_keeper", methods: "POST")] + #[Scene(scene: "setting_warehouse_keeper")] + public function settingWarehouseKeeper(WarehouseKeeperRequest $request) + { + return (new WarehouseService())->settingWarehouse(); + } +} \ No newline at end of file diff --git a/app/Model/WarehouseKeeper.php b/app/Model/WarehouseKeeper.php new file mode 100644 index 0000000..51ac7ed --- /dev/null +++ b/app/Model/WarehouseKeeper.php @@ -0,0 +1,48 @@ + 'integer', 'user_id' => 'integer', 'kitchen_id' => 'integer', 'is_del' => 'integer']; + + const string CREATED_AT = 'create_time'; + + const string UPDATED_AT = 'update_time'; + + /** + * @param int $userId + * @return Builder|\Hyperf\Database\Model\Model|null + */ + public function getInfoByUserId(int $userId): \Hyperf\Database\Model\Model|Builder|null + { + return $this->where('is_del',UserCode::IS_NO_DEL)->where('user_id', $userId)->first(); + } +} diff --git a/app/Request/Admin/ChefRequest.php b/app/Request/Admin/ChefRequest.php index 0c29ab6..d985e32 100644 --- a/app/Request/Admin/ChefRequest.php +++ b/app/Request/Admin/ChefRequest.php @@ -29,6 +29,7 @@ class ChefRequest extends FormRequest 'user_id' =>'required|integer|exists:chef,user_id', 'profile' =>'sometimes', 'specialties' =>'sometimes', + 'query_city_id' => 'sometimes|integer|exists:system_city,id', ]; } @@ -39,7 +40,9 @@ class ChefRequest extends FormRequest 'query_chef_id' ], 'chef_detail_list' => [ - 'chef_id', + 'limit', + 'query_city_id', + 'query_chef_name' ], 'setting_chef' => [ 'user_id', diff --git a/app/Request/Admin/WarehouseKeeperRequest.php b/app/Request/Admin/WarehouseKeeperRequest.php new file mode 100644 index 0000000..1734000 --- /dev/null +++ b/app/Request/Admin/WarehouseKeeperRequest.php @@ -0,0 +1,44 @@ + 'required|integer', + 'query_name' =>'sometimes|string', + 'query_city_id' =>'sometimes|integer|exists:system_city,id', + 'user_id' =>'required|integer|exists:warehouse_keeper,user_id', + 'kitchen_id' =>'integer|exists:kitchen,id', + ]; + } + + protected array $scenes = [ + 'warehouse_list' => [ + 'limit', + 'query_city_id', + 'query_name' + ], + 'setting_warehouse' => [ + 'user_id', + 'kitchen_id', + ], + ]; +} diff --git a/app/Service/Admin/System/WarehouseService.php b/app/Service/Admin/System/WarehouseService.php new file mode 100644 index 0000000..78e0d19 --- /dev/null +++ b/app/Service/Admin/System/WarehouseService.php @@ -0,0 +1,75 @@ +request->input('limit', 10); + $cityId = (int)$this->request->input('query_city_id'); + $name = $this->request->input('query_name'); + + $list = $this + ->warehouseKeeperModel + ->leftJoin('admin_user', 'admin_user.id', '=', 'warehouse_keeper.user_id') + ->where('admin_user.is_del',UserCode::IS_NO_DEL) + ->where('admin_user.status',UserCode::ENABLE) + ->where('admin_user.role_id',RoleCode::WAREHOUSE) + ->when(!empty($cityId), function ($query) use ($cityId) { + $query->where('admin_user.city_id', $cityId); + }) + ->when(!empty($name), function ($query) use ($name) { + $query->where('admin_user.chinese_name', 'like', "$name%"); + }) + ->paginate($limit,['warehouse_keeper.id','admin_user.avatar','admin_user.chinese_name','warehouse_keeper.kitchen_id'])->toArray(); + + if (empty($list)) return $this->return->success('success',['list' => []]); + + return $this->return->success('success',['list' => $list]); + } + + public function settingWarehouse(): array + { + $userId = (int)$this->request->input('user_id'); + $kitchenId = (int)$this->request->input('kitchen_id'); + $info = $this->warehouseKeeperModel->getInfoByUserId($userId); + + if (!empty($info)) { + if(!empty($kitchenId)) + $info->kitchen_id = $kitchenId; + } else { + throw new ErrException('设置厨师信息失败'); + } + if (!$info->save()) throw new ErrException('设置厨师信息失败'); + + return $this->return->success(); + } +} \ No newline at end of file diff --git a/app/Service/Admin/User/EmployeeService.php b/app/Service/Admin/User/EmployeeService.php index 0e50594..683008f 100644 --- a/app/Service/Admin/User/EmployeeService.php +++ b/app/Service/Admin/User/EmployeeService.php @@ -19,6 +19,7 @@ use App\Model\AdminRole; use App\Model\AdminUser; use App\Model\Chef; use App\Model\DriverSequence; +use App\Model\WarehouseKeeper; use App\Service\Admin\BaseService; use Exception; use Hyperf\Di\Annotation\Inject; @@ -112,6 +113,7 @@ class EmployeeService extends BaseService ]), RoleCode::CHEF => $this->addChef($model->id), + RoleCode::WAREHOUSE => $this->addWarehouseKeeper($model->id), default => true, }; @@ -126,6 +128,12 @@ class EmployeeService extends BaseService $chef->user_id = $id; return $chef->save(); } + public function addWarehouseKeeper($id): bool + { + $warehouseKeeper = new WarehouseKeeper(); + $warehouseKeeper->user_id = $id; + return $warehouseKeeper->save(); + } /** * 修改 @@ -152,6 +160,7 @@ class EmployeeService extends BaseService $del = match ($info->role_id) { RoleCode::DRIVER => (new DriverSequence)->where('driver_id', $info->id)->delete(), RoleCode::CHEF => (new Chef)->where('user_id', $info->id)->delete(), + RoleCode::WAREHOUSE => (new WarehouseKeeper)->where('user_id', $info->id)->delete(), default => true, }; @@ -160,6 +169,7 @@ class EmployeeService extends BaseService 'driver_id' => $info->id, ]), RoleCode::CHEF => $this->addChef($info->id), + RoleCode::WAREHOUSE => $this->addWarehouseKeeper($info->id), default => true, }; @@ -199,6 +209,7 @@ class EmployeeService extends BaseService $del = match ($info->role_id) { RoleCode::DRIVER => (new DriverSequence)->where('driver_id', $info->id)->update(['is_del' => UserCode::IS_DEL]), RoleCode::CHEF => (new Chef)->where('user_id', $info->id)->update(['is_del' => UserCode::IS_DEL]), + RoleCode::WAREHOUSE => (new WarehouseKeeper)->where('user_id', $info->id)->update(['is_del' => UserCode::IS_DEL]), default => true, }; From 4250db59b83af4b809d5c1c388477edfd02578f2 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Wed, 12 Feb 2025 09:46:41 +0800 Subject: [PATCH 26/54] feat:material --- app/Request/Admin/MaterialRequest.php | 2 +- app/Request/Api/MaterialRequest.php | 8 +++++--- app/Service/Admin/Material/MaterialService.php | 4 ++++ app/Service/Api/Material/MaterialService.php | 4 ++++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/Request/Admin/MaterialRequest.php b/app/Request/Admin/MaterialRequest.php index 8a19766..61502d3 100644 --- a/app/Request/Admin/MaterialRequest.php +++ b/app/Request/Admin/MaterialRequest.php @@ -40,6 +40,6 @@ class MaterialRequest extends FormRequest 'material_add' => ['category_id', 'name', 'standard', 'unit', 'bar_code', 'city_id', 'kitchen_id'], 'material_edit' => ['id','category_id', 'name', 'standard', 'unit', 'bar_code','status'], 'material_delete' => ['id'], - 'materialStock_list' => ['limit','query_name','query_depotId','query_supplierId','query_kitchenId'], + 'materialStock_list' => ['limit','query_name','query_materialId','query_depotId','query_supplierId','query_kitchenId'], ]; } diff --git a/app/Request/Api/MaterialRequest.php b/app/Request/Api/MaterialRequest.php index cdff404..d28c957 100644 --- a/app/Request/Api/MaterialRequest.php +++ b/app/Request/Api/MaterialRequest.php @@ -24,13 +24,15 @@ class MaterialRequest extends FormRequest return [ 'limit' => 'required|integer', 'query_name' =>'sometimes|string', - 'city_id' => 'sometimes|integer|exists:system_city,id', - 'kitchen_id' => 'sometimes|integer|exists:kitchen,id', + 'query_kitchen_id' =>'sometimes|integer|exists:kitchen,id', + 'city_id' => 'required|integer|exists:system_city,id', + 'kitchen_id' => 'required|integer|exists:kitchen,id', + 'id' => 'required|integer|exists:material_application,id', ]; } protected array $scenes = [ - 'material_list' => ['limit','query_name'], + 'material_list' => ['limit','query_name','query_kitchen_id'], 'material_application' => ['material_id','dish_id','number','processing','city_id','kitchen_id'], 'application_edit' => ['id','number','processing'], 'application_delete' => ['id'], diff --git a/app/Service/Admin/Material/MaterialService.php b/app/Service/Admin/Material/MaterialService.php index 80bf21a..85371df 100644 --- a/app/Service/Admin/Material/MaterialService.php +++ b/app/Service/Admin/Material/MaterialService.php @@ -112,6 +112,7 @@ class MaterialService extends BaseService{ { $limit = (int)$this->request->input('limit', 10); $name = $this->request->input('query_name'); + $materialId = $this->request->input('query_materialId'); $depotId = (int)$this->request->input('query_depotId'); $supplierId = (int)$this->request->input('query_supplierId'); $kitchenId = (int)$this->request->input('query_kitchenId'); @@ -123,6 +124,9 @@ class MaterialService extends BaseService{ ->when(!empty($name), function ($query) use ($name) { $query->where('material.name', 'like', "$name%"); }) + ->when(!empty($materialId), function ($query) use ($materialId) { + $query->where('material_stock.material_id', $materialId); + }) ->when(!empty($depotId), function ($query) use ($depotId) { $query->where('material_stock.depot_id', $depotId); }) diff --git a/app/Service/Api/Material/MaterialService.php b/app/Service/Api/Material/MaterialService.php index 6ee1d5f..a32991e 100644 --- a/app/Service/Api/Material/MaterialService.php +++ b/app/Service/Api/Material/MaterialService.php @@ -31,6 +31,7 @@ class MaterialService extends BaseService{ { $limit = (int)$this->request->input('limit', 10); $name = $this->request->input('query_name'); + $kitchenId = $this->request->input('query_kitchen_id'); $list = $this ->MaterialModel @@ -39,6 +40,9 @@ class MaterialService extends BaseService{ ->when(!empty($name), function ($query) use ($name) { $query->where('name', 'like', "$name%"); }) + ->when(!empty($kitchenId), function ($query) use ($kitchenId) { + $query->where('kitchen_id', $kitchenId); + }) ->paginate($limit)->toArray(); return $this->return->success('success',$list); From 8d5dc6ef229ea39eea403ce325aff321fccaa46f Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Wed, 12 Feb 2025 14:46:22 +0800 Subject: [PATCH 27/54] feat:warehouse_keeper --- app/Controller/Admin/WarehouseKeeperController.php | 2 +- app/Request/Admin/WarehouseKeeperRequest.php | 4 ++-- app/Service/Admin/System/WarehouseService.php | 2 +- sync/http/admin/auth.http | 11 +++++++++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/Controller/Admin/WarehouseKeeperController.php b/app/Controller/Admin/WarehouseKeeperController.php index 0cc0bf2..f8b3818 100644 --- a/app/Controller/Admin/WarehouseKeeperController.php +++ b/app/Controller/Admin/WarehouseKeeperController.php @@ -20,7 +20,7 @@ use Hyperf\Validation\Annotation\Scene; class WarehouseKeeperController { /** - * 厨师详细列表 + * 仓管详细列表 * @param WarehouseKeeperRequest $request * @return array */ diff --git a/app/Request/Admin/WarehouseKeeperRequest.php b/app/Request/Admin/WarehouseKeeperRequest.php index 1734000..a234c7c 100644 --- a/app/Request/Admin/WarehouseKeeperRequest.php +++ b/app/Request/Admin/WarehouseKeeperRequest.php @@ -31,12 +31,12 @@ class WarehouseKeeperRequest extends FormRequest } protected array $scenes = [ - 'warehouse_list' => [ + 'warehouse_keeper_list' => [ 'limit', 'query_city_id', 'query_name' ], - 'setting_warehouse' => [ + 'setting_warehouse_keeper' => [ 'user_id', 'kitchen_id', ], diff --git a/app/Service/Admin/System/WarehouseService.php b/app/Service/Admin/System/WarehouseService.php index 78e0d19..5800ed3 100644 --- a/app/Service/Admin/System/WarehouseService.php +++ b/app/Service/Admin/System/WarehouseService.php @@ -49,7 +49,7 @@ class WarehouseService extends BaseService{ ->when(!empty($name), function ($query) use ($name) { $query->where('admin_user.chinese_name', 'like', "$name%"); }) - ->paginate($limit,['warehouse_keeper.id','admin_user.avatar','admin_user.chinese_name','warehouse_keeper.kitchen_id'])->toArray(); + ->paginate($limit,['warehouse_keeper.id','admin_user.avatar','admin_user.chinese_name','admin_user.city_id','warehouse_keeper.kitchen_id'])->toArray(); if (empty($list)) return $this->return->success('success',['list' => []]); diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 642e931..bfa7f7a 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -530,3 +530,14 @@ GET {{host}}/api/depot/recycle_list?limit=10&query_kitchen_id=1 content-type: application/json Authorization: Bearer {{admin_token}} +### 仓管详细列表 +GET {{host}}/admin/warehouse_keeper/warehouse_keeper_list?limit=10&query_city_id=1 +content-type: application/json +Authorization: Bearer {{admin_token}} + +### 设置仓管数据 +POST {{host}}/admin/warehouse_keeper/setting_warehouse_keeper +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +user_id=5&kitchen_id=1 From 0d6694a7c8eb0b9c7d83c3286137a5f1918457a2 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Wed, 12 Feb 2025 16:02:18 +0800 Subject: [PATCH 28/54] fix:dish --- app/Controller/Admin/DishController.php | 2 +- app/Service/Admin/{Good => Material}/DishService.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename app/Service/Admin/{Good => Material}/DishService.php (97%) diff --git a/app/Controller/Admin/DishController.php b/app/Controller/Admin/DishController.php index 7dca1ca..45c7e4b 100644 --- a/app/Controller/Admin/DishController.php +++ b/app/Controller/Admin/DishController.php @@ -6,7 +6,7 @@ namespace App\Controller\Admin; use App\Middleware\Admin\JwtAuthMiddleware; use App\Request\Admin\DishRequest; -use App\Service\Admin\Good\DishService; +use App\Service\Admin\Material\DishService; use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Middlewares; use Hyperf\HttpServer\Annotation\RequestMapping; diff --git a/app/Service/Admin/Good/DishService.php b/app/Service/Admin/Material/DishService.php similarity index 97% rename from app/Service/Admin/Good/DishService.php rename to app/Service/Admin/Material/DishService.php index cf6b9f4..a5b7a4a 100644 --- a/app/Service/Admin/Good/DishService.php +++ b/app/Service/Admin/Material/DishService.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Service\Admin\Good; +namespace App\Service\Admin\Material; use App\Constants\Common\DishCode; use App\Model\Dish; From ac3b9a569279de7ec7e1911c9cfd1e0f5b84de17 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Wed, 12 Feb 2025 17:28:17 +0800 Subject: [PATCH 29/54] fix:warehouse_keeper --- app/Service/Admin/System/WarehouseService.php | 4 ++-- sync/http/admin/auth.http | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Service/Admin/System/WarehouseService.php b/app/Service/Admin/System/WarehouseService.php index 5800ed3..f9863d4 100644 --- a/app/Service/Admin/System/WarehouseService.php +++ b/app/Service/Admin/System/WarehouseService.php @@ -66,9 +66,9 @@ class WarehouseService extends BaseService{ if(!empty($kitchenId)) $info->kitchen_id = $kitchenId; } else { - throw new ErrException('设置厨师信息失败'); + throw new ErrException('设置仓管信息失败'); } - if (!$info->save()) throw new ErrException('设置厨师信息失败'); + if (!$info->save()) throw new ErrException('设置仓管信息失败'); return $this->return->success(); } diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index bfa7f7a..1925073 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -535,7 +535,7 @@ GET {{host}}/admin/warehouse_keeper/warehouse_keeper_list?limit=10&query_city_id content-type: application/json Authorization: Bearer {{admin_token}} -### 设置仓管数据 +### 设置仓管所在厨房 POST {{host}}/admin/warehouse_keeper/setting_warehouse_keeper Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{admin_token}} From 5b4eef567527b7876ce79a62f658f342c9d3bf01 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Thu, 13 Feb 2025 10:48:55 +0800 Subject: [PATCH 30/54] feat:depot_purchase --- app/Constants/Admin/DepotCode.php | 7 +++++++ app/Model/DepotPurchase.php | 3 ++- app/Service/Admin/Depot/DepotService.php | 4 +++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/Constants/Admin/DepotCode.php b/app/Constants/Admin/DepotCode.php index e986136..e8ef12c 100644 --- a/app/Constants/Admin/DepotCode.php +++ b/app/Constants/Admin/DepotCode.php @@ -14,4 +14,11 @@ class DepotCode extends AbstractConstants const int IS_NO_DEL = 1; const int IS_DEL = 2; + + /*** + * @var int 1=已入库 2=已出库 + */ + const INT INPUT = 1; + + const INT OUTPUT = 2; } \ No newline at end of file diff --git a/app/Model/DepotPurchase.php b/app/Model/DepotPurchase.php index c943923..666a2da 100644 --- a/app/Model/DepotPurchase.php +++ b/app/Model/DepotPurchase.php @@ -16,6 +16,7 @@ use Hyperf\DbConnection\Model\Model; * @property string $purchase_price * @property string $number * @property string $sum_price + * @property int $status * @property int $city_id * @property int $kitchen_id * @property int $operator_id @@ -38,7 +39,7 @@ class DepotPurchase extends Model /** * The attributes that should be cast to native types. */ - protected array $casts = ['id' => 'integer', 'depot_id' => 'integer', 'material_id' => 'integer', 'supplier_id' => 'integer', 'type' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'operator_id' => 'integer', 'is_del' => 'integer']; + protected array $casts = ['id' => 'integer', 'depot_id' => 'integer', 'material_id' => 'integer', 'supplier_id' => 'integer', 'type' => 'integer', 'status' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'operator_id' => 'integer', 'is_del' => 'integer']; const CREATED_AT = 'create_time'; diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index 440c420..0a9c694 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -173,6 +173,7 @@ class DepotService extends BaseService{ $depotPurchase->purchase_price = $purchase_price; $depotPurchase->number = $number; $depotPurchase->sum_price = $sum_price; + $depotPurchase->status = DepotCode::INPUT; $depotPurchase->city_id = $cityId; $depotPurchase->kitchen_id = $kitchenId; $depotPurchase->operator_id = $this->adminId; @@ -233,6 +234,7 @@ class DepotService extends BaseService{ $id = (int)$this->request->input('id'); // $number = (double)$this->request->input('number'); $info = $this->DepotPurchaseModel->getDepotPurchase($id); + $info->status = DepotCode::OUTPUT; if (!empty($info)){ $depotPurchase = new DepotPurchase(); $depotPurchase->depot_id = $info->depot_id; @@ -270,7 +272,7 @@ class DepotService extends BaseService{ $materialStock->current_stock = $materialStock->current_stock - $depotPurchase->number; } - if (!$depotPurchase->save() || !$materialStock->save()) throw new ErrException('采购退货失败'); + if (!$depotPurchase->save() || !$materialStock->save() || !$info->save()) throw new ErrException('采购退货异常'); return $this->return->success(); } From 9084f39837bfd7a53f965633bdfa59fbd28c43f0 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Thu, 13 Feb 2025 10:55:19 +0800 Subject: [PATCH 31/54] fix:warehouse_keeper --- app/Service/Admin/System/WarehouseService.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Service/Admin/System/WarehouseService.php b/app/Service/Admin/System/WarehouseService.php index f9863d4..3b73559 100644 --- a/app/Service/Admin/System/WarehouseService.php +++ b/app/Service/Admin/System/WarehouseService.php @@ -62,6 +62,9 @@ class WarehouseService extends BaseService{ $kitchenId = (int)$this->request->input('kitchen_id'); $info = $this->warehouseKeeperModel->getInfoByUserId($userId); + if (RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) + throw new ErrException('该角色没有权限'); + if (!empty($info)) { if(!empty($kitchenId)) $info->kitchen_id = $kitchenId; From 59f0f23abc8303035a1b98808af6d7db9f880ed9 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Mon, 17 Feb 2025 16:31:07 +0800 Subject: [PATCH 32/54] fix:material_application --- app/Service/Api/Material/MaterialService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Service/Api/Material/MaterialService.php b/app/Service/Api/Material/MaterialService.php index a32991e..84f2eac 100644 --- a/app/Service/Api/Material/MaterialService.php +++ b/app/Service/Api/Material/MaterialService.php @@ -84,8 +84,8 @@ class MaterialService extends BaseService{ if (!empty($number)){ $info->number = $number; - if($number <= $info->al_number){ - $info->status = MaterialCode::ALL_OUT; + if($number < $info->al_number){ + throw new ErrException('申请数量不能小于出库数量'); } } if (!empty($processing)){ From 6630a56bee2a5b20a2b6a650a9f624a60ecaa821 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Mon, 17 Feb 2025 16:32:34 +0800 Subject: [PATCH 33/54] feat:material --- app/Controller/Admin/MaterialController.php | 12 +++++++ app/Request/Admin/MaterialRequest.php | 3 +- .../Admin/Material/MaterialService.php | 35 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/app/Controller/Admin/MaterialController.php b/app/Controller/Admin/MaterialController.php index faa82da..ba44b33 100644 --- a/app/Controller/Admin/MaterialController.php +++ b/app/Controller/Admin/MaterialController.php @@ -78,5 +78,17 @@ class MaterialController return (new MaterialService())->materialStockList(); } + /** + * 厨师成本列表 + * @param MaterialRequest $request + * @return array + */ + #[RequestMapping(path: "chef_cost_list", methods: "GET")] + #[Scene(scene: "chef_cost_list")] + public function chefCostList(MaterialRequest $request): array + { + return (new MaterialService())->costListByChef(); + } + } diff --git a/app/Request/Admin/MaterialRequest.php b/app/Request/Admin/MaterialRequest.php index 61502d3..ffb14ea 100644 --- a/app/Request/Admin/MaterialRequest.php +++ b/app/Request/Admin/MaterialRequest.php @@ -36,10 +36,11 @@ class MaterialRequest extends FormRequest } protected array $scenes = [ - 'material_list' => ['limit','query_name','query_kitchenId'], + 'material_list' => ['limit','query_name','query_kitchen_id'], 'material_add' => ['category_id', 'name', 'standard', 'unit', 'bar_code', 'city_id', 'kitchen_id'], 'material_edit' => ['id','category_id', 'name', 'standard', 'unit', 'bar_code','status'], 'material_delete' => ['id'], 'materialStock_list' => ['limit','query_name','query_materialId','query_depotId','query_supplierId','query_kitchenId'], + 'chef_cost_list' => ['limit','chef_name','cycle_id','query_kitchen_id'], ]; } diff --git a/app/Service/Admin/Material/MaterialService.php b/app/Service/Admin/Material/MaterialService.php index 85371df..ca5e856 100644 --- a/app/Service/Admin/Material/MaterialService.php +++ b/app/Service/Admin/Material/MaterialService.php @@ -4,9 +4,11 @@ declare(strict_types=1); namespace App\Service\Admin\Material; +use App\Constants\Admin\DepotCode; use App\Constants\Common\MaterialCode; use App\Exception\ErrException; use App\Model\Material; +use App\Model\MaterialApplication; use App\Model\MaterialStock; use App\Service\Admin\BaseService; use Hyperf\Di\Annotation\Inject; @@ -22,6 +24,9 @@ class MaterialService extends BaseService{ #[Inject] protected MaterialStock $MaterialStockModel; + #[Inject] + protected MaterialApplication $MaterialApplicationModel; + public function handle() { @@ -142,4 +147,34 @@ class MaterialService extends BaseService{ return $this->return->success('success',$list); } + public function costListByChef():array + { + $limit = (int)$this->request->input('limit', 10); + $chefName = $this->request->input('chef_name'); + $cycleId = (int)$this->request->input('cycle_id'); + $kitchenId = (int)$this->request->input('query_kitchen_id'); + + $list = $this->MaterialApplicationModel + ->leftJoin('material','material_application.material_id','=','material.id') + ->leftJoin('dish','material_application.dish_id','=','dish.id') + ->leftJoin('depot_sale','material_application.id','=','depot_sale.application_id') + ->leftJoin('admin_user','material_application.operator_id','=','admin_user.id') + ->where('material_application.is_del',MaterialCode::IS_NO_DEL) + ->where('depot_sale.is_del',DepotCode::IS_NO_DEL) + ->when(!empty($chefName), function ($query) use ($chefName) { + $query->where('admin_user.chinese_name', $chefName); + }) + ->when(!empty($cycleId), function ($query) use ($cycleId) { + $query->where('dish.cycle_id', $cycleId); + }) + ->when(!empty($kitchenId), function ($query) use ($kitchenId) { + $query->where('material_application.kitchen_id', $kitchenId); + }) + ->paginate($limit,['admin_user.chinese_name','material.name','material_application.number as application_number','depot_sale.number as sale_number','depot_sale.back_number']) + ->toArray(); + +// return $this->return->success('success',['list' => $list]); + return $this->return->success('success',$list); + } + } \ No newline at end of file From a79f979a9a6a71121f7cf5ca2d85248ee51b6014 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Mon, 17 Feb 2025 16:55:26 +0800 Subject: [PATCH 34/54] feat:material_application --- app/Service/Api/Material/MaterialService.php | 2 ++ sync/http/admin/auth.http | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/Service/Api/Material/MaterialService.php b/app/Service/Api/Material/MaterialService.php index 84f2eac..7806fbc 100644 --- a/app/Service/Api/Material/MaterialService.php +++ b/app/Service/Api/Material/MaterialService.php @@ -113,12 +113,14 @@ class MaterialService extends BaseService{ public function applicationList(): array { $limit = (int)$this->request->input('limit', 10); + $dishId = (int)$this->request->input('dish_id'); $list = $this->MaterialApplication ->leftJoin('material', 'material.id', '=', 'material_id') ->leftJoin('dish', 'dish.id', '=', 'dish_id') ->leftJoin('admin_user', 'admin_user.id', '=', 'operator_id') ->where('material_application.is_del',MaterialCode::IS_NO_DEL) ->where('material_application.operator_id', $this->userId) + ->where('material_application.dish_id', $dishId) ->paginate($limit,['material_application.*','material.name as material_name','dish.dish as dish_name','admin_user.chinese_name as operator_name']) ->toArray(); diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 1925073..e77d788 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -445,7 +445,7 @@ Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{admin_token}} ### 个人申请材料列表 -GET {{host}}/api/material/application_list?limit=10 +GET {{host}}/api/material/application_list?limit=10&dish_id=1 content-type: application/json Authorization: Bearer {{admin_token}} @@ -541,3 +541,9 @@ Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{admin_token}} user_id=5&kitchen_id=1 + +### 厨师成本列表 +GET {{host}}/admin/material/chef_cost_list?limit=10&query_kitchen_id=1 +content-type: application/json +Authorization: Bearer {{admin_token}} + From e9eb3f238aca26045823492329fc1a50c08f2b96 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Mon, 17 Feb 2025 18:01:03 +0800 Subject: [PATCH 35/54] feat:dish --- app/Service/Admin/Material/DishService.php | 4 +++- app/Service/Api/Material/DishService.php | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Service/Admin/Material/DishService.php b/app/Service/Admin/Material/DishService.php index a5b7a4a..6582db3 100644 --- a/app/Service/Admin/Material/DishService.php +++ b/app/Service/Admin/Material/DishService.php @@ -37,6 +37,7 @@ class DishService extends BaseService $chefId = (int)$this->request->input('query_chef_id',0); $list = $this->DishModel + ->leftJoin('cycle','dish.cycle_id','=','cycle.id') ->where('is_del',DishCode::IS_NO_DEL) ->when($id > 0, function ($query) use ($id) { $query->where('id', $id); @@ -56,7 +57,8 @@ class DishService extends BaseService ->when($chefId, function ($query) use ($chefId) { $query->where('chef_id', $chefId); }) - ->paginate($limit)->toArray(); + ->orderBy('cycle.dates','desc') + ->paginate($limit,['dish.*','cycle.dates'])->toArray(); return $this->return->success('success',$list); } diff --git a/app/Service/Api/Material/DishService.php b/app/Service/Api/Material/DishService.php index 2d929aa..c698307 100644 --- a/app/Service/Api/Material/DishService.php +++ b/app/Service/Api/Material/DishService.php @@ -119,8 +119,10 @@ class DishService extends BaseService $limit = (int)$this->request->input('limit'); $chef_id = $this->userId; $list = $this->DishModel + ->leftJoin('cycle','dish.cycle_id','=','cycle.id') ->where('chef_id', $chef_id) - ->paginate($limit)->toArray(); + ->orderBy('cycle.dates','desc') + ->paginate($limit,['dish.*','cycle.dates'])->toArray(); return $this->return->success('success',$list); } From 1623571572b090d9529a9b4e20016b93d14dd081 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Tue, 18 Feb 2025 11:11:58 +0800 Subject: [PATCH 36/54] fix:depot_purchase --- app/Service/Admin/Depot/DepotService.php | 2 ++ sync/http/admin/auth.http | 8 +++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index 0a9c694..19f75cd 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -195,6 +195,7 @@ class DepotService extends BaseService{ else{ //库存增加 $materialStock->current_stock = $materialStock->current_stock + $number; + $materialStock->unit_price = $purchase_price; } if (!$depotPurchase->save() || !$materialStock->save()) throw new ErrException('采购添加失败'); @@ -298,6 +299,7 @@ class DepotService extends BaseService{ ->when($kitchenId,function ($query) use ($kitchenId) { $query->where('depot_purchase.kitchen_id',$kitchenId); }) + ->orderBy('depot_purchase.create_time','desc') ->paginate($limit,['depot_purchase.*','material.name as material_name','supplier.name as supplier_name','depot.name as depot_name']) ->toArray(); diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index e77d788..521feec 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -387,15 +387,13 @@ POST {{host}}/admin/depot/depot_purchase Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{admin_token}} -depot_id=1&material_id=1&supplier_id=1&purchase_price=60&number=2&city_id=1&kitchen_id=1 +depot_id=1&material_id=1&supplier_id=1&purchase_price=60&number=5&city_id=1&kitchen_id=1 -### 采购数量修改 -POST {{host}}/admin/depot/depot_purchase_update +### 采购退货 +POST {{host}}/admin/depot/depot_purchase_back?id=1 Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{admin_token}} -id=1&number=9 - ### 排菜列表 GET {{host}}/admin/dish/list?limit=10 content-type: application/json 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 37/54] 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 From a314c6153e7f2800a688b302120e422a5c98ad71 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Tue, 18 Feb 2025 16:34:51 +0800 Subject: [PATCH 38/54] feat:depot_recycle --- app/Service/Admin/Depot/DepotService.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index 0f0daae..7a75d9b 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -535,6 +535,7 @@ class DepotService extends BaseService{ ->first(); $saleInfo->back_number = $saleInfo->back_number + $number; + $saleInfo->sum_price = $saleInfo->sale_price * ($saleInfo->number - $saleInfo->back_number); if ($saleInfo->back_number > $saleInfo->number) throw new ErrException('回收数量不能大于出库数量'); @@ -604,6 +605,7 @@ class DepotService extends BaseService{ ->first(); $saleInfo->back_number = $saleInfo->back_number + $number - $old_number; + $saleInfo->sum_price = $saleInfo->sale_price * ($saleInfo->number - $saleInfo->back_number); if ($saleInfo->back_number > $saleInfo->number) throw new ErrException('回收数量不能大于出库数量'); @@ -639,6 +641,7 @@ class DepotService extends BaseService{ ->first(); $saleInfo->back_number = $saleInfo->back_number - $info->number; + $saleInfo->sum_price = $saleInfo->sale_price * ($saleInfo->number - $saleInfo->back_number); if (!$info->save() || !$materialStock->save() || !$saleInfo->save()) throw new ErrException('商品回收删除失败'); @@ -697,6 +700,7 @@ class DepotService extends BaseService{ } $saleInfo->back_number = $saleInfo->back_number + $info->number; + $saleInfo->sum_price = $saleInfo->sale_price * ($saleInfo->number - $saleInfo->back_number); $materialStock = $this->MaterialStockModel ->where('material_id',$info->material_id) @@ -735,6 +739,7 @@ class DepotService extends BaseService{ ->first(); $saleInfo->back_number = $saleInfo->back_number - $info->number; + $saleInfo->sum_price = $saleInfo->sale_price * ($saleInfo->number - $saleInfo->back_number); if (!$materialStock->save() || !$saleInfo->save()) throw new ErrException('回收审核异常'); } From 39924b57808fd5c354de6f4abf88bf7420d6d7ae Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Tue, 18 Feb 2025 17:15:00 +0800 Subject: [PATCH 39/54] fix:dish --- app/Model/Dish.php | 4 ++-- app/Request/Admin/DishRequest.php | 4 ++-- app/Request/Admin/MaterialRequest.php | 2 +- app/Request/Api/DishRequest.php | 4 ++-- app/Service/Admin/Material/DishService.php | 11 +++++------ app/Service/Admin/Material/MaterialService.php | 6 +++--- app/Service/Api/Material/DishService.php | 9 ++++----- sync/http/admin/auth.http | 2 +- 8 files changed, 20 insertions(+), 22 deletions(-) diff --git a/app/Model/Dish.php b/app/Model/Dish.php index 92d2a2d..6f4d583 100644 --- a/app/Model/Dish.php +++ b/app/Model/Dish.php @@ -16,7 +16,7 @@ use Hyperf\DbConnection\Model\Model; * @property string $price * @property string $side_dish * @property string $flavor - * @property int $cycle_id + * @property string $date * @property int $city_id * @property int $kitchen_id * @property int $chef_id @@ -39,7 +39,7 @@ class Dish extends Model /** * The attributes that should be cast to native types. */ - protected array $casts = ['id' => 'integer', 'pre_quantity' => 'integer', 'cycle_id' => 'integer', 'city_id' => 'integer','kitchen_id' => 'integer', 'chef_id' => 'integer', 'is_del' => 'integer']; + protected array $casts = ['id' => 'integer', 'pre_quantity' => 'integer', 'city_id' => 'integer','kitchen_id' => 'integer', 'chef_id' => 'integer', 'is_del' => 'integer']; const string CREATED_AT = 'create_time'; diff --git a/app/Request/Admin/DishRequest.php b/app/Request/Admin/DishRequest.php index 6d6e918..8356b37 100644 --- a/app/Request/Admin/DishRequest.php +++ b/app/Request/Admin/DishRequest.php @@ -26,7 +26,7 @@ class DishRequest extends FormRequest 'query_id' => 'sometimes|integer', 'query_dish_name' => 'sometimes|string', 'query_city_id' => 'sometimes|integer|exists:system_city,id', - 'query_date_id' => 'sometimes|integer|exists:cycle,id', + 'query_date' => 'sometimes', 'query_status' => 'sometimes|integer', 'query_chef_id' => 'sometimes|integer', @@ -34,6 +34,6 @@ class DishRequest extends FormRequest } protected array $scenes = [ - 'list' => ['limit','query_id','query_dish_name','query_city_id','query_date_id','query_status','query_chef_id'], + 'list' => ['limit','query_id','query_dish_name','query_city_id','query_date','query_status','query_chef_id'], ]; } diff --git a/app/Request/Admin/MaterialRequest.php b/app/Request/Admin/MaterialRequest.php index ffb14ea..b7a89ae 100644 --- a/app/Request/Admin/MaterialRequest.php +++ b/app/Request/Admin/MaterialRequest.php @@ -41,6 +41,6 @@ class MaterialRequest extends FormRequest 'material_edit' => ['id','category_id', 'name', 'standard', 'unit', 'bar_code','status'], 'material_delete' => ['id'], 'materialStock_list' => ['limit','query_name','query_materialId','query_depotId','query_supplierId','query_kitchenId'], - 'chef_cost_list' => ['limit','chef_name','cycle_id','query_kitchen_id'], + 'chef_cost_list' => ['limit','chef_name','date','query_kitchen_id'], ]; } diff --git a/app/Request/Api/DishRequest.php b/app/Request/Api/DishRequest.php index 800c289..4b4fb95 100644 --- a/app/Request/Api/DishRequest.php +++ b/app/Request/Api/DishRequest.php @@ -24,7 +24,7 @@ class DishRequest extends FormRequest return [ 'limit' => 'required|integer', 'dish_name' => 'sometimes|string', - 'cycle_id' => 'sometimes|integer|exists:cycle,id', + 'date' => 'sometimes', 'city_id' => 'sometimes|integer|exists:system_city,id', 'kitchen_id' => 'sometimes|integer|exists:kitchen,id', @@ -32,7 +32,7 @@ class DishRequest extends FormRequest } protected array $scenes = [ - 'add' => ['dish_name','profile','pre_quantity','price','side_dish','flavor','cycle_id','city_id','kitchen_id'], + 'add' => ['dish_name','profile','pre_quantity','price','side_dish','flavor','date','city_id','kitchen_id'], 'edit' => ['id','dish_name','profile','pre_quantity','price','side_dish','flavor'], 'list' =>['limit'], 'delete' =>['id'], diff --git a/app/Service/Admin/Material/DishService.php b/app/Service/Admin/Material/DishService.php index 6582db3..b61d0d1 100644 --- a/app/Service/Admin/Material/DishService.php +++ b/app/Service/Admin/Material/DishService.php @@ -32,12 +32,11 @@ class DishService extends BaseService $id = (int)$this->request->input('query_id'); $cityId = (int)$this->request->input('query_city_id',0); $dishName = $this->request->input('query_dish_name'); - $dateId = (int)$this->request->input('query_date_id'); + $date = $this->request->input('query_date'); $status = (int)$this->request->input('query_status'); $chefId = (int)$this->request->input('query_chef_id',0); $list = $this->DishModel - ->leftJoin('cycle','dish.cycle_id','=','cycle.id') ->where('is_del',DishCode::IS_NO_DEL) ->when($id > 0, function ($query) use ($id) { $query->where('id', $id); @@ -48,8 +47,8 @@ class DishService extends BaseService ->when($dishName, function ($query) use ($dishName) { $query->where('dish', 'like', "$dishName%"); }) - ->when($dateId, function ($query) use ($dateId) { - $query->where('cycle_id', $dateId); + ->when($date, function ($query) use ($date) { + $query->where('date', $date); }) ->when($status, function ($query) use ($status) { $query->where('status', $status); @@ -57,8 +56,8 @@ class DishService extends BaseService ->when($chefId, function ($query) use ($chefId) { $query->where('chef_id', $chefId); }) - ->orderBy('cycle.dates','desc') - ->paginate($limit,['dish.*','cycle.dates'])->toArray(); + ->orderBy('date','desc') + ->paginate($limit)->toArray(); return $this->return->success('success',$list); } diff --git a/app/Service/Admin/Material/MaterialService.php b/app/Service/Admin/Material/MaterialService.php index ca5e856..bf8b2c1 100644 --- a/app/Service/Admin/Material/MaterialService.php +++ b/app/Service/Admin/Material/MaterialService.php @@ -151,7 +151,7 @@ class MaterialService extends BaseService{ { $limit = (int)$this->request->input('limit', 10); $chefName = $this->request->input('chef_name'); - $cycleId = (int)$this->request->input('cycle_id'); + $date = $this->request->input('date'); $kitchenId = (int)$this->request->input('query_kitchen_id'); $list = $this->MaterialApplicationModel @@ -164,8 +164,8 @@ class MaterialService extends BaseService{ ->when(!empty($chefName), function ($query) use ($chefName) { $query->where('admin_user.chinese_name', $chefName); }) - ->when(!empty($cycleId), function ($query) use ($cycleId) { - $query->where('dish.cycle_id', $cycleId); + ->when(!empty($date), function ($query) use ($date) { + $query->where('dish.date', $date); }) ->when(!empty($kitchenId), function ($query) use ($kitchenId) { $query->where('material_application.kitchen_id', $kitchenId); diff --git a/app/Service/Api/Material/DishService.php b/app/Service/Api/Material/DishService.php index c698307..6b26756 100644 --- a/app/Service/Api/Material/DishService.php +++ b/app/Service/Api/Material/DishService.php @@ -39,7 +39,7 @@ class DishService extends BaseService $price = (double)$this->request->input('price'); $side_dish = $this->request->input('side_dish'); $flavor = $this->request->input('flavor'); - $cycle_id = (int)$this->request->input('cycle_id'); + $date = $this->request->input('date'); $city_id = (int)$this->request->input('city_id'); $kitchen_id = (int)$this->request->input('kitchen_id'); $chef_id = $this->userId; @@ -51,7 +51,7 @@ class DishService extends BaseService $dish ->price = $price; $dish ->side_dish = $side_dish; $dish ->flavor = $flavor; - $dish ->cycle_id = $cycle_id; + $dish ->date = $date; $dish ->city_id = $city_id; $dish ->kitchen_id = $kitchen_id; $dish ->chef_id = $chef_id; @@ -119,10 +119,9 @@ class DishService extends BaseService $limit = (int)$this->request->input('limit'); $chef_id = $this->userId; $list = $this->DishModel - ->leftJoin('cycle','dish.cycle_id','=','cycle.id') ->where('chef_id', $chef_id) - ->orderBy('cycle.dates','desc') - ->paginate($limit,['dish.*','cycle.dates'])->toArray(); + ->orderBy('date','desc') + ->paginate($limit)->toArray(); return $this->return->success('success',$list); } diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 5db909a..13703f0 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -409,7 +409,7 @@ POST {{host}}/api/dish/add Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{admin_token}} -dish_name=排骨饭&profile=加水&pre_quantity=500&price=15&side_dish=33333&flavor=清淡&cycle_id=1&city_id=1&kitchen_id=1 +dish_name=排骨饭&profile=加水&pre_quantity=500&price=15&side_dish=33333&flavor=清淡&date=2025-01-02&city_id=1&kitchen_id=1 ### 厨师修改菜品 POST {{host}}/api/dish/edit From b09916f47c1b011f1d93737abcc751fcb74242b0 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Wed, 19 Feb 2025 11:38:15 +0800 Subject: [PATCH 40/54] fix:depot --- app/Service/Admin/Depot/DepotService.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index 7a75d9b..c6a9f9f 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -143,18 +143,8 @@ class DepotService extends BaseService{ public function purchase():array { $depotId = (int)$this->request->input('depot_id'); - $depotInfo = $this->DepotModel->getInfoById($depotId); - if (empty($depotInfo)) throw new ErrException('仓库不存在'); - $materialId = (int)$this->request->input('material_id'); - $materialInfo = $this->MaterialModel->getInfoById($materialId); - if (empty($materialInfo)) throw new ErrException("材料不存在"); - $supplierId = (int)$this->request->input('supplier_id'); - if (!empty($supplierId)){ - $supplierInfo = $this->SupplierModel->getInfoById($supplierId); - if (empty($supplierInfo)) throw new ErrException('供应商不存在'); - } $purchase_price = (double)$this->request->input('purchase_price'); $number = (double)$this->request->input('number'); @@ -626,6 +616,10 @@ class DepotService extends BaseService{ ->where('id',$id) ->first(); + if ($info->status == MaterialCode::AUDITED){ + throw new ErrException('该回收已审核通过'); + } + $info->is_del = MaterialCode::IS_DEL; $materialStock = $this->MaterialStockModel From 327101514ad902597976dd03519c81edccca35b6 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Thu, 20 Feb 2025 14:19:05 +0800 Subject: [PATCH 41/54] fix:material --- app/Service/Admin/Material/MaterialService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Service/Admin/Material/MaterialService.php b/app/Service/Admin/Material/MaterialService.php index bf8b2c1..2c47ada 100644 --- a/app/Service/Admin/Material/MaterialService.php +++ b/app/Service/Admin/Material/MaterialService.php @@ -170,7 +170,7 @@ class MaterialService extends BaseService{ ->when(!empty($kitchenId), function ($query) use ($kitchenId) { $query->where('material_application.kitchen_id', $kitchenId); }) - ->paginate($limit,['admin_user.chinese_name','material.name','material_application.number as application_number','depot_sale.number as sale_number','depot_sale.back_number']) + ->paginate($limit,['admin_user.chinese_name','dish.dish','material.name as material_name','material_application.id as application_id','material_application.number as application_number','depot_sale.number as sale_number','depot_sale.back_number']) ->toArray(); // return $this->return->success('success',['list' => $list]); From b717bdbd9f9638c7a67db85438f8b1c43afff038 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Thu, 20 Feb 2025 15:16:19 +0800 Subject: [PATCH 42/54] fix:material --- app/Service/Api/Material/MaterialService.php | 7 ++++--- sync/http/admin/auth.http | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/Service/Api/Material/MaterialService.php b/app/Service/Api/Material/MaterialService.php index 7806fbc..75bb61d 100644 --- a/app/Service/Api/Material/MaterialService.php +++ b/app/Service/Api/Material/MaterialService.php @@ -38,12 +38,13 @@ class MaterialService extends BaseService{ ->where('is_del',MaterialCode::IS_NO_DEL) ->where('status',MaterialCode::ENABLE) ->when(!empty($name), function ($query) use ($name) { - $query->where('name', 'like', "$name%"); + $query->where('name', 'like', "%$name%"); }) ->when(!empty($kitchenId), function ($query) use ($kitchenId) { $query->where('kitchen_id', $kitchenId); }) - ->paginate($limit)->toArray(); + ->paginate($limit,['name','unit','standard']) + ->toArray(); return $this->return->success('success',$list); } @@ -106,7 +107,7 @@ class MaterialService extends BaseService{ $info = $this->MaterialApplication->getInfoById($id); $info->is_del = 2; if ($info->status == MaterialCode::ALL_OUT || $info->status == MaterialCode::PART_OUT) throw new ErrException("已进行出库"); - if (!$info->save()) throw new ErrException('申请删除失败'); + if (!$info->save()) throw new ErrException('材料有出库,申请删除失败'); return $this->return->success(); } diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 13703f0..8c29162 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -428,6 +428,11 @@ GET {{host}}/api/dish/list?limit=10 content-type: application/json Authorization: Bearer {{admin_token}} +###厨师查看材料列表 +GET {{host}}/api/material/list?limit=10 +content-type: application/json +Authorization: Bearer {{admin_token}} + ### 厨师申请材料 POST {{host}}/api/material/application Content-Type: application/x-www-form-urlencoded From 524f7565b654410eb94e3829ecd727079e7f930c Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Thu, 20 Feb 2025 15:23:27 +0800 Subject: [PATCH 43/54] fix:material --- app/Service/Api/Material/MaterialService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Service/Api/Material/MaterialService.php b/app/Service/Api/Material/MaterialService.php index 75bb61d..108d484 100644 --- a/app/Service/Api/Material/MaterialService.php +++ b/app/Service/Api/Material/MaterialService.php @@ -43,7 +43,7 @@ class MaterialService extends BaseService{ ->when(!empty($kitchenId), function ($query) use ($kitchenId) { $query->where('kitchen_id', $kitchenId); }) - ->paginate($limit,['name','unit','standard']) + ->paginate($limit,['bar_code','name','unit','standard']) ->toArray(); return $this->return->success('success',$list); From cc37f34abbdc80a9552ee59f852e3100fa824368 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Fri, 21 Feb 2025 14:41:23 +0800 Subject: [PATCH 44/54] feat:material --- app/Controller/Admin/MaterialController.php | 12 ++++++++++++ app/Request/Admin/MaterialRequest.php | 1 + .../Admin/Material/MaterialService.php | 19 +++++++++++++++++++ sync/http/admin/auth.http | 7 +++++++ 4 files changed, 39 insertions(+) diff --git a/app/Controller/Admin/MaterialController.php b/app/Controller/Admin/MaterialController.php index ba44b33..1079ab4 100644 --- a/app/Controller/Admin/MaterialController.php +++ b/app/Controller/Admin/MaterialController.php @@ -78,6 +78,18 @@ class MaterialController return (new MaterialService())->materialStockList(); } + /** + * 修改库存信息 + * @param MaterialRequest $request + * @return array + */ + #[RequestMapping(path: "materialStock_edit", methods: "POST")] + #[Scene(scene: "materialStock_edit")] + public function materialStockEdit(MaterialRequest $request): array + { + return (new MaterialService())->materialStockEdit(); + } + /** * 厨师成本列表 * @param MaterialRequest $request diff --git a/app/Request/Admin/MaterialRequest.php b/app/Request/Admin/MaterialRequest.php index b7a89ae..a80ccd4 100644 --- a/app/Request/Admin/MaterialRequest.php +++ b/app/Request/Admin/MaterialRequest.php @@ -41,6 +41,7 @@ class MaterialRequest extends FormRequest 'material_edit' => ['id','category_id', 'name', 'standard', 'unit', 'bar_code','status'], 'material_delete' => ['id'], 'materialStock_list' => ['limit','query_name','query_materialId','query_depotId','query_supplierId','query_kitchenId'], + 'materialStock_edit' => ['id', 'current_stock', 'unit_price'], 'chef_cost_list' => ['limit','chef_name','date','query_kitchen_id'], ]; } diff --git a/app/Service/Admin/Material/MaterialService.php b/app/Service/Admin/Material/MaterialService.php index 2c47ada..bf98bab 100644 --- a/app/Service/Admin/Material/MaterialService.php +++ b/app/Service/Admin/Material/MaterialService.php @@ -147,6 +147,25 @@ class MaterialService extends BaseService{ return $this->return->success('success',$list); } + public function materialStockEdit(): array{ + $id = (int)$this->request->input('id'); + $currentStock = (double)$this->request->input('current_stock'); + $unitPrice = (double)$this->request->input('unit_price'); + + $info = $this->MaterialStockModel->where('id',$id)->first(); + + if (!empty($currentStock)){ + $info->current_stock = $currentStock; + } + if (!empty($unitPrice)){ + $info->unit_price = $unitPrice; + } + + if (!$info->save()) throw new ErrException('修改失败'); + + return $this->return->success(); + } + public function costListByChef():array { $limit = (int)$this->request->input('limit', 10); diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 8c29162..18c5cc4 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -353,6 +353,13 @@ GET {{host}}/admin/material/materialStock_list?limit=10 content-type: application/json Authorization: Bearer {{admin_token}} +### 库存表修改 +POST {{host}}/admin/material/materialStock_edit +content-type: application/x-www-form-urlencoded +Authorization: Bearer {{admin_token}} + +id=1¤t_stock=10 + ### 供应商列表 GET {{host}}/admin/supplier/list?limit=10 content-type: application/json From bc1eaffeaf38e2815b7d2d6de33b5daf4aa9dfe8 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Mon, 24 Feb 2025 10:07:56 +0800 Subject: [PATCH 45/54] feat:depot_sale --- app/Controller/Admin/DepotController.php | 12 ++++++ app/Request/Admin/DepotRequest.php | 1 + app/Service/Admin/Depot/DepotService.php | 50 ++++++++++++++++++++++-- 3 files changed, 59 insertions(+), 4 deletions(-) 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'); From c5e9f6665f973843054f67f5f9260780504da070 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Mon, 24 Feb 2025 10:10:03 +0800 Subject: [PATCH 46/54] feat:depot_sale --- sync/http/admin/auth.http | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 18c5cc4..6c7488e 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -490,6 +490,11 @@ GET {{host}}/admin/depot/sale_list?limit=10&query_kitchen_id=1 content-type: application/json Authorization: Bearer {{admin_token}} +### 销售额统计 +GET {{host}}/admin/depot/sale_statistics?city_id=1 +content-type: application/json +Authorization: Bearer {{admin_token}} + ### 管理员回收商品 POST {{host}}/admin/depot/depot_recycle Content-Type: application/x-www-form-urlencoded From 51710eae9682eae04c1cf5c6999f375d91691056 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Mon, 24 Feb 2025 16:52:26 +0800 Subject: [PATCH 47/54] fix:dish material --- app/Request/Admin/MaterialRequest.php | 4 ++-- app/Request/Api/DishRequest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Request/Admin/MaterialRequest.php b/app/Request/Admin/MaterialRequest.php index a80ccd4..8a7a0f1 100644 --- a/app/Request/Admin/MaterialRequest.php +++ b/app/Request/Admin/MaterialRequest.php @@ -25,8 +25,8 @@ class MaterialRequest extends FormRequest 'limit' => 'required|integer', 'query_name' =>'sometimes|string', 'id' =>'required|integer', - 'category_id' =>'integer|exists:material_category,id', - 'name' =>'string', + 'category_id' =>'required|integer|exists:material_category,id', + 'name' =>'required|string', 'standard' =>'string', 'unit' =>'string', 'bar_code' =>'string', diff --git a/app/Request/Api/DishRequest.php b/app/Request/Api/DishRequest.php index 4b4fb95..7e4d377 100644 --- a/app/Request/Api/DishRequest.php +++ b/app/Request/Api/DishRequest.php @@ -25,8 +25,8 @@ class DishRequest extends FormRequest 'limit' => 'required|integer', 'dish_name' => 'sometimes|string', 'date' => 'sometimes', - 'city_id' => 'sometimes|integer|exists:system_city,id', - 'kitchen_id' => 'sometimes|integer|exists:kitchen,id', + 'city_id' => 'required|integer|exists:system_city,id', + 'kitchen_id' => 'required|integer|exists:kitchen,id', ]; } From dcd237486658eaff65c67bb20aba78174d0dd06a Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Tue, 25 Feb 2025 10:04:18 +0800 Subject: [PATCH 48/54] feat:depot_purchase --- app/Service/Admin/Depot/DepotService.php | 136 +++++++++++++---------- 1 file changed, 76 insertions(+), 60 deletions(-) diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index a8722a3..45b8348 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -18,6 +18,7 @@ use App\Model\MaterialApplication; use App\Model\MaterialStock; use App\Model\Supplier; use App\Service\Admin\BaseService; +use Hyperf\DbConnection\Db; use Hyperf\Di\Annotation\Inject; class DepotService extends BaseService{ @@ -142,81 +143,96 @@ class DepotService extends BaseService{ public function purchase():array { - $depotId = (int)$this->request->input('depot_id'); - $materialId = (int)$this->request->input('material_id'); - $supplierId = (int)$this->request->input('supplier_id'); + Db::beginTransaction(); + try { + $depotId = (int)$this->request->input('depot_id'); + $materialId = (int)$this->request->input('material_id'); + $supplierId = (int)$this->request->input('supplier_id'); - $purchase_price = (double)$this->request->input('purchase_price'); - $number = (double)$this->request->input('number'); + $purchase_price = (double)$this->request->input('purchase_price'); + $number = (double)$this->request->input('number'); - if (!empty($purchase_price) && !empty($number)){ - $sum_price = $purchase_price * $number; + if (!empty($purchase_price) && !empty($number)){ + $sum_price = $purchase_price * $number; + } + + $cityId = (int)$this->request->input('city_id'); + $kitchenId = (int)$this->request->input('kitchen_id'); + + $depotPurchase = new DepotPurchase(); + $depotPurchase->depot_id = $depotId; + $depotPurchase->material_id = $materialId; + $depotPurchase->supplier_id = $supplierId; + $depotPurchase->type = 1; + $depotPurchase->purchase_price = $purchase_price; + $depotPurchase->number = $number; + $depotPurchase->sum_price = $sum_price; + $depotPurchase->status = DepotCode::INPUT; + $depotPurchase->city_id = $cityId; + $depotPurchase->kitchen_id = $kitchenId; + $depotPurchase->operator_id = $this->adminId; + + + $materialStock = $this->MaterialStockModel + ->where('depot_id',$depotId) + ->where('material_id',$materialId) + ->where('supplier_id',$supplierId) + ->first(); + if (empty($materialStock)){ + $materialStock = new MaterialStock(); + $materialStock->depot_id = $depotId; + $materialStock->material_id = $materialId; + $materialStock->supplier_id = $supplierId; + $materialStock->current_stock = $number; + $materialStock->unit_price = $purchase_price; + } + else{ + //库存增加 + $totalValue = $purchase_price * $number + $materialStock->unit_price * $materialStock->current_stock; + $materialStock->current_stock = $materialStock->current_stock + $number; + $materialStock->unit_price = $totalValue/$materialStock->current_stock; + } + + if (!$depotPurchase->save() || !$materialStock->save()) throw new ErrException('采购添加失败'); + + DB::commit(); + } catch (ErrException $error) { + Db::rollBack(); + throw new ErrException($error->getMessage()); } - - $cityId = (int)$this->request->input('city_id'); - $kitchenId = (int)$this->request->input('kitchen_id'); - - $depotPurchase = new DepotPurchase(); - $depotPurchase->depot_id = $depotId; - $depotPurchase->material_id = $materialId; - $depotPurchase->supplier_id = $supplierId; - $depotPurchase->type = 1; - $depotPurchase->purchase_price = $purchase_price; - $depotPurchase->number = $number; - $depotPurchase->sum_price = $sum_price; - $depotPurchase->status = DepotCode::INPUT; - $depotPurchase->city_id = $cityId; - $depotPurchase->kitchen_id = $kitchenId; - $depotPurchase->operator_id = $this->adminId; - - - $materialStock = $this->MaterialStockModel - ->where('depot_id',$depotId) - ->where('material_id',$materialId) - ->where('supplier_id',$supplierId) - ->first(); - if (empty($materialStock)){ - $materialStock = new MaterialStock(); - $materialStock->depot_id = $depotId; - $materialStock->material_id = $materialId; - $materialStock->supplier_id = $supplierId; - $materialStock->current_stock = $number; - $materialStock->unit_price = $purchase_price; - } - else{ - //库存增加 - $materialStock->current_stock = $materialStock->current_stock + $number; - $materialStock->unit_price = $purchase_price; - } - - if (!$depotPurchase->save() || !$materialStock->save()) throw new ErrException('采购添加失败'); - return $this->return->success(); } public function purchaseUpdate():array { - $id = (int)$this->request->input('id'); - $info = $this->DepotPurchaseModel->getDepotPurchase($id); - $old_number = $info->number; + Db::beginTransaction(); + try { + $id = (int)$this->request->input('id'); + $info = $this->DepotPurchaseModel->getDepotPurchase($id); + $old_number = $info->number; - $number = (double)$this->request->input('number'); - $sum_price = $info->purchase_price * $number; + $number = (double)$this->request->input('number'); + $sum_price = $info->purchase_price * $number; - $info->number = $number; - $info->sum_price = $sum_price; + $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 = $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 + $number - $old_number; + $materialStock->current_stock = $materialStock->current_stock + $number - $old_number; - if (!$info->save() || !$materialStock->save()) throw new ErrException('采购数量修改失败'); + if (!$info->save() || !$materialStock->save()) throw new ErrException('采购数量修改失败'); + DB::commit(); + } catch (ErrException $error) { + Db::rollBack(); + throw new ErrException($error->getMessage()); + } return $this->return->success(); } From 4320138389fcc65ff2ff416abd09c2ecf22e6660 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Tue, 25 Feb 2025 15:36:29 +0800 Subject: [PATCH 49/54] fix:depot_purchase --- app/Request/Admin/DepotRequest.php | 4 +- app/Service/Admin/Depot/DepotService.php | 275 +++++++++++++---------- 2 files changed, 156 insertions(+), 123 deletions(-) diff --git a/app/Request/Admin/DepotRequest.php b/app/Request/Admin/DepotRequest.php index e42ed58..3a1917d 100644 --- a/app/Request/Admin/DepotRequest.php +++ b/app/Request/Admin/DepotRequest.php @@ -29,8 +29,8 @@ class DepotRequest extends FormRequest 'city_id' => 'required|integer|exists:system_city,id', 'kitchen_id' => 'required|integer|exists:kitchen,id', 'id' => 'required|integer', - 'purchase_price' => 'required', - 'number' => 'required', + 'purchase_price' => 'required|numeric', + 'number' => 'required|numeric', 'depot_id' => 'required|integer|exists:depot,id', 'material_id' => 'required|integer|exists:material,id', 'supplier_id' => 'required|integer|exists:supplier,id', diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index 45b8348..52dc4c2 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -149,11 +149,11 @@ class DepotService extends BaseService{ $materialId = (int)$this->request->input('material_id'); $supplierId = (int)$this->request->input('supplier_id'); - $purchase_price = (double)$this->request->input('purchase_price'); - $number = (double)$this->request->input('number'); + $purchase_price = $this->request->input('purchase_price'); + $number = $this->request->input('number'); if (!empty($purchase_price) && !empty($number)){ - $sum_price = $purchase_price * $number; + $sum_price = bcmul($purchase_price,$number); } $cityId = (int)$this->request->input('city_id'); @@ -188,9 +188,10 @@ class DepotService extends BaseService{ } else{ //库存增加 - $totalValue = $purchase_price * $number + $materialStock->unit_price * $materialStock->current_stock; - $materialStock->current_stock = $materialStock->current_stock + $number; - $materialStock->unit_price = $totalValue/$materialStock->current_stock; +// $totalValue = bcadd(bcmul($purchase_price,$number),bcmul($materialStock->unit_price,$materialStock->current_stock),2); + $materialStock->current_stock = bcadd($materialStock->current_stock,$number,2); +// $materialStock->unit_price = bcdiv($totalValue,$materialStock->current_stock,2); + $materialStock->unit_price = $purchase_price; } if (!$depotPurchase->save() || !$materialStock->save()) throw new ErrException('采购添加失败'); @@ -239,17 +240,19 @@ class DepotService extends BaseService{ public function purchaseBack():array { - $id = (int)$this->request->input('id'); + Db::beginTransaction(); + try { + $id = (int)$this->request->input('id'); // $number = (double)$this->request->input('number'); - $info = $this->DepotPurchaseModel->getDepotPurchase($id); - $info->status = DepotCode::OUTPUT; - if (!empty($info)){ - $depotPurchase = new DepotPurchase(); - $depotPurchase->depot_id = $info->depot_id; - $depotPurchase->material_id = $info->material_id; - $depotPurchase->supplier_id = $info->supplier_id; - $depotPurchase->type = 2; - $depotPurchase->purchase_price = $info->purchase_price; + $info = $this->DepotPurchaseModel->getDepotPurchase($id); + $info->status = DepotCode::OUTPUT; + if (!empty($info)){ + $depotPurchase = new DepotPurchase(); + $depotPurchase->depot_id = $info->depot_id; + $depotPurchase->material_id = $info->material_id; + $depotPurchase->supplier_id = $info->supplier_id; + $depotPurchase->type = 2; + $depotPurchase->purchase_price = $info->purchase_price; // if (empty($number)){ $depotPurchase->number = $info->number; // } @@ -260,27 +263,33 @@ class DepotService extends BaseService{ // throw new ErrException('采购退货数量不能大于进货数量'); // } - $depotPurchase->sum_price = $depotPurchase->purchase_price * $depotPurchase->number; - $depotPurchase->city_id = $info->city_id; - $depotPurchase->kitchen_id = $info->kitchen_id; - $depotPurchase->operator_id = $this->adminId; - } + $depotPurchase->sum_price = $depotPurchase->purchase_price * $depotPurchase->number; + $depotPurchase->city_id = $info->city_id; + $depotPurchase->kitchen_id = $info->kitchen_id; + $depotPurchase->operator_id = $this->adminId; + } - $materialStock = $this->MaterialStockModel - ->where('depot_id',$depotPurchase->depot_id) - ->where('material_id',$depotPurchase->material_id) - ->where('supplier_id',$depotPurchase->supplier_id) - ->first(); - if (empty($materialStock)) - throw new ErrException('库存更改异常'); - else{ - if ($materialStock->current_stock < $depotPurchase->number) - throw new ErrException('库存数量小于退货数量'); - //库存减少 - $materialStock->current_stock = $materialStock->current_stock - $depotPurchase->number; - } + $materialStock = $this->MaterialStockModel + ->where('depot_id',$depotPurchase->depot_id) + ->where('material_id',$depotPurchase->material_id) + ->where('supplier_id',$depotPurchase->supplier_id) + ->first(); + if (empty($materialStock)) + throw new ErrException('库存更改异常'); + else{ + if ($materialStock->current_stock < $depotPurchase->number) + throw new ErrException('库存数量小于退货数量'); + //库存减少 + $materialStock->current_stock = $materialStock->current_stock - $depotPurchase->number; + } - if (!$depotPurchase->save() || !$materialStock->save() || !$info->save()) throw new ErrException('采购退货异常'); + if (!$depotPurchase->save() || !$materialStock->save() || !$info->save()) throw new ErrException('采购退货异常'); + + DB::commit(); + } catch (ErrException $error) { + Db::rollBack(); + throw new ErrException($error->getMessage()); + } return $this->return->success(); } @@ -365,50 +374,58 @@ class DepotService extends BaseService{ 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'); + Db::beginTransaction(); + try { + $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'); - if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) - throw new ErrException('该角色没有权限'); + if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) + throw new ErrException('该角色没有权限'); - $applicationInfo = $this->MaterialApplicationModel - ->where('id',$applicationId) - ->first(); + $applicationInfo = $this->MaterialApplicationModel + ->where('id',$applicationId) + ->first(); - $materialStock = $this->MaterialStockModel - ->where('depot_id',$depotId) - ->where('material_id',$materialId) - ->where('supplier_id',$supplierId) - ->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->supplier_id = $supplierId; - $depotSale->sale_price = $materialStock->unit_price; - $depotSale->number = $number; - $depotSale->sum_price = $depotSale->sale_price * $number; - $depotSale->application_id = $applicationId; - $depotSale->city_id = $cityId; - $depotSale->kitchen_id = $kitchenId; - $depotSale->operator_id = $this->adminId; + $depotSale = new DepotSale(); + $depotSale->depot_id = $depotId; + $depotSale->dish_id = $applicationInfo->dish_id; + $depotSale->material_id = $materialId; + $depotSale->supplier_id = $supplierId; + $depotSale->sale_price = $materialStock->unit_price; + $depotSale->number = $number; + $depotSale->sum_price = $depotSale->sale_price * $number; + $depotSale->application_id = $applicationId; + $depotSale->city_id = $cityId; + $depotSale->kitchen_id = $kitchenId; + $depotSale->operator_id = $this->adminId; - //库存减少 - $materialStock->current_stock = $materialStock->current_stock - $number; + //库存减少 + $materialStock->current_stock = $materialStock->current_stock - $number; - $applicationInfo->al_number = $number + $applicationInfo->al_number; - if ($applicationInfo->al_number < $applicationInfo->number) - $applicationInfo->status = MaterialCode::PART_OUT; - else - $applicationInfo->status = MaterialCode::ALL_OUT; + $applicationInfo->al_number = $number + $applicationInfo->al_number; + if ($applicationInfo->al_number < $applicationInfo->number) + $applicationInfo->status = MaterialCode::PART_OUT; + else + $applicationInfo->status = MaterialCode::ALL_OUT; - if (!$depotSale->save() || !$materialStock->save() ||!$applicationInfo->save()) throw new ErrException('商品出库异常'); + if (!$depotSale->save() || !$materialStock->save() ||!$applicationInfo->save()) throw new ErrException('商品出库异常'); + + DB::commit(); + } catch (ErrException $error) { + Db::rollBack(); + throw new ErrException($error->getMessage()); + } return $this->return->success(); @@ -416,78 +433,94 @@ class DepotService extends BaseService{ public function saleUpdate():array { - $id = (int)$this->request->input('id'); + Db::beginTransaction(); + try { + $id = (int)$this->request->input('id'); - if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) - throw new ErrException('该角色没有权限'); + if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) + throw new ErrException('该角色没有权限'); - $info = $this->DepotSaleModel - ->where('id',$id) - ->first(); - $applicationInfo = $this->MaterialApplicationModel - ->where('id',$info->application_id) - ->first(); + $info = $this->DepotSaleModel + ->where('id',$id) + ->first(); + $applicationInfo = $this->MaterialApplicationModel + ->where('id',$info->application_id) + ->first(); - $old_number = $info->number; + $old_number = $info->number; - $number = (double)$this->request->input('number'); - $sum_price = $info->sale_price * $number; + $number = (double)$this->request->input('number'); + $sum_price = $info->sale_price * $number; - $info->number = $number; - $info->sum_price = $sum_price; + $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 = $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; + $materialStock->current_stock = $materialStock->current_stock + $old_number - $number; - $applicationInfo->al_number = $applicationInfo->al_number + $number - $old_number; - if ($applicationInfo->al_number < $applicationInfo->number) - $applicationInfo->status = MaterialCode::PART_OUT; - else - $applicationInfo->status = MaterialCode::ALL_OUT; + $applicationInfo->al_number = $applicationInfo->al_number + $number - $old_number; + if ($applicationInfo->al_number < $applicationInfo->number) + $applicationInfo->status = MaterialCode::PART_OUT; + else + $applicationInfo->status = MaterialCode::ALL_OUT; - if (!$info->save() || !$materialStock->save() || !$applicationInfo->save()) throw new ErrException('商品出库数量修改失败'); + if (!$info->save() || !$materialStock->save() || !$applicationInfo->save()) throw new ErrException('商品出库数量修改失败'); + + DB::commit(); + } catch (ErrException $error) { + Db::rollBack(); + throw new ErrException($error->getMessage()); + } return $this->return->success(); } public function saleDelete():array { - $id = (int)$this->request->input('id'); + Db::beginTransaction(); + try { + $id = (int)$this->request->input('id'); - if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) - throw new ErrException('该角色没有权限'); + if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) + throw new ErrException('该角色没有权限'); - $info = $this->DepotSaleModel - ->where('is_del',MaterialCode::IS_NO_DEL) - ->where('id',$id) - ->first(); + $info = $this->DepotSaleModel + ->where('is_del',MaterialCode::IS_NO_DEL) + ->where('id',$id) + ->first(); - $applicationInfo = $this->MaterialApplicationModel - ->where('id',$info->application_id) - ->first(); + $applicationInfo = $this->MaterialApplicationModel + ->where('id',$info->application_id) + ->first(); - $applicationInfo->al_number = $applicationInfo->al_number - $info->number; - if ($applicationInfo->al_number <= 0) - $applicationInfo->status = MaterialCode::AUDITED; - else if ($applicationInfo->al_number < $applicationInfo->number) - $applicationInfo->status = MaterialCode::PART_OUT; + $applicationInfo->al_number = $applicationInfo->al_number - $info->number; + if ($applicationInfo->al_number <= 0) + $applicationInfo->status = MaterialCode::AUDITED; + else if ($applicationInfo->al_number < $applicationInfo->number) + $applicationInfo->status = MaterialCode::PART_OUT; - $materialStock = $this->MaterialStockModel - ->where('depot_id',$info->depot_id) - ->where('material_id',$info->material_id) - ->where('supplier_id',$info->supplier_id) - ->first(); + $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 + $info->number; + $materialStock->current_stock = $materialStock->current_stock + $info->number; - $info->is_del = MaterialCode::IS_DEL; + $info->is_del = MaterialCode::IS_DEL; - if (!$applicationInfo->save() || !$materialStock->save() || !$info->save()) throw new ErrException('商品出库数量删除失败'); + if (!$applicationInfo->save() || !$materialStock->save() || !$info->save()) throw new ErrException('商品出库数量删除失败'); + + DB::commit(); + } catch (ErrException $error) { + Db::rollBack(); + throw new ErrException($error->getMessage()); + } return $this->return->success(); } From c044dba6a614c1b7d1a7e34b8d7d1b70597a64a6 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Tue, 25 Feb 2025 15:57:19 +0800 Subject: [PATCH 50/54] fix:depot --- app/Service/Admin/Depot/DepotService.php | 34 ++++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index 52dc4c2..bd2d908 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -153,7 +153,7 @@ class DepotService extends BaseService{ $number = $this->request->input('number'); if (!empty($purchase_price) && !empty($number)){ - $sum_price = bcmul($purchase_price,$number); + $sum_price = bcmul($purchase_price,$number,2); } $cityId = (int)$this->request->input('city_id'); @@ -213,8 +213,8 @@ class DepotService extends BaseService{ $info = $this->DepotPurchaseModel->getDepotPurchase($id); $old_number = $info->number; - $number = (double)$this->request->input('number'); - $sum_price = $info->purchase_price * $number; + $number = $this->request->input('number'); + $sum_price = bcmul($info->purchase_price,$number,2); $info->number = $number; $info->sum_price = $sum_price; @@ -225,7 +225,7 @@ class DepotService extends BaseService{ ->where('supplier_id',$info->supplier_id) ->first(); - $materialStock->current_stock = $materialStock->current_stock + $number - $old_number; + $materialStock->current_stock = bcsub(bcadd($materialStock->current_stock,$number,2),$old_number,2); if (!$info->save() || !$materialStock->save()) throw new ErrException('采购数量修改失败'); @@ -263,7 +263,7 @@ class DepotService extends BaseService{ // throw new ErrException('采购退货数量不能大于进货数量'); // } - $depotPurchase->sum_price = $depotPurchase->purchase_price * $depotPurchase->number; + $depotPurchase->sum_price = bcmul($depotPurchase->purchase_price,$depotPurchase->number,2); $depotPurchase->city_id = $info->city_id; $depotPurchase->kitchen_id = $info->kitchen_id; $depotPurchase->operator_id = $this->adminId; @@ -280,7 +280,7 @@ class DepotService extends BaseService{ if ($materialStock->current_stock < $depotPurchase->number) throw new ErrException('库存数量小于退货数量'); //库存减少 - $materialStock->current_stock = $materialStock->current_stock - $depotPurchase->number; + $materialStock->current_stock = bcsub($materialStock->current_stock,$depotPurchase->number,2); } if (!$depotPurchase->save() || !$materialStock->save() || !$info->save()) throw new ErrException('采购退货异常'); @@ -379,7 +379,7 @@ class DepotService extends BaseService{ $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'); + $number = $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'); @@ -404,16 +404,16 @@ class DepotService extends BaseService{ $depotSale->supplier_id = $supplierId; $depotSale->sale_price = $materialStock->unit_price; $depotSale->number = $number; - $depotSale->sum_price = $depotSale->sale_price * $number; + $depotSale->sum_price = bcmul($depotSale->sale_price,$number,2); $depotSale->application_id = $applicationId; $depotSale->city_id = $cityId; $depotSale->kitchen_id = $kitchenId; $depotSale->operator_id = $this->adminId; //库存减少 - $materialStock->current_stock = $materialStock->current_stock - $number; + $materialStock->current_stock = bcsub($materialStock->current_stock,$number,2); - $applicationInfo->al_number = $number + $applicationInfo->al_number; + $applicationInfo->al_number = bcadd($number,$applicationInfo->al_number,2); if ($applicationInfo->al_number < $applicationInfo->number) $applicationInfo->status = MaterialCode::PART_OUT; else @@ -449,8 +449,8 @@ class DepotService extends BaseService{ $old_number = $info->number; - $number = (double)$this->request->input('number'); - $sum_price = $info->sale_price * $number; + $number = $this->request->input('number'); + $sum_price = bcmul($info->sale_price,$number,2); $info->number = $number; $info->sum_price = $sum_price; @@ -461,9 +461,9 @@ class DepotService extends BaseService{ ->where('supplier_id',$info->supplier_id) ->first(); - $materialStock->current_stock = $materialStock->current_stock + $old_number - $number; + $materialStock->current_stock = bcadd($materialStock->current_stock,bcsub($old_number,$number,2),2); - $applicationInfo->al_number = $applicationInfo->al_number + $number - $old_number; + $applicationInfo->al_number = bcadd($applicationInfo->al_number,bcsub($number,$old_number,2),2); if ($applicationInfo->al_number < $applicationInfo->number) $applicationInfo->status = MaterialCode::PART_OUT; else @@ -498,8 +498,8 @@ class DepotService extends BaseService{ ->where('id',$info->application_id) ->first(); - $applicationInfo->al_number = $applicationInfo->al_number - $info->number; - if ($applicationInfo->al_number <= 0) + $applicationInfo->al_number = bcsub($applicationInfo->al_number,$info->number,2); + if (bccomp($applicationInfo->al_number,'0') <= 0) $applicationInfo->status = MaterialCode::AUDITED; else if ($applicationInfo->al_number < $applicationInfo->number) $applicationInfo->status = MaterialCode::PART_OUT; @@ -510,7 +510,7 @@ class DepotService extends BaseService{ ->where('supplier_id',$info->supplier_id) ->first(); - $materialStock->current_stock = $materialStock->current_stock + $info->number; + $materialStock->current_stock = bcadd($materialStock->current_stock,$info->number,2); $info->is_del = MaterialCode::IS_DEL; From 604c6ff79962e474a54e00d8ccae794a6a9ddc86 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Thu, 27 Feb 2025 16:55:58 +0800 Subject: [PATCH 51/54] fix:material_category --- app/Request/Admin/MaterialCategoryRequest.php | 1 + app/Service/Admin/Material/MaterialCategoryService.php | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/app/Request/Admin/MaterialCategoryRequest.php b/app/Request/Admin/MaterialCategoryRequest.php index 6fa0414..2d77fd8 100644 --- a/app/Request/Admin/MaterialCategoryRequest.php +++ b/app/Request/Admin/MaterialCategoryRequest.php @@ -37,5 +37,6 @@ class MaterialCategoryRequest extends FormRequest 'add' => ['name', 'parent_id', 'city_id', 'kitchen_id'], 'edit' => ['id','name', 'parent_id'], 'delete' => ['id'], + 'list' => ['query_city_id'], ]; } diff --git a/app/Service/Admin/Material/MaterialCategoryService.php b/app/Service/Admin/Material/MaterialCategoryService.php index c64ebb4..9ecdfb6 100644 --- a/app/Service/Admin/Material/MaterialCategoryService.php +++ b/app/Service/Admin/Material/MaterialCategoryService.php @@ -105,7 +105,12 @@ class MaterialCategoryService extends BaseService{ */ public function list(): array { + $cityId = (int)$this->request->input('query_city_id'); + $list = $this->MaterialCategoryModel + ->when($cityId > 0,function($query) use($cityId){ + $query->where('city_id',$cityId); + }) ->where('is_del',MaterialCode::IS_NO_DEL)->get(); return $this->return->success('success',['list' => $list->toArray()]); From 09603ee33ab1f48073f9a463acff3f2b3528d14f Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Thu, 27 Feb 2025 17:34:05 +0800 Subject: [PATCH 52/54] feat:material_category --- .../Admin/Material/MaterialCategoryService.php | 18 ++++++++++++++++-- sync/http/admin/auth.http | 5 +++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/Service/Admin/Material/MaterialCategoryService.php b/app/Service/Admin/Material/MaterialCategoryService.php index 9ecdfb6..5946ab1 100644 --- a/app/Service/Admin/Material/MaterialCategoryService.php +++ b/app/Service/Admin/Material/MaterialCategoryService.php @@ -111,8 +111,22 @@ class MaterialCategoryService extends BaseService{ ->when($cityId > 0,function($query) use($cityId){ $query->where('city_id',$cityId); }) - ->where('is_del',MaterialCode::IS_NO_DEL)->get(); + ->where('is_del',MaterialCode::IS_NO_DEL)->get()->toArray(); - return $this->return->success('success',['list' => $list->toArray()]); + $tree = []; + $map = []; + + foreach ($list as &$category) { + $category['children'] = []; + $map[$category['id']] = &$category; + + if ($category['parent_id'] && isset($map[$category['parent_id']])) { + $map[$category['parent_id']]['children'][] = &$category; + } else { + $tree[] = &$category; + } + } + + return $this->return->success('success',$tree); } } \ No newline at end of file diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 6c7488e..3a25829 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -324,6 +324,11 @@ GET {{host}}/admin/material_category/findById?query_id=1 Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{admin_token}} +### 材料种类列表 +GET {{host}}/admin/material_category/list?query_city_id=1 +content-type: application/json +Authorization: Bearer {{admin_token}} + ### 材料列表 GET {{host}}/admin/material/list?limit=10 content-type: application/json From 01d70dd374e62606c292a5ce04f36b3aed3dd9ac Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Fri, 28 Feb 2025 09:48:16 +0800 Subject: [PATCH 53/54] fix:material_category --- app/Request/Admin/MaterialCategoryRequest.php | 2 +- app/Service/Admin/Material/MaterialCategoryService.php | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/Request/Admin/MaterialCategoryRequest.php b/app/Request/Admin/MaterialCategoryRequest.php index 2d77fd8..790b350 100644 --- a/app/Request/Admin/MaterialCategoryRequest.php +++ b/app/Request/Admin/MaterialCategoryRequest.php @@ -37,6 +37,6 @@ class MaterialCategoryRequest extends FormRequest 'add' => ['name', 'parent_id', 'city_id', 'kitchen_id'], 'edit' => ['id','name', 'parent_id'], 'delete' => ['id'], - 'list' => ['query_city_id'], + 'list' => ['city_id'], ]; } diff --git a/app/Service/Admin/Material/MaterialCategoryService.php b/app/Service/Admin/Material/MaterialCategoryService.php index 5946ab1..a3a1154 100644 --- a/app/Service/Admin/Material/MaterialCategoryService.php +++ b/app/Service/Admin/Material/MaterialCategoryService.php @@ -105,12 +105,10 @@ class MaterialCategoryService extends BaseService{ */ public function list(): array { - $cityId = (int)$this->request->input('query_city_id'); + $cityId = (int)$this->request->input('city_id'); $list = $this->MaterialCategoryModel - ->when($cityId > 0,function($query) use($cityId){ - $query->where('city_id',$cityId); - }) + ->where('city_id',$cityId) ->where('is_del',MaterialCode::IS_NO_DEL)->get()->toArray(); $tree = []; From b139ea8db401919d9b99047c92836c8dfafa03e2 Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Fri, 28 Feb 2025 09:59:04 +0800 Subject: [PATCH 54/54] fix:depot --- app/Service/Admin/Depot/DepotService.php | 354 ++++++++++++----------- 1 file changed, 193 insertions(+), 161 deletions(-) diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php index bd2d908..85f108b 100644 --- a/app/Service/Admin/Depot/DepotService.php +++ b/app/Service/Admin/Depot/DepotService.php @@ -594,63 +594,72 @@ class DepotService extends BaseService{ public function recycle():array { - $materialId = (int)$this->request->input('material_id'); - $supplierId = (int)$this->request->input('supplier_id'); - $number = (double)$this->request->input('number'); - $saleId = (int)$this->request->input('sale_id'); - $cityId = (int)$this->request->input('city_id'); - $kitchenId = (int)$this->request->input('kitchen_id'); - $depotInfo = $this->DepotModel - ->getInfoByName('回收仓库',$kitchenId); - if (empty($depotInfo)) - throw new ErrException('未创建回收仓库'); - else - $depotId = $depotInfo->id; + Db::beginTransaction(); + try { + $materialId = (int)$this->request->input('material_id'); + $supplierId = (int)$this->request->input('supplier_id'); + $number = (double)$this->request->input('number'); + $saleId = (int)$this->request->input('sale_id'); + $cityId = (int)$this->request->input('city_id'); + $kitchenId = (int)$this->request->input('kitchen_id'); + $depotInfo = $this->DepotModel + ->getInfoByName('回收仓库',$kitchenId); + if (empty($depotInfo)) + throw new ErrException('未创建回收仓库'); + else + $depotId = $depotInfo->id; - if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) - throw new ErrException('该角色没有权限'); + if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) + throw new ErrException('该角色没有权限'); - $saleInfo = $this->DepotSaleModel - ->where('is_del',MaterialCode::IS_NO_DEL) - ->where('id',$saleId) - ->first(); + $saleInfo = $this->DepotSaleModel + ->where('is_del',MaterialCode::IS_NO_DEL) + ->where('id',$saleId) + ->first(); - $saleInfo->back_number = $saleInfo->back_number + $number; - $saleInfo->sum_price = $saleInfo->sale_price * ($saleInfo->number - $saleInfo->back_number); - if ($saleInfo->back_number > $saleInfo->number) - throw new ErrException('回收数量不能大于出库数量'); + $saleInfo->back_number = $saleInfo->back_number + $number; + $saleInfo->sum_price = $saleInfo->sale_price * ($saleInfo->number - $saleInfo->back_number); + if ($saleInfo->back_number > $saleInfo->number) + throw new ErrException('回收数量不能大于出库数量'); - $materialStock = $this->MaterialStockModel - ->where('material_id',$materialId) - ->where('depot_id',$depotId) - ->where('supplier_id',$supplierId) - ->first(); + $materialStock = $this->MaterialStockModel + ->where('material_id',$materialId) + ->where('depot_id',$depotId) + ->where('supplier_id',$supplierId) + ->first(); - $depotRecycle = new DepotRecycle(); - $depotRecycle->depot_id = $depotId; - $depotRecycle->material_id = $materialId; - $depotRecycle->supplier_id = $supplierId; - $depotRecycle->recycle_price = $saleInfo->sale_price; - $depotRecycle->number = $number; - $depotRecycle->sum_price = $saleInfo->sale_price * $number; - $depotRecycle->sale_id = $saleId; - $depotRecycle->status = MaterialCode::AUDITED; - $depotRecycle->city_id = $cityId; - $depotRecycle->kitchen_id = $kitchenId; - $depotRecycle->operator_id = $this->adminId; + $depotRecycle = new DepotRecycle(); + $depotRecycle->depot_id = $depotId; + $depotRecycle->material_id = $materialId; + $depotRecycle->supplier_id = $supplierId; + $depotRecycle->recycle_price = $saleInfo->sale_price; + $depotRecycle->number = $number; + $depotRecycle->sum_price = $saleInfo->sale_price * $number; + $depotRecycle->sale_id = $saleId; + $depotRecycle->status = MaterialCode::AUDITED; + $depotRecycle->city_id = $cityId; + $depotRecycle->kitchen_id = $kitchenId; + $depotRecycle->operator_id = $this->adminId; - if (empty($materialStock)){ - $materialStock = new MaterialStock(); - $materialStock->depot_id = $depotId; - $materialStock->material_id = $materialId; - $materialStock->supplier_id = $supplierId; - $materialStock->current_stock = $number; - $materialStock->unit_price = $depotRecycle->recycle_price; + if (empty($materialStock)){ + $materialStock = new MaterialStock(); + $materialStock->depot_id = $depotId; + $materialStock->material_id = $materialId; + $materialStock->supplier_id = $supplierId; + $materialStock->current_stock = $number; + $materialStock->unit_price = $depotRecycle->recycle_price; + } + else + $materialStock->current_stock = $materialStock->current_stock + $number; + + if (!$saleInfo->save() || !$depotRecycle->save() || !$materialStock->save()) throw new ErrException('回收发生异常'); + + DB::commit(); + } catch (ErrException $error) { + Db::rollBack(); + throw new ErrException($error->getMessage()); } - else - $materialStock->current_stock = $materialStock->current_stock + $number; - if (!$saleInfo->save() || !$depotRecycle->save() || !$materialStock->save()) throw new ErrException('回收发生异常'); return $this->return->success(); @@ -658,39 +667,46 @@ class DepotService extends BaseService{ public function recycleUpdate():array { - $id = (int)$this->request->input('id'); - $number = (double)$this->request->input('number'); + Db::beginTransaction(); + try { + $id = (int)$this->request->input('id'); + $number = (double)$this->request->input('number'); - if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) - throw new ErrException('该角色没有权限'); + if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) + throw new ErrException('该角色没有权限'); - $info = $this->DepotRecycleModel - ->where('id',$id) - ->first(); + $info = $this->DepotRecycleModel + ->where('id',$id) + ->first(); - $old_number = $info->number; - $sum_price = $info->recycle_price * $number; - $info->number = $number; - $info->sum_price = $sum_price; + $old_number = $info->number; + $sum_price = $info->recycle_price * $number; + $info->number = $number; + $info->sum_price = $sum_price; - $materialStock = $this->MaterialStockModel - ->where('material_id',$info->material_id) - ->where('depot_id',$info->depot_id) - ->where('supplier_id',$info->supplier_id) - ->first(); + $materialStock = $this->MaterialStockModel + ->where('material_id',$info->material_id) + ->where('depot_id',$info->depot_id) + ->where('supplier_id',$info->supplier_id) + ->first(); - $materialStock->current_stock = $materialStock->current_stock + $number - $old_number; + $materialStock->current_stock = $materialStock->current_stock + $number - $old_number; - $saleInfo = $this->DepotSaleModel - ->where('id',$info->sale_id) - ->first(); + $saleInfo = $this->DepotSaleModel + ->where('id',$info->sale_id) + ->first(); - $saleInfo->back_number = $saleInfo->back_number + $number - $old_number; - $saleInfo->sum_price = $saleInfo->sale_price * ($saleInfo->number - $saleInfo->back_number); - if ($saleInfo->back_number > $saleInfo->number) - throw new ErrException('回收数量不能大于出库数量'); + $saleInfo->back_number = $saleInfo->back_number + $number - $old_number; + $saleInfo->sum_price = $saleInfo->sale_price * ($saleInfo->number - $saleInfo->back_number); + if ($saleInfo->back_number > $saleInfo->number) + throw new ErrException('回收数量不能大于出库数量'); - if (!$info->save() || !$materialStock->save() || !$saleInfo->save()) throw new ErrException('商品回收数量修改失败'); + if (!$info->save() || !$materialStock->save() || !$saleInfo->save()) throw new ErrException('商品回收数量修改失败'); + DB::commit(); + } catch (ErrException $error) { + Db::rollBack(); + throw new ErrException($error->getMessage()); + } return $this->return->success(); @@ -698,39 +714,47 @@ class DepotService extends BaseService{ public function recycleDelete():array { - $id = (int)$this->request->input('id'); + Db::beginTransaction(); + try { + $id = (int)$this->request->input('id'); - if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) - throw new ErrException('该角色没有权限'); + if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) + throw new ErrException('该角色没有权限'); - $info = $this->DepotRecycleModel - ->where('id',$id) - ->first(); + $info = $this->DepotRecycleModel + ->where('id',$id) + ->first(); - if ($info->status == MaterialCode::AUDITED){ - throw new ErrException('该回收已审核通过'); + if ($info->status == MaterialCode::AUDITED){ + throw new ErrException('该回收已审核通过'); + } + + $info->is_del = MaterialCode::IS_DEL; + + $materialStock = $this->MaterialStockModel + ->where('material_id',$info->material_id) + ->where('depot_id',$info->depot_id) + ->where('supplier_id',$info->supplier_id) + ->first(); + + $materialStock->current_stock = $materialStock->current_stock - $info->number; + + $saleInfo = $this->DepotSaleModel + ->where('id',$info->sale_id) + ->first(); + + $saleInfo->back_number = $saleInfo->back_number - $info->number; + $saleInfo->sum_price = $saleInfo->sale_price * ($saleInfo->number - $saleInfo->back_number); + + if (!$info->save() || !$materialStock->save() || !$saleInfo->save()) + throw new ErrException('商品回收删除失败'); + + DB::commit(); + } catch (ErrException $error) { + Db::rollBack(); + throw new ErrException($error->getMessage()); } - $info->is_del = MaterialCode::IS_DEL; - - $materialStock = $this->MaterialStockModel - ->where('material_id',$info->material_id) - ->where('depot_id',$info->depot_id) - ->where('supplier_id',$info->supplier_id) - ->first(); - - $materialStock->current_stock = $materialStock->current_stock - $info->number; - - $saleInfo = $this->DepotSaleModel - ->where('id',$info->sale_id) - ->first(); - - $saleInfo->back_number = $saleInfo->back_number - $info->number; - $saleInfo->sum_price = $saleInfo->sale_price * ($saleInfo->number - $saleInfo->back_number); - - if (!$info->save() || !$materialStock->save() || !$saleInfo->save()) - throw new ErrException('商品回收删除失败'); - return $this->return->success(); } @@ -763,76 +787,84 @@ class DepotService extends BaseService{ public function recycleAudit():array { - $id = (int)$this->request->input('id'); - $status = (int)$this->request->input('status'); + Db::beginTransaction(); + try { + $id = (int)$this->request->input('id'); + $status = (int)$this->request->input('status'); - if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) - throw new ErrException('该角色没有权限'); + if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) + throw new ErrException('该角色没有权限'); - $info = $this->DepotRecycleModel - ->where('id',$id) - ->first(); + $info = $this->DepotRecycleModel + ->where('id',$id) + ->first(); - if ($info->status != MaterialCode::AUDITED){ - if ($status == MaterialCode::AUDITED){ - $saleInfo = $this->DepotSaleModel - ->where('is_del',MaterialCode::IS_NO_DEL) - ->where('id',$info->sale_id) - ->first(); + if ($info->status != MaterialCode::AUDITED){ + if ($status == MaterialCode::AUDITED){ + $saleInfo = $this->DepotSaleModel + ->where('is_del',MaterialCode::IS_NO_DEL) + ->where('id',$info->sale_id) + ->first(); + + if (empty($saleInfo)){ + throw new ErrException('无出库记录'); + } + + $saleInfo->back_number = $saleInfo->back_number + $info->number; + $saleInfo->sum_price = $saleInfo->sale_price * ($saleInfo->number - $saleInfo->back_number); + + $materialStock = $this->MaterialStockModel + ->where('material_id',$info->material_id) + ->where('depot_id',$info->depot_id) + ->where('supplier_id',$info->supplier_id) + ->first(); + + if (empty($materialStock)){ + $materialStock = new MaterialStock(); + $materialStock->depot_id = $info->depotId; + $materialStock->material_id = $info->materialId; + $materialStock->supplier_id = $info->supplierId; + $materialStock->current_stock = $info->number; + $materialStock->unit_price = $info->recycle_price; + } + else + $materialStock->current_stock = $materialStock->current_stock + $info->number; + + if (!$materialStock->save() || !$saleInfo->save()) throw new ErrException('回收审核异常'); - if (empty($saleInfo)){ - throw new ErrException('无出库记录'); } + } + if ($info->status == MaterialCode::AUDITED){ + if ($status == MaterialCode::UN_AUDIT || $status == MaterialCode::AUDIT_REFUSE){ + $materialStock = $this->MaterialStockModel + ->where('is_del',MaterialCode::IS_NO_DEL) + ->where('material_id',$info->material_id) + ->where('depot_id',$info->depot_id) + ->where('supplier_id',$info->supplier_id) + ->first(); - $saleInfo->back_number = $saleInfo->back_number + $info->number; - $saleInfo->sum_price = $saleInfo->sale_price * ($saleInfo->number - $saleInfo->back_number); + $materialStock->current_stock = $materialStock->current_stock - $info->number; - $materialStock = $this->MaterialStockModel - ->where('material_id',$info->material_id) - ->where('depot_id',$info->depot_id) - ->where('supplier_id',$info->supplier_id) - ->first(); + $saleInfo = $this->DepotSaleModel + ->where('id',$info->sale_id) + ->first(); - if (empty($materialStock)){ - $materialStock = new MaterialStock(); - $materialStock->depot_id = $info->depotId; - $materialStock->material_id = $info->materialId; - $materialStock->supplier_id = $info->supplierId; - $materialStock->current_stock = $info->number; - $materialStock->unit_price = $info->recycle_price; + $saleInfo->back_number = $saleInfo->back_number - $info->number; + $saleInfo->sum_price = $saleInfo->sale_price * ($saleInfo->number - $saleInfo->back_number); + + if (!$materialStock->save() || !$saleInfo->save()) throw new ErrException('回收审核异常'); } - else - $materialStock->current_stock = $materialStock->current_stock + $info->number; - - if (!$materialStock->save() || !$saleInfo->save()) throw new ErrException('回收审核异常'); - } + + $info->status = $status; + + if (!$info->save()) throw new ErrException('回收审核异常'); + + DB::commit(); + } catch (ErrException $error) { + Db::rollBack(); + throw new ErrException($error->getMessage()); } - if ($info->status == MaterialCode::AUDITED){ - if ($status == MaterialCode::UN_AUDIT || $status == MaterialCode::AUDIT_REFUSE){ - $materialStock = $this->MaterialStockModel - ->where('is_del',MaterialCode::IS_NO_DEL) - ->where('material_id',$info->material_id) - ->where('depot_id',$info->depot_id) - ->where('supplier_id',$info->supplier_id) - ->first(); - - $materialStock->current_stock = $materialStock->current_stock - $info->number; - - $saleInfo = $this->DepotSaleModel - ->where('id',$info->sale_id) - ->first(); - - $saleInfo->back_number = $saleInfo->back_number - $info->number; - $saleInfo->sum_price = $saleInfo->sale_price * ($saleInfo->number - $saleInfo->back_number); - - if (!$materialStock->save() || !$saleInfo->save()) throw new ErrException('回收审核异常'); - } - } - - $info->status = $status; - - if (!$info->save()) throw new ErrException('回收审核异常'); return $this->return->success();