新版流量池服务端提交
This commit is contained in:
@@ -6,6 +6,8 @@ use library\ResponseHelper;
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use app\cunkebao\service\DistributionRewardService;
|
||||
use app\cunkebao\service\TrafficPoolService;
|
||||
use app\common\model\TrafficPoolSource;
|
||||
|
||||
/**
|
||||
* 对外API接口控制器
|
||||
@@ -95,27 +97,28 @@ class PostExternalApiV1Controller extends Controller
|
||||
// 渠道ID(cid),对应 distribution_channel.id
|
||||
$channelId = !empty($params['cid']) ? intval($params['cid']) : 0;
|
||||
|
||||
|
||||
$trafficPool = Db::name('traffic_pool_v1')->where('identifier', $identifier)->find();
|
||||
if (!$trafficPool) {
|
||||
$trafficPoolId =Db::name('traffic_pool_v1')->insertGetId([
|
||||
'identifier' => $identifier,
|
||||
'mobile' => !empty($params['phone']) ? $params['phone'] : '',
|
||||
'createTime' => time()
|
||||
]);
|
||||
}else{
|
||||
$trafficPoolId = $trafficPool['id'];
|
||||
}
|
||||
// ========== 旧版流量池代码(已废弃,保留用于兼容) ==========
|
||||
// $trafficPool = Db::name('traffic_pool_v1')->where('identifier', $identifier)->find();
|
||||
// if (!$trafficPool) {
|
||||
// $trafficPoolId =Db::name('traffic_pool_v1')->insertGetId([
|
||||
// 'identifier' => $identifier,
|
||||
// 'mobile' => !empty($params['phone']) ? $params['phone'] : '',
|
||||
// 'createTime' => time()
|
||||
// ]);
|
||||
// }else{
|
||||
// $trafficPoolId = $trafficPool['id'];
|
||||
// }
|
||||
// ========== 旧版流量池代码结束 ==========
|
||||
|
||||
$taskCustomer = Db::name('task_customer')
|
||||
->where('task_id', $plan['id'])
|
||||
->where('phone', $identifier)
|
||||
->find();
|
||||
|
||||
// 处理用户画像
|
||||
if(!empty($params['portrait']) && is_array($params['portrait'])){
|
||||
$this->updatePortrait($params['portrait'],$trafficPoolId,$plan['companyId']);
|
||||
}
|
||||
// 处理用户画像(已迁移到V2流量池,此处保留兼容)
|
||||
// if(!empty($params['portrait']) && is_array($params['portrait'])){
|
||||
// $this->updatePortrait($params['portrait'],$trafficPoolId,$plan['companyId']);
|
||||
// }
|
||||
if (!$taskCustomer) {
|
||||
$tags = !empty($params['tags']) ? explode(',', $params['tags']) : [];
|
||||
$siteTags = !empty($params['siteTags']) ? explode(',', $params['siteTags']) : [];
|
||||
@@ -154,6 +157,60 @@ class PostExternalApiV1Controller extends Controller
|
||||
'createTime' => time(),
|
||||
]);
|
||||
|
||||
// 实时同步到 V2 流量池系统(异步处理,不影响主流程)
|
||||
if ($customerId) {
|
||||
try {
|
||||
$poolService = new TrafficPoolService();
|
||||
|
||||
// 判断 identifier 类型:手机号还是微信号
|
||||
$identifierType = 2; // 默认手机号
|
||||
$isPhone = preg_match('/^\+?\d{6,}$/', $identifier);
|
||||
if (!$isPhone && !empty($params['wechatId'])) {
|
||||
$identifierType = 1; // 微信号
|
||||
}
|
||||
|
||||
// 准备流量池数据
|
||||
$poolData = [
|
||||
'identifierType' => $identifierType,
|
||||
'mobile' => !empty($params['phone']) ? $params['phone'] : ($isPhone ? $identifier : ''),
|
||||
'wechatId' => !empty($params['wechatId']) ? $params['wechatId'] : (!$isPhone ? $identifier : ''),
|
||||
'nickname' => !empty($params['name']) ? $params['name'] : '',
|
||||
];
|
||||
|
||||
// 准备公司流量数据
|
||||
$companyData = [
|
||||
'phone' => !empty($params['phone']) ? $params['phone'] : ($isPhone ? $identifier : ''),
|
||||
'realName' => !empty($params['name']) ? $params['name'] : '',
|
||||
'remark' => !empty($params['remark']) ? $params['remark'] : '',
|
||||
];
|
||||
|
||||
// 准备来源数据
|
||||
$sourceData = [
|
||||
'sourceName' => !empty($params['source']) ? $params['source'] : ('场景获客_' . $plan['name']),
|
||||
'remark' => !empty($params['remark']) ? $params['remark'] : '',
|
||||
'extra' => json_encode([
|
||||
'planId' => $plan['id'],
|
||||
'planName' => $plan['name'],
|
||||
'channelId' => $finalChannelId,
|
||||
'customerId' => $customerId,
|
||||
], JSON_UNESCAPED_UNICODE),
|
||||
];
|
||||
|
||||
// 同步到 V2 流量池
|
||||
$poolService->enterPool(
|
||||
$identifier,
|
||||
$plan['companyId'],
|
||||
TrafficPoolSource::SOURCE_TYPE_API, // API导入
|
||||
$poolData,
|
||||
$companyData,
|
||||
$sourceData
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
// 记录错误但不影响主流程
|
||||
\think\facade\Log::error('同步到V2流量池失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 记录获客奖励(异步处理,不影响主流程)
|
||||
if ($customerId) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user