Merge pull request '新增仓库库存查询功能' (#279) from dev into main

Reviewed-on: #279
This commit is contained in:
mkm 2024-10-16 11:34:16 +08:00
commit 9cc2d00db2

View File

@ -61,11 +61,12 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
$this->searchWhere[] = ['cate_id', '=', $class_all];
}
}
$is_warehouse=$this->request->get('is_warehouse',0);
return StoreProduct::where($this->searchWhere)
->field(['id', 'image', 'store_info', 'store_name', 'top_cate_id', 'two_cate_id', 'swap', 'product_type', 'cate_id', 'batch', 'price', 'vip_price', 'sales', 'stock', 'is_show', 'unit', 'cost', 'rose', 'purchase', 'bar_code', 'manufacturer_information'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item) {
->select()->each(function ($item) use($is_warehouse) {
$item['bar_code_two'] = '';
if (in_array($item['unit'], [2, 21])) {
$item['bar_code_two'] = $item['bar_code'];
@ -99,10 +100,14 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
$item['product_type_name'] = '普通商品';
}
$item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name');
$nums = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums');
$stock = StoreBranchProduct::where('store_id', '<>', '4')->where('product_id', $item['id'])->sum('stock');
$item['stock'] = bcadd($nums, $stock);
$item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name');
if($is_warehouse==1){
$item['stock'] = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums');
}else{
$nums = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums');
$item['stock'] = bcadd($nums, $stock);
}
return $item;
})?->toArray();
}