DatumUrl.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. namespace app\Nutrition\controller;
  3. use app\common\model\DatumIntro;
  4. use app\common\model\PlatformSwitch;
  5. use app\common\model\SupplierGoods;
  6. use app\common\model\User;
  7. use library\Controller;
  8. use app\common\model\DatumCate;
  9. use function AlibabaCloud\Client\value;
  10. /**
  11. * 资料管理
  12. * Class OneDatum
  13. * @package app\Nutrition\controller
  14. */
  15. class DatumUrl extends Controller
  16. {
  17. /**
  18. * 绑定数据表
  19. * @var string
  20. */
  21. protected $table = 'DatumUrl';
  22. /**
  23. * 列表
  24. * @auth true
  25. * @menu true
  26. * @throws \think\Exception
  27. * @throws \think\db\exception\DataNotFoundException
  28. * @throws \think\db\exception\ModelNotFoundException
  29. * @throws \think\exception\DbException
  30. * @throws \think\exception\PDOException
  31. */
  32. public function index()
  33. {
  34. $this->title = '资料列表';
  35. $this->datum_id = input('datum_id');
  36. $sel_where = [];
  37. $sel_where[] = ['is_deleted','=',0];
  38. $sel_where[] = ['datum_id','=',$this->datum_id];
  39. $query = $this->_query($this->table);
  40. $query->where($sel_where)->order('sort desc,id asc')->page(false);
  41. }
  42. /**
  43. * 数据列表处理
  44. * @auth true
  45. * @menu true
  46. * @param array $data
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. * @throws \think\exception\DbException
  50. */
  51. protected function _index_page_filter(&$data)
  52. {
  53. }
  54. /**
  55. * 添加
  56. * @auth true
  57. * @menu true
  58. * @throws \think\Exception
  59. * @throws \think\db\exception\DataNotFoundException
  60. * @throws \think\db\exception\ModelNotFoundException
  61. * @throws \think\exception\DbException
  62. * @throws \think\exception\PDOException
  63. */
  64. public function add()
  65. {
  66. $this->title = '添加资料';
  67. $this->_form($this->table, 'form');
  68. }
  69. /**
  70. * 编辑
  71. * @auth true
  72. * @menu true
  73. * @throws \think\Exception
  74. * @throws \think\db\exception\DataNotFoundException
  75. * @throws \think\db\exception\ModelNotFoundException
  76. * @throws \think\exception\DbException
  77. * @throws \think\exception\PDOException
  78. */
  79. public function edit()
  80. {
  81. $this->title = '编辑资料';
  82. $this->_form($this->table, 'form') ;
  83. }
  84. /**
  85. * 删除资料
  86. * @auth true
  87. * @menu true
  88. * @throws \think\Exception
  89. * @throws \think\db\exception\DataNotFoundException
  90. * @throws \think\db\exception\ModelNotFoundException
  91. * @throws \think\exception\DbException
  92. * @throws \think\exception\PDOException
  93. */
  94. public function del()
  95. {
  96. $datum_id = \app\common\model\DatumUrl::where('id',input('id'))->value('datum_id');
  97. DatumIntro::where('id',$datum_id)->setDec('url_num');
  98. \app\common\model\DatumUrl::where('id',input('id'))->update(['is_deleted'=>1]);
  99. \app\common\model\DatumUrl::esAdd(input('id'));
  100. $this->success('删除成功!');
  101. }
  102. /**
  103. * 批量删除
  104. * @auth true
  105. * @menu true
  106. * @throws \think\Exception
  107. * @throws \think\db\exception\DataNotFoundException
  108. * @throws \think\db\exception\ModelNotFoundException
  109. * @throws \think\exception\DbException
  110. * @throws \think\exception\PDOException
  111. */
  112. public function remove()
  113. {
  114. $ids = input('id');
  115. foreach (explode(',',$ids) as $id) {
  116. $datum_id = \app\common\model\DatumUrl::where('id',$id)->value('datum_id');
  117. DatumIntro::where('id',$datum_id)->setDec('url_num');
  118. \app\common\model\DatumUrl::where('id',$id)->update(['is_deleted'=>1]);
  119. \app\common\model\DatumUrl::esAdd(input('id'));
  120. }
  121. $this->success('删除成功!');
  122. }
  123. /**
  124. * 表单数据处理
  125. * @auth true
  126. * @menu true
  127. * @param array $data
  128. */
  129. protected function _form_filter(&$data)
  130. {
  131. if($this->request->isGet()){
  132. $this->datum_id = input('datum_id');
  133. $this->datum_info = DatumIntro::where('id',$this->datum_id)->find()->toArray();
  134. $this->cate_name = DatumCate::where('id',$this->datum_info['datum_cate'])->value('title');
  135. // 视频
  136. $this->video_list = \app\common\model\VideoIntro::with('videoArr')
  137. ->where(['is_deleted'=>0])->order('id desc')
  138. ->select()->toArray();
  139. $this->supplier_goods = SupplierGoods::getSupplierGoodsList($this->request->action() == 'add' ? ['s.is_deleted'=>0]: []);
  140. }
  141. if($this->request->isPost()){
  142. list($post) = [$this->request->post()];
  143. if(empty($post['url'])) $this->error('请上传文件');
  144. if(!$post['is_encrypt'] && !strstr($post['url'],'https')) $this->error('请重新上传文件');
  145. if($post['is_encrypt'] && strstr($post['url'],'https')) $this->error('请重新上传文件');
  146. if(!$data['release_time']) $data['release_time'] = date("Y-m-d H:i:s");
  147. if(!empty($post['phone'])) {
  148. $user_id = User::where('phone|email',$post['phone'])->value('id');
  149. if(!$user_id) $this->error('账号未注册');
  150. $data['user_id'] = $user_id;
  151. }else{
  152. $data['user_id'] = '';
  153. }
  154. }
  155. }
  156. protected function _form_result($result)
  157. {
  158. $url_num = \app\common\model\DatumUrl::where(['datum_id'=>$this->request->post('datum_id'),'is_deleted'=>0])->count();
  159. DatumIntro::where('id',$this->request->post('datum_id'))->update(['url_num'=>$url_num]);
  160. \app\common\model\DatumUrl::esAdd($result);
  161. if($this->request->action() == 'add'){
  162. $datum_info = DatumIntro::where('id',$this->request->post('datum_id'))->find()->toArray();
  163. PlatformSwitch::followMsg(4,$this->request->post('datum_id'),$datum_info['title'],$this->request->post('title'),$result);
  164. }
  165. $this->success('保存成功');
  166. }
  167. /**
  168. * 禁用
  169. * @auth true
  170. * @menu true
  171. * @throws \think\Exception
  172. * @throws \think\db\exception\DataNotFoundException
  173. * @throws \think\db\exception\ModelNotFoundException
  174. * @throws \think\exception\DbException
  175. * @throws \think\exception\PDOException
  176. */
  177. public function forbidden()
  178. {
  179. \app\common\model\DatumUrl::where('id',input('id'))->update(['status'=>0]);
  180. \app\common\model\DatumUrl::esAdd(input('id'));
  181. $this->success('已禁用!');
  182. }
  183. /**
  184. * 启用
  185. * @auth true
  186. * @menu true
  187. * @throws \think\Exception
  188. * @throws \think\db\exception\DataNotFoundException
  189. * @throws \think\db\exception\ModelNotFoundException
  190. * @throws \think\exception\DbException
  191. * @throws \think\exception\PDOException
  192. */
  193. public function enable()
  194. {
  195. \app\common\model\DatumUrl::where('id',input('id'))->update(['status'=>1]);
  196. \app\common\model\DatumUrl::esAdd(input('id'));
  197. $this->success('已启用!');
  198. }
  199. }