fix(admin): 锁定已收款支付信息并支持人工退款核销

- 已收款/退款中订单禁止编辑支付状态、金额与支付方式,避免覆盖退款状态
- 退款中订单新增「确认已退款」入口,线下退款可核销为已退款
- 线上退款仍保留查询退款结果兜底
This commit is contained in:
lik
2026-11-06 17:30:29 +08:00
parent 4cbf6e7906
commit bfe820aa31
5 changed files with 64 additions and 12 deletions
+41 -2
View File
@@ -89,7 +89,9 @@ Page({
paymentMethodText: '',
payChannelText: '',
showQueryRefundBtn: false,
showManualRefundBtn: false,
queryingRefund: false,
completingRefund: false,
attendantSexText: '',
sexRequirementText: '',
// 操作按钮配置
@@ -164,9 +166,13 @@ Page({
paymentStatusText: PAYMENT_STATUS_MAP[payment.status] || payment.status || '未支付',
paymentMethodText: PAYMENT_METHOD_MAP[payment.method] || '',
payChannelText: PAY_CHANNEL_MAP[payment.payChannel || 'offline'] || '',
// 退款回调丢失时由管理端主动查退款补写终态
showQueryRefundBtn: payment.status === 'refunding',
// 线上退款:回调丢失时由管理端主动查退款补写终态;
// 人工核销:线下退款、或历史手工标记「线上微信」但无退款单的订单;
// 后端在存在处理中的线上退款时会拒绝,避免误把微信退款标成已完成
showQueryRefundBtn: payment.status === 'refunding' && payment.method === 'online_wechat',
showManualRefundBtn: payment.status === 'refunding',
queryingRefund: false,
completingRefund: false,
attendantSexText: attendant.sex === 'male' ? '男' : attendant.sex === 'female' ? '女' : '',
sexRequirementText: escort.sexRequirement === 'male' ? '要求男陪诊' : escort.sexRequirement === 'female' ? '要求女陪诊' : '不限',
// 操作按钮(任何状态下均可编辑订单信息)
@@ -292,6 +298,39 @@ Page({
}
},
// 线下/人工退款:平台确认已退款后核销,避免订单永远停在「退款中」
onCompleteManualRefund() {
if (this.data.completingRefund) return
wx.showModal({
title: '确认退款完成',
content: '请确认已通过现金/转账等方式将款项退还给用户,操作后订单将显示「已退款」。',
success: (modal) => {
if (modal.confirm) this.doCompleteManualRefund()
}
})
},
async doCompleteManualRefund() {
this.setData({ completingRefund: true })
wx.showLoading({ title: '处理中...' })
try {
const res = await API.escort.completeManualRefund(this.data.orderId)
wx.hideLoading()
if (res.code !== 0) {
wx.showToast({ title: res.msg || '操作失败', icon: 'none' })
return
}
wx.showToast({ title: '已标记退款完成', icon: 'success' })
this.loadOrderDetail(this.data.orderId)
} catch (err) {
wx.hideLoading()
console.error('人工核销退款失败', err)
wx.showToast({ title: '网络错误', icon: 'none' })
} finally {
this.setData({ completingRefund: false })
}
},
async updateStatus(newStatus) {
wx.showLoading({ title: '处理中...' })
try {
+2 -1
View File
@@ -190,8 +190,9 @@
</view>
<!-- 底部操作 -->
<view class="bottom-actions" wx:if="{{showEditBtn || showConfirmBtn || showCancelBtn || showStartBtn || showCompleteBtn || showQueryRefundBtn}}">
<view class="bottom-actions" wx:if="{{showEditBtn || showConfirmBtn || showCancelBtn || showStartBtn || showCompleteBtn || showQueryRefundBtn || showManualRefundBtn}}">
<view class="action-btn btn-ghost" wx:if="{{showQueryRefundBtn}}" bindtap="onQueryRefund">查询退款结果</view>
<view class="action-btn btn-ghost" wx:if="{{showManualRefundBtn}}" bindtap="onCompleteManualRefund">确认已退款</view>
<view class="action-btn btn-ghost" wx:if="{{showEditBtn}}" bindtap="onEdit">编辑订单</view>
<view class="action-btn btn-ghost" wx:if="{{showCancelBtn}}" bindtap="onCancel">{{cancelBtnText}}</view>
<view class="action-btn btn-solid" wx:if="{{showConfirmBtn}}" bindtap="onConfirm">确认订单</view>
+15 -6
View File
@@ -42,6 +42,8 @@ Page({
methodLabel: '',
// 存在未支付流水时金额锁定:需先关单/取消后再改价
amountLocked: false,
// 已收款/退款中的订单锁定支付信息,避免把退款状态改回未支付后被重复收款
paymentLocked: false,
today: '',
submitting: false
},
@@ -181,10 +183,13 @@ Page({
const sexLabel = p.sex === 'male' ? '男' : (p.sex === 'female' ? '女' : '')
const age = calcAge(p.birth)
this.originalTotalFee = Number(order.payment && order.payment.totalFee) || 0
const amountLocked = (order.payment?.status || 'unpaid') === 'unpaid'
&& !!order.payment?.paymentRecordId
const payStatus = (order.payment && order.payment.status) || 'unpaid'
const paymentLocked = ['partial', 'paid', 'refunding', 'refunded'].includes(payStatus)
const amountLocked = paymentLocked
|| (payStatus === 'unpaid' && !!order.payment?.paymentRecordId)
this.setData({
amountLocked,
paymentLocked,
// 有关联档案时交由 patient-info 按 ID 加载(不读缓存,以档案最新数据为准)
profileId: order.healthProfileId || '',
// 无关联档案时用订单 patient 快照兜底展示姓名/性别/年龄/电话;
@@ -494,15 +499,19 @@ Page({
'schedule.startTime': form.schedule.startTime || '',
'escort.serviceId': form.escort.serviceId || -1,
'escort.serviceName': form.escort.serviceName,
'payment.totalFee': form.payment.totalFee ? Number(form.payment.totalFee) : 0,
'payment.method': form.payment.method || '',
'payment.paidFee': form.payment.paid ? (form.payment.totalFee ? Number(form.payment.totalFee) : 0) : 0,
'payment.status': form.payment.paid ? 'paid' : 'unpaid',
'notes.patientNote': form.notes.patientNote,
'inquiry.medicalHistory': form.inquiry.medicalHistory,
'inquiry.demand': form.inquiry.demand
}
// 已收款/退款中的订单不回传 payment:回传旧值会把退款状态覆盖成 unpaid/paid
if (!this.data.paymentLocked) {
payload['payment.totalFee'] = form.payment.totalFee ? Number(form.payment.totalFee) : 0
payload['payment.method'] = form.payment.method || ''
payload['payment.paidFee'] = form.payment.paid ? (form.payment.totalFee ? Number(form.payment.totalFee) : 0) : 0
payload['payment.status'] = form.payment.paid ? 'paid' : 'unpaid'
}
this.setData({ submitting: true })
wx.showLoading({ title: '保存中...' })
+4 -3
View File
@@ -104,20 +104,21 @@
<view class="field">
<text class="field-label">费用(元)</text>
<input class="field-input" type="digit" placeholder="请输入服务费用" value="{{form.payment.totalFee}}" data-key="payment.totalFee" bindinput="onInput" disabled="{{amountLocked}}" />
<text class="field-tip" wx:if="{{amountLocked}}">存在未支付流水,金额已锁定</text>
<text class="field-tip" wx:if="{{paymentLocked}}">已收款订单支付信息已锁定,退款请走取消流程</text>
<text class="field-tip" wx:elif="{{amountLocked}}">存在未支付流水,金额已锁定</text>
</view>
<view class="field">
<text class="field-label">是否已支付</text>
<view class="field-switch">
<text class="switch-label {{form.payment.paid ? 'paid' : 'unpaid'}}">{{form.payment.paid ? '已支付' : '未支付'}}</text>
<switch checked="{{form.payment.paid}}" color="#17c3a5" bindchange="onPaidChange" />
<switch checked="{{form.payment.paid}}" color="#17c3a5" disabled="{{paymentLocked}}" bindchange="onPaidChange" />
</view>
</view>
<view class="field">
<text class="field-label">支付方式</text>
<picker class="field-picker" mode="selector" range="{{methodOptions}}" range-key="label" bindchange="onMethodChange">
<picker class="field-picker" mode="selector" range="{{methodOptions}}" range-key="label" disabled="{{paymentLocked}}" bindchange="onMethodChange">
<view class="field-value">
{{methodLabel || '未记录'}}
<text class="arrow">›</text>