calc(product-source-link): 计算商品溯源列表中的总数和仓库数
- 移除了字段 'total_nums', 'nums', 'warehouse_total_nums', 'warehouse_nums' 的直接查询 - 使用 each 函数遍历查询结果,计算每个商品的总数量和仓库数量 - 通过 ProductSourceLinkInfo 模型
This commit is contained in:
parent
47de656777
commit
8c4128ccd4
@ -6,7 +6,8 @@ namespace app\admin\lists\product_source_link;
|
|||||||
use app\admin\lists\BaseAdminDataLists;
|
use app\admin\lists\BaseAdminDataLists;
|
||||||
use app\common\model\product_source_link\ProductSourceLink;
|
use app\common\model\product_source_link\ProductSourceLink;
|
||||||
use app\common\lists\ListsSearchInterface;
|
use app\common\lists\ListsSearchInterface;
|
||||||
|
use app\common\model\product_source_link_info\ProductSourceLinkInfo;
|
||||||
|
use app\common\model\warehouse_product\WarehouseProduct;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品溯源管理列表
|
* 商品溯源管理列表
|
||||||
@ -44,11 +45,14 @@ class ProductSourceLinkLists extends BaseAdminDataLists implements ListsSearchIn
|
|||||||
{
|
{
|
||||||
return ProductSourceLink::where($this->searchWhere)
|
return ProductSourceLink::where($this->searchWhere)
|
||||||
->with(['product','warehouse','purchase'])
|
->with(['product','warehouse','purchase'])
|
||||||
// ->join('')
|
->field(['id', 'purchase_uid', 'product_id','warehouse_id',])
|
||||||
->field(['id', 'purchase_uid', 'product_id', 'total_nums', 'nums', 'warehouse_id', 'warehouse_total_nums', 'warehouse_nums'])
|
|
||||||
->limit($this->limitOffset, $this->limitLength)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['id' => 'desc'])
|
->order(['id' => 'desc'])
|
||||||
->select()
|
->select()
|
||||||
|
->each(function ($item) {
|
||||||
|
$item->total_nums = ProductSourceLinkInfo::where('product_id', $item->product_id)->where('oid',$item->id)->where('types',1)->sum('nums');
|
||||||
|
$item->warehouse_nums = ProductSourceLinkInfo::where('product_id', $item->product_id)->where('oid',$item->id)->where('types',2)->sum('nums');
|
||||||
|
})
|
||||||
->toArray();
|
->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user