order('sort desc,add_time desc')->select(); foreach ($list as &$item) { $item['number'] = RecommendRelation::where(['recommend_id' => $item['id']])->count(); } return $list; } public static function getRecommendList($where) { $model = self::where('is_fixed', $where['is_fixed']); if ($where['order']) { $model->order(self::setOrder($where['order'])); } else $model->order('sort desc,add_time desc'); $data = $model->page((int)$where['page'], (int)$where['limit'])->select(); foreach ($data as $item) { $item['type_name'] = self::getTypeNameAttr('', $item); $item['type_ting'] = self::getTypeseTingAttr('', $item); $item['number'] = 0; switch ($item['type']) { case 0: case 8: $item['number'] = RecommendRelation::where(['r.recommend_id' => $item['id']])->alias('r')->join('Special s', 's.id=r.link_id')->where(['s.is_del' => 0, 's.is_show' => 1, 's.status' => 1])->count(); break; case 4: $item['number'] = RecommendRelation::where(['r.recommend_id' => $item['id']])->alias('r')->join('StoreProduct p', 'p.id=r.link_id')->where(['p.is_del' => 0, 'p.is_show' => 1, 'p.status' => 1])->count(); break; case 1: $item['number'] = RecommendRelation::where(['recommend_id' => $item['id']])->alias('r')->join('Article a', 'a.id=r.link_id')->where(['a.hide' => 0, 'a.is_show' => 1])->count(); break; case 10: $item['number'] = RecommendRelation::where(['recommend_id' => $item['id']])->alias('r')->join('SpecialTask t', 't.id=r.link_id')->where(['t.is_del' => 0, 't.is_show' => 1])->count(); break; case 5: $item['number'] = Special::where(['type' => 4, 'is_show' => 1, 'is_del' => 0])->count(); break; case 6: $item['number'] = RecommendRelation::where(['recommend_id' => $item['id']])->alias('r')->join('Lecturer l', 'l.id=r.link_id')->where(['l.is_del' => 0, 'l.is_show' => 1])->count(); break; case 7: $item['number'] = 1; break; case 11: $item['number'] = RecommendRelation::where(['recommend_id' => $item['id']])->alias('r')->join('TestPaper t', 't.id=r.link_id')->where(['t.is_del' => 0, 't.is_show' => 1, 't.status' => 1])->count(); break; case 12: $item['number'] = RecommendRelation::where(['recommend_id' => $item['id']])->alias('r')->join('TestPaper t', 't.id=r.link_id')->where(['t.is_del' => 0, 't.is_show' => 1, 't.status' => 1])->count(); break; case 13: $ads = GroupDataService::getData('homepage_ads'); $item['number'] = count($ads); break; case 14: $item['number'] = RecommendRelation::where(['recommend_id' => $item['id']])->alias('r')->join('DataDownload d', 'd.id=r.link_id')->where(['d.is_del' => 0, 'd.is_show' => 1, 'd.status' => 1])->count(); break; } if ($item['type'] != 7) $item['number'] = $item['show_count'] < $item['number'] ? $item['show_count'] : $item['number']; $item['grade_title'] = $item['grade_id'] > 0 ? SpecialSubject::where(['id' => $item['grade_id'], 'is_del' => 0])->value('name') : '无'; } $count = self::where('is_fixed', $where['is_fixed'])->count(); return compact('data', 'count'); } }