feat: 商品列表添加品牌字段
parent
d9806a96cb
commit
1caff8fc70
|
@ -5,6 +5,7 @@ namespace app\api\logic;
|
||||||
|
|
||||||
use app\common\model\distribution\Distribution;
|
use app\common\model\distribution\Distribution;
|
||||||
use app\common\model\distribution\DistributionLevel;
|
use app\common\model\distribution\DistributionLevel;
|
||||||
|
use app\common\model\goods\GoodsBrand;
|
||||||
use app\common\model\goods\GoodsCategory;
|
use app\common\model\goods\GoodsCategory;
|
||||||
use app\common\model\shop\ShopFollow;
|
use app\common\model\shop\ShopFollow;
|
||||||
use app\common\model\user\User;
|
use app\common\model\user\User;
|
||||||
|
@ -428,16 +429,27 @@ class GoodsLogic extends Logic
|
||||||
$order = array_merge($elt, $order);
|
$order = array_merge($elt, $order);
|
||||||
}
|
}
|
||||||
|
|
||||||
$field = 'id,image,name,min_price,market_price,sales_actual,first_cate_id, second_cate_id,third_cate_id,sort_weight,brand_id,shop_id,sales_virtual,(sales_actual + sales_virtual) as sales_total';
|
$field = 'id,image,name,min_price,market_price,sales_actual,first_cate_id, second_cate_id,third_cate_id,sort_weight,brand_id,shop_id,sales_virtual,(sales_actual + sales_virtual) as sales_total, "" as brand_name';
|
||||||
|
|
||||||
$list = Goods::field($field)
|
|
||||||
->where($where)
|
|
||||||
->order($order)
|
|
||||||
->page($get['page_no'], $get['page_size'])
|
|
||||||
->select();
|
|
||||||
|
|
||||||
$count = Goods::where($where)->count();
|
$count = Goods::where($where)->count();
|
||||||
|
|
||||||
|
$list = [];
|
||||||
|
if ($count > 0) {
|
||||||
|
$list = Goods::field($field)
|
||||||
|
->where($where)
|
||||||
|
->order($order)
|
||||||
|
->page($get['page_no'], $get['page_size'])
|
||||||
|
->select();
|
||||||
|
$brandIds = $list->column('brand_id');
|
||||||
|
$brandIds = array_filter(array_unique($brandIds));
|
||||||
|
if (!empty($brandIds)) {
|
||||||
|
$brandName = GoodsBrand::whereIn('id', $brandIds)->column('name', 'id');
|
||||||
|
$list->each(function ($item) use ($brandName){
|
||||||
|
$item->brand_name = $brandName[$item->brand_id] ?? '';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$list = $list ? $list->toArray() : [];
|
$list = $list ? $list->toArray() : [];
|
||||||
|
|
||||||
$more = is_more($count, $get['page_no'], $get['page_size']);
|
$more = is_more($count, $get['page_no'], $get['page_size']);
|
||||||
|
|
Loading…
Reference in New Issue