diff --git a/app/admin/lists/store_branch_product/StoreBranchProductLists.php b/app/admin/lists/store_branch_product/StoreBranchProductLists.php index 906db345..aafc9f06 100644 --- a/app/admin/lists/store_branch_product/StoreBranchProductLists.php +++ b/app/admin/lists/store_branch_product/StoreBranchProductLists.php @@ -5,6 +5,7 @@ namespace app\admin\lists\store_branch_product; use app\admin\lists\BaseAdminDataLists; use app\common\model\cate\Cate; +use app\common\model\inventory_transfer\InventoryTransfer; use app\common\model\store_category\StoreCategory; use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\system_store\SystemStore; @@ -13,6 +14,7 @@ use app\common\model\store_branch_product\StoreBranchProduct; use app\common\lists\ListsExcelInterface; use app\common\lists\ListsSortInterface; use app\common\model\store_product\StoreProduct; +use app\common\model\warehouse_product\WarehouseProduct; /** * 门店商品辅助表 @@ -86,7 +88,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI if (isset($this->params['low_stock']) && $this->params['low_stock'] == 1) { $query->where('stock', '<=', 'low_stock'); } - return $query + $list = $query ->field(['id', 'store_id', 'product_id', 'image', 'store_name', 'store_info', 'cate_id', 'price', 'sales', 'stock', 'low_stock', 'unit', 'cost', 'purchase', 'status', 'batch', 'vip_price','bar_code', 'manufacturer_information','total_price']) ->when(!empty($this->adminInfo['store_id']), function ($query) { $query->where('store_id', $this->adminInfo['store_id']); @@ -95,6 +97,10 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI ->order($this->sortOrder) ->select() ->each(function ($item) use($export) { + $item['transfer_num'] = 0; + $item['banquet_num'] = 0; + $item['out_num'] = InventoryTransfer::where('one_type', 1)->where('one_id', $item['store_id'])->where('product_id', $item['product_id'])->sum('nums'); + $item['in_num'] = InventoryTransfer::where('two_type', 1)->where('two_id', $item['store_id'])->where('product_id', $item['product_id'])->sum('nums'); $item['system_store_name'] = SystemStore::where('id', $item['store_id'])->value('name'); $item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name'); $item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name'); @@ -104,6 +110,24 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI return $item; }) ->toArray(); + $productIds = array_unique(array_column($list, 'product_id')); + $warehouseProductQuery = WarehouseProduct::whereIn('order_type', [1, 3])->whereIn('product_id', $productIds); + if (!empty($this->params['store_id'])) { + $warehouseProductQuery->where('store_id', $this->params['store_id']); + } + $warehouseProducts = $warehouseProductQuery->group('product_id,order_type')->field('product_id,order_type,sum(nums) num')->select()->toArray(); + foreach ($warehouseProducts as $warehouseProduct) { + foreach ($list as &$item) { + if ($item['product_id'] == $warehouseProduct['product_id']) { + if ($warehouseProduct['order_type'] == 1) { + $item['transfer_num'] = $warehouseProduct['num']; + } elseif ($warehouseProduct['order_type'] == 3) { + $item['banquet_num'] = $warehouseProduct['num']; + } + } + } + } + return $list; } @@ -159,6 +183,10 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI 'cate_name' => '分类', 'stock' => '库存', 'sales' => '销量', + 'transfer_num' => '铺货数量', + 'banquet_num' => '一条龙数量', + 'out_num' => '调拨出库数量', + 'in_num' => '调拨入库数量', 'purchase' => '供货价', 'cost' => '商户价', 'vip_price' => '会员价',