2025-10-16 15:36:44 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace app\chukebao\controller;
|
|
|
|
|
|
|
2025-11-28 15:32:02 +08:00
|
|
|
|
use app\api\model\WechatChatroomModel;
|
2025-10-16 15:36:44 +08:00
|
|
|
|
use library\ResponseHelper;
|
|
|
|
|
|
use app\api\model\WechatFriendModel;
|
2025-11-27 17:09:53 +08:00
|
|
|
|
use app\api\model\WechatMessageModel;
|
2025-10-21 16:48:00 +08:00
|
|
|
|
use app\api\controller\MessageController;
|
|
|
|
|
|
|
2025-10-16 15:36:44 +08:00
|
|
|
|
|
|
|
|
|
|
class DataProcessing extends BaseController
|
|
|
|
|
|
{
|
|
|
|
|
|
public function index()
|
|
|
|
|
|
{
|
|
|
|
|
|
$userId = $this->getUserInfo('id');
|
|
|
|
|
|
$companyId = $this->getUserInfo('companyId');
|
|
|
|
|
|
$type = $this->request->param('type', '');
|
|
|
|
|
|
$wechatAccountId = $this->request->param('wechatAccountId', '');
|
|
|
|
|
|
//微信好友
|
|
|
|
|
|
$toAccountId = $this->request->param('toAccountId', '');
|
|
|
|
|
|
$wechatFriendId = $this->request->param('wechatFriendId', '');
|
|
|
|
|
|
$newRemark = $this->request->param('newRemark', '');
|
|
|
|
|
|
$labels = $this->request->param('labels', []);
|
|
|
|
|
|
//微信群
|
|
|
|
|
|
$wechatChatroomId = $this->request->param('wechatChatroomId', '');
|
2025-10-21 16:48:00 +08:00
|
|
|
|
|
|
|
|
|
|
//新消息
|
|
|
|
|
|
$friendMessage = $this->request->param('friendMessage', '');
|
|
|
|
|
|
$chatroomMessage = $this->request->param('chatroomMessage', '');
|
|
|
|
|
|
|
2025-10-16 15:36:44 +08:00
|
|
|
|
$typeData = [
|
|
|
|
|
|
'CmdModifyFriendRemark', //好友修改备注 {newRemark、wechatAccountId、wechatFriendId}
|
|
|
|
|
|
'CmdModifyFriendLabel', //好友修改标签 {labels、wechatAccountId、wechatFriendId}
|
|
|
|
|
|
'CmdAllotFriend', //转让好友 {labels、wechatAccountId、wechatFriendId}
|
|
|
|
|
|
'CmdChatroomOperate', //修改群信息 {chatroomName(群名)、announce(公告)、extra(公告)、wechatAccountId、wechatChatroomId}
|
2025-10-21 16:48:00 +08:00
|
|
|
|
'CmdNewMessage', //接收消息
|
2025-11-27 17:09:53 +08:00
|
|
|
|
'CmdSendMessageResult', //更新消息状态
|
2025-10-16 15:36:44 +08:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($type) || empty($wechatAccountId)) {
|
|
|
|
|
|
return ResponseHelper::error('参数缺失');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!in_array($type, $typeData)) {
|
|
|
|
|
|
return ResponseHelper::error('类型错误');
|
|
|
|
|
|
}
|
|
|
|
|
|
$msg = '';
|
2025-10-22 09:55:49 +08:00
|
|
|
|
$codee = 200;
|
2025-10-16 15:36:44 +08:00
|
|
|
|
switch ($type) {
|
|
|
|
|
|
case 'CmdModifyFriendRemark': //修改好友备注
|
|
|
|
|
|
if(empty($wechatFriendId) || empty($newRemark)){
|
|
|
|
|
|
return ResponseHelper::error('参数缺失');
|
|
|
|
|
|
}
|
|
|
|
|
|
$friend = WechatFriendModel::where(['id' => $wechatFriendId,'wechatAccountId' => $wechatAccountId])->find();
|
|
|
|
|
|
if(empty($friend)){
|
|
|
|
|
|
return ResponseHelper::error('好友不存在');
|
|
|
|
|
|
}
|
|
|
|
|
|
$friend->conRemark = $newRemark;
|
|
|
|
|
|
$friend->updateTime = time();
|
|
|
|
|
|
$friend->save();
|
|
|
|
|
|
$msg = '修改备成功';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 'CmdModifyFriendLabel': //修改好友标签
|
|
|
|
|
|
if(empty($wechatFriendId)){
|
|
|
|
|
|
return ResponseHelper::error('参数缺失');
|
|
|
|
|
|
}
|
|
|
|
|
|
$friend = WechatFriendModel::where(['id' => $wechatFriendId,'wechatAccountId' => $wechatAccountId])->find();
|
|
|
|
|
|
if(empty($friend)){
|
|
|
|
|
|
return ResponseHelper::error('好友不存在');
|
|
|
|
|
|
}
|
|
|
|
|
|
$friend->labels = json_encode($labels,256);
|
|
|
|
|
|
$friend->updateTime = time();
|
|
|
|
|
|
$friend->save();
|
|
|
|
|
|
$msg = '修标签成功';
|
|
|
|
|
|
break;
|
2025-10-20 14:22:20 +08:00
|
|
|
|
case 'CmdAllotFriend': //迁移好友
|
2025-10-16 15:36:44 +08:00
|
|
|
|
if(empty($toAccountId)){
|
|
|
|
|
|
return ResponseHelper::error('参数缺失');
|
|
|
|
|
|
}
|
2025-11-28 15:32:02 +08:00
|
|
|
|
if(empty($wechatFriendId) && empty($wechatChatroomId)){
|
|
|
|
|
|
return ResponseHelper::error('参数缺失');
|
|
|
|
|
|
}
|
2025-10-16 15:36:44 +08:00
|
|
|
|
|
2025-11-28 15:32:02 +08:00
|
|
|
|
|
|
|
|
|
|
if (!empty($wechatFriendId)){
|
2025-11-28 16:04:29 +08:00
|
|
|
|
$data = WechatFriendModel::where(['id' => $wechatFriendId,'wechatAccountId' => $wechatAccountId])->find();
|
2025-11-28 15:32:02 +08:00
|
|
|
|
$msg = '好友转移成功';
|
2025-11-28 16:04:29 +08:00
|
|
|
|
if(empty($data)){
|
2025-11-28 15:32:02 +08:00
|
|
|
|
return ResponseHelper::error('好友不存在');
|
|
|
|
|
|
}
|
2025-10-16 15:36:44 +08:00
|
|
|
|
}
|
2025-11-28 15:32:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($wechatChatroomId)){
|
2025-11-28 16:04:29 +08:00
|
|
|
|
$data = WechatChatroomModel::where(['id' => $wechatChatroomId,'wechatAccountId' => $wechatAccountId])->find();
|
2025-11-28 15:32:02 +08:00
|
|
|
|
$msg = '群聊转移成功';
|
2025-11-28 16:04:29 +08:00
|
|
|
|
if(empty($data)){
|
2025-11-28 15:32:02 +08:00
|
|
|
|
return ResponseHelper::error('群聊不存在');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-28 16:04:29 +08:00
|
|
|
|
$data->accountId = $toAccountId;
|
|
|
|
|
|
$data->updateTime = time();
|
|
|
|
|
|
$data->save();
|
2025-10-16 15:36:44 +08:00
|
|
|
|
break;
|
2025-10-21 16:48:00 +08:00
|
|
|
|
case 'CmdNewMessage':
|
2025-10-23 09:34:43 +08:00
|
|
|
|
if(empty($friendMessage) && empty($chatroomMessage)){
|
2025-10-21 16:48:00 +08:00
|
|
|
|
return ResponseHelper::error('参数缺失');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-23 09:34:43 +08:00
|
|
|
|
if(is_array($friendMessage) && is_array($chatroomMessage)){
|
|
|
|
|
|
return ResponseHelper::error('数据类型错误');
|
2025-10-21 16:48:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-23 09:34:43 +08:00
|
|
|
|
|
2025-10-21 16:48:00 +08:00
|
|
|
|
$messageController = new MessageController();
|
|
|
|
|
|
if (!empty($friendMessage)){
|
2025-10-23 09:34:43 +08:00
|
|
|
|
$res = $messageController->saveMessage($friendMessage[0]);
|
2025-10-21 16:48:00 +08:00
|
|
|
|
}else{
|
2025-10-23 09:34:43 +08:00
|
|
|
|
$res = $messageController->saveChatroomMessage($chatroomMessage[0]);
|
2025-10-21 16:48:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (!empty($res)){
|
|
|
|
|
|
$msg = '消息记录成功';
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$msg = '消息记录失败';
|
2025-11-28 15:32:02 +08:00
|
|
|
|
$codee = 200;
|
2025-10-21 16:48:00 +08:00
|
|
|
|
}
|
2025-11-27 17:09:53 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 'CmdSendMessageResult':
|
|
|
|
|
|
$friendMessageId = $this->request->param('friendMessageId', 0);
|
|
|
|
|
|
$chatroomMessageId = $this->request->param('chatroomMessageId', 0);
|
|
|
|
|
|
$sendStatus = $this->request->param('sendStatus', null);
|
|
|
|
|
|
$wechatTime = $this->request->param('wechatTime', 0);
|
|
|
|
|
|
|
|
|
|
|
|
if ($sendStatus === null) {
|
|
|
|
|
|
return ResponseHelper::error('sendStatus不能为空');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($friendMessageId) && empty($chatroomMessageId)) {
|
|
|
|
|
|
return ResponseHelper::error('friendMessageId或chatroomMessageId至少提供一个');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$messageId = $friendMessageId ?: $chatroomMessageId;
|
|
|
|
|
|
$update = [
|
|
|
|
|
|
'sendStatus' => (int)$sendStatus,
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($wechatTime)) {
|
|
|
|
|
|
$update['wechatTime'] = strlen((string)$wechatTime) > 10
|
|
|
|
|
|
? intval($wechatTime / 1000)
|
|
|
|
|
|
: (int)$wechatTime;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$affected = WechatMessageModel::where('id', $messageId)->update($update);
|
|
|
|
|
|
|
|
|
|
|
|
if ($affected === false) {
|
2025-11-27 18:10:23 +08:00
|
|
|
|
return ResponseHelper::success('','更新消息状态失败');
|
2025-11-27 17:09:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($affected === 0) {
|
2025-11-27 18:10:23 +08:00
|
|
|
|
return ResponseHelper::success('','消息不存在');
|
2025-11-27 17:09:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$msg = '更新消息状态成功';
|
|
|
|
|
|
break;
|
2025-10-16 15:36:44 +08:00
|
|
|
|
}
|
2025-10-22 09:55:49 +08:00
|
|
|
|
return ResponseHelper::success('',$msg,$codee);
|
2025-10-16 15:36:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|