hookehuyr

feat(预约): 添加时段类型支持并优化支付逻辑

添加 period_type 字段以区分日常和春节预约时段
修改支付逻辑以接口返回的 need_pay 为准判断是否需要支付
<!--
* @Date: 2024-01-15 13:35:51
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-01-15 16:47:29
* @LastEditTime: 2026-01-16 17:33:27
* @FilePath: /xyxBooking-weapp/src/pages/booking/index.vue
* @Description: 预约页面
-->
......@@ -234,9 +234,10 @@ const chooseDay = async (date) => { // 点击日期回调
// 如果可约,查询时间段信息
if (info.reserve_full === ReserveStatus.AVAILABLE) {
// 选择日期后,查询时间段信息
const { code, data } = await canReserveTimeListAPI({ month_date: checked_day.value});
const { code, data } = await canReserveTimeListAPI({ month_date: checked_day.value });
if (code) {
// rest_qty >0表示有余量,可约;=0表示没有余量,不可约;<0表示不限,可约;
// period_type 时段类型 REGULAR=日常预约,SPRING_FESTIVAL=春节预约
timePeriod.value = data;
checked_time.value = -1; // 重置已选择的时间段
}
......@@ -293,7 +294,7 @@ const nextBtn = () => {
if (!checked_day.value || checked_time.value === -1) {
Taro.showToast({ title: '请选择日期和时间段', icon: 'none' });
} else {
go('/submit', { date: checked_day.value, time: `${timePeriod.value[checked_time.value]['begin_time'].slice(0, -3)}-${timePeriod.value[checked_time.value]['end_time'].slice(0, -3)}`, price: checked_day_price.value });
go('/submit', { date: checked_day.value, time: `${timePeriod.value[checked_time.value]['begin_time'].slice(0, -3)}-${timePeriod.value[checked_time.value]['end_time'].slice(0, -3)}`, price: checked_day_price.value, period_type: timePeriod.value[checked_time.value].period_type });
}
}
</script>
......
<!--
* @Date: 2024-01-15 16:25:51
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-01-16 16:13:44
* @LastEditTime: 2026-01-16 17:29:46
* @FilePath: /xyxBooking-weapp/src/pages/submit/index.vue
* @Description: 预约人员信息
-->
......@@ -71,6 +71,7 @@ const visitorList = ref([]);
const date = ref('');
const time = ref('');
const price = ref(0);
const period_type = ref('');
/**
* 生成15位身份证号中间8位替换为*号
......@@ -124,6 +125,7 @@ const goToVisitor = () => {
// 待支付订单ID
const pending_pay_id = ref(null);
const pending_need_pay = ref(null);
const submitBtn = async () => {
if (!checked_visitors.value.length) {
......@@ -132,6 +134,7 @@ const submitBtn = async () => {
}
let pay_id = pending_pay_id.value;
let need_pay = pending_need_pay.value;
if (!pay_id) { // TAG: 提交订单, 如果没有待支付订单ID, 则创建一个新的订单
Taro.showLoading({ title: '提交中...' });
......@@ -139,20 +142,23 @@ const submitBtn = async () => {
reserve_date: date.value,
begin_time: time.value.split('-')[0],
end_time: time.value.split('-')[1],
person_id_list: JSON.stringify(checked_visitors.value)
person_id_list: JSON.stringify(checked_visitors.value),
period_type: period_type.value
});
Taro.hideLoading();
if (!code || code !== 1) {
if (code != 1) {
return;
}
pay_id = data.pay_id;
pending_pay_id.value = pay_id;
need_pay = data?.need_pay;
pending_need_pay.value = need_pay;
}
// 如果金额大于零, 走微信支付, 如果等于零直接跳转成功页
if (total.value > 0) {
// 以接口返回的 need_pay 为准:1=需要支付,0=不需要支付
if (Number(need_pay) === 1 || need_pay === true) {
Taro.showLoading({ title: '支付准备中...' });
const payParams = await wxPayAPI({ pay_id }); // 参数接口
Taro.hideLoading();
......@@ -166,6 +172,8 @@ const submitBtn = async () => {
signType: pay_params.signType,
paySign: pay_params.paySign,
success(res) {
pending_pay_id.value = null;
pending_need_pay.value = null;
go('/success', { pay_id });
},
fail(res) {
......@@ -176,10 +184,12 @@ const submitBtn = async () => {
})
} else {
pending_pay_id.value = null; // 支付参数获取失败,重置订单ID
pending_need_pay.value = null;
Taro.showToast({ title: payParams.msg || '获取支付信息失败', icon: 'none' });
}
} else {
// 金额等于零, 直接跳转成功页
pending_pay_id.value = null;
pending_need_pay.value = null;
go('/success', { pay_id });
}
}
......@@ -189,9 +199,10 @@ useDidShow(async () => {
date.value = params.date || '';
time.value = params.time || '';
price.value = params.price || 0;
period_type.value = params.period_type || '';
if (date.value && time.value) {
const { code, data } = await personListAPI({ reserve_date: date.value, begin_time: time.value.split('-')[0], end_time: time.value.split('-')[1] });
const { code, data } = await personListAPI({ reserve_date: date.value, begin_time: time.value.split('-')[0], end_time: time.value.split('-')[1], period_type: period_type.value });
if (code) {
visitorList.value = data || [];
}
......