feat(BranchProductLists): 根据请求参数调整商品列表API,增加库存和销售字段,修复查询逻辑
This commit is contained in:
parent
21baf23272
commit
0b42d7553a
@ -7,6 +7,8 @@ use app\api\lists\BaseApiDataLists;
|
|||||||
use app\common\model\store_product\StoreProduct;
|
use app\common\model\store_product\StoreProduct;
|
||||||
use app\common\lists\ListsSearchInterface;
|
use app\common\lists\ListsSearchInterface;
|
||||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
|
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||||
|
use app\common\model\warehouse_product\WarehouseProduct;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品列表列表
|
* 商品列表列表
|
||||||
@ -61,23 +63,23 @@ class BranchProductLists extends BaseApiDataLists implements ListsSearchInterfac
|
|||||||
*/
|
*/
|
||||||
public function lists(): array
|
public function lists(): array
|
||||||
{
|
{
|
||||||
// $order = $this->request->get('order', '');
|
$store_id = $this->request->__get('store_id');
|
||||||
// $field = $this->request->get('field', '');
|
if (!$store_id) return [];
|
||||||
// if (empty($order) || empty($field)) {
|
|
||||||
// $order = $this->sortOrder;
|
$fields = 'id,top_cate_id,cate_id,product_id,store_name,cost,vip_price,purchase,price,bar_code,image,sales,store_info,unit,batch,two_cate_id,stock,total_price';
|
||||||
// } else {
|
|
||||||
// $order = [$field => $order];
|
|
||||||
// }
|
|
||||||
$fields = 'id,top_cate_id,cate_id,store_name,cost,vip_price,purchase,price,bar_code,image,sales,store_info,unit,batch,two_cate_id,stock,total_price';
|
|
||||||
|
|
||||||
$this->searchWhere[] = ['status', '=', 1];
|
$this->searchWhere[] = ['status', '=', 1];
|
||||||
|
$this->searchWhere[] = ['store_id', '=', $store_id];
|
||||||
$this->searchWhere[] = ['product_type', 'in', [0,4]];
|
$this->searchWhere[] = ['product_type', 'in', [0,4]];
|
||||||
return StoreBranchProduct::where($this->searchWhere)
|
return StoreBranchProduct::where($this->searchWhere)
|
||||||
->field($fields)
|
->field($fields)
|
||||||
->with(['className', 'unitName'])
|
->with(['className', 'unitName'])
|
||||||
->limit($this->limitOffset, $this->limitLength)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order($this->sortOrder)
|
->order($this->sortOrder)
|
||||||
->select()
|
->select()->each(function($item){
|
||||||
|
$item->distribution_nums=WarehouseProduct::where(['store_id'=>$item['store_id'],'product_id'=>$item['product_id'],'financial_pm'=>0])->sum('nums');
|
||||||
|
$item->sales=StoreOrderCartInfo::where(['product_id'=>$item['product_id'],'store_id'=>$item['store_id'],'is_pay'=>1])->sum('cart_num');
|
||||||
|
})
|
||||||
->toArray();
|
->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user