Exclusive.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. }
  115. }