UserDatum.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. namespace app\Nutrition\controller;
  3. use app\common\model\VideoIntro;
  4. use app\common\model\VideoUrl;
  5. use library\Controller;
  6. use library\tools\Data;
  7. use think\Db;
  8. use app\common\model\VideoCate as VCM;
  9. /**
  10. * 资料管理
  11. * Class VideoManage
  12. * @package app\Nutrition\controller
  13. */
  14. class UserDatum extends Controller
  15. {
  16. /**
  17. * 绑定数据表
  18. * @var string
  19. */
  20. protected $table = 'UserDatum';
  21. /**
  22. * 列表
  23. * @auth true
  24. * @menu true
  25. * @throws \think\Exception
  26. * @throws \think\db\exception\DataNotFoundException
  27. * @throws \think\db\exception\ModelNotFoundException
  28. * @throws \think\exception\DbException
  29. * @throws \think\exception\PDOException
  30. */
  31. public function index()
  32. {
  33. $this->title = '资料列表';
  34. $video_cate = VCM::field('id,title')->select()->toArray();
  35. $this->video_cate = array_column($video_cate,null,'id');
  36. $sel_where = [];
  37. $sel_where[] = ['v.is_deleted','=',0];
  38. if($title = $this->request->get('title')) $sel_where[] = ['v.title','like','%'.$title.'%'];
  39. if($phone = $this->request->get('phone')) $sel_where[] = ['m.phone','like','%'.$phone.'%'];
  40. $this->status = $this->request->get('status',-1);
  41. if( $this->status >= 0 ) $sel_where[] = ['v.status','=', $this->status ];
  42. $query = $this->_query($this->table)->field('v.*,m.phone,m.name user_name, m.headimg')->alias('v')
  43. ->leftJoin('StoreMember m','m.id = v.user_id');
  44. $query->where($sel_where)->order('v.status desc ,v.is_top desc ,v.sort desc,v.id desc')->page();
  45. }
  46. /**
  47. * 数据列表处理
  48. * @auth true
  49. * @menu true
  50. * @param array $data
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. * @throws \think\exception\DbException
  54. */
  55. protected function _index_page_filter(&$data)
  56. {
  57. }
  58. /**
  59. * 编辑
  60. * @auth true
  61. * @menu true
  62. * @throws \think\Exception
  63. * @throws \think\db\exception\DataNotFoundException
  64. * @throws \think\db\exception\ModelNotFoundException
  65. * @throws \think\exception\DbException
  66. * @throws \think\exception\PDOException
  67. */
  68. public function edit()
  69. {
  70. $this->title = '编辑资料';
  71. $this->_form($this->table, 'form');
  72. }
  73. /**
  74. * 禁用
  75. * @auth true
  76. * @menu true
  77. * @throws \think\Exception
  78. * @throws \think\db\exception\DataNotFoundException
  79. * @throws \think\db\exception\ModelNotFoundException
  80. * @throws \think\exception\DbException
  81. * @throws \think\exception\PDOException
  82. */
  83. public function forbidden()
  84. {
  85. $this->_save($this->table, ['status' => '0']);
  86. }
  87. /**
  88. * 启用
  89. * @auth true
  90. * @menu true
  91. * @throws \think\Exception
  92. * @throws \think\db\exception\DataNotFoundException
  93. * @throws \think\db\exception\ModelNotFoundException
  94. * @throws \think\exception\DbException
  95. * @throws \think\exception\PDOException
  96. */
  97. public function enable()
  98. {
  99. $this->_save($this->table, ['status' => 1]);
  100. }
  101. /**
  102. * 删除资料
  103. * @auth true
  104. * @menu true
  105. * @throws \think\Exception
  106. * @throws \think\db\exception\DataNotFoundException
  107. * @throws \think\db\exception\ModelNotFoundException
  108. * @throws \think\exception\DbException
  109. * @throws \think\exception\PDOException
  110. */
  111. public function del()
  112. {
  113. $this->_save($this->table, ['is_deleted' => 1]);
  114. }
  115. /**
  116. * 表单数据处理
  117. * @auth true
  118. * @menu true
  119. * @param array $data
  120. */
  121. protected function _form_filter(&$data)
  122. {
  123. if($this->request->isGet() && in_array($this->request->action(),['add','edit'])){
  124. $all_cate = VCM::where(['is_deleted'=>0])->order('sort desc ,id desc')->select();
  125. $this->cate_tree = make_tree($all_cate);
  126. }
  127. if($this->request->isPost() && in_array($this->request->action(),['add','edit'])) {
  128. $select_label = [];
  129. if(isset($data['serve_label']) && !empty($data['serve_label'])){
  130. foreach ($data['serve_label'] as $key=>$value){
  131. if($value) $select_label[] = $key;
  132. }
  133. }
  134. if(!empty($select_label)) $data['label'] = ','.implode(',',$select_label);
  135. }
  136. }
  137. protected function _form_result($result){
  138. }
  139. /**
  140. * 资料添加到系列
  141. * @auth true
  142. * @throws \think\Exception
  143. * @throws \think\db\exception\DataNotFoundException
  144. * @throws \think\db\exception\ModelNotFoundException
  145. * @throws \think\exception\DbException
  146. * @throws \think\exception\PDOException
  147. */
  148. public function series()
  149. {
  150. if ($this->request->isGet()) {
  151. $id = $this->request->get('id');
  152. $has_series = VideoUrl::where('rel_id',$id)->column('video_id');
  153. $user_video = \app\common\model\UserVideo::where(['id' => $id])->find()->toArray();
  154. $series_list = VideoIntro::where(['is_deleted'=>0,'type'=>2])->where('id','not in',$has_series)->column('title','id');
  155. $this->fetch('', ['vo' => $user_video,'series_list'=>$series_list]);
  156. } else {
  157. $id = input('post.id');
  158. $series_id = input('post.series_id');
  159. $sort = input('post.sort');
  160. $is_vip = input('post.is_vip');
  161. $user_video = \app\common\model\UserVideo::where(['id' => $id])->find()->toArray();
  162. VideoUrl::create([
  163. 'video_id'=>$series_id,
  164. 'cover'=>$user_video['cover'],
  165. 'url'=>$user_video['video_url'],
  166. 'sort'=>$sort,
  167. 'is_vip'=>$is_vip,
  168. 'source'=>2,
  169. 'rel_id'=>$id,
  170. 'title'=>$user_video['title'],
  171. ]);
  172. $this->success('添加成功!');
  173. }
  174. }
  175. }