From b28e68966fbd299ec805216a03f75a36789b93a2 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 10 Dec 2024 14:33:27 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=BA=93=E5=AD=98):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E4=B8=89=E7=9A=84=E8=B4=9F=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 WorkbenchController 中增加对类型三的处理逻辑 - 新增 WarehouseProductStoregeTwoLists 类实现仓库商品存储列表查询 - 支持按仓库 ID 和商品 ID 搜索 - 可对库存数量进行排序 - 实现负库存列表导出功能 --- app/admin/controller/WorkbenchController.php | 4 + .../WarehouseProductStoregeTwoLists.php | 135 ++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 app/admin/lists/warehouse_product_storege/WarehouseProductStoregeTwoLists.php diff --git a/app/admin/controller/WorkbenchController.php b/app/admin/controller/WorkbenchController.php index d739c8436..444ab1160 100644 --- a/app/admin/controller/WorkbenchController.php +++ b/app/admin/controller/WorkbenchController.php @@ -17,6 +17,7 @@ namespace app\admin\controller; use app\admin\lists\statistics\StoreProductLists; use app\admin\lists\store_order_cart_info\StoreOrderCartInfoGroupLists; use app\admin\lists\store_order_cart_info\StoreOrderCartInfoGroupMonthLists; +use app\admin\lists\warehouse_product_storege\WarehouseProductStoregeTwoLists; use app\admin\logic\statistic\ProductStatisticLogic; use app\admin\logic\statistic\TradeStatisticLogic; use app\admin\logic\statistic\UserStatisticLogic; @@ -322,6 +323,9 @@ class WorkbenchController extends BaseAdminController public function negative_inventory() { $parmas = $this->request->get(); + if($parmas['type'] == 3){ + return $this->dataLists(new WarehouseProductStoregeTwoLists()); + } $data = WarehouseLogic::negativeInventory($parmas); return $this->data($data); } diff --git a/app/admin/lists/warehouse_product_storege/WarehouseProductStoregeTwoLists.php b/app/admin/lists/warehouse_product_storege/WarehouseProductStoregeTwoLists.php new file mode 100644 index 000000000..e14ea5daf --- /dev/null +++ b/app/admin/lists/warehouse_product_storege/WarehouseProductStoregeTwoLists.php @@ -0,0 +1,135 @@ + ['warehouse_id', 'product_id'], + ]; + } + /** + * @notes 设置支持排序字段 + * @return string[] + * @remark 格式: ['前端传过来的字段名' => '数据库中的字段名']; + */ + public function setSortFields(): array + { + return ['nums' => 'nums']; + } + /** + * @notes 设置默认排序 + * @return string[] + */ + public function setDefaultOrder(): array + { + return ['id' => 'desc', 'nums' => 'desc',]; + } + + /** + * @notes 获取仓库商品存储列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/08/01 10:22 + */ + public function lists(): array + { + if ($this->request->get('store_name')) { + $ids = StoreProduct::where('store_name', 'like', '%' . $this->request->get('store_name') . '%')->column('id'); + if ($ids) { + $this->searchWhere[] = ['product_id', 'in', $ids]; + } else { + return []; + } + } + $this->searchWhere[] = ['nums', '<=', 0]; + return WarehouseProductStorege::where($this->searchWhere) + ->field(['id', 'warehouse_id', 'product_id', 'nums', 'price', 'total_price', 'status']) + ->limit($this->limitOffset, $this->limitLength) + ->order($this->sortOrder) + ->select()->each(function ($item) { + $item->warehouse_name = Warehouse::where('id', $item->warehouse_id)->value('name'); + $find = StoreProduct::where('id', $item->product_id)->withTrashed()->find(); + $item->store_name = $find->store_name; + $item->image = $find->image; + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); + $item['stock'] = $item['nums']; + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取仓库商品存储数量 + * @return int + * @author admin + * @date 2024/08/01 10:22 + */ + public function count(): int + { + return WarehouseProductStorege::where($this->searchWhere)->count(); + + } + + /** + * @notes 导出文件名 + * @return string + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setFileName(): string + { + + return '仓库商品列表'; + } + + + /** + * @notes 导出字段 + * @return string[] + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setExcelFields(): array + { + + $data = [ + 'warehouse_name' => '仓库名称', + 'product_id' => '商品id', + 'store_name' => '商品名称', + 'unit_name' => '单位', + 'stock' => '数量', + ]; + + return $data; + } +}