手动录入表单新增备注功能
This commit is contained in:
@@ -148,11 +148,11 @@ class PosterWeChatMiniProgram extends Controller
|
||||
{
|
||||
|
||||
$taskId = request()->param('id');
|
||||
$phoneData = request()->param('phone');
|
||||
if (!$phoneData) {
|
||||
$rawInput = trim((string)request()->param('phone', ''));
|
||||
if ($rawInput === '') {
|
||||
return json([
|
||||
'code' => 400,
|
||||
'message' => '手机号不能为空'
|
||||
'message' => '手机号或微信号不能为空'
|
||||
]);
|
||||
}
|
||||
$task = Db::name('customer_acquisition_task')->where('id', $taskId)->find();
|
||||
@@ -165,31 +165,69 @@ class PosterWeChatMiniProgram extends Controller
|
||||
}
|
||||
|
||||
|
||||
$phoneData = explode("\n", $phoneData);
|
||||
foreach ($phoneData as $phone) {
|
||||
if (empty($phone)) {
|
||||
$lines = preg_split('/\r\n|\r|\n/', $rawInput);
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
if ($line === '') {
|
||||
continue;
|
||||
}
|
||||
$trafficPool = Db::name('traffic_pool')->where('identifier', $phone)->find();
|
||||
$parts = array_map('trim', explode(',', $line, 2));
|
||||
$identifier = $parts[0] ?? '';
|
||||
$remark = $parts[1] ?? '';
|
||||
if ($identifier === '') {
|
||||
continue;
|
||||
}
|
||||
$isPhone = preg_match('/^\+?\d{6,}$/', $identifier);
|
||||
$trafficPool = Db::name('traffic_pool')->where('identifier', $identifier)->find();
|
||||
if (!$trafficPool) {
|
||||
Db::name('traffic_pool')->insert([
|
||||
'identifier' => $phone,
|
||||
'mobile' => $phone,
|
||||
$insertData = [
|
||||
'identifier' => $identifier,
|
||||
'createTime' => time()
|
||||
]);
|
||||
];
|
||||
if ($isPhone) {
|
||||
$insertData['mobile'] = $identifier;
|
||||
} else {
|
||||
$insertData['wechatId'] = $identifier;
|
||||
}
|
||||
Db::name('traffic_pool')->insert($insertData);
|
||||
} else {
|
||||
$updates = [];
|
||||
if ($isPhone && empty($trafficPool['mobile'])) {
|
||||
$updates['mobile'] = $identifier;
|
||||
}
|
||||
if (!$isPhone && empty($trafficPool['wechatId'])) {
|
||||
$updates['wechatId'] = $identifier;
|
||||
}
|
||||
if (!empty($updates)) {
|
||||
$updates['updateTime'] = time();
|
||||
Db::name('traffic_pool')->where('id', $trafficPool['id'])->update($updates);
|
||||
}
|
||||
}
|
||||
|
||||
$taskCustomer = Db::name('task_customer')->where('task_id', $taskId)->where('phone', $phone)->find();
|
||||
$taskCustomer = Db::name('task_customer')
|
||||
->where('task_id', $taskId)
|
||||
->where('phone', $identifier)
|
||||
->find();
|
||||
if (empty($taskCustomer)) {
|
||||
Db::name('task_customer')->insert([
|
||||
$insertCustomer = [
|
||||
'task_id' => $taskId,
|
||||
// 'identifier' => $phone,
|
||||
'phone' => $phone,
|
||||
'phone' => $identifier,
|
||||
'source' => $task['name'],
|
||||
'createTime' => time(),
|
||||
'tags' => json_encode([]),
|
||||
'siteTags' => json_encode([]),
|
||||
]);
|
||||
];
|
||||
if ($remark !== '') {
|
||||
$insertCustomer['remark'] = $remark;
|
||||
}
|
||||
Db::name('task_customer')->insert($insertCustomer);
|
||||
} elseif ($remark !== '' && $taskCustomer['remark'] !== $remark) {
|
||||
Db::name('task_customer')
|
||||
->where('id', $taskCustomer['id'])
|
||||
->update([
|
||||
'remark' => $remark,
|
||||
'updateTime' => time()
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user