diff --git a/app/api/lists/branch_product/BranchProductLists.php b/app/api/lists/branch_product/BranchProductLists.php index d74a6a815..d4853886e 100644 --- a/app/api/lists/branch_product/BranchProductLists.php +++ b/app/api/lists/branch_product/BranchProductLists.php @@ -7,6 +7,8 @@ use app\api\lists\BaseApiDataLists; use app\common\model\store_product\StoreProduct; use app\common\lists\ListsSearchInterface; 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 { - // $order = $this->request->get('order', ''); - // $field = $this->request->get('field', ''); - // if (empty($order) || empty($field)) { - // $order = $this->sortOrder; - // } 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'; + $store_id = $this->request->__get('store_id'); + if (!$store_id) return []; + + $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'; $this->searchWhere[] = ['status', '=', 1]; + $this->searchWhere[] = ['store_id', '=', $store_id]; $this->searchWhere[] = ['product_type', 'in', [0,4]]; return StoreBranchProduct::where($this->searchWhere) ->field($fields) ->with(['className', 'unitName']) ->limit($this->limitOffset, $this->limitLength) ->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(); }