123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- namespace app\admin\controller;
- use app\admin\BaseController;
- //use app\common\model\Param as ParamModel;
- use app\common\model\Video as VideoModel;
- use think\facade\Session;
- use think\facade\Db;
- use think\facade\Request;
- class Video extends BaseController
- {
- public function videoList()
- {
- if($this->request->isAjax())
- {
- $limit = input('limit/d',20);
- $page = input('page/d',1);
- $keywords = trim(input('keywords/s'));
- $status = trim(input('status/d'));
- $workerid = trim(input('workerid/d'));
- $map = array();
- if(!empty($keywords))
- {
- $map[] =['a.title', 'like', '%'.$keywords.'%'];
- }
- if (!empty($workerid)){
- $map[] = ['a.workerid', '=', $workerid];
- }
- if (!empty($status)){
- $map[] = ['a.status', '=', $status];
- }
- $data = Db::name('video')
- ->alias('a')
- ->field('a.id,a.workerid,a.title video_title,a.imageurl,a.videourl,from_unixtime(a.createtime) createtime,a.status,b.title worker_title')
- ->join('worker b','b.id = a.workerid','LEFT')
- ->where($map)
- ->page($page)
- ->limit($limit)
- ->order('a.id desc')
- ->select()
- ->toArray();
- $count = Db::name('video')
- ->alias('a')
- ->join('worker b','b.id = a.workerid','LEFT')
- ->where($map)
- ->count();
- foreach($data as $k=>$v)
- {
- if($v['status'] == 1)
- {
- $data[$k]['status_text'] = '待审核';
- }elseif($v['status'] == 2){
- $data[$k]['status_text'] = '未通过';
- }elseif($v['status'] == 3){
- $data[$k]['status_text'] = '通过';
- }
- }
- //dd($data,$count);
- return array(
- 'code' => 0,
- 'msg' => "",
- 'count' => $count,
- 'data' => $data
- );
- }else{
- $worker_data = Db::name('worker')->field('id,title')->select()->toArray();
- return view('video/videoList',['worker_data'=>$worker_data]);
- }
- }
- public function videoform()
- {
- $id = input('id/d');
- if($this->request->isAjax())
- {
- // $old_imageurl = trim(input('old_imageurl'));
- // if(!$old_imageurl)
- // {
- // $data['imageurl'] = ;
- // }
-
- $imgstr = trim(input('imageurl'));
-
- $imgdata = substr($imgstr,strpos($imgstr,",") + 1);
- $decodedData = base64_decode($imgdata);
- $data['imageurl'] = "attachment/images/".date("Ymd")."/".md5(time()).".jpg";
- file_put_contents($data['imageurl'], $decodedData );
-
- $data['status'] = trim(input('status/d'));
- if(!empty($id))
- {
- $data['imageurl'] = request()->domain()."/".$data['imageurl'];
- $data['id'] = $id;
- $res = Db::name('video')->update($data);
- }
- if($res)
- {
- $rtn['code'] = 0;
- $rtn['message'] = '修改成功';
- }else{
- $rtn['code'] = 1;
- $rtn['message'] = '修改失败';
- }
- return $rtn;
- }else{
- $video_data = Db::name('video')
- ->alias('a')
- ->field('a.id,a.workerid,a.title video_title,a.imageurl,a.videourl,from_unixtime(a.createtime) createtime,a.status,b.title worker_title')
- ->join('worker b','a.workerid = b.id','LEFT')
- ->where('a.id',$id)
- ->find();
- return view('video/videoform',[
- 'video_data'=>$video_data
- ]);
- }
- }
- public function delVideo()
- {
- $idarr = input('idarr/a');
- $result = VideoModel::whereIn('id',$idarr)->delete();
- if ($result){
- exit(json_encode(array(
- 'code' => 0,
- 'msg' => ""
- )));
- }
- exit(json_encode(array(
- 'code' => 1,
- 'msg' => "删除失败,请稍后重试"
- )));
- }
- }
|