|
@@ -16,6 +16,7 @@ use App\Models\RegimentActive;
|
|
|
use App\Models\PayCity;
|
|
|
use App\Models\Regiment;
|
|
|
use App\Models\WeiBan\Tags as WeiBanTags;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
/**
|
|
|
* 产品接口
|
|
@@ -45,25 +46,28 @@ class Product extends Api{
|
|
|
// 接收参数
|
|
|
$name = request('name','');
|
|
|
$classId = request('class_id',0);
|
|
|
+ $getTop = request('get_top',0);
|
|
|
$limit = request('limit',10);
|
|
|
$cityId = empty($custom['city_id']) ? 0 : $custom['city_id'];
|
|
|
// 显示
|
|
|
- $map = [['status','=','0'],['stock','>',0]];
|
|
|
+ $map = [['product.status','=','0'],['product.stock','>',0]];
|
|
|
// 分类ID
|
|
|
- if( $classId ) $map[] = ['class_id','=',$classId];
|
|
|
+ if( $classId ) $map[] = ['product.class_id','=',$classId];
|
|
|
// 分类ID
|
|
|
- if( $name ) $map[] = ['name','like','%'.$name.'%'];
|
|
|
+ if( $name ) $map[] = ['product.name','like','%'.$name.'%'];
|
|
|
// 是否有城市
|
|
|
$wherIn = empty($custom['city_id']) ? [1] : [1,$custom['city_id']];
|
|
|
// 获取分页信息
|
|
|
$Paginator = $Model->query()
|
|
|
->join('product_city','product_city.product_id','=','product.id')
|
|
|
+ ->join('orders_product','orders_product.product_id','=','product.id')
|
|
|
->where($map)
|
|
|
->whereIn('product_city.city_id',$wherIn)
|
|
|
- ->groupBy('product_id')
|
|
|
- ->orderBy('product.sort')
|
|
|
+ ->groupBy('product.id')
|
|
|
+ ->orderBy( $getTop ? 'top_total' : 'product.sort', $getTop ? 'desc':'asc')
|
|
|
->orderBy('product.id')
|
|
|
- ->paginate($limit,['product.id','product.sort','product.business_id','product.name','product.tag_scope','product.tag_exclude','product.thumb','product.spec','product.price','product.market_price','product.stock']);
|
|
|
+ ->select(['product.id','product.sort','product.business_id','product.name','product.tag_scope','product.tag_exclude','product.thumb','product.spec','product.price','product.market_price','product.stock',DB::raw("count('product.id') as top_total")])
|
|
|
+ ->paginate($limit);
|
|
|
// 获取数据
|
|
|
$data['total'] = $Paginator->total();
|
|
|
$data['current_page'] = $Paginator->currentPage();
|