diff --git a/app/admin/controller/purchase_order/PurchaseOrderController.php b/app/admin/controller/purchase_order/PurchaseOrderController.php new file mode 100644 index 000000000..0555831d2 --- /dev/null +++ b/app/admin/controller/purchase_order/PurchaseOrderController.php @@ -0,0 +1,13 @@ +dataLists(new PurchaseOrderLists()); + } + +} \ No newline at end of file diff --git a/app/admin/controller/store_product/StoreProductController.php b/app/admin/controller/store_product/StoreProductController.php index 4e9046b04..6ea157ae6 100644 --- a/app/admin/controller/store_product/StoreProductController.php +++ b/app/admin/controller/store_product/StoreProductController.php @@ -99,15 +99,16 @@ class StoreProductController extends BaseAdminController $product_arr = $this->request->post('product_arr'); $store_arr = $this->request->post('store_arr'); $stock_type = $this->request->post('stock_type',1); + $warehouse_id = $this->request->post('warehouse_id'); if (count($store_arr) == 1) { $store_id = $store_arr[0]; foreach ($product_arr as $key => $arr) { - Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id,'stock_type'=>$stock_type, 'admin_id' => $this->adminId]); + Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id,'stock_type'=>$stock_type, 'admin_id' => $this->adminId,'warehouse_id'=>$warehouse_id]); } } else { foreach ($product_arr as $key => $arr) { foreach ($store_arr as $k => $store_id) { - Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id,'stock_type'=>$stock_type, 'admin_id' => $this->adminId]); + Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id,'stock_type'=>$stock_type, 'admin_id' => $this->adminId,'warehouse_id'=>$warehouse_id]); } } } 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..6f5817b35 --- /dev/null +++ b/app/admin/controller/warehouse_product/WarehouseProductController.php @@ -0,0 +1,108 @@ +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'); + $params['admin_id']=$this->adminId; + $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'); + $params['admin_id']=$this->adminId; + $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); + } + + /** + * 确认操作 + */ + public function enter(){ + $id=$this->request->post('id'); + $result = WarehouseProductLogic::enter($id); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(WarehouseProductLogic::getError()); + return $this->success($result); + } +} \ No newline at end of file diff --git a/app/admin/controller/warehouse_product_storege/WarehouseProductStoregeController.php b/app/admin/controller/warehouse_product_storege/WarehouseProductStoregeController.php new file mode 100644 index 000000000..cfa6f487f --- /dev/null +++ b/app/admin/controller/warehouse_product_storege/WarehouseProductStoregeController.php @@ -0,0 +1,95 @@ +dataLists(new WarehouseProductStoregeLists()); + } + + + // /** + // * @notes 添加仓库商品存储 + // * @return \think\response\Json + // * @author admin + // * @date 2024/08/01 10:22 + // */ + // public function add() + // { + // $params = (new WarehouseProductStoregeValidate())->post()->goCheck('add'); + // $result = WarehouseProductStoregeLogic::add($params); + // if (true === $result) { + // return $this->success('添加成功', [], 1, 1); + // } + // return $this->fail(WarehouseProductStoregeLogic::getError()); + // } + + + // /** + // * @notes 编辑仓库商品存储 + // * @return \think\response\Json + // * @author admin + // * @date 2024/08/01 10:22 + // */ + // public function edit() + // { + // $params = (new WarehouseProductStoregeValidate())->post()->goCheck('edit'); + // $result = WarehouseProductStoregeLogic::edit($params); + // if (true === $result) { + // return $this->success('编辑成功', [], 1, 1); + // } + // return $this->fail(WarehouseProductStoregeLogic::getError()); + // } + + + // /** + // * @notes 删除仓库商品存储 + // * @return \think\response\Json + // * @author admin + // * @date 2024/08/01 10:22 + // */ + // public function delete() + // { + // $params = (new WarehouseProductStoregeValidate())->post()->goCheck('delete'); + // WarehouseProductStoregeLogic::delete($params); + // return $this->success('删除成功', [], 1, 1); + // } + + + // /** + // * @notes 获取仓库商品存储详情 + // * @return \think\response\Json + // * @author admin + // * @date 2024/08/01 10:22 + // */ + // public function detail() + // { + // $params = (new WarehouseProductStoregeValidate())->goCheck('detail'); + // $result = WarehouseProductStoregeLogic::detail($params); + // return $this->data($result); + // } + + +} \ No newline at end of file diff --git a/app/admin/lists/purchase_order/PurchaseOrderLists.php b/app/admin/lists/purchase_order/PurchaseOrderLists.php new file mode 100644 index 000000000..29fe0f1d9 --- /dev/null +++ b/app/admin/lists/purchase_order/PurchaseOrderLists.php @@ -0,0 +1,62 @@ + ['store_id', 'order_id'], + ]; + } + + + /** + * @notes 获取采购订单列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 17:09 + */ + public function lists(): array + { + return PurchaseOrder::where($this->searchWhere) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select(); + } + + + /** + * @notes 获取采购订单数量 + * @return int + * @author admin + * @date 2024/05/31 17:09 + */ + public function count(): int + { + return PurchaseOrder::where($this->searchWhere)->count(); + } + +} \ 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..dbefbe64d --- /dev/null +++ b/app/admin/lists/warehouse_product/WarehouseProductLists.php @@ -0,0 +1,89 @@ + ['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', 'admin_id','warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'total_price', 'manufacture','expiration_date','status']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($item){ + if($item->financial_pm==0){ + $item->financial_pm_name='出库'; + }else{ + $item->financial_pm_name='入库'; + } + if($item->status==0){ + $item->status_name='未确认'; + }else{ + $item->status_name='已确认'; + } + if($item->admin_id){ + $item->admin_name=Admin::where('id',$item->admin_id)->value('name'); + }else{ + $item->admin_name=''; + } + if($item->product_id){ + $item->store_name=StoreProduct::where('id',$item->product_id)->value('store_name'); + }else{ + $item->store_name=''; + } + $item->expiration_date=$item->expiration_date?date('Y-m-d',$item->expiration_date):''; + $item->manufacture=$item->manufacture?date('Y-m-d',$item->manufacture):''; + }) + ->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/lists/warehouse_product_storege/WarehouseProductStoregeLists.php b/app/admin/lists/warehouse_product_storege/WarehouseProductStoregeLists.php new file mode 100644 index 000000000..6bd72ec01 --- /dev/null +++ b/app/admin/lists/warehouse_product_storege/WarehouseProductStoregeLists.php @@ -0,0 +1,85 @@ + ['warehouse_id', 'product_id', 'nums', 'price', 'total_price', 'status'], + ]; + } + + + /** + * @notes 获取仓库商品存储列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/08/01 10:22 + */ + public function lists(): array + { + return WarehouseProductStorege::where($this->searchWhere) + ->field(['id', 'warehouse_id', 'product_id', 'nums', 'price', 'total_price', 'status']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($item){ + $item->warehouse_name = Warehouse::where('id',$item->warehouse_id)->value('name'); + $find= StoreProduct::where('id',$item->product_id)->find(); + if($find){ + $item->store_name = $find->store_name; + $item->image = $find->image; + $item->bar_code = $find->bar_code; + $item->price = $find->price; + $item->cost = $find->cost; + $item->purchase = $find->purchase; + $item->store_info = $find->store_info; + $item->rose = $find->rose; + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); + $item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name'); + } + $item['stock']=$item['nums']; + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取仓库商品存储数量 + * @return int + * @author admin + * @date 2024/08/01 10:22 + */ + public function count(): int + { + return WarehouseProductStorege::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..0511360d8 --- /dev/null +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -0,0 +1,158 @@ + $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']??'', + 'admin_id' => $params['admin_id'], + 'code' => $params['code']??'', + 'manufacture' => $params['manufacture']?strtotime($params['manufacture']):'', + 'expiration_date' =>$params['expiration_date']?strtotime($params['expiration_date']):'', + 'status' => $params['status']??0, + 'mark' => $params['mark']??'', + ]); + self::enter($res['id']); + 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'], + 'admin_id' => $params['admin_id'], + 'total_price' => $params['total_price'], + 'code' => $params['code'], + 'manufacture' => strtotime($params['manufacture']), + 'expiration_date' => strtotime($params['expiration_date']), + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + /** + * @notes 确认商品仓储信息 + * @param array $params + * @author admin + * @date 2024/07/31 16:55 + */ + public static function enter($id) + { + Db::startTrans(); + try { + $find=WarehouseProduct::where('id',$id)->find(); + $find->status=1; + $find->save(); + StoreProduct::where('id',$find['product_id'])->inc('stock',$find['nums'])->update(); + $storege=WarehouseProductStorege::where('warehouse_id',$find['warehouse_id'])->where('product_id',$find['product_id'])->find(); + if($storege){ + $storege->nums=$storege->nums+$find['nums']; + $storege->save(); + }else{ + WarehouseProductStorege::create([ + 'warehouse_id' => $find['warehouse_id'], + 'product_id' => $find['product_id'], + 'nums' => $find['nums'], + ]); + } + 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 + { + $data= WarehouseProduct::findOrEmpty($params['id'])->toArray(); + if($data){ + $data['manufacture']=date('Y-m-d',$data['manufacture']); + $data['expiration_date']=date('Y-m-d',$data['expiration_date']); + + } + return $data; + } +} \ No newline at end of file diff --git a/app/admin/logic/warehouse_product_storege/WarehouseProductStoregeLogic.php b/app/admin/logic/warehouse_product_storege/WarehouseProductStoregeLogic.php new file mode 100644 index 000000000..eac41ece8 --- /dev/null +++ b/app/admin/logic/warehouse_product_storege/WarehouseProductStoregeLogic.php @@ -0,0 +1,104 @@ + $params['warehouse_id'], + 'product_id' => $params['product_id'], + '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/08/01 10:22 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + WarehouseProductStorege::where('id', $params['id'])->update([ + 'warehouse_id' => $params['warehouse_id'], + 'product_id' => $params['product_id'], + '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/08/01 10:22 + */ + public static function delete(array $params): bool + { + return WarehouseProductStorege::destroy($params['id']); + } + + + /** + * @notes 获取仓库商品存储详情 + * @param $params + * @return array + * @author admin + * @date 2024/08/01 10:22 + */ + public static function detail($params): array + { + return WarehouseProductStorege::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..a3a7cb795 --- /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']); + } + + + /** + * @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']); + } + + + /** + * @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/admin/validate/warehouse_product_storege/WarehouseProductStoregeValidate.php b/app/admin/validate/warehouse_product_storege/WarehouseProductStoregeValidate.php new file mode 100644 index 000000000..45905ac9d --- /dev/null +++ b/app/admin/validate/warehouse_product_storege/WarehouseProductStoregeValidate.php @@ -0,0 +1,94 @@ + 'require', + 'warehouse_id' => 'require', + 'product_id' => 'require', + 'nums' => 'require', + 'price' => 'require', + 'total_price' => 'require', + 'status' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'warehouse_id' => '仓库ID', + 'product_id' => '商品ID', + 'nums' => '数量', + 'price' => '价格', + 'total_price' => '价格', + 'status' => '状态', + ]; + + + /** + * @notes 添加场景 + * @return WarehouseProductStoregeValidate + * @author admin + * @date 2024/08/01 10:22 + */ + public function sceneAdd() + { + return $this->only(['warehouse_id','product_id','nums','price','total_price','status']); + } + + + /** + * @notes 编辑场景 + * @return WarehouseProductStoregeValidate + * @author admin + * @date 2024/08/01 10:22 + */ + public function sceneEdit() + { + return $this->only(['id','warehouse_id','product_id','nums','price','total_price','status']); + } + + + /** + * @notes 删除场景 + * @return WarehouseProductStoregeValidate + * @author admin + * @date 2024/08/01 10:22 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return WarehouseProductStoregeValidate + * @author admin + * @date 2024/08/01 10:22 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/purchase_order/PurchaseOrder.php b/app/common/model/purchase_order/PurchaseOrder.php new file mode 100644 index 000000000..10cada22f --- /dev/null +++ b/app/common/model/purchase_order/PurchaseOrder.php @@ -0,0 +1,22 @@ +findOrEmpty()->toArray(); if($stock_type == 1){ $this->ordinary($product_arr,$store_id,$admin_id,$find); @@ -40,7 +43,7 @@ class StoreStorageSend implements Consumer } /**普通 */ - public function ordinary($product_arr,$store_id,$admin_id,$find){ + public function ordinary($product_arr,$store_id,$admin_id,$find,$warehouse_id){ $store_find = StoreBranchProduct::where(['product_id' => $product_arr['id'], 'store_id' => $store_id])->findOrEmpty()->toArray(); if ($find && !$store_find) { $attr_value = StoreProductAttrValue::where('product_id', $product_arr['id'])->findOrEmpty(); @@ -82,7 +85,7 @@ class StoreStorageSend implements Consumer ]; StoreBranchProductAttrValue::create($arr); if ($product_arr['stock'] > 0) { - $this->storage($find, $store_id, $admin_id, $product_arr); + $this->storage($find, $store_id, $admin_id, $product_arr,$warehouse_id); } StoreProductLogic::updateGoodsclass($find['cate_id'],$store_id); Db::commit(); @@ -109,7 +112,7 @@ class StoreStorageSend implements Consumer } /**兑换 */ - public function exchange($product_arr,$store_id,$admin_id,$find){ + public function exchange($product_arr,$store_id,$admin_id,$find,$warehouse_id){ $store_find = StoreBranchProductExchange::where(['product_id' => $product_arr['id'], 'store_id' => $store_id])->findOrEmpty()->toArray(); if ($find && !$store_find) { Db::startTrans(); @@ -133,7 +136,7 @@ class StoreStorageSend implements Consumer ]; StoreBranchProductExchange::create($product); if ($product_arr['stock'] > 0) { - $this->storage($find, $store_id, $admin_id, $product_arr); + $this->storage($find, $store_id, $admin_id, $product_arr,$warehouse_id); } // StoreProductLogic::updateGoodsclass($find['cate_id'],$store_id); Db::commit(); @@ -158,7 +161,7 @@ class StoreStorageSend implements Consumer } } } - public function storage($find, $store_id, $admin_id, $product_arr,$stock_type=1) + public function storage($find, $store_id, $admin_id, $product_arr,$stock_type=1,$warehouse_id=0) { $storage = [ 'product_id' => $product_arr['id'], @@ -167,12 +170,27 @@ class StoreStorageSend implements Consumer 'admin_id' => $admin_id, 'type' => $stock_type, ]; - if ($find['stock'] < $product_arr['stock']) { - $storage['status'] = -1; - $storage['mark'] = '库存不足,主库存为:' . $find['stock']; + $data=[ + 'warehouse_id'=>$warehouse_id, + 'product_id' => $product_arr['id'], + 'financial_pm' => 0, + 'batch' => $product_arr['batch']??1, + 'nums' => $product_arr['stock'], + 'status' =>1, + 'admin_id' =>$admin_id, + ]; + $warehouse=WarehouseProductStorege::where('warehouse_id',$warehouse_id)->where('product_id',$product_arr['id'])->find(); + if ($warehouse) { + if($warehouse['nums']< $product_arr['stock']){ + $storage['status'] = -1; + $storage['mark'] = '库存不足,分库存为:' .$warehouse['nums']; + $data['mark'] = '库存不足,分库存为:' .$warehouse['nums'].' 总仓库存为:'.$find['stock']; + } SystemStoreStorage::create($storage); + WarehouseProductLogic::add($data); } else { SystemStoreStorage::create($storage); + WarehouseProductLogic::add($data); StoreProduct::where('id', $product_arr['id'])->dec('stock', $product_arr['stock'])->update(); } }