Exclusive.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\facade\Db;
  5. class Exclusive extends Base
  6. {
  7. public function __construct(App $app)
  8. {
  9. parent::__construct($app);
  10. }
  11. public function list(){
  12. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']) :"1";
  13. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  14. $where =[["is_del","=",0]];
  15. $cat_name=isset($this->post['name']) && $this->post['name'] !==""? trim($this->post['name']) :"";
  16. if($cat_name!==""){
  17. $where[]=['name',"like","%$cat_name%"];
  18. }
  19. $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
  20. if($pid!==""){
  21. $where[]=['pid',"=",$pid];
  22. }
  23. $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
  24. if($status!==""){
  25. $where[]=['status',"=",$status];
  26. }
  27. $count = Db::name("exclusive")->where($where)->count();
  28. $total = ceil($count / $size);
  29. $page = $page >= $total ? $total : $page;
  30. $list = Db::name('exclusive')->where($where)->page($page, $size)->select();
  31. return app_show(0, "获取成功", ['list' =>$list, 'count' => $count]);
  32. }
  33. public function add(){
  34. $name = isset($this->post['name'])&&$this->post['name']!=""? trim($this->post['name']):"";
  35. if($name==""){
  36. return error_show(1004,"参数name不能为空");
  37. }
  38. $pid =isset($this->post['pid'])&&$this->post['pid']!=="" ? intval($this->post['pid']):0;
  39. $level=1;
  40. $search = $name;
  41. if($pid!==0){
  42. $parent= Db::name("exclusive")->where(["id"=>$pid,"is_del"=>0])->find();
  43. if($parent==false){
  44. return error_show(1003,"父级数据未找到");
  45. }
  46. $search=$parent['search']."/".$name;
  47. $level=$parent['level']+1;
  48. }
  49. $token = isset($this->post['token'])&&$this->post['token']!="" ? trim($this->post['token']):"";
  50. $user =GetUserInfo($token);
  51. if(empty($user)||$user['code']!=0){
  52. return error_show($user['code'],$user['msg']);
  53. }
  54. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  55. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  56. $data=[
  57. "name"=>$name,
  58. "pid"=>$pid,
  59. "level"=>$level,
  60. "search"=>$search,
  61. "createrid"=>$createrid,
  62. "creater"=>$creater,
  63. "status"=>0,
  64. "is_del"=>0,
  65. "addtime"=>date("Y-m-d H:i:s"),
  66. "updatetime"=>date("Y-m-d H:i:s")
  67. ];
  68. $in =Db::name("exclusive")->insert($data);
  69. if($in){
  70. return app_show(0,"新建成功");
  71. }else{
  72. return error_show(1003,"新建失败");
  73. }
  74. }
  75. public function status(){
  76. $id=isset($this->post['id'])&&$this->post['id']!=="" ? intval($this->post['id']):"";
  77. if($id===""){
  78. return error_show(1004,"参数id不能为空");
  79. }
  80. $exclusive=Db::name("exclusive")->where(["id"=>$id,"is_del"=>0])->find();
  81. if($exclusive==false){
  82. return error_show(1004,"未找到数据");
  83. }
  84. $msg = $exclusive['status']==0? "启用":"禁用";
  85. $exclusive['status'] = $exclusive['status']==0?1:0;
  86. $exclusive['updatetime'] =date("Y-m-d H:i:s");
  87. $in =Db::name("exclusive")->save($exclusive);
  88. if($in){
  89. return app_show(0,"{$msg}成功");
  90. }else{
  91. return error_show(1004,"{$msg}失败");
  92. }
  93. }
  94. public function query(){
  95. // $where =[["is_del","=",0]];
  96. // $cat_name=isset($this->post['name']) && $this->post['name'] !==""? trim($this->post['name']) :"";
  97. // if($cat_name!==""){
  98. // $where[]=['name',"like","%$cat_name%"];
  99. // }
  100. // $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
  101. // if($pid!==""){
  102. // $where[]=['pid',"=",$pid];
  103. // }
  104. // $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
  105. // if($status!==""){
  106. // $where[]=['status',"=",$status];
  107. // }
  108. // $level=isset($this->post['level']) && $this->post['level'] !==""? intval($this->post['level']) :"";
  109. // if($level!==""){
  110. // $where[]=['level',"=",$level];
  111. // }
  112. // $list = Db::name("exclusive")->where($where)->select();
  113. // return app_show(0,"获取成功",$list);
  114. $where=[["is_del","=",0]];
  115. $pid = isset($this->post['pid']) &&$this->post['pid']!=="" ?intval($this->post['pid']): "0";
  116. $where[]=["pid","=",$pid];
  117. $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? intval($this->post['cat_name']) :"";
  118. if($cat_name!==""){
  119. $where[]=['cat_name',"like","%$cat_name%"];
  120. }
  121. $data = Db::name("exclusive")->where($where)->select();
  122. $vmp = [];
  123. foreach ($data as $sts){
  124. $vmp[]=coco($sts);
  125. }
  126. return app_show(0,"获取成功",$vmp);
  127. }
  128. // public function edit(){
  129. // $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  130. // if($id==""){
  131. // return error_show(1004,"参数id不能为空");
  132. // }
  133. // $info = Db::name('exclusive')->where(['id'=>$id,'is_del'=>0])->find();
  134. // if($info==""){
  135. // return error_show(1002,"未找到数据");
  136. // }
  137. // $name = isset($this->post['name'])&&$this->post['name']!=""? trim($this->post['name']):"";
  138. // if($name==""){
  139. // return error_show(1004,"参数name不能为空");
  140. // }
  141. // $pid =isset($this->post['pid'])&&$this->post['pid']!=="" ? intval($this->post['pid']):0;
  142. // $level=1;
  143. // $search = $name;
  144. // if($pid!==0){
  145. // $parent= Db::name("exclusive")->where(["id"=>$pid,"is_del"=>0])->find();
  146. // if($parent==false){
  147. // return error_show(1003,"父级数据未找到");
  148. // }
  149. // $search=$parent['search']."/".$name;
  150. // $level=$parent['level']+1;
  151. // }
  152. // $data=[
  153. // "id"=>$id,
  154. // "name"=>$name,
  155. // "pid"=>$pid,
  156. // "level"=>$level,
  157. // "search"=>$search,
  158. // "status"=>0,
  159. // "is_del"=>0,
  160. // "updatetime"=>date("Y-m-d H:i:s")
  161. // ];
  162. // $in =Db::name("exclusive")->save($data);
  163. // if($in){
  164. // return app_show(0,"编辑成功");
  165. // }else{
  166. // return error_show(1003,"编辑失败");
  167. // }
  168. // }
  169. public function delete(){
  170. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  171. $info = Db::name('exclusive')->where(["is_del"=>0,'id'=>$id])->find();
  172. if($info==false){
  173. return error_show(1002,"未找到数据");
  174. }
  175. $supp= Db::name('exclusive')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  176. if($supp){
  177. return error_show(0,"删除成功");
  178. }else{
  179. return error_show(1002,"删除失败");
  180. }
  181. }
  182. }