| | |
| | | |
| | | const router = Taro.useRouter(); |
| | | const { blLifeRecharge } = useLifeRechargeContext(); |
| | | |
| | | const channelConsultationId = router.params?.channelConsultationId ?? ''; |
| | | console.log('channelConsultationId: ', channelConsultationId); |
| | | const consultationId = router.params?.consultationId ?? ''; |
| | | |
| | | async function getPromoter(phoneNumber: string) { |
| | | try { |
| | |
| | | async function getChannelConsultationById() { |
| | | try { |
| | | let params: APIgetChannelConsultationByIdParams = { |
| | | id: channelConsultationId, |
| | | id: consultationId, |
| | | }; |
| | | return await blLifeRecharge.services.getChannelConsultationById(params); |
| | | } catch (error) {} |
| | | } |
| | | |
| | | async function createOrUpdatePromoter(name: string, phoneNumber: string) { |
| | | type CreateOrUpdatePromoterOptions = { |
| | | name?: string; |
| | | phoneNumber?: string; |
| | | }; |
| | | |
| | | async function createOrUpdatePromoter(options: CreateOrUpdatePromoterOptions = {}) { |
| | | try { |
| | | const { name, phoneNumber } = options; |
| | | let params: CreateOrUpdatePromoterInput = { |
| | | userId: blLifeRecharge.accountModel.userId, |
| | | name: name, |
| | |
| | | |
| | | async function generate() { |
| | | try { |
| | | if (channelConsultationId) { |
| | | if (consultationId) { |
| | | let res = await getChannelConsultationById(); |
| | | if (res) { |
| | | let promoterIdNumber = await getPromoter(res.phoneNumber); |
| | | if (promoterIdNumber) { |
| | | RouteHelper.navigateTo({ |
| | | url: `${RouterPath.promotionQrcode}?promoterIdNumber=${promoterIdNumber}`, |
| | | }); |
| | | let promoterRes = await getPromoter(res.phoneNumber); |
| | | let idNumber: string; |
| | | if (promoterRes?.idNumber) { |
| | | idNumber = promoterRes.idNumber; |
| | | } else { |
| | | let promoterIdNumber = await createOrUpdatePromoter(res.name, res.phoneNumber); |
| | | if (promoterIdNumber) { |
| | | RouteHelper.navigateTo({ |
| | | url: `${RouterPath.promotionQrcode}?promoterIdNumber=${res}`, |
| | | }); |
| | | let createOrUpdatePromoterRes = await createOrUpdatePromoter({ |
| | | name: res.name, |
| | | phoneNumber: res.phoneNumber, |
| | | }); |
| | | idNumber = createOrUpdatePromoterRes.idNumber; |
| | | } |
| | | if (idNumber) { |
| | | if (res.phoneNumber === blLifeRecharge.accountModel.phoneNumber) { |
| | | blLifeRecharge.accountModel.setUserPromoterIdNumber(idNumber); |
| | | } |
| | | RouteHelper.navigateTo({ |
| | | url: `${RouterPath.promotionQrcode}?promoterIdNumber=${idNumber}`, |
| | | }); |
| | | } |
| | | } |
| | | } else { |
| | | } |
| | | } catch (error) {} |
| | | } |