diff --git a/app/admin/lists/system_store_storage/SystemStoreStorageLists.php b/app/admin/lists/system_store_storage/SystemStoreStorageLists.php index 5918a2e69..42f458067 100644 --- a/app/admin/lists/system_store_storage/SystemStoreStorageLists.php +++ b/app/admin/lists/system_store_storage/SystemStoreStorageLists.php @@ -49,16 +49,16 @@ class SystemStoreStorageLists extends BaseAdminDataLists implements ListsSearchI ->field(['id', 'store_id', 'admin_id', 'staff_id', 'product_id', 'nums', 'status']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) - ->select()->each(function($item){ - $item['system_store_name']=SystemStore::where('id',$item['store_id'])->value('name'); - $item['admin_name']=Admin::where('id',$item['admin_id'])->value('name'); - $item['admin_name']=Admin::where('id',$item['admin_id'])->value('name'); - if($item['staff_id']>0){ - $item['staff_name']=SystemStoreStaff::where('id',$item['staff_id'])->value('staff_name'); - }else{ - $item['staff_name']='无'; + ->select()->each(function ($item) { + $item['system_store_name'] = SystemStore::where('id', $item['store_id'])->value('name'); + $item['admin_name'] = Admin::where('id', $item['admin_id'])->value('name'); + $item['admin_name'] = Admin::where('id', $item['admin_id'])->value('name'); + if ($item['staff_id'] > 0) { + $item['staff_name'] = SystemStoreStaff::where('id', $item['staff_id'])->value('staff_name'); + } else { + $item['staff_name'] = '无'; } - $item['store_name']=StoreProduct::where('id',$item['product_id'])->value('store_name'); + $item['store_name'] = StoreProduct::where('id', $item['product_id'])->value('store_name'); return $item; }) ->toArray(); @@ -76,4 +76,4 @@ class SystemStoreStorageLists extends BaseAdminDataLists implements ListsSearchI return SystemStoreStorage::where($this->searchWhere)->count(); } -} \ No newline at end of file +} diff --git a/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php b/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php index 2cb61584d..c59a2b52d 100644 --- a/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php +++ b/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php @@ -3,6 +3,8 @@ namespace app\admin\logic\system_store_storage; +use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue; use app\common\model\system_store_storage\SystemStoreStorage; use app\common\logic\BaseLogic; use think\facade\Db; @@ -101,4 +103,33 @@ class SystemStoreStorageLogic extends BaseLogic { return SystemStoreStorage::findOrEmpty($params['id'])->toArray(); } -} \ No newline at end of file + + public static function confirm($params) + { + $storage = SystemStoreStorage::where('id', $params['id'])->where('store_id', $params['store_id'])->find(); + if (empty($storage)) { + throw new \Exception('数据不存在'); + } + if ($storage['status'] != 0) { + throw new \Exception('当前状态不能确认入库'); + } + $StoreProduct = StoreBranchProduct::where('store_id', $storage['store_id'])->where('product_id', $storage['product_id'])->find(); + if (empty($StoreProduct)) { + throw new \Exception('商品不存在'); + } + Db::startTrans(); + try { + $StoreProduct->stock += $storage['nums']; + $StoreProduct->save(); + $storage->status = 1; + $storage->staff_id = $params['staff_id']; + $storage->save(); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + throw new \Exception($e->getMessage()); + } + } + +} diff --git a/app/store/controller/store_product/StoreStorageController.php b/app/store/controller/store_product/StoreStorageController.php new file mode 100644 index 000000000..0fc5a2509 --- /dev/null +++ b/app/store/controller/store_product/StoreStorageController.php @@ -0,0 +1,51 @@ +dataLists(new SystemStoreStorageLists()); + } + + #[ + ApiDoc\Title('确认入库'), + ApiDoc\url('/store/store_product/storeStorage/confirm'), + ApiDoc\Method('POST'), + ApiDoc\NotHeaders(), + ApiDoc\Header(ref: [Definitions::class, "token"]), + ApiDoc\Param(name: 'id', type: 'int', require: true, desc: 'id'), + ApiDoc\ResponseSuccess("data", type: "array"), + ] + public function confirm() + { + $params = (new SystemStoreStorageValidate())->post()->goCheck('edit'); + $params['store_id'] = $this->request->adminInfo['store_id']; + $params['staff_id'] = $this->request->adminInfo['admin_id']; + SystemStoreStorageLogic::confirm($params); + return $this->success('操作成功', [], 1, 1); + } + +}