代码优化
This commit is contained in:
@@ -38,7 +38,7 @@ class AccountController extends BaseController
|
||||
$params = [
|
||||
'showNormalAccount' => $this->request->param('showNormalAccount', ''),
|
||||
'keyword' => $this->request->param('keyword', ''),
|
||||
'departmentId' => $this->request->param('companyId', ''),
|
||||
'departmentId' => $this->request->param('departmentId', ''),
|
||||
'pageIndex' => !empty($pageIndex) ? $pageIndex : $this->request->param('pageIndex', 0),
|
||||
'pageSize' => !empty($pageSize) ? $pageSize : $this->request->param('pageSize',20)
|
||||
];
|
||||
@@ -59,8 +59,9 @@ class AccountController extends BaseController
|
||||
}
|
||||
|
||||
if($isJob){
|
||||
return json_encode(['code'=>200,'msg'=>'获取公司账号列表成功']);
|
||||
return json_encode(['code'=>200,'msg'=>'获取公司账号列表成功','data'=>$response]);
|
||||
}else{
|
||||
|
||||
return successJson($response);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
@@ -91,7 +92,7 @@ class AccountController extends BaseController
|
||||
$realName = $this->request->param('realName', '');
|
||||
$nickname = $this->request->param('nickname', '');
|
||||
$memo = $this->request->param('memo', '');
|
||||
$companyId = $this->request->param('companyId', 0);
|
||||
$departmentId = $this->request->param('departmentId', 0);
|
||||
|
||||
// 参数验证
|
||||
if (empty($userName)) {
|
||||
@@ -110,7 +111,7 @@ class AccountController extends BaseController
|
||||
if (empty($realName)) {
|
||||
return errorJson('真实姓名不能为空');
|
||||
}
|
||||
if (empty($companyId)) {
|
||||
if (empty($departmentId)) {
|
||||
return errorJson('公司ID不能为空');
|
||||
}
|
||||
|
||||
@@ -121,8 +122,8 @@ class AccountController extends BaseController
|
||||
'realName' => $realName,
|
||||
'nickname' => $nickname,
|
||||
'memo' => $memo,
|
||||
'departmentId' => $companyId,
|
||||
'departmentIdArr' => empty($companyId) ? [914] : [914, $companyId]
|
||||
'departmentId' => $departmentId,
|
||||
'departmentIdArr' => empty($departmentId) ? [914] : [914, $departmentId]
|
||||
];
|
||||
|
||||
// 设置请求头
|
||||
@@ -148,12 +149,16 @@ class AccountController extends BaseController
|
||||
* 获取部门列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getDepartmentList()
|
||||
public function getDepartmentList($isJob = false)
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
return errorJson('缺少授权信息');
|
||||
if($isJob){
|
||||
return json_encode(['code'=>500,'msg'=>'缺少授权信息']);
|
||||
}else{
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -173,9 +178,17 @@ class AccountController extends BaseController
|
||||
$this->processDepartments($response);
|
||||
}
|
||||
|
||||
return successJson($response, '获取部门列表成功');
|
||||
if($isJob){
|
||||
return json_encode(['code'=>200,'msg'=>'获取部门列表成功','data'=>$response]);
|
||||
}else{
|
||||
return successJson($response, '获取部门列表成功');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return errorJson('获取部门列表失败:' . $e->getMessage());
|
||||
if($isJob){
|
||||
return json_encode(['code'=>500,'msg'=>'获取部门列表失败:' . $e->getMessage()]);
|
||||
}else{
|
||||
return errorJson('获取部门列表失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,7 +424,7 @@ class AccountController extends BaseController
|
||||
$deleteTime = isset($item['deleteTime']) ? strtotime($item['deleteTime']) : null;
|
||||
|
||||
$data = [
|
||||
'tenantId' => $item['id'],
|
||||
'id' => $item['id'],
|
||||
'accountType' => isset($item['accountType']) ? $item['accountType'] : 0,
|
||||
'status' => isset($item['status']) ? $item['status'] : 0,
|
||||
'tenantId' => isset($item['tenantId']) ? $item['tenantId'] : 0,
|
||||
@@ -425,9 +438,9 @@ class AccountController extends BaseController
|
||||
'creator' => isset($item['creator']) ? $item['creator'] : 0,
|
||||
'creatorUserName' => isset($item['creatorUserName']) ? $item['creatorUserName'] : '',
|
||||
'creatorRealName' => isset($item['creatorRealName']) ? $item['creatorRealName'] : '',
|
||||
'companyId' => isset($item['departmentId']) ? $item['departmentId'] : 0,
|
||||
'departmentId' => isset($item['departmentId']) ? $item['departmentId'] : 0,
|
||||
'departmentName' => isset($item['departmentName']) ? $item['departmentName'] : '',
|
||||
'privilegeIds' => isset($item['privilegeIds']) ? $item['privilegeIds'] : [],
|
||||
'privilegeIds' => isset($item['privilegeIds']) ? json_encode($item['privilegeIds']) : json_encode([]),
|
||||
'alive' => isset($item['alive']) ? $item['alive'] : false,
|
||||
'hasXiakeAccount' => isset($item['hasXiakeAccount']) ? $item['hasXiakeAccount'] : false,
|
||||
'isDeleted' => isset($item['isDeleted']) ? $item['isDeleted'] : false,
|
||||
@@ -435,7 +448,7 @@ class AccountController extends BaseController
|
||||
];
|
||||
|
||||
// 使用tenantId作为唯一性判断
|
||||
$account = CompanyAccountModel::where('tenantId', $item['id'])->find();
|
||||
$account = CompanyAccountModel::where('id', $item['id'])->find();
|
||||
if ($account) {
|
||||
$account->save($data);
|
||||
} else {
|
||||
|
||||
@@ -10,8 +10,13 @@ use Endroid\QrCode\ErrorCorrectionLevel;
|
||||
|
||||
class DeviceController extends BaseController
|
||||
{
|
||||
/************************ 设备管理相关接口 ************************/
|
||||
|
||||
/**
|
||||
* 获取设备列表
|
||||
* @param string $pageIndex 页码
|
||||
* @param string $pageSize 每页数量
|
||||
* @param bool $isJob 是否为定时任务调用
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getlist($pageIndex = '',$pageSize = '',$isJob = false)
|
||||
@@ -79,65 +84,6 @@ class DeviceController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存设备数据到数据库
|
||||
* @param array $item 设备数据
|
||||
*/
|
||||
private function saveDevice($item)
|
||||
{
|
||||
$data = [
|
||||
'id' => isset($item['id']) ? $item['id'] : '',
|
||||
'userName' => isset($item['userName']) ? $item['userName'] : '',
|
||||
'nickname' => isset($item['nickname']) ? $item['nickname'] : '',
|
||||
'realName' => isset($item['realName']) ? $item['realName'] : '',
|
||||
'groupName' => isset($item['groupName']) ? $item['groupName'] : '',
|
||||
'wechatAccounts' => isset($item['wechatAccounts']) ? json_encode($item['wechatAccounts']) : json_encode([]),
|
||||
'alive' => isset($item['alive']) ? $item['alive'] : false,
|
||||
'lastAliveTime' => isset($item['lastAliveTime']) ? $item['lastAliveTime'] : null,
|
||||
'companyId' => isset($item['tenantId']) ? $item['tenantId'] : 0,
|
||||
'groupId' => isset($item['groupId']) ? $item['groupId'] : 0,
|
||||
'currentAccountId' => isset($item['currentAccountId']) ? $item['currentAccountId'] : 0,
|
||||
'imei' => $item['imei'],
|
||||
'memo' => isset($item['memo']) ? $item['memo'] : '',
|
||||
'createTime' => isset($item['createTime']) ? $item['createTime'] : null,
|
||||
'isDeleted' => isset($item['isDeleted']) ? $item['isDeleted'] : false,
|
||||
'deletedAndStop' => isset($item['deletedAndStop']) ? $item['deletedAndStop'] : false,
|
||||
'deleteTime' => isset($item['deleteTime']) ? $item['deleteTime'] : null,
|
||||
'rooted' => isset($item['rooted']) ? $item['rooted'] : false,
|
||||
'xPosed' => isset($item['xPosed']) ? $item['xPosed'] : false,
|
||||
'brand' => isset($item['brand']) ? $item['brand'] : '',
|
||||
'model' => isset($item['model']) ? $item['model'] : '',
|
||||
'operatingSystem' => isset($item['operatingSystem']) ? $item['operatingSystem'] : '',
|
||||
'softwareVersion' => isset($item['softwareVersion']) ? $item['softwareVersion'] : '',
|
||||
'extra' => isset($item['extra']) ? json_encode($item['extra']) : json_encode([]),
|
||||
'phone' => isset($item['phone']) ? $item['phone'] : '',
|
||||
'lastUpdateTime' => isset($item['lastUpdateTime']) ? $item['lastUpdateTime'] : null
|
||||
];
|
||||
|
||||
// 使用imei作为唯一性判断
|
||||
$device = DeviceModel::where('id', $item['id'])->find();
|
||||
|
||||
if ($device) {
|
||||
$device->save($data);
|
||||
} else {
|
||||
|
||||
// autoLike:自动点赞
|
||||
// momentsSync:朋友圈同步
|
||||
// autoCustomerDev:自动开发客户
|
||||
// groupMessageDeliver:群消息推送
|
||||
// autoGroup:自动建群
|
||||
|
||||
$data['taskConfig'] = json_encode([
|
||||
'autoLike' => true,
|
||||
'momentsSync' => true,
|
||||
'autoCustomerDev' => true,
|
||||
'groupMessageDeliver' => true,
|
||||
'autoGroup' => true,
|
||||
]);
|
||||
DeviceModel::create($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成设备二维码
|
||||
* @param int $accountId 账号ID
|
||||
@@ -184,7 +130,68 @@ class DeviceController extends BaseController
|
||||
return errorJson('生成设备二维码失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************ 私有辅助方法 ************************/
|
||||
|
||||
/**
|
||||
* 保存设备数据到数据库
|
||||
* @param array $item 设备数据
|
||||
*/
|
||||
private function saveDevice($item)
|
||||
{
|
||||
$data = [
|
||||
'id' => isset($item['id']) ? $item['id'] : '',
|
||||
'userName' => isset($item['userName']) ? $item['userName'] : '',
|
||||
'nickname' => isset($item['nickname']) ? $item['nickname'] : '',
|
||||
'realName' => isset($item['realName']) ? $item['realName'] : '',
|
||||
'groupName' => isset($item['groupName']) ? $item['groupName'] : '',
|
||||
'wechatAccounts' => isset($item['wechatAccounts']) ? json_encode($item['wechatAccounts']) : json_encode([]),
|
||||
'alive' => isset($item['alive']) ? $item['alive'] : false,
|
||||
'lastAliveTime' => isset($item['lastAliveTime']) ? $item['lastAliveTime'] : null,
|
||||
'tenantId' => isset($item['tenantId']) ? $item['tenantId'] : 0,
|
||||
'groupId' => isset($item['groupId']) ? $item['groupId'] : 0,
|
||||
'currentAccountId' => isset($item['currentAccountId']) ? $item['currentAccountId'] : 0,
|
||||
'imei' => $item['imei'],
|
||||
'memo' => isset($item['memo']) ? $item['memo'] : '',
|
||||
'createTime' => isset($item['createTime']) ? $item['createTime'] : null,
|
||||
'isDeleted' => isset($item['isDeleted']) ? $item['isDeleted'] : false,
|
||||
'deletedAndStop' => isset($item['deletedAndStop']) ? $item['deletedAndStop'] : false,
|
||||
'deleteTime' => isset($item['deleteTime']) ? $item['deleteTime'] : null,
|
||||
'rooted' => isset($item['rooted']) ? $item['rooted'] : false,
|
||||
'xPosed' => isset($item['xPosed']) ? $item['xPosed'] : false,
|
||||
'brand' => isset($item['brand']) ? $item['brand'] : '',
|
||||
'model' => isset($item['model']) ? $item['model'] : '',
|
||||
'operatingSystem' => isset($item['operatingSystem']) ? $item['operatingSystem'] : '',
|
||||
'softwareVersion' => isset($item['softwareVersion']) ? $item['softwareVersion'] : '',
|
||||
'extra' => isset($item['extra']) ? json_encode($item['extra']) : json_encode([]),
|
||||
'phone' => isset($item['phone']) ? $item['phone'] : '',
|
||||
'lastUpdateTime' => isset($item['lastUpdateTime']) ? $item['lastUpdateTime'] : null
|
||||
];
|
||||
|
||||
// 使用imei作为唯一性判断
|
||||
$device = DeviceModel::where('id', $item['id'])->find();
|
||||
|
||||
if ($device) {
|
||||
$device->save($data);
|
||||
} else {
|
||||
|
||||
// autoLike:自动点赞
|
||||
// momentsSync:朋友圈同步
|
||||
// autoCustomerDev:自动开发客户
|
||||
// groupMessageDeliver:群消息推送
|
||||
// autoGroup:自动建群
|
||||
|
||||
$data['taskConfig'] = json_encode([
|
||||
'autoLike' => true,
|
||||
'momentsSync' => true,
|
||||
'autoCustomerDev' => true,
|
||||
'groupMessageDeliver' => true,
|
||||
'autoGroup' => true,
|
||||
]);
|
||||
DeviceModel::create($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成二维码图片(base64格式)
|
||||
* @param string $data 二维码数据
|
||||
|
||||
@@ -7,11 +7,16 @@ use think\facade\Request;
|
||||
|
||||
class FriendTaskController extends BaseController
|
||||
{
|
||||
/************************ 好友任务管理相关接口 ************************/
|
||||
|
||||
/**
|
||||
* 获取添加好友记录列表
|
||||
* @param int $pageIndex 页码
|
||||
* @param int $pageSize 每页数量
|
||||
* @param bool $isJob 是否为定时任务调用
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getlist($pageIndex,$pageSize,$isJob = false)
|
||||
public function getlist($pageIndex, $pageSize, $isJob = false)
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
@@ -113,6 +118,8 @@ class FriendTaskController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/************************ 私有辅助方法 ************************/
|
||||
|
||||
/**
|
||||
* 保存添加好友记录到数据库
|
||||
* @param array $item 添加好友记录数据
|
||||
|
||||
@@ -7,7 +7,8 @@ use think\facade\Request;
|
||||
|
||||
class MessageController extends BaseController
|
||||
{
|
||||
|
||||
/************************ 好友消息相关接口 ************************/
|
||||
|
||||
/**
|
||||
* 获取微信好友列表
|
||||
* @return \think\response\Json
|
||||
@@ -114,55 +115,65 @@ class MessageController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 保存消息记录到数据库
|
||||
* @param array $item 消息记录数据
|
||||
* 用户聊天记录
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
private function saveMessage($item)
|
||||
public function getMessageList()
|
||||
{
|
||||
// 检查消息是否已存在
|
||||
$exists = WechatMessageModel::where('id', $item['id']) ->find();
|
||||
|
||||
// 如果消息已存在,直接返回
|
||||
if ($exists) {
|
||||
return;
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
|
||||
// 将毫秒时间戳转换为秒级时间戳
|
||||
$createTime = isset($item['createTime']) ? strtotime($item['createTime']) : null;
|
||||
$deleteTime = !empty($item['isDeleted']) ? strtotime($item['deleteTime']) : null;
|
||||
$wechatTime = isset($item['wechatTime']) ? floor($item['wechatTime'] / 1000) : null;
|
||||
try {
|
||||
// 构建请求参数
|
||||
$params = [
|
||||
'keyword' => $this->request->param('keyword', ''),
|
||||
'msgType' => $this->request->param('msgType', ''),
|
||||
'accountId' => $this->request->param('accountId', ''),
|
||||
'count' => $this->request->param('count', 100),
|
||||
'messageId' => $this->request->param('messageId', ''),
|
||||
'olderData' => $this->request->param('olderData', true),
|
||||
'wechatAccountId' => $this->request->param('wechatAccountId', ''),
|
||||
'wechatFriendId' => $this->request->param('wechatFriendId', ''),
|
||||
'from' => $this->request->param('from', ''),
|
||||
'to' => $this->request->param('to', ''),
|
||||
'searchFrom' => $this->request->param('searchFrom', 'admin')
|
||||
];
|
||||
|
||||
$data = [
|
||||
'id' => $item['id'],
|
||||
'type' => 1,
|
||||
'accountId' => $item['accountId'],
|
||||
'content' => $item['content'],
|
||||
'createTime' => $createTime,
|
||||
'deleteTime' => $deleteTime,
|
||||
'isDeleted' => $item['isDeleted'] ?? false,
|
||||
'isSend' => $item['isSend'] ?? true,
|
||||
'msgId' => $item['msgId'],
|
||||
'msgSubType' => $item['msgSubType'] ?? 0,
|
||||
'msgSvrId' => $item['msgSvrId'] ?? '',
|
||||
'msgType' => $item['msgType'],
|
||||
'origin' => $item['origin'] ?? 0,
|
||||
'recallId' => $item['recallId'] ?? false,
|
||||
'sendStatus' => $item['sendStatus'] ?? 0,
|
||||
'synergyAccountId' => $item['synergyAccountId'] ?? 0,
|
||||
'tenantId' => $item['tenantId'],
|
||||
'wechatAccountId' => $item['wechatAccountId'],
|
||||
'wechatFriendId' => $item['wechatFriendId'],
|
||||
'wechatTime' => $wechatTime
|
||||
];
|
||||
// 参数验证
|
||||
if (empty($params['wechatAccountId'])) {
|
||||
return errorJson('微信账号ID不能为空');
|
||||
}
|
||||
if (empty($params['wechatFriendId'])) {
|
||||
return errorJson('好友ID不能为空');
|
||||
}
|
||||
|
||||
// 创建新记录
|
||||
WechatMessageModel::create($data);
|
||||
// 设置请求头
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization, 'json');
|
||||
|
||||
// 发送请求获取聊天记录
|
||||
$result = requestCurl($this->baseUrl . 'api/FriendMessage/searchMessage', $params, 'GET', $header, 'json');
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 保存数据到数据库
|
||||
if (!empty($response)) {
|
||||
foreach ($response as $item) {
|
||||
$this->saveMessage($item);
|
||||
}
|
||||
}
|
||||
|
||||
return successJson($response);
|
||||
} catch (\Exception $e) {
|
||||
return errorJson('获取聊天记录失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/************************ 群聊消息相关接口 ************************/
|
||||
|
||||
/**
|
||||
* 获取微信群聊列表
|
||||
* @return \think\response\Json
|
||||
@@ -268,8 +279,114 @@ class MessageController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取群聊消息列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getChatroomMessages()
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
// 构建请求参数
|
||||
$params = [
|
||||
'keyword' => $this->request->param('keyword', ''),
|
||||
'msgType' => $this->request->param('msgType', ''),
|
||||
'accountId' => $this->request->param('accountId', ''),
|
||||
'count' => $this->request->param('count', 100),
|
||||
'messageId' => $this->request->param('messageId', ''),
|
||||
'olderData' => $this->request->param('olderData', true),
|
||||
'wechatId' => $this->request->param('wechatId', ''),
|
||||
'wechatAccountId' => $this->request->param('wechatAccountId', ''),
|
||||
'wechatChatroomId' => $this->request->param('wechatChatroomId', ''),
|
||||
'from' => $this->request->param('from', strtotime(date('Y-m-d 00:00:00', strtotime('-1 days')))),
|
||||
'to' => $this->request->param('to', strtotime(date('Y-m-d 00:00:00'))),
|
||||
'searchFrom' => $this->request->param('searchFrom', 'admin')
|
||||
];
|
||||
|
||||
// 参数验证
|
||||
if (empty($params['wechatAccountId'])) {
|
||||
return errorJson('微信账号ID不能为空');
|
||||
}
|
||||
if (empty($params['wechatChatroomId'])) {
|
||||
return errorJson('群聊ID不能为空');
|
||||
}
|
||||
|
||||
// 设置请求头
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization, 'json');
|
||||
|
||||
// 发送请求获取群聊消息
|
||||
$result = requestCurl($this->baseUrl . 'api/ChatroomMessage/searchMessage', $params, 'GET', $header, 'json');
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 保存数据到数据库
|
||||
if (!empty($response)) {
|
||||
foreach ($response as $item) {
|
||||
$res = $this->saveChatroomMessage($item);
|
||||
if(!$res){
|
||||
return errorJson('保存群聊消息失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return successJson($response);
|
||||
} catch (\Exception $e) {
|
||||
return errorJson('获取群聊消息失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/************************ 私有辅助方法 ************************/
|
||||
|
||||
/**
|
||||
* 保存消息记录到数据库
|
||||
* @param array $item 消息记录数据
|
||||
*/
|
||||
private function saveMessage($item)
|
||||
{
|
||||
// 检查消息是否已存在
|
||||
$exists = WechatMessageModel::where('id', $item['id']) ->find();
|
||||
|
||||
// 如果消息已存在,直接返回
|
||||
if ($exists) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 将毫秒时间戳转换为秒级时间戳
|
||||
$createTime = isset($item['createTime']) ? strtotime($item['createTime']) : null;
|
||||
$deleteTime = !empty($item['isDeleted']) ? strtotime($item['deleteTime']) : null;
|
||||
$wechatTime = isset($item['wechatTime']) ? floor($item['wechatTime'] / 1000) : null;
|
||||
|
||||
$data = [
|
||||
'id' => $item['id'],
|
||||
'type' => 1,
|
||||
'accountId' => $item['accountId'],
|
||||
'content' => $item['content'],
|
||||
'createTime' => $createTime,
|
||||
'deleteTime' => $deleteTime,
|
||||
'isDeleted' => $item['isDeleted'] ?? false,
|
||||
'isSend' => $item['isSend'] ?? true,
|
||||
'msgId' => $item['msgId'],
|
||||
'msgSubType' => $item['msgSubType'] ?? 0,
|
||||
'msgSvrId' => $item['msgSvrId'] ?? '',
|
||||
'msgType' => $item['msgType'],
|
||||
'origin' => $item['origin'] ?? 0,
|
||||
'recallId' => $item['recallId'] ?? false,
|
||||
'sendStatus' => $item['sendStatus'] ?? 0,
|
||||
'synergyAccountId' => $item['synergyAccountId'] ?? 0,
|
||||
'tenantId' => $item['tenantId'],
|
||||
'wechatAccountId' => $item['wechatAccountId'],
|
||||
'wechatFriendId' => $item['wechatFriendId'],
|
||||
'wechatTime' => $wechatTime
|
||||
];
|
||||
|
||||
// 创建新记录
|
||||
WechatMessageModel::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存群聊消息记录到数据库
|
||||
@@ -354,126 +471,4 @@ class MessageController extends BaseController
|
||||
// 如果没有匹配到格式,则返回原始内容
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户聊天记录
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getMessageList()
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
|
||||
try {
|
||||
// 构建请求参数
|
||||
$params = [
|
||||
'keyword' => $this->request->param('keyword', ''),
|
||||
'msgType' => $this->request->param('msgType', ''),
|
||||
'accountId' => $this->request->param('accountId', ''),
|
||||
'count' => $this->request->param('count', 100),
|
||||
'messageId' => $this->request->param('messageId', ''),
|
||||
'olderData' => $this->request->param('olderData', true),
|
||||
'wechatAccountId' => $this->request->param('wechatAccountId', ''),
|
||||
'wechatFriendId' => $this->request->param('wechatFriendId', ''),
|
||||
'from' => $this->request->param('from', ''),
|
||||
'to' => $this->request->param('to', ''),
|
||||
'searchFrom' => $this->request->param('searchFrom', 'admin')
|
||||
];
|
||||
|
||||
// 参数验证
|
||||
if (empty($params['wechatAccountId'])) {
|
||||
return errorJson('微信账号ID不能为空');
|
||||
}
|
||||
if (empty($params['wechatFriendId'])) {
|
||||
return errorJson('好友ID不能为空');
|
||||
}
|
||||
|
||||
// 设置请求头
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization, 'json');
|
||||
|
||||
// 发送请求获取聊天记录
|
||||
$result = requestCurl($this->baseUrl . 'api/FriendMessage/searchMessage', $params, 'GET', $header, 'json');
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 保存数据到数据库
|
||||
if (!empty($response)) {
|
||||
foreach ($response as $item) {
|
||||
$this->saveMessage($item);
|
||||
}
|
||||
}
|
||||
|
||||
return successJson($response);
|
||||
} catch (\Exception $e) {
|
||||
return errorJson('获取聊天记录失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取群聊消息列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getChatroomMessages()
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
|
||||
try {
|
||||
// 构建请求参数
|
||||
$params = [
|
||||
'keyword' => $this->request->param('keyword', ''),
|
||||
'msgType' => $this->request->param('msgType', ''),
|
||||
'accountId' => $this->request->param('accountId', ''),
|
||||
'count' => $this->request->param('count', 100),
|
||||
'messageId' => $this->request->param('messageId', ''),
|
||||
'olderData' => $this->request->param('olderData', true),
|
||||
'wechatId' => $this->request->param('wechatId', ''),
|
||||
'wechatAccountId' => $this->request->param('wechatAccountId', ''),
|
||||
'wechatChatroomId' => $this->request->param('wechatChatroomId', ''),
|
||||
'from' => $this->request->param('from', strtotime(date('Y-m-d 00:00:00', strtotime('-1 days')))),
|
||||
'to' => $this->request->param('to', strtotime(date('Y-m-d 00:00:00'))),
|
||||
'searchFrom' => $this->request->param('searchFrom', 'admin')
|
||||
];
|
||||
|
||||
// 参数验证
|
||||
if (empty($params['wechatAccountId'])) {
|
||||
return errorJson('微信账号ID不能为空');
|
||||
}
|
||||
if (empty($params['wechatChatroomId'])) {
|
||||
return errorJson('群聊ID不能为空');
|
||||
}
|
||||
|
||||
// 设置请求头
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization, 'json');
|
||||
|
||||
// 发送请求获取群聊消息
|
||||
$result = requestCurl($this->baseUrl . 'api/ChatroomMessage/searchMessage', $params, 'GET', $header, 'json');
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 保存数据到数据库
|
||||
if (!empty($response)) {
|
||||
foreach ($response as $item) {
|
||||
$res = $this->saveChatroomMessage($item);
|
||||
if(!$res){
|
||||
return errorJson('保存群聊消息失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return successJson($response);
|
||||
} catch (\Exception $e) {
|
||||
return errorJson('获取群聊消息失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,8 @@ use think\facade\Request;
|
||||
|
||||
class MomentsController extends BaseController
|
||||
{
|
||||
/************************ 朋友圈发布相关接口 ************************/
|
||||
|
||||
/**
|
||||
* 发布朋友圈
|
||||
* @return \think\response\Json
|
||||
@@ -99,7 +101,9 @@ class MomentsController extends BaseController
|
||||
return errorJson('发布朋友圈失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************ 朋友圈任务管理相关接口 ************************/
|
||||
|
||||
/**
|
||||
* 获取朋友圈任务列表
|
||||
* @return \think\response\Json
|
||||
|
||||
@@ -13,11 +13,11 @@ class WechatChatroomController extends BaseController
|
||||
* 获取微信群聊列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getlist($pageIndex = '',$pageSize = '',$authorization = '',$isJob = false)
|
||||
public function getlist($pageIndex = '',$pageSize = '',$isJob = false)
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = !empty($authorization) ? $authorization : trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
if($isJob){
|
||||
return json_encode(['code'=>500,'msg'=>'缺少授权信息']);
|
||||
}else{
|
||||
|
||||
@@ -7,66 +7,20 @@ use app\api\model\WechatAccountModel;
|
||||
class WechatController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 保存微信账号数据到数据库
|
||||
* @param array $item 微信账号数据
|
||||
* 获取微信账号列表
|
||||
* @param string $pageIndex 页码
|
||||
* @param string $pageSize 每页大小
|
||||
* @param bool $isJob 是否为任务调用
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
private function saveWechatAccount($item)
|
||||
{
|
||||
$data = [
|
||||
'id' => $item['id'],
|
||||
'wechatId' => $item['wechatId'],
|
||||
'deviceAccountId' => $item['deviceAccountId'],
|
||||
'imei' => $item['imei'],
|
||||
'deviceMemo' => $item['deviceMemo'],
|
||||
'accountUserName' => $item['accountUserName'],
|
||||
'accountRealName' => $item['accountRealName'],
|
||||
'accountNickname' => $item['accountNickname'],
|
||||
'keFuAlive' => $item['keFuAlive'],
|
||||
'deviceAlive' => $item['deviceAlive'],
|
||||
'wechatAlive' => $item['wechatAlive'],
|
||||
'yesterdayMsgCount' => $item['yesterdayMsgCount'],
|
||||
'sevenDayMsgCount' => $item['sevenDayMsgCount'],
|
||||
'thirtyDayMsgCount' => $item['thirtyDayMsgCount'],
|
||||
'totalFriend' => $item['totalFriend'],
|
||||
'maleFriend' => $item['maleFriend'],
|
||||
'femaleFriend' => $item['femaleFriend'],
|
||||
'wechatGroupName' => $item['wechatGroupName'],
|
||||
'tenantId' => $item['tenantId'],
|
||||
'nickname' => $item['nickname'],
|
||||
'alias' => $item['alias'],
|
||||
'avatar' => $item['avatar'],
|
||||
'gender' => $item['gender'],
|
||||
'region' => $item['region'],
|
||||
'signature' => $item['signature'],
|
||||
'bindQQ' => $item['bindQQ'],
|
||||
'bindEmail' => $item['bindEmail'],
|
||||
'bindMobile' => $item['bindMobile'],
|
||||
'currentDeviceId' => $item['currentDeviceId'],
|
||||
'isDeleted' => $item['isDeleted'],
|
||||
'deleteTime' => $item['deleteTime'],
|
||||
'groupId' => $item['groupId'],
|
||||
'memo' => $item['memo'],
|
||||
'wechatVersion' => $item['wechatVersion'],
|
||||
'labels' => !empty($item['labels']) ? json_encode($item['labels']) : json_encode([]),
|
||||
'updateTime' => time()
|
||||
];
|
||||
|
||||
$account = WechatAccountModel::where('id', $item['id'])->find();
|
||||
if ($account) {
|
||||
$account->save($data);
|
||||
} else {
|
||||
WechatAccountModel::create($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function getlist($pageIndex = '',$pageSize = '',$isJob = false)
|
||||
public function getlist($pageIndex = '', $pageSize = '', $isJob = false)
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
if($isJob){
|
||||
return json_encode(['code'=>500,'msg'=>'缺少授权信息']);
|
||||
}else{
|
||||
if ($isJob) {
|
||||
return json_encode(['code' => 500, 'msg' => '缺少授权信息']);
|
||||
} else {
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
}
|
||||
@@ -99,17 +53,75 @@ class WechatController extends BaseController
|
||||
$this->saveWechatAccount($item);
|
||||
}
|
||||
}
|
||||
if($isJob){
|
||||
return json_encode(['code'=>200,'msg'=>'获取微信账号列表成功','data'=>$response]);
|
||||
}else{
|
||||
|
||||
if ($isJob) {
|
||||
return json_encode(['code' => 200, 'msg' => '获取微信账号列表成功', 'data' => $response]);
|
||||
} else {
|
||||
return successJson($response);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
if($isJob){
|
||||
return json_encode(['code'=>500,'msg'=>'获取微信账号列表失败:' . $e->getMessage()]);
|
||||
}else{
|
||||
if ($isJob) {
|
||||
return json_encode(['code' => 500, 'msg' => '获取微信账号列表失败:' . $e->getMessage()]);
|
||||
} else {
|
||||
return errorJson('获取微信账号列表失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存微信账号数据到数据库
|
||||
* @param array $item 微信账号数据
|
||||
*/
|
||||
private function saveWechatAccount($item)
|
||||
{
|
||||
$createTime = isset($item['createTime']) ? strtotime($item['createTime']) : 0;
|
||||
$deleteTime = !empty($item['isDeleted']) ? strtotime($item['deleteTime']) : 0;
|
||||
|
||||
$data = [
|
||||
'id' => $item['id'],
|
||||
'wechatId' => $item['wechatId'],
|
||||
'deviceAccountId' => $item['deviceAccountId'],
|
||||
'imei' => $item['imei'],
|
||||
'deviceMemo' => $item['deviceMemo'],
|
||||
'accountUserName' => $item['accountUserName'],
|
||||
'accountRealName' => $item['accountRealName'],
|
||||
'accountNickname' => $item['accountNickname'],
|
||||
'keFuAlive' => $item['keFuAlive'],
|
||||
'deviceAlive' => $item['deviceAlive'],
|
||||
'wechatAlive' => $item['wechatAlive'],
|
||||
'yesterdayMsgCount' => $item['yesterdayMsgCount'],
|
||||
'sevenDayMsgCount' => $item['sevenDayMsgCount'],
|
||||
'thirtyDayMsgCount' => $item['thirtyDayMsgCount'],
|
||||
'totalFriend' => $item['totalFriend'],
|
||||
'maleFriend' => $item['maleFriend'],
|
||||
'femaleFriend' => $item['femaleFriend'],
|
||||
'wechatGroupName' => $item['wechatGroupName'],
|
||||
'tenantId' => $item['tenantId'],
|
||||
'nickname' => $item['nickname'],
|
||||
'alias' => $item['alias'],
|
||||
'avatar' => $item['avatar'],
|
||||
'gender' => $item['gender'],
|
||||
'region' => $item['region'],
|
||||
'signature' => $item['signature'],
|
||||
'bindQQ' => $item['bindQQ'],
|
||||
'bindEmail' => $item['bindEmail'],
|
||||
'bindMobile' => $item['bindMobile'],
|
||||
'currentDeviceId' => $item['currentDeviceId'],
|
||||
'isDeleted' => $item['isDeleted'],
|
||||
'groupId' => $item['groupId'],
|
||||
'memo' => $item['memo'],
|
||||
'wechatVersion' => $item['wechatVersion'],
|
||||
'labels' => !empty($item['labels']) ? json_encode($item['labels']) : json_encode([]),
|
||||
'createTime' => $createTime,
|
||||
'deleteTime' => $deleteTime,
|
||||
'updateTime' => time()
|
||||
];
|
||||
|
||||
$account = WechatAccountModel::where('id', $item['id'])->find();
|
||||
if ($account) {
|
||||
$account->save($data);
|
||||
} else {
|
||||
WechatAccountModel::create($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,19 +10,23 @@ class WechatFriendController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取微信好友列表数据
|
||||
* @param string $pageIndex 页码
|
||||
* @param string $pageSize 每页大小
|
||||
* @param string $preFriendId 上一个好友ID
|
||||
* @param bool $isJob 是否为任务调用
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getlist($pageIndex = '',$pageSize = '',$preFriendId = '',$isJob = false)
|
||||
public function getlist($pageIndex = '', $pageSize = '', $preFriendId = '', $isJob = false)
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
if($isJob){
|
||||
return json_encode(['code'=>500,'msg'=>'缺少授权信息']);
|
||||
}else{
|
||||
return errorJson('缺少授权信息');
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
if ($isJob) {
|
||||
return json_encode(['code' => 500, 'msg' => '缺少授权信息']);
|
||||
} else {
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// 构建请求参数
|
||||
@@ -37,19 +41,20 @@ class WechatFriendController extends BaseController
|
||||
'groupId' => null,
|
||||
'isDeleted' => null,
|
||||
'isPass' => null,
|
||||
'keyword' => input('keyword', ''),
|
||||
'keyword' => input('keyword', ''),
|
||||
'labels' => '[]',
|
||||
'pageIndex' => !empty($pageIndex) ? $pageIndex : input('pageIndex', 0),
|
||||
'pageSize' => !empty($pageSize) ? $pageSize : input('pageSize', 20),
|
||||
'preFriendId' => !empty($preFriendId) ? $preFriendId : input('preFriendId', ''),
|
||||
'wechatAccountKeyword' => input('wechatAccountKeyword', '')
|
||||
];
|
||||
|
||||
// 设置请求头
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization);
|
||||
|
||||
// 发送请求获取好友列表
|
||||
$result = requestCurl($this->baseUrl . 'api/WechatFriend/friendlistData', $params, 'POST', $header,'json');
|
||||
$result = requestCurl($this->baseUrl . 'api/WechatFriend/friendlistData', $params, 'POST', $header, 'json');
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 保存数据到数据库
|
||||
@@ -59,17 +64,16 @@ class WechatFriendController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
if($isJob){
|
||||
return json_encode(['code'=>200,'msg'=>'success','data'=>$response]);
|
||||
}else{
|
||||
if ($isJob) {
|
||||
return json_encode(['code' => 200, 'msg' => 'success', 'data' => $response]);
|
||||
} else {
|
||||
return successJson($response);
|
||||
}
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
if($isJob){
|
||||
return json_encode(['code'=>500,'msg'=>'获取微信好友列表失败:' . $e->getMessage()]);
|
||||
}else{
|
||||
if ($isJob) {
|
||||
return json_encode(['code' => 500, 'msg' => '获取微信好友列表失败:' . $e->getMessage()]);
|
||||
} else {
|
||||
return errorJson('获取微信好友列表失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
@@ -117,12 +121,12 @@ class WechatFriendController extends BaseController
|
||||
'country' => $item['country'],
|
||||
'privince' => isset($item['privince']) ? $item['privince'] : '',
|
||||
'city' => isset($item['city']) ? $item['city'] : '',
|
||||
'createTime' =>isset($item['createTime']) ? $item['createTime'] : '',
|
||||
'createTime' => isset($item['createTime']) ? $item['createTime'] : '',
|
||||
'updateTime' => time()
|
||||
];
|
||||
|
||||
// 使用三个字段的组合作为唯一性判断
|
||||
$friend = WechatFriendModel::where('id',$item['id'])->find();
|
||||
// 使用ID作为唯一性判断
|
||||
$friend = WechatFriendModel::where('id', $item['id'])->find();
|
||||
|
||||
if ($friend) {
|
||||
$friend->save($data);
|
||||
|
||||
@@ -7,5 +7,5 @@ use think\Model;
|
||||
class CompanyAccountModel extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'company_account';
|
||||
protected $table = 's2_company_account';
|
||||
}
|
||||
@@ -6,5 +6,5 @@ use think\Model;
|
||||
|
||||
class CompanyModel extends Model {
|
||||
// 设置表名
|
||||
protected $name = 'company';
|
||||
protected $table = 's2_department';
|
||||
}
|
||||
@@ -6,5 +6,5 @@ use think\Model;
|
||||
|
||||
class DeviceModel extends Model {
|
||||
// 设置表名
|
||||
protected $name = 'device';
|
||||
protected $table = 's2_device';
|
||||
}
|
||||
@@ -7,5 +7,5 @@ use think\Model;
|
||||
class FriendTaskModel extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'friend_task';
|
||||
protected $table = 's2_friend_task';
|
||||
}
|
||||
@@ -7,5 +7,5 @@ use think\Model;
|
||||
class WechatAccountModel extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'wechat_account';
|
||||
protected $table = 's2_wechat_account';
|
||||
}
|
||||
@@ -7,5 +7,5 @@ use think\Model;
|
||||
class WechatChatroomMemberModel extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'wechat_chatroom_member';
|
||||
protected $table = 's2_wechat_chatroom_member';
|
||||
}
|
||||
@@ -7,5 +7,5 @@ use think\Model;
|
||||
class WechatChatroomModel extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'wechat_chatroom';
|
||||
protected $table = 's2_wechat_chatroom';
|
||||
}
|
||||
@@ -7,5 +7,5 @@ use think\Model;
|
||||
class WechatFriendModel extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'wechat_friend';
|
||||
protected $table = 's2_wechat_friend';
|
||||
}
|
||||
@@ -7,5 +7,5 @@ use think\Model;
|
||||
class WechatMessageModel extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'wechat_message';
|
||||
protected $table = 's2_wechat_message';
|
||||
}
|
||||
@@ -10,12 +10,13 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
return [
|
||||
'device:list' => 'app\command\DeviceListCommand', // 设备列表
|
||||
'wechatFriends:list' => 'app\command\WechatFriendCommand', // 微信好友列表
|
||||
'wechatChatroom:list' => 'app\command\WechatChatroomCommand', // 微信群列表
|
||||
'friendTask:list' => 'app\command\FriendTaskCommand', // 添加好友任务列表
|
||||
'wechatList:list' => 'app\command\WechatListCommand', // 微信客服列表
|
||||
'account:list' => 'app\command\AccountListCommand', // 公司账号列表
|
||||
'message:friendsList' => 'app\command\MessageFriendsListCommand', // 微信好友列表
|
||||
'message:chatroomList' => 'app\command\MessageChatroomListCommand', // 微信群聊列表
|
||||
'device:list' => 'app\command\DeviceListCommand', // 设备列表 √
|
||||
'wechatFriends:list' => 'app\command\WechatFriendCommand', // 微信好友列表 √
|
||||
'wechatChatroom:list' => 'app\command\WechatChatroomCommand', // 微信群列表 √
|
||||
'friendTask:list' => 'app\command\FriendTaskCommand', // 添加好友任务列表 √
|
||||
'wechatList:list' => 'app\command\WechatListCommand', // 微信客服列表 √
|
||||
'account:list' => 'app\command\AccountListCommand', // 公司账号列表 √
|
||||
'message:friendsList' => 'app\command\MessageFriendsListCommand', // 微信好友消息列表 √
|
||||
'message:chatroomList' => 'app\command\MessageChatroomListCommand', // 微信群聊消息列表 √
|
||||
'department:list' => 'app\command\DepartmentListCommand', // 部门列表 √
|
||||
];
|
||||
|
||||
57
Server/application/command/DepartmentListCommand.php
Normal file
57
Server/application/command/DepartmentListCommand.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Log;
|
||||
use think\Queue;
|
||||
use app\job\DepartmentListJob;
|
||||
|
||||
class DepartmentListCommand extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('department:list')
|
||||
->setDescription('获取部门列表,并根据分页自动处理下一页');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$output->writeln('开始处理部门列表任务...');
|
||||
|
||||
try {
|
||||
// 初始页码
|
||||
$pageIndex = 0;
|
||||
$pageSize = 100; // 每页获取100条记录
|
||||
|
||||
// 将第一页任务添加到队列
|
||||
$this->addToQueue($pageIndex, $pageSize);
|
||||
|
||||
$output->writeln('部门列表任务已添加到队列');
|
||||
} catch (\Exception $e) {
|
||||
Log::error('部门列表任务添加失败:' . $e->getMessage());
|
||||
$output->writeln('部门列表任务添加失败:' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加任务到队列
|
||||
* @param int $pageIndex 页码
|
||||
* @param int $pageSize 每页大小
|
||||
*/
|
||||
protected function addToQueue($pageIndex, $pageSize)
|
||||
{
|
||||
$data = [
|
||||
'pageIndex' => $pageIndex,
|
||||
'pageSize' => $pageSize
|
||||
];
|
||||
|
||||
// 添加到队列,设置任务名为 account_list
|
||||
Queue::push(DepartmentListJob::class, $data, 'department_list');
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ use think\console\Output;
|
||||
use think\facade\Log;
|
||||
use think\Queue;
|
||||
use app\job\FriendTaskJob;
|
||||
use think\facade\Cache;
|
||||
|
||||
class FriendTaskCommand extends Command
|
||||
{
|
||||
@@ -22,11 +23,13 @@ class FriendTaskCommand extends Command
|
||||
$output->writeln('开始处理添加好友任务...');
|
||||
|
||||
try {
|
||||
// 初始页码
|
||||
$pageIndex = 0;
|
||||
$pageSize = 100; // 每页获取100条记录
|
||||
// 从缓存获取初始页码,缓存10分钟有效
|
||||
$pageIndex = Cache::get('friendTaskPage', 21);
|
||||
$output->writeln('从缓存获取页码:' . $pageIndex);
|
||||
|
||||
// 将第一页任务添加到队列
|
||||
$pageSize = 1000; // 每页获取1000条记录
|
||||
|
||||
// 将任务添加到队列
|
||||
$this->addToQueue($pageIndex, $pageSize);
|
||||
|
||||
$output->writeln('添加好友任务已添加到队列');
|
||||
|
||||
@@ -8,6 +8,7 @@ use think\console\Output;
|
||||
use think\facade\Log;
|
||||
use think\Queue;
|
||||
use app\job\WechatChatroomJob;
|
||||
use think\facade\Cache;
|
||||
|
||||
class WechatChatroomCommand extends Command
|
||||
{
|
||||
@@ -22,11 +23,13 @@ class WechatChatroomCommand extends Command
|
||||
$output->writeln('开始处理微信聊天室列表任务...');
|
||||
|
||||
try {
|
||||
// 初始页码
|
||||
$pageIndex = 0;
|
||||
// 从缓存获取初始页码,缓存10分钟有效
|
||||
$pageIndex = Cache::get('chatroomPage', 0);
|
||||
$output->writeln('从缓存获取页码:' . $pageIndex);
|
||||
|
||||
$pageSize = 100; // 每页获取100条记录
|
||||
|
||||
// 将第一页任务添加到队列
|
||||
// 将任务添加到队列
|
||||
$this->addToQueue($pageIndex, $pageSize);
|
||||
|
||||
$output->writeln('微信聊天室列表任务已添加到队列');
|
||||
@@ -51,7 +54,7 @@ class WechatChatroomCommand extends Command
|
||||
'pageSize' => $pageSize
|
||||
];
|
||||
|
||||
// 添加到队列,设置任务名为 device_list
|
||||
// 添加到队列,设置任务名为 wechat_chatroom
|
||||
Queue::push(WechatChatroomJob::class, $data, 'wechat_chatroom');
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,8 @@ class WechatFriendCommand extends Command
|
||||
|
||||
try {
|
||||
// 从缓存获取初始页码和上次处理的好友ID,缓存10分钟有效
|
||||
$pageIndex = Cache::get('friendsPage', 0);
|
||||
$preFriendId = Cache::get('preFriendId', '');
|
||||
$pageIndex = Cache::get('friendsPage', 21);
|
||||
$preFriendId = Cache::get('preFriendId', 19426090);
|
||||
|
||||
$output->writeln('从缓存获取页码:' . $pageIndex . ',上次处理的好友ID:' . ($preFriendId ?: '无'));
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ class User extends Model
|
||||
* 数据表名
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'tk_users';
|
||||
protected $table = 'ck_users';
|
||||
|
||||
/**
|
||||
* 主键
|
||||
|
||||
@@ -10,7 +10,7 @@ use think\Model;
|
||||
class Conversation extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'coze_conversation';
|
||||
protected $table = 'ck_coze_conversation';
|
||||
|
||||
// 设置主键
|
||||
protected $pk = 'id';
|
||||
|
||||
@@ -6,7 +6,7 @@ use think\Model;
|
||||
|
||||
class Message extends Model
|
||||
{
|
||||
protected $name = 'coze_message';
|
||||
protected $table = 'ck_coze_message';
|
||||
protected $pk = 'id';
|
||||
|
||||
// 自动写入时间戳
|
||||
|
||||
@@ -10,7 +10,7 @@ use think\Model;
|
||||
class Workspace extends Model
|
||||
{
|
||||
// 设置当前模型对应的完整数据表名称
|
||||
protected $name = 'coze_workspace';
|
||||
protected $table = 'ck_coze_workspace';
|
||||
|
||||
// 设置主键
|
||||
protected $pk = 'id';
|
||||
|
||||
@@ -161,6 +161,9 @@ class WorkbenchController extends Controller
|
||||
'momentsSync' => function($query) {
|
||||
$query->field('workbenchId,syncInterval,syncCount,syncType,startTime,endTime,accountType,devices,contentLibraries');
|
||||
},
|
||||
'user' => function($query) {
|
||||
$query->field('username');
|
||||
},
|
||||
// 'groupPush' => function($query) {
|
||||
// $query->field('workbenchId,pushInterval,pushContent,pushTime,devices,targetGroups');
|
||||
// },
|
||||
|
||||
25
Server/application/cunkebao/model/User.php
Normal file
25
Server/application/cunkebao/model/User.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace app\cunkebao\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 用户模型
|
||||
*/
|
||||
class User extends Model
|
||||
{
|
||||
protected $pk = 'id';
|
||||
protected $name = 'users';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
|
||||
// 定义关联的工作台
|
||||
public function workbench()
|
||||
{
|
||||
return $this->hasMany('Workbench', 'id', 'userId');
|
||||
}
|
||||
}
|
||||
@@ -55,4 +55,9 @@ class Workbench extends Model
|
||||
return $this->hasOne('WorkbenchGroupCreate', 'workbenchId', 'id');
|
||||
}
|
||||
|
||||
// 用户关联
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne('User', 'id', 'userId');
|
||||
}
|
||||
}
|
||||
115
Server/application/job/DepartmentListJob.php
Normal file
115
Server/application/job/DepartmentListJob.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace app\job;
|
||||
|
||||
use think\queue\Job;
|
||||
use think\facade\Log;
|
||||
use think\Queue;
|
||||
use think\facade\Config;
|
||||
use app\api\controller\AccountController;
|
||||
|
||||
class DepartmentListJob
|
||||
{
|
||||
/**
|
||||
* 队列任务处理
|
||||
* @param Job $job 队列任务
|
||||
* @param array $data 任务数据
|
||||
* @return void
|
||||
*/
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
try {
|
||||
// 如果任务执行成功后删除任务
|
||||
if ($this->processDepartmentList($data, $job->attempts())) {
|
||||
$job->delete();
|
||||
Log::info('部门列表任务执行成功,页码:' . $data['pageIndex']);
|
||||
} else {
|
||||
if ($job->attempts() > 3) {
|
||||
// 超过重试次数,删除任务
|
||||
Log::error('部门列表任务执行失败,已超过重试次数,页码:' . $data['pageIndex']);
|
||||
$job->delete();
|
||||
} else {
|
||||
// 任务失败,重新放回队列
|
||||
Log::warning('部门列表任务执行失败,重试次数:' . $job->attempts() . ',页码:' . $data['pageIndex']);
|
||||
$job->release(Config::get('queue.failed_delay', 10));
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 出现异常,记录日志
|
||||
Log::error('部门列表任务异常:' . $e->getMessage());
|
||||
if ($job->attempts() > 3) {
|
||||
$job->delete();
|
||||
} else {
|
||||
$job->release(Config::get('queue.failed_delay', 10));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理部门列表获取
|
||||
* @param array $data 任务数据
|
||||
* @param int $attempts 重试次数
|
||||
* @return bool
|
||||
*/
|
||||
protected function processDepartmentList($data, $attempts)
|
||||
{
|
||||
// 获取参数
|
||||
$pageIndex = isset($data['pageIndex']) ? $data['pageIndex'] : 0;
|
||||
$pageSize = isset($data['pageSize']) ? $data['pageSize'] : 100;
|
||||
|
||||
Log::info('开始获取部门列表,页码:' . $pageIndex . ',页大小:' . $pageSize);
|
||||
|
||||
// 实例化控制器
|
||||
$accountController = new AccountController();
|
||||
|
||||
// 构建请求参数
|
||||
$params = [
|
||||
'pageIndex' => $pageIndex,
|
||||
'pageSize' => $pageSize
|
||||
];
|
||||
|
||||
// 设置请求信息
|
||||
$request = request();
|
||||
$request->withGet($params);
|
||||
|
||||
// 调用公司账号列表获取方法
|
||||
$result = $accountController->getDepartmentList(true);
|
||||
$response = json_decode($result,true);
|
||||
|
||||
|
||||
// 判断是否成功
|
||||
if ($response['code'] == 200) {
|
||||
$data = $response['data'];
|
||||
|
||||
// 判断是否有下一页
|
||||
if (!empty($data) && count($data['results']) > 0) {
|
||||
// 有下一页,将下一页任务添加到队列
|
||||
$nextPageIndex = $pageIndex + 1;
|
||||
$this->addNextPageToQueue($nextPageIndex, $pageSize);
|
||||
Log::info('添加下一页任务到队列,页码:' . $nextPageIndex);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
$errorMsg = isset($response['msg']) ? $response['msg'] : '未知错误';
|
||||
Log::error('获取部门列表失败:' . $errorMsg);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加下一页任务到队列
|
||||
* @param int $pageIndex 页码
|
||||
* @param int $pageSize 每页大小
|
||||
*/
|
||||
protected function addNextPageToQueue($pageIndex, $pageSize)
|
||||
{
|
||||
$data = [
|
||||
'pageIndex' => $pageIndex,
|
||||
'pageSize' => $pageSize
|
||||
];
|
||||
|
||||
// 添加到队列,设置任务名为 account_list
|
||||
Queue::push(self::class, $data, 'department_list');
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use think\queue\Job;
|
||||
use think\facade\Log;
|
||||
use think\Queue;
|
||||
use think\facade\Config;
|
||||
use think\facade\Cache;
|
||||
use app\api\controller\FriendTaskController;
|
||||
|
||||
class FriendTaskJob
|
||||
@@ -73,9 +74,8 @@ class FriendTaskJob
|
||||
$request->withGet($params);
|
||||
|
||||
// 调用添加好友任务获取方法
|
||||
$result = $friendTaskController->getlist($pageIndex,$pageSize,true);
|
||||
$response = json_decode($result,true);
|
||||
|
||||
$result = $friendTaskController->getlist($pageIndex, $pageSize, true);
|
||||
$response = json_decode($result, true);
|
||||
|
||||
// 判断是否成功
|
||||
if ($response['code'] == 200) {
|
||||
@@ -83,10 +83,18 @@ class FriendTaskJob
|
||||
|
||||
// 判断是否有下一页
|
||||
if (!empty($data) && count($data['results']) > 0) {
|
||||
// 更新缓存中的页码,设置10分钟过期
|
||||
Cache::set('friendTaskPage', $pageIndex + 1, 600);
|
||||
Log::info('更新缓存,下一页页码:' . ($pageIndex + 1) . ',缓存时间:10分钟');
|
||||
|
||||
// 有下一页,将下一页任务添加到队列
|
||||
$nextPageIndex = $pageIndex + 1;
|
||||
$this->addNextPageToQueue($nextPageIndex, $pageSize);
|
||||
Log::info('添加下一页任务到队列,页码:' . $nextPageIndex);
|
||||
} else {
|
||||
// 没有下一页,重置缓存,设置10分钟过期
|
||||
Cache::set('friendTaskPage', 0, 600);
|
||||
Log::info('获取完成,重置缓存,缓存时间:10分钟');
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -6,6 +6,7 @@ use think\queue\Job;
|
||||
use think\facade\Log;
|
||||
use think\Queue;
|
||||
use think\facade\Config;
|
||||
use think\facade\Cache;
|
||||
use app\api\controller\WechatChatroomController;
|
||||
|
||||
class WechatChatroomJob
|
||||
@@ -74,7 +75,6 @@ class WechatChatroomJob
|
||||
|
||||
// 调用设备列表获取方法
|
||||
$result = $wechatChatroomController->getlist($pageIndex,$pageSize,true);
|
||||
|
||||
$response = json_decode($result,true);
|
||||
|
||||
// 判断是否成功
|
||||
@@ -83,10 +83,18 @@ class WechatChatroomJob
|
||||
|
||||
// 判断是否有下一页
|
||||
if (!empty($data) && count($data['results']) > 0) {
|
||||
// 更新缓存中的页码,设置10分钟过期
|
||||
Cache::set('chatroomPage', $pageIndex + 1, 600);
|
||||
Log::info('更新缓存,下一页页码:' . ($pageIndex + 1) . ',缓存时间:10分钟');
|
||||
|
||||
// 有下一页,将下一页任务添加到队列
|
||||
$nextPageIndex = $pageIndex + 1;
|
||||
$this->addNextPageToQueue($nextPageIndex, $pageSize);
|
||||
Log::info('添加下一页任务到队列,页码:' . $nextPageIndex);
|
||||
} else {
|
||||
// 没有下一页,重置缓存,设置10分钟过期
|
||||
Cache::set('chatroomPage', 0, 600);
|
||||
Log::info('获取完成,重置缓存,缓存时间:10分钟');
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -55,7 +55,7 @@ class WechatListJob
|
||||
{
|
||||
// 获取参数
|
||||
$pageIndex = isset($data['pageIndex']) ? $data['pageIndex'] : 0;
|
||||
$pageSize = isset($data['pageSize']) ? $data['pageSize'] : 100;
|
||||
$pageSize = isset($data['pageSize']) ? $data['pageSize'] : 1000;
|
||||
|
||||
Log::info('开始获取微信客服列表,页码:' . $pageIndex . ',页大小:' . $pageSize);
|
||||
|
||||
|
||||
@@ -35,10 +35,10 @@ class BaseController extends Api
|
||||
$device = Cache::get($cacheKey);
|
||||
// 如果缓存不存在,则从数据库获取
|
||||
if (!$device) {
|
||||
$device = Db::name('device_user')
|
||||
$device = Db::table('ck_device_user')
|
||||
->alias('du')
|
||||
->join('device d', 'd.id = du.deviceId','left')
|
||||
->join('wechat_account wa', 'd.id = wa.currentDeviceId','left')
|
||||
->join('s2_device d', 'd.id = du.deviceId','left')
|
||||
->join('s2_wechat_account wa', 'd.id = wa.currentDeviceId','left')
|
||||
->where([
|
||||
'du.userId' => $this->userInfo['id'],
|
||||
'du.companyId' => $this->userInfo['companyId']
|
||||
|
||||
@@ -54,11 +54,11 @@ class CustomerController extends Api
|
||||
// }
|
||||
|
||||
// 构建查询
|
||||
$query = Db::name('device_user')
|
||||
$query = Db::table('ck_device_user')
|
||||
->alias('du')
|
||||
->join('device d', 'd.id = du.deviceId','left')
|
||||
->join('wechat_account wa', 'wa.imei = d.imei','left')
|
||||
->join('wechat_friend wf', 'wf.ownerWechatId = wa.wechatId','left')
|
||||
->join('s2_device d', 'd.id = du.deviceId','left')
|
||||
->join('s2_wechat_account wa', 'wa.imei = d.imei','left')
|
||||
->join('s2_wechat_friend wf', 'wf.ownerWechatId = wa.wechatId','left')
|
||||
->where($where)
|
||||
->field('d.id as deviceId,d.imei,wf.*')
|
||||
->group('wf.wechatId'); // 防止重复数据
|
||||
|
||||
@@ -78,7 +78,7 @@ class SystemConfigController extends BaseController
|
||||
|
||||
|
||||
// 更新数据库
|
||||
$result = Db::name('device')
|
||||
$result = Db::table('s2_device')
|
||||
->where('id', $deviceId)
|
||||
->update([
|
||||
'taskConfig' => $taskConfig,
|
||||
|
||||
@@ -6,7 +6,7 @@ use think\Model;
|
||||
|
||||
class FlowPackageModel extends Model
|
||||
{
|
||||
protected $name = 'flow_package';
|
||||
protected $table = 'ck_flow_package';
|
||||
|
||||
// 定义字段自动转换
|
||||
protected $type = [
|
||||
|
||||
@@ -10,7 +10,7 @@ use think\Model;
|
||||
class FlowPackageOrderModel extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'flow_package_order';
|
||||
protected $table = 'ck_flow_package_order';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
|
||||
@@ -6,7 +6,7 @@ use think\Model;
|
||||
|
||||
class UserFlowPackageModel extends Model
|
||||
{
|
||||
protected $name = 'user_flow_package';
|
||||
protected $table = 'ck_user_flow_package';
|
||||
/**
|
||||
* 获取用户当前有效的流量套餐
|
||||
*
|
||||
|
||||
@@ -6,6 +6,6 @@ use think\Model;
|
||||
|
||||
class WechatFriendModel extends Model
|
||||
{
|
||||
protected $name = 'wechat_friend';
|
||||
protected $table = 'ck_wechat_friend';
|
||||
|
||||
}
|
||||
@@ -6,6 +6,6 @@ use think\Model;
|
||||
|
||||
class WechatMessageModel extends Model
|
||||
{
|
||||
protected $name = 'wechat_message';
|
||||
protected $table = 'ck_wechat_message';
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user