diff --git a/app/admin/controller/warehouse/WarehouseController.php b/app/admin/controller/warehouse/WarehouseController.php new file mode 100644 index 000000000..8f4506ef4 --- /dev/null +++ b/app/admin/controller/warehouse/WarehouseController.php @@ -0,0 +1,95 @@ +dataLists(new WarehouseLists()); + } + + + /** + * @notes 添加仓库信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:10 + */ + public function add() + { + $params = (new WarehouseValidate())->post()->goCheck('add'); + $result = WarehouseLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(WarehouseLogic::getError()); + } + + + /** + * @notes 编辑仓库信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:10 + */ + public function edit() + { + $params = (new WarehouseValidate())->post()->goCheck('edit'); + $result = WarehouseLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(WarehouseLogic::getError()); + } + + + /** + * @notes 删除仓库信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:10 + */ + public function delete() + { + $params = (new WarehouseValidate())->post()->goCheck('delete'); + WarehouseLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取仓库信息详情 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:10 + */ + public function detail() + { + $params = (new WarehouseValidate())->goCheck('detail'); + $result = WarehouseLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/controller/warehouse_product/WarehouseProductController.php b/app/admin/controller/warehouse_product/WarehouseProductController.php new file mode 100644 index 000000000..e1bac316b --- /dev/null +++ b/app/admin/controller/warehouse_product/WarehouseProductController.php @@ -0,0 +1,95 @@ +dataLists(new WarehouseProductLists()); + } + + + /** + * @notes 添加商品仓储信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:55 + */ + public function add() + { + $params = (new WarehouseProductValidate())->post()->goCheck('add'); + $result = WarehouseProductLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(WarehouseProductLogic::getError()); + } + + + /** + * @notes 编辑商品仓储信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:55 + */ + public function edit() + { + $params = (new WarehouseProductValidate())->post()->goCheck('edit'); + $result = WarehouseProductLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(WarehouseProductLogic::getError()); + } + + + /** + * @notes 删除商品仓储信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:55 + */ + public function delete() + { + $params = (new WarehouseProductValidate())->post()->goCheck('delete'); + WarehouseProductLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取商品仓储信息详情 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:55 + */ + public function detail() + { + $params = (new WarehouseProductValidate())->goCheck('detail'); + $result = WarehouseProductLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/lists/warehouse/WarehouseLists.php b/app/admin/lists/warehouse/WarehouseLists.php new file mode 100644 index 000000000..4552a97c7 --- /dev/null +++ b/app/admin/lists/warehouse/WarehouseLists.php @@ -0,0 +1,65 @@ + ['name', 'contacts', 'tel'], + ]; + } + + + /** + * @notes 获取仓库信息列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/07/31 16:10 + */ + public function lists(): array + { + return Warehouse::where($this->searchWhere) + ->field(['id', 'name', 'code', 'contacts', 'tel', 'address', 'notes', 'sort']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取仓库信息数量 + * @return int + * @author admin + * @date 2024/07/31 16:10 + */ + public function count(): int + { + return Warehouse::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/lists/warehouse_product/WarehouseProductLists.php b/app/admin/lists/warehouse_product/WarehouseProductLists.php new file mode 100644 index 000000000..c33e58cde --- /dev/null +++ b/app/admin/lists/warehouse_product/WarehouseProductLists.php @@ -0,0 +1,65 @@ + ['warehouse_id', 'product_id', 'financial_pm'], + ]; + } + + + /** + * @notes 获取商品仓储信息列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/07/31 16:55 + */ + public function lists(): array + { + return WarehouseProduct::where($this->searchWhere) + ->field(['id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'total_price', 'status']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取商品仓储信息数量 + * @return int + * @author admin + * @date 2024/07/31 16:55 + */ + public function count(): int + { + return WarehouseProduct::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/logic/warehouse/WarehouseLogic.php b/app/admin/logic/warehouse/WarehouseLogic.php new file mode 100644 index 000000000..13568bdbe --- /dev/null +++ b/app/admin/logic/warehouse/WarehouseLogic.php @@ -0,0 +1,106 @@ + $params['name'], + 'code' => $params['code'], + 'contacts' => $params['contacts'], + 'tel' => $params['tel'], + 'address' => $params['address'], + 'notes' => $params['notes'], + 'sort' => $params['sort'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑仓库信息 + * @param array $params + * @return bool + * @author admin + * @date 2024/07/31 16:10 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + Warehouse::where('id', $params['id'])->update([ + 'name' => $params['name'], + 'code' => $params['code'], + 'contacts' => $params['contacts'], + 'tel' => $params['tel'], + 'address' => $params['address'], + 'notes' => $params['notes'], + 'sort' => $params['sort'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除仓库信息 + * @param array $params + * @return bool + * @author admin + * @date 2024/07/31 16:10 + */ + public static function delete(array $params): bool + { + return Warehouse::destroy($params['id']); + } + + + /** + * @notes 获取仓库信息详情 + * @param $params + * @return array + * @author admin + * @date 2024/07/31 16:10 + */ + public static function detail($params): array + { + return Warehouse::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php new file mode 100644 index 000000000..b829fc580 --- /dev/null +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -0,0 +1,108 @@ + $params['warehouse_id'], + 'product_id' => $params['product_id'], + 'financial_pm' => $params['financial_pm'], + 'batch' => $params['batch'], + 'nums' => $params['nums'], + 'price' => $params['price'], + 'total_price' => $params['total_price'], + 'status' => $params['status'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑商品仓储信息 + * @param array $params + * @return bool + * @author admin + * @date 2024/07/31 16:55 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + WarehouseProduct::where('id', $params['id'])->update([ + 'warehouse_id' => $params['warehouse_id'], + 'product_id' => $params['product_id'], + 'financial_pm' => $params['financial_pm'], + 'batch' => $params['batch'], + 'nums' => $params['nums'], + 'price' => $params['price'], + 'total_price' => $params['total_price'], + 'status' => $params['status'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除商品仓储信息 + * @param array $params + * @return bool + * @author admin + * @date 2024/07/31 16:55 + */ + public static function delete(array $params): bool + { + return WarehouseProduct::destroy($params['id']); + } + + + /** + * @notes 获取商品仓储信息详情 + * @param $params + * @return array + * @author admin + * @date 2024/07/31 16:55 + */ + public static function detail($params): array + { + return WarehouseProduct::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/validate/warehouse/WarehouseValidate.php b/app/admin/validate/warehouse/WarehouseValidate.php new file mode 100644 index 000000000..e044a6ffa --- /dev/null +++ b/app/admin/validate/warehouse/WarehouseValidate.php @@ -0,0 +1,84 @@ + 'require', + 'name' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'name' => '仓库名称', + ]; + + + /** + * @notes 添加场景 + * @return WarehouseValidate + * @author admin + * @date 2024/07/31 16:10 + */ + public function sceneAdd() + { + return $this->only(['name']); + } + + + /** + * @notes 编辑场景 + * @return WarehouseValidate + * @author admin + * @date 2024/07/31 16:10 + */ + public function sceneEdit() + { + return $this->only(['id','name']); + } + + + /** + * @notes 删除场景 + * @return WarehouseValidate + * @author admin + * @date 2024/07/31 16:10 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return WarehouseValidate + * @author admin + * @date 2024/07/31 16:10 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/admin/validate/warehouse_product/WarehouseProductValidate.php b/app/admin/validate/warehouse_product/WarehouseProductValidate.php new file mode 100644 index 000000000..afbe4862a --- /dev/null +++ b/app/admin/validate/warehouse_product/WarehouseProductValidate.php @@ -0,0 +1,98 @@ + 'require', + 'warehouse_id' => 'require', + 'product_id' => 'require', + 'financial_pm' => 'require', + 'batch' => 'require', + 'nums' => 'require', + 'price' => 'require', + 'total_price' => 'require', + 'status' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'warehouse_id' => '仓库ID', + 'product_id' => '商品ID', + 'financial_pm' => '0 = 出库 1 = 获得', + 'batch' => '批次', + 'nums' => '数量', + 'price' => '价格', + 'total_price' => '总价', + 'status' => '状态', + ]; + + + /** + * @notes 添加场景 + * @return WarehouseProductValidate + * @author admin + * @date 2024/07/31 16:55 + */ + public function sceneAdd() + { + return $this->only(['warehouse_id','product_id','financial_pm','batch','nums','price','total_price','status']); + } + + + /** + * @notes 编辑场景 + * @return WarehouseProductValidate + * @author admin + * @date 2024/07/31 16:55 + */ + public function sceneEdit() + { + return $this->only(['id','warehouse_id','product_id','financial_pm','batch','nums','price','total_price','status']); + } + + + /** + * @notes 删除场景 + * @return WarehouseProductValidate + * @author admin + * @date 2024/07/31 16:55 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return WarehouseProductValidate + * @author admin + * @date 2024/07/31 16:55 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/warehouse/Warehouse.php b/app/common/model/warehouse/Warehouse.php new file mode 100644 index 000000000..4689aefac --- /dev/null +++ b/app/common/model/warehouse/Warehouse.php @@ -0,0 +1,22 @@ +