| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 | 
							- <?php
 
- // +—————————————————————————————————————————————————————————————————————
 
- // | Created by Yunbao
 
- // +—————————————————————————————————————————————————————————————————————
 
- // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
 
- // +—————————————————————————————————————————————————————————————————————
 
- // | Author: https://gitee.com/yunbaokeji
 
- // +—————————————————————————————————————————————————————————————————————
 
- // | Date: 2022-02-17
 
- // +—————————————————————————————————————————————————————————————————————
 
- /**
 
-  * 直播分类
 
-  */
 
- namespace app\admin\controller;
 
- use cmf\controller\AdminBaseController;
 
- use think\Db;
 
- class LiveclassController extends AdminbaseController {
 
-     public function index(){
 
- 			
 
-     	$lists = Db::name("live_class")
 
-             //->where()
 
-             ->order("list_order asc, id desc")
 
-             ->paginate(20);
 
-             
 
-         
 
-         $page = $lists->render();
 
-     	$this->assign('lists', $lists);
 
-     	$this->assign("page", $page);
 
-     	
 
-     	return $this->fetch();
 
-     }
 
- 		
 
-     public function del(){
 
-         
 
-         $id = $this->request->param('id', 0, 'intval');
 
-         
 
-         $rs = DB::name('live_class')->where("id={$id}")->delete();
 
-         if(!$rs){
 
-             $this->error("删除失败!");
 
-         }
 
-         Db::name("live")->where(['liveclassid'=>$id])->update(['liveclassid'=>0]);
 
-         Db::name("live_record")->where(['liveclassid'=>$id])->update(['liveclassid'=>0]);
 
-         
 
-        
 
-                     
 
-         $this->resetcache();
 
-         $this->success("删除成功!");				
 
-     }		
 
-     //排序
 
-     public function listOrder() { 
 
- 		
 
-         $model = DB::name('live_class');
 
-         parent::listOrders($model);
 
-         
 
-        
 
-         
 
-         $this->resetcache();
 
-         $this->success("排序更新成功!");
 
-     }	
 
-     
 
-     public function add(){        
 
-         return $this->fetch();
 
-     }	
 
-     public function addPost(){
 
-         if ($this->request->isPost()) {
 
-             
 
-             $data = $this->request->param();
 
-             
 
- 			$name=$data['name'];
 
- 			if($name==""){
 
- 				$this->error("请填写名称");
 
- 			}
 
- 			$thumb=$data['thumb'];
 
- 			if($thumb==""){
 
- 				$this->error("请上传图标");
 
- 			}
 
-             $data['thumb']=set_upload_path($thumb);
 
-             $des=$data['des'];
 
-             if($des==''){
 
-                 $this->error("请填写直播分类描述");
 
-             }
 
-             if(mb_strlen($des)>200){
 
-                 $this->error("直播分类描述在200字以内");
 
-             }
 
-             
 
- 			$id = DB::name('live_class')->insertGetId($data);
 
-             if(!$id){
 
-                 $this->error("添加失败!");
 
-             }
 
-             
 
-             
 
-             
 
-             $this->resetcache();
 
-             $this->success("添加成功!");
 
-             
 
- 		}
 
-     }		
 
-     public function edit(){
 
-         
 
-         $id   = $this->request->param('id', 0, 'intval');
 
-         
 
-         $data=Db::name('live_class')
 
-             ->where("id={$id}")
 
-             ->find();
 
-         if(!$data){
 
-             $this->error("信息错误");
 
-         }
 
-         
 
-         $this->assign('data', $data);
 
-         return $this->fetch(); 			
 
-     }
 
-     
 
-     public function editPost(){
 
-         if ($this->request->isPost()) {
 
-             
 
-             $data      = $this->request->param();
 
-             
 
- 			$name=$data['name'];
 
- 			if($name==""){
 
- 				$this->error("请填写名称");
 
- 			}
 
- 			$thumb=$data['thumb'];
 
- 			if($thumb==""){
 
- 				$this->error("请上传图标");
 
- 			}
 
- 			$des=$data['des'];
 
-             if($des==''){
 
-                 $this->error("请填写直播分类描述");
 
-             }
 
-             if(mb_strlen($des)>200){
 
-                 $this->error("直播分类描述在200字以内");
 
-             }
 
-             $thumb_old=$data['thumb_old'];
 
-             if($thumb_old!=$thumb){
 
-                 $data['thumb']=set_upload_path($thumb);
 
-             }
 
-             unset($data['thumb_old']);
 
-             
 
- 			$id = DB::name('live_class')->update($data);
 
-             if($id===false){
 
-                 $this->error("修改失败!");
 
-             }
 
-             
 
-           
 
-             
 
-             $this->resetcache();
 
-             $this->success("修改成功!");
 
- 		}	
 
-     }
 
-     
 
-     public function resetcache(){
 
-         $key='getLiveClass';
 
-         $rules= DB::name('live_class')
 
-                 ->order('list_order asc,id desc')
 
-                 ->select();
 
-         if($rules){
 
-             setcaches($key,$rules);
 
-         }else{
 
- 			delcache($key);
 
- 		}
 
-         
 
-         return 1;
 
-     }
 
- }
 
 
  |