VideoUrl.php 8.1 KB

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