Selaa lähdekoodia

fix: 优化智能推送函数

carver 2 vuotta sitten
vanhempi
commit
518312206e

+ 24 - 0
antbuilder/core/utils/ywtService.js

@@ -1,4 +1,5 @@
 import { ywtRequest } from "./request";
+import { getAuthUser } from "../utils/jsapi";
 
 // 进行授权
 export async function ywtAuth(data) {
@@ -54,3 +55,26 @@ export async function submitAuthCode(data) {
 	if (err || !res) return [err, null];
 	return [null, res];
 }
+
+// 消息推送授权
+export async function getSubscribeAuth() {
+	const [err, authResult] = await getAuthUser(["auth_user", "hospital_order"]);
+	if (err) {
+		my.showToast({
+			type: "fail",
+			content: "智能消息推送授权失败",
+		});
+		return [err, null];
+	} else {
+		const [error, result] = await submitAuthCode({
+			authCode: authResult.authCode,
+		});
+		if (!error) {
+			my.showToast({
+				type: "success",
+				content: "消息订阅成功",
+			});
+		}
+		return [error, result];
+	}
+}

+ 3 - 24
antbuilder/industry/hospitalV2/components/appointment-result/index.js

@@ -4,8 +4,7 @@ import { cuttingDate } from "../../utils";
 import history from "../../utils/history";
 import { tradePay } from "../../utils/tradePay";
 import { reportApi } from "../../utils/cloudMonitorHelper";
-import { getAuthUser } from "../../../../core/utils/jsapi";
-import { submitAuthCode } from "../../../../core/utils/ywtService";
+import { getSubscribeAuth } from "../../../../core/utils/ywtService";
 Component({
 	props: {},
 	data: {
@@ -182,28 +181,8 @@ Component({
 
 		// 消息订阅授权
 		async grantSubscribe(orderId) {
-			// todo 添加智能推送接口
-			const [err, authResult] = await getAuthUser([
-				"auth_user",
-				"hospital_order",
-			]);
-			if (err) {
-				my.showToast({
-					type: "fail",
-					content: "智能消息推送授权失败",
-				});
-			} else {
-				const [error, result] = await submitAuthCode({
-					authCode: authResult.authCode,
-				});
-				if (!error) {
-					my.showToast({
-						type: "success",
-						content: "消息订阅成功",
-					});
-				}
-				return [error, result];
-			}
+			// 获取智能消息推送授权
+			await getSubscribeAuth();
 		},
 
 		// 发起倒计时

+ 3 - 23
antbuilder/industry/hospitalV2/components/hospital-payment-detail/index.js

@@ -2,8 +2,7 @@ import { payDetail } from "./service";
 import { tradePay } from "../../utils/tradePay";
 import history from "../../utils/history";
 import { reportApi, reportCmPV_YL } from "../../utils/cloudMonitorHelper";
-import { getAuthUser } from "../../../../core/utils/jsapi";
-import { submitAuthCode } from "../../../../core/utils/ywtService";
+import { getSubscribeAuth } from "../../../../core/utils/ywtService";
 Component({
 	props: {},
 	data: {
@@ -142,27 +141,8 @@ Component({
 			const { medicareBinded = false } = e.target.dataset;
 			const { order: oreder } = this.data;
 
-			const [err, authResult] = await getAuthUser([
-				"auth_user",
-				"hospital_order",
-			]);
-			if (err) {
-				my.showToast({
-					type: "fail",
-					content: "智能消息推送授权失败",
-				});
-			} else {
-				const [error, result] = await submitAuthCode({
-					authCode: authResult.authCode,
-				});
-				if (!error) {
-					my.showToast({
-						type: "success",
-						content: "消息订阅成功",
-					});
-				}
-				return [error, result];
-			}
+			// 获取智能消息推送授权
+			await getSubscribeAuth();
 
 			if (oreder.type === 1) {
 				await tradePay(

+ 3 - 23
antbuilder/industry/hospitalV2/components/hospital-payment/index.js

@@ -2,8 +2,7 @@ import { payHistory } from "./service";
 import history from "../../utils/history";
 import { tradePay } from "../../utils/tradePay";
 import { reportCmPV_YL } from "../../utils/cloudMonitorHelper";
-import { getAuthUser } from "../../../../core/utils/jsapi";
-import { submitAuthCode } from "../../../../core/utils/ywtService";
+import { getSubscribeAuth } from "../../../../core/utils/ywtService";
 Component({
 	props: {},
 	data: {
@@ -133,27 +132,8 @@ Component({
 		// 付款
 		async onPayment(e) {
 			const { medicareBinded = false, item } = e.target.dataset; // 同意订阅消息后发起支付
-			const [err, authResult] = await getAuthUser([
-				"auth_user",
-				"hospital_order",
-			]);
-			if (err) {
-				my.showToast({
-					type: "fail",
-					content: "智能消息推送授权失败",
-				});
-			} else {
-				const [error, result] = await submitAuthCode({
-					authCode: authResult.authCode,
-				});
-				if (!error) {
-					my.showToast({
-						type: "success",
-						content: "消息订阅成功",
-					});
-				}
-				return [error, result];
-			}
+			// 获取智能消息推送授权
+			await getSubscribeAuth();
 			// 挂号
 			if (item.type === 1) {
 				await tradePay(

+ 3 - 43
antbuilder/industry/hospitalV2/components/hospital-project/index.js

@@ -1,5 +1,4 @@
 import { createSubscribe } from "applet-page-component";
-import { getAuthUser } from "../../../../core/utils/jsapi";
 import {
 	getTestTimeList,
 	getQuestionnaire,
@@ -10,7 +9,7 @@ import { getPatientList } from "../edit-patient/service";
 import history from "../../utils/history";
 import { tradePay } from "../../utils/tradePay";
 import { reportCmPV_YL } from "../../utils/cloudMonitorHelper";
-import { submitAuthCode } from "../../../../core/utils/ywtService";
+import { getSubscribeAuth } from "../../../../core/utils/ywtService";
 const deptCodeMap = {
 	黄石总院: 500,
 	沙河分院: 499,
@@ -108,7 +107,6 @@ Component(
 				const { questionList: formList } = await getQuestionnaire({
 					hospitalDistrictId,
 				});
-				console.log("query", query);
 				my.showLoading();
 				const projects = await getItemList({
 					hospitalDistrictId,
@@ -297,26 +295,8 @@ Component(
 						doctorCode,
 						fee,
 					}); // 区分支持线上支付 和 不支持线上支付
-					const [err, authResult] = await getAuthUser([
-						"auth_user",
-						"hospital_order",
-					]);
-					if (err) {
-						my.showToast({
-							type: "fail",
-							content: "智能消息推送授权失败",
-						});
-					} else {
-						const [error, result] = await submitAuthCode({
-							authCode: authResult.authCode,
-						});
-						if (!error) {
-							my.showToast({
-								type: "success",
-								content: "消息订阅成功",
-							});
-						}
-					}
+					// 获取智能消息推送授权
+					await getSubscribeAuth();
 					if (res.amount && onlinePay) {
 						// const orderRes = await tradeNoQuery({
 						//   type: 1,
@@ -353,26 +333,6 @@ Component(
 							}
 						)
 							.then(async () => {
-								const [err, authResult] = await getAuthUser([
-									"auth_user",
-									"hospital_order",
-								]);
-								if (err) {
-									my.showToast({
-										type: "fail",
-										content: "智能消息推送授权失败",
-									});
-								} else {
-									const [error, result] = await submitAuthCode({
-										authCode: authResult.authCode,
-									});
-									if (!error) {
-										my.showToast({
-											type: "success",
-											content: "消息订阅成功",
-										});
-									}
-								}
 								history.replace({
 									query: {
 										hospitalDistrictId,