测试
This commit is contained in:
@@ -450,9 +450,11 @@ class MessageController extends BaseController
|
||||
*/
|
||||
public function saveChatroomMessage($item)
|
||||
{
|
||||
// 检查消息是否已存在
|
||||
$exists = WechatMessageModel::where('id', $item['id'])->find();
|
||||
// 检查消息是否已存在(必须指定 type=2 表示群聊消息)
|
||||
$exists = WechatMessageModel::where(['id' => $item['id'], 'type' => 2])->find();
|
||||
|
||||
// 如果消息已存在且 sendStatus == 0(已发送),则跳过更新
|
||||
// 注意:这里只跳过已发送的消息,未发送的消息(sendStatus != 0)仍然需要更新
|
||||
if (!empty($exists) && $exists['sendStatus'] == 0){
|
||||
return true;
|
||||
}
|
||||
@@ -503,16 +505,29 @@ class MessageController extends BaseController
|
||||
'recallId' => $item['recallId'] ?? false
|
||||
];
|
||||
|
||||
// 创建新记录
|
||||
// 创建或更新记录
|
||||
try {
|
||||
if(empty($exists)){
|
||||
WechatMessageModel::create($data);
|
||||
// 新记录,直接创建
|
||||
$result = WechatMessageModel::create($data);
|
||||
if (!$result) {
|
||||
throw new \Exception('创建群聊消息记录失败');
|
||||
}
|
||||
}else{
|
||||
// 已存在记录,更新(排除 id 字段)
|
||||
unset($data['id']);
|
||||
$exists->save($data);
|
||||
$result = $exists->save($data);
|
||||
if ($result === false) {
|
||||
throw new \Exception('更新群聊消息记录失败');
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
// 记录错误日志,便于调试
|
||||
\think\facade\Log::error('保存群聊消息失败:' . $e->getMessage(), [
|
||||
'message_id' => $item['id'] ?? '',
|
||||
'data' => $data ?? []
|
||||
]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user