代码优化
This commit is contained in:
@@ -60,10 +60,22 @@ class AccountController extends BaseController
|
||||
$result = requestCurl($this->baseUrl . 'api/Account/myTenantPageAccounts', $params, 'GET', $header);
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 确保 response 是数组格式
|
||||
if (!is_array($response)) {
|
||||
$response = [];
|
||||
}
|
||||
|
||||
// 确保 results 字段存在且是数组
|
||||
if (!isset($response['results']) || !is_array($response['results'])) {
|
||||
$response['results'] = [];
|
||||
}
|
||||
|
||||
// 保存数据到数据库
|
||||
if (!empty($response['results'])) {
|
||||
foreach ($response['results'] as $item) {
|
||||
$this->saveAccount($item);
|
||||
if (is_array($item)) {
|
||||
$this->saveAccount($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,11 +41,18 @@ class AllotRuleController extends BaseController
|
||||
$result = requestCurl($this->baseUrl . 'api/AllotRule/all', [], 'GET', $header);
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 确保 response 是数组格式
|
||||
if (!is_array($response)) {
|
||||
$response = [];
|
||||
}
|
||||
|
||||
// 保存数据到数据库
|
||||
if (!empty($response)) {
|
||||
AllotRuleModel::where('1=1')->update(['isDel' => 1]);
|
||||
foreach ($response as $item) {
|
||||
$this->saveAllotRule($item);
|
||||
if (is_array($item)) {
|
||||
$this->saveAllotRule($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,10 +68,22 @@ class CallRecordingController extends BaseController
|
||||
$result = requestCurl($this->baseUrl . 'api/CallRecording/list', $params, 'GET', $header);
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 确保 response 是数组格式
|
||||
if (!is_array($response)) {
|
||||
$response = [];
|
||||
}
|
||||
|
||||
// 确保 results 字段存在且是数组
|
||||
if (!isset($response['results']) || !is_array($response['results'])) {
|
||||
$response['results'] = [];
|
||||
}
|
||||
|
||||
// 保存数据到数据库
|
||||
if (!empty($response['results'])) {
|
||||
foreach ($response['results'] as $item) {
|
||||
$this->saveCallRecording($item);
|
||||
if (is_array($item)) {
|
||||
$this->saveCallRecording($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,10 +74,22 @@ class DeviceController extends BaseController
|
||||
$result = requestCurl($this->baseUrl . 'api/device/pageResult', $params, 'GET', $header);
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 确保 response 是数组格式
|
||||
if (!is_array($response)) {
|
||||
$response = [];
|
||||
}
|
||||
|
||||
// 确保 results 字段存在且是数组
|
||||
if (!isset($response['results']) || !is_array($response['results'])) {
|
||||
$response['results'] = [];
|
||||
}
|
||||
|
||||
// 保存数据到数据库
|
||||
if (!empty($response['results'])) {
|
||||
foreach ($response['results'] as $item) {
|
||||
$this->saveDevice($item);
|
||||
if (is_array($item)) {
|
||||
$this->saveDevice($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,10 +479,17 @@ class DeviceController extends BaseController
|
||||
// 发送请求
|
||||
$result = requestCurl($this->baseUrl . 'api/DeviceGroup/list', [], 'GET', $header,'json');
|
||||
$response = handleApiResponse($result);
|
||||
// 确保 response 是数组格式
|
||||
if (!is_array($response)) {
|
||||
$response = [];
|
||||
}
|
||||
|
||||
// 保存数据到数据库
|
||||
if (!empty($response)) {
|
||||
foreach ($response as $item) {
|
||||
$this->saveDeviceGroup($item);
|
||||
if (is_array($item)) {
|
||||
$this->saveDeviceGroup($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
if($isInner){
|
||||
|
||||
@@ -46,11 +46,22 @@ class FriendTaskController extends BaseController
|
||||
$result = requestCurl($this->baseUrl . 'api/AddFriendByPhoneTask/list', $params, 'GET', $header,'json');
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 确保 response 是数组格式
|
||||
if (!is_array($response)) {
|
||||
$response = [];
|
||||
}
|
||||
|
||||
// 确保 results 字段存在且是数组
|
||||
if (!isset($response['results']) || !is_array($response['results'])) {
|
||||
$response['results'] = [];
|
||||
}
|
||||
|
||||
// 保存数据到数据库
|
||||
if (!empty($response['results'])) {
|
||||
foreach ($response['results'] as $item) {
|
||||
$this->saveFriendTask($item);
|
||||
if (is_array($item)) {
|
||||
$this->saveFriendTask($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
if($isInner){
|
||||
|
||||
@@ -53,13 +53,25 @@ class WechatChatroomController extends BaseController
|
||||
$result = requestCurl($this->baseUrl . 'api/WechatChatroom/pagelist', $params, 'GET', $header,'json');
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 确保 response 是数组格式
|
||||
if (!is_array($response)) {
|
||||
$response = [];
|
||||
}
|
||||
|
||||
// 确保 results 字段存在且是数组
|
||||
if (!isset($response['results']) || !is_array($response['results'])) {
|
||||
$response['results'] = [];
|
||||
}
|
||||
|
||||
// 保存数据到数据库
|
||||
if (!empty($response['results'])) {
|
||||
$isUpdate = false;
|
||||
foreach ($response['results'] as $item) {
|
||||
$updated = $this->saveChatroom($item);
|
||||
if($updated && $isDel == 0){
|
||||
$isUpdate = true;
|
||||
if (is_array($item)) {
|
||||
$updated = $this->saveChatroom($item);
|
||||
if($updated && $isDel == 0){
|
||||
$isUpdate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -174,10 +186,17 @@ class WechatChatroomController extends BaseController
|
||||
$result = requestCurl($this->baseUrl . 'api/WechatChatroom/listChatroomMember', $params, 'GET', $header);
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 确保 response 是数组格式
|
||||
if (!is_array($response)) {
|
||||
$response = [];
|
||||
}
|
||||
|
||||
// 保存数据到数据库
|
||||
if (!empty($response)) {
|
||||
foreach ($response as $item) {
|
||||
$this->saveChatroomMember($item, $chatroomId);
|
||||
if (is_array($item)) {
|
||||
$this->saveChatroomMember($item, $chatroomId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,10 +50,23 @@ class WechatController extends BaseController
|
||||
// 发送请求获取基本信息
|
||||
$result = requestCurl($this->baseUrl . 'api/WechatAccount/list', $params, 'GET', $header);
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 确保 response 是数组格式
|
||||
if (!is_array($response)) {
|
||||
$response = [];
|
||||
}
|
||||
|
||||
// 确保 results 字段存在且是数组
|
||||
if (!isset($response['results']) || !is_array($response['results'])) {
|
||||
$response['results'] = [];
|
||||
}
|
||||
|
||||
// 保存基本数据到数据库
|
||||
if (!empty($response['results'])) {
|
||||
foreach ($response['results'] as $item) {
|
||||
$this->saveWechatAccount($item);
|
||||
if (is_array($item)) {
|
||||
$this->saveWechatAccount($item);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取并更新微信账号状态信息
|
||||
|
||||
@@ -76,13 +76,20 @@ class WechatFriendController extends BaseController
|
||||
$result = requestCurl($this->baseUrl . 'api/WechatFriend/friendlistData', $params, 'POST', $header, 'json');
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 确保 response 是数组格式
|
||||
if (!is_array($response)) {
|
||||
$response = [];
|
||||
}
|
||||
|
||||
// 保存数据到数据库
|
||||
if (is_array($response)) {
|
||||
if (!empty($response)) {
|
||||
$isUpdate = false;
|
||||
foreach ($response as $item) {
|
||||
$updated = $this->saveFriend($item);
|
||||
if($updated && $isDel == 0){
|
||||
$isUpdate = true;
|
||||
if (is_array($item)) {
|
||||
$updated = $this->saveFriend($item);
|
||||
if($updated && $isDel == 0){
|
||||
$isUpdate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,14 +82,24 @@ class MessageFriendsListJob
|
||||
// 调用添加好友任务获取方法
|
||||
$result = $messageController->getFriendsList($pageIndex,$pageSize,true);
|
||||
$response = json_decode($result,true);
|
||||
|
||||
// 确保 response 是数组格式
|
||||
if (!is_array($response)) {
|
||||
$response = [];
|
||||
}
|
||||
|
||||
|
||||
// 判断是否成功
|
||||
if ($response['code'] == 200) {
|
||||
$data = $response['data'];
|
||||
if (isset($response['code']) && $response['code'] == 200) {
|
||||
$data = isset($response['data']) ? $response['data'] : [];
|
||||
|
||||
// 确保 data 是数组格式
|
||||
if (!is_array($data)) {
|
||||
$data = [];
|
||||
}
|
||||
|
||||
// 判断是否有下一页,且未超过最大同步页数
|
||||
if (!empty($data) && count($data) > 0) {
|
||||
if (!empty($data) && is_array($data) && count($data) > 0) {
|
||||
$nextPageIndex = $pageIndex + 1;
|
||||
// 检查是否超过最大同步页数
|
||||
if ($nextPageIndex < self::MAX_SYNC_PAGES) {
|
||||
|
||||
@@ -28,7 +28,7 @@ return [
|
||||
'command' => 'wechatFriends:list',
|
||||
'schedule' => '*/1 * * * *', // 每1分钟
|
||||
'options' => ['--isDel=0'],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'crontab_wechatFriends_active.log',
|
||||
],
|
||||
@@ -39,7 +39,7 @@ return [
|
||||
'command' => 'friendTask:list',
|
||||
'schedule' => '*/1 * * * *', // 每1分钟
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'crontab_friendTask.log',
|
||||
],
|
||||
@@ -50,7 +50,7 @@ return [
|
||||
'command' => 'message:friendsList',
|
||||
'schedule' => '*/1 * * * *', // 每1分钟
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'crontab_messageFriends.log',
|
||||
],
|
||||
@@ -72,7 +72,7 @@ return [
|
||||
'command' => 'kf:notice',
|
||||
'schedule' => '*/1 * * * *', // 每1分钟
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'kf_notice.log',
|
||||
],
|
||||
@@ -87,7 +87,7 @@ return [
|
||||
'command' => 'device:list',
|
||||
'schedule' => '*/5 * * * *', // 每5分钟
|
||||
'options' => ['--isDel=0'],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'crontab_device_active.log',
|
||||
],
|
||||
@@ -98,7 +98,7 @@ return [
|
||||
'command' => 'wechatChatroom:list',
|
||||
'schedule' => '*/5 * * * *', // 每5分钟
|
||||
'options' => ['--isDel=0'],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'crontab_wechatChatroom_active.log',
|
||||
],
|
||||
@@ -109,7 +109,7 @@ return [
|
||||
'command' => 'groupFriends:list',
|
||||
'schedule' => '*/5 * * * *', // 每5分钟
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'crontab_groupFriends.log',
|
||||
],
|
||||
@@ -120,7 +120,7 @@ return [
|
||||
'command' => 'wechatList:list',
|
||||
'schedule' => '*/5 * * * *', // 每5分钟
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'crontab_wechatList.log',
|
||||
],
|
||||
@@ -131,7 +131,7 @@ return [
|
||||
'command' => 'account:list',
|
||||
'schedule' => '*/5 * * * *', // 每5分钟
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'crontab_account.log',
|
||||
],
|
||||
@@ -153,7 +153,7 @@ return [
|
||||
'command' => 'workbench:autoLike',
|
||||
'schedule' => '*/6 * * * *', // 每6分钟
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'crontab_workbench_autoLike.log',
|
||||
],
|
||||
@@ -164,7 +164,7 @@ return [
|
||||
'command' => 'workbench:groupCreate',
|
||||
'schedule' => '*/5 * * * *', // 每5分钟
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'workbench_groupCreate.log',
|
||||
],
|
||||
@@ -175,7 +175,7 @@ return [
|
||||
'command' => 'workbench:import-contact',
|
||||
'schedule' => '*/5 * * * *', // 每5分钟
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'import_contact.log',
|
||||
],
|
||||
@@ -190,7 +190,7 @@ return [
|
||||
'command' => 'sync:wechatData',
|
||||
'schedule' => '*/2 * * * *', // 每2分钟
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'sync_wechat_data.log',
|
||||
],
|
||||
@@ -201,7 +201,7 @@ return [
|
||||
'command' => 'workbench:trafficDistribute',
|
||||
'schedule' => '*/2 * * * *', // 每2分钟
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'traffic_distribute.log',
|
||||
],
|
||||
@@ -212,7 +212,7 @@ return [
|
||||
'command' => 'workbench:moments',
|
||||
'schedule' => '*/2 * * * *', // 每2分钟
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'workbench_moments.log',
|
||||
],
|
||||
@@ -223,7 +223,7 @@ return [
|
||||
'command' => 'switch:friends',
|
||||
'schedule' => '*/2 * * * *', // 每2分钟
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'switch_friends.log',
|
||||
],
|
||||
@@ -238,7 +238,7 @@ return [
|
||||
'command' => 'call-recording:list',
|
||||
'schedule' => '*/30 * * * *', // 每30分钟
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'call_recording.log',
|
||||
],
|
||||
@@ -253,7 +253,7 @@ return [
|
||||
'command' => 'device:list',
|
||||
'schedule' => '0 1 * * *', // 每天1点
|
||||
'options' => ['--isDel=1'],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'crontab_device_deleted.log',
|
||||
],
|
||||
@@ -264,7 +264,7 @@ return [
|
||||
'command' => 'device:list',
|
||||
'schedule' => '10 1 * * *', // 每天1:10
|
||||
'options' => ['--isDel=2'],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'crontab_device_stopped.log',
|
||||
],
|
||||
@@ -275,7 +275,7 @@ return [
|
||||
'command' => 'wechatFriends:list',
|
||||
'schedule' => '30 1 * * *', // 每天1:30
|
||||
'options' => ['--isDel=1'],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'crontab_wechatFriends_deleted.log',
|
||||
],
|
||||
@@ -286,7 +286,7 @@ return [
|
||||
'command' => 'wechatChatroom:list',
|
||||
'schedule' => '30 1 * * *', // 每天1:30
|
||||
'options' => ['--isDel=1'],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'crontab_wechatChatroom_deleted.log',
|
||||
],
|
||||
@@ -297,7 +297,7 @@ return [
|
||||
'command' => 'wechat:calculate-score',
|
||||
'schedule' => '0 2 * * *', // 每天2点
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'calculate_score.log',
|
||||
],
|
||||
@@ -310,7 +310,7 @@ return [
|
||||
'command' => 'sync:allFriends',
|
||||
'schedule' => '0 3 */3 * *', // 每3天的3点
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'all_friends.log',
|
||||
],
|
||||
@@ -321,7 +321,7 @@ return [
|
||||
'command' => 'check:unread-message',
|
||||
'schedule' => '*/5 * * * *', // 每5分钟
|
||||
'options' => ['--minutes=30'], // 30分钟未读/未回复
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'check_unread_message.log',
|
||||
],
|
||||
@@ -332,7 +332,7 @@ return [
|
||||
'command' => 'department:list',
|
||||
'schedule' => '*/30 * * * *', // 每30分钟
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'crontab_department.log',
|
||||
],
|
||||
@@ -343,7 +343,7 @@ return [
|
||||
'command' => 'content:sync',
|
||||
'schedule' => '0 2 * * *', // 每天2点
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'crontab_content_sync.log',
|
||||
],
|
||||
@@ -354,7 +354,7 @@ return [
|
||||
'command' => 'moments:collect',
|
||||
'schedule' => '0 6 * * *', // 每天6点
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'crontab_moments_collect.log',
|
||||
],
|
||||
@@ -365,7 +365,7 @@ return [
|
||||
'command' => 'allotrule:list',
|
||||
'schedule' => '0 3 * * *', // 每天3点
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'crontab_allotrule_list.log',
|
||||
],
|
||||
@@ -376,7 +376,7 @@ return [
|
||||
'command' => 'allotrule:autocreate',
|
||||
'schedule' => '0 4 * * *', // 每天4点
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'crontab_allotrule_autocreate.log',
|
||||
],
|
||||
@@ -387,7 +387,7 @@ return [
|
||||
'command' => 'workbench:groupWelcome',
|
||||
'schedule' => '*/1 * * * *', // 每1分钟
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'workbench_groupWelcome.log',
|
||||
],
|
||||
@@ -398,7 +398,7 @@ return [
|
||||
'command' => 'own:moments:collect',
|
||||
'schedule' => '*/30 * * * *', // 每30分钟
|
||||
'options' => [],
|
||||
'enabled' => true,
|
||||
'enabled' => false,
|
||||
'max_concurrent' => 1,
|
||||
'log_file' => 'own_moments_collect.log',
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user