From 66b74b6e7ce06e0893690d790791535090b14edc Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 11 Feb 2025 10:43:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor(warehouse):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E4=BB=93=E5=BA=93=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改了 SystemStoreStorageController 中的 lists 方法,使用 StoreWarehouseProductLists 替代 SystemStoreStorageLists - 更新了 SystemStoreStorageLogic 中的数据查询,使用 WarehouseProduct 替代 SystemStoreStorage - 调整了 WarehouseProductLogic 中的入库逻辑,注释掉了创建 SystemStoreStorage 记录的部分 - 修改了 WarehouseProductLogic 中的保存逻辑,将状态设置为 0 --- .../SystemStoreStorageController.php | 4 +- .../StoreWarehouseProductLists.php | 182 ++++++++++++++++++ .../SystemStoreStorageLogic.php | 6 +- .../WarehouseProductLogic.php | 30 +-- 4 files changed, 204 insertions(+), 18 deletions(-) create mode 100644 app/admin/lists/warehouse_product/StoreWarehouseProductLists.php diff --git a/app/admin/controller/system_store_storage/SystemStoreStorageController.php b/app/admin/controller/system_store_storage/SystemStoreStorageController.php index c584b8c19..76b4aba3c 100644 --- a/app/admin/controller/system_store_storage/SystemStoreStorageController.php +++ b/app/admin/controller/system_store_storage/SystemStoreStorageController.php @@ -5,6 +5,7 @@ namespace app\admin\controller\system_store_storage; use app\admin\controller\BaseAdminController; use app\admin\lists\system_store_storage\SystemStoreStorageLists; +use app\admin\lists\warehouse_product\StoreWarehouseProductLists; use app\admin\logic\store_product\StoreProductLogic; use app\admin\logic\system_store_storage\SystemStoreStorageLogic; use app\admin\validate\system_store_storage\SystemStoreStorageValidate; @@ -29,7 +30,8 @@ class SystemStoreStorageController extends BaseAdminController */ public function lists() { - return $this->dataLists(new SystemStoreStorageLists()); + // return $this->dataLists(new SystemStoreStorageLists()); + return $this->dataLists(new StoreWarehouseProductLists()); } diff --git a/app/admin/lists/warehouse_product/StoreWarehouseProductLists.php b/app/admin/lists/warehouse_product/StoreWarehouseProductLists.php new file mode 100644 index 000000000..bccc99cbf --- /dev/null +++ b/app/admin/lists/warehouse_product/StoreWarehouseProductLists.php @@ -0,0 +1,182 @@ + ['store_id', 'status',], + 'between_time' => 'create_time' + ]; + } + + + /** + * @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 + { + if ($this->request->get('product_name')) { + $product_name = $this->request->get('product_name'); + $ids = StoreProduct::where('store_name', 'like', '%' . $product_name . '%')->withTrashed()->column('id'); + if ($ids) { + $this->searchWhere[] = ['product_id', 'in', $ids]; + $this->ids = $ids; + } else { + return []; + } + } + $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', 'status', 'mark', 'create_time',]) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + // ->withTrashed() + ->select()->each(function ($item) { + $item->store_name = ''; + $item->image = ''; + $item->unit_name = ''; + if ($item->store_id > 0) { + $item->system_store_name = SystemStore::where('id', $item->store_id)->value('name'); + } else { + $item->system_store_name = ''; + } + if ($item->status == 0) { + $item->status_name = '未确认'; + } elseif ($item->status == 1) { + $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) { + $find = StoreProduct::where('id', $item->product_id)->field('image,store_name,unit')->withTrashed()->find(); + if($find){ + $item->store_name = $find->store_name; + $item->image = $find->image; + $item->unit_name = StoreProductUnit::where('id', $find->unit)->value('name'); + } + } + }) + ->toArray(); + } + + + /** + * @notes 获取商品仓储信息数量 + * @return int + * @author admin + * @date 2024/07/31 16:55 + */ + public function count(): int + { + if ($this->ids) { + return WarehouseProduct::whereIn('id', $this->ids)->where($this->searchWhere)->count(); + } else { + return WarehouseProduct::where($this->searchWhere)->count(); + } + } + /** + * @notes 导出文件名 + * @return string + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setFileName(): string + { + $financial_pm = $this->request->get('financial_pm'); + if ($financial_pm == 1) { + return '入库列表'; + } + return '出库列表'; + } + + + /** + * @notes 导出字段 + * @return string[] + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setExcelFields(): array + { + $financial_pm = $this->request->get('financial_pm'); + if ($financial_pm == 1) { + $data = [ + 'admin_name' => '操作人员', + 'warehouse_name' => '仓库', + 'supplier_name' => '供应商', + 'store_name' => '商品名称', + 'financial_pm_name' => '出入库', + 'code' => '入库单', + 'batch' => '批次', + 'nums' => '数量', + 'manufacture' => '生产日期', + 'expiration_date' => '保质期', + 'purchase' => '采购价', + 'price' => '零售', + 'total_price' => '总价', + 'create_time' => '操作时间', + ]; + } else { + $data = [ + 'id' => 'id', + 'admin_name' => '操作人员', + 'warehouse_name' => '仓库', + 'store_name' => '商品名称', + 'top_cate_name' => '分类', + 'store_info' => '规格', + 'unit_name' => '单位', + 'financial_pm_name' => '出入库', + 'code' => '出库单', + 'system_store_name' => '门店', + 'nums' => '数量', + 'purchase' => '供货价', + 'price' => '零售价', + 'total_price' => '供货总价', + 'create_time' => '操作时间', + ]; + } + + return $data; + } +} diff --git a/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php b/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php index 3ee63283c..88beae83c 100644 --- a/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php +++ b/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php @@ -63,7 +63,8 @@ class SystemStoreStorageLogic extends BaseLogic { Db::startTrans(); try { - $find=SystemStoreStorage::where(['id' => $params['id']])->find(); + $find= WarehouseProduct::where(['id' => $params['id']])->find(); + // $find=SystemStoreStorage::where(['id' => $params['id']])->find(); if($find){ // if($find['order_type']==1){ $find->save(['status'=>1,'staff_id'=>$params['staff_id']??0,'admin_id'=>$params['admin_id']??0,'mark'=>'入库时间:'.date('Y-m-d H:i:s',time())]); @@ -103,7 +104,8 @@ class SystemStoreStorageLogic extends BaseLogic $productIds = StoreProduct::where('store_name', 'like', '%' . $params['product_name'] . '%')->column('id'); $where[] = ['product_id', 'in', $productIds]; } - $list = SystemStoreStorage::where($where)->column('id'); + // $list = SystemStoreStorage::where($where)->column('id'); + $list = WarehouseProduct::where($where)->column('id'); foreach ($list as $item) { $params['id'] = $item; self::edit($params, $adminId); diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index 76ba8499e..3edd24a5a 100644 --- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -129,20 +129,20 @@ class WarehouseProductLogic extends BaseLogic if ($params['order_type'] != 6) { $storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find(); if ($storege) { - if (($params['store_id'] == 3 && in_array($params['order_type'], [1, 2, 3, 4, 8])) || in_array($params['order_type'], [1, 4])) { - SystemStoreStorage::create([ - 'store_id' => $params['store_id'], - 'admin_id' => $params['admin_id'], - 'order_type' => $params['order_type'], - 'staff_id' => 0, - 'type' => 1, - 'product_id' => $params['product_id'], - 'nums' => $params['nums'], - 'outbound_id' => $params['oid'] ?? 0, - 'warehouse_id' =>1, - 'status' => 0 - ]); - } + // if (($params['store_id'] == 3 && in_array($params['order_type'], [1, 2, 3, 4, 8])) || in_array($params['order_type'], [1, 4])) { + // SystemStoreStorage::create([ + // 'store_id' => $params['store_id'], + // 'admin_id' => $params['admin_id'], + // 'order_type' => $params['order_type'], + // 'staff_id' => 0, + // 'type' => 1, + // 'product_id' => $params['product_id'], + // 'nums' => $params['nums'], + // 'outbound_id' => $params['oid'] ?? 0, + // 'warehouse_id' =>1, + // 'status' => 0 + // ]); + // } $after_nums = bcsub($storege['nums'], $params['nums']); $total_price = bcmul($after_nums, $params['purchase'], 2); WarehouseProductStorege::update(['nums' => bcsub($storege['nums'], $params['nums']), 'total_price' => $total_price], ['id' => $storege['id']]); @@ -180,7 +180,7 @@ class WarehouseProductLogic extends BaseLogic 'admin_id' => $params['admin_id'], 'code' => $params['code'] ?? '', 'unit' => $params['unit'] ?? 0, - 'status' => 1, + 'status' => 0, 'mark' => $params['mark'] ?? '', 'order_type' => $params['order_type'] ?? '', ];