接通前端订单与支付链路

Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com
This commit is contained in:
lik
2026-10-24 18:18:15 +08:00
committed by trae-solo-agent
co-authored by Claude Sonnet 4.6 noreply@anthropic.com
parent 031227710d
commit d3f399d1ad
19 changed files with 817 additions and 705 deletions
+68 -57
View File
@@ -19,9 +19,6 @@ const SERVICE_UI = {
// 全天 / 半天是核心营收项,靠排在前两位形成隐性推荐位
const SERVICE_ORDER = [1, 2, 7, 3, 4, 5, 8, 6]
// 计入"待服务订单"的订单状态:待确认 / 已确认 / 进行中
const PENDING_ORDER_STATUS = ['pending', 'confirmed', 'in_progress']
Page({
data: {
escortServices: [], // 陪诊服务(来自后端,按 SERVICE_ORDER 展示)
@@ -72,67 +69,81 @@ Page({
// 读取后端服务列表,拼装成首页宫格所需的展示数据
loadServices() {
const app = getApp()
// servicesReady 由 app.onLaunch 创建,兜底避免极端情况下取不到
const ready = app.globalData.servicesReady || Promise.resolve(app.globalData.services || [])
ready.then((services) => {
const serviceMap = {}
;(services || []).forEach((service) => {
serviceMap[service.id] = service
})
// 按展示顺序拼装。首页宫格不取 price / subtitle——
// 定价与服务介绍分别留到指南页、详情页展示
const escortServices = SERVICE_ORDER
.filter((id) => serviceMap[id])
.map((id) => {
const service = serviceMap[id]
const ui = SERVICE_UI[id] || {}
return {
id,
name: ui.name || service.title,
// 图标类名:与 index.wxss 中 .assist-icon-{id} 对应
iconClass: 'assist-icon-' + id
}
})
this.setData({
escortServices
})
})
},
// 统计待服务订单:仅在登录信息就绪后请求,未就绪时稍后重试一次
refreshPendingCount(retry) {
const app = getApp()
const user = app.globalData.user
if (!user || !user._id) {
// 首次进入时 App 的登录请求可能还没返回,延迟重试一次即可
if (!retry) {
setTimeout(() => this.refreshPendingCount(1), 1500)
}
return
}
API.escort.getMyRecords({
userId: user._id,
page: 1,
pageSize: 50
})
.then((res) => {
if (res.code !== 0) {
app.loadServices()
.then((services) => {
if (!services) {
this.setData({ escortServices: [] })
console.error('首页服务列表加载失败')
return
}
const records = (res.data && res.data.records) || []
const pendingCount = records.filter((record) => PENDING_ORDER_STATUS.indexOf(record.status) > -1).length
this.setData({
pendingCount
const serviceMap = {}
services.forEach((service) => {
serviceMap[service.id] = service
})
// 按展示顺序拼装。首页宫格不取 price / subtitle——
// 定价与服务介绍分别留到指南页、详情页展示
const escortServices = SERVICE_ORDER
.filter((id) => serviceMap[id])
.map((id) => {
const service = serviceMap[id]
const ui = SERVICE_UI[id] || {}
return {
id,
name: ui.name || service.title,
// 图标类名:与 index.wxss 中 .assist-icon-{id} 对应
iconClass: 'assist-icon-' + id
}
})
this.setData({
escortServices
})
})
.catch((err) => {
this.setData({ escortServices: [] })
console.error('首页服务列表加载失败', err)
})
},
// 统计待服务订单:等待鉴权完成,登录后由后端按状态汇总
refreshPendingCount() {
if (this.pendingRequest) return this.pendingRequest
const app = getApp()
this.pendingRequest = app.waitForAuth()
.then(() => {
const user = app.globalData.user
if (!user || !user._id) {
this.setData({ pendingCount: 0 })
return null
}
return API.escort.getMyRecords({
page: 1,
pageSize: 1,
status: 'pending,confirmed,in_progress'
})
})
.then((res) => {
if (!res || res.code !== 0) return
const data = res.data || {}
const counts = data.counts || {}
const pendingCount = counts.ongoing === undefined || counts.ongoing === null
? (data.total || 0)
: counts.ongoing
this.setData({ pendingCount })
})
.catch((err) => {
console.log('获取待服务订单失败', err)
})
.finally(() => {
this.pendingRequest = null
})
return this.pendingRequest
},
// 页脚三个 B 端入口:都进「合作与入驻」页,用 section 定位到各自的卡片