field('id,title,title_en') ->where("status=1") ->order('orderno asc') ->select(); setcaches($key,$class_list); } if($k==''){ return $class_list; } return isset($class_list[$k]) ? $class_list[$k]: ''; } /*视频分类列表*/ public function classlist(){ $video_model=Db::name("author_center_class"); $lists = $video_model ->where(function(Query $query){ $data = $this->request->param(); $keyword=isset($data['keyword']) ? $data['keyword']: ''; if(!empty($keyword)){ $query->where('title', 'like', "%$keyword%"); } }) ->order("orderno asc") ->paginate(20); //分页-->筛选条件参数 $data = $this->request->param(); $lists->appends($data); // 获取分页显示 $page = $lists->render(); $this->assign('lists', $lists); $this->assign("page", $page); return $this->fetch(); } //排序 public function listordersset() { $ids=$this->request->param('listorders'); foreach ($ids as $key => $r) { $data['orderno'] = $r; Db::name("author_center_class")->where(array('id' => $key))->update($data); } $status = true; if ($status) { $this->resetCache(); $this->success("排序更新成功!"); } else { $this->error("排序更新失败!"); } } public function resetCache(){ $key='authorCenterClass'; $rules= Db::name("author_center_class") ->field('id,title') ->where("status=1") ->order('orderno asc') ->select(); setcaches($key,$rules); return 1; } public function delclass(){ $id=$this->request->param('id',0,'intval'); if($id){ $result=Db::name("author_center_class")->where(["id"=>$id])->delete(); if($result){ $this->resetCache(); $this->success('删除成功'); }else{ $this->error('删除失败'); } }else{ $this->error('数据传入失败!'); } return $this->fetch(); } public function addclass(){ return $this->fetch(); } public function addclass_post(){ if($this->request->isPost()){ $data=$this->request->param(); $data['addtime']=time(); $title=$data['title']; if($title==""){ $this->error("请填写分类标题"); } //判断标题是否存在 $info=Db::name("author_center_class")->where("title='{$title}'")->find(); if($info){ $this->error("分类标题已经存在"); } $result=Db::name("author_center_class")->insert($data); if($result){ $this->resetCache(); $this->success('添加成功','admin/authorcenter/classlist'); }else{ $this->error('添加失败'); } } } public function editclass(){ $id=$this->request->param('id',0,'intval'); if($id){ $info=Db::name("author_center_class")->where("id={$id}")->find(); $this->assign('info', $info); }else{ $this->error('数据传入失败!'); } return $this->fetch(); } public function editclass_post(){ if($this->request->isPost()){ $data=$this->request->param(); $id=$data['id']; $title=trim($data['title']); if($title==""){ $this->error("请填写分类标题"); } $data['title']=$title; //判断名称是否存在 $info=Db::name("author_center_class")->where("id !={$id} and title='{$title}'")->find(); if($info){ $this->error("分类标题已经存在"); } $result=Db::name("author_center_class")->update($data); if($result!==false){ $this->resetCache(); $this->success('修改成功'); }else{ $this->error('修改失败'); } } } /** * 添加活动 * @return [type] [description] */ public function addactive(){ $class_list = $this->getClassList(); $this->assign('class_list',$class_list); return $this->fetch(); } /** * 添加活动保存 * @return [type] [description] */ public function addactive_post(){ if($this->request->isPost()) { $data=$this->request->param(); if($data['title']==''){ $this->error("请填写活动标题"); } if($data['thumb']==''){ $this->error("请上传活动封面"); } if($data['starttime']==''){ $this->error("请选择活动开始时间"); } if($data['endtime']==''){ $this->error("请选择活动结束时间"); } $starttime=strtotime($data['starttime']); $endtime=strtotime($data['endtime']); if($endtime < $starttime){ $this->error("活动结束时间必须晚于活动开始时间"); } $data['starttime']=$starttime; $data['endtime']=$endtime; if($data['draft_starttime']==''){ $this->error("请选择投稿开始时间"); } if($data['draft_endtime']==''){ $this->error("请选择投稿结束时间"); } $draft_starttime=strtotime($data['draft_starttime']); $draft_endtime=strtotime($data['draft_endtime']); if($draft_endtime<$draft_starttime){ $this->error("投稿结束时间必须晚于投稿开始时间"); } $data['draft_starttime']=$draft_starttime; $data['draft_endtime']=$draft_endtime; if($draft_starttime < $starttime){ $this->error("投稿开始时间必须晚于活动开始时间"); } if($draft_endtime > $endtime){ $this->error("投稿结束时间必须早于活动结束时间"); } if($data['playway']==''){ $this->error("请填写活动玩法"); } if(count($data['subject'])==1 && $data['subject'][0]==''){ $this->error("请填写关联话题"); } if($data['reward']==''){ $this->error("请填写活动奖励"); } $subject_arr = $data['subject']; $new_arr=[]; foreach ($subject_arr as $k => $v) { if($v !=''){ $new_arr[]=$v; } } $data['subject'] = json_encode($new_arr); $data['addtime']=time(); $res = Db::name("author_center_activity")->insert($data); if($res==false){ $this->error("活动添加失败"); } $this->success("活动添加成功"); } } /** * 活动列表 * @return array 活动列表 */ public function activelist(){ $data = $this->request->param(); $map=[]; $classid = isset($data['classid']) ? $data['classid']:''; if($classid){ $map[]=['classid','=',$classid]; } $status = isset($data['status']) ? $data['status']:''; if($status){ $map[]=['status','=',$status]; } $starttime=isset($data['starttime']) ? $data['starttime']: ''; $endtime=isset($data['endtime']) ? $data['endtime']: ''; if($starttime!=""){ $map[]=['starttime','>=',strtotime($starttime)]; } if($endtime!=""){ $map[]=['endtime','<=',strtotime($endtime)]; } $title = isset($data['title']) ? $data['title']:''; if($title){ $map[]=['title','like',"%".$title."%"]; } /*var_dump($map); die;*/ $lists = DB::name("author_center_activity") ->where($map) ->order('id desc') ->paginate(20); $lists->each(function($v,$k){ $class_info= Db::name("author_center_class") ->field('id,title') ->where(['id'=>$v['classid']]) ->find(); if(!empty($class_info)){ $v['class_name']=$class_info['title']; }else{ $v['class_name']=''; } $subject_arr = json_decode($v['subject'],true); $v['subject_str'] = '#'.implode('#',$subject_arr); if(!$v['status']){ $v['status_name']='不显示'; }else{ $v['status_name']='显示'; } return $v; }); $lists->appends($data); $page = $lists->render(); $this->assign('lists', $lists); $this->assign("page", $page); $class_list = $this->getClassList(); $this->assign('class_list',$class_list); return $this->fetch(); } /** * 修改活动 * @return [type] [description] */ public function editactive(){ $id = $this->request->param('id', 0, 'intval'); $data=Db::name('author_center_activity') ->where("id={$id}") ->find(); if(!$data){ $this->error("信息错误"); } $subject_arr = json_decode($data['subject'],true); $data['subject'] = $subject_arr[0]; unset($subject_arr[0]); $class_list = $this->getClassList(); $this->assign('class_list',$class_list); $this->assign('data', $data); $this->assign('subject_arr', $subject_arr); return $this->fetch(); } /** * 活动编辑提交 * @return [type] [description] */ public function editactive_post(){ if ($this->request->isPost()) { $data = $this->request->param(); if($data['title']==''){ $this->error("请填写活动标题"); } if($data['thumb']==''){ $this->error("请上传活动封面"); } if($data['starttime']==''){ $this->error("请选择活动开始时间"); } if($data['endtime']==''){ $this->error("请选择活动结束时间"); } $starttime=strtotime($data['starttime']); $endtime=strtotime($data['endtime']); if($endtime < $starttime){ $this->error("活动结束时间必须晚于活动开始时间"); } $data['starttime']=$starttime; $data['endtime']=$endtime; if($data['draft_starttime']==''){ $this->error("请选择投稿开始时间"); } if($data['draft_endtime']==''){ $this->error("请选择投稿结束时间"); } $draft_starttime=strtotime($data['draft_starttime']); $draft_endtime=strtotime($data['draft_endtime']); if($draft_endtime<$draft_starttime){ $this->error("投稿结束时间必须晚于投稿开始时间"); } $data['draft_starttime']=$draft_starttime; $data['draft_endtime']=$draft_endtime; if($draft_starttime < $starttime){ $this->error("投稿开始时间必须晚于活动开始时间"); } if($draft_endtime > $endtime){ $this->error("投稿结束时间必须早于活动结束时间"); } if($data['playway']==''){ $this->error("请填写活动玩法"); } if(count($data['subject'])==1 && $data['subject'][0]==''){ $this->error("请填写关联话题"); } if($data['reward']==''){ $this->error("请填写活动奖励"); } $subject_arr = $data['subject']; $new_arr=[]; foreach ($subject_arr as $k => $v) { if($v !=''){ $new_arr[]=$v; } } $data['subject'] = json_encode($new_arr); $data['uptime']=time(); $res = Db::name("author_center_activity")->update($data); if($res==false){ $this->error("活动修改失败"); } $this->success("活动修改成功"); } } /** * 删除活动 * @return [type] [description] */ public function delactive(){ $id = $this->request->param('id', 0, 'intval'); if($id){ $result=DB::name("author_center_activity")->delete($id); if($result){ Db::name("author_center_activity_collect")->where(['activeid'=>$id])->delete(); $this->success('删除成功'); }else{ $this->error('删除失败'); } }else{ $this->error('数据传入失败!'); } } }