1,'t_choice.choice_type'=>$choice_type); $orderList = array( 1=>array('t_choice.operate_dt desc','创建时间从近到远',1), 2=>array('t_choice.operate_dt asc','创建时间从远到近',2), 3=>array('reply desc','评论数从高到低',3), 4=>array('reply asc','评论数从低到高',4), 5=>array('praise desc','点赞数从高到低',5), 6=>array('praise asc','点赞数从低到高',6), ); $statusList = array('全部状态',1=>'未上架',3=>'已上架'); $orderby = $orderList[$sort][0]; if (!empty($keyword)){ $condition['t_choice.choice_name'] = array('LIKE','%'.$keyword.'%'); } if (!empty($choiceStatus)){ $condition['t_choice.choice_status'] = $choiceStatus; } $this->assign('sort',$sort); $this->assign('orderby',$orderby); $this->assign('keyword',$keyword); $this->assign('orderList',$orderList); $this->assign('statusList',$statusList); $this->assign('choice_source',$choice_source); $this->assign('choiceStatus',$choiceStatus); $count = M('choice')->where($condition)->count(); //分页 $Page = new \Think\Page($count); $show = $Page->show(); $Model = M('choice'); $choiceList = $Model->join('left join t_user on t_user.user_id = t_choice.user_id')->join('left join (select choice_id,count(uc_id) as collect from t_user_choices group by choice_id) as a on a.choice_id = t_choice.choice_id')->join('left join (select choice_id,count(cr_id) as reply from t_choice_reply group by choice_id) as b on b.choice_id = t_choice.choice_id')->join('left join (select choice_id,count(cp_id) as praise from t_choice_praise group by choice_id) as c on c.choice_id = t_choice.choice_id')->where($condition)->order($orderby)->group('t_choice.choice_id')->limit($Page->firstRow.','.$Page->listRows)->field('t_choice.*,t_user.user_name,ifnull(a.collect,0) as collect,ifnull(b.reply,0) as reply,ifnull(c.praise,0) as praise')->select(); foreach($choiceList as $k=>$v){ $tmp=explode(',',$v['choice_img']); $choiceList[$k]['choice_img']=$tmp[0]; } $this->assign('page',$show); $this->assign('list',$choiceList); $this->display(); } //修改精选状态 public function status(){ $choiceId = I('choice_id',''); $choiceStatus = I('choice_status',''); if (empty($choiceId) || $choiceId<1000000){ $this->error("精选ID错误",'/admin/choice/index'); } M('choice')->where(array('choice_id'=>$choiceId))->save(array('choice_status'=>$choiceStatus)); $this->success('精选状态修改成功','/admin/choice/index'); } //修改精选类型 public function type(){ $choiceId = I('choice_id',''); $choiceType = I('choice_type',''); if (empty($choiceId) || $choiceId<1000000){ $this->error("精选ID错误",'/admin/choice/index'); } if($choiceType==2){ $info = M('choice')->where(array('choice_id'=>$choiceId))->find(); $choice_name=$info['choice_name']; $uid=$info['user_id']; $noticeContent = '被评为精选'; $temp=array('choice_id'=>$choiceId,'choice_name'=>$choice_name,'choice_type'=>2); M('Notice')->add(array('ref_user_id'=>$uid,'user_id'=>0,'notice_flag'=>0,'notice_status'=>1,'notice_type'=>0,'notice_title'=>'被评为精选','notice_content'=>$noticeContent,'operate_dt'=>time(),'extra'=>json_encode($temp))); M('User')->where(array('user_id'=>$uid))->setInc('sys_notice'); $data = array('type'=>0,'msg'=>$noticeContent,'data'=>array('title'=>$choice_name,'choice_id'=>$choiceId)); $url="http://www.hanlinyuanonline.com/api/choice/push?uid=".$uid."&data=".urlencode(base64_encode(json_encode($data))); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); } M('choice')->where(array('choice_id'=>$choiceId))->save(array('choice_type'=>$choiceType)); $this->success('精选状态修改成功','/admin/choice/index?choice_type='.$choiceType); } //删除精选 public function del(){ $choiceId = I('choice_id',''); if (empty($choiceId) || $choiceId<1000000){ $this->error("精选ID错误",'/admin/choice/index'); } M('choice')->where(array('choice_id'=>$choiceId))->delete(); $this->success('精选删除成功','/admin/choice/index'); } //编辑精选 public function edit(){ $step = I('step',''); $choiceId = I('choice_id',''); if (empty($step)){ $info = array(); if (!empty($choiceId)){ $info = M('choice')->where(array('choice_id'=>$choiceId))->find(); } $this->assign('info',$info); $this->display(); }else if($step==2){ $choiceName = I('choice_name',''); $choice_img = I('choice_img',''); $choice_content = I('choice_content',''); if (mb_strlen($choiceName,'UTF8')<2 || mb_strlen($choiceName,'UTF8')>30){ $this->error('精选名称2到30个汉字'); } if ( mb_strlen(html_entity_decode(strip_tags($choice_content)),'UTF8')>100020){ $this->error('精选内容限制10000个汉字'); } if ( !$choice_img){ $this->error('请上传精选封面'); } $res = M('choice')->where(array('choice_name'=>$choiceName,'is_delete'=>1))->field('choice_id')->find(); //新增 if (!$choiceId && $res){ $this->error('精选名称重复'); } //更新 if ($choiceId && $res && $choiceId!=$res['choice_id']){ $this->error('精选名称重复'); } if (empty($choiceId)){ M('choice')->add(array('choice_type'=>2,'choice_img'=>$choice_img,'choice_content'=>$choice_content,'choice_name'=>$choiceName,'operate_dt'=>time())); }else{ M('choice')->where(array('choice_id'=>$choiceId))->save(array('choice_img'=>$choice_img,'choice_content'=>$choice_content,'choice_name'=>$choiceName,'operate_dt'=>time())); } $this->success('精选操作成功','/admin/choice/index'); } } //获取精选的详情 public function detail(){ $choiceId = I('choice_id',''); if (empty($choiceId) || $choiceId<1000000){ $this->error("精选ID错误",'/admin/choice/index'); } $condition = array('is_delete'=>1,'choice_id'=>$choiceId); $Info = M('choice')->where(array('choice_id'=>$choiceId))->find(); $Info['choice_content']=htmlspecialchars_decode($Info['choice_content']); $tmp=explode(',',$Info['choice_img']); $Info['choice_img']=$tmp; $this->assign('info',$Info); $this->assign('choiceId', $choiceId); $this->display(); } }