Ver Fonte

组织架构,去除account_plat

wufeng há 2 anos atrás
pai
commit
52f3140305

+ 284 - 0
app/controller/CompanyItem.php

@@ -0,0 +1,284 @@
+<?php
+
+namespace app\controller;
+
+use app\BaseController;
+use app\model\Account;
+use app\model\AccountCompany;
+use think\Exception;
+use think\facade\Db;
+use think\facade\Validate;
+
+//【组织架构】
+class CompanyItem extends BaseController
+{
+    //列表
+    public function getList()
+    {
+
+        $post = $this->request->only(['pid' => '', 'name' => '', 'nickname' => '', 'companyNo' => ''], 'post', 'trim');
+
+        $condition = [['is_del', '=', 0]];
+        $depart = [['a.is_del', '=', 0]];
+
+        if ($post['pid'] !== '') $condition[] = ["pid", "=", $post['pid']];
+        if ($post['name'] != "") $condition[] = ["name", "like", "%{$post['name']}%"];
+        if ($post['pid'] === '' && $post['name'] == '' && $post['nickname'] == '') $condition[] = ["pid", "=", 0];
+        if ($post['nickname'] != '') {
+            $is = Db::name("account")
+                ->alias('a')
+                ->leftJoin('account_company b', 'b.account_id=a.id')
+                ->leftJoin('user c', 'c.account_id=a.id')
+                ->where('a.is_del', 0)
+                ->whereLike('c.nickname', '%' . $post['nickname'] . '%')
+                ->column('b.itemid');
+            if (empty($is)) return json_show(1004, "未找到数据");
+            $condition[] = ["id", "in", $is];
+        }
+
+        $pidlist = Db::name("company_item")
+            ->where($condition)
+            ->column("pid");
+        if (!empty($pidlist)) $depart[] = [["b.itemid", "in", $pidlist]];
+        else {
+            if ($post['pid'] === "") $depart[] = ['b.itemid', '=', 0];
+            else $depart[] = ['b.itemid', '=', $post['pid']];
+        }
+
+        $item = Db::name("account")
+            ->alias('a')
+            ->field('a.id account_id,c.nickname,b.itemid,a.is_del,a.status,b.position')
+            ->leftJoin('account_company b', 'b.account_id=a.id')
+            ->leftJoin('user c', 'c.account_id=a.id')
+            ->where($depart)
+            ->select()
+            ->toArray();
+
+        $list = Db::name("company_item")
+            ->where($condition)
+            ->select()
+            ->toArray();
+
+        return json_show(0, '获取成功', ["depart" => $list, "item" => $item]);
+
+    }
+
+    //添加
+    public function add()
+    {
+        $param = $this->request->only([
+            'companyNo',
+            'name',
+            'pid',
+            'level' => 1,
+            'weight' => 1,
+        ], 'post', 'trim');
+
+        $val = Validate::rule([
+            'companyNo|所属企业' => 'require|max:255',
+            'name|部门名称' => 'require|max:255',
+            'pid|父级id' => 'require|number|gt:0',
+            'level|部门层级' => 'number|gt:0',
+            'weight|排序权重' => 'number|gt:0',
+        ]);
+
+        if ($val->check($param) == false) return json_show(1004, $val->getError());
+
+        Db::startTrans();
+
+        try {
+
+            $tmp = Db::name('company_item')
+                ->field('id')
+                ->where(["is_del" => 0, "name" => $param['name'], 'companyNo' => $param['companyNo']])
+                ->findOrEmpty();
+            if (!empty($tmp)) throw new Exception('部门名称已存在');
+
+            $spid = ['depart_link' => ''];
+            if ($param['pid'] != 0) {
+                $spid = Db::name('company_item')
+                    ->field('depart_link')
+                    ->where(['id' => $param['pid'], 'is_del' => 0])
+                    ->find();
+                if (empty($spid)) throw new Exception('父级数据不能为空');
+            }
+
+
+            $id = Db::name('company_item')
+                ->insertGetId([
+                    "name" => $param['name'],
+                    "pid" => $param['pid'],
+                    "level" => $param['level'],
+                    "weight" => $param['weight'],
+                    "is_del" => 0,
+                    'companyNo' => $param['companyNo'],
+                    "addtime" => date("Y-m-d H:i:s"),
+                    "updatetime" => date("Y-m-d H:i:s"),
+                ]);
+
+            $depart_link = $spid['depart_link'] . "{$id}-";
+            $level = explode('-', $depart_link);
+            $level = array_filter($level);
+            $level = count($level);
+
+            Db::name('company_item')
+                ->where('id', $id)
+                ->update([
+                    'depart_link' => $depart_link,
+                    'level' => $level
+                ]);
+
+            Db::commit();
+
+            return json_show(0, '添加成功');
+
+        } catch (Exception $e) {
+            Db::rollback();
+            return json_show(1002, '添加失败,' . $e->getMessage());
+        }
+    }
+
+    //编辑
+    public function update()
+    {
+
+        $param = $this->request->only(['id', 'companyNo', 'name', 'pid', 'level' => 1, 'weight' => 1,], 'post', 'trim');
+
+        $val = Validate::rule([
+            'id' => 'require|number|gt:0',
+            'companyNo|所属企业' => 'require|max:255',
+            'name|部门名称' => 'require|max:255',
+            'pid|父级id' => 'require|number|gt:0',
+            'level|部门层级' => 'number|gt:0',
+            'weight|排序权重' => 'number|gt:0',
+        ]);
+
+        if ($val->check($param) == false) return json_show(1004, $val->getError());
+
+        Db::startTrans();
+
+        try {
+
+            $tmp = Db::name("company_item")
+                ->field('id')
+                ->where(['id' => $param['id'], 'is_del' => 0])
+                ->findOrEmpty();
+
+            if (empty($tmp)) throw new Exception('部门信息不存在');
+
+            $tmp = Db::name('company_item')
+                ->field('id')
+                ->where(["is_del" => 0, "name" => $param['name'], 'companyNo' => $param['companyNo']])
+                ->where('id', '<>', $param['id'])
+                ->findOrEmpty();
+            if (!empty($tmp)) throw new Exception('部门名称已存在');
+
+            $spid = ['depart_link' => ''];
+            if ($param['pid'] != 0) {
+                $spid = Db::name('company_item')
+                    ->field('depart_link')
+                    ->where(['id' => $param['pid'], 'is_del' => 0])
+                    ->find();
+                if (empty($spid)) throw new Exception('父级数据不能为空');
+            }
+
+            Db::name('company_item')
+                ->where(['id' => $param['id'], 'is_del' => 0])
+                ->update([
+                    "name" => $param['name'],
+                    "pid" => $param['pid'],
+                    "level" => $param['level'],
+                    "weight" => $param['weight'],
+                    'companyNo' => $param['companyNo'],
+                    "updatetime" => date("Y-m-d H:i:s"),
+                ]);
+
+            $depart_link = $spid['depart_link'] . "{$param['id']}-";
+            $level = explode('-', $depart_link);
+            $level = array_filter($level);
+            $level = count($level);
+
+            Db::name('company_item')
+                ->where('id', $param['id'])
+                ->update([
+                    'depart_link' => $depart_link,
+                    'level' => $level
+                ]);
+
+            Db::commit();
+
+            return json_show(0, '信息更新成功');
+
+        } catch (Exception $e) {
+            Db::rollback();
+            return json_show(1002, '信息更新失败,' . $e->getMessage());
+        }
+
+
+    }
+
+    //查询
+    public function query()
+    {
+    }
+
+
+    //删除
+    public function delete()
+    {
+
+        $id = $this->request->filter('trim')->post('id/d', 0);
+
+        $rs = Db::name("company_item")
+            ->where(['id' => $id, 'is_del' => 0])
+            ->update(['is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]);
+
+        return $rs ? json_show(0, '删除成功') : json_show(1003, '删除失败');
+
+    }
+
+    //启禁用
+    public function status()
+    {
+        $id = $this->request->filter('trim')->post('id/d', 0);
+
+        $rs = Db::name("company_item")
+            ->field('id,status')
+            ->where(['id' => $id, 'is_del' => 0])
+            ->findOrEmpty();
+
+        if (empty($rs)) return json_show(1005, '未找到部门');
+
+        $status = $rs['status'] == 1 ? 0 : 1;
+
+        $rs = Db::name("company_item")
+            ->where(['id' => $id, 'is_del' => 0])
+            ->update(['status' => $status, 'updatetime' => date('Y-m-d H:i:s')]);
+
+        return $rs ? json_show(0, '更新成功') : json_show(1003, '更新失败');
+
+    }
+
+    //改变职位
+    public function userp()
+    {
+        $post = $this->request->only(['account_id', 'itemid', 'position'], 'post', 'trim');
+
+        $val = Validate::rule([
+            'account_id|账户id' => 'require|number|gt:0',
+            'itemid|部门id' => 'require|number|gt:0',
+            'position|职位' => 'require|number|in:1,2',
+        ]);
+
+        if ($val->check($post) == false) return json_show(1005, $val->getError());
+
+        $rs = Db::name('account_item')
+            ->where(['account_id' => $post['account_id'], 'itemid' => $post['itemid']])
+            ->update(['position' => $post['position'], 'updatetime' => date('Y-m-d H:i:s')]);
+
+        return $rs ? json_show(0, '修改成功') : json_show(1005, '修改失败');
+
+    }
+
+
+}

+ 37 - 29
app/controller/Headquarters.php

@@ -12,42 +12,37 @@ use think\facade\Validate;
 //【公司汇总】
 class Headquarters extends BaseController
 {
-
     //列表
     public function getList()
     {
-        try {
 
-            $post = $this->request->only(['code' => '', 'name' => '', 'status' => '', 'page' => 1, 'size' => 10, 'level' => '', 'account_id' => '', 'other'], 'post');
-            $condition = [['is_del', '=', 0]];
-
-            if ($post['code'] != '') $condition[] = ['code', 'like', "%{$post['code']}%"];
-            if ($post['name'] != '') $condition[] = ['name', 'like', "%{$post['name']}%"];
-            if ($post['status'] != '') $condition[] = ['status', '=', $post['status']];
-            if ($post['level'] != '') {
-                $companyCode = Db::name('account_company')
-                    ->where(['account_id' => $post['account_id'], 'is_del' => 0, 'status' => 1])
-                    ->column('companyCode');
-                $condition[] = ['code', 'in', $companyCode];
-            }
-            //兼容原有各个接口的筛选
-            $count = Db::name('headquarters')
-                ->where($condition)
-                ->count('id');
+        $post = $this->request->only(['code' => '', 'name' => '', 'status' => '', 'page' => 1, 'size' => 10, 'level' => '', 'account_id' => ''], 'post');
+        $condition = [['is_del', '=', 0]];
+
+        if ($post['code'] != '') $condition[] = is_array($post['code']) ? ['code', 'in', $post['code']] : ['code', 'like', "%{$post['code']}%"];
+        if ($post['name'] != '') $condition[] = ['name', 'like', "%{$post['name']}%"];
+        if ($post['status'] != '') $condition[] = ['status', '=', $post['status']];
+        if ($post['level'] != 1) {
+            $companyCode = Db::name('account_company')
+                ->where(['account_id' => $post['account_id'], 'is_del' => 0, 'status' => 1])
+                ->column('companyCode');
+            $condition[] = ['code', 'in', $companyCode];
+        }
+        //兼容原有各个接口的筛选
+        $count = Db::name('headquarters')
+            ->where($condition)
+            ->count('id');
 
-            $list = Db::name('headquarters')
-                ->field('id,code,name,type,status,addtime')
-                ->where($condition)
-                ->page($post['page'], $post['size'])
-                ->order(['addtime' => 'desc', 'id' => 'desc'])
-                ->select()
-                ->toArray();
+        $list = Db::name('headquarters')
+            ->field('id,code,name,type,status,addtime')
+            ->where($condition)
+            ->page($post['page'], $post['size'])
+            ->order(['addtime' => 'desc', 'id' => 'desc'])
+            ->select()
+            ->toArray();
 
-            return json_show(0, '获取成功', ['list' => $list, 'count' => $count]);
+        return json_show(0, '获取成功', ['list' => $list, 'count' => $count]);
 
-        } catch (Exception $exception) {
-            return json_show(1005, $exception->getMessage());
-        }
     }
 
     //添加
@@ -338,6 +333,19 @@ class Headquarters extends BaseController
 
     }
 
+    //获取指定编码和名称
+    public function getCodeAndName()
+    {
+        $companyNo = $this->request->filter('trim')->post('code');
+
+        $res = Db::name('headquarters')
+            ->where('is_del', 0)
+            ->whereIn('code', $companyNo)
+            ->column('name', 'code');
+
+        return json_show(0, '请求成功', $res);
+    }
+
 
     //业务企业
     public function bGetList()

+ 52 - 52
app/controller/User.php

@@ -140,52 +140,53 @@ class User extends BaseController
 	 */
     public function login()
     {
-        $post = $this->request->only(["username"=>"","password"=>"","plat_code"=>""],"post","trim");
-         $validate=Validate::rule([
-    		'username|账户名称' => 'require|max:255',
-    		'password|密码' => 'require|min:6|max:200',
-            ]);
-    	if($validate->check($post)==false) return json_show(1004,$validate->getError());
+        $post = $this->request->only(["username" => "", "password" => "", "plat_code" => ""], "post", "trim");
+        $validate = Validate::rule([
+            'username|账户名称' => 'require|max:255',
+            'password|密码' => 'require|min:6|max:200',
+        ]);
+        if ($validate->check($post) == false) return json_show(1004, $validate->getError());
+
+        $acc = Db::name("account")
+            ->where(['username' => $post['username'], "is_del" => Account::$account_del])
+            ->find();
+        if ($acc == false) return json_show(1003, '账户名不存在');
+
+        if ($acc['status'] == Account::$account_end) return json_show(1003, '账户已禁用');
+
+        $sha1 = sha1($post['password'] . $acc['salt']);
+        if ($sha1 != $acc['password']) return json_show(1003, '账户或密码错误');
 
-        $acc= Db::name("account")->where(['username'=>$post['username'],"is_del"=>Account::$account_del])->find();
-        if($acc==false){
-            return json_show(1003,'账户名不存在');
-        }
-        if($acc['status']==Account::$account_end){
-            return json_show(1003,'账户已禁用');
-        }
-        $sha1=sha1($post['password'].$acc['salt']);
-        if($sha1!=$acc['password']){
-            return json_show(1003,'账户或密码错误');
-        }
         $token = makeToken($acc);
-        if($token==""){
-            return json_show(1003,'token生成失败');
-        }
-        if($post['plat_code']!=""){
-        	$platinfo = Db::name("account_plat")->alias("a")
-        	->leftJoin("platform b","a.plat_code=b.plat_code and b.is_del=0 and b.status=1")
-        	->where(["a.status"=>1,"a.is_del"=>0,"a.plat_code"=>$post['plat_code'],"a.account_id"=>$acc['id']])
-        	->findOrEmpty();
-        	if(empty($platinfo)){
-        		 return json_show(1003,'该系统账号未开通登录');
-        	}
-        }
-		$user =Db::name("account")->alias("a")
-		->leftJoin("user b","a.id=b.account_id and b.status=1")
-		->field("a.id,a.username,a.mobile,a.source,b.nickname,b.sex,b.email,a.addtime,a.updatetime")
-		->where(["a.id"=>$acc["id"]])
-		->find();
-        if($user==false){
-        	 return json_show(1003,'用户信息不存在');
-        }
-		$usercompany = Db::name("account_company")->where(["account_id"=>$user['id'],"is_del"=>0,"status"=>1])
-		->column("companyCode,companyName,company_type,is_main,status");
+        if ($token == "") return json_show(1003, 'token生成失败');
+
+        //account_plat 是空表
+//        if ($post['plat_code'] != "") {
+//            $platinfo = Db::name("account_plat")
+//                ->alias("a")
+//                ->leftJoin("platform b", "a.plat_code=b.plat_code and b.is_del=0 and b.status=1")
+//                ->where(["a.status" => 1, "a.is_del" => 0, "a.plat_code" => $post['plat_code'], "a.account_id" => $acc['id']])
+//                ->findOrEmpty();
+//            if (empty($platinfo)) return json_show(1003, '该系统账号未开通登录');
+//
+//        }
+        $user = Db::name("account")
+            ->alias("a")
+            ->leftJoin("user b", "a.id=b.account_id and b.status=1")
+            ->leftJoin("account_item c", "c.account_id=a.id")
+            ->field("a.id,a.username,a.mobile,a.source,a.level,b.nickname,b.sex,b.email,a.addtime,a.updatetime,c.itemid,c.position")
+            ->where(["a.id" => $acc["id"]])
+            ->find();
+        if ($user == false) return json_show(1003, '用户信息不存在');
+
+        $usercompany = Db::name("account_company")
+            ->where(["account_id" => $user['id'], "is_del" => 0, "status" => 1])
+            ->column("companyCode,companyCode companyNo,companyName,companyName company_name,company_type,is_main,status");
         $user['company_relaton'] = $usercompany;
-        $cache = Cache::store("redis")->set("user:info:{$token}",$user ,$this->token_time);
-        if($cache==false)  return json_show(1003,'token保存失败');
-        $user['token']=$token;
-        return json_show(0,"登录成功",$user);
+        $cache = Cache::store("redis")->set("user:info:{$token}", $user, $this->token_time);
+        if ($cache == false) return json_show(1003, 'token保存失败');
+        $user['token'] = $token;
+        return json_show(0, "登录成功", $user);
     }
 
     /**
@@ -304,15 +305,14 @@ class User extends BaseController
 	* @throws \think\db\exception\ModelNotFoundException
 	* @throws \think\exception\DbException
 	 */
-   public function  verify_token(){
-       $post=$this->request->only(["token"=>''],"post");
-        $validate=Validate::rule([
-    		'token' => 'require',
-            ]);
-    	if($validate->check($post)==false) return json_show(1004,$validate->getError());
-        $getToken=checkToken($post['token'],$this->token_time);
-      return $getToken ==false?json_show(104,"token失效") :json_show(0,"获取成功",$getToken);
-   }
+    public function verify_token()
+    {
+        $post = $this->request->only(["token" => ''], "post");
+        $validate = Validate::rule(['token' => 'require']);
+        if ($validate->check($post) == false) return json_show(1004, $validate->getError());
+        $getToken = checkToken($post['token'], $this->token_time);
+        return $getToken == false ? json_show(104, "token失效") : json_show(0, "获取成功", $getToken);
+    }
 
     /**
      * @return \think\response\Json|void

+ 2 - 2
app/controller/UserCompany.php

@@ -31,7 +31,7 @@ class UserCompany extends BaseController
 
         $list = Db::name('account_company')
             ->alias('a')
-            ->field('a.id,a.account_id,a.companyCode,a.companyName,a.company_type,a.is_main,a.status com_status,c.username,c.mobile,c.source,c.status account_status,b.nickname,b.sex,b.email,c.addtime,c.updatetime')
+            ->field('a.id,a.account_id,a.companyCode,a.companyName,a.company_type,a.is_main,a.status com_status,c.username,c.mobile,c.source,c.status account_status,b.nickname,b.sex,b.email,c.addtime,c.updatetime,c.level')
             ->leftJoin('user b', 'a.account_id=b.account_id')
             ->leftJoin('account c', 'c.id=a.account_id and c.is_del=0')
             ->where($condition)
@@ -132,7 +132,7 @@ class UserCompany extends BaseController
 
         $rs = Db::name('account_company')
             ->alias('a')
-            ->field('a.id,a.account_id,a.companyCode,a.companyName,a.company_type,a.is_main,a.status com_status,c.username,c.mobile,c.source,c.status account_status,b.nickname,b.sex,b.email,c.addtime,c.updatetime')
+            ->field('a.id,a.account_id,a.companyCode,a.companyName,a.company_type,a.is_main,a.status com_status,c.username,c.mobile,c.source,c.status account_status,b.nickname,b.sex,b.email,c.addtime,c.updatetime,c.level')
             ->leftJoin('user b', 'a.account_id=b.account_id')
             ->leftJoin('account c', 'c.id=a.account_id and c.is_del=0')
             ->where(['a.id' => $id, 'a.is_del' => 0])

+ 79 - 56
app/controller/UserCompanyBasic.php

@@ -16,12 +16,14 @@ class UserCompanyBasic extends BaseController
     //列表
     public function getList()
     {
-        $post = $this->request->only(['nickname' => '', 'username' => '', 'status' => '', 'page' => 1, 'size' => 10], 'post');
+        $post = $this->request->only(['nickname' => '', 'username' => '', 'status' => '', 'page' => 1, 'size' => 10, 'islevel' => 1], 'post');
         $condition = [['a.is_del', '=', 0]];
 
         if ($post['nickname'] != '') $condition[] = ['nickname', 'like', "%{$post['nickname']}%"];
         if ($post['username'] != '') $condition[] = ['username', 'like', "%{$post['username']}%"];
         if ($post['status'] != '') $condition[] = ['a.status', '=', $post['status']];
+        if ($post['islevel'] == 1) $condition[] = ['a.level', '=', 1];
+        else $condition[] = ['a.level', '<>', 1];
 
         $count = Db::name('account')
             ->alias('a')
@@ -35,7 +37,7 @@ class UserCompanyBasic extends BaseController
             ->leftJoin('user b', 'a.id=b.account_id and b.status=1')
             ->where($condition)
             ->page($post['page'], $post['size'])
-//            ->append(['plat', 'company_relaton'])
+            ->append(['plat', 'company_relaton'])
 //            ->withAttr('plat', function ($val, $da) {
 //                return Db::name('account_plat')
 //                    ->alias('a')
@@ -45,13 +47,13 @@ class UserCompanyBasic extends BaseController
 //                    ->select()
 //                    ->toArray();
 //            })
-//            ->withAttr('company_relaton', function ($val, $da) {
-//                return Db::name('account_company')
-//                    ->where(['account_id' => $da['id'], 'is_del' => 0])
-//                    ->field('companyCode,companyName,company_type,is_main,status')
-//                    ->select()
-//                    ->toArray();
-//            })
+            ->withAttr('company_relaton', function ($val, $da) {
+                return Db::name('account_company')
+                    ->where(['account_id' => $da['id'], 'is_del' => 0])
+                    ->field('companyCode,companyName,company_type,is_main,status')
+                    ->select()
+                    ->toArray();
+            })
             ->order('a.addtime desc')
             ->select()
             ->toArray();
@@ -130,7 +132,7 @@ class UserCompanyBasic extends BaseController
                         $acount->saveAll($company_insert);
                     }
                     Db::commit();
-                    return json_show(0, '账户注册成功',['uid'=>$reuslt]);
+                    return json_show(0, '账户注册成功', ['uid' => $reuslt]);
                 }
             } else throw new Exception();
 
@@ -183,13 +185,11 @@ class UserCompanyBasic extends BaseController
     //编辑
     public function update()
     {
-        $post = $this->request->only(['id', 'nickname', 'mobile', 'email' => '', 'portrait' => '', 'sex' => '',], 'post');
+        $post = $this->request->only(['id', 'itemid'], 'post');
+
         $validate = Validate::rule([
             'id|主键ID' => 'require|number|gt:0',
-            'nickname|名称' => 'require|max:255',
-            'mobile|手机号' => 'require|number|length:11|mobile',
-            'email|名称' => 'email',
-            'sex|性别' => 'number|in:0,1,2',
+            'itemid|部门ID' => 'require|number|gt:0',
         ]);
         if ($validate->check($post) == false) return json_show(1004, $validate->getError());
         $account = Db::name('account')
@@ -198,41 +198,62 @@ class UserCompanyBasic extends BaseController
             ->findOrEmpty();
         if (empty($account)) return json_show(1003, '账户不存在');
 
-        $accountinfo = Db::name('user')
+        $tmp = Db::name('account_item')
             ->field('id')
-            ->where([['account_id', '=', $post['id']]])
+            ->where(['account_id' => $post['id']])
             ->findOrEmpty();
-        if (empty($accountinfo)) return json_show(1003, '账户信息不存在');
-
-        Db::startTrans();
-        try {
-
-            Db::name('user')
-                ->where($accountinfo)
-                ->update([
-                    'nickname' => $post['nickname'],
-                    'mobile' => $post['mobile'],
-                    'email' => $post['email'],
-                    'portrait' => $post['portrait'],
-                    'sex' => $post['sex'],
-                    'updatetime' => date('Y-m-d H:i:s')
-                ]);
-
-            Db::name('account')
-                ->where('id', $post['id'])
-                ->update([
-                    'id' => $post['id'],
-                    'mobile' => $post['mobile'],
-                    'username' => $post['mobile'],
-                    'updatetime' => date('Y-m-d H:i:s'),
-                ]);
-
-            Db::commit();
-            return json_show(0, '信息修改成功');
-        } catch (Exception $exception) {
-            Db::rollback();
-            return json_show(1005, '信息修改失败,' . $exception->getMessage());
-        }
+        $date = date('Y-m-d H:i:s');
+        if (empty($tmp)) $rs = Db::name('account_item')
+            ->insert([
+                'account_id' => $post['id'],
+                'itemid' => $post['itemid'],
+                'addtime' => $date,
+                'updatetime' => $date,
+            ]);
+        else  $rs = Db::name('account_item')
+            ->where(['id' => $tmp['id']])
+            ->update([
+                'itemid' => $post['itemid'],
+                'updatetime' => $date
+            ]);
+
+        return $rs ? json_show(0, '信息修改成功') : json_show(0, '信息修改失败');;
+
+//        $accountinfo = Db::name('user')
+//            ->field('id')
+//            ->where([['account_id', '=', $post['id']]])
+//            ->findOrEmpty();
+//        if (empty($accountinfo)) return json_show(1003, '账户信息不存在');
+
+//        Db::startTrans();
+//        try {
+
+//            Db::name('user')
+//                ->where($accountinfo)
+//                ->update([
+//                    'nickname' => $post['nickname'],
+//                    'mobile' => $post['mobile'],
+//                    'email' => $post['email'],
+//                    'portrait' => $post['portrait'],
+//                    'sex' => $post['sex'],
+//                    'updatetime' => date('Y-m-d H:i:s')
+//                ]);
+//
+//            Db::name('account')
+//                ->where('id', $post['id'])
+//                ->update([
+//                    'id' => $post['id'],
+//                    'mobile' => $post['mobile'],
+//                    'username' => $post['mobile'],
+//                    'updatetime' => date('Y-m-d H:i:s'),
+//                ]);
+
+//            Db::commit();
+//            return json_show(0, '信息修改成功');
+//        } catch (Exception $exception) {
+//            Db::rollback();
+//            return json_show(1005, '信息修改失败,' . $exception->getMessage());
+//        }
 
     }
 
@@ -283,21 +304,23 @@ class UserCompanyBasic extends BaseController
 
         $list = Db::name('account')
             ->alias('a')
-            ->field('a.id,a.username,a.mobile,a.source,a.status,b.nickname,b.sex,b.email,a.addtime,a.updatetime')
+            ->field('a.id,a.username,a.mobile,a.source,a.status,b.nickname,b.sex,b.email,a.addtime,a.updatetime,c.itemid,d.name item_name')
             ->leftJoin('user b', 'a.id=b.account_id')
-//            ->append(['plat','company_relaton'])
-//            ->withAttr('plat',function($val,$da){
+            ->leftJoin('account_item c', 'c.account_id=a.id')
+            ->leftJoin('company_item d', 'd.id=c.itemid')
+            ->append(['plat', 'company_relaton'])
+//            ->withAttr('plat', function ($val, $da) {
 //                return Db::name('account_plat')
 //                    ->alias('a')
 //                    ->leftJoin('platform b', 'a.plat_code=b.plat_code and b.status=1')
 //                    ->where(['a.status' => 1, 'a.is_del' => 0, 'a.account_id' => $da['id']])
 //                    ->column('a.plat_code,plat_name');
 //            })
-//            ->withAttr('company_relaton',function($val,$da){
-//                return Db::name('account_company')
-//                    ->where(['account_id' => $da['id'], 'is_del' => 0, 'status' => 1])
-//                    ->column('companyCode,companyName,company_type,is_main,status');
-//            })
+            ->withAttr('company_relaton', function ($val, $da) {
+                return Db::name('account_company')
+                    ->where(['account_id' => $da['id'], 'is_del' => 0, 'status' => 1])
+                    ->column('companyCode,companyName,company_type,is_main,status');
+            })
             ->where(['a.id' => $id, 'a.is_del' => 0])
             ->findOrEmpty();
         if (empty($list)) return json_show(1004, '未找到用户信息');

+ 23 - 23
app/controller/UserInfo.php

@@ -26,14 +26,14 @@ class UserInfo extends BaseController
 	 */
 	public function UserList()
     {
-        $post=$this->request->only(["nickname"=>"","username"=>"","status"=>"","companyNo"=>"","uid"=>[],"nuid"=>[],
-        "page"=>1,"size"=>10],"post");
+        $post=$this->request->only(["nickname"=>"","username"=>"","status"=>"","companyNo"=>"","uid"=>[],"nuid"=>[], "page"=>1,"size"=>10,'level'=>''],"post");
         $condition = [["a.is_del","=",0]];
         isset($post['nickname'])&& $post['nickname']!="" ? $condition[]=["nickname","like","%{$post['nickname']}%"] : "";
         isset($post['username'])&& $post['username']!="" ? $condition[]=["username","like","%{$post['username']}%"] : "";
         isset($post['status'])&& $post['status']!=="" ? $condition[]=["a.status","=",$post['status']] : "";
         isset($post['uid'])&& !empty($post['uid']) ? $condition[]=["a.id","in",$post['uid']] : "";
         isset($post['nuid'])&& !empty($post['nuid']) ? $condition[]=["a.id","not in",$post['nuid']] : "";
+        isset($post['level'])&& !empty($post['level']) ? $condition[]=["a.level",'=',$post['level']] : "";
 
         if ($post['companyNo']!=""){
         	$uid =Db::name("account_company")->where(["companyCode"=>$post['companyNo'],"is_del"=>0])->column("account_id");
@@ -49,15 +49,15 @@ class UserInfo extends BaseController
         $list =  Db::name("account")->alias("a")
 			->leftJoin("user b","a.id=b.account_id and b.status=1")
 			->append(['plat', 'company_relaton'])
-            ->withAttr('plat', function ($val, $da) {
-                return Db::name("account_plat")
-                    ->alias("a")
-                    ->leftJoin("platform b", "a.plat_code=b.plat_code and b.is_del=0 and b.status=1")
-                    ->where(["a.status" => 1, "a.is_del" => 0, "a.account_id" => $da['id']])
-                    ->field("a.plat_code,plat_name")
-                    ->select()
-                    ->toArray();
-            })
+//            ->withAttr('plat', function ($val, $da) {
+//                return Db::name("account_plat")
+//                    ->alias("a")
+//                    ->leftJoin("platform b", "a.plat_code=b.plat_code and b.is_del=0 and b.status=1")
+//                    ->where(["a.status" => 1, "a.is_del" => 0, "a.account_id" => $da['id']])
+//                    ->field("a.plat_code,plat_name")
+//                    ->select()
+//                    ->toArray();
+//            })
             ->withAttr('company_relaton', function ($val, $da) {
                 return Db::name("account_company")
                     ->where(["account_id" => $da['id'], "is_del" => 0])
@@ -89,9 +89,9 @@ class UserInfo extends BaseController
         if(empty($list)){
             return json_show(1004,"未找到用户信息");
         }
-        $list['plat']= Db::name("account_plat")->alias("a")
-        	->leftJoin("platform b","a.plat_code=b.plat_code and b.status=1")
-        	->where(["a.status"=>1,"a.is_del"=>0,"a.account_id"=>$list['id']])->column("a.plat_code,plat_name");
+//        $list['plat']= Db::name("account_plat")->alias("a")
+//        	->leftJoin("platform b","a.plat_code=b.plat_code and b.status=1")
+//        	->where(["a.status"=>1,"a.is_del"=>0,"a.account_id"=>$list['id']])->column("a.plat_code,plat_name");
         $list['company_relaton'] = Db::name("account_company")->where(["account_id"=>$list['id'],"is_del"=>0,"status"=>1])
 				->column("companyCode,companyName,company_type,is_main,status");
         return json_show(0,"获取成功",$list);
@@ -333,15 +333,15 @@ class UserInfo extends BaseController
             ->whereOr($whereor)
             ->page($page, $size)
             ->append(['plat', 'company_relaton'])
-            ->withAttr('plat', function ($val, $da) {
-                return Db::name("account_plat")
-                    ->alias("a")
-                    ->leftJoin("platform b", "a.plat_code=b.plat_code and b.is_del=0 and b.status=1")
-                    ->where(["a.status" => 1, "a.is_del" => 0, "a.account_id" => $da['id']])
-                    ->field("a.plat_code,plat_name")
-                    ->select()
-                    ->toArray();
-            })
+//            ->withAttr('plat', function ($val, $da) {
+//                return Db::name("account_plat")
+//                    ->alias("a")
+//                    ->leftJoin("platform b", "a.plat_code=b.plat_code and b.is_del=0 and b.status=1")
+//                    ->where(["a.status" => 1, "a.is_del" => 0, "a.account_id" => $da['id']])
+//                    ->field("a.plat_code,plat_name")
+//                    ->select()
+//                    ->toArray();
+//            })
             ->withAttr('company_relaton', function ($val, $da) {
                 return Db::name("account_company")
                     ->where(["account_id" => $da['id'], "is_del" => 0])

+ 10 - 0
route/app.php

@@ -55,3 +55,13 @@ Route::rule('sEdit', 'Headquarters/sEdit');
 Route::rule('cTitle', 'Headquarters/cTitle');
 Route::rule('delete', 'Headquarters/delete');
 Route::rule('status', 'Headquarters/status');
+Route::rule('getCodeAndName', 'Headquarters/getCodeAndName');
+
+//组织架构
+Route::rule('ulist', 'CompanyItem/getList');
+Route::rule('add', 'CompanyItem/add');
+Route::rule('refresh', 'CompanyItem/update');
+Route::rule('itemdel', 'CompanyItem/delete');
+Route::rule('stat', 'CompanyItem/status');
+Route::rule('userp', 'CompanyItem/userp');
+