Procházet zdrojové kódy

Merge branch 'dev' of http://120.46.155.214:3000/wugg/useraccount into dev

wugg před 2 roky
rodič
revize
73661712f4

+ 1 - 1
app/controller/User.php

@@ -168,7 +168,7 @@ class User extends BaseController
         	->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,'该系统账号开通登录');
+        		 return json_show(1003,'该系统账号开通登录');
         	}
         }
 		$user =Db::name("account")->alias("a")

+ 147 - 0
app/controller/UserCompany.php

@@ -0,0 +1,147 @@
+<?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 UserCompany extends BaseController
+{
+
+    //列表
+    public function getList()
+    {
+        $post = $this->request->only(['account_id' => '', 'status' => '', 'page' => 1, 'size' => 10], 'post');
+        $condition = [['a.is_del', '=', 0]];
+
+        if ($post['account_id'] != '') $condition[] = ['a.account_id', '=', $post['account_id']];
+        if ($post['status'] != '') $condition[] = ['a.status', '=', $post['status']];
+
+        $count = Db::name('account_company')
+            ->alias('a')
+            ->leftJoin('user b', 'a.account_id=b.account_id')
+            ->leftJoin('account c', 'c.id=a.account_id and c.is_del=0')
+            ->where($condition)
+            ->count('a.id');
+
+        $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')
+            ->leftJoin('user b', 'a.account_id=b.account_id')
+            ->leftJoin('account c', 'c.id=a.account_id and c.is_del=0')
+            ->where($condition)
+            ->page($post['page'], $post['size'])
+            ->order('a.addtime desc')
+            ->select()
+            ->toArray();
+
+        return json_show(0, '获取成功', ['list' => $list, 'count' => $count]);
+    }
+
+    //编辑
+    public function update()
+    {
+        $post = $this->request->only(['id', 'nickname', 'mobile', 'email' => '', 'portrait' => '', 'sex' => '',], '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',
+        ]);
+        if ($validate->check($post) == false) return json_show(1004, $validate->getError());
+        $account = Db::name('account')
+            ->field('id')
+            ->where([['id', '=', $post['id']], ['is_del', '=', 0]])
+            ->findOrEmpty();
+        if (empty($account)) return json_show(1003, '账户不存在');
+
+        $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(['account_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());
+        }
+
+    }
+
+    //启禁用
+    public function status()
+    {
+        $post = $this->request->only(['id', 'status'], 'post', 'trim');
+        $validate = Validate::rule(['id|主键ID' => 'require|number|gt:0', 'status|状态' => 'require|number|in:0,1']);
+        if ($validate->check($post) == false) return json_show(1004, $validate->getError());
+
+        $tmp = Db::name('account_company')
+            ->field('id,account_id,companyCode companyNo')
+            ->where(['id' => $post['id'], 'is_del' => 0])
+            ->findOrEmpty();
+
+        if (empty($tmp)) return json_show(1004, '该记录不存在');
+        if ($tmp['status'] == $post['status']) return json_show(1004, '重复操作');
+
+        $rs = Db::name('account_company')
+            ->where('status', '<>', $post['status'])
+            ->where(['id' => $post['id'], 'is_del' => 0])
+            ->update(['status' => $post['status'], 'updatetime' => date('Y-m-d H:i:s')]);
+
+        return $rs ? json_show(0, '操作成功',$tmp) : json_show(1004, '操作失败');
+
+    }
+
+    //详情
+    public function info()
+    {
+
+        $id = $this->request->post('id/d', 0, 'trim');
+        if ($id == 0) return json_show(1003, "参数 id 不能为空");
+
+        $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')
+            ->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])
+            ->findOrEmpty();
+
+        if (empty($rs)) return json_show(1004, '未找到用户信息');
+
+        return json_show(0, '获取成功', $rs);
+    }
+
+
+}

+ 314 - 0
app/controller/UserCompanyBasic.php

@@ -0,0 +1,314 @@
+<?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 UserCompanyBasic extends BaseController
+{
+
+    //列表
+    public function getList()
+    {
+        $post = $this->request->only(['nickname' => '', 'username' => '', 'status' => '', 'page' => 1, 'size' => 10], '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']];
+
+        $count = Db::name('account')
+            ->alias('a')
+            ->leftJoin('user b', 'a.id=b.account_id and b.status=1')
+            ->where($condition)
+            ->count('a.id');
+
+        $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')
+            ->leftJoin('user b', 'a.id=b.account_id and b.status=1')
+            ->where($condition)
+            ->page($post['page'], $post['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('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();
+
+        return json_show(0, '获取成功', ['list' => $list, 'count' => $count]);
+    }
+
+    //注册
+    public function add()
+    {
+        $post = $this->request->only(['nickname' => '', 'mobile' => '', 'email' => '', 'companyArr' => []], 'post', 'trim');
+        $validate = Validate::rule([
+            'nickname|真实姓名' => 'require|min:2|max:200',
+            'mobile|手机号' => 'require|number|length:11|mobile',
+            'email|邮箱' => 'email',
+            'companyArr|关联业务公司' => 'require|array|max:100',
+        ]);
+        if ($validate->check($post) == false) return json_show(1004, $validate->getError());
+        Db::startTrans();
+
+        try {
+
+            $uiq = Db::table('sys_account')
+                ->field('id')
+                ->where(['mobile' => $post['mobile']])
+                ->findOrEmpty();
+            if ($uiq) throw new Exception('手机号已注册!');
+
+            $date = date('Y-m-d H:i:s');
+            $salt = makeSalt();
+            $password = sha1('dingding123' . $salt);
+            $data = [
+                'username' => $post['mobile'],
+                'password' => $password,
+                'salt' => $salt,
+                'mobile' => $post['mobile'],
+                'source' => 'paltadd',
+                'status' => 1,
+                'addtime' => $date,
+                'updatetime' => $date
+            ];
+            $reuslt = Db::table('sys_account')->insertGetId($data);
+            if ($reuslt) {
+                $data = [
+                    'nickname' => $post['nickname'],
+                    'mobile' => $post['mobile'],
+                    'email' => $post['email'],
+                    'portrait' => '',
+                    'sex' => 1,
+                    'post' => '',
+                    'department' => '',
+                    'account_id' => $reuslt,
+                    'status' => 1,
+                    'addtime' => $date,
+                    'updatetime' => $date
+                ];
+                $user = Db::table('sys_user')->insert($data);
+                if ($user != false) {
+                    if (!empty($post['companyArr'])) {
+                        $company_insert = [];
+                        $acount = new AccountCompany();
+
+                        foreach ($post['companyArr'] as $company) {
+                            $company_insert[] = [
+                                'account_id' => $reuslt,
+                                'companyCode' => $company['companyCode'],
+                                'companyName' => $company['companyName'],
+                                'company_type' => $company['company_type'],
+                                'is_main' => $company['is_main'],
+                                'status' => 1,
+                                'is_del' => 0,
+                                'addtime' => $date,
+                                'updatetime' => $date,
+                            ];
+                        }
+                        $acount->saveAll($company_insert);
+                    }
+                    Db::commit();
+                    return json_show(0, '账户注册成功',['uid'=>$reuslt]);
+                }
+            } else throw new Exception();
+
+        } catch (Exception $e) {
+            Db::rollback();
+            return json_show(1002, '账户注册失败,' . $e->getMessage());
+        }
+    }
+
+    //删除
+    public function delete()
+    {
+
+        $param = $this->request->only(['ids'], 'post', 'trim');
+
+        $val = Validate::rule([
+            'ids' => 'require|array|max:100',
+        ]);
+
+        if (!$val->check($param)) return json_show(1004, $val->getError());
+
+        Db::startTrans();
+
+        try {
+            Db::name('account')
+                ->where(['is_del' => 0])
+                ->whereIn('id', $param['ids'])
+                ->update([
+                    'is_del' => 1,
+                    'updatetime' => date('Y-m-d H:i:s')
+                ]);
+
+            Db::name('account_company')
+                ->where(['is_del' => 0])
+                ->whereIn('account_id', $param['ids'])
+                ->update([
+                    'is_del' => 1,
+                    '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());
+        }
+
+    }
+
+    //编辑
+    public function update()
+    {
+        $post = $this->request->only(['id', 'nickname', 'mobile', 'email' => '', 'portrait' => '', 'sex' => '',], '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',
+        ]);
+        if ($validate->check($post) == false) return json_show(1004, $validate->getError());
+        $account = Db::name('account')
+            ->field('id')
+            ->where([['id', '=', $post['id']], ['is_del', '=', 0]])
+            ->findOrEmpty();
+        if (empty($account)) return json_show(1003, '账户不存在');
+
+        $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());
+        }
+
+    }
+
+    //启禁用
+    public function status()
+    {
+        $post = $this->request->only(['id', 'status'], 'post', 'trim');
+        $validate = Validate::rule(['id|主键ID' => 'require|number|gt:0', 'status|状态' => 'require|number|in:0,1']);
+        if ($validate->check($post) == false) return json_show(1004, $validate->getError());
+
+        Db::startTrans();
+
+        try {
+
+            $account = Account::where(['id' => $post['id'], 'is_del' => 0])
+                ->field('id,status')
+                ->findOrEmpty();
+            if (empty($account)) throw new Exception('账户不存在');
+
+            if ($account['status'] == $post['status']) throw new Exception('重复操作');
+
+            $message = $post['status'] == 1 ? '启用' : '禁用';
+
+            Db::name('account')
+                ->where('status', '<>', $post['status'])
+                ->where(['id' => $post['id'], 'is_del' => 0])
+                ->save(['status' => $post['status'], 'updatetime' => date('Y-m-d H:i:s')]);
+
+            Db::name('account_company')
+                ->where('status', '<>', $post['status'])
+                ->where(['account_id' => $post['id'], 'is_del' => 0])
+                ->save(['status' => $post['status'], 'updatetime' => date('Y-m-d H:i:s')]);
+
+            Db::commit();
+            return json_show(0, "账户{$message}成功");
+
+        } catch (Exception $exception) {
+            Db::rollback();
+            return json_show(1004, '操作失败,' . $exception->getMessage());
+        }
+    }
+
+    //详情
+    public function info()
+    {
+        $id = $this->request->post('id/d', 0, 'trim');
+        if ($id == 0) return json_show(1003, "参数 id 不能为空");
+
+        $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')
+            ->leftJoin('user b', 'a.id=b.account_id')
+//            ->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');
+//            })
+            ->where(['a.id' => $id, 'a.is_del' => 0])
+            ->findOrEmpty();
+        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['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);
+    }
+
+
+}

+ 13 - 2
route/app.php

@@ -22,7 +22,18 @@ Route::rule('userinfo', 'UserInfo/info');
 Route::rule('setpasswd', 'UserInfo/PassSet');
 Route::rule('setcompany', 'UserInfo/setCompany');
 Route::rule('companystatus', 'UserInfo/setCompanyStatus');
-Route::rule('userlistbycompany', 'UserInfo/UserListByCompany');
 Route::rule('useradd', 'UserInfo/userAdd');
+Route::rule('userDelete', 'UserInfo/userDelete');
 
-
+//【公司账号管理】
+Route::rule('userCompanyBasicAdd', 'UserCompanyBasic/add');
+Route::rule('userCompanyBasicList', 'UserCompanyBasic/getList');
+Route::rule('userCompanyBasicDelete', 'UserCompanyBasic/delete');
+Route::rule('userCompanyBasicUpdate', 'UserCompanyBasic/update');
+Route::rule('userCompanyBasicStatus', 'UserCompanyBasic/status');
+Route::rule('userCompanyBasicInfo', 'UserCompanyBasic/info');
+//【公司账号查询】
+Route::rule('userCompanyList', 'admin/UserCompany/getList');
+Route::rule('userCompanyInfo', 'admin/UserCompany/info');
+Route::rule('userCompanyUpdate', 'admin/UserCompany/update');
+Route::rule('userCompanyStatus', 'admin/UserCompany/status');