编辑用户信息及修改密码
This commit is contained in:
@@ -576,6 +576,76 @@ class AccountController extends BaseController
|
||||
|
||||
|
||||
|
||||
public function accountModify($data = [])
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = $this->authorization;
|
||||
if (empty($authorization)) {
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
|
||||
|
||||
$id = !empty($data['id']) ? $data['id'] : '';
|
||||
if (empty($id)) {
|
||||
return errorJson('账号ID不能为空');
|
||||
}
|
||||
|
||||
$account = CompanyAccountModel::where('id', $id)->find();
|
||||
|
||||
|
||||
|
||||
if (empty($account)) {
|
||||
return errorJson('账号不存在');
|
||||
}
|
||||
$privilegeIds = json_decode($account->privilegeIds,true);
|
||||
$privilegeIds = !empty($privilegeIds) ? $privilegeIds : [1001,1002,1004,1023,1406,20003,20021,20022,20023,20032,20041,20049,20054,20055,20060,20100,20102,20107,20055];
|
||||
|
||||
// 构建请求参数
|
||||
$params = [
|
||||
'accountType' => !empty($data['accountType']) ? $data['accountType'] : $account->accountType,
|
||||
'alive' => !empty($data['alive']) ? $data['alive'] : $account->alive,
|
||||
'avatar' => !empty($data['avatar']) ? $data['avatar'] : $account->avatar,
|
||||
'createTime' => !empty($data['createTime']) ? $data['createTime'] : $account->createTime,
|
||||
'creator' => !empty($data['creator']) ? $data['creator'] : $account->creator,
|
||||
'creatorRealName' => !empty($data['creatorRealName']) ? $data['creatorRealName'] : $account->creatorRealName,
|
||||
'creatorUserName' => !empty($data['creatorUserName']) ? $data['creatorUserName'] : $account->creatorUserName,
|
||||
'departmentId' => !empty($data['departmentId']) ? $data['departmentId'] : $account->departmentId,
|
||||
'departmentIdArr' => !empty($data['departmentIdArr']) ? $data['departmentIdArr'] : [914,$account->departmentId],
|
||||
'departmentName' => !empty($data['departmentName']) ? $data['departmentName'] : $account->departmentName,
|
||||
'hasXiakeAccount' => !empty($data['hasXiakeAccount']) ? $data['hasXiakeAccount'] : false,
|
||||
'id' => !empty($data['id']) ? $data['id'] : $account->id,
|
||||
'memo' => !empty($data['memo']) ? $data['memo'] : $account->memo,
|
||||
'nickname' => !empty($data['nickname']) ? $data['nickname'] : $account->nickname,
|
||||
'privilegeIds' => !empty($data['privilegeIds']) ? $data['privilegeIds'] : $privilegeIds,
|
||||
'realName' => !empty($data['realName']) ? $data['realName'] : $account->realName,
|
||||
'status' => !empty($data['status']) ? $data['status'] : $account->status,
|
||||
'tenantId' => !empty($data['tenantId']) ? $data['tenantId'] : $account->tenantId,
|
||||
'userName' => !empty($data['userName']) ? $data['userName'] : $account->userName,
|
||||
];
|
||||
// 设置请求头
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization, 'json');
|
||||
|
||||
// 发送请求修改部门
|
||||
$result = requestCurl($this->baseUrl . 'api/account/modify', $params, 'PUT', $header, 'json');
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
|
||||
if(empty($response)){
|
||||
$newData = [
|
||||
'nickname' => $params['nickname'],
|
||||
'avatar' => $params['avatar'],
|
||||
];
|
||||
CompanyAccountModel::where('id', $id)->update($newData);
|
||||
return json_encode(['code' => 200, 'msg' => '账号修改成功']);
|
||||
}else{
|
||||
return json_encode(['code' => 500, 'msg' => $response]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/************************ 私有辅助方法 ************************/
|
||||
|
||||
@@ -7,6 +7,14 @@ use think\facade\Route;
|
||||
|
||||
// 定义RESTful风格的API路由
|
||||
Route::group('v1/', function () {
|
||||
|
||||
Route::group('user', function () {
|
||||
Route::put('editUserInfo', 'app\cunkebao\controller\BaseController@editUserInfo');
|
||||
Route::put('editPassWord', 'app\cunkebao\controller\BaseController@editPassWord');
|
||||
});
|
||||
|
||||
|
||||
|
||||
// 设备管理相关
|
||||
Route::group('devices', function () {
|
||||
Route::put('refresh', 'app\cunkebao\controller\device\RefreshDeviceDetailV1Controller@index');
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
|
||||
namespace app\cunkebao\controller;
|
||||
|
||||
use app\api\controller\AccountController;
|
||||
use app\common\service\ClassTableService;
|
||||
use library\ResponseHelper;
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 设备管理控制器
|
||||
@@ -58,4 +61,96 @@ class BaseController extends Controller
|
||||
|
||||
return $column ? $user[$column] : $user;
|
||||
}
|
||||
|
||||
|
||||
public function editUserInfo()
|
||||
{
|
||||
$userId = $this->request->param('userId', '');
|
||||
$nickname = $this->request->param('nickname', '');
|
||||
$avatar = $this->request->param('avatar', '');
|
||||
$phone = $this->request->param('phone', '');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
if (empty($userId)) {
|
||||
return ResponseHelper::error('用户id不能为空');
|
||||
}
|
||||
|
||||
if (empty($nickname) && empty($avatar) && empty($phone)) {
|
||||
return ResponseHelper::error('修改的用户信息不能为空');
|
||||
}
|
||||
|
||||
$user = Db::name('users')->where(['id' => $userId, 'companyId' => $companyId])->find();
|
||||
if (empty($user)) {
|
||||
return ResponseHelper::error('用户不存在');
|
||||
}
|
||||
|
||||
$user2 = Db::name('users')->where(['phone' => $phone])->find();
|
||||
if (!empty($user2) && $user2['id'] != $userId) {
|
||||
return ResponseHelper::error('修改的手机号已存在');
|
||||
}
|
||||
|
||||
$data = [
|
||||
'id' => $user['s2_accountId'],
|
||||
];
|
||||
|
||||
if (!empty($nickname)) {
|
||||
$data['nickname'] = $nickname;
|
||||
}
|
||||
if (!empty($avatar)) {
|
||||
$data['avatar'] = $avatar;
|
||||
}
|
||||
if (!empty($phone)) {
|
||||
$data['phone'] = $phone;
|
||||
}
|
||||
|
||||
$AccountControllel = new AccountController();
|
||||
$res = $AccountControllel->accountModify($data);
|
||||
$res = json_decode($res, true);
|
||||
if ($res['code'] == 200) {
|
||||
unset($data['id']);
|
||||
if (!empty($nickname)) {
|
||||
$data['username'] = $nickname;
|
||||
unset($data['nickname']);
|
||||
}
|
||||
Db::name('users')->where(['id' => $userId, 'companyId' => $companyId])->update($data);
|
||||
return ResponseHelper::success('更新成功');
|
||||
} else {
|
||||
return ResponseHelper::error($res['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function editPassWord()
|
||||
{
|
||||
$userId = $this->request->param('userId', '');
|
||||
$passWord = $this->request->param('passWord', '');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
if (empty($userId)) {
|
||||
return ResponseHelper::error('用户id不能为空');
|
||||
}
|
||||
|
||||
if (empty($passWord)) {
|
||||
return ResponseHelper::error('密码不能为空');
|
||||
}
|
||||
|
||||
$user = Db::name('users')->where(['id' => $userId, 'companyId' => $companyId])->find();
|
||||
if (empty($user)) {
|
||||
return ResponseHelper::error('用户不存在');
|
||||
}
|
||||
if ($user['passwordMd5'] == md5($passWord)) {
|
||||
return ResponseHelper::error('新密码与旧密码一致');
|
||||
}
|
||||
|
||||
$data = [
|
||||
'passwordMd5' => md5($passWord),
|
||||
'passwordLocal' => localEncrypt($passWord),
|
||||
'updateTime' => time()
|
||||
];
|
||||
|
||||
$res = Db::name('users')->where(['id' => $userId, 'companyId' => $companyId])->update($data);
|
||||
if (!empty($res)) {
|
||||
return ResponseHelper::success('密码修改成功');
|
||||
} else {
|
||||
return ResponseHelper::error('密码修改失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user