feat(M08-A): 接入顾客端续费换房分享

This commit is contained in:
Codex
2026-06-25 11:34:23 +08:00
parent a4e13d911e
commit 874b9b8e29
7 changed files with 337 additions and 5 deletions
+80
View File
@@ -9,6 +9,11 @@ Page({
order: null,
history: [],
cancellation: null,
renewMinutes: 60,
changeRoomId: '',
shareTtlMinutes: 30,
shareToken: '',
sharePermissions: ['VIEW_ROOM', 'OPEN_DOOR'],
},
onLoad(options) {
@@ -79,6 +84,81 @@ Page({
})
},
onRenewMinutesInput(event) {
this.setData({ renewMinutes: Number(event.detail.value || 0) })
},
onChangeRoomInput(event) {
this.setData({ changeRoomId: String(event.detail.value || '').trim() })
},
onShareTtlInput(event) {
this.setData({ shareTtlMinutes: Number(event.detail.value || 0) })
},
async renewOrder() {
if (!this.data.orderId || !this.data.order) return
const minutes = Number(this.data.renewMinutes || 0)
if (!Number.isFinite(minutes) || minutes < 15) {
this.setData({ errorMessage: '续费时长至少 15 分钟' })
return
}
const currentEnd = new Date(this.data.order.endAt)
const nextEnd = new Date(currentEnd.getTime() + minutes * 60000)
await this.withOrderRequest(async () => {
const response = await request(`/orders/${encodeURIComponent(this.data.orderId)}/renew`, {
method: 'POST',
data: {
endAt: nextEnd.toISOString(),
pricingPolicy: 'CURRENT',
reason: `顾客小程序续费 ${minutes} 分钟`,
},
})
await this.loadOrder(this.data.orderId)
this.setData({
successMessage: `续费已提交,补差 ${cents(response.data.amountDeltaCents)}`,
})
})
},
async changeRoom() {
if (!this.data.orderId || !this.data.changeRoomId) {
this.setData({ errorMessage: '请输入目标房间 ID' })
return
}
await this.withOrderRequest(async () => {
const response = await request(`/orders/${encodeURIComponent(this.data.orderId)}/change-room`, {
method: 'POST',
data: {
roomId: this.data.changeRoomId,
reason: '顾客小程序换房',
},
})
await this.loadOrder(this.data.orderId)
this.setData({
successMessage: `换房已提交,差价 ${cents(response.data.amountDeltaCents)}`,
})
})
},
async createShare() {
if (!this.data.orderId) return
const ttlMinutes = Math.min(Math.max(Number(this.data.shareTtlMinutes || 30), 5), 1440)
await this.withOrderRequest(async () => {
const response = await request(`/orders/${encodeURIComponent(this.data.orderId)}/shares`, {
method: 'POST',
data: {
permissions: this.data.sharePermissions,
ttlMinutes,
},
})
this.setData({
shareToken: response.data.token,
successMessage: `分享口令已生成,${response.data.expiresInMinutes} 分钟内有效`,
})
})
},
async withOrderRequest(work) {
this.setData({ loading: true, errorMessage: '', successMessage: '' })
try {
+30 -2
View File
@@ -5,7 +5,7 @@
<view wx:if="{{successMessage}}" class="success">{{successMessage}}</view>
<view wx:if="{{order}}" class="card">
<view class="order-title">{{order.storeName}} · {{order.roomName}}</view>
<view class="order-title">{{order.storeName}} / {{order.roomName}}</view>
<view class="muted">订单号:{{order.orderNo}}</view>
<view class="muted">房间:{{order.roomNo}}</view>
<view class="muted">开始:{{order.startText}}</view>
@@ -26,6 +26,34 @@
<button loading="{{loading}}" bindtap="cancelOrder">取消订单</button>
</view>
<view class="card">
<view class="section-title">续费</view>
<view class="field">
<text>分钟</text>
<input type="number" value="{{renewMinutes}}" bindinput="onRenewMinutesInput" />
</view>
<button loading="{{loading}}" bindtap="renewOrder">提交续费</button>
</view>
<view class="card">
<view class="section-title">换房</view>
<view class="field">
<text>目标房间 ID</text>
<input type="number" value="{{changeRoomId}}" bindinput="onChangeRoomInput" />
</view>
<button loading="{{loading}}" bindtap="changeRoom">提交换房</button>
</view>
<view class="card">
<view class="section-title">分享</view>
<view class="field">
<text>有效分钟</text>
<input type="number" value="{{shareTtlMinutes}}" bindinput="onShareTtlInput" />
</view>
<button loading="{{loading}}" bindtap="createShare">生成分享口令</button>
<view wx:if="{{shareToken}}" class="token">{{shareToken}}</view>
</view>
<view wx:if="{{cancellation}}" class="card">
<view class="section-title">取消测算</view>
<view class="muted">是否允许:{{cancellation.allowed ? '允许' : '不允许'}}</view>
@@ -34,7 +62,7 @@
<view class="muted">免费取消分钟线:{{cancellation.cutoffMinutes}}</view>
</view>
<view class="section-title">状态历史</view>
<view class="section-title history-title">状态历史</view>
<view wx:for="{{history}}" wx:key="id" class="history-item">
<view>{{item.action}}{{item.fromStatus || '-'}} → {{item.toStatus}}</view>
<view class="muted">{{item.createdText}}</view>
+35
View File
@@ -59,6 +59,41 @@
flex: 1 1 220rpx;
}
.field {
display: flex;
align-items: center;
gap: 16rpx;
margin: 20rpx 0;
}
.field text {
width: 180rpx;
color: #475467;
}
.field input {
flex: 1;
min-height: 72rpx;
padding: 0 20rpx;
border: 1rpx solid #d0d5dd;
border-radius: 8rpx;
background: #ffffff;
}
.token {
margin-top: 16rpx;
padding: 16rpx;
word-break: break-all;
border-radius: 8rpx;
background: #f2f4f7;
color: #344054;
font-size: 24rpx;
}
.history-title {
margin-top: 28rpx;
}
.success {
margin: 16rpx 0;
color: #17823b;