123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <?php
- namespace app\Nutrition\controller;
- use app\common\model\DatumIntro;
- use app\common\model\NutritionCase;
- use app\common\model\VideoIntro;
- use app\common\model\VideoUrl;
- use hg\apidoc\annotation\explain\Url;
- use library\Controller;
- use library\tools\Data;
- use think\Db;
- use app\common\model\VideoCate as VCM;
- /**
- * 视频管理
- * Class VideoManage
- * @package app\Nutrition\controller
- */
- class VideoManage extends Controller
- {
- /**
- * 绑定数据表
- * @var string
- */
- protected $table = 'VideoIntro';
- protected $url_suffix = '?x-oss-process=video/snapshot,t_2000,m_fast';
- /**
- * 列表
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function index()
- {
- $this->title = '视频列表';
- $video_cate = VCM::field('id,title')->select()->toArray();
- $this->video_cate = array_column($video_cate,null,'id');
- $sel_where = [];
- $sel_where[] = ['is_deleted','=',0];
- $sel_where[] = ['type','=',1];
- if($title = $this->request->get('title')) $sel_where[] = ['title','like','%'.$title.'%'];
- if($label = $this->request->get('label')) $sel_where[] = ['label','like','%'.$label.'%'];
- if($user_id = $this->request->get('user_id')) $sel_where[] = ['user_id','=',$user_id];
- $query = $this->_query($this->table);
- $query->where($sel_where)->order('status desc ,is_top desc ,sort desc,id desc')->page();
- }
- /**
- * 数据列表处理
- * @auth true
- * @menu true
- * @param array $data
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- protected function _index_page_filter(&$data)
- {
- foreach ($data as &$v) {
- $v['url_id'] = VideoUrl::where(['video_id'=>$v['id']])->value('id');
- }
- }
- /**
- * 添加
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function add()
- {
- $this->title = '添加视频';
- $this->type = input('get.type',1);
- $this->_form($this->table, 'form');
- }
- /**
- * 编辑
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function edit()
- {
- $this->title = '编辑视频';
- $this->type = input('get.type',1);
- $this->_form($this->table, 'form') ;
- }
- /**
- * 禁用
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function forbidden()
- {
- $this->_save($this->table, ['status' => '0']);
- }
- /**
- * 启用
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function enable()
- {
- $this->_save($this->table, ['status' => 1]);
- }
- /**
- * 删除视频
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function del()
- {
- $this->_save($this->table, ['is_deleted' => 1]);
- }
- /**
- * 表单数据处理
- * @auth true
- * @menu true
- * @param array $data
- */
- protected function _form_filter(&$data)
- {
- if($this->request->isGet()){
- $all_cate = VCM::where(['is_deleted'=>0])->order('sort desc ,id desc')->select();
- $this->r = input('get.r',0);
- $this->cate_tree = make_tree($all_cate);
- if($this->request->action() == 'add') {
- $this->video_url = $this->request->get('type',1) == 1 ? '' :[];
- }else{
- if($this->request->get('type',1) == 1 ) {
- $this->video_url = VideoUrl::where(['video_id'=>$data['id']])->find()->toArray();
- }else{
- $this->video_url = VideoUrl::where(['video_id'=>$data['id']])->order('sort desc,id asc')->select()->toArray();
- }
- }
- // 文章列表
- $this->article_list = \app\common\model\ArticleIntro::with('itemList')
- ->where(['is_deleted'=>0])->order('id desc')
- ->select()->toArray();
- // 资料
- $this->datum_list = DatumIntro::with('urlArr')
- ->where(['is_deleted'=>0])->order('id desc')
- ->select()->toArray();
- }
- if($this->request->isPost()) {
- if($data['up_type'] == 1){
- $data['url'] = $data['up_url'];
- }else{
- $data['url'] = $data['path'];
- }
- if($data['type'] == 1){
- if( !$data['url']) $this->error('请上传视频');
- }else{
- $item_title = input('post.item_title');
- if(empty($item_title)) $this->error('请上传视频');
- }
- }
- }
- protected function _form_result($result){
- if($this->request->isPost() && in_array($this->request->action(),['add','edit'])) {
- if($this->request->post('type') == 1) {
- $url = input('post.up_type',1) == 1 ? input('post.up_url'):input('post.path');
- Data::save('VideoUrl',['video_id'=>$result,
- 'url'=> $url,
- 'cover'=>input('post.cover'),
- 'is_vip'=>input('post.is_vip'),
- 'title'=>input('post.title'),
- 'article_id'=>input('post.article_id'),
- 'article_item'=>input('post.article_item'),
- 'datum_id'=>input('post.datum_id'),
- 'datum_item'=>input('post.datum_item'),
- 'up_type'=>input('post.up_type'),
- 'ppt'=>input('post.ppt'),
- 'label'=>input('post.label'),
- 'user_id'=>input('post.user_id'),
- 'desc'=>input('post.desc'),
- 'read_num'=>input('post.read_num'),
- ],'video_id',['video_id'=>$result]);
- $up = [];
- $up['video_url'] = $url;
- $up['cover'] = input('post.cover');
- VideoIntro::where('id',$result)->update($up);
- }
- }
- }
- }
|