VideoManage.php 7.7 KB

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