有个新需求,
一张表有两个相同的商品排序信息,不同的是 type值和sort不同,如果有type等于1那就连接type等于一的那条商品信息进行排序,如果没有等于0的那就连排序等于0的进行排序
下面是代码,亲测有效
$resultGoods = ProductSales::with('homeGood')
// ->leftJoin('goods as g','g.goodsId','=','productId')
->leftJoin('goods as g',function ($join){
$join->on('g.goodsId','=','productId')
->where('g.goodsStatus','=',1)
->where('g.isSale','=',1)
->where('g.dataFlag','=',1);
})
->join('good_recommend as gr',function($join){
$join->on('gr.goods_id','=','g.goodsId')
->where(['gr.status'=>0,'gr.type'=>DB::raw("(SELECT DISTINCT CONCAT(IF(EXISTS(SELECT * FROM tgs_good_recommend WHERE goods_id=productId AND TYPE=1 and status=0),1,0)) AS c FROM tgs_good_recommend)")]);
}, null,null,'left')
->where('product_sales.status',1)
->where('saleStartDatetime', '>', $saleStarTime)
->where('saleStartDatetime', '<=', $endTime)
->orderBy('saleEndDatetime', 'desc')
->orderBy('sort','desc')
->groupBy('productId')
->paginate($size, ['productId', 'currentSalesVolume', 'saleStartDatetime', 'saleEndDatetime', 'salesPeriodNumber','g.shopId','gr.sort'], 'page', $page);作者:浪里小黑龙
原文链接:https://www.cnblogs.com/gjclr/p/10250409.html
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
