| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535 |
- <?php
- /**
- * 短视频分类
- */
- namespace app\admin\controller;
- use cmf\controller\AdminBaseController;
- use think\facade\Db;
- use think\db\Query;
- class AuthorcenterController extends AdminbaseController {
- private function getClassList($k=''){
- $key='authorCenterClass';
- $class_list = getcaches($key);
- if(!$class_list){
- $class_list= Db::name("author_center_class")
- ->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('数据传入失败!');
- }
- }
-
- }
|