VideoManage.php 7.2 KB

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