Video.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\BaseController;
  4. //use app\common\model\Param as ParamModel;
  5. use app\common\model\Video as VideoModel;
  6. use think\facade\Session;
  7. use think\facade\Db;
  8. use think\facade\Request;
  9. class Video extends BaseController
  10. {
  11. public function videoList()
  12. {
  13. if($this->request->isAjax())
  14. {
  15. $limit = input('limit/d',20);
  16. $page = input('page/d',1);
  17. $keywords = trim(input('keywords/s'));
  18. $status = trim(input('status/d'));
  19. $workerid = trim(input('workerid/d'));
  20. $map = array();
  21. if(!empty($keywords))
  22. {
  23. $map[] =['a.title', 'like', '%'.$keywords.'%'];
  24. }
  25. if (!empty($workerid)){
  26. $map[] = ['a.workerid', '=', $workerid];
  27. }
  28. if (!empty($status)){
  29. $map[] = ['a.status', '=', $status];
  30. }
  31. $data = Db::name('video')
  32. ->alias('a')
  33. ->field('a.id,a.workerid,a.title video_title,a.imageurl,a.videourl,from_unixtime(a.createtime) createtime,a.status,b.title worker_title')
  34. ->join('worker b','b.id = a.workerid','LEFT')
  35. ->where($map)
  36. ->page($page)
  37. ->limit($limit)
  38. ->order('a.id desc')
  39. ->select()
  40. ->toArray();
  41. $count = Db::name('video')
  42. ->alias('a')
  43. ->join('worker b','b.id = a.workerid','LEFT')
  44. ->where($map)
  45. ->count();
  46. foreach($data as $k=>$v)
  47. {
  48. if($v['status'] == 1)
  49. {
  50. $data[$k]['status_text'] = '待审核';
  51. }elseif($v['status'] == 2){
  52. $data[$k]['status_text'] = '未通过';
  53. }elseif($v['status'] == 3){
  54. $data[$k]['status_text'] = '通过';
  55. }
  56. }
  57. //dd($data,$count);
  58. return array(
  59. 'code' => 0,
  60. 'msg' => "",
  61. 'count' => $count,
  62. 'data' => $data
  63. );
  64. }else{
  65. $worker_data = Db::name('worker')->field('id,title')->select()->toArray();
  66. return view('video/videoList',['worker_data'=>$worker_data]);
  67. }
  68. }
  69. public function videoform()
  70. {
  71. $id = input('id/d');
  72. if($this->request->isAjax())
  73. {
  74. // $old_imageurl = trim(input('old_imageurl'));
  75. // if(!$old_imageurl)
  76. // {
  77. // $data['imageurl'] = ;
  78. // }
  79. $imgstr = trim(input('imageurl'));
  80. $imgdata = substr($imgstr,strpos($imgstr,",") + 1);
  81. $decodedData = base64_decode($imgdata);
  82. $data['imageurl'] = "attachment/images/".date("Ymd")."/".md5(time()).".jpg";
  83. file_put_contents($data['imageurl'], $decodedData );
  84. $data['status'] = trim(input('status/d'));
  85. if(!empty($id))
  86. {
  87. $data['imageurl'] = request()->domain()."/".$data['imageurl'];
  88. $data['id'] = $id;
  89. $res = Db::name('video')->update($data);
  90. }
  91. if($res)
  92. {
  93. $rtn['code'] = 0;
  94. $rtn['message'] = '修改成功';
  95. }else{
  96. $rtn['code'] = 1;
  97. $rtn['message'] = '修改失败';
  98. }
  99. return $rtn;
  100. }else{
  101. $video_data = Db::name('video')
  102. ->alias('a')
  103. ->field('a.id,a.workerid,a.title video_title,a.imageurl,a.videourl,from_unixtime(a.createtime) createtime,a.status,b.title worker_title')
  104. ->join('worker b','a.workerid = b.id','LEFT')
  105. ->where('a.id',$id)
  106. ->find();
  107. return view('video/videoform',[
  108. 'video_data'=>$video_data
  109. ]);
  110. }
  111. }
  112. public function delVideo()
  113. {
  114. $idarr = input('idarr/a');
  115. $result = VideoModel::whereIn('id',$idarr)->delete();
  116. if ($result){
  117. exit(json_encode(array(
  118. 'code' => 0,
  119. 'msg' => ""
  120. )));
  121. }
  122. exit(json_encode(array(
  123. 'code' => 1,
  124. 'msg' => "删除失败,请稍后重试"
  125. )));
  126. }
  127. }