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; + } +}