VideoManage.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php
  2. namespace app\Nutrition\controller;
  3. use app\common\model\DatumIntro;
  4. use app\common\model\NutritionCase;
  5. use app\common\model\User;
  6. use app\common\model\VideoIntro;
  7. use app\common\model\VideoUrl;
  8. use hg\apidoc\annotation\explain\Url;
  9. use library\Controller;
  10. use library\tools\Data;
  11. use think\Db;
  12. use app\common\model\VideoCate as VCM;
  13. /**
  14. * 视频管理
  15. * Class VideoManage
  16. * @package app\Nutrition\controller
  17. */
  18. class VideoManage extends Controller
  19. {
  20. /**
  21. * 绑定数据表
  22. * @var string
  23. */
  24. protected $table = 'VideoIntro';
  25. protected $url_suffix = '?x-oss-process=video/snapshot,t_2000,m_fast';
  26. /**
  27. * 列表
  28. * @auth true
  29. * @menu true
  30. * @throws \think\Exception
  31. * @throws \think\db\exception\DataNotFoundException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. * @throws \think\exception\DbException
  34. * @throws \think\exception\PDOException
  35. */
  36. public function index()
  37. {
  38. $this->title = '视频列表';
  39. $video_cate = VCM::field('id,title')->select()->toArray();
  40. $this->video_cate = array_column($video_cate,null,'id');
  41. $sel_where = [];
  42. $sel_where[] = ['is_deleted','=',0];
  43. $sel_where[] = ['type','=',1];
  44. if($title = $this->request->get('title')) $sel_where[] = ['title','like','%'.$title.'%'];
  45. if($label = $this->request->get('label')) $sel_where[] = ['label','like','%'.$label.'%'];
  46. $in_ids = '';
  47. if($phone = $this->request->get('phone')) $in_ids = VideoUrl::where('phone','like','%'.$phone.'%')->column('video_id');
  48. $query = $this->_query($this->table);
  49. $query->where($sel_where)
  50. ->when($in_ids,function ($query)use ($in_ids){
  51. if(!empty($in_ids)) $query->where('id','in',$in_ids);
  52. })->order('sort desc,id asc')->page();
  53. }
  54. /**
  55. * 数据列表处理
  56. * @auth true
  57. * @menu true
  58. * @param array $data
  59. * @throws \think\db\exception\DataNotFoundException
  60. * @throws \think\db\exception\ModelNotFoundException
  61. * @throws \think\exception\DbException
  62. */
  63. protected function _index_page_filter(&$data)
  64. {
  65. foreach ($data as &$v) {
  66. $v['url_id'] = VideoUrl::where(['video_id'=>$v['id']])->value('id');
  67. }
  68. }
  69. /**
  70. * 添加
  71. * @auth true
  72. * @menu true
  73. * @throws \think\Exception
  74. * @throws \think\db\exception\DataNotFoundException
  75. * @throws \think\db\exception\ModelNotFoundException
  76. * @throws \think\exception\DbException
  77. * @throws \think\exception\PDOException
  78. */
  79. public function add()
  80. {
  81. $this->title = '添加视频';
  82. $this->type = input('get.type',1);
  83. $this->_form($this->table, 'form');
  84. }
  85. /**
  86. * 编辑
  87. * @auth true
  88. * @menu true
  89. * @throws \think\Exception
  90. * @throws \think\db\exception\DataNotFoundException
  91. * @throws \think\db\exception\ModelNotFoundException
  92. * @throws \think\exception\DbException
  93. * @throws \think\exception\PDOException
  94. */
  95. public function edit()
  96. {
  97. $this->title = '编辑视频';
  98. $this->type = input('get.type',1);
  99. $this->_form($this->table, 'form') ;
  100. }
  101. /**
  102. * 禁用
  103. * @auth true
  104. * @menu true
  105. * @throws \think\Exception
  106. * @throws \think\db\exception\DataNotFoundException
  107. * @throws \think\db\exception\ModelNotFoundException
  108. * @throws \think\exception\DbException
  109. * @throws \think\exception\PDOException
  110. */
  111. public function forbidden()
  112. {
  113. $this->_save($this->table, ['status' => '0']);
  114. }
  115. /**
  116. * 启用
  117. * @auth true
  118. * @menu true
  119. * @throws \think\Exception
  120. * @throws \think\db\exception\DataNotFoundException
  121. * @throws \think\db\exception\ModelNotFoundException
  122. * @throws \think\exception\DbException
  123. * @throws \think\exception\PDOException
  124. */
  125. public function enable()
  126. {
  127. $this->_save($this->table, ['status' => 1]);
  128. }
  129. /**
  130. * 删除视频
  131. * @auth true
  132. * @menu true
  133. * @throws \think\Exception
  134. * @throws \think\db\exception\DataNotFoundException
  135. * @throws \think\db\exception\ModelNotFoundException
  136. * @throws \think\exception\DbException
  137. * @throws \think\exception\PDOException
  138. */
  139. public function del()
  140. {
  141. $this->_save($this->table, ['is_deleted' => 1]);
  142. }
  143. /**
  144. * 表单数据处理
  145. * @auth true
  146. * @menu true
  147. * @param array $data
  148. */
  149. protected function _form_filter(&$data)
  150. {
  151. if($this->request->isGet()){
  152. $data['up_type'] = 2;
  153. $all_cate = VCM::where(['is_deleted'=>0])->order('sort desc ,id desc')->select();
  154. $this->r = input('get.r',0);
  155. $this->cate_tree = make_tree($all_cate);
  156. if($this->request->action() == 'add') {
  157. $this->video_url = $this->request->get('type',1) == 1 ? '' :[];
  158. }else{
  159. if($this->request->get('type',1) == 1 ) {
  160. $this->video_url = VideoUrl::where(['video_id'=>$data['id']])->find()->toArray();
  161. }else{
  162. $this->video_url = VideoUrl::where(['video_id'=>$data['id']])->order('sort desc,id asc')->select()->toArray();
  163. }
  164. }
  165. $this->article_list =\app\common\model\ArticleIntro::with('itemChildren')
  166. ->field('id,title')
  167. ->where(['is_deleted'=>0])->order('id asc')
  168. ->select()->toArray();
  169. // 资料
  170. $this->datum_list = DatumIntro::with('urlArr')
  171. ->where(['is_deleted'=>0])->order('id asc')
  172. ->select()->toArray();
  173. }
  174. if($this->request->isPost()) {
  175. $data['up_type'] = 2;
  176. /*if($data['up_type'] == 1){
  177. $data['url'] = $data['up_url'];
  178. }else{
  179. $data['url'] = $data['path'];
  180. }*/
  181. if(empty($data['cover'])) $this->error('请上传视频封面');
  182. if(empty($data['ali_vid'])) $this->error('云点播ID不能为空');
  183. if(!empty($data['phone'])) {
  184. $user_id = User::where('phone|email',$data['phone'])->value('id');
  185. if(!$user_id) $this->error('该账号未注册');
  186. }
  187. }
  188. }
  189. protected function _form_result($result){
  190. if($this->request->isPost() && in_array($this->request->action(),['add','edit'])) {
  191. if($this->request->post('type') == 1) {
  192. $url = input('post.up_type',1) == 1 ? input('post.up_url'):input('post.path');
  193. if(!empty(input('post.phone'))) {
  194. $user_id = User::where('phone|email',input('post.phone'))->value('id');
  195. }else{
  196. $user_id= '';
  197. }
  198. $vid_info = getVideoTime(input('post.ali_vid'));
  199. Data::save('VideoUrl',['video_id'=>$result,
  200. 'url'=> $url,
  201. 'cover'=>input('post.cover'),
  202. 'is_vip'=>input('post.is_vip'),
  203. 'title'=>input('post.title'),
  204. 'article_id'=>input('post.article_id'),
  205. 'article_item'=>input('post.article_item'),
  206. 'datum_id'=>input('post.datum_id'),
  207. 'datum_item'=>input('post.datum_item'),
  208. 'up_type'=>input('post.up_type'),
  209. 'ppt'=>input('post.ppt'),
  210. 'label'=>input('post.label'),
  211. 'user_id'=>$user_id,
  212. 'phone'=>input('post.phone'),
  213. 'desc'=>input('post.desc'),
  214. 'read_num'=>input('post.read_num'),
  215. 'ali_vid'=>input('post.ali_vid'),
  216. 'duration'=>$vid_info['duration'],
  217. 'duration_str'=> $vid_info['duration_str'],
  218. ],'video_id',['video_id'=>$result]);
  219. $up = [];
  220. $up['video_url'] = $url;
  221. $up['cover'] = input('post.cover');
  222. VideoIntro::where('id',$result)->update($up);
  223. }
  224. }
  225. $this->success('操作成功', 'javascript:history.back()');
  226. }
  227. }