feat(v1.1.0): 支付改由 epay 插件承载、插件纳入版本库,补齐媒体上传/LBS/互动/优惠券/后台看板,并修复余额充值资损
## 一、支付:改由已安装的 epay 插件承载(不再自研签名)
- 下单:\addons\epay\library\Service::submitOrder($amount 元, $orderNo, 'wechat', $body, $notifyUrl, null, 'miniapp', $openid)
- 验签:Service::checkNotify('wechat')(内部 $pay->verify());应答:$pay->success()(v2 = XML)
- 业务编排仍在 application/api/controller/Pay.php,不改插件源码:
POST /pay/prepay(取调起参数,下发前剔除 appId);POST /pay/notify(公开路由:插件验签 → 金额核对 → 幂等分派)
- 配置真源 = addons/epay/config.php(后台「插件管理 → 微信支付宝整合插件 → 配置」);
fc_config 的 wx.mchId / wx.apiKey / wx.payNotifyUrl 废弃;后台「系统设置」支付表单改只读并跳插件配置页
- 插件 API 保持 version=v2(PHP 7.4 可跑);certs/* 为 0 字节占位,不含任何真实密钥
- 修复 BUG-015:Pay::notify() 与基类站内信同名且签名不兼容导致 /pay/* 全 500,动作改名 notifyCallback()
## 二、插件纳入 Git 版本管理
- .gitignore 移除 /addons/* 与 /public/assets/addons/*(保留 .gitkeep 占位)
- 入库 addons/epay、addons/wechat、public/assets/addons/*、addons/.htaccess(deny from all)
- config.php 入库为空白模板;服务器请在填好密钥后执行
git update-index --skip-worktree addons/epay/config.php,避免真实密钥回传仓库
## 三、安全修复:余额充值资损(高危,已实测复现)
- 现象:POST /order/recharge {payType:'balance'} 只加余额不扣款(余额 134.50 → 1022.50),等于凭空增发余额,
可再去买会员 / 付费发布 / 解锁联系方式
- 修复:/order/recharge 仅接受 payType=wxpay,balance → 「余额充值仅支持微信支付」,其它 → 「支付方式不支持」;
订单恒为 status=pending、pay_type=wxpay、paytime=null;入账只发生在 /pay/notify 回调(Order::creditRecharge)
或后台「会员管理 → 余额充值」(fc/userext/recharge)
- 小程序充值页同步为「仅微信支付」+ 防重复提交 + onShow 刷新资产;mock / 用例 / 文档同步
## 四、其他 v1.1.0 能力
- 媒体上传:POST /post/upload(图片 ≤10MB / 视频 ≤50MB,真落盘),发布页 uni.uploadFile 真上传
- LBS:fc_post.lat/lng、首页 sort=nearby(距离升序、无坐标排最后)、卡片 distance、详情页地图
- 互动:举报 POST /report(原因字典)、收藏 / 关注(fc_favorite / fc_follow、/favorite/*、/follow/toggle)
- 交易:余额充值 POST /order/recharge、优惠券 /coupon/list|receive(fc_coupon / fc_user_coupon、我的资产券)
- 发布计费:会员发布折扣(discountRate/discountText)+ 免费发布条数(freeQuota*)
- 后台新增:数据总览 fc/dashboard、系统设置 fc/setting、优惠券管理 fc/coupon(含菜单与权限节点)
## 五、本批审核修复
- 详情页:游客不再请求登录态接口(避免 401 被清 token 踢去登录);微信付费查看改为支付后轮询解锁,
不再读取 wxpay 分支未返回的 contact;加防重复提交
- 发布页:freeLeftToday → freeQuotaLeft / freeQuotaCycle / freeUnlimited(对齐后端出参);
上传图预览拼后端域名(新增 format.js#assetUrl,后端返回相对路径)
- 收藏空态「去首页」:switchTab → reLaunch(项目用自绘 fc-tabbar,无 tabBar,switchTab 必然失败)
- 会员券 days=0 显示「永久有效」;manifest.json 补 requiredPrivateInfos(getLocation / chooseLocation)
- 后端:publishConfig 补 discountRate/discountText 与 memberPostDiscountText();优惠券总开关 coupon.enabled
真生效(关闭后 list/receive 拒绝);后台 fc/Coupon 的 add/edit 补 strip_tags 过滤(防存储型 XSS)、
补 searchFields='name',列表 name 列再做一次 HTML 转义
- FcInstall:补清理后台菜单缓存 __menu__(否则新菜单要等缓存过期才显示),并同步 README 说明
- 后台语言包 fc/setting.php 按「支付只读 + 跳插件配置」的新页面重写
- 文档同步:uniapp/docs/{01,03,04}、uniapp/README.md、docs/05-后端实现规范.md、后台 README 上线步骤
## 六、校验结果(全部通过)
- 后端端到端:tools/verify-api.mjs 226/226(含新增「拒绝余额充值(资损防护)」用例)
- 小程序:uniapp/tests/run.mjs 167/167;validate.mjs 0 错 0 警;check-scss 19/19
- 后台:check-admin-i18n 0 错 0 警;check-theme 0 错 0 警;9 个页面 HTTP 200 全中文
- php -l 改动/新增 PHP 文件 0 语法错误;探针复测:余额不再增长、epay 插件下单/验签链路通
这个提交包含在:
@@ -25,14 +25,26 @@
|
||||
|
||||
<view class="create__label create__label--mt">图片 / 视频</view>
|
||||
<view class="create__media">
|
||||
<view v-for="(m, i) in form.media" :key="i" class="create__media-item fc-thumb">
|
||||
<image class="fc-icon fc-icon--md" :src="iconUrl('image')" mode="aspectFit" />
|
||||
<view v-for="(m, i) in form.media" :key="m + i" class="create__media-item fc-thumb">
|
||||
<image v-if="!isVideo(m)" class="create__media-img" :src="assetUrl(m)" mode="aspectFill" />
|
||||
<view v-else class="create__media-video">
|
||||
<image class="fc-icon fc-icon--md" :src="iconUrl('plus-ink')" mode="aspectFit" />
|
||||
<text class="create__media-video-txt">视频</text>
|
||||
</view>
|
||||
<view class="create__media-del" @click.stop="removeMedia(i)">
|
||||
<text>×</text>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="form.media.length < 6" class="create__upload" @click="chooseMedia">
|
||||
<view v-if="!uploading && imageCount < 6" class="create__upload" @click="chooseImage">
|
||||
<image class="fc-icon fc-icon--md" :src="iconUrl('plus-ink')" mode="aspectFit" />
|
||||
<text class="create__upload-txt">上传</text>
|
||||
<text class="create__upload-txt">图片 {{ imageCount }}/6</text>
|
||||
</view>
|
||||
<view v-if="!uploading && videoCount < 1" class="create__upload" @click="chooseVideo">
|
||||
<image class="fc-icon fc-icon--md" :src="iconUrl('plus-ink')" mode="aspectFit" />
|
||||
<text class="create__upload-txt">视频 {{ videoCount }}/1</text>
|
||||
</view>
|
||||
</view>
|
||||
<text v-if="uploading" class="create__uploading">媒体上传中,请稍候…</text>
|
||||
</view>
|
||||
|
||||
<!-- 联系方式 -->
|
||||
@@ -128,7 +140,7 @@ import memberApi from '@/common/api/member.js'
|
||||
import { useUserStore } from '@/common/store/index.js'
|
||||
import { iconUrl, categoryIconUrl, loadUiConfig } from '@/common/store/ui.js'
|
||||
import { pay } from '@/common/utils/pay.js'
|
||||
import { yuan2fen } from '@/common/utils/format.js'
|
||||
import { assetUrl } from '@/common/utils/format.js'
|
||||
import config from '@/common/config/index.js'
|
||||
|
||||
export default {
|
||||
@@ -137,6 +149,7 @@ export default {
|
||||
categories: [],
|
||||
drafts: [],
|
||||
submitting: false,
|
||||
uploading: false,
|
||||
draftTimer: null,
|
||||
form: {
|
||||
categoryId: 0,
|
||||
@@ -146,13 +159,17 @@ export default {
|
||||
contact: '',
|
||||
phone: '',
|
||||
address: '',
|
||||
lat: null,
|
||||
lng: null,
|
||||
plan: 'free',
|
||||
payType: config.defaultPayType,
|
||||
},
|
||||
// 发布配置(后台「发布与费用配置」下发:发布模式 / 价格 / 我的剩余额度)
|
||||
// 发布配置(后台「发布与费用配置」下发:发布模式 / 价格 / 我的剩余额度 / 会员折扣率)
|
||||
publish: {
|
||||
mode: 'paid',
|
||||
singlePrice: 5,
|
||||
discountRate: 1,
|
||||
discountText: '',
|
||||
monthPrice: 19.9,
|
||||
monthQuota: 30,
|
||||
yearPrice: 168,
|
||||
@@ -160,7 +177,10 @@ export default {
|
||||
quotaLeft: 0,
|
||||
freePerDay: 0,
|
||||
freeUsedToday: 0,
|
||||
freeLeftToday: 0,
|
||||
// 免费发布条数剩余(后端 post.freeQuota / freeQuotaCycle;-1 = 不限制)
|
||||
freeQuotaLeft: 0,
|
||||
freeQuotaCycle: 'daily',
|
||||
freeUnlimited: false,
|
||||
isMember: false,
|
||||
},
|
||||
}
|
||||
@@ -173,17 +193,53 @@ export default {
|
||||
return 0
|
||||
}
|
||||
},
|
||||
/** 已选图片数量(视频单独计数,最多 1 个) */
|
||||
imageCount() {
|
||||
return this.form.media.filter((m) => !this.isVideo(m)).length
|
||||
},
|
||||
videoCount() {
|
||||
return this.form.media.filter((m) => this.isVideo(m)).length
|
||||
},
|
||||
/** 会员折扣率(服务端下发,未下发时视作 1;不得前端写死) */
|
||||
discountRate() {
|
||||
const r = Number(this.publish.discountRate)
|
||||
return r > 0 && r <= 1 ? r : 1
|
||||
},
|
||||
/** 单条发布折后金额(展示用;实付金额仍由服务端计算) */
|
||||
singlePriceFinal() {
|
||||
return Math.round(Number(this.publish.singlePrice || 0) * this.discountRate * 100) / 100
|
||||
},
|
||||
/** 折扣文案(如「8 折」),无折扣时为空 */
|
||||
discountLabel() {
|
||||
return this.discountRate < 1 ? this.publish.discountText || `${Math.round(this.discountRate * 100) / 10} 折` : ''
|
||||
},
|
||||
/** 发布方式选项:由后台配置生成(免费模式不展示;付费模式按剩余额度插入「套餐额度」) */
|
||||
plans() {
|
||||
const p = this.publish
|
||||
if (p.mode === 'free') return []
|
||||
const list = []
|
||||
// 免费发布条数:字段名与后端 publishConfig 对齐(freeQuotaLeft / freeQuotaCycle / freeUnlimited)
|
||||
const freeLeft = Number(p.freeQuotaLeft)
|
||||
const freeUnlimited = p.freeUnlimited === true || freeLeft === -1
|
||||
if (p.quotaLeft > 0) {
|
||||
list.push({ key: 'quota', name: '套餐额度', price: '免费', desc: `剩余 ${p.quotaLeft} 条`, tag: '可用' })
|
||||
} else if (p.freeLeftToday > 0) {
|
||||
list.push({ key: 'quota', name: '今日免费', price: '免费', desc: `今日剩余 ${p.freeLeftToday} 条`, tag: '可用' })
|
||||
} else if (freeUnlimited || freeLeft > 0) {
|
||||
const cycle = { daily: '今日', monthly: '本月', total: '累计' }[p.freeQuotaCycle] || '本期'
|
||||
list.push({
|
||||
key: 'quota',
|
||||
name: `${cycle}免费`,
|
||||
price: '免费',
|
||||
desc: freeUnlimited ? '不限条数' : `${cycle}剩余 ${freeLeft} 条`,
|
||||
tag: '可用',
|
||||
})
|
||||
}
|
||||
list.push({ key: 'single', name: '会员单条', price: `¥${this.money(p.singlePrice)}`, desc: '发布 1 条' })
|
||||
list.push({
|
||||
key: 'single',
|
||||
name: '会员单条',
|
||||
price: `¥${this.money(this.singlePriceFinal)}`,
|
||||
desc: this.discountLabel ? `${this.discountLabel}(原价 ¥${this.money(p.singlePrice)})` : '发布 1 条',
|
||||
tag: this.discountLabel ? '会员价' : '',
|
||||
})
|
||||
list.push({ key: 'month', name: '按月发布', price: `¥${this.money(p.monthPrice)}`, desc: `含 ${p.monthQuota} 条`, tag: '推荐' })
|
||||
list.push({ key: 'year', name: '按年发布', price: `¥${this.money(p.yearPrice)}`, desc: `含 ${p.yearQuota} 条`, tag: '更划算' })
|
||||
return list
|
||||
@@ -199,6 +255,8 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
iconUrl,
|
||||
// 上传/后端返回的是相对路径,展示前拼后端域名(否则小程序按包内路径解析 → 裂图)
|
||||
assetUrl,
|
||||
// 分类图标:优先用后端下发的 iconKey(支持后台自定义覆盖),
|
||||
// 否则按分类 ID 映射内置配图(与 post/list.vue 保持同一套逻辑)
|
||||
catIcon(c) {
|
||||
@@ -224,7 +282,7 @@ export default {
|
||||
if (p.mode === 'free') {
|
||||
this.form.plan = 'free'
|
||||
} else {
|
||||
const freeAvailable = p.quotaLeft > 0 || p.freeLeftToday > 0
|
||||
const freeAvailable = p.quotaLeft > 0 || p.freeUnlimited === true || Number(p.freeQuotaLeft) > 0
|
||||
this.form.plan = freeAvailable ? 'quota' : 'single'
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -235,21 +293,68 @@ export default {
|
||||
const n = Number(v || 0)
|
||||
return Number.isInteger(n) ? String(n) : n.toFixed(2)
|
||||
},
|
||||
chooseMedia() {
|
||||
/** 是否为视频地址(按扩展名判定,用于缩略图/计数) */
|
||||
isVideo(url) {
|
||||
return /\.(mp4|mov|m4v|avi|webm|mkv)(\?|$)/i.test(String(url || ''))
|
||||
},
|
||||
/** 选图片(最多 6 张)→ 逐张真上传 */
|
||||
chooseImage() {
|
||||
if (this.uploading) return
|
||||
const remain = 6 - this.imageCount
|
||||
if (remain <= 0) return uni.showToast({ title: '最多上传 6 张图片', icon: 'none' })
|
||||
uni.chooseImage({
|
||||
count: 6 - this.form.media.length,
|
||||
success: (res) => {
|
||||
this.form.media = this.form.media.concat(res.tempFilePaths || [])
|
||||
},
|
||||
fail: () => {
|
||||
this.form.media.push('local://demo.jpg')
|
||||
count: remain,
|
||||
success: async (res) => {
|
||||
await this.uploadFiles(res.tempFilePaths || [], 'image')
|
||||
},
|
||||
})
|
||||
},
|
||||
/** 选视频(最多 1 个)→ 真上传 */
|
||||
chooseVideo() {
|
||||
if (this.uploading) return
|
||||
if (this.videoCount >= 1) return uni.showToast({ title: '最多上传 1 个视频', icon: 'none' })
|
||||
uni.chooseVideo({
|
||||
maxDuration: 60,
|
||||
success: async (res) => {
|
||||
await this.uploadFiles([res.tempFilePath], 'video')
|
||||
},
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 真上传:uni.uploadFile → POST /post/upload(Authorization: Bearer <token>)
|
||||
* 上传中显示 loading;成功把返回的 url 存入 form.media;失败 Toast 且不入列表。
|
||||
*/
|
||||
async uploadFiles(paths, type) {
|
||||
if (!paths.length) return
|
||||
this.uploading = true
|
||||
uni.showLoading({ title: '上传中…', mask: true })
|
||||
try {
|
||||
for (const p of paths) {
|
||||
const up = await postApi.uploadMedia(p, type)
|
||||
if (up && up.url) this.form.media.push(up.url)
|
||||
}
|
||||
this.autoSave()
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: '上传成功', icon: 'none' })
|
||||
} catch (e) {
|
||||
// 失败:Toast 且不写入 form.media(不再使用 local://demo.jpg 这类假兜底)
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: e.message || '上传失败', icon: 'none' })
|
||||
} finally {
|
||||
this.uploading = false
|
||||
}
|
||||
},
|
||||
removeMedia(i) {
|
||||
this.form.media.splice(i, 1)
|
||||
this.autoSave()
|
||||
},
|
||||
chooseLocation() {
|
||||
uni.chooseLocation({
|
||||
success: (res) => {
|
||||
this.form.address = res.address || res.name
|
||||
// 契约 §2.1:发布可带 lat/lng,用于首页「附近」排序与详情地图导航
|
||||
this.form.lat = typeof res.latitude === 'number' ? res.latitude : null
|
||||
this.form.lng = typeof res.longitude === 'number' ? res.longitude : null
|
||||
this.autoSave()
|
||||
},
|
||||
fail: () => {
|
||||
@@ -299,6 +404,10 @@ export default {
|
||||
},
|
||||
async submit() {
|
||||
if (this.submitting) return
|
||||
if (this.uploading) {
|
||||
uni.showToast({ title: '媒体上传中,请稍候', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const err = this.validate()
|
||||
if (err) {
|
||||
uni.showToast({ title: err, icon: 'none' })
|
||||
@@ -309,21 +418,27 @@ export default {
|
||||
const plan = this.publish.mode === 'free' ? 'free' : this.form.plan
|
||||
// 月卡/年卡:先开通会员套餐(含发布条数,复用会员开通接口),额度到账后再按「额度内免费」发布
|
||||
if (plan === 'month' || plan === 'year') {
|
||||
await memberApi.open({
|
||||
const opened = await memberApi.open({
|
||||
planId: plan === 'month' ? 'M1' : 'M12',
|
||||
payType: this.form.payType,
|
||||
})
|
||||
// 微信支付:下单拿到 orderNo 后先 /pay/prepay 再 requestPayment
|
||||
if (this.form.payType === config.constants.PAY_TYPE.WXPAY && opened && opened.orderNo) {
|
||||
await pay({ orderNo: opened.orderNo, payType: this.form.payType })
|
||||
}
|
||||
await useUserStore().fetchProfile()
|
||||
}
|
||||
// 传给后端只两种:free(免费/额度内/刚开通套餐)与 single(单条付费);金额由服务端算
|
||||
const apiPlan = (plan === 'free' || plan === 'quota' || plan === 'month' || plan === 'year') ? 'free' : plan
|
||||
const res = await postApi.create({
|
||||
...this.form,
|
||||
// media 为上传后的 URL 数组;lat/lng 为选择定位时的坐标
|
||||
media: this.form.media,
|
||||
plan: apiPlan,
|
||||
payType: this.form.payType,
|
||||
})
|
||||
if (res.order) {
|
||||
await pay({ ...res.order, amount: yuan2fen(res.order.amount) })
|
||||
await pay(res.order)
|
||||
}
|
||||
if (typeof res.quotaLeft === 'number') this.publish.quotaLeft = res.quotaLeft
|
||||
uni.showToast({ title: '发布成功,等待审核', icon: 'none' })
|
||||
@@ -454,6 +569,44 @@ export default {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
position: relative;
|
||||
background: $fc-bg;
|
||||
border-radius: 20rpx;
|
||||
overflow: hidden;
|
||||
}
|
||||
.create__media-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.create__media-video {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.create__media-video-txt {
|
||||
margin-top: 6rpx;
|
||||
font-size: $fc-font-xs;
|
||||
color: $fc-primary-text;
|
||||
}
|
||||
.create__media-del {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: 40rpx;
|
||||
height: 40rpx;
|
||||
border-radius: 0 0 0 20rpx;
|
||||
background: rgba(4, 48, 30, 0.6);
|
||||
color: #ffffff;
|
||||
font-size: 28rpx;
|
||||
line-height: 40rpx;
|
||||
text-align: center;
|
||||
}
|
||||
.create__uploading {
|
||||
display: block;
|
||||
margin-top: 8rpx;
|
||||
font-size: $fc-font-xs;
|
||||
color: $fc-primary-text;
|
||||
}
|
||||
.create__upload {
|
||||
width: 150rpx;
|
||||
|
||||
在新工单中引用
屏蔽一个用户