根据活动状态 = 1优先排序,根据创建时间倒序

            $lists = Db::name('need')->alias('n')
                ->field("n.id,n.name,n.detail,n.createtime,n.start_time,n.end_time,n.people_count,n.status,u.mobile,u.username,n.images,m.`status` AS join_status,SUM(IF(m.status =1,1,0)) AS join_count")
                ->join('user u', 'n.apply_user_id = u.id')
                ->join('need_member m', 'm.need_id = n.id AND m.user_id = ' . $userId, 'LEFT')
                ->where($where)
                ->where('n.status not in(0,4)')
                ->orderRaw('n.status = 1 DESC,n.createtime DESC')
                ->group('n.id')
                ->limit($offSet, $pageSize)
                ->select();
SELECT n.id,n.name,n.detail,n.createtime,n.start_time,n.end_time,n.people_count,u.mobile,u.username,n.status,n.images,SUM(IF(m.status =1,1,0)) AS join_count FROM `yzj_need` `n` INNER JOIN `yzj_user` `u` ON `n`.`apply_user_id`=`u`.`id` LEFT JOIN `yzj_need_member` `m` ON `m`.`need_id`=`n`.`id` WHERE  `from` IN (2,3)  AND (  n.status not in(0,4) ) GROUP BY `n`.`id` ORDER BY n.status = 1 DESC,n.createtime DESC LIMIT 0,100

发表评论

邮箱地址不会被公开。 必填项已用*标注