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']); } }