Merge branch 'develop' of https://e.coding.net/g-xtcy5189/cunkebao/cunkebao_v3 into develop
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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/************************ 私有辅助方法 ************************/
|
||||
|
||||
@@ -9,12 +9,11 @@ use think\Db;
|
||||
use think\facade\Log;
|
||||
use WebSocket\Client;
|
||||
use think\facade\Env;
|
||||
use app\api\model\WechatFriendModel as WechatFriend;
|
||||
use app\api\model\WechatFriendModel as WechatFriend;
|
||||
use app\api\model\WechatMomentsModel as WechatMoments;
|
||||
use think\facade\Cache;
|
||||
|
||||
|
||||
|
||||
class WebSocketController extends BaseController
|
||||
{
|
||||
protected $authorized;
|
||||
@@ -27,7 +26,7 @@ class WebSocketController extends BaseController
|
||||
/************************************
|
||||
* 初始化相关功能
|
||||
************************************/
|
||||
|
||||
|
||||
/**
|
||||
* 构造函数 - 初始化WebSocket连接
|
||||
* @param array $userData 用户数据
|
||||
@@ -44,39 +43,39 @@ class WebSocketController extends BaseController
|
||||
*/
|
||||
protected function initConnection($userData = [])
|
||||
{
|
||||
if(!empty($userData) && count($userData)){
|
||||
if (!empty($userData) && count($userData)) {
|
||||
if (empty($userData['userName']) || empty($userData['password'])) {
|
||||
return json_encode(['code'=>400,'msg'=>'参数缺失']);
|
||||
return json_encode(['code' => 400, 'msg' => '参数缺失']);
|
||||
}
|
||||
|
||||
// 检查缓存中是否存在有效的token
|
||||
$cacheKey = 'websocket_token_' . $userData['userName'];
|
||||
$cachedToken = Cache::get($cacheKey);
|
||||
|
||||
$cachedToken = Cache::get($cacheKey);
|
||||
|
||||
if ($cachedToken) {
|
||||
$this->authorized = $cachedToken;
|
||||
$this->accountId = $userData['accountId'];
|
||||
} else {
|
||||
$params = [
|
||||
'grant_type' => 'password',
|
||||
'username' => $userData['userName'],
|
||||
'password' => $userData['password']
|
||||
];
|
||||
$params = [
|
||||
'grant_type' => 'password',
|
||||
'username' => $userData['userName'],
|
||||
'password' => $userData['password']
|
||||
];
|
||||
|
||||
// 调用登录接口获取token
|
||||
$headerData = ['client:kefu-client'];
|
||||
$header = setHeader($headerData, '', 'plain');
|
||||
$result = requestCurl('https://kf.quwanzhi.com:9991/token', $params, 'POST', $header);
|
||||
$result_array = handleApiResponse($result);
|
||||
// 调用登录接口获取token
|
||||
$headerData = ['client:kefu-client'];
|
||||
$header = setHeader($headerData, '', 'plain');
|
||||
$result = requestCurl('https://kf.quwanzhi.com:9991/token', $params, 'POST', $header);
|
||||
$result_array = handleApiResponse($result);
|
||||
|
||||
if (isset($result_array['access_token']) && !empty($result_array['access_token'])) {
|
||||
$this->authorized = $result_array['access_token'];
|
||||
$this->accountId = $userData['accountId'];
|
||||
|
||||
// 将token存入缓存,有效期5分钟
|
||||
Cache::set($cacheKey, $this->authorized, 300);
|
||||
} else {
|
||||
return json_encode(['code'=>400,'msg'=>'获取系统授权信息失败']);
|
||||
if (isset($result_array['access_token']) && !empty($result_array['access_token'])) {
|
||||
$this->authorized = $result_array['access_token'];
|
||||
$this->accountId = $userData['accountId'];
|
||||
|
||||
// 将token存入缓存,有效期5分钟
|
||||
Cache::set($cacheKey, $this->authorized, 300);
|
||||
} else {
|
||||
return json_encode(['code' => 400, 'msg' => '获取系统授权信息失败']);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -85,7 +84,7 @@ class WebSocketController extends BaseController
|
||||
}
|
||||
|
||||
if (empty($this->authorized) || empty($this->accountId)) {
|
||||
return json_encode(['code'=>400,'msg'=>'缺失关键参数']);
|
||||
return json_encode(['code' => 400, 'msg' => '缺失关键参数']);
|
||||
}
|
||||
|
||||
$this->connect();
|
||||
@@ -97,40 +96,40 @@ class WebSocketController extends BaseController
|
||||
protected function connect()
|
||||
{
|
||||
try {
|
||||
//证书
|
||||
$context = stream_context_create();
|
||||
stream_context_set_option($context, 'ssl', 'verify_peer', false);
|
||||
stream_context_set_option($context, 'ssl', 'verify_peer_name', false);
|
||||
|
||||
//开启WS链接
|
||||
$result = [
|
||||
"accessToken" => $this->authorized,
|
||||
"accountId" => $this->accountId,
|
||||
"client" => "kefu-client",
|
||||
"cmdType" => "CmdSignIn",
|
||||
"seq" => 1,
|
||||
];
|
||||
//证书
|
||||
$context = stream_context_create();
|
||||
stream_context_set_option($context, 'ssl', 'verify_peer', false);
|
||||
stream_context_set_option($context, 'ssl', 'verify_peer_name', false);
|
||||
|
||||
$content = json_encode($result);
|
||||
$this->client = new Client("wss://kf.quwanzhi.com:9993",
|
||||
[
|
||||
'filter' => ['text', 'binary', 'ping', 'pong', 'close','receive', 'send'],
|
||||
'context' => $context,
|
||||
'headers' => [
|
||||
'Sec-WebSocket-Protocol' => 'soap',
|
||||
'origin' => 'localhost',
|
||||
],
|
||||
'timeout' => 86400,
|
||||
]
|
||||
);
|
||||
|
||||
$this->client->send($content);
|
||||
//开启WS链接
|
||||
$result = [
|
||||
"accessToken" => $this->authorized,
|
||||
"accountId" => $this->accountId,
|
||||
"client" => "kefu-client",
|
||||
"cmdType" => "CmdSignIn",
|
||||
"seq" => 1,
|
||||
];
|
||||
|
||||
$content = json_encode($result);
|
||||
$this->client = new Client("wss://kf.quwanzhi.com:9993",
|
||||
[
|
||||
'filter' => ['text', 'binary', 'ping', 'pong', 'close', 'receive', 'send'],
|
||||
'context' => $context,
|
||||
'headers' => [
|
||||
'Sec-WebSocket-Protocol' => 'soap',
|
||||
'origin' => 'localhost',
|
||||
],
|
||||
'timeout' => 86400,
|
||||
]
|
||||
);
|
||||
|
||||
$this->client->send($content);
|
||||
$this->isConnected = true;
|
||||
$this->lastHeartbeatTime = time();
|
||||
|
||||
|
||||
// 启动心跳检测
|
||||
//$this->startHeartbeat();
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("WebSocket连接失败:" . $e->getMessage());
|
||||
$this->isConnected = false;
|
||||
@@ -143,7 +142,7 @@ class WebSocketController extends BaseController
|
||||
protected function startHeartbeat()
|
||||
{
|
||||
// 使用定时器发送心跳
|
||||
\Swoole\Timer::tick($this->heartbeatInterval * 1000, function() {
|
||||
\Swoole\Timer::tick($this->heartbeatInterval * 1000, function () {
|
||||
if ($this->isConnected) {
|
||||
$this->sendHeartbeat();
|
||||
}
|
||||
@@ -160,10 +159,10 @@ class WebSocketController extends BaseController
|
||||
"cmdType" => "CmdHeartbeat",
|
||||
"seq" => time()
|
||||
];
|
||||
|
||||
|
||||
$this->client->send(json_encode($heartbeat));
|
||||
$this->lastHeartbeatTime = time();
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("发送心跳包失败:" . $e->getMessage());
|
||||
$this->reconnect();
|
||||
@@ -204,7 +203,7 @@ class WebSocketController extends BaseController
|
||||
protected function sendMessage($data)
|
||||
{
|
||||
$this->checkConnection();
|
||||
|
||||
|
||||
try {
|
||||
$this->client->send(json_encode($data));
|
||||
$response = $this->client->receive();
|
||||
@@ -235,9 +234,9 @@ class WebSocketController extends BaseController
|
||||
$currentPage = 1; // 当前页码
|
||||
$allMoments = []; // 存储所有朋友圈数据
|
||||
|
||||
//过滤消息
|
||||
//过滤消息
|
||||
if (empty($wechatAccountId)) {
|
||||
return json_encode(['code'=>400,'msg'=>'指定账号不能为空']);
|
||||
return json_encode(['code' => 400, 'msg' => '指定账号不能为空']);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -263,21 +262,21 @@ class WebSocketController extends BaseController
|
||||
sleep(10);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 检查返回结果
|
||||
if (!isset($message['result']) || empty($message['result']) || !is_array($message['result'])) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 检查是否遇到旧数据
|
||||
$hasOldData = false;
|
||||
foreach ($message['result'] as $moment) {
|
||||
$momentId = WechatMoments::where('snsId', $moment['snsId'])
|
||||
->where('wechatAccountId', $wechatAccountId)
|
||||
->value('id');
|
||||
|
||||
|
||||
if (!empty($momentId)) {
|
||||
$hasOldData = true;
|
||||
break;
|
||||
@@ -330,31 +329,31 @@ class WebSocketController extends BaseController
|
||||
|
||||
return json_encode($result);
|
||||
} catch (\Exception $e) {
|
||||
return json_encode(['code'=>500,'msg'=>$e->getMessage()]);
|
||||
return json_encode(['code' => 500, 'msg' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 朋友圈点赞
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function momentInteract($data = [])
|
||||
{
|
||||
|
||||
|
||||
$snsId = !empty($data['snsId']) ? $data['snsId'] : '';
|
||||
$wechatAccountId = !empty($data['wechatAccountId']) ? $data['wechatAccountId'] : '';
|
||||
$wechatFriendId = !empty($data['wechatFriendId']) ? $data['wechatFriendId'] : 0;
|
||||
|
||||
|
||||
//过滤消息
|
||||
if (empty($snsId)) {
|
||||
return json_encode(['code'=>400,'msg'=>'snsId不能为空']);
|
||||
if (empty($snsId)) {
|
||||
return json_encode(['code' => 400, 'msg' => 'snsId不能为空']);
|
||||
}
|
||||
if (empty($wechatAccountId)) {
|
||||
return json_encode(['code'=>400,'msg'=>'微信id不能为空']);
|
||||
if (empty($wechatAccountId)) {
|
||||
return json_encode(['code' => 400, 'msg' => '微信id不能为空']);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
try {
|
||||
$result = [
|
||||
"cmdType" => "CmdMomentInteract",
|
||||
"momentInteractType" => 1,
|
||||
@@ -362,16 +361,16 @@ class WebSocketController extends BaseController
|
||||
"snsId" => $snsId,
|
||||
"wechatAccountId" => $wechatAccountId,
|
||||
"wechatFriendId" => $wechatFriendId,
|
||||
];
|
||||
];
|
||||
|
||||
$message = $this->sendMessage($result);
|
||||
return json_encode(['code'=>200,'msg'=>'点赞成功','data'=>$message]);
|
||||
} catch (\Exception $e) {
|
||||
return json_encode(['code'=>500,'msg'=>$e->getMessage()]);
|
||||
return json_encode(['code' => 200, 'msg' => '点赞成功', 'data' => $message]);
|
||||
} catch (\Exception $e) {
|
||||
return json_encode(['code' => 500, 'msg' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 朋友圈取消点赞
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
@@ -381,36 +380,36 @@ class WebSocketController extends BaseController
|
||||
$data = $this->request->param();
|
||||
|
||||
if (empty($data)) {
|
||||
return json_encode(['code'=>400,'msg'=>'参数缺失']);
|
||||
return json_encode(['code' => 400, 'msg' => '参数缺失']);
|
||||
}
|
||||
|
||||
//过滤消息
|
||||
if (empty($data['snsId'])) {
|
||||
return json_encode(['code'=>400,'msg'=>'snsId不能为空']);
|
||||
return json_encode(['code' => 400, 'msg' => 'snsId不能为空']);
|
||||
}
|
||||
if (empty($data['wechatAccountId'])) {
|
||||
return json_encode(['code'=>400,'msg'=>'微信id不能为空']);
|
||||
return json_encode(['code' => 400, 'msg' => '微信id不能为空']);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$result = [
|
||||
"CommentId2" => '',
|
||||
"CommentTime" => 0,
|
||||
"cmdType" => "CmdMomentCancelInteract",
|
||||
"optType" => 1,
|
||||
"seq" => time(),
|
||||
"snsId" => $data['snsId'],
|
||||
"wechatAccountId" => $data['wechatAccountId'],
|
||||
"wechatFriendId" => 0,
|
||||
];
|
||||
$result = [
|
||||
"CommentId2" => '',
|
||||
"CommentTime" => 0,
|
||||
"cmdType" => "CmdMomentCancelInteract",
|
||||
"optType" => 1,
|
||||
"seq" => time(),
|
||||
"snsId" => $data['snsId'],
|
||||
"wechatAccountId" => $data['wechatAccountId'],
|
||||
"wechatFriendId" => 0,
|
||||
];
|
||||
|
||||
$message = $this->sendMessage($result);
|
||||
return json_encode(['code'=>200,'msg'=>'取消点赞成功','data'=>$message]);
|
||||
return json_encode(['code' => 200, 'msg' => '取消点赞成功', 'data' => $message]);
|
||||
} catch (\Exception $e) {
|
||||
return json_encode(['code'=>500,'msg'=>$e->getMessage()]);
|
||||
return json_encode(['code' => 500, 'msg' => $e->getMessage()]);
|
||||
}
|
||||
} else {
|
||||
return json_encode(['code'=>400,'msg'=>'非法请求']);
|
||||
return json_encode(['code' => 400, 'msg' => '非法请求']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,19 +461,19 @@ class WebSocketController extends BaseController
|
||||
|
||||
// 发送请求
|
||||
$this->client->send(json_encode($params));
|
||||
|
||||
|
||||
// 接收响应
|
||||
$response = $this->client->receive();
|
||||
$message = json_decode($response, true);
|
||||
|
||||
if(empty($message)){
|
||||
return json_encode(['code'=>500,'msg'=>'获取朋友圈资源链接失败']);
|
||||
if (empty($message)) {
|
||||
return json_encode(['code' => 500, 'msg' => '获取朋友圈资源链接失败']);
|
||||
}
|
||||
if($message['cmdType'] == 'CmdDownloadMomentImagesResult' && is_array($message['urls']) && count($message['urls']) > 0){
|
||||
$urls = json_encode($message['urls'],256);
|
||||
Db::table('s2_wechat_moments')->where('snsId',$data['snsId'])->update(['resUrls'=>$urls]);
|
||||
if ($message['cmdType'] == 'CmdDownloadMomentImagesResult' && is_array($message['urls']) && count($message['urls']) > 0) {
|
||||
$urls = json_encode($message['urls'], 256);
|
||||
Db::table('s2_wechat_moments')->where('snsId', $data['snsId'])->update(['resUrls' => $urls]);
|
||||
}
|
||||
return json_encode(['code'=>200,'msg'=>'获取朋友圈资源链接成功','data'=>$message]);
|
||||
return json_encode(['code' => 200, 'msg' => '获取朋友圈资源链接成功', 'data' => $message]);
|
||||
} catch (\Exception $e) {
|
||||
// 记录错误日志
|
||||
Log::error('获取朋友圈资源链接异常:' . $e->getMessage());
|
||||
@@ -507,19 +506,18 @@ class WebSocketController extends BaseController
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
try {
|
||||
foreach ($momentList as $moment) {
|
||||
// 提取momentEntity中的数据
|
||||
$momentEntity = $moment['momentEntity'] ?? [];
|
||||
|
||||
|
||||
// 检查朋友圈数据是否已存在
|
||||
$momentId = WechatMoments::where('snsId', $moment['snsId'])
|
||||
->where('wechatAccountId', $wechatAccountId)
|
||||
->value('id');
|
||||
|
||||
|
||||
|
||||
$dataToSave = [
|
||||
'commentList' => json_encode($moment['commentList'] ?? [], 256),
|
||||
'createTime' => $moment['createTime'] ?? 0,
|
||||
@@ -543,7 +541,7 @@ class WebSocketController extends BaseController
|
||||
// 如果已存在,则更新数据
|
||||
Db::table('s2_wechat_moments')->where('id', $momentId)->update($dataToSave);
|
||||
} else {
|
||||
if(empty($wechatFriendId)){
|
||||
if (empty($wechatFriendId)) {
|
||||
$wechatFriendId = WechatFriend::where('wechatAccountId', $wechatAccountId)->where('wechatId', $momentEntity['userName'])->value('id');
|
||||
}
|
||||
// 如果不存在,则插入新数据
|
||||
@@ -588,7 +586,7 @@ class WebSocketController extends BaseController
|
||||
if (empty($wechatFriendId)) {
|
||||
return json_encode(['code' => 400, 'msg' => '好友ID不能为空']);
|
||||
}
|
||||
|
||||
|
||||
if (empty($wechatAccountId)) {
|
||||
return json_encode(['code' => 400, 'msg' => '微信账号ID不能为空']);
|
||||
}
|
||||
@@ -609,7 +607,7 @@ class WebSocketController extends BaseController
|
||||
|
||||
// 发送请求并获取响应
|
||||
$message = $this->sendMessage($params);
|
||||
|
||||
|
||||
// 记录日志
|
||||
Log::info('修改好友标签:' . json_encode($params, 256));
|
||||
Log::info('修改好友标签结果:' . json_encode($message, 256));
|
||||
@@ -619,7 +617,7 @@ class WebSocketController extends BaseController
|
||||
} catch (\Exception $e) {
|
||||
// 记录错误日志
|
||||
Log::error('修改好友标签失败:' . $e->getMessage());
|
||||
|
||||
|
||||
// 返回错误响应
|
||||
return json_encode(['code' => 500, 'msg' => '修改标签失败:' . $e->getMessage()]);
|
||||
}
|
||||
@@ -653,24 +651,23 @@ class WebSocketController extends BaseController
|
||||
// 消息拼接 msgType(1:文本 3:图片 43:视频 47:动图表情包(gif、其他表情包) 49:小程序/其他:图文、文件)
|
||||
// 当前,type 为文本、图片、动图表情包的时候,content为string, 其他情况为对象 {type: 'file/link/...', url: '', title: '', thunmbPath: '', desc: ''}
|
||||
$params = [
|
||||
"cmdType" => "CmdSendMessage",
|
||||
"content" => $dataArray['content'],
|
||||
"msgSubType" => 0,
|
||||
"msgType" => $dataArray['msgType'],
|
||||
"seq" => time(),
|
||||
"wechatAccountId" => $dataArray['wechatAccountId'],
|
||||
"wechatChatroomId" => 0,
|
||||
"wechatFriendId" => $dataArray['wechatFriendId'],
|
||||
];
|
||||
"cmdType" => "CmdSendMessage",
|
||||
"content" => $dataArray['content'],
|
||||
"msgSubType" => 0,
|
||||
"msgType" => $dataArray['msgType'],
|
||||
"seq" => time(),
|
||||
"wechatAccountId" => $dataArray['wechatAccountId'],
|
||||
"wechatChatroomId" => 0,
|
||||
"wechatFriendId" => $dataArray['wechatFriendId'],
|
||||
];
|
||||
|
||||
// 发送请求
|
||||
$this->client->send(json_encode($params));
|
||||
// 接收响应
|
||||
$response = $this->client->receive();
|
||||
$message = json_decode($response, true);
|
||||
|
||||
if(!empty($message)){
|
||||
return json_encode(['code'=>500,'msg'=>'信息发送成功','data'=>$message]);
|
||||
if (!empty($message)) {
|
||||
return json_encode(['code' => 200, 'msg' => '信息发送成功', 'data' => $message]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -678,65 +675,55 @@ class WebSocketController extends BaseController
|
||||
* 发送群消息
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function sendCommunity()
|
||||
public function sendCommunity($dataArray = [])
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->post();
|
||||
if (empty($data)) {
|
||||
return json_encode(['code'=>400,'msg'=>'参数缺失']);
|
||||
}
|
||||
$dataArray = $data;
|
||||
if (!is_array($dataArray)) {
|
||||
return json_encode(['code'=>400,'msg'=>'数据格式错误']);
|
||||
}
|
||||
|
||||
//过滤消息
|
||||
if (empty($dataArray['content'])) {
|
||||
return json_encode(['code'=>400,'msg'=>'内容缺失']);
|
||||
}
|
||||
if (empty($dataArray['wechatAccountId'])) {
|
||||
return json_encode(['code'=>400,'msg'=>'微信id不能为空']);
|
||||
}
|
||||
|
||||
if (empty($dataArray['msgType'])) {
|
||||
return json_encode(['code'=>400,'msg'=>'类型缺失']);
|
||||
}
|
||||
if (empty($dataArray['wechatChatroomId'])) {
|
||||
return json_encode(['code'=>400,'msg'=>'群id不能为空']);
|
||||
}
|
||||
|
||||
$msg = '消息成功发送';
|
||||
$message = [];
|
||||
try {
|
||||
//消息拼接 msgType(1:文本 3:图片 43:视频 47:动图表情包 49:小程序)
|
||||
$result = [
|
||||
"cmdType" => "CmdSendMessage",
|
||||
"content" => htmlspecialchars_decode($dataArray['content']),
|
||||
"msgSubType" => 0,
|
||||
"msgType" => $dataArray['msgType'],
|
||||
"seq" => time(),
|
||||
"wechatAccountId" => $dataArray['wechatAccountId'],
|
||||
"wechatChatroomId" => $dataArray['wechatChatroomId'],
|
||||
"wechatFriendId" => 0,
|
||||
];
|
||||
|
||||
$result = json_encode($result);
|
||||
$this->client->send($result);
|
||||
$message = $this->client->receive();
|
||||
//关闭WS链接
|
||||
$this->client->close();
|
||||
//Log::write('WS群消息发送');
|
||||
//Log::write($message);
|
||||
$message = json_decode($message, 1);
|
||||
} catch (\Exception $e) {
|
||||
$msg = $e->getMessage();
|
||||
}
|
||||
return json_encode(['code'=>200,'msg'=>$msg,'data'=>$message]);
|
||||
|
||||
} else {
|
||||
return json_encode(['code'=>400,'msg'=>'非法请求']);
|
||||
//return errorJson('非法请求');
|
||||
if (!is_array($dataArray)) {
|
||||
return json_encode(['code' => 400, 'msg' => '数据格式错误']);
|
||||
}
|
||||
|
||||
//过滤消息
|
||||
if (empty($dataArray['content'])) {
|
||||
return json_encode(['code' => 400, 'msg' => '内容缺失']);
|
||||
}
|
||||
if (empty($dataArray['wechatAccountId'])) {
|
||||
return json_encode(['code' => 400, 'msg' => '微信id不能为空']);
|
||||
}
|
||||
|
||||
if (empty($dataArray['msgType'])) {
|
||||
return json_encode(['code' => 400, 'msg' => '类型缺失']);
|
||||
}
|
||||
if (empty($dataArray['wechatChatroomId'])) {
|
||||
return json_encode(['code' => 400, 'msg' => '群id不能为空']);
|
||||
}
|
||||
|
||||
$message = [];
|
||||
try {
|
||||
//消息拼接 msgType(1:文本 3:图片 43:视频 47:动图表情包 49:小程序)
|
||||
$params = [
|
||||
"cmdType" => "CmdSendMessage",
|
||||
"content" => htmlspecialchars_decode($dataArray['content']),
|
||||
"msgSubType" => 0,
|
||||
"msgType" => $dataArray['msgType'],
|
||||
"seq" => time(),
|
||||
"wechatAccountId" => $dataArray['wechatAccountId'],
|
||||
"wechatChatroomId" => $dataArray['wechatChatroomId'],
|
||||
"wechatFriendId" => 0,
|
||||
];
|
||||
|
||||
// 发送请求
|
||||
$this->client->send(json_encode($params));
|
||||
// 接收响应
|
||||
$response = $this->client->receive();
|
||||
$message = json_decode($response, true);
|
||||
if (!empty($message)) {
|
||||
return json_encode(['code' => 200, 'msg' => '信息发送成功', 'data' => $message]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$msg = $e->getMessage();
|
||||
return json_encode(['code' => 400, 'msg' => $msg, 'data' => $message]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -747,26 +734,26 @@ class WebSocketController extends BaseController
|
||||
public function sendCommunitys($data = [])
|
||||
{
|
||||
if (empty($data)) {
|
||||
return json_encode(['code'=>400,'msg'=>'参数缺失']);
|
||||
return json_encode(['code' => 400, 'msg' => '参数缺失']);
|
||||
}
|
||||
$dataArray = $data;
|
||||
if (!is_array($dataArray)) {
|
||||
return json_encode(['code'=>400,'msg'=>'数据格式错误']);
|
||||
return json_encode(['code' => 400, 'msg' => '数据格式错误']);
|
||||
}
|
||||
|
||||
//过滤消息
|
||||
if (empty($dataArray['content'])) {
|
||||
return json_encode(['code'=>400,'msg'=>'内容缺失']);
|
||||
return json_encode(['code' => 400, 'msg' => '内容缺失']);
|
||||
}
|
||||
if (empty($dataArray['wechatAccountId'])) {
|
||||
return json_encode(['code'=>400,'msg'=>'微信id不能为空']);
|
||||
return json_encode(['code' => 400, 'msg' => '微信id不能为空']);
|
||||
}
|
||||
|
||||
if (empty($dataArray['msgType'])) {
|
||||
return json_encode(['code'=>400,'msg'=>'类型缺失']);
|
||||
return json_encode(['code' => 400, 'msg' => '类型缺失']);
|
||||
}
|
||||
if (empty($dataArray['wechatChatroomId'])) {
|
||||
return json_encode(['code'=>400,'msg'=>'群id不能为空']);
|
||||
return json_encode(['code' => 400, 'msg' => '群id不能为空']);
|
||||
}
|
||||
|
||||
$msg = '消息成功发送';
|
||||
@@ -796,11 +783,10 @@ class WebSocketController extends BaseController
|
||||
$msg = $e->getMessage();
|
||||
}
|
||||
|
||||
return json_encode(['code'=>200,'msg'=>$msg,'data'=>$message]);
|
||||
return json_encode(['code' => 200, 'msg' => $msg, 'data' => $message]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 邀请好友入群
|
||||
* @param array $data 请求参数
|
||||
@@ -843,11 +829,11 @@ class WebSocketController extends BaseController
|
||||
Log::info('邀请好友入群请求:' . json_encode($params, 256));
|
||||
|
||||
$message = $this->sendMessage($params);
|
||||
return json_encode(['code'=>200,'msg'=>'邀请成功','data'=>$message]);
|
||||
return json_encode(['code' => 200, 'msg' => '邀请成功', 'data' => $message]);
|
||||
} catch (\Exception $e) {
|
||||
// 记录错误日志
|
||||
Log::error('邀请好友入群异常:' . $e->getMessage());
|
||||
// 返回错误响应
|
||||
// 返回错误响应
|
||||
return json_encode(['code' => 500, 'msg' => '邀请好友入群异常:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,5 +32,6 @@ return [
|
||||
'sync:wechatData' => 'app\command\SyncWechatDataToCkbTask', // 同步微信数据到存客宝
|
||||
'sync:allFriends' => 'app\command\SyncAllFriendsCommand', // 同步所有在线好友
|
||||
'workbench:trafficDistribute' => 'app\command\WorkbenchTrafficDistributeCommand', // 工作台流量分发任务
|
||||
'workbench:groupPush' => 'app\command\WorkbenchGroupPushCommand', // 工作台群组同步任务
|
||||
'switch:friends' => 'app\command\SwitchFriendsCommand',
|
||||
];
|
||||
|
||||
@@ -51,6 +51,7 @@ class SyncWechatDataToCkbTask extends Command
|
||||
$this->syncWechatDeviceLoginLog($ChuKeBaoAdapter);
|
||||
$this->syncWechatDevice($ChuKeBaoAdapter);
|
||||
$this->syncWechatCustomer($ChuKeBaoAdapter);
|
||||
$this->syncWechatGroup($ChuKeBaoAdapter);
|
||||
$this->syncWechatFriendToTrafficPoolBatch($ChuKeBaoAdapter);
|
||||
$this->syncTrafficSourceUser($ChuKeBaoAdapter);
|
||||
$this->syncTrafficSourceGroup($ChuKeBaoAdapter);
|
||||
@@ -108,5 +109,10 @@ class SyncWechatDataToCkbTask extends Command
|
||||
return $ChuKeBaoAdapter->syncTrafficSourceGroup();
|
||||
}
|
||||
|
||||
protected function syncWechatGroup(ChuKeBaoAdapter $ChuKeBaoAdapter)
|
||||
{
|
||||
return $ChuKeBaoAdapter->syncWechatGroup();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
76
Server/application/command/WorkbenchGroupPushCommand.php
Normal file
76
Server/application/command/WorkbenchGroupPushCommand.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
namespace app\command;
|
||||
|
||||
use app\job\WorkbenchGroupPushJob;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\console\input\Option;
|
||||
use think\facade\Log;
|
||||
use think\Queue;
|
||||
use think\facade\Cache;
|
||||
|
||||
class WorkbenchGroupPushCommand extends Command
|
||||
{
|
||||
// 队列名称
|
||||
protected $queueName = 'workbench_groupPush';
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('workbench:groupPush')
|
||||
->setDescription('工作台群组同步任务队列')
|
||||
->addOption('jobId', null, Option::VALUE_OPTIONAL, '任务ID,用于区分不同实例', date('YmdHis') . rand(1000, 9999));
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$output->writeln('开始处理工作台群组同步任务...');
|
||||
|
||||
try {
|
||||
// 获取任务ID
|
||||
$jobId = $input->getOption('jobId');
|
||||
|
||||
$output->writeln('任务ID: ' . $jobId);
|
||||
|
||||
// 检查队列是否已经在运行
|
||||
$queueLockKey = "queue_lock:{$this->queueName}";
|
||||
Cache::rm($queueLockKey);
|
||||
if (Cache::get($queueLockKey)) {
|
||||
$output->writeln("队列 {$this->queueName} 已经在运行中,跳过执行");
|
||||
Log::warning("队列 {$this->queueName} 已经在运行中,跳过执行");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 设置队列运行锁,有效期1小时
|
||||
Cache::set($queueLockKey, $jobId, 3600);
|
||||
$output->writeln("已设置队列运行锁,键名:{$queueLockKey},值:{$jobId},有效期:1小时");
|
||||
|
||||
// 将任务添加到队列
|
||||
$this->addToQueue($jobId, $queueLockKey);
|
||||
|
||||
$output->writeln('工作台群组同步任务已添加到队列');
|
||||
} catch (\Exception $e) {
|
||||
Log::error('工作台群组同步任务添加失败:' . $e->getMessage());
|
||||
$output->writeln('工作台群组同步任务添加失败:' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加任务到队列
|
||||
* @param string $jobId 任务ID
|
||||
* @param string $queueLockKey 队列锁键名
|
||||
*/
|
||||
public function addToQueue($jobId = '', $queueLockKey = '')
|
||||
{
|
||||
$data = [
|
||||
'jobId' => $jobId,
|
||||
'queueLockKey' => $queueLockKey
|
||||
];
|
||||
|
||||
// 添加到队列,设置任务名为 workbench_groupPush
|
||||
Queue::push(WorkbenchGroupPushJob::class, $data, $this->queueName);
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
@@ -86,6 +94,9 @@ Route::group('v1/', function () {
|
||||
Route::get('device-labels', 'app\cunkebao\controller\WorkbenchController@getDeviceLabels'); // 获取设备微信好友标签统计
|
||||
Route::get('group-list', 'app\cunkebao\controller\WorkbenchController@getGroupList'); // 获取群列表
|
||||
Route::get('account-list', 'app\cunkebao\controller\WorkbenchController@getAccountList'); // 获取账号列表
|
||||
|
||||
Route::get('getJdSocialMedia', 'app\cunkebao\controller\WorkbenchController@getJdSocialMedia'); // 获取京东联盟导购媒体
|
||||
Route::get('getJdPromotionSite', 'app\cunkebao\controller\WorkbenchController@getJdPromotionSite'); // 获取京东联盟广告位
|
||||
});
|
||||
|
||||
// 内容库相关
|
||||
|
||||
@@ -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('密码修改失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1500,4 +1500,38 @@ class WorkbenchController extends Controller
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取京东联盟导购媒体
|
||||
* @return \think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function getJdSocialMedia()
|
||||
{
|
||||
$data = Db::name('jd_social_media')->order('id DESC')->select();
|
||||
return json(['code' => 200, 'msg' => '获取成功', 'data' => $data]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取京东联盟广告位
|
||||
* @return \think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function getJdPromotionSite()
|
||||
{
|
||||
$id = $this->request->param('id', '');
|
||||
if (empty($id)) {
|
||||
return json(['code' => 500, 'msg' => '参数缺失']);
|
||||
}
|
||||
|
||||
$data = Db::name('jd_promotion_site')->where('jdSocialMediaId',$id)->order('id DESC')->select();
|
||||
return json(['code' => 200, 'msg' => '获取成功', 'data' => $data]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -270,7 +270,7 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
$percentage = number_format(($taskNum / $passNum) * 100, 2);
|
||||
$total['percentage'] = $percentage;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$data['total'] = $total;
|
||||
@@ -322,14 +322,20 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
public function getUserTags()
|
||||
{
|
||||
$userId = $this->request->param('userId', '');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
if (empty($userId)) {
|
||||
return json_encode(['code' => 500, 'msg' => '用户id不能为空']);
|
||||
}
|
||||
$data = Db::name('traffic_pool')->alias('tp')
|
||||
->join(['s2_wechat_friend' => 'wf'], 'tp.wechatId=wf.wechatId', 'left')
|
||||
->join('wechat_friendship f', 'tp.wechatId=f.wechatId AND f.companyId='.$companyId, 'left')
|
||||
->join(['s2_wechat_friend' => 'wf'], 'f.wechatId=wf.wechatId', 'left')
|
||||
->where(['tp.id' => $userId])
|
||||
->order('tp.createTime desc')
|
||||
->column('wf.id,wf.labels,wf.siteLabels');
|
||||
if (empty($data)) {
|
||||
return ResponseHelper::success(['wechat' => [], 'siteLabels' => []]);
|
||||
}
|
||||
|
||||
|
||||
$tags = [];
|
||||
$siteLabels = [];
|
||||
@@ -350,5 +356,31 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController
|
||||
return ResponseHelper::success(['wechat' => $tags, 'siteLabels' => $siteLabels]);
|
||||
}
|
||||
|
||||
/* public function editUserTags()
|
||||
{
|
||||
$userId = $this->request->param('userId', '');
|
||||
if (empty($userId)) {
|
||||
return json_encode(['code' => 500, 'msg' => '用户id不能为空']);
|
||||
}
|
||||
$tags = $this->request->param('tags', []);
|
||||
$tags = $this->request->param('tags', []);
|
||||
$isWechat = $this->request->param('isWechat', false);
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
|
||||
$friend = Db::name('traffic_pool')->alias('tp')
|
||||
->join('wechat_friendship f', 'tp.wechatId=f.wechatId AND f.companyId='.$companyId, 'left')
|
||||
->join(['s2_wechat_friend' => 'wf'], 'f.wechatId=wf.wechatId', 'left')
|
||||
->where(['tp.id' => $userId])
|
||||
->order('tp.createTime desc')
|
||||
->column('wf.id,wf.accountId,wf.labels,wf.siteLabels');
|
||||
if (empty($data)) {
|
||||
return ResponseHelper::error('该用户不存在');
|
||||
}
|
||||
|
||||
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -57,6 +57,9 @@
|
||||
# 同步微信数据到存客宝
|
||||
0 9 * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think sync:wechatData >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/sync_wechat_data.log 2>&1
|
||||
|
||||
# 工作台群发消息
|
||||
*/2 * * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think workbench:groupPush >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/workbench_groupPush.log 2>&1
|
||||
|
||||
# 工作台流量分发
|
||||
0 9 * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think workbench:trafficDistribute >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/traffic_distribute.log 2>&1
|
||||
|
||||
|
||||
@@ -1318,4 +1318,44 @@ class Adapter implements WeChatServiceInterface
|
||||
}
|
||||
} while ($affected > 0);
|
||||
}
|
||||
|
||||
public function syncWechatGroup()
|
||||
{
|
||||
$sql = "insert into ck_wechat_group(`id`,`wechatAccountId`,`chatroomId`,`name`,`avatar`,`companyId`,`ownerWechatId`,`createTime`,`updateTime`,`deleteTime`)
|
||||
SELECT
|
||||
g.id id,
|
||||
g.wechatAccountId wechatAccountId,
|
||||
g.chatroomId chatroomId,
|
||||
g.nickname name,
|
||||
g.chatroomAvatar avatar,
|
||||
c.departmentId companyId,
|
||||
g.wechatAccountWechatId ownerWechatId,
|
||||
g.createTime createTime,
|
||||
g.updateTime updateTime,
|
||||
g.deleteTime deleteTime
|
||||
FROM
|
||||
s2_wechat_chatroom g
|
||||
LEFT JOIN s2_company_account c ON g.accountId = c.id
|
||||
ORDER BY g.id DESC
|
||||
LIMIT ?, ?
|
||||
ON DUPLICATE KEY UPDATE
|
||||
chatroomId=VALUES(chatroomId),
|
||||
companyId=VALUES(companyId),
|
||||
ownerWechatId=VALUES(ownerWechatId)";
|
||||
|
||||
|
||||
$offset = 0;
|
||||
$limit = 2000;
|
||||
$usleepTime = 50000;
|
||||
do {
|
||||
$affected = Db::execute($sql, [$offset, $limit]);
|
||||
$offset += $limit;
|
||||
if ($affected > 0) {
|
||||
usleep($usleepTime);
|
||||
}
|
||||
} while ($affected > 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user