|
@@ -0,0 +1,125 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+
|
|
|
+namespace app\admin\controller;
|
|
|
+
|
|
|
+
|
|
|
+use think\App;
|
|
|
+use think\facade\Db;
|
|
|
+
|
|
|
+class Exclusive extends Base
|
|
|
+{
|
|
|
+ public function __construct(App $app)
|
|
|
+ {
|
|
|
+ parent::__construct($app);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function list(){
|
|
|
+ $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']) :"1";
|
|
|
+ $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
|
|
|
+ $where =[["is_del","=",0]];
|
|
|
+ $cat_name=isset($this->post['name']) && $this->post['name'] !==""? trim($this->post['name']) :"";
|
|
|
+ if($cat_name!==""){
|
|
|
+ $where[]=['name',"like","%$cat_name%"];
|
|
|
+ }
|
|
|
+ $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
|
|
|
+ if($pid!==""){
|
|
|
+ $where[]=['pid',"=",$pid];
|
|
|
+ }
|
|
|
+ $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
|
|
|
+ if($status!==""){
|
|
|
+ $where[]=['status',"=",$status];
|
|
|
+ }
|
|
|
+ $count = Db::name("exclusive")->where($where)->count();
|
|
|
+ $total = ceil($count / $size);
|
|
|
+ $page = $page >= $total ? $total : $page;
|
|
|
+ $list = Db::name('exclusive')->where($where)->page($page, $size)->select();
|
|
|
+ return app_show(0, "获取成功", ['list' =>$list, 'count' => $count]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function add(){
|
|
|
+ $name = isset($this->post['name'])&&$this->post['name']!=""? trim($this->post['name']):"";
|
|
|
+ if($name==""){
|
|
|
+ return error_show(1004,"参数name不能为空");
|
|
|
+ }
|
|
|
+ $pid =isset($this->post['pid'])&&$this->post['pid']!=="" ? intval($this->post['pid']):0;
|
|
|
+ $level=1;
|
|
|
+ $search = $name;
|
|
|
+ if($pid!==0){
|
|
|
+ $parent= Db::name("exclusive")->where(["id"=>$pid,"is_del"=>0])->find();
|
|
|
+ if($parent==false){
|
|
|
+ return error_show(1003,"父级数据未找到");
|
|
|
+ }
|
|
|
+ $search=$parent['search']."/".$name;
|
|
|
+ $level=$parent['level']+1;
|
|
|
+ }
|
|
|
+ $token = isset($this->post['token'])&&$this->post['token']!="" ? trim($this->post['token']):"";
|
|
|
+ $user =GetUserInfo($token);
|
|
|
+ if(empty($user)||$user['code']!=0){
|
|
|
+ return error_show($user['code'],$user['msg']);
|
|
|
+ }
|
|
|
+ $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
|
|
|
+ $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
|
|
|
+
|
|
|
+ $data=[
|
|
|
+ "name"=>$name,
|
|
|
+ "pid"=>$pid,
|
|
|
+ "level"=>$level,
|
|
|
+ "search"=>$search,
|
|
|
+ "createrid"=>$createrid,
|
|
|
+ "creater"=>$creater,
|
|
|
+ "status"=>0,
|
|
|
+ "is_del"=>0,
|
|
|
+ "addtime"=>date("Y-m-d H:i:s"),
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+ $in =Db::name("exclusive")->insert($data);
|
|
|
+ if($in){
|
|
|
+ return app_show(0,"新建成功");
|
|
|
+ }else{
|
|
|
+ return error_show(1003,"新建失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function status(){
|
|
|
+ $id=isset($this->post['id'])&&$this->post['id']!=="" ? intval($this->post['id']):"";
|
|
|
+ if($id===""){
|
|
|
+ return error_show(1004,"参数id不能为空");
|
|
|
+ }
|
|
|
+ $exclusive=Db::name("exclusive")->where(["id"=>$id,"is_del"=>0])->find();
|
|
|
+ if($exclusive==false){
|
|
|
+ return error_show(1004,"未找到数据");
|
|
|
+ }
|
|
|
+ $msg = $exclusive['status']==0? "启用":"禁用";
|
|
|
+ $exclusive['status'] = $exclusive['status']==0?1:0;
|
|
|
+ $exclusive['updatetime'] =date("Y-m-d H:i:s");
|
|
|
+ $in =Db::name("exclusive")->save($exclusive);
|
|
|
+ if($in){
|
|
|
+ return app_show(0,"{$msg}成功");
|
|
|
+ }else{
|
|
|
+ return error_show(1004,"{$msg}失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function query(){
|
|
|
+ $where =[["is_del","=",0]];
|
|
|
+ $cat_name=isset($this->post['name']) && $this->post['name'] !==""? trim($this->post['name']) :"";
|
|
|
+ if($cat_name!==""){
|
|
|
+ $where[]=['name',"like","%$cat_name%"];
|
|
|
+ }
|
|
|
+ $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
|
|
|
+ if($pid!==""){
|
|
|
+ $where[]=['pid',"=",$pid];
|
|
|
+ }
|
|
|
+ $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
|
|
|
+ if($status!==""){
|
|
|
+ $where[]=['status',"=",$status];
|
|
|
+ }
|
|
|
+ $level=isset($this->post['level']) && $this->post['level'] !==""? intval($this->post['level']) :"";
|
|
|
+ if($level!==""){
|
|
|
+ $where[]=['level',"=",$level];
|
|
|
+ }
|
|
|
+ $list = Db::name("exclusive")->where($where)->select();
|
|
|
+ return app_show(0,"获取成功",$list);
|
|
|
+ }
|
|
|
+}
|