VideoUrl.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace app\Nutrition\controller;
  3. use app\common\model\DatumIntro;
  4. use library\Controller;
  5. use app\common\model\DatumCate;
  6. use function AlibabaCloud\Client\value;
  7. /**
  8. * 视频管理
  9. * Class VideoUrl
  10. * @package app\Nutrition\controller
  11. */
  12. class VideoUrl extends Controller
  13. {
  14. /**
  15. * 绑定数据表
  16. * @var string
  17. */
  18. protected $table = 'VideoUrl';
  19. /**
  20. * 列表
  21. * @auth true
  22. * @menu true
  23. * @throws \think\Exception
  24. * @throws \think\db\exception\DataNotFoundException
  25. * @throws \think\db\exception\ModelNotFoundException
  26. * @throws \think\exception\DbException
  27. * @throws \think\exception\PDOException
  28. */
  29. public function index()
  30. {
  31. $this->title = '视频列表';
  32. $this->video_id = input('video_id');
  33. $sel_where = [];
  34. $sel_where[] = ['is_deleted','=',0];
  35. $sel_where[] = ['video_id','=',$this->video_id];
  36. $query = $this->_query($this->table);
  37. $query->where($sel_where)->order('sort desc,id desc')->page(false);
  38. }
  39. /**
  40. * 数据列表处理
  41. * @auth true
  42. * @menu true
  43. * @param array $data
  44. * @throws \think\db\exception\DataNotFoundException
  45. * @throws \think\db\exception\ModelNotFoundException
  46. * @throws \think\exception\DbException
  47. */
  48. protected function _index_page_filter(&$data)
  49. {
  50. }
  51. /**
  52. * 添加
  53. * @auth true
  54. * @menu true
  55. * @throws \think\Exception
  56. * @throws \think\db\exception\DataNotFoundException
  57. * @throws \think\db\exception\ModelNotFoundException
  58. * @throws \think\exception\DbException
  59. * @throws \think\exception\PDOException
  60. */
  61. public function add()
  62. {
  63. $this->title = '添加视频';
  64. $this->_form($this->table, 'form');
  65. }
  66. /**
  67. * 编辑
  68. * @auth true
  69. * @menu true
  70. * @throws \think\Exception
  71. * @throws \think\db\exception\DataNotFoundException
  72. * @throws \think\db\exception\ModelNotFoundException
  73. * @throws \think\exception\DbException
  74. * @throws \think\exception\PDOException
  75. */
  76. public function edit()
  77. {
  78. $this->title = '编辑视频';
  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 del()
  92. {
  93. $video_id = \app\common\model\VideoUrl::where('id',input('id'))->value('video_id');
  94. DatumIntro::where('id',$video_id)->setDec('url_num');
  95. $this->_save($this->table, ['is_deleted' => 1]);
  96. }
  97. /**
  98. * 表单数据处理
  99. * @auth true
  100. * @menu true
  101. * @param array $data
  102. */
  103. protected function _form_filter(&$data)
  104. {
  105. if($this->request->isGet()){
  106. $this->video_id = input('video_id');
  107. $this->video_info = DatumIntro::where('id',$this->video_id)->find()->toArray();
  108. $this->cate_name = DatumCate::where('id',$this->video_info['video_cate'])->value('title');
  109. }
  110. if($this->request->isPost()){
  111. list($post) = [$this->request->post()];
  112. if(empty($post['url'])) $this->error('请上传文件');
  113. }
  114. }
  115. protected function _form_result($result)
  116. {
  117. $url_num = \app\common\model\VideoUrl::where(['video_id'=>$this->request->post('video_id'),'is_deleted'=>0])->count();
  118. DatumIntro::where('id',$this->request->post('video_id'))->update(['url_num'=>$url_num]);
  119. }
  120. }