feat: 新增地址选择插件及订阅消息等多项功能优化
- 新增地址选择插件,支持地图位置选择并返回地址和经纬度 - 新增微信订阅消息发送功能,支持审核结果、提现通知等场景 - 新增订单支付状态查询、提现收款人姓名保存等接口 - 新增服务区域管理,支持按省市区划分并同步到信息发布 - 新增资金流水和营收报表导出功能 - 新增可用优惠券查询、订单退款拆分处理等功能 - 优化后台角标显示、首页数据统计、UI配置下发等 - 修复订单支付并发问题、地区管理逻辑等
这个提交包含在:
@@ -13,6 +13,8 @@ export const authApi = {
|
||||
bindPhone: (payload) => post('/auth/bind-phone', payload, { silent: true }),
|
||||
/** 微信手机号快捷获取(<button open-type="getPhoneNumber"> 回调的 code) */
|
||||
wxPhone: (payload) => post('/auth/wx-phone', payload, { silent: true }),
|
||||
/** 保存收款人真实姓名(提现商家转账用,需与微信实名一致) */
|
||||
saveRealname: (payload) => post('/auth/realname', payload, { silent: true }),
|
||||
/** 更新个人资料(微信昵称 / 头像路径) */
|
||||
saveProfile: (payload) => post('/auth/profile', payload, { silent: true }),
|
||||
/**
|
||||
|
||||
@@ -11,15 +11,21 @@ export const homeApi = {
|
||||
categories: () => get('/home/categories', {}, { silent: true }),
|
||||
/**
|
||||
* 信息流(LBS + 筛选排序)
|
||||
* 入参:{ page, size, categoryId, keyword, area, sort, lat, lng }
|
||||
* 入参:{ page, size, categoryId, keyword, areaId, area, sort, lat, lng }
|
||||
* 区域:只按服务区域(区县)筛选,兼容旧的 area 名称
|
||||
* sort: new 最新 / hot 最热 / price 价格 / nearby 附近(按 distance 升序,无坐标排最后)
|
||||
* 出参列表项含 distance(float|km,一位小数;信息无坐标时 null)
|
||||
*/
|
||||
feed: (params = {}) => get('/home/feed', params, { silent: true }),
|
||||
/** 热门搜索词 */
|
||||
hotKeywords: () => get('/home/search/hot', {}, { silent: true }),
|
||||
/** 区域列表(后台「区域管理」下发,供首页/列表/发布页筛选项使用) → [string] */
|
||||
/**
|
||||
* 服务区域列表(平铺:每条记录自带省 / 市 / 区县)
|
||||
* → [{id,province,city,district,lat,lng}];省/市由前端生成级联列
|
||||
*/
|
||||
areas: () => get('/home/areas', {}, { silent: true }),
|
||||
/** 按定位匹配服务区域 {lat,lng} → {areaId,province,city,district,distance}|null */
|
||||
locate: (params = {}) => get('/home/locate', params, { silent: true }),
|
||||
}
|
||||
|
||||
export default homeApi
|
||||
|
||||
@@ -10,6 +10,8 @@ export const payApi = {
|
||||
/** 微信支付统一下单:拿 JSAPI 调起参数(未配置商户参数时后端返回「微信支付未配置」) */
|
||||
prepay: (payload = {}) =>
|
||||
post('/pay/prepay', typeof payload === 'string' ? { orderNo: payload } : payload, { silent: true }),
|
||||
/** 查询订单支付状态(客户端支付成功 ≠ 服务端回调已处理,用于支付后确认) */
|
||||
status: (orderNo) => post('/pay/status', { orderNo }, { silent: true }),
|
||||
}
|
||||
|
||||
export default payApi
|
||||
|
||||
@@ -59,8 +59,8 @@ export const postApi = {
|
||||
/** 删除信息 */
|
||||
remove: (id) => del(`/post/${id}`, {}, { silent: true }),
|
||||
|
||||
/** 详情 */
|
||||
detail: (id) => get(`/post/${id}`, {}, { silent: true }),
|
||||
/** 详情(accessOnly=1:仅回读解锁态,不计浏览量) */
|
||||
detail: (id, params = {}) => get(`/post/${id}`, params, { silent: true }),
|
||||
/** 付费查看联系方式(微信/余额) */
|
||||
payView: (id, payload) => post(`/post/${id}/pay-view`, payload, { silent: true }),
|
||||
/** 发表评价(评分 + 图文) */
|
||||
|
||||
@@ -14,7 +14,7 @@ const IS_DEV = ENV !== 'production'
|
||||
|
||||
// 各环境后端域名(dev=运行 / prod=发行)
|
||||
const HOSTS = {
|
||||
dev: 'http://192.168.10.14:9980', // 本地后端(phpstudy 虚拟域名与端口 9980)
|
||||
dev: 'http://192.168.2.61:9980', // 本地后端(phpstudy 虚拟域名与端口 9980)
|
||||
prod: 'https://fenleixinxi.gzyakj.com.cn', // 远程正式后端
|
||||
}
|
||||
// 接口统一前缀
|
||||
|
||||
@@ -15,7 +15,13 @@ export const SHOP_TEXT = { normal: '正常', pending: '待审核', banned: '已
|
||||
export const ORDER_TEXT = { pending: '待支付', paid: '已支付', refunded: '已退款', closed: '已关闭' }
|
||||
|
||||
/** 提现状态 */
|
||||
export const WITHDRAW_TEXT = { auditing: '审核中', paid: '已打款', rejected: '已驳回' }
|
||||
export const WITHDRAW_TEXT = {
|
||||
auditing: '审核中',
|
||||
paying: '转账中',
|
||||
paid: '已到账',
|
||||
failed: '转账失败',
|
||||
rejected: '已驳回',
|
||||
}
|
||||
|
||||
/** 订单类型 */
|
||||
export const ORDER_TYPE_TEXT = { post: '发布订单', member: '会员订单', recharge: '充值订单' }
|
||||
|
||||
@@ -381,13 +381,13 @@ export const datasets = {
|
||||
shareTitle: '同城分类信息 · 身边的好帮手',
|
||||
},
|
||||
|
||||
/** 后台 · 地区管理 */
|
||||
/** 后台 · 服务区域(平铺:每条自带省/市/区县) */
|
||||
areas: [
|
||||
{ id: 1, name: '云岩区', sort: 1, enabled: true },
|
||||
{ id: 2, name: '南明区', sort: 2, enabled: true },
|
||||
{ id: 3, name: '观山湖区', sort: 3, enabled: true },
|
||||
{ id: 4, name: '花溪区', sort: 4, enabled: true },
|
||||
{ id: 5, name: '白云区', sort: 5, enabled: false },
|
||||
{ id: 1, province: '贵州省', city: '贵阳市', district: '云岩区', lat: 26.605, lng: 106.71, sort: 1, enabled: true },
|
||||
{ id: 2, province: '贵州省', city: '贵阳市', district: '南明区', lat: 26.568, lng: 106.716, sort: 2, enabled: true },
|
||||
{ id: 3, province: '贵州省', city: '贵阳市', district: '观山湖区', lat: 26.625, lng: 106.625, sort: 3, enabled: true },
|
||||
{ id: 4, province: '贵州省', city: '贵阳市', district: '花溪区', lat: 26.43, lng: 106.67, sort: 4, enabled: true },
|
||||
{ id: 5, province: '贵州省', city: '贵阳市', district: '白云区', lat: 26.678, lng: 106.623, sort: 5, enabled: false },
|
||||
],
|
||||
|
||||
/**
|
||||
@@ -397,8 +397,12 @@ export const datasets = {
|
||||
*/
|
||||
uiConfig: {
|
||||
siteName: '同城分类信息',
|
||||
appName: '同城分类信息',
|
||||
logo: '',
|
||||
icons: {},
|
||||
servicePhone: '400-000-0000',
|
||||
aboutUs: '本地同城分类信息服务平台,招聘/房产/二手/服务一站直达。',
|
||||
shareTitle: '同城分类信息 · 身边的好帮手',
|
||||
updatedAt: iso(0),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
import config from '../config/index.js'
|
||||
import { datasets } from './data.js'
|
||||
|
||||
/** 已付费解锁的信息 ID(模拟 fc_pay_view;会员免费不写这里,直接按 datasets.user.isMember 判定) */
|
||||
const paidViewIds = new Set()
|
||||
|
||||
/** 解析 /post/12 -> { id: '12' } */
|
||||
function parseParams(pattern, url) {
|
||||
const pSeg = pattern.split('/').filter(Boolean)
|
||||
@@ -30,6 +33,21 @@ function fail(message, code = 1) {
|
||||
throw e
|
||||
}
|
||||
|
||||
/** 站点 UI / 小程序配置响应(用户端与管理端共用同一份数据) */
|
||||
function uiPayload() {
|
||||
const cfg = datasets.uiConfig
|
||||
const siteName = cfg.siteName || '同城分类信息'
|
||||
return {
|
||||
appName: cfg.appName || siteName,
|
||||
siteName,
|
||||
logo: cfg.logo || '',
|
||||
servicePhone: cfg.servicePhone || '',
|
||||
aboutUs: cfg.aboutUs || '',
|
||||
shareTitle: cfg.shareTitle || siteName,
|
||||
icons: { ...(cfg.icons || {}) },
|
||||
}
|
||||
}
|
||||
|
||||
/** 生成分页结构 */
|
||||
function paginate(list, page = 1, size = 10) {
|
||||
const p = Number(page) || 1
|
||||
@@ -152,7 +170,14 @@ export const mockRoutes = {
|
||||
let list = datasets.posts.map((p) => ({ ...p, isTop: !!p.isTop }))
|
||||
if (data && data.categoryId) list = list.filter((p) => p.categoryId === Number(data.categoryId))
|
||||
if (data && data.keyword) list = list.filter((p) => p.title.includes(data.keyword))
|
||||
if (data && data.area) list = list.filter((p) => p.area === data.area)
|
||||
// 区域:只按服务区域(区县)筛选
|
||||
const areaId = data && data.areaId ? Number(data.areaId) : 0
|
||||
if (areaId) {
|
||||
const a = datasets.areas.find((x) => x.id === areaId)
|
||||
if (a) list = list.filter((p) => Number(p.districtId) === a.id || p.area === a.district)
|
||||
} else if (data && data.area) {
|
||||
list = list.filter((p) => p.area === data.area)
|
||||
}
|
||||
|
||||
// LBS:带坐标时按坐标实时计算距离(km,一位小数);信息自身无坐标时 distance = null
|
||||
const hasLoc =
|
||||
@@ -188,14 +213,44 @@ export const mockRoutes = {
|
||||
return ok(paginate(list, data && data.page, data && data.size))
|
||||
},
|
||||
'GET /home/search/hot': () => ok(datasets.hotKeywords),
|
||||
// 区域列表:与后台「区域管理」同源,仅下发启用项并按 sort 升序(返回名称数组)
|
||||
'GET /home/areas': () =>
|
||||
ok(
|
||||
datasets.areas
|
||||
.filter((a) => a.enabled)
|
||||
.sort((a, b) => (a.sort || 0) - (b.sort || 0))
|
||||
.map((a) => a.name)
|
||||
),
|
||||
// 服务区域:与后台「区域管理」同源,仅下发启用项(平铺:每条自带省/市/区县)
|
||||
'GET /home/areas': () => {
|
||||
const list = datasets.areas
|
||||
.filter((a) => a.enabled)
|
||||
.slice()
|
||||
.sort((a, b) => String(a.province).localeCompare(String(b.province), 'zh')
|
||||
|| String(a.city).localeCompare(String(b.city), 'zh')
|
||||
|| (a.sort || 0) - (b.sort || 0)
|
||||
|| a.id - b.id)
|
||||
.map((a) => ({
|
||||
id: a.id,
|
||||
province: a.province,
|
||||
city: a.city,
|
||||
district: a.district,
|
||||
lat: a.lat ?? null,
|
||||
lng: a.lng ?? null,
|
||||
}))
|
||||
return ok(list)
|
||||
},
|
||||
// 按定位匹配最近服务区域(300km 内)
|
||||
'GET /home/locate': ({ data }) => {
|
||||
const lat = data && data.lat != null ? Number(data.lat) : NaN
|
||||
const lng = data && data.lng != null ? Number(data.lng) : NaN
|
||||
if (!Number.isFinite(lat) || !Number.isFinite(lng)) return ok(null)
|
||||
let best = null
|
||||
for (const a of datasets.areas.filter((x) => x.enabled && x.lat != null && x.lng != null)) {
|
||||
const distance = round1(haversineKm(lat, lng, Number(a.lat), Number(a.lng)))
|
||||
if (!best || distance < best.distance) best = { a, distance }
|
||||
}
|
||||
if (!best || best.distance > 300) return ok(null)
|
||||
return ok({
|
||||
areaId: best.a.id,
|
||||
province: best.a.province,
|
||||
city: best.a.city,
|
||||
district: best.a.district,
|
||||
distance: best.distance,
|
||||
})
|
||||
},
|
||||
|
||||
// ==================== 用户端 · 信息发布 ====================
|
||||
'POST /post/upload': ({ data }) => {
|
||||
@@ -261,6 +316,9 @@ export const mockRoutes = {
|
||||
// 落入「我的发布」,供 /post/mine 与全链路测试读取
|
||||
const id = Date.now()
|
||||
const media = Array.isArray(data.media) ? data.media.slice() : []
|
||||
const area = datasets.areas.find((a) => a.id === Number(data.areaId || data.districtId || 0))
|
||||
|| datasets.areas.find((a) => a.district === (data.area || ''))
|
||||
|| null
|
||||
datasets.myPosts.unshift({
|
||||
id,
|
||||
title: data.title,
|
||||
@@ -271,7 +329,8 @@ export const mockRoutes = {
|
||||
media,
|
||||
price: Number(data.price) || 0,
|
||||
priceUnit: data.priceUnit || '面议',
|
||||
area: data.area || '',
|
||||
area: area ? area.district : (data.area || ''),
|
||||
districtId: area ? Number(area.id) : 0,
|
||||
address: data.address || '',
|
||||
lat: data.lat != null && data.lat !== '' ? Number(data.lat) : null,
|
||||
lng: data.lng != null && data.lng !== '' ? Number(data.lng) : null,
|
||||
@@ -341,6 +400,8 @@ export const mockRoutes = {
|
||||
const followed = !!publisherId && datasets.follows.some((f) => String(f.targetUserId) === String(publisherId))
|
||||
// 契约 §2.1:详情出参新增 lat/lng/faved/followed/favoriteCount
|
||||
const favoriteCount = datasets.favorites.filter((f) => String(f.postId) === String(post.id)).length
|
||||
// 解锁态:会员免费 / 已付费解锁(与后端 Post::contactAccess 口径一致)
|
||||
const unlocked = !!datasets.user.isMember || paidViewIds.has(String(post.id))
|
||||
return ok({
|
||||
...post,
|
||||
lat: post.lat != null ? Number(post.lat) : null,
|
||||
@@ -348,9 +409,12 @@ export const mockRoutes = {
|
||||
faved,
|
||||
followed,
|
||||
favoriteCount,
|
||||
unlocked,
|
||||
contact: unlocked ? datasets.secretContact.phone : post.contact,
|
||||
wechat: unlocked ? datasets.secretContact.wechat : '',
|
||||
})
|
||||
},
|
||||
'POST /post/:id/pay-view': ({ data }) => {
|
||||
'POST /post/:id/pay-view': ({ data, params }) => {
|
||||
const pt = data && data.payType
|
||||
if (![config.constants.PAY_TYPE.WXPAY, config.constants.PAY_TYPE.BALANCE].includes(pt)) fail('支付方式不支持')
|
||||
// 与后端 Post::payView 对齐:wxpay 只返回待支付订单(**不含 contact**,解锁由 /pay/notify 回调写 fc_pay_view 后
|
||||
@@ -360,6 +424,7 @@ export const mockRoutes = {
|
||||
order: { orderNo: 'VO' + Date.now(), amount: 2, payType: pt, type: 'payview', status: 'pending' },
|
||||
})
|
||||
}
|
||||
paidViewIds.add(String(params.id))
|
||||
return ok({ unlocked: true, contact: datasets.secretContact })
|
||||
},
|
||||
'POST /post/:id/comment': ({ data }) => {
|
||||
@@ -681,46 +746,38 @@ export const mockRoutes = {
|
||||
},
|
||||
'GET /admin/setting/areas': () => ok(datasets.areas),
|
||||
'POST /admin/setting/area': ({ data }) => {
|
||||
if (!data || !data.name) fail('区域名称不能为空')
|
||||
return ok({ id: Date.now(), ...data })
|
||||
if (!data || !data.province) fail('省份不能为空')
|
||||
if (!data.city) fail('城市不能为空')
|
||||
if (!data.district) fail('区县不能为空')
|
||||
const dup = datasets.areas.find((a) => a.province === data.province && a.city === data.city && a.district === data.district)
|
||||
if (dup) fail('该省市区组合已存在')
|
||||
const row = { id: Date.now(), sort: 0, enabled: true, ...data }
|
||||
datasets.areas.push(row)
|
||||
return ok({ id: row.id, fullName: `${row.province} / ${row.city} / ${row.district}` })
|
||||
},
|
||||
|
||||
// ==================== 站点 UI 配置(LOGO / 图标,前后台共用) ====================
|
||||
'GET /setting/ui': () =>
|
||||
ok({
|
||||
siteName: datasets.uiConfig.siteName,
|
||||
logo: datasets.uiConfig.logo,
|
||||
icons: { ...datasets.uiConfig.icons },
|
||||
}),
|
||||
'GET /admin/setting/ui': () =>
|
||||
ok({
|
||||
siteName: datasets.uiConfig.siteName,
|
||||
logo: datasets.uiConfig.logo,
|
||||
icons: { ...datasets.uiConfig.icons },
|
||||
updatedAt: datasets.uiConfig.updatedAt,
|
||||
}),
|
||||
// ==================== 站点 UI 配置(名称 / LOGO / 图标 / 客服 / 关于,前后台共用) ====================
|
||||
'GET /setting/ui': () => ok(uiPayload()),
|
||||
'GET /admin/setting/ui': () => ok({ ...uiPayload(), updatedAt: datasets.uiConfig.updatedAt }),
|
||||
'POST /admin/setting/ui': ({ data }) => {
|
||||
if (!data) fail('配置内容不能为空')
|
||||
if (data.siteName !== undefined && !String(data.siteName).trim()) fail('小程序名称不能为空')
|
||||
const icons = data.icons || {}
|
||||
for (const k of Object.keys(icons)) {
|
||||
if (typeof icons[k] !== 'string') fail(`图标 ${k} 的地址必须是字符串`)
|
||||
}
|
||||
datasets.uiConfig.siteName = data.siteName !== undefined ? data.siteName : datasets.uiConfig.siteName
|
||||
datasets.uiConfig.appName = data.siteName !== undefined ? data.siteName : datasets.uiConfig.appName
|
||||
datasets.uiConfig.logo = data.logo !== undefined ? data.logo : datasets.uiConfig.logo
|
||||
datasets.uiConfig.icons = { ...datasets.uiConfig.icons, ...icons }
|
||||
datasets.uiConfig.updatedAt = new Date().toISOString()
|
||||
return ok({
|
||||
siteName: datasets.uiConfig.siteName,
|
||||
logo: datasets.uiConfig.logo,
|
||||
icons: { ...datasets.uiConfig.icons },
|
||||
updatedAt: datasets.uiConfig.updatedAt,
|
||||
})
|
||||
return ok({ ...uiPayload(), updatedAt: datasets.uiConfig.updatedAt })
|
||||
},
|
||||
'POST /admin/setting/ui/reset': () => {
|
||||
datasets.uiConfig.logo = ''
|
||||
datasets.uiConfig.icons = {}
|
||||
datasets.uiConfig.updatedAt = new Date().toISOString()
|
||||
return ok({ siteName: datasets.uiConfig.siteName, logo: '', icons: {}, reset: true })
|
||||
return ok({ ...uiPayload(), logo: '', icons: {}, reset: true })
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,11 @@ export const uiState = reactive({
|
||||
logo: '',
|
||||
icons: {},
|
||||
siteName: '',
|
||||
appName: '',
|
||||
servicePhone: '',
|
||||
aboutUs: '',
|
||||
shareTitle: '',
|
||||
subscribe: {},
|
||||
loaded: false,
|
||||
})
|
||||
|
||||
@@ -30,7 +35,12 @@ export const uiState = reactive({
|
||||
export function applyUiConfig(cfg = {}) {
|
||||
uiState.logo = cfg.logo || ''
|
||||
uiState.icons = cfg.icons || {}
|
||||
uiState.siteName = cfg.siteName || ''
|
||||
uiState.siteName = cfg.siteName || cfg.appName || ''
|
||||
uiState.appName = cfg.appName || cfg.siteName || ''
|
||||
uiState.servicePhone = cfg.servicePhone || ''
|
||||
uiState.aboutUs = cfg.aboutUs || ''
|
||||
uiState.shareTitle = cfg.shareTitle || cfg.siteName || cfg.appName || ''
|
||||
uiState.subscribe = cfg.subscribe || {}
|
||||
setRemoteUi(cfg)
|
||||
}
|
||||
|
||||
|
||||
82
uniapp/common/utils/area.js
普通文件
82
uniapp/common/utils/area.js
普通文件
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* 服务区域工具(每条记录自带省 / 市 / 区县,区县为最终服务区域)
|
||||
*
|
||||
* 后端 /home/areas 返回平铺列表:
|
||||
* [{ id, province, city, district, lat, lng }]
|
||||
* 省 / 市仅用于前端生成级联列,不作为独立记录或筛选条件。
|
||||
*/
|
||||
|
||||
/**
|
||||
* 把平铺服务区域按 省 > 市 > 区县 分组,供三级级联选择器使用
|
||||
* @param {Array} rows /home/areas 返回的平铺列表
|
||||
* @returns {Array} [{ name, cities: [{ name, districts: [{ id, name, lat, lng }] }] }]
|
||||
*/
|
||||
export function groupAreaTree(rows) {
|
||||
if (!Array.isArray(rows)) return []
|
||||
const provinceMap = new Map()
|
||||
|
||||
rows.forEach((row) => {
|
||||
const provinceName = row.province || ''
|
||||
const cityName = row.city || ''
|
||||
const districtName = row.district || ''
|
||||
if (!provinceName || !cityName || !districtName) return
|
||||
|
||||
let province = provinceMap.get(provinceName)
|
||||
if (!province) {
|
||||
province = { name: provinceName, cities: [], cityMap: new Map() }
|
||||
provinceMap.set(provinceName, province)
|
||||
}
|
||||
let city = province.cityMap.get(cityName)
|
||||
if (!city) {
|
||||
city = { name: cityName, districts: [] }
|
||||
province.cityMap.set(cityName, city)
|
||||
province.cities.push(city)
|
||||
}
|
||||
city.districts.push({
|
||||
id: Number(row.id) || 0,
|
||||
name: districtName,
|
||||
lat: row.lat != null ? Number(row.lat) : null,
|
||||
lng: row.lng != null ? Number(row.lng) : null,
|
||||
})
|
||||
})
|
||||
|
||||
// 去掉仅用于分组的 Map,返回可直接绑定的结构
|
||||
return Array.from(provinceMap.values()).map((province) => ({
|
||||
name: province.name,
|
||||
cities: province.cities.map((city) => ({ name: city.name, districts: city.districts })),
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* 把服务区域拍平成「全部区域 + 区县」筛选选项
|
||||
* @param {Array} rows /home/areas 返回的平铺列表
|
||||
* @returns {Array<{key:string,label:string,sub:string,areaId:number}>}
|
||||
*/
|
||||
export function flattenAreaTree(rows) {
|
||||
const options = [{ key: 'all', label: '全部区域', sub: '', areaId: 0 }]
|
||||
if (!Array.isArray(rows)) return options
|
||||
|
||||
rows.forEach((row) => {
|
||||
if (!row.district) return
|
||||
options.push({
|
||||
key: `area-${row.id}`,
|
||||
label: row.district,
|
||||
sub: row.city || '',
|
||||
areaId: Number(row.id) || 0,
|
||||
})
|
||||
})
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
/**
|
||||
* 按服务区域 ID 找到对应选项(用于回显)
|
||||
* @param {Array} options flattenAreaTree() 的结果
|
||||
* @param {number} areaId
|
||||
*/
|
||||
export function findAreaOption(options, areaId) {
|
||||
if (!Array.isArray(options) || !options.length) return null
|
||||
const id = Number(areaId) || 0
|
||||
if (!id) return options[0] || null
|
||||
return options.find((o) => o.areaId === id) || null
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
* 语义:
|
||||
* · 余额支付 balance —— 服务端下单即扣款(订单直接 paid),前端只需确认成功;
|
||||
* · 微信支付 wxpay —— 先 POST /pay/prepay 拿 JSAPI 调起参数,再 uni.requestPayment;
|
||||
* 支付成功后轮询 /pay/status 确认服务端已置 paid(回调可能有延迟);
|
||||
* 未配置商户参数 / 下单失败时给出中文提示。
|
||||
*/
|
||||
import config from '../config/index.js'
|
||||
@@ -15,10 +16,28 @@ function toErr(message, code = 'PAY_FAIL') {
|
||||
return e
|
||||
}
|
||||
|
||||
/** 轮询订单状态:最多 5 次、间隔 800ms(回调通常 1~3 秒内到达) */
|
||||
function confirmPaid(orderNo) {
|
||||
if (!orderNo) return Promise.resolve(false)
|
||||
|
||||
let tries = 0
|
||||
const tick = () => {
|
||||
if (tries++ >= 5) return Promise.resolve(false)
|
||||
return payApi
|
||||
.status(orderNo)
|
||||
.then((res) => {
|
||||
if (res && res.paid) return true
|
||||
return new Promise((resolve) => setTimeout(resolve, 800)).then(tick)
|
||||
})
|
||||
.catch(() => false)
|
||||
}
|
||||
return tick()
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起支付
|
||||
* @param {Object} order 订单信息 { orderNo, amount, payType, payParams? }
|
||||
* @returns {Promise<{success:boolean,payType:string,orderNo:string,mock?:boolean}>}
|
||||
* @returns {Promise<{success:boolean,payType:string,orderNo:string,confirmed?:boolean,mock?:boolean}>}
|
||||
*/
|
||||
export function pay(order = {}) {
|
||||
const payType = order.payType || config.constants.PAY_TYPE.WXPAY
|
||||
@@ -46,18 +65,29 @@ export function pay(order = {}) {
|
||||
timeStamp: String(payParams.timeStamp || ''),
|
||||
nonceStr: payParams.nonceStr || '',
|
||||
package: payParams.package || '',
|
||||
// JSAPI v2 默认 MD5;若服务端下发 signType 以服务端为准
|
||||
signType: payParams.signType || 'MD5',
|
||||
// V3 为 RSA、V2 为 MD5;以服务端下发为准,缺省按当前接入版本(V3)兜底
|
||||
signType: payParams.signType || 'RSA',
|
||||
paySign: payParams.paySign || '',
|
||||
}
|
||||
|
||||
if (typeof uni === 'undefined' || !uni.requestPayment) {
|
||||
// H5 / Node 测试环境:视为支付成功,便于离线联调
|
||||
// 仅开发环境允许“模拟支付”便于离线联调;
|
||||
// 生产环境若缺失支付能力必须报错,绝不能让用户不付钱就看到“支付成功”。
|
||||
if (!config.isDev) {
|
||||
return Promise.reject(toErr('当前环境不支持微信支付,请在小程序内使用'))
|
||||
}
|
||||
return { success: true, payType, orderNo, mock: true, payParams: params }
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.requestPayment({
|
||||
...params,
|
||||
success: () => resolve({ success: true, payType, orderNo }),
|
||||
success: () => {
|
||||
// 客户端支付成功 → 再向后端确认(回调可能延迟,超时也不阻断用户流程)
|
||||
confirmPaid(orderNo)
|
||||
.then((confirmed) => resolve({ success: true, payType, orderNo, confirmed }))
|
||||
.catch(() => resolve({ success: true, payType, orderNo, confirmed: false }))
|
||||
},
|
||||
fail: (err) => reject(Object.assign(new Error('支付已取消'), { raw: err, code: 'PAY_CANCEL' })),
|
||||
})
|
||||
})
|
||||
|
||||
30
uniapp/common/utils/subscribe.js
普通文件
30
uniapp/common/utils/subscribe.js
普通文件
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 微信订阅消息授权
|
||||
*
|
||||
* 模板 ID 由后台「系统配置 → 小程序配置」下发(/setting/ui 的 subscribe 字段)。
|
||||
* 未配置 / 非小程序环境时静默跳过,不阻断业务。
|
||||
*/
|
||||
import { uiState } from '../store/ui.js'
|
||||
|
||||
/**
|
||||
* 请求订阅授权(需在用户点击事件中调用)
|
||||
* @param {'audit'|'transfer'} scene
|
||||
* @returns {Promise<string>} accepted | reject | none | unsupported
|
||||
*/
|
||||
export function requestSubscribe(scene) {
|
||||
const id = (uiState.subscribe && uiState.subscribe[scene]) || ''
|
||||
if (!id) return Promise.resolve('none')
|
||||
if (typeof uni === 'undefined' || !uni.requestSubscribeMessage) {
|
||||
return Promise.resolve('unsupported')
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
uni.requestSubscribeMessage({
|
||||
tmplIds: [id],
|
||||
success: (res) => resolve((res && res[id]) || 'accepted'),
|
||||
fail: () => resolve('reject'),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export default { requestSubscribe }
|
||||
在新工单中引用
屏蔽一个用户