diff --git a/app/admin/controller/inventory_store/InventoryStoreController.php b/app/admin/controller/inventory_store/InventoryStoreController.php new file mode 100644 index 000000000..d7c844d8a --- /dev/null +++ b/app/admin/controller/inventory_store/InventoryStoreController.php @@ -0,0 +1,81 @@ +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'); + $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/lists/inventory_store/InventoryStoreLists.php b/app/admin/lists/inventory_store/InventoryStoreLists.php new file mode 100644 index 000000000..aede20268 --- /dev/null +++ b/app/admin/lists/inventory_store/InventoryStoreLists.php @@ -0,0 +1,71 @@ + ['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 => '未知', + }; + }) + ->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/logic/inventory_store/InventoryStoreLogic.php b/app/admin/logic/inventory_store/InventoryStoreLogic.php new file mode 100644 index 000000000..bd713a63c --- /dev/null +++ b/app/admin/logic/inventory_store/InventoryStoreLogic.php @@ -0,0 +1,113 @@ +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([ + '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','<>','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']); + } + + + /** + * @notes 获取门店盘存详情 + * @param $params + * @return array + * @author admin + * @date 2025/02/14 11:46 + */ + public static function detail($params): array + { + return InventoryStore::findOrEmpty($params['id'])->toArray(); + } +} \ 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/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 @@ +