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 插件下单/验签链路通
这个提交包含在:
@@ -67,9 +67,12 @@
|
||||
</view>
|
||||
<view class="detail__map-info">
|
||||
<text class="detail__map-name">{{ post.address }}</text>
|
||||
<text class="detail__map-action">地图导航 ›</text>
|
||||
<text class="detail__map-action">{{ hasLocation ? '地图导航 ›' : '暂无定位信息' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="detail__report" @click="openReport">
|
||||
<text class="detail__report-text">举报该信息 ›</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 付费查看联系方式 -->
|
||||
@@ -183,8 +186,13 @@
|
||||
|
||||
<script>
|
||||
import postApi from '@/common/api/post.js'
|
||||
import favoriteApi from '@/common/api/favorite.js'
|
||||
import reportApi from '@/common/api/report.js'
|
||||
import { REPORT_REASONS } from '@/common/constants/report.js'
|
||||
import { iconUrl, categoryIconUrl, loadUiConfig } from '@/common/store/ui.js'
|
||||
import { fromNow, maskPhone } from '@/common/utils/format.js'
|
||||
import { pay } from '@/common/utils/pay.js'
|
||||
import { useUserStore } from '@/common/store/index.js'
|
||||
import config from '@/common/config/index.js'
|
||||
|
||||
export default {
|
||||
@@ -198,16 +206,24 @@ export default {
|
||||
comments: [],
|
||||
followed: false,
|
||||
faved: false,
|
||||
favoriteCount: 0,
|
||||
reportReasons: REPORT_REASONS,
|
||||
showComment: false,
|
||||
showPoster: false,
|
||||
score: 5,
|
||||
commentText: '',
|
||||
// 支付/提交中:防连点重复下单(余额支付是即时扣款)
|
||||
submitting: false,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
timeText() {
|
||||
return fromNow(this.post.createdAt)
|
||||
},
|
||||
/** 详情是否带真实坐标(契约新增 lat/lng) */
|
||||
hasLocation() {
|
||||
return this.post.lat != null && this.post.lng != null
|
||||
},
|
||||
},
|
||||
onLoad(query) {
|
||||
this.id = Number(query.id || 101)
|
||||
@@ -228,20 +244,82 @@ export default {
|
||||
{ id: 5002, user: '果果', score: 4, content: '信息真实,价格合理。', reply: '感谢支持~' },
|
||||
]
|
||||
this.contact = { phone: maskPhone(res.contact), wechat: '' }
|
||||
// 契约:详情出参已带 faved/followed,先用返回值回显;
|
||||
// 兼容旧后端:缺失时再用 /favorite/status 批量回显。
|
||||
this.faved = !!res.faved
|
||||
this.followed = !!res.followed
|
||||
this.favoriteCount = Number(res.favoriteCount || 0)
|
||||
// /favorite/status 强制登录(游客调用会 401 → 被拦截器清 token 并跳登录页),
|
||||
// 因此只在已登录时用它兜底回显;未登录直接用详情返回的 faved/followed。
|
||||
if (this.isLogin()) await this.loadInteractStatus()
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '信息加载失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
/** 是否已登录(未登录时不请求需要登录态的接口) */
|
||||
isLogin() {
|
||||
try {
|
||||
return !!useUserStore().isLogin.value
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
},
|
||||
/** 进入详情时回显收藏 / 关注状态(失败静默,保持默认状态) */
|
||||
async loadInteractStatus() {
|
||||
const publisherId = this.post.publisher && this.post.publisher.id
|
||||
try {
|
||||
const res = await favoriteApi.status({ postIds: [this.id], userIds: publisherId ? [publisherId] : [] })
|
||||
if (res && res.faved) this.faved = !!res.faved[this.id]
|
||||
if (res && res.followed && publisherId) this.followed = !!res.followed[publisherId]
|
||||
} catch (e) {
|
||||
// 状态回显失败不影响详情可用性
|
||||
}
|
||||
},
|
||||
async payView(payType) {
|
||||
if (this.submitting) return
|
||||
this.submitting = true
|
||||
try {
|
||||
const res = await postApi.payView(this.id, { payType })
|
||||
this.unlocked = true
|
||||
this.contact = { phone: res.contact.phone, wechat: res.contact.wechat }
|
||||
// 微信支付:下单只返回 {order}(**不含 contact**),解锁由支付回调 /pay/notify 写 fc_pay_view 完成
|
||||
if (res.order) {
|
||||
await pay({ ...res.order, payType })
|
||||
await this.waitUnlock()
|
||||
return
|
||||
}
|
||||
this.applyContact(res)
|
||||
uni.showToast({ title: '已解锁完整联系方式', icon: 'none' })
|
||||
} catch (e) {
|
||||
uni.showToast({ title: e.message || '支付失败', icon: 'none' })
|
||||
} finally {
|
||||
this.submitting = false
|
||||
}
|
||||
},
|
||||
/** 写入已解锁的联系方式(余额/会员/重新拉取时复用) */
|
||||
applyContact(res) {
|
||||
const c = (res && res.contact) || {}
|
||||
this.unlocked = true
|
||||
this.contact = { phone: c.phone || '', wechat: c.wechat || '' }
|
||||
},
|
||||
/**
|
||||
* 微信支付成功后轮询解锁结果:回调写 fc_pay_view 有延迟,
|
||||
* 再次调用 /pay-view 只会命中后端「已解锁直接返回」分支(不会重复扣费),最多试 4 次。
|
||||
*/
|
||||
async waitUnlock() {
|
||||
for (let i = 0; i < 4; i++) {
|
||||
await new Promise((resolve) => setTimeout(resolve, i === 0 ? 800 : 1200))
|
||||
try {
|
||||
const res = await postApi.payView(this.id, { payType: config.constants.PAY_TYPE.WXPAY })
|
||||
if (res && res.unlocked) {
|
||||
this.applyContact(res)
|
||||
uni.showToast({ title: '已解锁完整联系方式', icon: 'none' })
|
||||
return
|
||||
}
|
||||
} catch (e) {
|
||||
// 回调尚未到达:继续重试
|
||||
}
|
||||
}
|
||||
uni.showToast({ title: '支付成功,解锁结果稍后生效', icon: 'none' })
|
||||
},
|
||||
async submitComment() {
|
||||
if (!this.commentText.trim()) {
|
||||
uni.showToast({ title: '请输入评价内容', icon: 'none' })
|
||||
@@ -257,22 +335,65 @@ export default {
|
||||
uni.showToast({ title: e.message, icon: 'none' })
|
||||
}
|
||||
},
|
||||
toggleFollow() {
|
||||
this.followed = !this.followed
|
||||
/** 关注:调接口,失败回退本地状态并 Toast(保持可用) */
|
||||
async toggleFollow() {
|
||||
const publisherId = this.post.publisher && this.post.publisher.id
|
||||
if (!publisherId) return uni.showToast({ title: '发布者信息缺失', icon: 'none' })
|
||||
const prev = this.followed
|
||||
this.followed = !prev
|
||||
try {
|
||||
const res = await favoriteApi.follow({ userId: publisherId })
|
||||
this.followed = !!(res && res.followed)
|
||||
uni.showToast({ title: this.followed ? '已关注' : '已取消关注', icon: 'none' })
|
||||
} catch (e) {
|
||||
this.followed = prev
|
||||
uni.showToast({ title: e.message || '操作失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
toggleFav() {
|
||||
this.faved = !this.faved
|
||||
uni.showToast({ title: this.faved ? '已收藏' : '已取消收藏', icon: 'none' })
|
||||
/** 收藏:调接口,失败回退本地状态并 Toast(保持可用) */
|
||||
async toggleFav() {
|
||||
const prev = this.faved
|
||||
this.faved = !prev
|
||||
try {
|
||||
const res = await favoriteApi.toggle({ postId: this.id })
|
||||
this.faved = !!(res && res.faved)
|
||||
if (res && typeof res.count === 'number') this.favoriteCount = res.count
|
||||
uni.showToast({ title: this.faved ? '已收藏' : '已取消收藏', icon: 'none' })
|
||||
} catch (e) {
|
||||
this.faved = prev
|
||||
uni.showToast({ title: e.message || '操作失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
/** 举报:原因取自常量(与后端 report.reasons 默认值一致) */
|
||||
openReport() {
|
||||
uni.showActionSheet({
|
||||
itemList: this.reportReasons,
|
||||
success: async (r) => {
|
||||
const reason = this.reportReasons[r.tapIndex]
|
||||
if (!reason) return
|
||||
try {
|
||||
await reportApi.create({ targetType: 'post', targetId: this.id, reason })
|
||||
uni.showToast({ title: '举报已提交,我们会尽快核实', icon: 'none' })
|
||||
} catch (e) {
|
||||
uni.showToast({ title: e.message || '举报失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
fail: () => {},
|
||||
})
|
||||
},
|
||||
goVip() {
|
||||
uni.navigateTo({ url: '/pages/member/index' })
|
||||
},
|
||||
openMap() {
|
||||
if (!this.hasLocation) {
|
||||
uni.showToast({ title: '暂无定位信息', icon: 'none' })
|
||||
return
|
||||
}
|
||||
uni.openLocation({
|
||||
latitude: 26.647,
|
||||
longitude: 106.63,
|
||||
name: this.post.address,
|
||||
address: this.post.area,
|
||||
latitude: Number(this.post.lat),
|
||||
longitude: Number(this.post.lng),
|
||||
name: this.post.address || this.post.title,
|
||||
address: this.post.area || '',
|
||||
fail: () => uni.showToast({ title: '导航需在小程序内使用', icon: 'none' }),
|
||||
})
|
||||
},
|
||||
@@ -470,6 +591,16 @@ export default {
|
||||
font-size: $fc-font-xs;
|
||||
color: $fc-primary-text;
|
||||
}
|
||||
/* 举报入口:低调,不抢主操作 */
|
||||
.detail__report {
|
||||
margin-top: 16rpx;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.detail__report-text {
|
||||
font-size: $fc-font-xs;
|
||||
color: $fc-text-placeholder;
|
||||
}
|
||||
.detail__locked {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
130
uniapp/pages/favorite/index.vue
普通文件
130
uniapp/pages/favorite/index.vue
普通文件
@@ -0,0 +1,130 @@
|
||||
<template>
|
||||
<view class="fav fc-page">
|
||||
<view v-if="loading && !list.length" class="fav__loading">
|
||||
<view v-for="i in 3" :key="i" class="fc-skeleton fav__skeleton"></view>
|
||||
</view>
|
||||
|
||||
<fc-empty v-else-if="!list.length" icon="bar-fav" text="还没有收藏的信息" btn-text="去逛逛" @action="goHome" />
|
||||
|
||||
<view v-else class="fav__list">
|
||||
<view v-for="p in list" :key="p.id" class="fav__item">
|
||||
<fc-post-card :post="p" @click="goDetail(p)" />
|
||||
<view class="fav__ops">
|
||||
<text class="fav__op" @click.stop="goDetail(p)">查看</text>
|
||||
<text class="fav__op fav__op--danger" @click.stop="remove(p)">取消收藏</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="fav__more">
|
||||
<text v-if="loading">加载中…</text>
|
||||
<text v-else-if="!hasMore">— 没有更多了 —</text>
|
||||
<text v-else @click="loadMore">加载更多</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import FcPostCard from '@/components/fc-post-card/fc-post-card.vue'
|
||||
import FcEmpty from '@/components/fc-empty/fc-empty.vue'
|
||||
import favoriteApi from '@/common/api/favorite.js'
|
||||
|
||||
export default {
|
||||
components: { FcPostCard, FcEmpty },
|
||||
data() {
|
||||
return {
|
||||
list: [],
|
||||
page: 1,
|
||||
size: 10,
|
||||
hasMore: true,
|
||||
loading: false,
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.fetch(true)
|
||||
},
|
||||
onShow() {
|
||||
// 详情页取消收藏 / 重新收藏后返回,需要看到最新列表
|
||||
this.page = 1
|
||||
this.fetch(true)
|
||||
},
|
||||
onReachBottom() {
|
||||
this.loadMore()
|
||||
},
|
||||
methods: {
|
||||
async fetch(reset = false) {
|
||||
this.loading = true
|
||||
try {
|
||||
const res = await favoriteApi.list({ page: this.page, size: this.size })
|
||||
this.list = reset ? res.list : this.list.concat(res.list)
|
||||
this.hasMore = !!res.hasMore
|
||||
} catch (e) {
|
||||
uni.showToast({ title: e.message || '加载失败', icon: 'none' })
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
loadMore() {
|
||||
if (!this.hasMore || this.loading) return
|
||||
this.page += 1
|
||||
this.fetch()
|
||||
},
|
||||
goDetail(p) {
|
||||
uni.navigateTo({ url: `/pages/detail/detail?id=${p.id}` })
|
||||
},
|
||||
goHome() {
|
||||
// 项目用自绘 fc-tabbar(pages.json 无 tabBar),switchTab 会失败,统一用 reLaunch
|
||||
uni.reLaunch({ url: '/pages/index/index' })
|
||||
},
|
||||
/** 取消收藏:调接口成功后从列表移除(失败保留并 Toast) */
|
||||
async remove(p) {
|
||||
try {
|
||||
await favoriteApi.toggle({ postId: p.id })
|
||||
this.list = this.list.filter((x) => x.id !== p.id)
|
||||
uni.showToast({ title: '已取消收藏', icon: 'none' })
|
||||
} catch (e) {
|
||||
uni.showToast({ title: e.message || '操作失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.fav {
|
||||
padding-bottom: 60rpx;
|
||||
}
|
||||
.fav__loading {
|
||||
padding: 24rpx;
|
||||
}
|
||||
.fav__skeleton {
|
||||
height: 240rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
.fav__list {
|
||||
padding-top: 24rpx;
|
||||
}
|
||||
.fav__item {
|
||||
position: relative;
|
||||
}
|
||||
.fav__ops {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
margin: -10rpx 40rpx 24rpx 0;
|
||||
}
|
||||
.fav__op {
|
||||
margin-left: 28rpx;
|
||||
font-size: $fc-font-sm;
|
||||
color: $fc-primary-text;
|
||||
font-weight: 600;
|
||||
&--danger {
|
||||
color: $fc-danger;
|
||||
}
|
||||
}
|
||||
.fav__more {
|
||||
text-align: center;
|
||||
padding: 24rpx 0 40rpx;
|
||||
font-size: $fc-font-sm;
|
||||
color: $fc-text-placeholder;
|
||||
}
|
||||
</style>
|
||||
@@ -162,12 +162,15 @@ export default {
|
||||
loading: false,
|
||||
sort: 'new',
|
||||
area: '',
|
||||
lat: null,
|
||||
lng: null,
|
||||
showAreaPicker: false,
|
||||
areaOptions: ['云岩区', '南明区', '观山湖区', '花溪区'],
|
||||
sorts: [
|
||||
{ label: '最新', value: 'new' },
|
||||
{ label: '最热', value: 'hot' },
|
||||
{ label: '价格', value: 'price' },
|
||||
{ label: '附近', value: 'nearby' },
|
||||
],
|
||||
}
|
||||
},
|
||||
@@ -186,6 +189,8 @@ export default {
|
||||
} catch (e) {}
|
||||
// 拉取后台自定义的 LOGO 与图标配置(失败自动用内置默认图)
|
||||
loadUiConfig()
|
||||
// LBS:取一次坐标(失败静默降级,不阻塞首页)
|
||||
this.fetchLocation()
|
||||
this.bootstrap()
|
||||
},
|
||||
// 每次切回首页都强制重新拉取后台配置:
|
||||
@@ -227,6 +232,24 @@ export default {
|
||||
await this.fetchFeed(true)
|
||||
this.loading = false
|
||||
},
|
||||
/**
|
||||
* 取用户坐标(gcj02,与后端 LBS 口径一致)。
|
||||
* 失败静默降级:不弹提示、不阻塞首页,仅本次请求不带 lat/lng。
|
||||
*/
|
||||
fetchLocation() {
|
||||
if (typeof uni === 'undefined' || !uni.getLocation) return
|
||||
uni.getLocation({
|
||||
type: 'gcj02',
|
||||
success: (res) => {
|
||||
this.lat = res.latitude
|
||||
this.lng = res.longitude
|
||||
// 坐标到手后刷新一次(排序/距离随之生效)
|
||||
this.page = 1
|
||||
this.fetchFeed(true)
|
||||
},
|
||||
fail: () => {},
|
||||
})
|
||||
},
|
||||
async fetchFeed(reset = false) {
|
||||
this.loading = true
|
||||
try {
|
||||
@@ -235,6 +258,8 @@ export default {
|
||||
size: this.size,
|
||||
sort: this.sort,
|
||||
area: this.area || undefined,
|
||||
lat: this.lat != null ? this.lat : undefined,
|
||||
lng: this.lng != null ? this.lng : undefined,
|
||||
})
|
||||
this.list = reset ? res.list : this.list.concat(res.list)
|
||||
this.hasMore = res.hasMore
|
||||
@@ -277,7 +302,9 @@ export default {
|
||||
uni.navigateTo({ url: `/pages/detail/detail?id=${p.id}` })
|
||||
},
|
||||
onLocation() {
|
||||
uni.showToast({ title: '已定位到 观山湖区', icon: 'none' })
|
||||
// 手动点定位:重新取一次坐标(失败静默,保持现有显示)
|
||||
this.fetchLocation()
|
||||
uni.showToast({ title: '已按当前位置刷新', icon: 'none' })
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<text class="vip__card-label">账户余额(元)</text>
|
||||
</view>
|
||||
<view class="vip__card-asset">
|
||||
<text class="vip__card-num">{{ (assets.coupons || []).length }}</text>
|
||||
<text class="vip__card-num">{{ assetCouponCount }}</text>
|
||||
<text class="vip__card-label">优惠券</text>
|
||||
</view>
|
||||
<view class="vip__card-asset">
|
||||
@@ -44,6 +44,27 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 优惠券:可领取 + 已领取(我的资产口径) -->
|
||||
<view class="fc-card">
|
||||
<view class="vip__coupon-head">
|
||||
<text class="vip__section-title">优惠券</text>
|
||||
<text class="vip__coupon-count">已拥有 {{ couponCount }} 张</text>
|
||||
</view>
|
||||
<view v-for="c in coupons" :key="c.id" class="vip__coupon">
|
||||
<view class="vip__coupon-val">
|
||||
<text class="vip__coupon-amount">{{ couponValue(c) }}</text>
|
||||
<text class="vip__coupon-cond">{{ couponCond(c) }}</text>
|
||||
</view>
|
||||
<view class="vip__coupon-mid">
|
||||
<text class="vip__coupon-name">{{ c.name }}</text>
|
||||
<text class="vip__coupon-days">有效期 {{ c.days > 0 ? c.days + ' 天' : '永久有效' }}</text>
|
||||
</view>
|
||||
<view v-if="c.received" class="vip__coupon-btn vip__coupon-btn--done"><text>已领取</text></view>
|
||||
<view v-else class="vip__coupon-btn" @click="receiveCoupon(c)"><text>领取</text></view>
|
||||
</view>
|
||||
<text v-if="!coupons.length" class="vip__coupon-empty">暂无可领取优惠券</text>
|
||||
</view>
|
||||
|
||||
<!-- 会员开通 -->
|
||||
<view class="fc-card">
|
||||
<text class="vip__section-title">开通 / 续费会员</text>
|
||||
@@ -97,9 +118,11 @@
|
||||
|
||||
<script>
|
||||
import memberApi from '@/common/api/member.js'
|
||||
import couponApi from '@/common/api/coupon.js'
|
||||
import { useUserStore } from '@/common/store/index.js'
|
||||
import { iconUrl, loadUiConfig } from '@/common/store/ui.js'
|
||||
import { formatTime } from '@/common/utils/format.js'
|
||||
import { pay } from '@/common/utils/pay.js'
|
||||
import config from '@/common/config/index.js'
|
||||
|
||||
export default {
|
||||
@@ -109,6 +132,7 @@ export default {
|
||||
plans: [],
|
||||
benefits: {},
|
||||
assets: {},
|
||||
coupons: [],
|
||||
planId: 'M12',
|
||||
payType: config.defaultPayType,
|
||||
}
|
||||
@@ -131,6 +155,14 @@ export default {
|
||||
benefitsList() {
|
||||
return this.benefits.benefits || []
|
||||
},
|
||||
/** 我的资产优惠券数量(契约:/member/assets 的 couponCount) */
|
||||
assetCouponCount() {
|
||||
return this.assets.couponCount != null ? this.assets.couponCount : (this.assets.coupons || []).length
|
||||
},
|
||||
/** 已拥有的优惠券张数(含已领取但未使用的) */
|
||||
couponCount() {
|
||||
return this.assets.couponCount != null ? this.assets.couponCount : this.coupons.filter((c) => c.received).length
|
||||
},
|
||||
expireText() {
|
||||
return this.userInfo.memberExpireAt ? formatTime(this.userInfo.memberExpireAt).slice(0, 10) : '--'
|
||||
},
|
||||
@@ -162,11 +194,46 @@ export default {
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
}
|
||||
this.loadAssets()
|
||||
this.loadCoupons()
|
||||
},
|
||||
async loadAssets() {
|
||||
try {
|
||||
this.assets = await memberApi.assets()
|
||||
} catch (e) {}
|
||||
},
|
||||
async loadCoupons() {
|
||||
try {
|
||||
const res = await couponApi.list({ page: 1, size: 20 })
|
||||
this.coupons = res.list || []
|
||||
} catch (e) {
|
||||
this.coupons = []
|
||||
}
|
||||
},
|
||||
couponValue(c) {
|
||||
return Number(c.type) === 0 || c.type === 'discount' ? `${Number(c.amount) * 10}折` : `¥${c.amount}`
|
||||
},
|
||||
couponCond(c) {
|
||||
return c.type === 'discount' ? '折扣券' : (Number(c.minAmount) > 0 ? `满 ${c.minAmount} 元可用` : '无门槛')
|
||||
},
|
||||
async receiveCoupon(c) {
|
||||
try {
|
||||
await couponApi.receive(c.id)
|
||||
uni.showToast({ title: '领取成功', icon: 'none' })
|
||||
await Promise.all([this.loadCoupons(), this.loadAssets()])
|
||||
} catch (e) {
|
||||
uni.showToast({ title: e.message || '领取失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
async openVip() {
|
||||
try {
|
||||
const res = await memberApi.open({ planId: this.planId, payType: this.payType })
|
||||
// 微信支付:下单拿到 orderNo 后先 /pay/prepay 拿 payParams,再 requestPayment
|
||||
if (this.payType === config.constants.PAY_TYPE.WXPAY && res && res.orderNo) {
|
||||
await pay({ orderNo: res.orderNo, payType: this.payType })
|
||||
}
|
||||
await useUserStore().fetchProfile()
|
||||
await this.loadAssets()
|
||||
uni.showToast({ title: '开通成功', icon: 'none' })
|
||||
setTimeout(() => uni.navigateBack(), 800)
|
||||
} catch (e) {
|
||||
@@ -174,13 +241,8 @@ export default {
|
||||
}
|
||||
},
|
||||
recharge() {
|
||||
// 用户端余额充值未开放(微信支付商户参数未配置):
|
||||
// 测试阶段由平台在 FastAdmin 后台「同城业务 → 用户与商家 → 会员管理」中充值
|
||||
uni.showModal({
|
||||
title: '余额充值',
|
||||
content: '请联系客服充值,或由平台在后台为您充值余额。',
|
||||
showCancel: false,
|
||||
})
|
||||
// 余额充值:走用户端自助页面(仅微信支付,付款后由回调入账)
|
||||
uni.navigateTo({ url: '/pages/member/recharge' })
|
||||
},
|
||||
go(url) {
|
||||
uni.navigateTo({ url })
|
||||
@@ -264,6 +326,81 @@ export default {
|
||||
font-size: $fc-font-xs;
|
||||
color: $fc-text-secondary;
|
||||
}
|
||||
.vip__coupon-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.vip__coupon-count {
|
||||
font-size: $fc-font-xs;
|
||||
color: $fc-text-placeholder;
|
||||
}
|
||||
.vip__coupon {
|
||||
margin-top: 20rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: $fc-bg;
|
||||
border-radius: $fc-radius-lg;
|
||||
overflow: hidden;
|
||||
}
|
||||
.vip__coupon-val {
|
||||
width: 190rpx;
|
||||
flex: 0 0 190rpx;
|
||||
padding: 20rpx 8rpx;
|
||||
background: $fc-gradient-warm;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.vip__coupon-amount {
|
||||
font-size: 40rpx;
|
||||
font-weight: 700;
|
||||
color: #ffffff;
|
||||
}
|
||||
.vip__coupon-cond {
|
||||
margin-top: 4rpx;
|
||||
font-size: 20rpx;
|
||||
color: rgba(255, 255, 255, 0.92);
|
||||
}
|
||||
.vip__coupon-mid {
|
||||
flex: 1;
|
||||
padding: 20rpx 16rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
}
|
||||
.vip__coupon-name {
|
||||
font-size: $fc-font;
|
||||
font-weight: 600;
|
||||
color: $fc-text;
|
||||
}
|
||||
.vip__coupon-days {
|
||||
margin-top: 6rpx;
|
||||
font-size: $fc-font-xs;
|
||||
color: $fc-text-placeholder;
|
||||
}
|
||||
.vip__coupon-btn {
|
||||
margin-right: 20rpx;
|
||||
flex: 0 0 auto;
|
||||
padding: 10rpx 26rpx;
|
||||
border-radius: $fc-radius-pill;
|
||||
background: $fc-gradient-primary;
|
||||
color: $fc-primary-ink;
|
||||
font-size: $fc-font-sm;
|
||||
font-weight: 700;
|
||||
&--done {
|
||||
background: $fc-border;
|
||||
color: $fc-text-placeholder;
|
||||
}
|
||||
}
|
||||
.vip__coupon-empty {
|
||||
display: block;
|
||||
margin-top: 24rpx;
|
||||
text-align: center;
|
||||
font-size: $fc-font-sm;
|
||||
color: $fc-text-placeholder;
|
||||
}
|
||||
.vip__plans {
|
||||
display: flex;
|
||||
margin-top: 24rpx;
|
||||
|
||||
263
uniapp/pages/member/recharge.vue
普通文件
263
uniapp/pages/member/recharge.vue
普通文件
@@ -0,0 +1,263 @@
|
||||
<template>
|
||||
<view class="recharge fc-page">
|
||||
<!-- 余额卡 -->
|
||||
<view class="recharge__hero">
|
||||
<text class="recharge__hero-label">账户余额(元)</text>
|
||||
<text class="recharge__hero-num">{{ assets.balance != null ? assets.balance : '0.00' }}</text>
|
||||
<text class="recharge__hero-tip">充值后可用于付费发布、会员开通与联系方式解锁</text>
|
||||
</view>
|
||||
|
||||
<!-- 充值金额 -->
|
||||
<view class="fc-card">
|
||||
<text class="recharge__title">选择充值金额</text>
|
||||
<view class="recharge__tiers">
|
||||
<view v-for="t in tiers" :key="t.value" class="recharge__tier"
|
||||
:class="{ 'recharge__tier--active': Number(amount) === t.value }" @click="pickTier(t.value)">
|
||||
<text class="recharge__tier-amount">¥{{ t.value }}</text>
|
||||
<text v-if="t.tag" class="recharge__tier-tag">{{ t.tag }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="recharge__custom">
|
||||
<text class="recharge__custom-symbol">¥</text>
|
||||
<input v-model="amount" class="recharge__custom-input" type="digit" placeholder="自定义充值金额(元)" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 支付方式:充值只支持微信支付(余额「充值」= 用余额给余额加钱,服务端已禁止,防资损) -->
|
||||
<view class="fc-card">
|
||||
<text class="recharge__title">支付方式</text>
|
||||
<view class="recharge__pay">
|
||||
<view class="recharge__pay-type recharge__pay-type--active">
|
||||
<image class="fc-icon fc-icon--sm" :src="iconUrl('paywechat')" mode="aspectFit" />
|
||||
<text class="recharge__pay-text">微信支付</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="recharge__btn" @click="submit">
|
||||
<text>立即充值 ¥{{ payAmount }}</text>
|
||||
</view>
|
||||
<text class="recharge__note">充值仅支持微信支付,支付成功后余额由微信回调自动入账(通常几秒内到账)。</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import memberApi from '@/common/api/member.js'
|
||||
import orderApi from '@/common/api/order.js'
|
||||
import { iconUrl, loadUiConfig } from '@/common/store/ui.js'
|
||||
import { pay } from '@/common/utils/pay.js'
|
||||
import config from '@/common/config/index.js'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
assets: {},
|
||||
tiers: [
|
||||
{ value: 50, tag: '' },
|
||||
{ value: 100, tag: '推荐' },
|
||||
{ value: 200, tag: '' },
|
||||
{ value: 500, tag: '' },
|
||||
{ value: 1000, tag: '' },
|
||||
],
|
||||
amount: '',
|
||||
// 充值只允许微信支付(服务端 /order/recharge 已禁止 payType=balance,防「用余额给余额加钱」资损)
|
||||
payType: config.constants.PAY_TYPE.WXPAY,
|
||||
submitting: false,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
/** 待充值金额(展示用,保留两位小数) */
|
||||
payAmount() {
|
||||
const n = Number(this.amount)
|
||||
return !n || n <= 0 ? '0.00' : n.toFixed(2)
|
||||
},
|
||||
},
|
||||
onLoad() {
|
||||
loadUiConfig()
|
||||
this.loadAssets()
|
||||
},
|
||||
/** 从收银台返回时重新拉余额:微信回调入账后这里能刷新到最新值 */
|
||||
onShow() {
|
||||
this.loadAssets()
|
||||
},
|
||||
methods: {
|
||||
iconUrl,
|
||||
async loadAssets() {
|
||||
try {
|
||||
this.assets = await memberApi.assets()
|
||||
} catch (e) {
|
||||
this.assets = { balance: 0 }
|
||||
}
|
||||
},
|
||||
pickTier(v) {
|
||||
this.amount = String(v)
|
||||
},
|
||||
async submit() {
|
||||
if (this.submitting) return
|
||||
const num = Number(this.amount)
|
||||
if (!num || num <= 0) {
|
||||
uni.showToast({ title: '请输入正确的充值金额', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (num > 100000) {
|
||||
uni.showToast({ title: '单次充值不能超过 100000 元', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.submitting = true
|
||||
try {
|
||||
const res = await orderApi.recharge({ amount: num, payType: this.payType })
|
||||
// 微信支付:下单只落 pending,付款后由 /pay/notify 回调入账(余额不会立刻变化)
|
||||
await pay({ orderNo: res.orderNo, payType: this.payType })
|
||||
await this.loadAssets()
|
||||
this.amount = ''
|
||||
uni.showToast({ title: '支付成功,到账略有延迟', icon: 'none' })
|
||||
} catch (e) {
|
||||
uni.showToast({ title: e.message || '充值失败', icon: 'none' })
|
||||
} finally {
|
||||
this.submitting = false
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.recharge {
|
||||
padding-bottom: 60rpx;
|
||||
}
|
||||
.recharge__hero {
|
||||
background: $fc-gradient-hero;
|
||||
padding: 48rpx 40rpx 60rpx;
|
||||
border-radius: 0 0 40rpx 40rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
.recharge__hero-label {
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
font-size: $fc-font-sm;
|
||||
}
|
||||
.recharge__hero-num {
|
||||
margin-top: 16rpx;
|
||||
color: #ffffff;
|
||||
font-size: 72rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
.recharge__hero-tip {
|
||||
margin-top: 16rpx;
|
||||
color: rgba(255, 255, 255, 0.82);
|
||||
font-size: $fc-font-xs;
|
||||
}
|
||||
.recharge__title {
|
||||
font-size: $fc-font-lg;
|
||||
font-weight: 700;
|
||||
color: $fc-text;
|
||||
}
|
||||
.recharge__tiers {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
.recharge__tier {
|
||||
position: relative;
|
||||
width: 31.5%;
|
||||
margin: 0 2.6% 20rpx 0;
|
||||
padding: 28rpx 0;
|
||||
border: 2rpx solid $fc-border;
|
||||
border-radius: $fc-radius;
|
||||
background: $fc-bg;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
&:nth-child(3n) {
|
||||
margin-right: 0;
|
||||
}
|
||||
&--active {
|
||||
border-color: $fc-primary-text;
|
||||
background: $fc-primary-lighter;
|
||||
}
|
||||
}
|
||||
.recharge__tier-amount {
|
||||
font-size: $fc-font-lg;
|
||||
font-weight: 700;
|
||||
color: $fc-text;
|
||||
}
|
||||
.recharge__tier-tag {
|
||||
position: absolute;
|
||||
top: -14rpx;
|
||||
right: 10rpx;
|
||||
padding: 2rpx 12rpx;
|
||||
border-radius: $fc-radius-pill;
|
||||
background: $fc-gradient-warm;
|
||||
color: #ffffff;
|
||||
font-size: 18rpx;
|
||||
}
|
||||
.recharge__custom {
|
||||
margin-top: 8rpx;
|
||||
height: 96rpx;
|
||||
border-radius: $fc-radius;
|
||||
background: $fc-bg;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 28rpx;
|
||||
}
|
||||
.recharge__custom-symbol {
|
||||
font-size: 40rpx;
|
||||
font-weight: 700;
|
||||
color: $fc-price;
|
||||
}
|
||||
.recharge__custom-input {
|
||||
flex: 1;
|
||||
margin-left: 12rpx;
|
||||
font-size: $fc-font-lg;
|
||||
color: $fc-text;
|
||||
}
|
||||
.recharge__pay {
|
||||
display: flex;
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
.recharge__pay-type {
|
||||
flex: 1;
|
||||
height: 80rpx;
|
||||
border-radius: $fc-radius;
|
||||
border: 2rpx solid $fc-border;
|
||||
background: $fc-bg;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: $fc-font-sm;
|
||||
color: $fc-text-regular;
|
||||
&:first-child {
|
||||
margin-right: 16rpx;
|
||||
}
|
||||
&--active {
|
||||
border-color: $fc-primary-text;
|
||||
background: $fc-primary-lighter;
|
||||
color: $fc-primary-text;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
.recharge__pay-text {
|
||||
margin-left: 10rpx;
|
||||
}
|
||||
.recharge__btn {
|
||||
margin-top: 28rpx;
|
||||
height: 90rpx;
|
||||
border-radius: $fc-radius-pill;
|
||||
background: $fc-gradient-primary;
|
||||
color: $fc-primary-ink;
|
||||
font-size: 32rpx;
|
||||
font-weight: 700;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-shadow: 0 10rpx 28rpx rgba(4, 48, 30, 0.3);
|
||||
}
|
||||
.recharge__note {
|
||||
display: block;
|
||||
margin-top: 20rpx;
|
||||
font-size: $fc-font-xs;
|
||||
color: $fc-text-placeholder;
|
||||
line-height: $fc-leading;
|
||||
}
|
||||
</style>
|
||||
@@ -29,7 +29,7 @@
|
||||
<text class="mine__asset-label">积分</text>
|
||||
</view>
|
||||
<view class="mine__asset" @click="go('/pages/member/index')">
|
||||
<text class="mine__asset-num">{{ (assets.coupons || []).length }}</text>
|
||||
<text class="mine__asset-num">{{ couponCount }}</text>
|
||||
<text class="mine__asset-label">优惠券</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -66,7 +66,7 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="mine__version">同城分类信息 v1.0.0</view>
|
||||
<view class="mine__version">同城分类信息 v1.1.0</view>
|
||||
|
||||
<view class="mine__tabbar-space"></view>
|
||||
<fc-tabbar :current="3" />
|
||||
@@ -89,6 +89,8 @@ export default {
|
||||
entries: [
|
||||
{ iconKey: 'mine-post', text: '我的发布', url: '/pages/post/mine' },
|
||||
{ iconKey: 'mine-order', text: '我的订单', url: '/pages/member/orders' },
|
||||
{ iconKey: 'bar-fav-on', text: '我的收藏', url: '/pages/favorite/index' },
|
||||
{ iconKey: 'link-recharge', text: '余额充值', url: '/pages/member/recharge' },
|
||||
{ iconKey: 'mine-dist', text: '分销中心', url: '/pages/distribution/index' },
|
||||
{ iconKey: 'mine-vip', text: '会员中心', url: '/pages/member/index' },
|
||||
],
|
||||
@@ -128,6 +130,11 @@ export default {
|
||||
expireText() {
|
||||
return this.userInfo.memberExpireAt ? formatTime(this.userInfo.memberExpireAt).slice(0, 10) : '--'
|
||||
},
|
||||
/** 我的资产优惠券数量(契约:/member/assets 的 couponCount,兼容旧字段 coupons) */
|
||||
couponCount() {
|
||||
if (this.assets.couponCount != null) return this.assets.couponCount
|
||||
return (this.assets.coupons || []).length
|
||||
},
|
||||
},
|
||||
onLoad() {
|
||||
try {
|
||||
@@ -286,7 +293,7 @@ export default {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.mine__entry {
|
||||
width: 25%;
|
||||
width: 33.33%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
|
||||
@@ -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;
|
||||
|
||||
在新工单中引用
屏蔽一个用户