|
@@ -0,0 +1,198 @@
|
|
|
+<?php
|
|
|
+namespace app\Nutrition\controller;
|
|
|
+use app\common\model\VideoIntro;
|
|
|
+use app\common\model\VideoUrl;
|
|
|
+use library\Controller;
|
|
|
+use library\tools\Data;
|
|
|
+use think\Db;
|
|
|
+use app\common\model\VideoCate as VCM;
|
|
|
+/**
|
|
|
+ * 资料管理
|
|
|
+ * Class VideoManage
|
|
|
+ * @package app\Nutrition\controller
|
|
|
+ */
|
|
|
+class UserDatum extends Controller
|
|
|
+{
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 绑定数据表
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $table = 'UserDatum';
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 列表
|
|
|
+ * @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[] = ['v.is_deleted','=',0];
|
|
|
+ if($title = $this->request->get('title')) $sel_where[] = ['v.title','like','%'.$title.'%'];
|
|
|
+ if($phone = $this->request->get('phone')) $sel_where[] = ['m.phone','like','%'.$phone.'%'];
|
|
|
+ $this->status = $this->request->get('status',-1);
|
|
|
+ if( $this->status >= 0 ) $sel_where[] = ['v.status','=', $this->status ];
|
|
|
+ $query = $this->_query($this->table)->field('v.*,m.phone,m.name user_name, m.headimg')->alias('v')
|
|
|
+ ->leftJoin('StoreMember m','m.id = v.user_id');
|
|
|
+ $query->where($sel_where)->order('v.status desc ,v.is_top desc ,v.sort desc,v.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)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑
|
|
|
+ * @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->_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() && in_array($this->request->action(),['add','edit'])){
|
|
|
+ $all_cate = VCM::where(['is_deleted'=>0])->order('sort desc ,id desc')->select();
|
|
|
+ $this->cate_tree = make_tree($all_cate);
|
|
|
+ }
|
|
|
+
|
|
|
+ if($this->request->isPost() && in_array($this->request->action(),['add','edit'])) {
|
|
|
+ $select_label = [];
|
|
|
+ if(isset($data['serve_label']) && !empty($data['serve_label'])){
|
|
|
+ foreach ($data['serve_label'] as $key=>$value){
|
|
|
+ if($value) $select_label[] = $key;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!empty($select_label)) $data['label'] = ','.implode(',',$select_label);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function _form_result($result){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 资料添加到系列
|
|
|
+ * @auth true
|
|
|
+ * @throws \think\Exception
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ * @throws \think\exception\PDOException
|
|
|
+ */
|
|
|
+ public function series()
|
|
|
+ {
|
|
|
+ if ($this->request->isGet()) {
|
|
|
+ $id = $this->request->get('id');
|
|
|
+ $has_series = VideoUrl::where('rel_id',$id)->column('video_id');
|
|
|
+ $user_video = \app\common\model\UserVideo::where(['id' => $id])->find()->toArray();
|
|
|
+ $series_list = VideoIntro::where(['is_deleted'=>0,'type'=>2])->where('id','not in',$has_series)->column('title','id');
|
|
|
+ $this->fetch('', ['vo' => $user_video,'series_list'=>$series_list]);
|
|
|
+ } else {
|
|
|
+ $id = input('post.id');
|
|
|
+ $series_id = input('post.series_id');
|
|
|
+ $sort = input('post.sort');
|
|
|
+ $is_vip = input('post.is_vip');
|
|
|
+ $user_video = \app\common\model\UserVideo::where(['id' => $id])->find()->toArray();
|
|
|
+ VideoUrl::create([
|
|
|
+ 'video_id'=>$series_id,
|
|
|
+ 'cover'=>$user_video['cover'],
|
|
|
+ 'url'=>$user_video['video_url'],
|
|
|
+ 'sort'=>$sort,
|
|
|
+ 'is_vip'=>$is_vip,
|
|
|
+ 'source'=>2,
|
|
|
+ 'rel_id'=>$id,
|
|
|
+ 'title'=>$user_video['title'],
|
|
|
+ ]);
|
|
|
+ $this->success('添加成功!');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|