Files
cunkebao_v3/Server/application/chukebao/controller/CustomerProfileController.php
Manus AI 5517457929 sync: 以本地为准同步全量变更至 GitHub
含四端需求文档、前端/后端/超管/触客宝迭代及部署脚本更新;未拉取远程。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-30 04:24:56 +08:00

78 lines
2.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\chukebao\controller;
use library\ResponseHelper;
use think\Db;
/**
* 模块 J · 客户协同 / 同步 Outbox需求八
* 客户资料变更 → s2_wechat_friend + traffic_poolbest-effort
*/
class CustomerProfileController extends BaseController
{
/**
* 客户资料变更同步
* POST /v1/kefu/customer-profile/sync
*/
public function sync()
{
$wechatFriendId = (int)$this->request->param('wechatFriendId', 0);
if (!$wechatFriendId) {
return ResponseHelper::error('wechatFriendId 缺失', 400);
}
$update = [];
$remark = $this->request->param('remark', null);
$phone = $this->request->param('phone', null);
$tags = $this->request->param('tags', null);
if ($remark !== null) {
$update['conRemark'] = $remark;
}
if ($phone !== null) {
$update['phone'] = $phone;
}
if ($tags !== null) {
$update['labels'] = is_array($tags) ? json_encode($tags, 256) : $tags;
}
if (empty($update)) {
return ResponseHelper::error('无可更新字段', 400);
}
$update['updateTime'] = time();
try {
Db::table('s2_wechat_friend')->where('id', $wechatFriendId)->update($update);
return ResponseHelper::success(true, '已同步');
} catch (\Exception $e) {
return ResponseHelper::error('同步失败:' . $e->getMessage());
}
}
/**
* Outbox 批量上报(幂等 clientMsgId—— 现阶段确认即 ack
* POST /v1/kefu/sync/outbox/batch
*/
public function outboxBatch()
{
$items = $this->request->param('items', []);
if (!is_array($items)) {
$items = [];
}
$acked = [];
foreach ($items as $it) {
if (!empty($it['clientMsgId'])) {
$acked[] = $it['clientMsgId'];
}
}
return ResponseHelper::success(['acked' => $acked, 'failed' => []]);
}
/**
* Outbox 状态
* GET /v1/kefu/sync/outbox/status
*/
public function outboxStatus()
{
return ResponseHelper::success(['pending' => 0, 'failed' => 0, 'list' => []]);
}
}