123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- namespace app\admin\controller;
- use app\BaseController;
- use think\App;
- use think\facade\Db;
- class Model extends BaseController
- {
- public $post="";
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->post=$this->request->post();
- }
- public function list(){
- $where=[["is_del","=",0],["status","=",1]];
- $name = isset($this->post['name']) && $this->post['name'] !==""? trim($this->post['name']):"";
- if($name!==""){
- $where[]=["name","like","%$name%"];
- }
- $pid = isset($this->post['pid']) && $this->post['pid'] !==""?intval($this->post['pid']) :"";
- if($pid!==""){
- $where[]=["pid","=",$pid];
- }
- $level = isset($this->post['level']) && $this->post['level'] !==""? intval($this->post['level']):"";
- if($level!==""){
- $where[]=["level","=",$level];
- }
- $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"";
- if ($status!==""){
- $where[]=["status","=",$status];
- }
- $company_type = isset($this->post['company_type']) && $this->post['company_type'] !==""? intval($this->post['company_type']):"";
- if ($company_type!==""){
- $where[]=["company_type","=",$company_type];
- }
- $list = Db::name('model')->where($where)->order("weight desc")->select();
- $data=[];
- foreach ($list as $value){
- $temp = Db::name("model")->where(['pid'=>$value['id'],'is_del'=>0,"status"=>1])->order("weight desc")
- ->select();
- $value['child']=$temp;
- $data[]=$value;
- }
- return app_show(0,"获取成功",$data);
- }
- //public function create(){
- // $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']):"";
- // if($name==""){
- // return error_show(0,"参数name不能为空");
- // }
- // $level = isset($this->post['level']) && $this->post['level'] !== "" ? intval($this->post['level']) : "";
- // $rename = Db::name('model')->where(['name'=>$name,'level'=>$level,'is_del'=>0])->find();
- // if(!empty($rename)){
- // return error_show(1002,"模块名称已存在");
- // }
- // $pid = isset($this->post['pid']) && $this->post['pid'] !=="" ? trim($this->post['pid']) :"";
- // if($pid===""){
- // return error_show(1002,"父级id不能为空");
- // }
- // if($pid!=0){
- // $spid = Db::name('model')->where(['id'=>$pid, 'is_del'=>0])->find();
- // if(empty($spid)){
- // return error_show(1004,"父级不能为空");
- // }
- // }
- //
- // $level =1;
- // if ($pid !== 0) {
- // $levl=Db::name('model')->where(['id'=>$pid])->find();
- // if(empty($levl)){
- // return error_show(1002,"未找到父级数据");
- // }
- // $level =$levl['level']+1;
- // }
- // $status= isset($this->post['status']) && $this->post['status'] !==""?intval($this->post['status']):"1";
- // $data = [
- // "name"=>$name,
- // "pid"=>$pid,
- // "status"=>$status,
- // "level"=>$level,
- // "is_del"=>0,
- // "addtime"=>date("Y-m-d H:i:s"),
- // "updatetime"=>date("Y-m-d H:i:s")
- // ];
- // $datainfo = Db::name('model')->insert($data);
- // if($datainfo){
- // return error_show(0,"添加成功");
- // }else{
- // return error_show(1002,"添加失败");
- // }
- //}
- //public function edit(){
- // $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
- // if($id==""){
- // return error_show(1002,"参数id不能为空");
- // }
- // $info =Db::name('model')->where(['id'=>$id,'is_del'=>0])->find();
- // if(empty($info)){
- // return error_show(1004,"未找到数据");
- // }
- // $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']):"";
- // if($name==""){
- // return error_show(0,"参数name不能为空");
- // }
- // $level = isset($this->post['level']) && $this->post['level'] !== "" ? intval($this->post['level']) : "";
- // $rename = Db::name('model')->where(['name'=>$name,'level'=>$level,'is_del'=>0])->find();
- // if(!empty($rename)){
- // return error_show(1002,"模块名称已存在");
- // }
- // $pid = isset($this->post['pid']) && $this->post['pid'] !=="" ? trim($this->post['pid']) :"";
- // if($pid===""){
- // return error_show(1002,"父级id不能为空");
- // }
- // if($pid!=0){
- // $spid = Db::name('model')->where(['id'=>$pid, 'is_del'=>0])->find();
- // if(empty($spid)){
- // return error_show(1004,"父级不能为空");
- // }
- // }
- // $status= isset($this->post['status']) && $this->post['status'] !==""?intval($this->post['status']):"1";
- // $data = [
- // "name"=>$name,
- // "pid"=>$pid,
- // "status"=>$status,
- // "level"=>$level,
- // "is_del"=>0,
- // "addtime"=>date("Y-m-d H:i:s"),
- // "updatetime"=>date("Y-m-d H:i:s")
- // ];
- // $datainfo=Db::name('model')->where($info)->save($data);
- // if($datainfo){
- // return error_show(0,"更新成功");
- // }else{
- // return error_show(1002,"更新失败");
- // }
- //}
- //public function info(){
- // $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
- // if($id==""){
- // return error_show(1002,"参数id不能为空");
- // }
- // $idinfo = Db::name('model')->where(['id'=>$id,'is_del'=>0])->find();
- // return app_show(0,"获取成功",$idinfo);
- //}
- //public function del(){
- // $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
- // if($id==""){
- // return error_show(1002,"参数不能为空");
- // }
- // $info=Db::name('model')->where(['id'=>$id,'is_del'=>0])->find();
- // if(empty($info)){
- // return error_show(1002,"未找到数据");
- // }
- // $str['is_del']=1;
- // $str['updatetime']=date("Y-m-d H:i:s");
- // $info=Db::name('model')->where($info)->save($str);
- // return $info ? app_show(0,"删除成功") :error_show(1002,"删除失败");
- //}
- }
|