添加部门和账号优化
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -10,3 +10,4 @@ Server/.specstory/
|
|||||||
Store_vue/.specstory/
|
Store_vue/.specstory/
|
||||||
*.zip
|
*.zip
|
||||||
*.cursorindexingignore
|
*.cursorindexingignore
|
||||||
|
*.md
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class AccountController extends BaseController
|
|||||||
* @param bool $isJob 是否为定时任务调用
|
* @param bool $isJob 是否为定时任务调用
|
||||||
* @return \think\response\Json
|
* @return \think\response\Json
|
||||||
*/
|
*/
|
||||||
public function getlist($pageIndex = '',$pageSize = '',$isJob = false)
|
public function getlist($pageIndex = '', $pageSize = '', $isJob = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
$api = new AccountLogic();
|
$api = new AccountLogic();
|
||||||
@@ -32,9 +32,9 @@ class AccountController extends BaseController
|
|||||||
// 获取授权token
|
// 获取授权token
|
||||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||||
if (empty($authorization)) {
|
if (empty($authorization)) {
|
||||||
if($isJob){
|
if ($isJob) {
|
||||||
return json_encode(['code'=>500,'msg'=>'缺少授权信息']);
|
return json_encode(['code' => 500, 'msg' => '缺少授权信息']);
|
||||||
}else{
|
} else {
|
||||||
return errorJson('缺少授权信息');
|
return errorJson('缺少授权信息');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,7 @@ class AccountController extends BaseController
|
|||||||
'keyword' => $this->request->param('keyword', ''),
|
'keyword' => $this->request->param('keyword', ''),
|
||||||
'departmentId' => $this->request->param('departmentId', ''),
|
'departmentId' => $this->request->param('departmentId', ''),
|
||||||
'pageIndex' => !empty($pageIndex) ? $pageIndex : $this->request->param('pageIndex', 0),
|
'pageIndex' => !empty($pageIndex) ? $pageIndex : $this->request->param('pageIndex', 0),
|
||||||
'pageSize' => !empty($pageSize) ? $pageSize : $this->request->param('pageSize',20)
|
'pageSize' => !empty($pageSize) ? $pageSize : $this->request->param('pageSize', 20)
|
||||||
];
|
];
|
||||||
|
|
||||||
// 设置请求头
|
// 设置请求头
|
||||||
@@ -64,16 +64,16 @@ class AccountController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($isJob){
|
if ($isJob) {
|
||||||
return json_encode(['code'=>200,'msg'=>'获取公司账号列表成功','data'=>$response]);
|
return json_encode(['code' => 200, 'msg' => '获取公司账号列表成功', 'data' => $response]);
|
||||||
}else{
|
} else {
|
||||||
|
|
||||||
return successJson($response);
|
return successJson($response);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
if($isJob){
|
if ($isJob) {
|
||||||
return json_encode(['code'=>500,'msg'=>'获取公司账号列表失败:' . $e->getMessage()]);
|
return json_encode(['code' => 500, 'msg' => '获取公司账号列表失败:' . $e->getMessage()]);
|
||||||
}else{
|
} else {
|
||||||
return errorJson('获取公司账号列表失败:' . $e->getMessage());
|
return errorJson('获取公司账号列表失败:' . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,7 +140,21 @@ class AccountController extends BaseController
|
|||||||
$result = requestCurl($this->baseUrl . 'api/account/newAccount', $params, 'POST', $header, 'json');
|
$result = requestCurl($this->baseUrl . 'api/account/newAccount', $params, 'POST', $header, 'json');
|
||||||
|
|
||||||
if (is_numeric($result)) {
|
if (is_numeric($result)) {
|
||||||
return successJson($result);
|
$res = CompanyAccountModel::create([
|
||||||
|
'id' => $result,
|
||||||
|
'tenantId' => 242,
|
||||||
|
'userName' => $userName,
|
||||||
|
'realName' => $realName,
|
||||||
|
'nickname' => $nickname,
|
||||||
|
'passwordMd5' => md5($password),
|
||||||
|
'passwordLocal' => localEncrypt($password),
|
||||||
|
'memo' => $memo,
|
||||||
|
'accountType' => 11,
|
||||||
|
'departmentId' => $departmentId,
|
||||||
|
'createTime' => time(),
|
||||||
|
'privilegeIds' => json_encode([])
|
||||||
|
]);
|
||||||
|
return successJson($res);
|
||||||
} else {
|
} else {
|
||||||
return errorJson($result);
|
return errorJson($result);
|
||||||
}
|
}
|
||||||
@@ -150,7 +164,6 @@ class AccountController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建新账号(包含创建部门)
|
* 创建新账号(包含创建部门)
|
||||||
* @return \think\response\Json
|
* @return \think\response\Json
|
||||||
@@ -186,70 +199,82 @@ class AccountController extends BaseController
|
|||||||
|
|
||||||
// 检查部门是否已存在
|
// 检查部门是否已存在
|
||||||
$existingDepartment = CompanyModel::where('name', $departmentName)->find();
|
$existingDepartment = CompanyModel::where('name', $departmentName)->find();
|
||||||
if ($existingDepartment) {
|
|
||||||
return errorJson('部门名称已存在');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查账号是否已存在
|
// 检查账号是否已存在
|
||||||
$existingAccount = CompanyAccountModel::where('userName', $accountName)->find();
|
$existingAccount = CompanyAccountModel::where('userName', $accountName)->find();
|
||||||
if ($existingAccount) {
|
|
||||||
return errorJson('账号名称已存在');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1. 创建部门
|
|
||||||
$departmentParams = [
|
|
||||||
'name' => $departmentName,
|
|
||||||
'memo' => $departmentMemo,
|
|
||||||
'departmentIdArr' => [914],
|
|
||||||
'parentId' => 914
|
|
||||||
];
|
|
||||||
|
|
||||||
$headerData = ['client:system'];
|
$headerData = ['client:system'];
|
||||||
$header = setHeader($headerData, $authorization, 'json');
|
$header = setHeader($headerData, $authorization, 'json');
|
||||||
$departmentResult = requestCurl($this->baseUrl . 'api/Department/createDepartment', $departmentParams, 'POST', $header, 'json');
|
|
||||||
|
|
||||||
if (is_numeric($departmentResult)) {
|
// 1. 创建部门
|
||||||
// 保存部门到数据库
|
if (empty($existingDepartment)) {
|
||||||
$department = CompanyModel::create([
|
$departmentParams = [
|
||||||
'id' => $departmentResult,
|
|
||||||
'name' => $departmentName,
|
'name' => $departmentName,
|
||||||
'memo' => $departmentMemo,
|
'memo' => $departmentMemo,
|
||||||
'tenantId' => 242,
|
'departmentIdArr' => [914],
|
||||||
'isTop' => 0,
|
'parentId' => 914
|
||||||
'level' => 1,
|
];
|
||||||
'parentId' => 914,
|
|
||||||
'privileges' => '',
|
$departmentResult = requestCurl($this->baseUrl . 'api/Department/createDepartment', $departmentParams, 'POST', $header, 'json');
|
||||||
'createTime' => time(),
|
if (is_numeric($departmentResult)) {
|
||||||
'lastUpdateTime' => 0
|
// 保存部门到数据库
|
||||||
]);
|
CompanyModel::create([
|
||||||
|
'id' => $departmentResult,
|
||||||
|
'name' => $departmentName,
|
||||||
|
'memo' => $departmentMemo,
|
||||||
|
'tenantId' => 242,
|
||||||
|
'isTop' => 0,
|
||||||
|
'level' => 1,
|
||||||
|
'parentId' => 914,
|
||||||
|
'privileges' => '',
|
||||||
|
'createTime' => time(),
|
||||||
|
'lastUpdateTime' => 0
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
return errorJson('创建部门失败:' . $departmentResult);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return errorJson('创建部门失败:' . $departmentResult);
|
$departmentResult = $existingDepartment['id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 创建账号
|
if (empty($existingAccount)) {
|
||||||
$accountParams = [
|
// 2. 创建账号
|
||||||
'userName' => $accountName,
|
$accountParams = [
|
||||||
'password' => $accountPassword,
|
'userName' => $accountName,
|
||||||
'realName' => $accountRealName,
|
'password' => $accountPassword,
|
||||||
'nickname' => $accountNickname,
|
'realName' => $accountRealName,
|
||||||
'memo' => $accountMemo,
|
'nickname' => $accountNickname,
|
||||||
'departmentId' => $departmentResult,
|
'memo' => $accountMemo,
|
||||||
'departmentIdArr' => [914, $departmentResult]
|
'departmentId' => $departmentResult,
|
||||||
];
|
'departmentIdArr' => [914, $departmentResult]
|
||||||
|
];
|
||||||
|
|
||||||
$accountResult = requestCurl($this->baseUrl . 'api/Account/newAccount', $accountParams, 'POST', $header, 'json');
|
$accountResult = requestCurl($this->baseUrl . 'api/Account/newAccount', $accountParams, 'POST', $header, 'json');
|
||||||
|
|
||||||
|
if (is_numeric($accountResult)) {
|
||||||
|
$res = CompanyAccountModel::create([
|
||||||
|
'id' => $accountResult,
|
||||||
|
'tenantId' => 242,
|
||||||
if (!is_numeric($accountResult)) {
|
'userName' => $accountName,
|
||||||
// 如果创建账号失败,删除已创建的部门
|
'realName' => $accountRealName,
|
||||||
$this->deleteDepartment($accountResult);
|
'nickname' => $accountNickname,
|
||||||
return errorJson('创建账号失败:' . $accountResult['msg']);
|
'passwordMd5' => md5($accountPassword),
|
||||||
|
'passwordLocal' => localEncrypt($accountPassword),
|
||||||
|
'memo' => $accountMemo,
|
||||||
|
'accountType' => 11,
|
||||||
|
'departmentId' => $departmentResult,
|
||||||
|
'createTime' => time(),
|
||||||
|
'privilegeIds' => json_encode([])
|
||||||
|
]);
|
||||||
|
return successJson($res, '账号创建成功');
|
||||||
|
} else {
|
||||||
|
// 如果创建账号失败,删除已创建的部门
|
||||||
|
$this->deleteDepartment($accountResult);
|
||||||
|
return errorJson('创建账号失败:' . $accountResult['msg']);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return successJson($existingAccount, '账号获取成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
return successJson($accountResult,'账号创建成功');
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return errorJson('创建账号失败:' . $e->getMessage());
|
return errorJson('创建账号失败:' . $e->getMessage());
|
||||||
}
|
}
|
||||||
@@ -268,9 +293,9 @@ class AccountController extends BaseController
|
|||||||
// 获取授权token
|
// 获取授权token
|
||||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||||
if (empty($authorization)) {
|
if (empty($authorization)) {
|
||||||
if($isJob){
|
if ($isJob) {
|
||||||
return json_encode(['code'=>500,'msg'=>'缺少授权信息']);
|
return json_encode(['code' => 500, 'msg' => '缺少授权信息']);
|
||||||
}else{
|
} else {
|
||||||
return errorJson('缺少授权信息');
|
return errorJson('缺少授权信息');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -292,15 +317,15 @@ class AccountController extends BaseController
|
|||||||
$this->processDepartments($response);
|
$this->processDepartments($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($isJob){
|
if ($isJob) {
|
||||||
return json_encode(['code'=>200,'msg'=>'获取部门列表成功','data'=>$response]);
|
return json_encode(['code' => 200, 'msg' => '获取部门列表成功', 'data' => $response]);
|
||||||
}else{
|
} else {
|
||||||
return successJson($response, '获取部门列表成功');
|
return successJson($response, '获取部门列表成功');
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
if($isJob){
|
if ($isJob) {
|
||||||
return json_encode(['code'=>500,'msg'=>'获取部门列表失败:' . $e->getMessage()]);
|
return json_encode(['code' => 500, 'msg' => '获取部门列表失败:' . $e->getMessage()]);
|
||||||
}else{
|
} else {
|
||||||
return errorJson('获取部门列表失败:' . $e->getMessage());
|
return errorJson('获取部门列表失败:' . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -345,7 +370,7 @@ class AccountController extends BaseController
|
|||||||
$header = setHeader($headerData, $authorization, 'json');
|
$header = setHeader($headerData, $authorization, 'json');
|
||||||
|
|
||||||
// 发送请求创建部门
|
// 发送请求创建部门
|
||||||
$result = requestCurl($this->baseUrl . 'api/Department/createDepartment', $params, 'POST', $header,'json');
|
$result = requestCurl($this->baseUrl . 'api/Department/createDepartment', $params, 'POST', $header, 'json');
|
||||||
|
|
||||||
// 处理返回结果
|
// 处理返回结果
|
||||||
if (is_numeric($result)) {
|
if (is_numeric($result)) {
|
||||||
@@ -468,16 +493,15 @@ class AccountController extends BaseController
|
|||||||
// 发送删除请求
|
// 发送删除请求
|
||||||
$result = requestCurl($this->baseUrl . 'api/Department/del/' . $id, [], 'DELETE', $header);
|
$result = requestCurl($this->baseUrl . 'api/Department/del/' . $id, [], 'DELETE', $header);
|
||||||
|
|
||||||
if($result){
|
if ($result) {
|
||||||
return errorJson($result);
|
return errorJson($result);
|
||||||
}else{
|
} else {
|
||||||
// 删除本地数据库记录
|
// 删除本地数据库记录
|
||||||
$department->delete();
|
$department->delete();
|
||||||
return successJson([], '部门删除成功');
|
return successJson([], '部门删除成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return errorJson('删除部门失败:' . $e->getMessage());
|
return errorJson('删除部门失败:' . $e->getMessage());
|
||||||
}
|
}
|
||||||
@@ -521,7 +545,7 @@ class AccountController extends BaseController
|
|||||||
'parentId' => isset($item['parentId']) ? $item['parentId'] : 0,
|
'parentId' => isset($item['parentId']) ? $item['parentId'] : 0,
|
||||||
'tenantId' => isset($item['tenantId']) ? $item['tenantId'] : 0,
|
'tenantId' => isset($item['tenantId']) ? $item['tenantId'] : 0,
|
||||||
'privileges' => isset($item['privileges']) ? (is_array($item['privileges']) ? json_encode($item['privileges']) : $item['privileges']) : '',
|
'privileges' => isset($item['privileges']) ? (is_array($item['privileges']) ? json_encode($item['privileges']) : $item['privileges']) : '',
|
||||||
'createTime' => isset($item['createTime']) ? strtotime($item['createTime']) : 0,
|
'createTime' => isset($item['createTime']) ? strtotime($item['createTime']) : 0,
|
||||||
'lastUpdateTime' => isset($item['lastUpdateTime']) ? ($item['lastUpdateTime'] == '0001-01-01T00:00:00' ? 0 : strtotime($item['lastUpdateTime'])) : 0
|
'lastUpdateTime' => isset($item['lastUpdateTime']) ? ($item['lastUpdateTime'] == '0001-01-01T00:00:00' ? 0 : strtotime($item['lastUpdateTime'])) : 0
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -64,4 +64,9 @@ Route::group('v1/', function () {
|
|||||||
Route::post('update', 'app\\cunkebao\\controller\\ContentLibraryController@update'); // 更新内容库
|
Route::post('update', 'app\\cunkebao\\controller\\ContentLibraryController@update'); // 更新内容库
|
||||||
Route::delete('delete', 'app\\cunkebao\\controller\\ContentLibraryController@delete'); // 删除内容库
|
Route::delete('delete', 'app\\cunkebao\\controller\\ContentLibraryController@delete'); // 删除内容库
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 好友相关
|
||||||
|
Route::group('friend', function () {
|
||||||
|
Route::get('', 'app\\cunkebao\\controller\\FriendController@index'); // 获取好友列表
|
||||||
|
});
|
||||||
})->middleware(['jwt']);
|
})->middleware(['jwt']);
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
namespace app\cunkebao\controller\friend;
|
||||||
|
|
||||||
|
use app\common\model\Device as DeviceModel;
|
||||||
|
use app\common\model\DeviceUser as DeviceUserModel;
|
||||||
|
use app\common\model\WechatFriend;
|
||||||
|
use app\cunkebao\controller\BaseController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备管理控制器
|
||||||
|
*/
|
||||||
|
class GetFriendListV1Controller extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取好友列表
|
||||||
|
* @return \think\response\Json
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
|
||||||
|
$where = [];
|
||||||
|
if ($this->getUserInfo('isAdmin') == 1) {
|
||||||
|
$where['companyId'] = $this->getUserInfo('companyId');
|
||||||
|
} else {
|
||||||
|
$where['companyId'] = $this->getUserInfo('companyId');
|
||||||
|
$where['userId'] = $this->getUserInfo('id');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$data = WechatFriend::alias('wf')
|
||||||
|
->field(['wa1.nickname','wa1.avatar','wa1.alias','wa1.wechatId','wa2.nickname as ownerNickname','wa2.alias as ownerAlias','wf.createTime'])
|
||||||
|
->leftJoin('wechat_account wa1','wf.wechatId = wa1.wechatId')
|
||||||
|
->leftJoin('wechat_account wa2','wf.ownerWechatId = wa2.wechatId')
|
||||||
|
->where($where);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return json([
|
||||||
|
'code' => 200,
|
||||||
|
'msg' => '获取成功',
|
||||||
|
'data' => [
|
||||||
|
'list' => $data->select(),
|
||||||
|
'total' => $data->total(),
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return json([
|
||||||
|
'code' => $e->getCode(),
|
||||||
|
'msg' => $e->getMessage()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user