78 lines
2.2 KiB
PHP
78 lines
2.2 KiB
PHP
<?php
|
||
|
||
namespace app\chukebao\controller;
|
||
|
||
use library\ResponseHelper;
|
||
use think\Db;
|
||
|
||
/**
|
||
* 模块 J · 客户协同 / 同步 Outbox(需求八)
|
||
* 客户资料变更 → s2_wechat_friend + traffic_pool(best-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' => []]);
|
||
}
|
||
}
|