diff --git a/app/admin/controller/system_store_storage/SystemStoreStorageController.php b/app/admin/controller/system_store_storage/SystemStoreStorageController.php index 146f97de..fe21f824 100644 --- a/app/admin/controller/system_store_storage/SystemStoreStorageController.php +++ b/app/admin/controller/system_store_storage/SystemStoreStorageController.php @@ -56,6 +56,7 @@ class SystemStoreStorageController extends BaseAdminController public function edit() { $params = (new SystemStoreStorageValidate())->post()->goCheck('edit'); + $params['admin_id']=$this->adminId; $result = SystemStoreStorageLogic::edit($params); if (true === $result) { return $this->success('编辑成功', [], 1, 1); diff --git a/app/admin/lists/store_finance_flow/StoreFinanceFlowLists.php b/app/admin/lists/store_finance_flow/StoreFinanceFlowLists.php index c4e39bbd..c3ef1689 100644 --- a/app/admin/lists/store_finance_flow/StoreFinanceFlowLists.php +++ b/app/admin/lists/store_finance_flow/StoreFinanceFlowLists.php @@ -49,33 +49,6 @@ class StoreFinanceFlowLists extends BaseAdminDataLists implements ListsSearchInt public function lists(): array { return StoreFinanceFlow::where($this->searchWhere) - ->when(!empty($this->request->adminInfo['store_id']), function ($query) { - $query->where('store_id', $this->request->adminInfo['store_id']); - }) - ->when(!empty($this->params['keyword']), function (Query $query) { - $userIds = User::where('nickname', 'like', "%{$this->params['keyword']}%")->column('id'); - $query->where(function ($query) use($userIds) { - $query->where('user_id', 'in', $userIds)->whereOr('financial_record_sn', 'like', "%{$this->params['keyword']}%"); - }); - }) - ->when(!empty($this->params['date_type']) && !empty($this->params['date']), function (Query $query) { - switch ($this->params['date_type']) { - case 2: - $start = new \DateTime($this->params['date']); - $start = $start->getTimestamp(); - $end = $start + (86400 * 7); - break; - case 3: - $start = strtotime($this->params['date']); - $end = strtotime('+1 month', strtotime($this->params['date'])); - break; - default: - $start = strtotime($this->params['date']); - $end = strtotime($this->params['date']) + 86400; - break; - } - $query->whereBetweenTime('create_time', $start, $end); - }) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item) { @@ -110,44 +83,7 @@ class StoreFinanceFlowLists extends BaseAdminDataLists implements ListsSearchInt */ public function count(): int { - return StoreFinanceFlow::where($this->searchWhere) - ->when(!empty($this->params['start_time']), function ($query) { - $query->whereTime('create_time', '>=', $this->params['start_time']); - }) - ->when(!empty($this->params['end_time']), function ($query) { - if ($this->params['end_time'] == $this->params['start_time']) { - $this->params['end_time'] = strtotime($this->params['end_time']) + 86399; - } - $query->whereTime('create_time', '<=', $this->params['end_time']); - }) - ->when(!empty($this->request->adminInfo['store_id']), function ($query) { - $query->where('store_id', $this->request->adminInfo['store_id']); - }) - ->when(!empty($this->params['keyword']), function (Query $query) { - $userIds = User::where('nickname', 'like', "%{$this->params['keyword']}%")->column('id'); - $query->where(function ($query) use($userIds) { - $query->where('user_id', 'in', $userIds)->whereOr('financial_record_sn', 'like', "%{$this->params['keyword']}%"); - }); - }) - ->when(!empty($this->params['date_type']) && !empty($this->params['date']), function (Query $query) { - switch ($this->params['date_type']) { - case 2: - $start = new \DateTime($this->params['date']); - $start = $start->getTimestamp(); - $end = $start + (86400 * 7); - break; - case 3: - $start = strtotime($this->params['date']); - $end = strtotime('+1 month', strtotime($this->params['date'])); - break; - default: - $start = strtotime($this->params['date']); - $end = strtotime($this->params['date']) + 86400; - break; - } - $query->whereBetweenTime('create_time', $start, $end); - }) - ->count(); + return StoreFinanceFlow::where($this->searchWhere)->count(); } } diff --git a/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php b/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php index c59a2b52..f9f75441 100644 --- a/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php +++ b/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php @@ -7,6 +7,7 @@ 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 app\common\model\store_product\StoreProduct; use think\facade\Db; @@ -58,17 +59,20 @@ class SystemStoreStorageLogic extends BaseLogic */ public static function edit(array $params): bool { + $stock=StoreProduct::where('id', $params['product_id'])->value('stock'); + $nums=SystemStoreStorage::where('id', $params['id'])->value('nums'); + $stock=bcadd($stock,$nums); + if($stock<$params['nums']){ + self::setError('库存不足,主库为:'.$stock); + return false; + } Db::startTrans(); try { SystemStoreStorage::where('id', $params['id'])->update([ - 'store_id' => $params['store_id'], - 'admin_id' => $params['admin_id'], - 'staff_id' => $params['staff_id'], - 'product_id' => $params['product_id'], 'nums' => $params['nums'], - 'status' => $params['status'] + 'admin_id' => $params['admin_id'], ]); - + StoreProduct::where('id', $params['product_id'])->update(['stock'=>bcsub($stock,$params['nums'])]); Db::commit(); return true; } catch (\Exception $e) { diff --git a/app/admin/validate/system_store_storage/SystemStoreStorageValidate.php b/app/admin/validate/system_store_storage/SystemStoreStorageValidate.php index b7959cfa..5391edce 100644 --- a/app/admin/validate/system_store_storage/SystemStoreStorageValidate.php +++ b/app/admin/validate/system_store_storage/SystemStoreStorageValidate.php @@ -20,6 +20,8 @@ class SystemStoreStorageValidate extends BaseValidate */ protected $rule = [ 'id' => 'require', + 'product_id' => 'require', + 'nums' => 'require', ]; @@ -29,6 +31,8 @@ class SystemStoreStorageValidate extends BaseValidate */ protected $field = [ 'id' => 'id', + 'product_id' => '商品id', + 'nums' => '入库数量', ]; @@ -52,7 +56,7 @@ class SystemStoreStorageValidate extends BaseValidate */ public function sceneEdit() { - return $this->only(['id']); + return $this->only(['id','product_id','nums']); }