123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- <?php
- namespace app\admin\controller;
- use app\admin\common\User as UserCommon;
- use think\facade\Db;
- use think\facade\Validate;
- //【公司账号查询】
- class UserCompany extends Base
- {
- //列表
- public function getList()
- {
- $param = $this->request->only(['account_id' => '', 'status' => '', 'page' => 1, 'size' => 10], 'post', 'trim');
- $userCommon = UserCommon::getIns();
- $rs = $userCommon->handle('userCompanyList', $param);
- if (isset($rs['code']) && $rs['code'] == 0) {
- //补充角色信息
- foreach ($rs['data']['list'] as &$item) {
- $tmp = Db::name('user_role')
- ->alias('a')
- ->field('b.role_name')
- ->leftJoin('role b', 'b.id=a.roleid')
- ->where(['a.uid' => $item['account_id'], 'a.is_del' => 0, 'a.companyNo' => $item['companyCode']])
- ->findOrEmpty();
- $item['role_name'] = $tmp['role_name'] ?? '';
- }
- }
- return json_show($rs['code'], $rs['message'], $rs['data']);
- }
- //编辑
- public function update()
- {
- $param = $this->request->only(['account_id', 'companyNo', 'roleid'], 'post');
- $val = Validate::rule([
- 'account_id|账户id' => 'require|number|gt:0',
- 'companyNo|公司编码' => 'require|length:18',
- 'roleid|角色' => 'require|number|gt:0',
- ]);
- if (!$val->check($param)) return json_show(1004, $val->getError());
- // $role = Db::name('role')
- // ->field('id')
- // ->where('id', $param['roleid'])
- // ->where('level', '<>', 1)
- // ->findOrEmpty();
- //
- // if (empty($role)) return json_show(1004, '角色不存在或等级不符合要求');
- // $item = Db::name('company_item')
- // ->field('id')
- // ->where(['id' => $param['itemid'], 'companyNo' => $param['companyNo']])
- // ->findOrEmpty();
- // if (empty($item)) return json_show(1004, '该公司部门不存在');
- // $tmp = Db::name('user_role')
- // ->field('id')
- // ->where(['uid' => $param['account_id'], 'companyNo' => $param['companyNo'], 'is_del' => 0])
- // ->findOrEmpty();
- $date = date('Y-m-d H:i:s');
- $tmp = Db::name('user_role')
- ->field('id')
- ->where(['uid' => $param['account_id'], 'companyNo' => $param['companyNo'], 'is_del' => 0])
- ->findOrEmpty();
- if (empty($tmp)) {
- $rs = Db::name('user_role')
- ->insert([
- 'uid' => $param['account_id'],
- 'roleid' => $param['roleid'],
- 'companyNo' => $param['companyNo'],
- 'addtime' => $date,
- 'updatetime' => $date,
- ]);
- } else {
- $rs = Db::name('user_role')
- ->where('id', $tmp['id'])
- ->update(['roleid' => $param['roleid'], 'updatetime' => $date]);
- }
- // $userCommon = UserCommon::getIns();
- // $rs = json_decode($userCommon->handle('userCompanyUpdate', $param), true);
- return $rs ? json_show(0, '修改成功') : json_show(1004, '修改失败');
- }
- //启禁用
- public function status()
- {
- $param = $this->request->only(['id', 'status'], 'post', 'trim');
- $val = Validate::rule([
- 'id' => 'require|number|gt:0',
- 'status' => 'require|number|in:0,1',
- ]);
- if ($val->check($param) == false) return json_show(1004, $val->getError());
- $userCommon = UserCommon::getIns();
- $rs = $userCommon->handle('userCompanyStatus', $param);
- if (!isset($rs['code']) || $rs['code'] != 0) return json_show($rs['code'], $rs['message'], $rs['data']);
- else {
- $res = Db::name('user_role')
- ->where('status', '<>', $param['status'])
- ->where(['uid' => $rs['data']['account_id'], 'companyNo' => $rs['data']['companyNo'], 'is_del' => 0])
- ->update(['status' => $param['status'], 'updatetime' => date('Y-m-d H:i:s')]);
- return $res ? json_show(0, '操作成功') : json_show(1004, '操作失败');
- }
- }
- //详情
- public function info()
- {
- $param = $this->request->post(['id'], 'post', 'trim');
- $userCommon = UserCommon::getIns();
- $rs = $userCommon->handle('userCompanyInfo', $param);
- if (isset($rs['code']) && $rs['code'] == 0) {
- $tmp = Db::name('user_role')
- ->alias('a')
- ->field('a.roleid,b.role_name')
- ->leftJoin('role b', 'b.id=a.roleid')
- // ->leftJoin('company_item c', 'c.id=a.itemid and c.companyNo=a.companyNo')
- ->where(['a.uid' => $rs['data']['account_id'], 'is_del' => 0, 'a.companyNo' => $rs['data']['companyCode']])
- ->findOrEmpty();
- $rs['data']['roleid'] = $tmp['roleid'] ?? '';
- $rs['data']['role_name'] = $tmp['role_name'] ?? '';
- // $rs['data']['item_name'] = $tmp['item_name'] ?? '';
- }
- return json_show($rs['code'], $rs['message'], $rs['data']);
- }
- //获取当前账号绑定公司列表
- public function myCompanyList()
- {
- $param = $this->request->only(['status' => '', 'page' => 1, 'size' => 10, 'companyCode' => '', 'companyName' => ''], 'post', 'trim');
- $param['account_id'] = $this->uid;
- $userCommon = UserCommon::getIns();
- $rs = $userCommon->handle('userCompanyList', $param);
- if (isset($rs['code']) && $rs['code'] == 0) {
- //补充角色信息
- foreach ($rs['data']['list'] as &$item) {
- $tmp = Db::name('user_role')
- ->alias('a')
- ->field('a.roleid,b.role_name')
- ->leftJoin('role b', 'b.id=a.roleid')
- ->where(['a.uid' => $item['account_id'], 'a.is_del' => 0, 'a.companyNo' => [$item['companyCode'],'']])
- ->order(['a.companyNo'=>'desc'])
- ->findOrEmpty();
- $item['roleid'] = $tmp['roleid'] ?? '';
- $item['role_name'] = $tmp['role_name'] ?? '';
- }
- }
- return json_show($rs['code'], $rs['message'], $rs['data']);
- }
- //切换默认公司
- public function changeMain()
- {
- $param = $this->request->filter('trim')->post();
- $userCommon = UserCommon::getIns();
- $rs = $userCommon->handle('changeMain', $param);
- return json_show($rs['code'], $rs['message'], $rs['data']);
- }
- }
|