| | |
| | |
|
| | | import Taro from "@tarojs/taro";
|
| | | import { checkOtp } from "./tools";
|
| | | import { saveUserSubscribeMessage } from "../robotaxi/api/subscribe"; |
| | | import { saveUserSubscribeMessage } from "../robotaxi/api/subscribe";
|
| | | import {
|
| | | OPERATION_COUPON_SUBSCRIBE_CONFIG,
|
| | | ORDER_SUCCESS_SUBSCRIBE_CONFIG,
|
| | |
| | | return `${sceneKey}_${bizId}`;
|
| | | }
|
| | |
|
| | | /** |
| | | * 从订阅结果中提取用户同意(accept)的模板 ID。 |
| | | */ |
| | | function getAcceptedTemplateIds(tmplIds: string[], result: Record<string, string>) { |
| | | return tmplIds.filter((id) => result?.[id] === 'accept'); |
| | | } |
| | | |
| | | /** |
| | | * 用户同意订阅后上报后端(失败不影响主流程)。 |
| | | */ |
| | | async function saveAcceptedSubscribeTemplates(templateIds: string[]) { |
| | | if (!Array.isArray(templateIds) || templateIds.length === 0) return; |
| | | try { |
| | | const loginRes = await Taro.login(); |
| | | const jscode = loginRes?.code; |
| | | if (!jscode) return; |
| | | await saveUserSubscribeMessage({ |
| | | templateIds, |
| | | jscode |
| | | }); |
| | | } catch (error) { |
| | | } |
| | | } |
| | | |
| | | /**
|
| | | * 从订阅结果中提取用户同意(accept)的模板 ID。
|
| | | */
|
| | | function getAcceptedTemplateIds(tmplIds: string[], result: Record<string, string>) {
|
| | | return tmplIds.filter((id) => result?.[id] === 'accept');
|
| | | }
|
| | |
|
| | | /**
|
| | | * 用户同意订阅后上报后端(失败不影响主流程)。
|
| | | */
|
| | | async function saveAcceptedSubscribeTemplates(templateIds: string[]) {
|
| | | if (!Array.isArray(templateIds) || templateIds.length === 0) return;
|
| | | try {
|
| | | const loginRes = await Taro.login();
|
| | | const jscode = loginRes?.code;
|
| | | if (!jscode) return;
|
| | | await saveUserSubscribeMessage({
|
| | | templateIds,
|
| | | jscode
|
| | | });
|
| | | } catch (error) {
|
| | | }
|
| | | }
|
| | |
|
| | | // 执行通用订阅流程(失败/拒绝不影响主流程)
|
| | | export async function runSubscribeScene(config: SubscribeSceneConfig, bizId?: string | number) {
|
| | | try {
|
| | |
| | | tmplIds: config.tmplIds,
|
| | | success: (result) => {
|
| | | checkSubscribeStatus(type, config.tmplIds, result, config.limit);
|
| | | const acceptedTemplateIds = getAcceptedTemplateIds(config.tmplIds, result as Record<string, string>); |
| | | void saveAcceptedSubscribeTemplates(acceptedTemplateIds); |
| | | const acceptedTemplateIds = getAcceptedTemplateIds(config.tmplIds, result as Record<string, string>);
|
| | | void saveAcceptedSubscribeTemplates(acceptedTemplateIds);
|
| | | resolve();
|
| | | },
|
| | | fail: () => {
|