复杂联合查询

TopRecomFine   0 252
才疏学浅
才疏学浅 12-03 00:14

 

img[/uploads/images/20181027/8913ed2a24b3956e0a313cc88e4c7eb6.jpg] [pre] public function search(){ $time = input('time', ''); $q = input('q', ''); $page = $this->request->param('page', 1, 'intval'); $o = $this->request->param('o', 'id'); $t = $this->request->param('t', ''); $where = []; if(!empty($t)) $where['p.'.$t] = 1; if(!empty($q)){ $where['p.title'] = ['like', '%'.$q.'%']; } if(!empty($time)){ $today_1 = strtotime(date('Y-m-d',time())); $today_0 = $today_1 - 24*60*60; $today_2 = $today_1 + 24*60*60; if($time == 'today') $where['p.create_time'] = ['between', $today_1.','.$today_2]; if($time == 'yesterday') $where['p.create_time'] = ['between', $today_0.','.$today_1]; } $count = Db::name('bbs_post')->alias('p')->where($where)->count(); $post_list =Db::name('bbs_post') ->alias('p') ->field('c.name as plate_name,c.en_name as plate_en_name,p.id,plate_id,user_id,title,content,is_top,is_sticky,is_recom,see_num,reply_num,tag,p.create_time,u.id as uid,u.avatar,u.username,u.wali_avatar') ->join('admin_user u', 'u.id = p.user_id','LEFT') ->join('bbs_plate c', 'c.id = p.plate_id', 'LEFT') ->where($where) ->order($this->getOrder('p.is_top DESC, p.'.$o.' DESC')) ->page($page.','.config('bbs_page_size')) ->select(); if($this->lang == 'en'){ foreach($post_list as &$v){ $v['plate_name'] = $v['plate_en_name']; } } $this->assign('post_list', $post_list); $this->assign('count', $count); $this->assign('page', $page); $this->assign('q', $q); $this->assign('t', $t); $this->assign('o', $o); $this->assign('time', $time); $this->assign('curr_week_hot_reply', getCurrWeekHotReply()); $recom_list = PostModel::recomList(); foreach($recom_list as &$v) { if ($this->lang == 'en') { $v['name'] = $v['en_name']; } } $this->assign('recom_list', $recom_list); return $this->fetch(); } [/pre]
Reply list
  • - -   No Data   - -