Model.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. class Model extends BaseController
  7. {
  8. public $post="";
  9. public function __construct(App $app)
  10. {
  11. parent::__construct($app);
  12. $this->post=$this->request->post();
  13. }
  14. public function list(){
  15. $where=[["is_del","=",0],["status","=",1]];
  16. $name = isset($this->post['name']) && $this->post['name'] !==""? trim($this->post['name']):"";
  17. if($name!==""){
  18. $where[]=["name","like","%$name%"];
  19. }
  20. $pid = isset($this->post['pid']) && $this->post['pid'] !==""?intval($this->post['pid']) :"";
  21. if($pid!==""){
  22. $where[]=["pid","=",$pid];
  23. }
  24. $level = isset($this->post['level']) && $this->post['level'] !==""? intval($this->post['level']):"";
  25. if($level!==""){
  26. $where[]=["level","=",$level];
  27. }
  28. $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"";
  29. if ($status!==""){
  30. $where[]=["status","=",$status];
  31. }
  32. $company_type = isset($this->post['company_type']) && $this->post['company_type'] !==""? intval($this->post['company_type']):"";
  33. if ($company_type!==""){
  34. $where[]=["company_type","=",$company_type];
  35. }
  36. $list = Db::name('model')->where($where)->order("weight desc")->select();
  37. $data=[];
  38. foreach ($list as $value){
  39. $temp = Db::name("model")->where(['pid'=>$value['id'],'is_del'=>0,"status"=>1])->order("weight desc")
  40. ->select();
  41. $value['child']=$temp;
  42. $data[]=$value;
  43. }
  44. return app_show(0,"获取成功",$data);
  45. }
  46. //public function create(){
  47. // $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']):"";
  48. // if($name==""){
  49. // return error_show(0,"参数name不能为空");
  50. // }
  51. // $level = isset($this->post['level']) && $this->post['level'] !== "" ? intval($this->post['level']) : "";
  52. // $rename = Db::name('model')->where(['name'=>$name,'level'=>$level,'is_del'=>0])->find();
  53. // if(!empty($rename)){
  54. // return error_show(1002,"模块名称已存在");
  55. // }
  56. // $pid = isset($this->post['pid']) && $this->post['pid'] !=="" ? trim($this->post['pid']) :"";
  57. // if($pid===""){
  58. // return error_show(1002,"父级id不能为空");
  59. // }
  60. // if($pid!=0){
  61. // $spid = Db::name('model')->where(['id'=>$pid, 'is_del'=>0])->find();
  62. // if(empty($spid)){
  63. // return error_show(1004,"父级不能为空");
  64. // }
  65. // }
  66. //
  67. // $level =1;
  68. // if ($pid !== 0) {
  69. // $levl=Db::name('model')->where(['id'=>$pid])->find();
  70. // if(empty($levl)){
  71. // return error_show(1002,"未找到父级数据");
  72. // }
  73. // $level =$levl['level']+1;
  74. // }
  75. // $status= isset($this->post['status']) && $this->post['status'] !==""?intval($this->post['status']):"1";
  76. // $data = [
  77. // "name"=>$name,
  78. // "pid"=>$pid,
  79. // "status"=>$status,
  80. // "level"=>$level,
  81. // "is_del"=>0,
  82. // "addtime"=>date("Y-m-d H:i:s"),
  83. // "updatetime"=>date("Y-m-d H:i:s")
  84. // ];
  85. // $datainfo = Db::name('model')->insert($data);
  86. // if($datainfo){
  87. // return error_show(0,"添加成功");
  88. // }else{
  89. // return error_show(1002,"添加失败");
  90. // }
  91. //}
  92. //public function edit(){
  93. // $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  94. // if($id==""){
  95. // return error_show(1002,"参数id不能为空");
  96. // }
  97. // $info =Db::name('model')->where(['id'=>$id,'is_del'=>0])->find();
  98. // if(empty($info)){
  99. // return error_show(1004,"未找到数据");
  100. // }
  101. // $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']):"";
  102. // if($name==""){
  103. // return error_show(0,"参数name不能为空");
  104. // }
  105. // $level = isset($this->post['level']) && $this->post['level'] !== "" ? intval($this->post['level']) : "";
  106. // $rename = Db::name('model')->where(['name'=>$name,'level'=>$level,'is_del'=>0])->find();
  107. // if(!empty($rename)){
  108. // return error_show(1002,"模块名称已存在");
  109. // }
  110. // $pid = isset($this->post['pid']) && $this->post['pid'] !=="" ? trim($this->post['pid']) :"";
  111. // if($pid===""){
  112. // return error_show(1002,"父级id不能为空");
  113. // }
  114. // if($pid!=0){
  115. // $spid = Db::name('model')->where(['id'=>$pid, 'is_del'=>0])->find();
  116. // if(empty($spid)){
  117. // return error_show(1004,"父级不能为空");
  118. // }
  119. // }
  120. // $status= isset($this->post['status']) && $this->post['status'] !==""?intval($this->post['status']):"1";
  121. // $data = [
  122. // "name"=>$name,
  123. // "pid"=>$pid,
  124. // "status"=>$status,
  125. // "level"=>$level,
  126. // "is_del"=>0,
  127. // "addtime"=>date("Y-m-d H:i:s"),
  128. // "updatetime"=>date("Y-m-d H:i:s")
  129. // ];
  130. // $datainfo=Db::name('model')->where($info)->save($data);
  131. // if($datainfo){
  132. // return error_show(0,"更新成功");
  133. // }else{
  134. // return error_show(1002,"更新失败");
  135. // }
  136. //}
  137. //public function info(){
  138. // $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  139. // if($id==""){
  140. // return error_show(1002,"参数id不能为空");
  141. // }
  142. // $idinfo = Db::name('model')->where(['id'=>$id,'is_del'=>0])->find();
  143. // return app_show(0,"获取成功",$idinfo);
  144. //}
  145. //public function del(){
  146. // $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  147. // if($id==""){
  148. // return error_show(1002,"参数不能为空");
  149. // }
  150. // $info=Db::name('model')->where(['id'=>$id,'is_del'=>0])->find();
  151. // if(empty($info)){
  152. // return error_show(1002,"未找到数据");
  153. // }
  154. // $str['is_del']=1;
  155. // $str['updatetime']=date("Y-m-d H:i:s");
  156. // $info=Db::name('model')->where($info)->save($str);
  157. // return $info ? app_show(0,"删除成功") :error_show(1002,"删除失败");
  158. //}
  159. }