initialize(); $args = []; foreach ($argv as $arg) { if (strpos($arg, '=') !== false) { [$k, $v] = explode('=', $arg, 2); $args[trim($k)] = trim($v); } } $phone = $args['phone'] ?? '15880802661'; $apply = !empty($args['apply']); $mode = $apply ? '【APPLY】' : '【DRY-RUN】'; $user = Db::name('users') ->where('phone', $phone) ->whereOr('account', $phone) ->find(); if (!$user) { fwrite(STDERR, "未找到手机号 {$phone}\n"); exit(1); } $targetCompanyId = (int)$user['companyId']; $userId = (int)$user['id']; echo "{$mode} phone={$phone} userId={$userId} targetCompanyId={$targetCompanyId}\n"; $sceneExists = Db::name('plan_scene')->where('id', 12)->where('deleteTime', 0)->find(); if (!$sceneExists) { echo " · 将插入 ck_plan_scene id=12 网站获客\n"; if ($apply) { Db::name('plan_scene')->insert([ 'id' => 12, 'name' => '网站获客', 'description' => '存客宝官网/落地页 POST /v1/api/scenarios 留资', 'image' => '', 'status' => 1, 'sort' => 72, 'scenarioTags' => '[]', 'createTime' => time(), 'updateTime' => time(), 'deleteTime' => 0, ]); } } else { echo " · ck_plan_scene id=12 已存在: {$sceneExists['name']}\n"; if ($apply && ($sceneExists['name'] ?? '') !== '网站获客') { Db::name('plan_scene')->where('id', 12)->update([ 'name' => '网站获客', 'updateTime' => time(), ]); echo " · 已更名 scene 12 → 网站获客\n"; } if ($apply && (int)$sceneExists['status'] !== 1) { Db::name('plan_scene')->where('id', 12)->update(['status' => 1, 'updateTime' => time()]); echo " · 已开启 scene 12 status=1\n"; } } $planQuery = Db::name('customer_acquisition_task') ->where('deleteTime', 0) ->where(function ($q) { $q->where('id', 779) ->whereOr('name', 'like', '存客宝官网%') ->whereOr('name', 'like', '%试用咨询留资%'); }); $plans = $planQuery->field('id,name,companyId,sceneId,status,userId')->select(); echo ' · 命中计划 ' . count($plans) . " 条\n"; foreach ($plans as $p) { $p = is_array($p) ? $p : $p->toArray(); echo sprintf( " #%d %s | company %d→%d scene %d→12\n", (int)$p['id'], $p['name'], (int)$p['companyId'], $targetCompanyId, (int)$p['sceneId'] ); } if ($apply && count($plans) > 0) { $ids = array_column($plans, 'id'); Db::name('customer_acquisition_task') ->whereIn('id', $ids) ->update([ 'sceneId' => 12, 'companyId' => $targetCompanyId, 'userId' => $userId, 'updateTime' => time(), ]); echo " · 已更新 " . count($ids) . " 条计划\n"; } echo "完成。\n";