diff --git a/app/Constants/Admin/DepotCode.php b/app/Constants/Admin/DepotCode.php new file mode 100644 index 0000000..e8ef12c --- /dev/null +++ b/app/Constants/Admin/DepotCode.php @@ -0,0 +1,24 @@ +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(); + } + + /** + * 采购入库 + * @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(); + } + + /** + * 采购修改 + * @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 + * @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 + * @return array + */ + #[RequestMapping(path: "purchase_list", methods: "GET")] + #[Scene(scene: "purchase_list")] + public function purchaseList(DepotRequest $request): array + { + 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 + * @return array + * @throws Exception + */ + #[RequestMapping(path: "depot_sale", methods: "POST")] + #[Scene(scene: "sale")] + public function depotSale(DepotRequest $request): array + { + return (new DepotService)->depotSale(); + } + + /** + * 销售出库数量修改 + * @param DepotRequest $request + * @return array + * @throws Exception + */ + #[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(); + } + + /** + * 统计销售额 + * @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 + * @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(); + } + + /** + * 回收审核 + * @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/Admin/DishController.php b/app/Controller/Admin/DishController.php new file mode 100644 index 0000000..45c7e4b --- /dev/null +++ b/app/Controller/Admin/DishController.php @@ -0,0 +1,33 @@ +dishList(); + } + + +} diff --git a/app/Controller/Admin/MaterialCategoryController.php b/app/Controller/Admin/MaterialCategoryController.php new file mode 100644 index 0000000..8450337 --- /dev/null +++ b/app/Controller/Admin/MaterialCategoryController.php @@ -0,0 +1,81 @@ +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..1079ab4 --- /dev/null +++ b/app/Controller/Admin/MaterialController.php @@ -0,0 +1,106 @@ +materialList(); + } + + /** + * 添加材料信息 + * @param MaterialRequest $request + * @return array + */ + #[RequestMapping(path: "add", methods: "POST")] + #[Scene(scene: "material_add")] + public function add(MaterialRequest $request): array + { + return (new MaterialService)->add(); + } + + /** + * 删除材料信息 + * @param MaterialRequest $request + * @return array + */ + #[RequestMapping(path: "delete", methods: "GET")] + #[Scene(scene: "material_delete")] + public function delete(MaterialRequest $request): array + { + return (new MaterialService())->delete(); + } + + /** + * 修改材料信息 + * @param MaterialRequest $request + * @return array + */ + #[RequestMapping(path: "edit", methods: "POST")] + #[Scene(scene: "material_edit")] + public function edit(MaterialRequest $request): array + { + 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(); + } + + /** + * 修改库存信息 + * @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 + * @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/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/Controller/Admin/WarehouseKeeperController.php b/app/Controller/Admin/WarehouseKeeperController.php new file mode 100644 index 0000000..f8b3818 --- /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/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/Controller/Api/DishController.php b/app/Controller/Api/DishController.php new file mode 100644 index 0000000..ca1ce84 --- /dev/null +++ b/app/Controller/Api/DishController.php @@ -0,0 +1,68 @@ +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(); + } + + /** + * 菜品删除 + * @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/Controller/Api/MaterialController.php b/app/Controller/Api/MaterialController.php new file mode 100644 index 0000000..28fa4a7 --- /dev/null +++ b/app/Controller/Api/MaterialController.php @@ -0,0 +1,82 @@ +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/Chef.php b/app/Model/Chef.php index ca2a669..6c49777 100644 --- a/app/Model/Chef.php +++ b/app/Model/Chef.php @@ -13,7 +13,8 @@ use Hyperf\Tappable\HigherOrderTapProxy; * @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 @@ -33,7 +34,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'; 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/DepotPurchase.php b/app/Model/DepotPurchase.php new file mode 100644 index 0000000..666a2da --- /dev/null +++ b/app/Model/DepotPurchase.php @@ -0,0 +1,52 @@ + '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'; + + public function getDepotPurchase(int $id): \Hyperf\Database\Model\Model|Builder|null + { + return $this->where('id',$id)->first(); + } +} diff --git a/app/Model/DepotRecycle.php b/app/Model/DepotRecycle.php new file mode 100644 index 0000000..c87f561 --- /dev/null +++ b/app/Model/DepotRecycle.php @@ -0,0 +1,52 @@ + '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'; + + 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 new file mode 100644 index 0000000..350a6db --- /dev/null +++ b/app/Model/DepotSale.php @@ -0,0 +1,53 @@ + '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'; + + 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/Dish.php b/app/Model/Dish.php new file mode 100644 index 0000000..6f4d583 --- /dev/null +++ b/app/Model/Dish.php @@ -0,0 +1,56 @@ + 'integer', 'pre_quantity' => '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'; + + /** + * @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/Material.php b/app/Model/Material.php new file mode 100644 index 0000000..2c687fa --- /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/MaterialApplication.php b/app/Model/MaterialApplication.php new file mode 100644 index 0000000..71d7990 --- /dev/null +++ b/app/Model/MaterialApplication.php @@ -0,0 +1,50 @@ + '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'; + + 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/Model/MaterialCategory.php b/app/Model/MaterialCategory.php new file mode 100644 index 0000000..b68aa0d --- /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/Model/MaterialStock.php b/app/Model/MaterialStock.php new file mode 100644 index 0000000..634d05a --- /dev/null +++ b/app/Model/MaterialStock.php @@ -0,0 +1,51 @@ + '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) + ->first(); + } +} 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/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/DepotRequest.php b/app/Request/Admin/DepotRequest.php new file mode 100644 index 0000000..3a1917d --- /dev/null +++ b/app/Request/Admin/DepotRequest.php @@ -0,0 +1,64 @@ + 'required|integer', + 'query_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', + 'id' => 'required|integer', + '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', + 'application_id' => 'required|integer|exists:material_application,id', + 'sale_id' => 'required|integer|exists:depot_sale,id', + 'status' => 'required|integer', + ]; + } + + protected array $scenes = [ + 'depot_list' => ['limit','query_id','query_kitchen_id'], + 'depot_add' => ['name','city_id','kitchen_id'], + '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'], + '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'], + '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'], + 'recycle_list' => ['limit','query_id','query_kitchen_id'], + 'recycle_audit' => ['id','status'], + ]; +} diff --git a/app/Request/Admin/DishRequest.php b/app/Request/Admin/DishRequest.php new file mode 100644 index 0000000..8356b37 --- /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' => 'sometimes', + 'query_status' => 'sometimes|integer', + 'query_chef_id' => 'sometimes|integer', + + ]; + } + + protected array $scenes = [ + 'list' => ['limit','query_id','query_dish_name','query_city_id','query_date','query_status','query_chef_id'], + ]; +} diff --git a/app/Request/Admin/MaterialCategoryRequest.php b/app/Request/Admin/MaterialCategoryRequest.php new file mode 100644 index 0000000..790b350 --- /dev/null +++ b/app/Request/Admin/MaterialCategoryRequest.php @@ -0,0 +1,42 @@ +'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'], + 'delete' => ['id'], + 'list' => ['city_id'], + ]; +} diff --git a/app/Request/Admin/MaterialRequest.php b/app/Request/Admin/MaterialRequest.php new file mode 100644 index 0000000..8a7a0f1 --- /dev/null +++ b/app/Request/Admin/MaterialRequest.php @@ -0,0 +1,47 @@ + 'required|integer', + 'query_name' =>'sometimes|string', + 'id' =>'required|integer', + 'category_id' =>'required|integer|exists:material_category,id', + 'name' =>'required|string', + 'standard' =>'string', + 'unit' =>'string', + 'bar_code' =>'string', + 'city_id' =>'required|integer|exists:system_city,id', + 'kitchen_id' =>'required|integer|exists:kitchen,id', + ]; + } + + protected array $scenes = [ + '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'], + 'materialStock_edit' => ['id', 'current_stock', 'unit_price'], + 'chef_cost_list' => ['limit','chef_name','date','query_kitchen_id'], + ]; +} 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/Request/Admin/WarehouseKeeperRequest.php b/app/Request/Admin/WarehouseKeeperRequest.php new file mode 100644 index 0000000..a234c7c --- /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_keeper_list' => [ + 'limit', + 'query_city_id', + 'query_name' + ], + 'setting_warehouse_keeper' => [ + 'user_id', + 'kitchen_id', + ], + ]; +} diff --git a/app/Request/Api/DishRequest.php b/app/Request/Api/DishRequest.php new file mode 100644 index 0000000..7e4d377 --- /dev/null +++ b/app/Request/Api/DishRequest.php @@ -0,0 +1,41 @@ + 'required|integer', + 'dish_name' => 'sometimes|string', + 'date' => 'sometimes', + 'city_id' => 'required|integer|exists:system_city,id', + 'kitchen_id' => 'required|integer|exists:kitchen,id', + + ]; + } + + protected array $scenes = [ + '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/Request/Api/MaterialRequest.php b/app/Request/Api/MaterialRequest.php new file mode 100644 index 0000000..d28c957 --- /dev/null +++ b/app/Request/Api/MaterialRequest.php @@ -0,0 +1,41 @@ + 'required|integer', + 'query_name' =>'sometimes|string', + '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','query_kitchen_id'], + 'material_application' => ['material_id','dish_id','number','processing','city_id','kitchen_id'], + 'application_edit' => ['id','number','processing'], + 'application_delete' => ['id'], + 'application_list' => ['limit'], + ]; +} diff --git a/app/Service/Admin/Depot/DepotService.php b/app/Service/Admin/Depot/DepotService.php new file mode 100644 index 0000000..85f108b --- /dev/null +++ b/app/Service/Admin/Depot/DepotService.php @@ -0,0 +1,872 @@ +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; + + 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(); + } + + public function purchase():array + { + 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 = $this->request->input('purchase_price'); + $number = $this->request->input('number'); + + if (!empty($purchase_price) && !empty($number)){ + $sum_price = bcmul($purchase_price,$number,2); + } + + $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 = 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('采购添加失败'); + + DB::commit(); + } catch (ErrException $error) { + Db::rollBack(); + throw new ErrException($error->getMessage()); + } + return $this->return->success(); + + } + + public function purchaseUpdate():array + { + Db::beginTransaction(); + try { + $id = (int)$this->request->input('id'); + $info = $this->DepotPurchaseModel->getDepotPurchase($id); + $old_number = $info->number; + + $number = $this->request->input('number'); + $sum_price = bcmul($info->purchase_price,$number,2); + + $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 = bcsub(bcadd($materialStock->current_stock,$number,2),$old_number,2); + + if (!$info->save() || !$materialStock->save()) throw new ErrException('采购数量修改失败'); + + DB::commit(); + } catch (ErrException $error) { + Db::rollBack(); + throw new ErrException($error->getMessage()); + } + return $this->return->success(); + + } + + public function purchaseBack():array + { + 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; +// if (empty($number)){ + $depotPurchase->number = $info->number; +// } +// else{ +// if ($info->number >= $number) +// $depotPurchase->number = $number; +// else +// throw new ErrException('采购退货数量不能大于进货数量'); +// } + + $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; + } + + $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 = bcsub($materialStock->current_stock,$depotPurchase->number,2); + } + + 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(); + } + + public function purchaseList():array + { + $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 + ->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(!empty($type), function ($query) use ($type) { + $query->where('type', $type); + }) + ->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(); + + 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',DepotCode::INPUT) + ->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',DepotCode::INPUT) + ->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',DepotCode::INPUT) + ->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',DepotCode::INPUT) + ->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 + { + 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 = $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('该角色没有权限'); + + $applicationInfo = $this->MaterialApplicationModel + ->where('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->supplier_id = $supplierId; + $depotSale->sale_price = $materialStock->unit_price; + $depotSale->number = $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 = bcsub($materialStock->current_stock,$number,2); + + $applicationInfo->al_number = bcadd($number,$applicationInfo->al_number,2); + 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('商品出库异常'); + + DB::commit(); + } catch (ErrException $error) { + Db::rollBack(); + throw new ErrException($error->getMessage()); + } + + return $this->return->success(); + + } + + public function saleUpdate():array + { + 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('该角色没有权限'); + + $info = $this->DepotSaleModel + ->where('id',$id) + ->first(); + $applicationInfo = $this->MaterialApplicationModel + ->where('id',$info->application_id) + ->first(); + + $old_number = $info->number; + + $number = $this->request->input('number'); + $sum_price = bcmul($info->sale_price,$number,2); + + $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 = bcadd($materialStock->current_stock,bcsub($old_number,$number,2),2); + + $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 + $applicationInfo->status = MaterialCode::ALL_OUT; + + 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 + { + 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('该角色没有权限'); + + $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 = 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; + + $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 = bcadd($materialStock->current_stock,$info->number,2); + + $info->is_del = MaterialCode::IS_DEL; + + 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(); + } + + 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); + } + + 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 + { + 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('该角色没有权限'); + + $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('回收数量不能大于出库数量'); + + $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; + + 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()); + } + + + return $this->return->success(); + + } + + public function recycleUpdate():array + { + 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('该角色没有权限'); + + $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 + ->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; + + $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('回收数量不能大于出库数量'); + + 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(); + + } + + public function recycleDelete():array + { + 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('该角色没有权限'); + + $info = $this->DepotRecycleModel + ->where('id',$id) + ->first(); + + 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()); + } + + 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'); + + 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') + ->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); + } + + public function recycleAudit():array + { + 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('该角色没有权限'); + + $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; + $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 ($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('回收审核异常'); + + DB::commit(); + } catch (ErrException $error) { + Db::rollBack(); + throw new ErrException($error->getMessage()); + } + + return $this->return->success(); + + } +} \ No newline at end of file diff --git a/app/Service/Admin/Material/DishService.php b/app/Service/Admin/Material/DishService.php new file mode 100644 index 0000000..b61d0d1 --- /dev/null +++ b/app/Service/Admin/Material/DishService.php @@ -0,0 +1,65 @@ +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'); + $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 + ->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($date, function ($query) use ($date) { + $query->where('date', $date); + }) + ->when($status, function ($query) use ($status) { + $query->where('status', $status); + }) + ->when($chefId, function ($query) use ($chefId) { + $query->where('chef_id', $chefId); + }) + ->orderBy('date','desc') + ->paginate($limit)->toArray(); + + return $this->return->success('success',$list); + } + +} \ No newline at end of file diff --git a/app/Service/Admin/Material/MaterialCategoryService.php b/app/Service/Admin/Material/MaterialCategoryService.php new file mode 100644 index 0000000..a3a1154 --- /dev/null +++ b/app/Service/Admin/Material/MaterialCategoryService.php @@ -0,0 +1,130 @@ +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; + + 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 + { + $cityId = (int)$this->request->input('city_id'); + + $list = $this->MaterialCategoryModel + ->where('city_id',$cityId) + ->where('is_del',MaterialCode::IS_NO_DEL)->get()->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/app/Service/Admin/Material/MaterialService.php b/app/Service/Admin/Material/MaterialService.php new file mode 100644 index 0000000..bf98bab --- /dev/null +++ b/app/Service/Admin/Material/MaterialService.php @@ -0,0 +1,199 @@ +request->input('limit', 10); + $name = $this->request->input('query_name'); + $kitchenId = $this->request->input('query_kitchen_id'); + + $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%"); + }) + ->when(!empty($kitchenId), function ($query) use ($kitchenId) { + $query->where('kitchen_id', $kitchenId); + }) + ->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(); + } + + public function materialStockList(): array + { + $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'); + $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($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); + }) + ->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(); + + 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); + $chefName = $this->request->input('chef_name'); + $date = $this->request->input('date'); + $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($date), function ($query) use ($date) { + $query->where('dish.date', $date); + }) + ->when(!empty($kitchenId), function ($query) use ($kitchenId) { + $query->where('material_application.kitchen_id', $kitchenId); + }) + ->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]); + return $this->return->success('success',$list); + } + +} \ No newline at end of file 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/app/Service/Admin/System/WarehouseService.php b/app/Service/Admin/System/WarehouseService.php new file mode 100644 index 0000000..3b73559 --- /dev/null +++ b/app/Service/Admin/System/WarehouseService.php @@ -0,0 +1,78 @@ +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','admin_user.city_id','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 (RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId) + throw new ErrException('该角色没有权限'); + + 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, }; 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/app/Service/Api/Material/DishService.php b/app/Service/Api/Material/DishService.php new file mode 100644 index 0000000..6b26756 --- /dev/null +++ b/app/Service/Api/Material/DishService.php @@ -0,0 +1,129 @@ +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'); + $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; + + $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 ->date = $date; + $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 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'); + $chef_id = $this->userId; + $list = $this->DishModel + ->where('chef_id', $chef_id) + ->orderBy('date','desc') + ->paginate($limit)->toArray(); + + return $this->return->success('success',$list); + } + +} \ No newline at end of file diff --git a/app/Service/Api/Material/MaterialService.php b/app/Service/Api/Material/MaterialService.php new file mode 100644 index 0000000..108d484 --- /dev/null +++ b/app/Service/Api/Material/MaterialService.php @@ -0,0 +1,131 @@ +request->input('limit', 10); + $name = $this->request->input('query_name'); + $kitchenId = $this->request->input('query_kitchen_id'); + + $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%"); + }) + ->when(!empty($kitchenId), function ($query) use ($kitchenId) { + $query->where('kitchen_id', $kitchenId); + }) + ->paginate($limit,['bar_code','name','unit','standard']) + ->toArray(); + + 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 = (double)$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->number = $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'); + $number = (int)$this->request->input('number'); + $processing = $this->request->input('processing'); + + $info = $this->MaterialApplication->getInfoById($id); + + if (!empty($number)){ + $info->number = $number; + if($number < $info->al_number){ + throw new ErrException('申请数量不能小于出库数量'); + } + } + if (!empty($processing)){ + $info->processing = $processing; + } + if($info->status == MaterialCode::AUDIT_REFUSE){ + $info->status = MaterialCode::UN_AUDIT; + } + + 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 || $info->status == MaterialCode::PART_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); + $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(); + + 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..3a25829 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -276,3 +276,299 @@ GET {{host}}/admin/member/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}} + +### 材料种类添加 +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_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 +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 + +### 材料库存列表 +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 +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}} + +### 采购列表 +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=5&city_id=1&kitchen_id=1 + +### 采购退货 +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 +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=清淡&date=2025-01-02&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 + +### 厨师删除菜品 +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 +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 +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&dish_id=1 +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}} + +### 销售额统计 +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 +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=3 +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}} + +### 管理员审核回收 +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}} + +### 仓管详细列表 +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 + +### 厨师成本列表 +GET {{host}}/admin/material/chef_cost_list?limit=10&query_kitchen_id=1 +content-type: application/json +Authorization: Bearer {{admin_token}} +