$query = Student::from('student as s')
->join('user as u','u.object_id','=','s.id')
//2020 年 2 月 28 日 08:12:41 新增添加下载证书次数
->leftjoin('check_result as cr','s.id','cr.student_id')
//->leftJoin('classroom_member as cm','cm.user_id','=','u.id')
//->leftJoin('classroom as c',function($join){
->join('classroom_member as cm','cm.user_id','=','u.id')
->join('classroom as c',function($join){
$join->on('c.id','=','cm.classroom_id')
->where('c.status','<>',2);
})
->when($year, function($query)use($year){
return $query->whereRaw('SUBSTRING(c.start_date,1,4) = '.$year);
})
->where('s.is_delete', 0)
->where('u.status',0)
->when(get_user_school_id(),function($query)
{
$query->where('c.school_id',get_user_school_id());
})
->where('u.type',0) //学生
->when($search, function($query)use($search){
return $query->where(function($q)use($search){
$q->where('s.name','like',$search.'%')
->orWhere('s.mobile','like',$search.'%');
});
})
->orderBy('c.id','desc');
$peixunrenci = $query->distinct('cm.id')->count('cm.id');
$list = $query->groupBy('s.id')
->select(
's.id as stuid','s.name','s.sex','s.nation','s.mobile','s.id_card','s.work',
's.title','s.address', 's.email','s.office_phone','s.create_time','s.nation',
's.post_code', 'u.id as uid','cr.download_count'
)
->addSelect(DB::raw('count(distinct(cm.id)) as count, max(c.start_date) as date'))
->paginate($pageSize);
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.