VideoManage.php 6.8 KB

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