UserDatum.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace app\Nutrition\controller;
  3. use app\common\model\DatumIntro;
  4. use library\Controller;
  5. use library\tools\Data;
  6. /**
  7. * 资料管理
  8. * Class UserDatum
  9. * @package app\Nutrition\controller
  10. */
  11. class UserDatum extends Controller
  12. {
  13. /**
  14. * 绑定数据表
  15. * @var string
  16. */
  17. protected $table = 'UserDatum';
  18. /**
  19. * 列表
  20. * @auth true
  21. * @menu true
  22. * @throws \think\Exception
  23. * @throws \think\db\exception\DataNotFoundException
  24. * @throws \think\db\exception\ModelNotFoundException
  25. * @throws \think\exception\DbException
  26. * @throws \think\exception\PDOException
  27. */
  28. public function index()
  29. {
  30. $this->title = '资料列表';
  31. $datum_cate = \app\common\model\DatumCate::field('id,title')->select()->toArray();
  32. $this->datum_cate = array_column($datum_cate,null,'id');
  33. $sel_where = [];
  34. $sel_where[] = ['v.is_deleted','=',0];
  35. if($title = $this->request->get('title')) $sel_where[] = ['v.title','like','%'.$title.'%'];
  36. if($phone = $this->request->get('phone')) $sel_where[] = ['m.phone','like','%'.$phone.'%'];
  37. $this->status = $this->request->get('status',-1);
  38. if( $this->status >= 0 ) $sel_where[] = ['v.status','=', $this->status ];
  39. $query = $this->_query($this->table)->field('v.*,m.phone,m.name user_name, m.headimg')->alias('v')
  40. ->leftJoin('StoreMember m','m.id = v.user_id');
  41. $query->where($sel_where)->order('v.status desc ,v.is_top desc ,v.sort desc,v.id desc')->page();
  42. }
  43. /**
  44. * 数据列表处理
  45. * @auth true
  46. * @menu true
  47. * @param array $data
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. * @throws \think\exception\DbException
  51. */
  52. protected function _index_page_filter(&$data)
  53. {
  54. }
  55. /**
  56. * 编辑
  57. * @auth true
  58. * @menu true
  59. * @throws \think\Exception
  60. * @throws \think\db\exception\DataNotFoundException
  61. * @throws \think\db\exception\ModelNotFoundException
  62. * @throws \think\exception\DbException
  63. * @throws \think\exception\PDOException
  64. */
  65. public function edit()
  66. {
  67. $this->title = '编辑资料';
  68. $this->_form($this->table, 'form');
  69. }
  70. /**
  71. * 表单数据处理
  72. * @auth true
  73. * @menu true
  74. * @param array $data
  75. */
  76. protected function _form_filter(&$data)
  77. {
  78. }
  79. protected function _form_result($result){
  80. }
  81. /**
  82. * 资料添加到系列
  83. * @auth true
  84. * @throws \think\Exception
  85. * @throws \think\db\exception\DataNotFoundException
  86. * @throws \think\db\exception\ModelNotFoundException
  87. * @throws \think\exception\DbException
  88. * @throws \think\exception\PDOException
  89. */
  90. public function series()
  91. {
  92. if ($this->request->isGet()) {
  93. $id = $this->request->get('id');
  94. $has_series = \app\common\model\DatumUrl::where('rel_id',$id)->column('datum_id');
  95. $user_datum = \app\common\model\UserDatum::where(['id' => $id])->find()->toArray();
  96. $series_list = DatumIntro::where(['is_deleted'=>0,'type'=>2])->where('id','not in',$has_series)->column('title','id');
  97. $this->fetch('', ['vo' => $user_datum,'series_list'=>$series_list]);
  98. } else {
  99. $id = input('post.id');
  100. $series_id = input('post.series_id');
  101. $sort = input('post.sort');
  102. $is_vip = input('post.is_vip');
  103. $user_datum = \app\common\model\UserDatum::where(['id' => $id])->find()->toArray();
  104. \app\common\model\DatumUrl::create([
  105. 'datum_id'=>$series_id,
  106. 'url'=>$user_datum['datum_url'],
  107. 'sort'=>$sort,
  108. 'is_vip'=>$is_vip,
  109. 'source'=>2,
  110. 'rel_id'=>$id,
  111. 'title'=>$user_datum['title'],
  112. ]);
  113. DatumIntro::where('id',$series_id)->setInc('url_num');
  114. $this->success('添加成功!');
  115. }
  116. }
  117. public function new_datum()
  118. {
  119. if($this->request->isAjax())
  120. {
  121. $id = input('id');
  122. $user_datum = \app\common\model\UserDatum::where(['id' => $id])->find()->toArray();
  123. $new_datum = [
  124. 'title' => $user_datum['title'],
  125. 'desc' => $user_datum['desc'],
  126. 'datum_url' => $user_datum['datum_url'],
  127. 'label' => $user_datum['label'],
  128. 'is_over' => 1,
  129. 'is_vip' => 0,
  130. ];
  131. $result = DatumIntro::create($new_datum);
  132. $datum_url = [
  133. 'datum_id' => $result->id,
  134. 'url' => $new_datum['datum_url'],
  135. 'sort' => 0,
  136. 'is_deleted' => 0,
  137. 'is_vip' => $new_datum['is_vip'],
  138. 'source' => 1,
  139. 'title' => $new_datum['title'],
  140. 'rel_id' => $id,
  141. ];
  142. Data::save('DatumUrl',$datum_url,'datum_id',['datum_id' => $result->id]);
  143. $this->success('创建成功');
  144. }
  145. }
  146. }