diff --git a/app/admin/controller/inventory_store/InventoryStoreController.php b/app/admin/controller/inventory_store/InventoryStoreController.php new file mode 100644 index 000000000..af2d41d94 --- /dev/null +++ b/app/admin/controller/inventory_store/InventoryStoreController.php @@ -0,0 +1,82 @@ +dataLists(new InventoryStoreLists()); + } + + + /** + * @notes 添加门店盘存 + * @return \think\response\Json + * @author admin + * @date 2025/02/14 11:46 + */ + public function add() + { + $params = (new InventoryStoreValidate())->post()->goCheck('add'); + $result = InventoryStoreLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(InventoryStoreLogic::getError()); + } + + + /** + * @notes 编辑门店盘存 + * @return \think\response\Json + * @author admin + * @date 2025/02/14 11:46 + */ + public function edit() + { + $params = (new InventoryStoreValidate())->post()->goCheck('edit'); + $params['admin_id']=$this->adminId; + $result = InventoryStoreLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(InventoryStoreLogic::getError()); + } + + + /** + * @notes 门店盘存核准 + * @return \think\response\Json + * @author admin + * @date 2025/02/14 11:46 + */ + public function enter_nums() + { + $params = $this->request->post(); + $result = InventoryStoreLogic::enterNums($params); + if (true === $result) { + return $this->success('核准成功', [], 1, 1); + } + } +} \ No newline at end of file diff --git a/app/admin/controller/inventory_warehouse/InventoryWarehouseController.php b/app/admin/controller/inventory_warehouse/InventoryWarehouseController.php new file mode 100644 index 000000000..78ee75c02 --- /dev/null +++ b/app/admin/controller/inventory_warehouse/InventoryWarehouseController.php @@ -0,0 +1,96 @@ +dataLists(new InventoryWarehouseLists()); + } + + + /** + * @notes 添加仓库盘存 + * @return \think\response\Json + * @author admin + * @date 2025/02/14 17:24 + */ + public function add() + { + $params = (new InventoryWarehouseValidate())->post()->goCheck('add'); + $result = InventoryWarehouseLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(InventoryWarehouseLogic::getError()); + } + + + /** + * @notes 编辑仓库盘存 + * @return \think\response\Json + * @author admin + * @date 2025/02/14 17:24 + */ + public function edit() + { + $params = (new InventoryWarehouseValidate())->post()->goCheck('edit'); + $params['admin_id']=$this->adminId; + $result = InventoryWarehouseLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(InventoryWarehouseLogic::getError()); + } + + + /** + * @notes 删除仓库盘存 + * @return \think\response\Json + * @author admin + * @date 2025/02/14 17:24 + */ + public function delete() + { + $params = (new InventoryWarehouseValidate())->post()->goCheck('delete'); + InventoryWarehouseLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + /** + * @notes 门店盘存核准 + * @return \think\response\Json + * @author admin + * @date 2025/02/14 11:46 + */ + public function enter_nums() + { + $params = $this->request->post(); + $params['warehouse_id']=1; + $result = InventoryWarehouseLogic::enterNums($params); + if (true === $result) { + return $this->success('核准成功', [], 1, 1); + } + } +} \ No newline at end of file diff --git a/app/admin/lists/inventory_store/InventoryStoreLists.php b/app/admin/lists/inventory_store/InventoryStoreLists.php new file mode 100644 index 000000000..dfeb044a6 --- /dev/null +++ b/app/admin/lists/inventory_store/InventoryStoreLists.php @@ -0,0 +1,86 @@ + ['store_id', 'nums', 'enter_nums', 'status'], + ]; + } + + + /** + * @notes 获取门店盘存列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2025/02/14 11:46 + */ + public function lists(): array + { + return InventoryStore::where($this->searchWhere) + ->field(['id', 'product_id', 'admin_id', 'staff_id', 'store_id', 'nums', 'enter_nums', 'status', 'create_time']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['create_time' => 'desc']) + ->select()->each(function ($item) { + $item->status_name = match ($item->status) { + 0 => '待盘点', + 1 => '盘点中', + 2 => '盘点完成', + default => '未知', + }; + if($item->admin_id){ + $item->admin_name = Admin::where('id',$item->admin_id)->value('name'); + } + if($item->staff_id){ + $item->staff_name = SystemStoreStaff::where('id',$item->staff_id)->value('staff_name'); + } + if($item->store_id){ + $item->store_name = SystemStore::where('id',$item->store_id)->value('name'); + } + if($item->product_id){ + $item->product_name = StoreProduct::where('id',$item->product_id)->withTrashed()->value('store_name'); + } + }) + ->toArray(); + } + + + /** + * @notes 获取门店盘存数量 + * @return int + * @author admin + * @date 2025/02/14 11:46 + */ + public function count(): int + { + return InventoryStore::where($this->searchWhere)->count(); + } +} diff --git a/app/admin/lists/inventory_warehouse/InventoryWarehouseLists.php b/app/admin/lists/inventory_warehouse/InventoryWarehouseLists.php new file mode 100644 index 000000000..d428c934e --- /dev/null +++ b/app/admin/lists/inventory_warehouse/InventoryWarehouseLists.php @@ -0,0 +1,79 @@ + ['product_id', 'warehouse_id'], + ]; + } + + + /** + * @notes 获取仓库盘存列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2025/02/14 17:24 + */ + public function lists(): array + { + return InventoryWarehouse::where($this->searchWhere) + ->field(['id', 'product_id', 'admin_id', 'warehouse_id', 'nums', 'enter_nums', 'status','create_time']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($item) { + $item->status_name = match ($item->status) { + 0 => '待盘点', + 1 => '盘点中', + 2 => '盘点完成', + default => '未知', + }; + if($item->admin_id){ + $item->admin_name = Admin::where('id',$item->admin_id)->value('name'); + } + if($item->product_id){ + $item->product_name = StoreProduct::where('id',$item->product_id)->withTrashed()->value('store_name'); + } + }) + ->toArray(); + } + + + /** + * @notes 获取仓库盘存数量 + * @return int + * @author admin + * @date 2025/02/14 17:24 + */ + public function count(): int + { + return InventoryWarehouse::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/lists/warehouse_product/StoreWarehouseProductLists.php b/app/admin/lists/warehouse_product/StoreWarehouseProductLists.php index c62e1aee4..fefdb4e9e 100644 --- a/app/admin/lists/warehouse_product/StoreWarehouseProductLists.php +++ b/app/admin/lists/warehouse_product/StoreWarehouseProductLists.php @@ -4,6 +4,7 @@ namespace app\admin\lists\warehouse_product; use app\admin\lists\BaseAdminDataLists; +use app\common\model\beforehand_order\BeforehandOrder; use app\common\model\warehouse_product\WarehouseProduct; use app\common\lists\ListsSearchInterface; use app\common\model\auth\Admin; @@ -65,7 +66,7 @@ class StoreWarehouseProductLists extends BaseAdminDataLists implements ListsSear $this->searchWhere[] = ['financial_pm', '=',0]; $this->searchWhere[] = ['order_type', 'in',[1, 2, 3, 4, 8]]; return WarehouseProduct::where($this->searchWhere) - ->field(['id', 'admin_id', 'store_id','product_id', 'nums', 'refund_nums', 'status', 'mark', 'create_time',]) + ->field(['id', 'admin_id', 'store_id','product_id', 'nums', 'refund_nums', 'status', 'mark', 'create_time', 'order_type']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) // ->withTrashed() @@ -96,6 +97,7 @@ class StoreWarehouseProductLists extends BaseAdminDataLists implements ListsSear $item->unit_name = StoreProductUnit::where('id', $find->unit)->value('name'); } } + $item->order_type_name = BeforehandOrder::getOrderTypeName($item->order_type); }) ->toArray(); } diff --git a/app/admin/lists/warehouse_product/WarehouseProductLists.php b/app/admin/lists/warehouse_product/WarehouseProductLists.php index 20c42fcbd..1c637e7ca 100644 --- a/app/admin/lists/warehouse_product/WarehouseProductLists.php +++ b/app/admin/lists/warehouse_product/WarehouseProductLists.php @@ -73,7 +73,7 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt } } return WarehouseProduct::where($this->searchWhere) - ->field(['id', 'code','pay_type','oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'purchase', 'cost', 'total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time','is_pay']) + ->field(['id', 'code','pay_type','oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'purchase', 'cost', 'total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time','is_pay', 'order_type']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) // ->withTrashed() diff --git a/app/admin/logic/inventory_store/InventoryStoreLogic.php b/app/admin/logic/inventory_store/InventoryStoreLogic.php new file mode 100644 index 000000000..44cb5062e --- /dev/null +++ b/app/admin/logic/inventory_store/InventoryStoreLogic.php @@ -0,0 +1,107 @@ +whereDay('create_time')->find(); + if($find){ + throw new BusinessException('今日数据已生成'); + } + $arr=StoreBranchProduct::where('store_id',$params['store_id'])->field('product_id,store_id,stock as nums')->select()->toArray(); + (new InventoryStore())->saveAll($arr); + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 编辑门店盘存 + * @param array $params + * @return bool + * @author admin + * @date 2025/02/14 11:46 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + InventoryStore::where('id', $params['id'])->update([ + 'admin_id'=>$params['admin_id']??0, + 'enter_nums'=>$params['nums'] + ]); + + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + public static function enterNums(array $params): bool + { + Db::startTrans(); + try { + InventoryStore::where('store_id', $params['store_id'])->whereDay('create_time',$params['create_time'])->update([ + 'status'=>2 + ]); + + $arr=InventoryStore::where('store_id', $params['store_id'])->where('nums','<>',new Raw('enter_nums'))->whereDay('create_time',$params['create_time'])->select(); + foreach ($arr as $k=>$v){ + StoreBranchProduct::where('product_id',$v['product_id'])->where('store_id',$v['store_id'])->update([ + 'stock'=>$v['enter_nums'] + ]); + } + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 删除门店盘存 + * @param array $params + * @return bool + * @author admin + * @date 2025/02/14 11:46 + */ + public static function delete(array $params): bool + { + return InventoryStore::destroy($params['id']); + } + +} \ No newline at end of file diff --git a/app/admin/logic/inventory_warehouse/InventoryWarehouseLogic.php b/app/admin/logic/inventory_warehouse/InventoryWarehouseLogic.php new file mode 100644 index 000000000..32e82fe61 --- /dev/null +++ b/app/admin/logic/inventory_warehouse/InventoryWarehouseLogic.php @@ -0,0 +1,108 @@ +whereDay('create_time')->find(); + if($find){ + throw new BusinessException('今日数据已生成'); + } + $arr=WarehouseProductStorege::where('warehouse_id',1)->field('product_id,nums,warehouse_id')->select()->toArray(); + (new InventoryWarehouse())->saveAll($arr); + + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 编辑仓库盘存 + * @param array $params + * @return bool + * @author admin + * @date 2025/02/14 17:24 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + InventoryWarehouse::where('id', $params['id'])->update([ + 'admin_id'=>$params['admin_id']??0, + 'enter_nums'=>$params['nums'] + ]); + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 删除仓库盘存 + * @param array $params + * @return bool + * @author admin + * @date 2025/02/14 17:24 + */ + public static function delete(array $params): bool + { + return InventoryWarehouse::destroy($params['id']); + } + + public static function enterNums(array $params): bool + { + Db::startTrans(); + try { + InventoryWarehouse::where('warehouse_id', $params['warehouse_id'])->whereDay('create_time',$params['create_time'])->update([ + 'status'=>2 + ]); + + $arr=InventoryWarehouse::where('warehouse_id', $params['warehouse_id'])->where('nums','<>',new Raw('enter_nums'))->whereDay('create_time',$params['create_time'])->select(); + foreach ($arr as $k=>$v){ + WarehouseProductStorege::where('product_id',$v['product_id'])->where('warehouse_id',$v['warehouse_id'])->update([ + 'nums'=>$v['enter_nums'] + ]); + } + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + +} \ No newline at end of file diff --git a/app/admin/validate/inventory_store/InventoryStoreValidate.php b/app/admin/validate/inventory_store/InventoryStoreValidate.php new file mode 100644 index 000000000..5891017e1 --- /dev/null +++ b/app/admin/validate/inventory_store/InventoryStoreValidate.php @@ -0,0 +1,82 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return InventoryStoreValidate + * @author admin + * @date 2025/02/14 11:46 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return InventoryStoreValidate + * @author admin + * @date 2025/02/14 11:46 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return InventoryStoreValidate + * @author admin + * @date 2025/02/14 11:46 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return InventoryStoreValidate + * @author admin + * @date 2025/02/14 11:46 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/admin/validate/inventory_warehouse/InventoryWarehouseValidate.php b/app/admin/validate/inventory_warehouse/InventoryWarehouseValidate.php new file mode 100644 index 000000000..99da9280f --- /dev/null +++ b/app/admin/validate/inventory_warehouse/InventoryWarehouseValidate.php @@ -0,0 +1,82 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return InventoryWarehouseValidate + * @author admin + * @date 2025/02/14 17:24 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return InventoryWarehouseValidate + * @author admin + * @date 2025/02/14 17:24 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return InventoryWarehouseValidate + * @author admin + * @date 2025/02/14 17:24 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return InventoryWarehouseValidate + * @author admin + * @date 2025/02/14 17:24 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/beforehand_order/BeforehandOrder.php b/app/common/model/beforehand_order/BeforehandOrder.php index 1ec1322f3..f709fccac 100644 --- a/app/common/model/beforehand_order/BeforehandOrder.php +++ b/app/common/model/beforehand_order/BeforehandOrder.php @@ -29,8 +29,10 @@ class BeforehandOrder extends BaseModel 3 => '一条龙订单', 4 => '线上订单', 5 => '仓库补货', - 6 => '采购订单', - 7 => '其他订单', + 6 => '往期补单', + 7 => '采购订单', + 8 => '其他订单', + 9 => '往期补单', ]; return $typeMap[$type] ?? ''; } diff --git a/app/common/model/inventory_store/InventoryStore.php b/app/common/model/inventory_store/InventoryStore.php new file mode 100644 index 000000000..eeed76808 --- /dev/null +++ b/app/common/model/inventory_store/InventoryStore.php @@ -0,0 +1,22 @@ +