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 插件下单/验签链路通
这个提交包含在:
@@ -11,8 +11,8 @@
|
||||
| --- | --- | --- |
|
||||
| **① 功能模块清单(PM)** | [`docs/01-产品功能模块清单.md`](docs/01-产品功能模块清单.md) | 用户端 + 后台管理端模块清单、优先级、业务规则、接口映射 |
|
||||
| **② UI 设计规范(UI)** | [`docs/02-UI设计规范.md`](docs/02-UI设计规范.md) | 春绿设计令牌、排版、组件、动效规范 |
|
||||
| **③ 接口文档(前后端)** | [`docs/03-接口文档.md`](docs/03-接口文档.md) | 52 个接口字段级契约 + Mock 兜底机制 + 联调清单 |
|
||||
| **④ 全链路测试报告(QA)** | [`docs/04-全链路测试用例与报告.md`](docs/04-全链路测试用例与报告.md) | 139 条用例、15 步 E2E、14 个缺陷记录与修复 |
|
||||
| **③ 接口文档(前后端)** | [`docs/03-接口文档.md`](docs/03-接口文档.md) | 73 个接口(用户端 41 + 后台 32)字段级契约 + Mock 兜底机制 + 联调清单 |
|
||||
| **④ 全链路测试报告(QA)** | [`docs/04-全链路测试用例与报告.md`](docs/04-全链路测试用例与报告.md) | 167 条用例、15 步 E2E、15 个缺陷记录与修复 |
|
||||
|
||||
## 二、目录结构
|
||||
|
||||
@@ -20,16 +20,18 @@
|
||||
fenleixinxi/
|
||||
├── App.vue # 全局主题样式(春绿 CSS 变量 + 原子类)
|
||||
├── uni.scss # 设计令牌($fc-* 自动注入所有 scss)
|
||||
├── pages.json # 13 个页面路由
|
||||
├── pages.json # 15 个页面路由
|
||||
├── pages/ # 用户端页面
|
||||
│ ├── index/index.vue # 首页:定位/搜索/轮播/分类/会员条/筛选/信息流
|
||||
│ ├── search/index.vue # 智能搜索:历史 + 热门
|
||||
│ ├── post/list.vue # 分类列表:多维筛选 + 分页
|
||||
│ ├── post/create.vue # 发布:表单/发布方式(免费·单条·套餐)/草稿箱
|
||||
│ ├── post/create.vue # 发布:表单/真上传/定位/发布方式(免费·单条·套餐)/草稿箱
|
||||
│ ├── post/mine.vue # 我的发布:审核状态筛选 + 驳回原因 + 删除(v1.0.7 新增)
|
||||
│ ├── detail/detail.vue # 详情:图文/地图/付费查看/评价/海报
|
||||
│ ├── member/index.vue # 会员:权益/开通/资产
|
||||
│ ├── detail/detail.vue # 详情:图文/真实坐标地图/付费查看/评价/海报/收藏关注/举报
|
||||
│ ├── member/index.vue # 会员:权益/开通/资产/优惠券领取
|
||||
│ ├── member/orders.vue # 订单管理
|
||||
│ ├── member/recharge.vue # 余额充值(v1.1.0 新增)
|
||||
│ ├── favorite/index.vue # 我的收藏(v1.1.0 新增)
|
||||
│ ├── distribution/index.vue # 分销:佣金/邀请/团队/提现
|
||||
│ ├── message/index.vue # 消息中心
|
||||
│ ├── mine/index.vue # 我的
|
||||
@@ -39,9 +41,10 @@ fenleixinxi/
|
||||
│ ├── config/index.js # 网关地址、开关、常量
|
||||
│ ├── utils/request.js # 统一请求层(鉴权/解包/401/降级)
|
||||
│ ├── utils/{storage,format,pay}.js
|
||||
│ ├── api/ # auth/home/post/member/distribution/message/admin
|
||||
│ ├── api/ # auth/home/post/member/distribution/message/favorite/report/order/pay/coupon/setting/admin
|
||||
│ ├── constants/report.js # 举报原因字典(report.js,v1.1.0)
|
||||
│ ├── assets/ # 图标注册表(icons.js)+ 轮播取图与主题护栏(banners.js)
|
||||
│ ├── mock/ # 52 条 mock 路由 + 数据集(离线可跑)
|
||||
│ ├── mock/ # 77 条 mock 路由 + 数据集(离线可跑)
|
||||
│ ├── constants/ui.js # 状态/图标映射
|
||||
│ └── store/index.js # 轻量全局状态
|
||||
├── static/ # 74 枚图标 + 3 张轮播插画(banners/)+ LOGO
|
||||
@@ -149,7 +152,7 @@ sh tests/run.sh
|
||||
# 等价于依次执行:
|
||||
# 1) node tests/validate.mjs 项目结构校验(路由/.vue 标签/SCSS 括号/import 依赖)
|
||||
# 2) node tools/check-scss.cjs 用 dart-sass 编译全部 SCSS
|
||||
# 3) node tests/run.mjs 全链路接口测试(139 例)
|
||||
# 3) node tests/run.mjs 全链路接口测试(167 例)
|
||||
```
|
||||
|
||||
## 七、设计主色调(春绿 · Spring Green)
|
||||
@@ -182,10 +185,11 @@ node tools/preview-theme.mjs --render # 首页仿真 + 全量令牌色板;
|
||||
|
||||
```
|
||||
[1/3] 项目结构校验 : 错误 0,警告 0
|
||||
[2/3] SCSS 编译校验 : 通过 17 个,失败 0(dart-sass)
|
||||
[3/3] 全链路接口测试 : 用例总数 139 通过 139 失败 0 (通过率 100%)
|
||||
—— 含 配图完整性与后台自定义闭环 16 例 + 轮播配图与主题护栏 14 例
|
||||
—— 含 v1.0.7 新增:我的发布 / 发布配置与计费 / 后台置顶闭环 15 例
|
||||
[2/3] SCSS 编译校验 : 通过 19 个,失败 0(dart-sass)
|
||||
[3/3] 全链路接口测试 : 用例总数 167 通过 167 失败 0 (通过率 100%)
|
||||
—— 含 配图完整性与后台自定义闭环 16 例 + 轮播配图与主题护栏 17 例
|
||||
—— 含 v1.0.7 新增:我的发布 / 发布配置与计费 / 后台置顶闭环 14 例
|
||||
—— 含 v1.1.0 新增:支付 / 上传 / LBS / 收藏关注 / 举报 / 充值 / 优惠券 28 例
|
||||
```
|
||||
|
||||
| 视觉资源 | 状态 |
|
||||
@@ -199,13 +203,14 @@ node tools/preview-theme.mjs --render # 首页仿真 + 全量令牌色板;
|
||||
### 8.1 后端接口(线上真实环境)
|
||||
|
||||
后端 v1 业务接口已实现并部署到 `https://fenleixinxi.gzyakj.com.cn/api/v1`,
|
||||
与本前端 `common/api/*.js` 的 65 个端点**逐一对应**,契约见 `docs/03-接口文档.md`。
|
||||
与本前端 `common/api/*.js` 的端点**逐一对应**(`application/route.php` 共 73 条:用户端 41 + 后台 32),契约见 `docs/03-接口文档.md`。
|
||||
|
||||
```
|
||||
后端接口端到端验证(tools/verify-api.mjs)
|
||||
用例总数: 183 通过: 183 失败: 0
|
||||
—— 65 端点契约 + 12 条业务规则文案比对 + 8 步双端业务闭环
|
||||
用例总数: 226 通过: 226 失败: 0
|
||||
—— 端点契约 + 业务规则文案比对 + 8 步双端业务闭环
|
||||
(用户发布 → 后台待审 → 后台审核 → 前台可见 → 消息通知 → 操作留痕)
|
||||
—— v1.1.0 新增 39 例:媒体上传 / LBS / 收藏关注 / 举报 / 充值 / prepay / 回调 / 优惠券 / 发布回读
|
||||
```
|
||||
|
||||
**后端种子数据与本前端 `common/mock/data.js` 逐字段对齐**,因此把
|
||||
@@ -239,6 +244,7 @@ node tools/preview-theme.mjs --render # 首页仿真 + 全量令牌色板;
|
||||
| **1.0.7** | 2026-10-15 | **发布侧三件事(缺陷 + 两个新功能)**:① **「我的发布」页上线**——原先「我的」页入口指向 `/pages/post/list`(分类信息列表,只显示别人审核通过的信息),用户发完**看不到自己的发布记录**,现新增 `GET /post/mine`(按 全部/待审核/已通过/已驳回/已下架 筛选 + 各类计数 + 驳回原因)与 `pages/post/mine.vue`,发布成功后直接跳转该页;② **后台手动置顶**——`fc_post.is_top` 正式接入用户端:后台「信息管理」新增「置顶/取消置顶」(工具栏批量 + 行内按钮 + 状态徽章,附站内消息通知),`Home::feed` 与 `/post/mine` 均按 `is_top desc` 排序,卡片显示「置顶」角标;③ **免费/付费发布开关**——后台新增「发布与费用配置」页(同城业务 → 基础数据):发布模式(免费发布 / 付费发布)+ 会员单条发布价格 + 按月(价格 + 含条数)+ 按年(价格 + 含条数),保存后同步会员套餐(月卡 M1 / 年卡 M12);`fc_user_ext` 新增发布额度 `post_quota_left`,开通月/年卡自动发放额度、额度内免费发布(付费模式下仍保留「每日免费条数」避免硬付费墙);④ **计费改为服务端定价**(BUG-012):原先发布金额由前端 `amount` 传入并被后端直接采信,客户端可改价(0.01 元发帖),现金额一律按后台配置在服务端计算;新增 15 条用例(总用例 134,全绿) |
|
||||
| **1.0.8** | 2026-10-16 | **会员手机号真绑定 + 后台会员列表字段调整**:① **修复「手机号授权绑定」假实现**(BUG-013)——原先登录页点击绑定只在前端拼 `138 + 时间戳` 的假号、从不落库,导致微信注册会员 `fa_user.mobile` 恒为空、后台会员列表手机号大面积为空;现改为 `<button open-type="getPhoneNumber">` 调用新增的 `POST /auth/wx-phone`(后端用小程序 access_token 调微信 `phonenumber.getPhoneNumber` 真实取号并写入 `fa_user.mobile`,access_token 带缓存),微信侧不可用时自动回落手动输入 `bind-phone`;② **后台会员列表**按要求去掉「角色组 / 电子邮箱 / 等级」三列,手机号列前置并**全量展示**:未绑定号时回落显示该会员最近一条发布信息里的联系电话并标注「来自发布信息」(`mobile_source=post`),两者都无显示「未绑定」;③ 后台 JS 变更后 bump `site.version` 强制刷新浏览器静态资源缓存;新增 2 条用例(总用例 136,全绿) |
|
||||
| **1.0.9** | 2026-10-16 | **采集会员微信昵称与头像**(BUG-014):微信自 2022 年已回收主动拉取资料接口,登录页改用官方 `open-type="chooseAvatar"` + `<input type="nickname">` 由用户授权采集,登录时随 `wx-login` 提交;新增 `POST /auth/avatar`(用户端 multipart 上传头像,落盘并写 `fa_user.avatar`)与 `POST /auth/profile`(随时补填资料);后台「会员列表」昵称/头像列由此显示真实微信资料(无头像仍显示字母头像);另含 v1.0.8 的会员手机号真绑定与列表字段调整。新增 3 条用例(总用例 139,全绿) |
|
||||
| **1.1.0** | 2026-10-17 | **支付闭环 + 媒体上传 + LBS + 互动 + 优惠券 + 后台看板/设置**:① **微信支付改用 epay 插件承载(插件下单 + 插件验签,本地业务编排在 `api/Pay`)**——新增 `POST /pay/prepay`、`POST /pay/notify`:下单走 `\addons\epay\library\Service::submitOrder(..., 'miniapp', $openid)`,验签与应答由插件 `checkNotify()` / `$pay->success()` 生成;商户号/密钥真源为**插件配置**(`addons/epay/config.php`,后台「插件管理 → 微信支付宝整合插件 → 配置」),回调地址按当前请求域名动态生成、回调新增金额核对;`/post/{id}/pay-view`、`/member/open`、`/order/recharge` 微信支付统一改为**只落 `pending` 订单**、由回调置 `paid` 并分派后续动作(会员发放 / 余额入账 / 付费解锁),回调幂等;修复 **BUG-015**(`Pay::notify()` 与基类站内信 `notify()` 同名签名不兼容导致 `/pay/*` 全 500,动作改名 `notifyCallback()`);② **发布媒体真上传**——新增 `POST /post/upload`(图片 ≤10MB / 视频 ≤50MB),发布页 `uni.uploadFile` 真上传并提交 URL 数组;③ **LBS**——`fc_post` 增 `lat`/`lng`,首页 `uni.getLocation` + `sort=nearby`(按距离升序、无坐标排最后)、卡片显示 `distance`,详情页真实坐标地图;④ **举报**——新增 `POST /report` + 详情页入口(原因字典 `report.reasons`);⑤ **收藏 / 关注**——新增 `fc_favorite`/`fc_follow` 与 `/favorite/*`、`/follow/toggle`,新增「我的收藏」页;⑥ **余额充值**——新增 `POST /order/recharge` 与 `pages/member/recharge`(**只允许微信支付**:`payType=balance` 等于用余额给余额加钱、余额只增不减,会凭空增发余额,属资损漏洞,已禁止并加用例守护);⑦ **优惠券**——新增 `fc_coupon`/`fc_user_coupon`、后台 CRUD(`fc/coupon`)、用户领取(`/coupon/*`)与资产展示(**不含下单抵扣**);⑧ **发布折扣**——单条付费按 `member.benefit.postDiscount` 折扣计价(BR-16);⑨ **后台 PC**新增「数据总览」`fc/dashboard`(核心看板 + 近 14 天趋势,置首)、「系统设置」`fc/setting`(仅基础配置 `base.*`,支付配置改由插件页维护)、「优惠券管理」`fc/coupon`,商家表单增店铺头图/公告/推荐位;`site.version` → `1.7.0.20261017`。新增 28 条用例(**总用例 167,全绿**),后端端到端 226/226,后台 6 页面 HTTP 200 |
|
||||
|
||||
**生产构建命令**(无需 HBuilderX GUI,复用同级项目的 uni-app 工具链):
|
||||
|
||||
@@ -287,7 +293,7 @@ rm -rf /tmp/fcmp && cp -R "$OUTPUT_DIR" /tmp/fcmp
|
||||
|
||||
### 8.4 余额支付测试指引(微信支付未配置时的替代方案)
|
||||
|
||||
微信支付商户参数(`mchId`/`apiKey`)尚未配置,因此**测试阶段统一走余额支付**。
|
||||
微信支付尚未配置:商户号/密钥的真源是 **epay 插件配置**(`wechat.miniapp_id`/`wechat.mch_id`/`wechat.key`),当前为空,因此**测试阶段统一走余额支付**。
|
||||
|
||||
**① 支付方式由一处开关控制**
|
||||
|
||||
@@ -334,3 +340,45 @@ defaultPayType: 'balance',
|
||||
付费查看 余额 → 10.00 → 8.00,付费记录 ¥2.00 balance(重复查看不再扣款)
|
||||
余额不足 → 「余额不足」,余额不变,且**不产生假订单**
|
||||
```
|
||||
|
||||
### 8.5 部署说明(v1.1.0 上线步骤)
|
||||
|
||||
1. **推送/部署后端代码**后,在**服务器执行一次**(幂等,可重复执行):
|
||||
|
||||
> **首次拉取本批改动的特别注意**:`addons/epay`、`addons/wechat`、`public/assets/addons/*` 此前被 `.gitignore` 忽略,
|
||||
> 服务器上早就有这些文件却不在 Git 里 → 直接 `git pull` 会报 `untracked working tree files would be overwritten by merge`。
|
||||
> 若**已在服务器配置过插件密钥**,先备份 `addons/epay/config.php`(当前为空白模板):
|
||||
|
||||
```bash
|
||||
cd /www/wwwroot/fenleixinxi.gzyakj.com.cn
|
||||
cp addons/epay/config.php /root/epay-config.bak # 只有已配置过才需要
|
||||
rm -rf addons/epay addons/wechat public/assets/addons/epay public/assets/addons/wechat
|
||||
git pull
|
||||
cp /root/epay-config.bak addons/epay/config.php # 上面备份过的才需要复原
|
||||
git update-index --skip-worktree addons/epay/config.php # 之后服务器改插件配置不再污染 git 状态
|
||||
php think fc:install # 不带 --reset,常规上线勿带
|
||||
```
|
||||
|
||||
该命令会**幂等补齐**本轮新增结构:建 4 张新表(`fa_fc_favorite` / `fa_fc_follow` / `fa_fc_coupon` / `fa_fc_user_coupon`)、
|
||||
补列(`fa_fc_post.lat` / `lng`,`fa_fc_merchant.banner` / `notice` / `recommend`)、
|
||||
补配置(`coupon.enabled` / `report.reasons`;**支付配置不在其中**,改由 epay 插件配置维护)、
|
||||
补后台菜单与权限节点(数据总览 / 系统设置 / 优惠券管理)。**已存在的列 / 配置一律跳过,不覆盖运营已改的值**;
|
||||
菜单与权限节点按 `name` **对齐标题/上级/排序**(若在后台改过这三个新页面的菜单名,会被重置回默认名)。
|
||||
从 v1.1.0 起它还会**清理插件钩子缓存 `hooks`**:`application/extra/addons.php` 的钩子会被 File 缓存,
|
||||
若该缓存是在「插件目录还不存在」时生成的,插件启用后也不会被加载(症状:微信支付报 `Class 'Yansongda\Pay\Pay' not found`)。
|
||||
同时清理后台左侧菜单缓存 `__menu__`(`Auth::getSidebar()` 依赖它,否则新菜单要等缓存过期才显示)。
|
||||
手工兜底:删除 `runtime/cache` 目录即可重建。
|
||||
|
||||
2. 后台 JS/视图/CSS 变更已通过 bump `site.version`(`1.7.0.20261017`)强制刷新浏览器静态资源缓存。
|
||||
|
||||
3. **微信支付真机联调前置**:在后台「插件管理 → 微信支付宝整合插件 → 配置」填写 `wechat.miniapp_id`(**小程序 AppID,必须填这一项**)、`wechat.mch_id`(商户号)、`wechat.key`(v2 密钥);
|
||||
未配置时 `/pay/prepay` 会返回「微信支付未配置」,`/pay/notify` 返回 SUCCESS 但不处理(余额支付不受影响)。
|
||||
|
||||
4. 小程序侧为 **1.1.0**(`manifest.json` `versionName=1.1.0` / `versionCode=110`),新增页面 `pages/favorite/index`、`pages/member/recharge` 已注册进 `pages.json`。
|
||||
|
||||
5. **插件已入库**:`.gitignore` 已移除 `/addons/*` 与 `/public/assets/addons/*`,`addons/epay`、`addons/wechat` 与 `public/assets/addons/{epay,wechat}` 现由 git 跟踪(`addons/epay` 即微信支付宝整合插件源码,无需在服务器另行放置插件包)。
|
||||
|
||||
6. **重要提示(插件密钥防冲突)**:插件的商户号/密钥保存在 `addons/epay/config.php`,该文件已入库(当前为**空白模板**);在服务器上通过后台配置后该文件会被改写,为避免 `git pull` 冲突,请在服务器上执行 `git update-index --skip-worktree addons/epay/config.php`;**切勿把填了真实密钥的该文件提交到仓库**。
|
||||
|
||||
7. **插件 API 版本必须保持 `v2`**:站点与服务器均为 PHP 7.4,插件配置里的 `version` 只能用 `v2`(V3 版本要求 PHP 8.0+ 且需上传 API 证书);
|
||||
`addons/epay/certs/*.pem` 是插件自带的**空白占位文件**,V2 支付(JSAPI 统一下单 + 回调验签)用不到它们,无需处理。
|
||||
|
||||
16
uniapp/common/api/coupon.js
普通文件
16
uniapp/common/api/coupon.js
普通文件
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* 接口模块 · 优惠券(用户端)
|
||||
* 对应契约 §2.1:
|
||||
* GET /coupon/list {page,size} → 分页(可领取 + 已领取标记 received)
|
||||
* POST /coupon/receive {couponId} → {userCouponId}
|
||||
*/
|
||||
import { get, post } from '../utils/request.js'
|
||||
|
||||
export const couponApi = {
|
||||
/** 可领取优惠券列表(含 received 已领取标记) */
|
||||
list: (params = {}) => get('/coupon/list', params, { silent: true }),
|
||||
/** 领取优惠券 */
|
||||
receive: (couponId) => post('/coupon/receive', { couponId }, { silent: true }),
|
||||
}
|
||||
|
||||
export default couponApi
|
||||
22
uniapp/common/api/favorite.js
普通文件
22
uniapp/common/api/favorite.js
普通文件
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* 接口模块 · 收藏与关注(用户端)
|
||||
* 对应契约 §2.1:
|
||||
* GET /favorite/list 分页(list 项为 Post 结构)
|
||||
* POST /favorite/toggle {postId} → {faved,count}
|
||||
* POST /follow/toggle {userId} → {followed}
|
||||
* POST /favorite/status {postIds:[],userIds:[]} → {faved:{},followed:{}}
|
||||
*/
|
||||
import { get, post } from '../utils/request.js'
|
||||
|
||||
export const favoriteApi = {
|
||||
/** 我的收藏(分页,list 项为 Post 结构) */
|
||||
list: (params = {}) => get('/favorite/list', params, { silent: true }),
|
||||
/** 收藏 / 取消收藏(返回最新状态与收藏总数) */
|
||||
toggle: (payload = {}) => post('/favorite/toggle', payload, { silent: true }),
|
||||
/** 关注 / 取消关注发布者 */
|
||||
follow: (payload = {}) => post('/follow/toggle', payload, { silent: true }),
|
||||
/** 批量回显收藏 / 关注状态 */
|
||||
status: (payload = {}) => post('/favorite/status', payload, { silent: true }),
|
||||
}
|
||||
|
||||
export default favoriteApi
|
||||
@@ -9,7 +9,12 @@ export const homeApi = {
|
||||
banners: () => get('/home/banners', {}, { silent: true }),
|
||||
/** 分类导航 */
|
||||
categories: () => get('/home/categories', {}, { silent: true }),
|
||||
/** 信息流(LBS + 筛选排序) */
|
||||
/**
|
||||
* 信息流(LBS + 筛选排序)
|
||||
* 入参:{ page, size, categoryId, keyword, area, sort, lat, lng }
|
||||
* 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 }),
|
||||
|
||||
@@ -10,3 +10,9 @@ export { distributionApi } from './distribution.js'
|
||||
export { messageApi } from './message.js'
|
||||
export { settingApi } from './setting.js'
|
||||
export { adminApi } from './admin.js'
|
||||
// v1.1.0 新增(契约 §2.1)
|
||||
export { favoriteApi } from './favorite.js'
|
||||
export { reportApi } from './report.js'
|
||||
export { orderApi } from './order.js'
|
||||
export { payApi } from './pay.js'
|
||||
export { couponApi } from './coupon.js'
|
||||
|
||||
17
uniapp/common/api/order.js
普通文件
17
uniapp/common/api/order.js
普通文件
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* 接口模块 · 订单(用户端)
|
||||
* 对应契约 §2.1:POST /order/recharge {amount,payType} → {orderNo,amount,status,payType}
|
||||
* 说明:与后端 application/api/controller/Order.php 不是同一文件,仅为前端封装。
|
||||
*/
|
||||
import { post } from '../utils/request.js'
|
||||
|
||||
export const orderApi = {
|
||||
/**
|
||||
* 余额充值下单
|
||||
* ⚠️ 只支持微信支付(payType='wxpay'):订单落 pending,走 /pay/prepay 调起收银台后由 /pay/notify 回调入账。
|
||||
* 服务端禁止 payType='balance'(用余额给余额加钱会凭空增发余额,属资损)。
|
||||
*/
|
||||
recharge: (payload = {}) => post('/order/recharge', payload, { silent: true }),
|
||||
}
|
||||
|
||||
export default orderApi
|
||||
15
uniapp/common/api/pay.js
普通文件
15
uniapp/common/api/pay.js
普通文件
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 接口模块 · 支付(用户端)
|
||||
* 对应契约 §2.1:POST /pay/prepay {orderNo} → {orderNo,payType:'wxpay',payParams:{timeStamp,nonceStr,package,signType,paySign}}
|
||||
* 说明:与后端 application/api/controller/Pay.php 不是同一文件,仅为前端封装。
|
||||
* 页面不要直接调用本模块,统一走 common/utils/pay.js。
|
||||
*/
|
||||
import { post } from '../utils/request.js'
|
||||
|
||||
export const payApi = {
|
||||
/** 微信支付统一下单:拿 JSAPI 调起参数(未配置商户参数时后端返回「微信支付未配置」) */
|
||||
prepay: (payload = {}) =>
|
||||
post('/pay/prepay', typeof payload === 'string' ? { orderNo: payload } : payload, { silent: true }),
|
||||
}
|
||||
|
||||
export default payApi
|
||||
@@ -2,9 +2,48 @@
|
||||
* 接口模块 · 信息发布 与 信息详情(用户端)
|
||||
* 对应模块:发布表单 / 付费置帖 / 套餐发帖 / 草稿箱 / 内容展示 / 付费查看 / 评价互动
|
||||
*/
|
||||
import { get, post, del } from '../utils/request.js'
|
||||
import { get, post, del, buildUrl, buildHeaders } from '../utils/request.js'
|
||||
|
||||
export const postApi = {
|
||||
/**
|
||||
* 上传发布媒体(图片 / 视频)
|
||||
* 契约 §2.1:POST /post/upload multipart `file`(+可选 `type=image|video`)→ {url,type,size,name}
|
||||
* 小程序环境走 uni.uploadFile(multipart/form-data,带 Authorization),
|
||||
* Node 测试 / H5 环境回落 mock 路由,保证离线可跑。
|
||||
* @param {String} filePath uni.chooseImage / uni.chooseVideo 得到的临时路径
|
||||
* @param {'image'|'video'} type
|
||||
* @returns {Promise<{url:string,type:string,size:number,name:string}>}
|
||||
*/
|
||||
uploadMedia(filePath, type = 'image') {
|
||||
const kind = type === 'video' ? 'video' : 'image'
|
||||
if (typeof uni === 'undefined' || !uni.uploadFile) {
|
||||
return post('/post/upload', { file: filePath, type: kind }, { silent: true })
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
const header = buildHeaders()
|
||||
// uni.uploadFile 自行设置 multipart 边界,不能带 application/json
|
||||
delete header['Content-Type']
|
||||
uni.uploadFile({
|
||||
url: buildUrl('/post/upload'),
|
||||
filePath,
|
||||
name: 'file',
|
||||
formData: { type: kind },
|
||||
header,
|
||||
success: (res) => {
|
||||
let body = res && res.data
|
||||
try {
|
||||
body = JSON.parse(res.data)
|
||||
} catch (e) {}
|
||||
if (body && body.code === 0) {
|
||||
resolve(body.data)
|
||||
return
|
||||
}
|
||||
reject(new Error((body && body.message) || '上传失败'))
|
||||
},
|
||||
fail: () => reject(new Error('上传失败')),
|
||||
})
|
||||
})
|
||||
},
|
||||
/** 发布信息(返回审核状态,付费时返回支付订单;金额由服务端按后台配置计算) */
|
||||
create: (payload) => post('/post/create', payload, { silent: true }),
|
||||
/** 我的发布(status: all 默认 / pending 待审核 / passed 已通过 / rejected 已驳回 / offline 已下架) */
|
||||
|
||||
15
uniapp/common/api/report.js
普通文件
15
uniapp/common/api/report.js
普通文件
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 接口模块 · 举报(用户端)
|
||||
* 对应契约 §2.1:POST /report {targetType:'post'|'comment', targetId, reason, detail?} → {reportId}
|
||||
*/
|
||||
import { post } from '../utils/request.js'
|
||||
import { REPORT_REASONS } from '../constants/report.js'
|
||||
|
||||
export const reportApi = {
|
||||
/** 提交举报(原因取自常量清单,默认与后端 report.reasons 一致) */
|
||||
create: (payload = {}) => post('/report', payload, { silent: true }),
|
||||
/** 举报原因清单(供页面 uni.showActionSheet 使用) */
|
||||
reasons: REPORT_REASONS,
|
||||
}
|
||||
|
||||
export default reportApi
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 举报相关常量(用户端)
|
||||
* 与后端 fc_config 的 `report.reasons`(JSON 数组)保持同一份默认值,
|
||||
* 前端不再各页面硬编码原因列表。
|
||||
*/
|
||||
|
||||
/** 举报原因(默认清单,后端可通过 report.reasons 覆盖下发) */
|
||||
export const REPORT_REASONS = ['虚假信息', '违法违禁', '垃圾广告', '重复发布', '其他']
|
||||
|
||||
/** 举报对象类型(与 api/v1/report 的 targetType 一致) */
|
||||
export const REPORT_TARGET = { POST: 'post', COMMENT: 'comment' }
|
||||
|
||||
export default { REPORT_REASONS, REPORT_TARGET }
|
||||
@@ -44,7 +44,7 @@ export const datasets = {
|
||||
/** 热门搜索 */
|
||||
hotKeywords: ['租房 一室一厅', '二手电动车', '急招快递员', '钢琴家教', '空调维修'],
|
||||
|
||||
/** 信息流(含待审核/已通过/已驳回,供两端联调) */
|
||||
/** 信息流(含待审核/已通过/已驳回,供两端联调;lat/lng 为 LBS 坐标,distance 单位 km 一位小数) */
|
||||
posts: [
|
||||
{
|
||||
id: 101, categoryId: 1, categoryName: '招聘求职', title: '急招快递分拣员(日结)',
|
||||
@@ -53,7 +53,7 @@ export const datasets = {
|
||||
contact: '139****8888', contactFull: '13988888888', views: 1892, likes: 32,
|
||||
isPaid: false, auditStatus: 1, createdAt: iso(0.2), tags: ['日结', '包吃'],
|
||||
publisher: { id: 2001, name: '顺捷物流', avatar: '', isMerchant: true, verified: true },
|
||||
commentCount: 12, distance: 1200,
|
||||
commentCount: 12, lat: 26.6157, lng: 106.6979, distance: 7.6,
|
||||
},
|
||||
{
|
||||
id: 102, categoryId: 2, categoryName: '房产租售', title: '整租·未来方舟精装一室一厅',
|
||||
@@ -62,7 +62,7 @@ export const datasets = {
|
||||
contact: '135****6666', contactFull: '13566666666', views: 3204, likes: 88,
|
||||
isPaid: true, auditStatus: 1, createdAt: iso(0.5), tags: ['精装', '近地铁'],
|
||||
publisher: { id: 2002, name: '安家房产', avatar: '', isMerchant: true, verified: true },
|
||||
commentCount: 26, distance: 3400,
|
||||
commentCount: 26, lat: 26.5716, lng: 106.7314, distance: 13.1,
|
||||
},
|
||||
{
|
||||
id: 103, categoryId: 3, categoryName: '二手闲置', title: '九成新山地自行车 转让',
|
||||
@@ -71,7 +71,7 @@ export const datasets = {
|
||||
contact: '137****1234', contactFull: '13712341234', views: 640, likes: 21,
|
||||
isPaid: false, isTop: true, auditStatus: 1, createdAt: iso(1), tags: ['自提', '9成新'],
|
||||
publisher: { id: 2003, name: '骑行爱好者', avatar: '', isMerchant: false, verified: false },
|
||||
commentCount: 4, distance: 820,
|
||||
commentCount: 4, lat: 26.6300, lng: 106.6250, distance: 1.9,
|
||||
},
|
||||
{
|
||||
id: 104, categoryId: 4, categoryName: '车辆买卖', title: '2019 款家用轿车 一手车',
|
||||
@@ -80,7 +80,7 @@ export const datasets = {
|
||||
contact: '138****0000', contactFull: '13800000000', views: 1120, likes: 40,
|
||||
isPaid: true, auditStatus: 0, createdAt: iso(0.1), tags: ['无事故', '可检测'],
|
||||
publisher: { id: 2004, name: '车行天下', avatar: '', isMerchant: true, verified: true },
|
||||
commentCount: 0, distance: 5100,
|
||||
commentCount: 0, lat: 26.6049, lng: 106.7194, distance: 10.0,
|
||||
},
|
||||
{
|
||||
id: 105, categoryId: 5, categoryName: '本地服务', title: '专业空调清洗 / 加氟上门',
|
||||
@@ -89,7 +89,7 @@ export const datasets = {
|
||||
contact: '131****5678', contactFull: '13156785678', views: 2310, likes: 66,
|
||||
isPaid: false, auditStatus: 0, createdAt: iso(0.05), tags: ['上门', '不满意不收费'],
|
||||
publisher: { id: 2005, name: '洁净到家', avatar: '', isMerchant: true, verified: true },
|
||||
commentCount: 18, distance: 2600,
|
||||
commentCount: 18, lat: 26.5600, lng: 106.6870, distance: 11.2,
|
||||
},
|
||||
{
|
||||
id: 106, categoryId: 3, categoryName: '二手闲置', title: 'iPad 2021 64G 深空灰',
|
||||
@@ -98,7 +98,7 @@ export const datasets = {
|
||||
contact: '150****3344', contactFull: '15033443344', views: 480, likes: 15,
|
||||
isPaid: false, auditStatus: 2, createdAt: iso(2), tags: ['验机'],
|
||||
publisher: { id: 2006, name: '小王同学', avatar: '', isMerchant: false, verified: false },
|
||||
commentCount: 1, distance: 1500,
|
||||
commentCount: 1, lat: 26.6230, lng: 106.6400, distance: 2.8,
|
||||
},
|
||||
],
|
||||
|
||||
@@ -114,17 +114,25 @@ export const datasets = {
|
||||
* 发布配置(后台「发布与费用配置」下发;与 fa_fc_config 的 post.* 对齐)
|
||||
* mode:free 免费发布 / paid 付费发布(付费模式下按 singlePrice 或套餐额度)
|
||||
* quotaLeft:当前用户的剩余发布条数(套餐额度,随会员有效期)
|
||||
* discountRate:会员发布折扣率(1 = 无折扣,0.8 = 8 折);单条金额 = round(singlePrice * discountRate, 2)
|
||||
* discountText:折扣展示文案(如「8 折」),无折扣时为空
|
||||
*/
|
||||
publishRule: {
|
||||
mode: 'paid',
|
||||
singlePrice: 5,
|
||||
discountRate: 1,
|
||||
discountText: '',
|
||||
monthPrice: 19.9,
|
||||
monthQuota: 30,
|
||||
yearPrice: 168,
|
||||
yearQuota: 500,
|
||||
quotaLeft: 30,
|
||||
freePerDay: 2, // 每日免费发布条数(付费模式下仍保留的免费次数)
|
||||
freeUsedToday: 0,
|
||||
// 免费发布条数(字段名与后端 Post::publishConfig 对齐:freeQuota/freeQuotaCycle/freeQuotaUsed/freeQuotaLeft/freeUnlimited)
|
||||
freeQuota: 2, // 周期内免费发布条数
|
||||
freeQuotaCycle: 'daily',
|
||||
freeQuotaUsed: 0,
|
||||
freeQuotaLeft: 2, // -1 表示不限制
|
||||
freeUnlimited: false,
|
||||
quotaExpireAt: iso(-25),
|
||||
isMember: true,
|
||||
memberExpireAt: iso(-25),
|
||||
@@ -183,13 +191,38 @@ export const datasets = {
|
||||
benefits: ['每日免费查看 20 条联系方式', '发布信息 8 折', '专属会员标识', '分销佣金加速结算'],
|
||||
},
|
||||
|
||||
/** 我的资产 */
|
||||
/** 我的资产(coupons / couponCount 由 /member/assets 从 fc_user_coupon 实时聚合) */
|
||||
assets: {
|
||||
balance: 128.5,
|
||||
coupons: [{ id: 1, name: '发布立减 3 元', amount: 3, expireAt: iso(-20) }],
|
||||
points: 320,
|
||||
},
|
||||
|
||||
/** 可领取的优惠券定义(fc_coupon) */
|
||||
coupons: [
|
||||
{ id: 1, name: '发布立减 3 元', type: 'fixed', amount: 3, minAmount: 0, total: 1000, receivedCount: 12, enabled: true, sort: 1, days: 30 },
|
||||
{ id: 2, name: '满 50 减 10', type: 'fixed', amount: 10, minAmount: 50, total: 500, receivedCount: 88, enabled: true, sort: 2, days: 15 },
|
||||
{ id: 3, name: '会员开通 9 折', type: 'discount', amount: 0.9, minAmount: 0, total: 200, receivedCount: 30, enabled: true, sort: 3, days: 7 },
|
||||
{ id: 4, name: '已停发券', type: 'fixed', amount: 5, minAmount: 20, total: 100, receivedCount: 100, enabled: false, sort: 4, days: 10 },
|
||||
],
|
||||
|
||||
/** 我已领取的优惠券(fc_user_coupon) */
|
||||
userCoupons: [
|
||||
{ id: 1, couponId: 1, status: 'unused', orderNo: '', usetime: '', expiretime: iso(-20), createtime: iso(2) },
|
||||
],
|
||||
|
||||
/** 我的收藏(fc_favorite:user_id + post_id) */
|
||||
favorites: [
|
||||
{ id: 1, postId: 101, createtime: iso(1) },
|
||||
],
|
||||
|
||||
/** 我的关注(fc_follow:user_id + target_user_id) */
|
||||
follows: [
|
||||
{ id: 1, targetUserId: 2001, createtime: iso(2) },
|
||||
],
|
||||
|
||||
/** 微信支付商户参数是否已配置(未配置时 /pay/prepay 返回「微信支付未配置」,余额支付不受影响) */
|
||||
wxPayConfigured: true,
|
||||
|
||||
/** 订单(发布/会员/充值 三类,供用户端与后台共用) */
|
||||
orders: [
|
||||
{ id: 3001, orderNo: 'PO20240101001', type: 'post', title: '单条付费发布', amount: 5, payType: 'wxpay', status: 'paid', createdAt: iso(1) },
|
||||
|
||||
@@ -43,6 +43,63 @@ function paginate(list, page = 1, size = 10) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 保留一位小数 */
|
||||
function round1(n) {
|
||||
return Math.round(Number(n) * 10) / 10
|
||||
}
|
||||
|
||||
/** 保留两位小数(金额) */
|
||||
function round2(n) {
|
||||
return Math.round(Number(n) * 100) / 100
|
||||
}
|
||||
|
||||
/**
|
||||
* 经纬度球面距离(km,Haversine)
|
||||
* 与后端 fc_post.lat/lng 的 LBS 口径一致:出参 distance 单位 km、一位小数。
|
||||
*/
|
||||
function haversineKm(lat1, lng1, lat2, lng2) {
|
||||
const R = 6371
|
||||
const rad = (d) => (d * Math.PI) / 180
|
||||
const dLat = rad(lat2 - lat1)
|
||||
const dLng = rad(lng2 - lng1)
|
||||
const a =
|
||||
Math.sin(dLat / 2) ** 2 +
|
||||
Math.cos(rad(lat1)) * Math.cos(rad(lat2)) * Math.sin(dLng / 2) ** 2
|
||||
return 2 * R * Math.asin(Math.min(1, Math.sqrt(a)))
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析后台配置的会员发布折扣文案(如 '8 折' → 0.8)
|
||||
* 解析失败或不含折扣时视作 1(与契约 §2.1 一致)。
|
||||
*/
|
||||
export function parseDiscountRate(text) {
|
||||
if (text == null || text === '') return 1
|
||||
if (typeof text === 'number') return text > 0 && text <= 1 ? text : 1
|
||||
const s = String(text)
|
||||
const m = s.match(/(\d+(?:\.\d+)?)\s*折/)
|
||||
if (!m) return 1
|
||||
const zhe = Number(m[1])
|
||||
if (!zhe || zhe <= 0 || zhe > 10) return 1
|
||||
return Math.round((zhe / 10) * 100) / 100
|
||||
}
|
||||
|
||||
/** 聚合我的优惠券(fc_user_coupon + fc_coupon),字段与后端 /member/assets 一致 */
|
||||
function buildUserCoupons() {
|
||||
return datasets.userCoupons.map((uc) => {
|
||||
const c = datasets.coupons.find((x) => x.id === uc.couponId) || {}
|
||||
return {
|
||||
id: uc.id,
|
||||
couponId: uc.couponId,
|
||||
name: c.name || '',
|
||||
type: c.type || 'fixed',
|
||||
amount: c.amount || 0,
|
||||
minAmount: c.minAmount || 0,
|
||||
status: uc.status,
|
||||
expireAt: uc.expiretime,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const mockRoutes = {
|
||||
// ==================== 用户端 · 认证与登录 ====================
|
||||
'POST /auth/wx-login': ({ data }) => {
|
||||
@@ -96,14 +153,56 @@ export const mockRoutes = {
|
||||
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)
|
||||
|
||||
// LBS:带坐标时按坐标实时计算距离(km,一位小数);信息自身无坐标时 distance = null
|
||||
const hasLoc =
|
||||
!!(data && data.lat != null && data.lng != null && data.lat !== '' && data.lng !== '')
|
||||
list = list.map((p) => {
|
||||
const hasPostLoc = p.lat != null && p.lng != null
|
||||
if (hasLoc) {
|
||||
return {
|
||||
...p,
|
||||
distance: hasPostLoc
|
||||
? round1(haversineKm(Number(data.lat), Number(data.lng), Number(p.lat), Number(p.lng)))
|
||||
: null,
|
||||
}
|
||||
}
|
||||
// 请求未带坐标:与后端 Home::feed 口径一致,一律 distance = null
|
||||
// (不再回退数据集里的静态距离,否则前端会显示"假距离")
|
||||
return { ...p, distance: null }
|
||||
})
|
||||
|
||||
list.sort((a, b) => (Number(b.isTop) - Number(a.isTop)) || (new Date(b.createdAt) - new Date(a.createdAt)))
|
||||
if (data && data.sort === 'price') list.sort((a, b) => (Number(b.isTop) - Number(a.isTop)) || ((a.price || 0) - (b.price || 0)))
|
||||
if (data && data.sort === 'hot') list.sort((a, b) => (Number(b.isTop) - Number(a.isTop)) || (b.views - a.views))
|
||||
// 附近:按距离升序,无坐标的排最后(置顶仍优先)
|
||||
if (data && data.sort === 'nearby') {
|
||||
const byDistance = (a, b) => {
|
||||
if (a.distance == null && b.distance == null) return 0
|
||||
if (a.distance == null) return 1
|
||||
if (b.distance == null) return -1
|
||||
return a.distance - b.distance
|
||||
}
|
||||
list.sort((a, b) => (Number(b.isTop) - Number(a.isTop)) || byDistance(a, b))
|
||||
}
|
||||
return ok(paginate(list, data && data.page, data && data.size))
|
||||
},
|
||||
'GET /home/search/hot': () => ok(datasets.hotKeywords),
|
||||
|
||||
// ==================== 用户端 · 信息发布 ====================
|
||||
'POST /post/upload': ({ data }) => {
|
||||
// 真实后端为 multipart 上传落盘;mock 只返回**相对路径**(与后端一致,由前端拼域名展示)
|
||||
if (!data || !data.file) fail('未接收到上传文件')
|
||||
const type = data.type === 'video' ? 'video' : 'image'
|
||||
const ext = type === 'video' ? '.mp4' : '.jpg'
|
||||
const path = `/uploads/mock/post_${Date.now()}${ext}`
|
||||
return ok({
|
||||
url: path,
|
||||
type,
|
||||
size: type === 'video' ? 1024 * 1024 : 120 * 1024,
|
||||
name: `post_${Date.now()}${ext}`,
|
||||
})
|
||||
},
|
||||
'POST /post/create': ({ data }) => {
|
||||
if (!data || !data.title) fail('标题不能为空')
|
||||
if (!data.content) fail('内容不能为空')
|
||||
@@ -113,18 +212,25 @@ export const mockRoutes = {
|
||||
let plan = data.plan || (data.paid ? 'single' : 'free')
|
||||
if (plan === 'month' || plan === 'year') fail('发布方式不支持,请先开通会员套餐')
|
||||
|
||||
// 会员折扣率由服务端下发(未下发 / 解析失败时视作 1),金额仍只由服务端计算
|
||||
const discountRate = Number(rule.discountRate) > 0 ? Number(rule.discountRate) : parseDiscountRate(rule.discountText)
|
||||
|
||||
let amount = 0
|
||||
if (rule.mode === 'paid') {
|
||||
if (plan === 'single') {
|
||||
amount = Number(rule.singlePrice)
|
||||
amount = round2(Number(rule.singlePrice) * discountRate)
|
||||
if (![config.constants.PAY_TYPE.WXPAY, config.constants.PAY_TYPE.BALANCE].includes(data.payType)) {
|
||||
fail('支付方式不支持')
|
||||
}
|
||||
} else if (rule.quotaLeft > 0) {
|
||||
rule.quotaLeft -= 1 // 套餐额度内免费发布
|
||||
plan = 'quota'
|
||||
} else if (Number(rule.freePerDay) > Number(rule.freeUsedToday)) {
|
||||
rule.freeUsedToday += 1 // 每日免费额度内免费发布
|
||||
} else if (rule.freeUnlimited || Number(rule.freeQuotaLeft) > 0) {
|
||||
// 免费发布条数内免费发布(freeUnlimited = 不限制,不扣减)
|
||||
if (!rule.freeUnlimited) {
|
||||
rule.freeQuotaUsed = Number(rule.freeQuotaUsed) + 1
|
||||
rule.freeQuotaLeft = Math.max(0, Number(rule.freeQuota) - rule.freeQuotaUsed)
|
||||
}
|
||||
plan = 'free'
|
||||
} else {
|
||||
fail('请选择发布方式')
|
||||
@@ -137,24 +243,30 @@ export const mockRoutes = {
|
||||
? {
|
||||
orderNo: 'PO' + Date.now(),
|
||||
amount,
|
||||
discountRate,
|
||||
payType: data.payType,
|
||||
type: 'post',
|
||||
status: data.payType === config.constants.PAY_TYPE.BALANCE ? 'paid' : 'pending',
|
||||
}
|
||||
: null
|
||||
|
||||
// 落入「我的发布」,供 /post/mine 与全链路测试读取
|
||||
const id = Date.now()
|
||||
const media = Array.isArray(data.media) ? data.media.slice() : []
|
||||
datasets.myPosts.unshift({
|
||||
id,
|
||||
title: data.title,
|
||||
content: data.content,
|
||||
categoryId: Number(data.categoryId) || 1,
|
||||
categoryName: '招聘求职',
|
||||
cover: '',
|
||||
cover: media[0] || '',
|
||||
media,
|
||||
price: Number(data.price) || 0,
|
||||
priceUnit: data.priceUnit || '面议',
|
||||
area: data.area || '',
|
||||
address: data.address || '',
|
||||
lat: data.lat != null && data.lat !== '' ? Number(data.lat) : null,
|
||||
lng: data.lng != null && data.lng !== '' ? Number(data.lng) : null,
|
||||
auditStatus: config.constants.AUDIT.PENDING,
|
||||
auditReason: '',
|
||||
status: 1,
|
||||
@@ -173,12 +285,15 @@ export const mockRoutes = {
|
||||
order,
|
||||
plan,
|
||||
amount,
|
||||
discountRate,
|
||||
quotaLeft: rule.mode === 'paid' ? rule.quotaLeft : 0,
|
||||
})
|
||||
},
|
||||
'GET /post/publish-config': () => {
|
||||
const r = datasets.publishRule
|
||||
return ok({ ...r, freeLeftToday: Math.max(0, Number(r.freePerDay) - Number(r.freeUsedToday)) })
|
||||
// 与后端 Post::publishConfig 出参对齐:freeQuotaLeft(-1 = 不限制)+ discountRate/discountText
|
||||
const freeQuotaLeft = r.freeUnlimited ? -1 : Math.max(0, Number(r.freeQuota) - Number(r.freeQuotaUsed))
|
||||
return ok({ ...r, freeQuotaLeft })
|
||||
},
|
||||
'GET /post/mine': ({ data }) => {
|
||||
const status = (data && data.status) || 'all'
|
||||
@@ -213,11 +328,30 @@ export const mockRoutes = {
|
||||
'GET /post/:id': ({ params }) => {
|
||||
const post = datasets.posts.find((p) => String(p.id) === String(params.id)) || datasets.posts[0]
|
||||
if (!post) fail('信息不存在', 404)
|
||||
return ok(post)
|
||||
const faved = datasets.favorites.some((f) => String(f.postId) === String(post.id))
|
||||
const publisherId = post.publisher && post.publisher.id
|
||||
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
|
||||
return ok({
|
||||
...post,
|
||||
lat: post.lat != null ? Number(post.lat) : null,
|
||||
lng: post.lng != null ? Number(post.lng) : null,
|
||||
faved,
|
||||
followed,
|
||||
favoriteCount,
|
||||
})
|
||||
},
|
||||
'POST /post/:id/pay-view': ({ data }) => {
|
||||
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 后
|
||||
// 再调本接口才拿到 unlocked+contact);余额/会员免费才同步返回 unlocked+contact
|
||||
if (pt === config.constants.PAY_TYPE.WXPAY) {
|
||||
return ok({
|
||||
order: { orderNo: 'VO' + Date.now(), amount: 2, payType: pt, type: 'payview', status: 'pending' },
|
||||
})
|
||||
}
|
||||
return ok({ unlocked: true, contact: datasets.secretContact })
|
||||
},
|
||||
'POST /post/:id/comment': ({ data }) => {
|
||||
@@ -248,7 +382,148 @@ export const mockRoutes = {
|
||||
})
|
||||
},
|
||||
'GET /member/orders': ({ data }) => ok(paginate(datasets.orders, data && data.page, data && data.size)),
|
||||
'GET /member/assets': () => ok(datasets.assets),
|
||||
'GET /member/assets': () => {
|
||||
// coupons 来自 fc_user_coupon + fc_coupon(字段与后端一致);couponCount 供「我的资产」直接展示
|
||||
const coupons = buildUserCoupons()
|
||||
return ok({ ...datasets.assets, coupons, couponCount: coupons.length })
|
||||
},
|
||||
|
||||
// ==================== 用户端 · 收藏与关注 ====================
|
||||
'GET /favorite/list': ({ data }) => {
|
||||
const list = datasets.favorites
|
||||
.map((f) => datasets.posts.find((p) => String(p.id) === String(f.postId)))
|
||||
.filter(Boolean)
|
||||
return ok(paginate(list, data && data.page, data && data.size))
|
||||
},
|
||||
'POST /favorite/toggle': ({ data }) => {
|
||||
const postId = Number(data && data.postId)
|
||||
if (!postId) fail('缺少信息 ID')
|
||||
const idx = datasets.favorites.findIndex((f) => String(f.postId) === String(postId))
|
||||
let faved
|
||||
if (idx > -1) {
|
||||
datasets.favorites.splice(idx, 1)
|
||||
faved = false
|
||||
} else {
|
||||
datasets.favorites.unshift({ id: Date.now(), postId, createtime: new Date().toISOString() })
|
||||
faved = true
|
||||
}
|
||||
return ok({ faved, count: datasets.favorites.length })
|
||||
},
|
||||
'POST /follow/toggle': ({ data }) => {
|
||||
const userId = Number(data && data.userId)
|
||||
if (!userId) fail('缺少用户 ID')
|
||||
const idx = datasets.follows.findIndex((f) => String(f.targetUserId) === String(userId))
|
||||
let followed
|
||||
if (idx > -1) {
|
||||
datasets.follows.splice(idx, 1)
|
||||
followed = false
|
||||
} else {
|
||||
datasets.follows.push({ id: Date.now(), targetUserId: userId, createtime: new Date().toISOString() })
|
||||
followed = true
|
||||
}
|
||||
return ok({ followed })
|
||||
},
|
||||
'POST /favorite/status': ({ data }) => {
|
||||
const postIds = (data && data.postIds) || []
|
||||
const userIds = (data && data.userIds) || []
|
||||
const faved = {}
|
||||
const followed = {}
|
||||
postIds.forEach((id) => {
|
||||
faved[id] = datasets.favorites.some((f) => String(f.postId) === String(id))
|
||||
})
|
||||
userIds.forEach((id) => {
|
||||
followed[id] = datasets.follows.some((f) => String(f.targetUserId) === String(id))
|
||||
})
|
||||
return ok({ faved, followed })
|
||||
},
|
||||
|
||||
// ==================== 用户端 · 举报 ====================
|
||||
'POST /report': ({ data }) => {
|
||||
if (!data || !data.targetType) fail('缺少举报对象类型')
|
||||
if (!['post', 'comment'].includes(data.targetType)) fail('举报对象类型不合法')
|
||||
if (!data.targetId) fail('缺少举报对象')
|
||||
if (!data.reason) fail('请选择举报原因')
|
||||
const id = Date.now()
|
||||
datasets.reports.unshift({
|
||||
id,
|
||||
targetType: data.targetType,
|
||||
targetId: Number(data.targetId),
|
||||
reason: data.reason,
|
||||
detail: data.detail || '',
|
||||
reporter: String(datasets.user.id),
|
||||
status: 'pending',
|
||||
createdAt: new Date().toISOString(),
|
||||
})
|
||||
return ok({ reportId: id })
|
||||
},
|
||||
|
||||
// ==================== 用户端 · 余额充值 与 微信支付 ====================
|
||||
'POST /order/recharge': ({ data }) => {
|
||||
const amount = round2(data && data.amount)
|
||||
// 与后端 application/api/controller/Order::recharge 对齐:金额 0/超限同一文案;
|
||||
// 充值只允许微信支付(balance = 用余额给余额加钱,属资损,后端已禁止)
|
||||
if (!amount || amount <= 0 || amount > 100000) fail('充值金额不合法')
|
||||
const payType = data && data.payType
|
||||
if (payType === config.constants.PAY_TYPE.BALANCE) fail('余额充值仅支持微信支付')
|
||||
if (payType !== config.constants.PAY_TYPE.WXPAY) fail('支付方式不支持')
|
||||
|
||||
const orderNo = 'RO' + Date.now()
|
||||
datasets.orders.unshift({
|
||||
id: Date.now(),
|
||||
orderNo,
|
||||
type: 'recharge',
|
||||
title: '余额充值',
|
||||
amount,
|
||||
payType,
|
||||
status: 'pending',
|
||||
createdAt: new Date().toISOString(),
|
||||
})
|
||||
return ok({ orderNo, amount, status: 'pending', payType })
|
||||
},
|
||||
'POST /pay/prepay': ({ data }) => {
|
||||
const orderNo = data && data.orderNo
|
||||
if (!orderNo) fail('缺少订单号')
|
||||
if (!datasets.wxPayConfigured) fail('微信支付未配置')
|
||||
return ok({
|
||||
orderNo,
|
||||
payType: config.constants.PAY_TYPE.WXPAY,
|
||||
payParams: {
|
||||
timeStamp: String(Math.floor(Date.now() / 1000)),
|
||||
nonceStr: 'mocknonce' + Date.now(),
|
||||
package: 'prepay_id=mock_prepay_' + orderNo,
|
||||
signType: 'MD5',
|
||||
paySign: 'MOCKSIGN',
|
||||
},
|
||||
})
|
||||
},
|
||||
|
||||
// ==================== 用户端 · 优惠券 ====================
|
||||
'GET /coupon/list': ({ data }) => {
|
||||
const receivedIds = datasets.userCoupons.map((u) => u.couponId)
|
||||
const list = datasets.coupons
|
||||
.filter((c) => c.enabled)
|
||||
.sort((a, b) => (a.sort || 0) - (b.sort || 0))
|
||||
.map((c) => ({ ...c, received: receivedIds.includes(c.id) }))
|
||||
return ok(paginate(list, data && data.page, data && data.size))
|
||||
},
|
||||
'POST /coupon/receive': ({ data }) => {
|
||||
const couponId = Number(data && data.couponId)
|
||||
const coupon = datasets.coupons.find((c) => c.id === couponId)
|
||||
if (!coupon) fail('优惠券不存在')
|
||||
if (!coupon.enabled) fail('该优惠券已停止发放')
|
||||
if (datasets.userCoupons.some((u) => u.couponId === couponId)) fail('您已领取过该优惠券')
|
||||
const id = Date.now()
|
||||
datasets.userCoupons.push({
|
||||
id,
|
||||
couponId,
|
||||
status: 'unused',
|
||||
orderNo: '',
|
||||
usetime: '',
|
||||
expiretime: new Date(Date.now() + (Number(coupon.days) || 30) * 86400000).toISOString(),
|
||||
createtime: new Date().toISOString(),
|
||||
})
|
||||
return ok({ userCouponId: id })
|
||||
},
|
||||
|
||||
// ==================== 用户端 · 分销中心 ====================
|
||||
'GET /distribution/overview': () => ok(datasets.distOverview),
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
* 格式化工具集
|
||||
*/
|
||||
|
||||
import config from '../config/index.js'
|
||||
|
||||
/** 金额分转元 */
|
||||
export function fen2yuan(fen) {
|
||||
return (Number(fen || 0) / 100).toFixed(2)
|
||||
@@ -56,4 +58,40 @@ export function formatDistance(meters) {
|
||||
return `${(m / 1000).toFixed(1)}km`
|
||||
}
|
||||
|
||||
export default { fen2yuan, yuan2fen, formatTime, fromNow, maskPhone, formatDistance }
|
||||
/**
|
||||
* 距离格式化(千米,一位小数)
|
||||
* 契约 §2.1:feed / 详情下发的 distance 单位为 km(一位小数),无坐标时为 null。
|
||||
*/
|
||||
export function formatKm(km) {
|
||||
if (km === null || km === undefined || km === '') return ''
|
||||
const n = Number(km)
|
||||
if (isNaN(n)) return ''
|
||||
return `${n.toFixed(1)}km`
|
||||
}
|
||||
|
||||
/**
|
||||
* 资源地址:后端统一返回**相对路径**(/uploads/YYYYMMDD/xxx.jpg,与用户头像口径一致),
|
||||
* 小程序 `<image src="/uploads/...">` 会被当成包内路径而裂图,因此展示前必须拼上后端域名。
|
||||
* 已是 http(s)/data/blob 的地址原样返回。
|
||||
* @param {string} url
|
||||
* @returns {string}
|
||||
*/
|
||||
export function assetUrl(url) {
|
||||
const s = String(url == null ? '' : url)
|
||||
if (!s) return ''
|
||||
if (/^(https?:)?\/\//i.test(s) || /^(data|blob):/i.test(s)) return s
|
||||
// config.baseURL 形如 https://host/api,这里只取域名部分(uploads 挂在站点根目录)
|
||||
const origin = String(config.baseURL || '').replace(/^(https?:\/\/[^/]+).*$/i, '$1')
|
||||
return origin + (s.charAt(0) === '/' ? s : '/' + s)
|
||||
}
|
||||
|
||||
export default {
|
||||
fen2yuan,
|
||||
yuan2fen,
|
||||
formatTime,
|
||||
fromNow,
|
||||
maskPhone,
|
||||
formatDistance,
|
||||
formatKm,
|
||||
assetUrl,
|
||||
}
|
||||
|
||||
@@ -1,37 +1,65 @@
|
||||
/**
|
||||
* 统一支付封装
|
||||
* 支持:微信支付(uni.requestPayment)/ 余额支付(服务端直接扣减)
|
||||
* 统一支付封装(所有支付点必须走这里,页面不直接调 /pay/prepay)
|
||||
*
|
||||
* 语义:
|
||||
* · 余额支付 balance —— 服务端下单即扣款(订单直接 paid),前端只需确认成功;
|
||||
* · 微信支付 wxpay —— 先 POST /pay/prepay 拿 JSAPI 调起参数,再 uni.requestPayment;
|
||||
* 未配置商户参数 / 下单失败时给出中文提示。
|
||||
*/
|
||||
import config from '../config/index.js'
|
||||
import payApi from '../api/pay.js'
|
||||
|
||||
function toErr(message, code = 'PAY_FAIL') {
|
||||
const e = new Error(message)
|
||||
e.code = code
|
||||
return e
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起支付
|
||||
* @param {Object} order 订单信息 { orderNo, amount, payType }
|
||||
* @returns {Promise<{success:boolean, payType:string, orderNo:string}>}
|
||||
* @param {Object} order 订单信息 { orderNo, amount, payType, payParams? }
|
||||
* @returns {Promise<{success:boolean,payType:string,orderNo:string,mock?:boolean}>}
|
||||
*/
|
||||
export function pay(order = {}) {
|
||||
const payType = order.payType || config.constants.PAY_TYPE.WXPAY
|
||||
const orderNo = order.orderNo || ''
|
||||
|
||||
// 余额支付:直接调用服务端确认接口(此处由调用方传入回调)
|
||||
// 余额支付:服务端已即时扣款,无需收银台
|
||||
if (payType === config.constants.PAY_TYPE.BALANCE) {
|
||||
return Promise.resolve({ success: true, payType, orderNo: order.orderNo })
|
||||
return Promise.resolve({ success: true, payType, orderNo })
|
||||
}
|
||||
|
||||
// 微信支付
|
||||
return new Promise((resolve, reject) => {
|
||||
if (typeof uni === 'undefined' || !uni.requestPayment) {
|
||||
// 非小程序环境(如 H5/测试)直接视为成功,便于联调
|
||||
return resolve({ success: true, payType, orderNo: order.orderNo, mock: true })
|
||||
}
|
||||
uni.requestPayment({
|
||||
// 微信支付:先拿调起参数(已在订单里带上 payParams 时直接复用)
|
||||
const fetchPayParams = () => {
|
||||
if (order.payParams) return Promise.resolve(order.payParams)
|
||||
if (!orderNo) return Promise.reject(toErr('缺少订单号,无法发起微信支付'))
|
||||
return payApi.prepay({ orderNo }).then((res) => {
|
||||
const params = res && res.payParams
|
||||
if (!params) throw toErr('微信支付未配置')
|
||||
return params
|
||||
})
|
||||
}
|
||||
|
||||
return fetchPayParams().then((payParams) => {
|
||||
const params = {
|
||||
provider: 'wxpay',
|
||||
timeStamp: order.timeStamp,
|
||||
nonceStr: order.nonceStr,
|
||||
package: order.package,
|
||||
signType: order.signType || 'RSA',
|
||||
paySign: order.paySign,
|
||||
success: () => resolve({ success: true, payType, orderNo: order.orderNo }),
|
||||
fail: (err) => reject(Object.assign(new Error('支付已取消'), { raw: err, code: 'PAY_CANCEL' })),
|
||||
timeStamp: String(payParams.timeStamp || ''),
|
||||
nonceStr: payParams.nonceStr || '',
|
||||
package: payParams.package || '',
|
||||
// JSAPI v2 默认 MD5;若服务端下发 signType 以服务端为准
|
||||
signType: payParams.signType || 'MD5',
|
||||
paySign: payParams.paySign || '',
|
||||
}
|
||||
if (typeof uni === 'undefined' || !uni.requestPayment) {
|
||||
// H5 / Node 测试环境:视为支付成功,便于离线联调
|
||||
return { success: true, payType, orderNo, mock: true, payParams: params }
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.requestPayment({
|
||||
...params,
|
||||
success: () => resolve({ success: true, payType, orderNo }),
|
||||
fail: (err) => reject(Object.assign(new Error('支付已取消'), { raw: err, code: 'PAY_CANCEL' })),
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
</view>
|
||||
<view class="fc-post-card__meta">
|
||||
<text class="fc-post-card__area">{{ post.area }}</text>
|
||||
<text v-if="distanceText" class="fc-post-card__dot">·</text>
|
||||
<text v-if="distanceText" class="fc-post-card__distance">{{ distanceText }}</text>
|
||||
<text class="fc-post-card__dot">·</text>
|
||||
<text class="fc-post-card__time">{{ timeText }}</text>
|
||||
</view>
|
||||
@@ -38,7 +40,7 @@
|
||||
|
||||
<script>
|
||||
import { iconUrl, categoryIconUrl } from '@/common/store/ui.js'
|
||||
import { fromNow } from '@/common/utils/format.js'
|
||||
import { fromNow, formatKm } from '@/common/utils/format.js'
|
||||
|
||||
export default {
|
||||
name: 'FcPostCard',
|
||||
@@ -49,6 +51,10 @@ export default {
|
||||
timeText() {
|
||||
return fromNow(this.post.createdAt)
|
||||
},
|
||||
/** 距离文案(如「1.2km」);契约下发的 distance 为 km,信息无坐标时为 null 不展示 */
|
||||
distanceText() {
|
||||
return this.post.distance == null ? '' : formatKm(this.post.distance)
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
iconUrl,
|
||||
@@ -122,6 +128,10 @@ export default {
|
||||
.fc-post-card__dot {
|
||||
margin: 0 8rpx;
|
||||
}
|
||||
.fc-post-card__distance {
|
||||
color: $fc-primary-text;
|
||||
font-weight: 600;
|
||||
}
|
||||
.fc-post-card__bottom {
|
||||
margin-top: auto;
|
||||
display: flex;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
> 角色视角:产品经理(PM)
|
||||
> 需求来源:客户提供的《同城分类信息小程序功能清单》功能表(角色端 / 一级模块 / 二级模块 / 核心功能描述)
|
||||
> 输出物:**用户端(小程序)**、**后台管理端(PC)** 功能模块清单 + 优先级 + 业务规则 + 接口映射
|
||||
> 版本:v1.0.0 编制日期:2026-10-15
|
||||
> 版本:v1.0.0 编制日期:2026-10-15(v1.1.0 状态更新:2026-10-17)
|
||||
|
||||
---
|
||||
|
||||
@@ -46,17 +46,17 @@
|
||||
| --- | --- | --- | --- | --- |
|
||||
| H1 | 分类导航 | 招聘、房产、二手、车辆、本地服务等一级分类展示(含图标、信息量) | P0 | `GET /home/categories` |
|
||||
| H2 | 轮播广告位 | 首页顶部轮播 Banner(**亮绿渐变底 + 墨绿字 + 白色插画大徽章**,可后台换色/换图),支持跳转分类/活动页 | P0 | `GET /home/banners` |
|
||||
| H3 | 信息流推荐 | 基于 LBS 定位的同城信息推荐,下拉刷新 + 上拉分页加载 | P0 | `GET /home/feed` |
|
||||
| H3 | 信息流推荐 | 基于 LBS 定位的同城信息推荐(✅ v1.1.0 已接入 `lat`/`lng`),下拉刷新 + 上拉分页加载 | P0 | `GET /home/feed` |
|
||||
| H4 | 智能搜索 | 关键词搜索、搜索历史(本地留存 10 条)、热门搜索词 | P0 | `GET /home/feed`、`GET /home/search/hot` |
|
||||
| H5 | 筛选排序 | 按区域、价格、发布时间、热度多维度筛选与排序 | P0 | `GET /home/feed?area=&sort=` |
|
||||
| H5 | 筛选排序 | 按区域、价格、发布时间、热度多维度筛选与排序;✅ v1.1.0 新增「附近」排序(`sort=nearby`,按距离升序,卡片显示 `distance`) | P0 | `GET /home/feed?area=&sort=` |
|
||||
| H6 | 会员引导位 | 首页会员权益卡片,引导开通(提升转化) | P1 | `GET /member/benefits` |
|
||||
|
||||
### 3.3 信息发布(Module-POST)
|
||||
|
||||
| 编号 | 二级模块 | 核心功能描述 | 优先级 | 对应接口 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| P1 | 发布表单 | 标题、内容、图片/视频上传、联系人、联系电话、地址定位 | P0 | `POST /post/create` |
|
||||
| P2 | 付费发布 | 按后台配置的单条价格付费发布(金额由**服务端**计算,客户端不可传价);支持微信 / 余额支付 | P0 | `POST /post/create` |
|
||||
| P1 | 发布表单 | 标题、内容、图片/视频上传(✅ v1.1.0 真上传 `POST /post/upload`)、联系人、联系电话、地址定位(✅ v1.1.0 采集 `lat`/`lng`) | P0 | `POST /post/upload`、`POST /post/create` |
|
||||
| P2 | 付费发布 | 按后台配置的单条价格付费发布(金额由**服务端**计算,客户端不可传价;✅ v1.1.0 支持会员折扣 `postDiscount`);支持微信 / 余额支付 | P0 | `POST /post/create` |
|
||||
| P3 | 套餐发帖 | 由后台「发布与费用配置」决定呈现:**免费发布**(全免)或**付费发布**(单条价格 / 按月含 N 条 / 按年含 M 条);购买后获得发布额度 | P1 | `GET /post/publish-config`、`GET /member/plans`、`POST /member/open` |
|
||||
| P4 | 草稿箱 | 编辑中自动保存(防抖 800ms),支持再次编辑发布 | P1 | `GET /post/drafts`、`POST /post/draft` |
|
||||
| P5 | 发布校验 | 必填校验、手机号格式校验、分类必选 | P0 | 前端 + `POST /post/create` |
|
||||
@@ -67,21 +67,22 @@
|
||||
| 编号 | 二级模块 | 核心功能描述 | 优先级 | 对应接口 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| D1 | 内容展示 | 图文详情、价格、区域地址、发布者信息 | P0 | `GET /post/{id}` |
|
||||
| D2 | 地图导航 | 点击地址调用 `uni.openLocation` 唤起地图导航 | P1 | 端能力 |
|
||||
| D3 | 收藏 / 分享 | 收藏信息;分享链接;生成分享海报 | P1 | 端能力 |
|
||||
| D4 | 付费查看 | 非会员查看联系方式/完整内容需付费或开通会员;后台可配置免费或付费 | P0 | `POST /post/{id}/pay-view` |
|
||||
| D2 | 地图导航 | 点击地址调用 `uni.openLocation` 唤起地图导航;✅ v1.1.0 使用信息真实坐标 `lat`/`lng` | P1 | `GET /post/{id}`、端能力 |
|
||||
| D3 | 收藏 / 分享 | 收藏信息(✅ v1.1.0 走接口 `POST /favorite/toggle` + 我的收藏页);分享链接;生成分享海报 | P1 | `POST /favorite/toggle`、`GET /favorite/list`、端能力 |
|
||||
| D4 | 付费查看 | 非会员查看联系方式/完整内容需付费或开通会员;后台可配置免费或付费;✅ v1.1.0 微信支付由 **epay 插件**承载(下单 → `/pay/prepay` → 回调解锁) | P0 | `POST /post/{id}/pay-view`、`POST /pay/prepay` |
|
||||
| D5 | 评价互动 | 会员可对信息评价/打分(1-5 星),支持图文评价 | P1 | `POST /post/{id}/comment` |
|
||||
| D6 | 联系与关注 | 拨打电话、复制微信号、关注发布者 | P1 | 端能力 |
|
||||
| D6 | 联系与关注 | 拨打电话、复制微信号、关注发布者(✅ v1.1.0 关注走接口 `POST /follow/toggle`) | P1 | `POST /follow/toggle`、端能力 |
|
||||
| D7 | **举报** | ✅ v1.1.0 新增:信息详情页举报入口(选原因 → 提交),原因字典由后台 `report.reasons` 维护 | P1 | `POST /report` |
|
||||
|
||||
### 3.5 会员中心(Module-MEMBER)
|
||||
|
||||
| 编号 | 二级模块 | 核心功能描述 | 优先级 | 对应接口 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| M1 | 会员权益 | 免费查看信息条数、发布折扣、分销比例;价格变化/到期状态提醒 | P0 | `GET /member/benefits` |
|
||||
| M2 | 会员开通 | 购买月卡 / 季卡 / 年卡;微信支付 / 余额支付 | P0 | `GET /member/plans`、`POST /member/open` |
|
||||
| M2 | 会员开通 | 购买月卡 / 季卡 / 年卡;微信支付 / 余额支付;✅ v1.1.0 微信支付由 **epay 插件**承载(pending 订单 → `/pay/prepay` → `/pay/notify` 发放) | P0 | `GET /member/plans`、`POST /member/open`、`POST /pay/prepay` |
|
||||
| M3 | 订单管理 | 查看发布订单、会员订单、充值订单状态 | P0 | `GET /member/orders` |
|
||||
| M4 | 我的资产 | 账户余额、优惠券管理、积分 | P1 | `GET /member/assets` |
|
||||
| M5 | 余额充值 | 余额充值下单与对账 | P2 | `POST /order/recharge` |
|
||||
| M4 | 我的资产 | 账户余额、优惠券管理、积分;✅ v1.1.0 `coupons` 返回真实已领券数组 + `couponCount` | P1 | `GET /member/assets` |
|
||||
| M5 | 余额充值 | ✅ v1.1.0 已实现:`pages/member/recharge` 充值下单与对账(**仅微信支付**,由 **epay 插件**经 `/pay/prepay` 调起、回调入账;服务端禁止 `payType=balance`——用余额给余额加钱属资损) | P2 | `POST /order/recharge`、`POST /pay/prepay` |
|
||||
|
||||
### 3.6 分销中心(Module-DIST)
|
||||
|
||||
@@ -104,8 +105,8 @@
|
||||
|
||||
| 编号 | 二级模块 | 核心功能描述 | 优先级 | 对应接口 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| U1 | 用户卡与资产 | 头像昵称、身份标签、余额/积分/优惠券概览 | P0 | `GET /member/assets` |
|
||||
| U2 | 功能入口 | 我的发布(→ `pages/post/mine`)、我的订单、分销中心、会员中心 | P0 | `GET /post/mine` |
|
||||
| U1 | 用户卡与资产 | 头像昵称、身份标签、余额/积分/优惠券概览;✅ v1.1.0 展示优惠券数量 | P0 | `GET /member/assets` |
|
||||
| U2 | 功能入口 | 我的发布(→ `pages/post/mine`)、我的订单、分销中心、会员中心;✅ v1.1.0 新增「我的收藏」(→ `pages/favorite/index`)与「余额充值」(→ `pages/member/recharge`) | P0 | `GET /post/mine`、`GET /favorite/list` |
|
||||
| U3 | 设置与关于 | 草稿箱、搜索记录、系统设置、关于我们 | P2 | `GET /admin/setting/base` |
|
||||
|
||||
---
|
||||
@@ -116,8 +117,10 @@
|
||||
|
||||
| 编号 | 二级模块 | 核心功能描述 | 优先级 | 对应接口 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| AD1 | 核心数据看板 | 今日/历史 PV·UV、发布量、订单额、会员数、商家数、分销佣金、待审核数 | P0 | `GET /admin/dashboard/overview` |
|
||||
| AD2 | 趋势分析 | 流量趋势图、营收趋势图、用户增长曲线 | P0 | `GET /admin/dashboard/trend?type=` |
|
||||
| AD1 | 核心数据看板 | 今日/累计发布量、待审核数、今日/累计订单额、会员/商家/用户数、待结算/已结算佣金、待审提现;✅ v1.1.0 后台 PC 页 `s.php/fc/dashboard/index` 已实现(**直接查 `fa_fc_*`/`fa_user`**) | P0 | 后台 `fc/dashboard/index` |
|
||||
| AD2 | 趋势分析 | 近 14 天发布量 / 订单额 / 新增用户趋势(echarts,含表格降级);✅ v1.1.0 同上页面 | P0 | 后台 `fc/dashboard/index` |
|
||||
|
||||
> 说明:`/api/v1/admin/dashboard/**` 接口仍存在且契约不变,但后台「数据总览」页面**直接查库**,未消费该组接口(`/api/v1/admin/**` 仍无 PC 界面消费)。
|
||||
|
||||
### 4.2 商家管理(Module-ADM-MERCHANT)
|
||||
|
||||
@@ -125,7 +128,7 @@
|
||||
| --- | --- | --- | --- | --- |
|
||||
| AM1 | 商家列表 | 商家信息、认证状态、店铺信息、违规记录检索 | P0 | `GET /admin/merchants` |
|
||||
| AM2 | 资质审核 | 营业执照、法人身份证人工审核,支持通过/驳回 | P0 | `POST /admin/merchant/{id}/audit` |
|
||||
| AM3 | 店铺管理 | 店铺装修、推荐位设置、店铺状态(封禁/恢复) | P1 | `POST /admin/merchant/{id}/shop` |
|
||||
| AM3 | 店铺管理 | ⚠️ v1.1.0 实现**字段级**店铺装修:店铺头图 `banner`、店铺公告 `notice`、推荐位 `recommend`(后台 `fc/merchant` add/edit 可编辑);**不含商家自助装修页**;店铺状态(封禁/恢复)沿用既有能力 | P1 | 后台 `fc/merchant/{add,edit}` |
|
||||
|
||||
### 4.3 会员管理(Module-ADM-MEMBER)
|
||||
|
||||
@@ -147,7 +150,7 @@
|
||||
| 编号 | 二级模块 | 核心功能描述 | 优先级 | 对应接口 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| AC1 | 评价列表 | 全平台评价查看,支持回复、置顶、删除 | P1 | `GET /admin/comments`、`POST /admin/comment/{id}/reply` |
|
||||
| AC2 | 举报处理 | 用户举报评价/信息的核实与处理 | P1 | `GET /admin/reports` |
|
||||
| AC2 | 举报处理 | 用户举报评价/信息的核实与处理;✅ v1.1.0 用户端举报入口上线(`POST /report`,详情页可提交) | P1 | `GET /admin/reports`、`POST /report` |
|
||||
|
||||
|
||||
### 4.6 分销管理(Module-ADM-DIST)
|
||||
@@ -186,12 +189,20 @@
|
||||
|
||||
| 编号 | 二级模块 | 核心功能描述 | 优先级 | 对应接口 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| AZ1 | 基础配置 | 小程序名称、Logo、客服电话、关于我们、分享标题 | P0 | `GET/POST /admin/setting/base` |
|
||||
| AZ2 | 支付配置 | 微信支付商户号、API 密钥配置 | P0 | `POST /admin/setting/pay` |
|
||||
| AZ1 | 基础配置 | 小程序名称、Logo、客服电话、关于我们、分享标题;✅ v1.1.0 后台 PC 页 `s.php/fc/setting/index` 已实现(键 `base.*`,与 `api/AdminSetting::base()` 同源) | P0 | 后台 `fc/setting/index` |
|
||||
| AZ2 | 支付配置 | 微信支付商户号、v2 密钥、小程序 AppID;✅ v1.1.0 改由 **epay 插件**维护(后台「插件管理 → 微信支付宝整合插件 → 配置」,键 `wechat.miniapp_id`/`wechat.mch_id`/`wechat.key`);后台 `fc/setting` 页已移除支付表单,仅保留只读状态 + 跳转插件配置 | P0 | 后台「插件管理 → 微信支付宝整合插件 → 配置」 |
|
||||
| AZ3 | 费用标准 | 单条发布价格、会员套餐价格(月/季/年)动态设置 | P0 | `GET/POST /admin/setting/fee` |
|
||||
| AZ5 | **发布与费用配置** | 发布模式开关(**免费发布 / 付费发布**)+ 会员单条发布价格 + 按月(价格 + 含条数)+ 按年(价格 + 含条数);保存后同步月卡(M1)/年卡(M12) 套餐 | P0 | 后台 `fc/publish/index` |
|
||||
| AZ4 | 地区管理 | 同城服务区域划分(增删改、排序、启用) | P0 | `GET /admin/setting/areas`、`POST /admin/setting/area` |
|
||||
|
||||
### 4.11 优惠券管理(Module-ADM-COUPON,v1.1.0 新增)
|
||||
|
||||
| 编号 | 二级模块 | 核心功能描述 | 优先级 | 对应位置 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| AC-C1 | 优惠券 CRUD | 优惠券模板增删改查:名称 / 类型(满减 `fixed`·折扣 `discount`)/ 面额 / 使用门槛 / 发行总量(0=不限量)/ 领取后有效天数 / 启用 / 排序 | P1 | 后台 `fc/coupon/index`(标准 CRUD) |
|
||||
|
||||
> 用户端领取与资产展示见 §3.5 M4 与接口文档 §2.7;**本轮不含下单抵扣**。
|
||||
|
||||
---
|
||||
|
||||
## 五、核心业务规则(产品约束)
|
||||
@@ -213,6 +224,7 @@
|
||||
| BR-13 | 发布计费 | 免费模式全部免费;付费模式按「套餐额度 → 每日免费条数 → 单条付费」顺序判定 | `post/create` |
|
||||
| BR-14 | 服务端定价 | 发布金额一律按后台配置计算,客户端传入的 `amount` 无效 | `post/create` |
|
||||
| BR-15 | 置顶优先 | 后台置顶的信息在首页信息流与「我的发布」中优先展示 | `post/top`、`home/feed` |
|
||||
| BR-16 | 发布折扣计价 | 单条付费金额 = `round(singlePrice × discountRate, 2)`,折扣率由 `member.benefit.postDiscount` 解析(如「8 折」→0.8);金额仍由服务端计算 | `post/create` |
|
||||
|
||||
## 六、优先级与迭代规划
|
||||
|
||||
@@ -226,8 +238,33 @@
|
||||
|
||||
| 端 | 接口前缀 | 接口数量 | 说明 |
|
||||
| --- | --- | --- | --- |
|
||||
| 用户端 | `/api/v1/auth`、`/home`、`/post`、`/member`、`/distribution`、`/message` | 24 | 小程序端调用 |
|
||||
| 后台管理端 | `/api/v1/admin/**` | 28 | PC 端调用 |
|
||||
| 用户端 | `/api/v1/auth`、`/home`、`/post`、`/member`、`/distribution`、`/message`、`/order`、`/pay`、`/coupon`、`/favorite`、`/follow`、`/report`、`/setting` | 41 | 小程序端调用(以 `application/route.php` 实际条目为准) |
|
||||
| 后台管理端 | `/api/v1/admin/**` | 32 | PC 端调用(以 `application/route.php` 实际条目为准) |
|
||||
|
||||
> 完整字段级契约见 `docs/03-接口文档.md`;全链路验证结论见 `docs/04-全链路测试用例与报告.md`。
|
||||
> 合计 **73 条**(用户端 41 + 后台 32)。完整字段级契约见 `docs/03-接口文档.md`;全链路验证结论见 `docs/04-全链路测试用例与报告.md`。
|
||||
|
||||
## 八、v1.1.0 实现状态与仍未实现项
|
||||
|
||||
**v1.1.0 已实现(接口端到端实测 226 例全绿)**:
|
||||
|
||||
| 能力 | 状态 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| LBS 定位 / 附近排序 | ✅ | `fc_post.lat/lng`;`GET /home/feed?sort=nearby` + `distance` |
|
||||
| 媒体上传 | ✅ | 用户端 `POST /post/upload`(图片 ≤10MB / 视频 ≤50MB),发布提交 URL 数组 |
|
||||
| 举报 | ✅ | `POST /report` + 详情页入口,原因字典 `report.reasons` |
|
||||
| 收藏 / 关注 | ✅ | `fc_favorite`/`fc_follow` + `/favorite/*`、`/follow/toggle` + 我的收藏页 |
|
||||
| 余额充值 | ✅ | `POST /order/recharge` + `pages/member/recharge` |
|
||||
| 优惠券 | ✅(部分) | 后台 CRUD + 用户领取 + 资产展示;**不含下单抵扣** |
|
||||
| 数据总览 | ✅ | 后台 `fc/dashboard/index`(直接查库) |
|
||||
| 系统设置 | ✅ | 后台 `fc/setting/index`(仅基础配置 `base.*`;支付配置改由插件配置页维护) |
|
||||
| 店铺装修 | ✅(字段级) | `fc_merchant.banner/notice/recommend` |
|
||||
|
||||
**本轮仍未实现**:
|
||||
|
||||
| 项 | 状态 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| 发票管理 | ❌ 未实现 | 会员/订单发票能力本轮未做 |
|
||||
| 优惠券下单抵扣 | ❌ 未实现 | 仅实现领取与展示 |
|
||||
| 商家自助装修页 | ❌ 未实现 | 仅后台字段级编辑(头图/公告/推荐位) |
|
||||
| 微信支付真机联调 | ❌ 未联调 | 插件商户参数尚未配置(`wechat.miniapp_id`/`wechat.mch_id`/`wechat.key` 为空),`/pay/prepay` 按契约返回「微信支付未配置」,`/pay/notify` 返回 SUCCESS 但不处理 |
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
> 角色视角:后端 / 前端联调工程师
|
||||
> 网关地址:`https://fenleixinxi.gzyakj.com.cn/api`
|
||||
> 版本前缀:`/api/v1`
|
||||
> 版本:v1.0.0 编制日期:2026-10-15
|
||||
> 版本:v1.0.0 编制日期:2026-10-15(v1.1.0 增补日期:2026-10-17)
|
||||
> **接口总数:73 条**(用户端 41 + 后台 32,以 `application/route.php` 实际登记条目为准;v1.1.0 新增用户端 11 条)
|
||||
|
||||
---
|
||||
|
||||
@@ -88,10 +89,12 @@
|
||||
| --- | --- | --- | --- |
|
||||
| GET | `/home/banners` | — | `[{ id, title, image, link, color }]` |
|
||||
| GET | `/home/categories` | — | `[{ id, name, icon, color, count }]` |
|
||||
| GET | `/home/feed` | `{ page, size, categoryId?, keyword?, area?, sort? }` | 分页 `list:[Post]`(含 `isTop`) |
|
||||
| GET | `/home/feed` | `{ page, size, categoryId?, keyword?, area?, sort?, lat?, lng? }` | 分页 `list:[Post]`(含 `isTop`、`distance`) |
|
||||
| GET | `/home/search/hot` | — | `[string]` |
|
||||
|
||||
- `sort` 枚举:`new`(默认,按发布时间)/ `hot`(按浏览量)/ `price`(按价格升序)
|
||||
- `sort` 枚举:`new`(默认,按发布时间)/ `hot`(按浏览量)/ `price`(按价格升序)/ **`nearby`(v1.1.0,按距离升序)**
|
||||
- **LBS 距离(v1.1.0)**:传入 `lat`/`lng`(gcj02,可与 `categoryId`/`keyword`/`area` 组合)后,列表项新增 `distance`(number|**km,一位小数**;请求未带坐标或信息未定位时为 `null`)。
|
||||
`sort=nearby` 时按 `distance` 升序,**无坐标的信息排最后**;请求未带 `lat`/`lng` 时 `nearby` 回落发布时间倒序。距离由服务端 Haversine 计算(`Post`/`Home` 同一算法),客户端不参与排序。
|
||||
- **置顶优先(v1.0.7)**:三种排序都先按 `is_top desc` 再按所选排序,即后台置顶的信息**始终排在非置顶之前**;
|
||||
`Post` 结构新增 `isTop: boolean`,卡片据此显示「置顶」角标
|
||||
|
||||
@@ -108,14 +111,15 @@
|
||||
|
||||
| 方法 | 路径 | 入参 | 返回 |
|
||||
| --- | --- | --- | --- |
|
||||
| POST | `/post/create` | `{ categoryId, title, content, media[], contact, phone, address, plan, payType }` | `{ postId, auditStatus, order?, plan, amount, quotaLeft }` |
|
||||
| POST | `/post/upload` | multipart `file`(+可选 `type=image\|video`) | `{ url, type, size, name }`(图片 ≤10MB / 视频 ≤50MB) |
|
||||
| POST | `/post/create` | `{ categoryId, title, content, media[], contact, phone, address, lat?, lng?, plan, payType }` | `{ postId, auditStatus, order?, plan, amount, discountRate, quotaLeft }` |
|
||||
| GET | `/post/mine` | `{ status?, page, size }` | 分页 `list:[MyPost]` + `counts{all,pending,passed,rejected,offline}` |
|
||||
| GET | `/post/publish-config` | — | `{ mode, singlePrice, monthPrice, monthQuota, yearPrice, yearQuota, quotaLeft, freePerDay, freeUsedToday, freeLeftToday, isMember }` |
|
||||
| GET | `/post/publish-config` | — | `{ mode, singlePrice, discountRate, discountText, monthPrice, monthQuota, yearPrice, yearQuota, quotaLeft, freeQuota, freeQuotaCycle, freeQuotaUsed, freeQuotaLeft, freeUnlimited, quotaExpireAt, isMember, memberExpireAt }` |
|
||||
| GET | `/post/drafts` | — | `[{ draftId, title, content, categoryId, savedAt }]` |
|
||||
| POST | `/post/draft` | 草稿内容 | `{ draftId, savedAt }` |
|
||||
| DELETE | `/post/{id}` | — | `{ deleted: true }` |
|
||||
| GET | `/post/{id}` | — | `Post`(含 `publisher`、`commentCount`) |
|
||||
| POST | `/post/{id}/pay-view` | `{ payType: 'wxpay'\|'balance' }` | `{ unlocked, contact: { phone, wechat } }` |
|
||||
| GET | `/post/{id}` | — | `Post`(含 `publisher`、`commentCount`、`lat`、`lng`、`distance`、`faved`、`followed`、`favoriteCount`、`media`) |
|
||||
| POST | `/post/{id}/pay-view` | `{ payType: 'wxpay'\|'balance' }` | 微信:`{ order: { orderNo, amount, payType, status: 'pending' } }`;余额:`{ unlocked, contact: { phone, wechat } }` |
|
||||
| POST | `/post/{id}/comment` | `{ score:1-5, content }` | `{ commentId }` |
|
||||
|
||||
**业务规则**:标题/内容必填;`payType` 仅支持 `wxpay`/`balance`;`score` 必须 1–5。
|
||||
@@ -133,6 +137,13 @@
|
||||
- `plan` 返回值为实际采用的方式:`free`(免费/每日免费额度)/ `quota`(套餐额度)/ `single`(单条付费)。
|
||||
- 额度与有效期:开通月/年卡时按套餐 `post_quota` 发放到 `fc_user_ext.post_quota_left`,有效期随会员到期时间,过期由服务端自动清零。
|
||||
|
||||
**媒体与坐标(v1.1.0)**:
|
||||
|
||||
- `media` 改为接收**上传后的 URL 数组**(先调 `POST /post/upload` 拿到 `url` 再提交),不再接受本地临时路径;`lat`/`lng` 可选(前端 `chooseLocation` 采集,gcj02),用于首页「附近」排序与详情页地图。
|
||||
- **单条付费折扣(v1.1.0)**:单条金额 = `round(singlePrice × discountRate, 2)`,`discountRate` 由会员权益 `member.benefit.postDiscount` 解析(如 `'8 折'`→0.8、`'9.5折'`→0.95;解析失败或不含折扣视作 1),返回体含 `discountRate`。金额仍只由服务端计算。
|
||||
- **付费查看改为真实支付闭环(v1.1.0)**:`payType=wxpay` 时**只落 `status=pending` 订单**(`type=payview`、`related_id=信息ID`),前端再调 `POST /pay/prepay` 调起收银台,支付成功后由 `/pay/notify` 写解锁记录;`payType=balance` 仍即时解锁并返回 `{ unlocked, contact }`。
|
||||
- **详情出参扩充(v1.1.0)**:`GET /post/{id}` 新增 `lat`、`lng`、`distance`、`faved`(我是否已收藏)、`followed`(我是否已关注发布者)、`favoriteCount`、`media`。
|
||||
|
||||
**我的发布(P8)状态口径**:`status` 支持 `all`(默认)/`pending` 待审核/`passed` 已通过/`rejected` 已驳回/`offline` 已下架;
|
||||
`MyPost` 含 `auditStatus`、`auditReason`(驳回原因)、`status`、`isTop`、`isPaid`、`amount`、`views`、`commentCount`、`createdAt`。
|
||||
|
||||
@@ -142,9 +153,12 @@
|
||||
| --- | --- | --- | --- |
|
||||
| GET | `/member/plans` | — | `[{ planId, name, price, originPrice, days, tag, postQuota }]` |
|
||||
| GET | `/member/benefits` | — | `{ freeView, postDiscount, distRate, benefits[] }` |
|
||||
| POST | `/member/open` | `{ planId, payType }` | `{ orderNo, status, expireAt, postQuota, quotaLeft, quotaExpireAt }` |
|
||||
| POST | `/member/open` | `{ planId, payType }` | 微信:`{ order: { orderNo, amount, payType, status: 'pending' }, status: 'pending' }`;余额:`{ orderNo, status: 'paid', expireAt, postQuota, quotaLeft, quotaExpireAt }` |
|
||||
| GET | `/member/orders` | `{ page, size }` | 分页订单(`type: post\|member\|recharge`) |
|
||||
| GET | `/member/assets` | — | `{ balance, coupons[], points }` |
|
||||
| GET | `/member/assets` | — | `{ balance, coupons[], couponCount, points }` |
|
||||
|
||||
- **会员开通改为真实支付闭环(v1.1.0)**:`payType=wxpay` 时**只落 `status=pending` 订单**(`related_id=套餐ID`),前端再调 `POST /pay/prepay`;会员由 `/pay/notify` 复用 `Member::grantMembership()` 发放。`payType=balance` 仍即时开通。
|
||||
- **我的资产(v1.1.0)**:`coupons` 返回**真实已领券数组**(来自 `fc_user_coupon` + `fc_coupon`):`[{ id, couponId, name, type, amount, minAmount, status, expireAt }]`;新增 `couponCount`(= 已领券数量)。
|
||||
|
||||
### 2.5 分销中心 `common/api/distribution.js`
|
||||
|
||||
@@ -164,6 +178,44 @@
|
||||
| GET | `/message/list` | `{ type: 'system'\|'interact', page, size }` | 分页 `[{ id, type, title, content, read, createdAt }]` |
|
||||
| POST | `/message/{id}/read` | — | `{ read: true }` |
|
||||
|
||||
### 2.7 交易与支付(v1.1.0)`common/api/{order,pay,coupon}.js`
|
||||
|
||||
| 方法 | 路径 | 入参 | 返回 |
|
||||
| --- | --- | --- | --- |
|
||||
| POST | `/order/recharge` | `{ amount, payType: 'wxpay' }`(**只允许微信支付**) | `{ orderNo, amount, status: 'pending', payType: 'wxpay' }` |
|
||||
| POST | `/pay/prepay` | `{ orderNo }` | `{ orderNo, payType: 'wxpay', payParams: { timeStamp, nonceStr, package, signType, paySign } }`(**不含 `appId`**,下发前已剔除) |
|
||||
| POST | `/pay/notify` | 微信支付异步通知(**公开路由,无需登录**;V2 报文为 XML,验签与应答均由 **epay 插件**处理) | 纯 XML 应答(`SUCCESS` / `FAIL`) |
|
||||
| GET | `/coupon/list` | `{ page, size }` | 分页 `list:[{ id, couponId, name, type, amount, minAmount, total, receivedCount, left, days, received, createdAt }]` |
|
||||
| POST | `/coupon/receive` | `{ couponId }` | `{ userCouponId }` |
|
||||
|
||||
**余额充值(`/order/recharge`)**:`amount > 0 且 ≤ 100000`(否则「充值金额不合法」);**`payType` 仅支持 `wxpay`**(`balance` → 「余额充值仅支持微信支付」,其它 → 「支付方式不支持」)。
|
||||
`wxpay` → 订单落 `pending`,前端调 `/pay/prepay` 调起收银台,付款成功后由 `/pay/notify` 回调入账(`Order::creditRecharge()`)。
|
||||
> ⚠️ **为什么禁止 `balance` 充值**:用余额给余额加钱没有任何收款方(余额只 +amount、不扣减),等于给用户**凭空增发余额**(可再去买会员 / 付费发布 / 解锁联系方式),属资损漏洞,v1.1.0 已修复。
|
||||
> 给用户加余额只有两条合法路径:① 微信支付回调;② 后台「会员管理 → 余额充值」(`fc/userext/recharge`)。
|
||||
|
||||
**微信支付统一下单(`/pay/prepay`)**:校验订单属于当前用户、`status=pending`、`pay_type=wxpay`;金额只用**服务端订单金额**(元,插件内部 ×100 转分);取 `fc_user_ext.openid` 作小程序支付者;下单由 **epay 插件** `Service::submitOrder($amount, $orderNo, 'wechat', $body, $notifyUrl, null, 'miniapp', $openid)` 完成,插件返回的调起参数**剔除 `appId`** 后下发 `payParams`(仅 `timeStamp/nonceStr/package/signType/paySign` 五个字段)。
|
||||
插件商户参数未配置(`wechat.miniapp_id`/`wechat.mch_id`/`wechat.key` 未齐备)→ `fail('微信支付未配置')`。契约详见 `docs/05-后端实现规范.md §7.9`。
|
||||
|
||||
**支付回调(`/pay/notify`)**:**公开路由、无需登录**;验签与应答由 **epay 插件**承担(`Service::checkNotify('wechat')` + `$pay->verify()`,成功应答由 `$pay->success()` 生成,V2 为纯 XML);回调地址由服务端按当前请求域名 + `/api/v1/pay/notify` 动态生成。处理顺序:**幂等**(订单已 `paid` 直接返回 SUCCESS)→ **金额核对**(回调 `total_fee`(分)必须等于订单金额(元×100),不一致返回 FAIL「订单金额不一致」)→ 按 `fc_order.type` 分派后续动作。**该接口是全项目唯一以纯 XML(而非 JSON)应答的动作**,原因与 `notifyCallback()` 命名见 `docs/05-后端实现规范.md §7.9`(BUG-015)。
|
||||
|
||||
**优惠券(`/coupon/list`、`/coupon/receive`)**:`list` 仅下发 `enabled=1` 的券,`received` 表示当前用户是否已领取,`left` 为剩余可领(`-1` 表示不限量)。
|
||||
`receive` 校验:券存在且启用、未领完(否则「优惠券已领完」)、同一用户同一券只能领一次(否则「您已领取过该优惠券」);`days>0` 时按「领取时间 + days 天」写 `expiretime`。
|
||||
> 本轮优惠券**仅实现后台 CRUD + 用户领取 + 资产展示,不含下单抵扣**。
|
||||
|
||||
### 2.8 互动(举报 / 收藏 / 关注,v1.1.0)`common/api/{report,favorite}.js`
|
||||
|
||||
| 方法 | 路径 | 入参 | 返回 |
|
||||
| --- | --- | --- | --- |
|
||||
| POST | `/report` | `{ targetType: 'post'\|'comment', targetId, reason, detail? }` | `{ reportId }` |
|
||||
| GET | `/favorite/list` | `{ page, size }` | 分页 `list:[Post]`(与信息流同构) |
|
||||
| POST | `/favorite/toggle` | `{ postId }` | `{ faved, count }` |
|
||||
| POST | `/follow/toggle` | `{ userId }` | `{ followed }` |
|
||||
| POST | `/favorite/status` | `{ postIds: [], userIds: [] }` | `{ faved: { postId: bool }, followed: { userId: bool } }` |
|
||||
|
||||
- **举报**:`targetType` 仅 `post`/`comment`(否则「举报类型不支持」);`reason` 必填(否则「请选择举报原因」,字典见 `report.reasons`);被举报对象必须存在;`detail` 写入 `fc_report.remark`,状态默认 `pending`。
|
||||
- **收藏 / 关注**:`faved=true` 表示本次操作后为「已收藏」,`count` 为该信息当前收藏总数;`follow/toggle` 不能关注自己(「不能关注自己」)。两表均有唯一索引,并发写入幂等。
|
||||
- **批量回显**:`favorite/status` 入参为空数组时返回**空对象** `{}`,查询结果按请求的 id 全量回填(未收藏/未关注为 `false`)。
|
||||
|
||||
---
|
||||
|
||||
## 三、后台管理端接口(PC)`common/api/admin.js`
|
||||
@@ -243,7 +295,7 @@
|
||||
| 方法 | 路径 | 入参 | 返回 |
|
||||
| --- | --- | --- | --- |
|
||||
| GET/POST | `/admin/setting/base` | `{ appName, logo, servicePhone, aboutUs }` | 基础配置(`appName` 必填) |
|
||||
| POST | `/admin/setting/pay` | `{ mchId, apiKey }` | `{ configured: true }`(两项均必填) |
|
||||
| POST | `/admin/setting/pay` | `{ mchId, apiKey }` | `{ configured: true }`(两项均必填;语义为把 `mchId`/`apiKey` 写入 **epay 插件配置** 的 `wechat.mch_id`/`wechat.key`,不再写 `fc_config`) |
|
||||
| GET/POST | `/admin/setting/fee` | `{ singlePost, memberMonth, memberQuarter, memberYear }` | 费用标准(不得为负) |
|
||||
| GET | `/admin/setting/areas` | — | 区域列表 |
|
||||
| POST | `/admin/setting/area` | `{ name, sort, enabled }` | `{ id, name }`(`name` 必填) |
|
||||
@@ -296,7 +348,7 @@ LOGO = logo(后台自定义) || '/static/logo.png'(内置)
|
||||
| 真实请求失败(超时/断网)且 `enableMockFallback = true` | 自动降级到同名 mock 路由 |
|
||||
| mock 无匹配路由 | 抛出原始网络异常 |
|
||||
|
||||
- Mock 路由表:`common/mock/index.js`(65 条路由,覆盖上表全部接口,含 v1.0.7 的 `/post/mine`、`/post/publish-config`、服务端定价模拟与 v1.0.8 的 `/auth/wx-phone`)
|
||||
- Mock 路由表:`common/mock/index.js`(**77 条**路由,覆盖上表全部接口,含 v1.0.7 的 `/post/mine`、`/post/publish-config`、服务端定价模拟,v1.0.8 的 `/auth/wx-phone`,以及 v1.1.0 的 `/post/upload`、`/report`、`/favorite/*`、`/follow/toggle`、`/order/recharge`、`/pay/*`、`/coupon/*` 与 `home/feed` 的 LBS)
|
||||
- Mock 数据集:`common/mock/data.js`
|
||||
- 切换真实后端:确保 `common/config/index.js` 中 `forceMock = false`、`enableMockFallback = false`(生产建议关闭降级以暴露真实问题)
|
||||
|
||||
@@ -307,7 +359,7 @@ LOGO = logo(后台自定义) || '/static/logo.png'(内置)
|
||||
- [x] 分页统一返回 `{ list, page, size, total, hasMore }`
|
||||
- [x] 字段命名保持小驼峰,与本文档一致
|
||||
- [ ] 小程序后台已配置 `request 合法域名`:`https://fenleixinxi.gzyakj.com.cn`
|
||||
- [x] 图片/视频上传走独立上传接口 `POST /admin/upload`
|
||||
- [x] 图片/视频上传走独立上传接口:用户端 `POST /post/upload`(v1.1.0)、后台 `POST /admin/upload`
|
||||
|
||||
---
|
||||
|
||||
@@ -368,27 +420,29 @@ FastAdmin 原生 `Api::success()` 输出 `{code:1,msg,time,data}`,与本契约
|
||||
|
||||
## 七、验证结果(真实线上环境)
|
||||
|
||||
验证脚本:`tools/verify-api.mjs`(63 端点 + 12 条业务规则 + 8 步双端业务闭环)
|
||||
验证脚本:`tools/verify-api.mjs`(端点契约 + 业务规则文案比对 + 8 步双端业务闭环)
|
||||
|
||||
```bash
|
||||
node tools/verify-api.mjs # 验证线上
|
||||
FC_BASE=http://127.0.0.1/api/v1 node tools/verify-api.mjs # 验证本地
|
||||
FC_BASE=http://127.0.0.1:8899/api/v1 node tools/verify-api.mjs # 验证本地
|
||||
```
|
||||
|
||||
```
|
||||
————————— 验证结果 —————————
|
||||
用例总数: 178 通过: 178 失败: 0
|
||||
用例总数: 226 通过: 226 失败: 0
|
||||
```
|
||||
|
||||
> v1.1.0 在 v1.0.9 的 187 例基础上**新增 39 例**(覆盖 媒体上传 / LBS 附近排序与 `distance` / 详情新增字段 / 收藏关注 / 举报 / 余额充值 / 微信 prepay / 回调公开路由 / 优惠券领取 / 会员资产券 / 发布带媒体与坐标回读)。
|
||||
|
||||
**覆盖内容**
|
||||
|
||||
| 分类 | 用例数 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| 用户端接口 | 47 | 28 个端点 + 字段契约断言 |
|
||||
| 后台端接口 | 63 | 35 个端点 + 字段契约断言 |
|
||||
| 业务规则 BR-01~BR-12 | 33 | 错误码与**文案逐字比对** |
|
||||
| 结构断言 | 27 | HTTP 200 / `{code,message,data}` / 分页结构 / 字段齐全 |
|
||||
| 双端业务闭环 | 8 | 见下 |
|
||||
| 分类 | 说明 |
|
||||
| --- | --- |
|
||||
| 用户端接口 | 全部用户端端点 + 字段契约断言(含 v1.1.0 的 `/post/upload`、`/home/feed?sort=nearby`、`/favorite/*`、`/follow/toggle`、`/report`、`/order/recharge`、`/pay/prepay`、`/pay/notify`、`/coupon/*`) |
|
||||
| 后台端接口 | `/api/v1/admin/**` 全部端点 + 字段契约断言 |
|
||||
| 业务规则 | BR 错误码与**文案逐字比对** |
|
||||
| 结构断言 | HTTP 200 / `{code,message,data}` / 分页结构 / 字段齐全 |
|
||||
| 双端业务闭环 | 见下 |
|
||||
|
||||
**双端业务闭环(用户操作 → 后台操作 → 前台生效)**
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
> 角色视角:软件测试工程师(QA)
|
||||
> 测试类型:接口契约测试 + 端到端业务流测试 + 边界/异常测试
|
||||
> 执行方式:Node 18 运行 `tests/run.sh`(零第三方依赖,可在 HBuilderX 内置 Node 下执行)
|
||||
> 执行日期:2026-10-16 版本:v1.0.9(微信昵称/头像采集 + 会员手机号真绑定 + 后台会员列表字段调整)
|
||||
> 执行日期:2026-10-17 版本:v1.1.0(微信支付闭环 + 媒体上传 + LBS + 举报 + 收藏关注 + 余额充值 + 优惠券 + 数据总览/系统设置)
|
||||
|
||||
---
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
|
||||
| 项 | 说明 |
|
||||
| --- | --- |
|
||||
| 被测对象 | ① 统一请求层 `common/utils/request.js` ② 7 个 API 模块(用户端 6 + 后台 1) ③ Mock 路由表 `common/mock`(作为接口契约参照) ④ 工具函数 `common/utils/format.js` |
|
||||
| 覆盖接口 | 用户端 29 个 + 后台端 35 个 = **64 个接口** |
|
||||
| 被测对象 | ① 统一请求层 `common/utils/request.js` ② API 模块 `common/api/*.js`(认证/首页/发布/会员/分销/消息/收藏/举报/订单/支付/优惠券/设置/后台) ③ Mock 路由表 `common/mock`(作为接口契约参照) ④ 工具函数 `common/utils/format.js` |
|
||||
| 覆盖接口 | `application/route.php` 实际 **73 条**路由(用户端 41 + 后台 32);Mock 路由表 **77 条** |
|
||||
| 测试层级 | 单元(工具/请求层)→ 集成(API 模块 ↔ Mock 契约)→ 端到端(用户端 8 步 + 后台端 7 步业务闭环) |
|
||||
| 测试手段 | 断言响应结构、业务规则拦截、异常分支、分页边界、精度校验 |
|
||||
| 缺陷判定 | 用例失败即缺陷;已发现并修复 14 个缺陷(详见第五章) |
|
||||
| 缺陷判定 | 用例失败即缺陷;已发现并修复 15 个缺陷(详见第五章) |
|
||||
|
||||
## 二、用例清单与结果
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
| AC-RBAC-02 | 权限 | 新建角色需名称 + 至少 1 项权限 | ✅ PASS |
|
||||
| AC-RBAC-03 | 权限 | 子账号与操作日志可查询 | ✅ PASS |
|
||||
| AC-SET-01 | 系统设置 | 基础配置:小程序名称必填 | ✅ PASS |
|
||||
| AC-SET-02 | 系统设置 | 支付配置:商户号与密钥必填 | ✅ PASS |
|
||||
| AC-SET-02 | 系统设置 | 支付配置:商户号与密钥必填(写入 **epay 插件配置** `wechat.mch_id`/`wechat.key`) | ✅ PASS |
|
||||
| AC-SET-03 | 系统设置 | 费用标准动态设置,不得为负 | ✅ PASS |
|
||||
| AC-SET-04 | 系统设置 | 地区管理:区域名称必填 | ✅ PASS |
|
||||
|
||||
@@ -204,7 +204,7 @@
|
||||
| PUB-02 | 免费模式:所有人免费发布且不消耗额度 | 无订单、`plan=free`、`amount=0`(额度为 0 也不收费) | ✅ PASS |
|
||||
| PUB-03 | 套餐额度内免费发布 | 无订单、`plan=quota`、`quotaLeft` 递减,且该信息出现在「我的发布 → 待审核」 | ✅ PASS |
|
||||
| PUB-04 | 额度与每日免费次数都用尽时拦截 | 报「请选择发布方式」(BR-13) | ✅ PASS |
|
||||
| PUB-05 | 付费模式保留每日免费额度 | 每日前 N 条免费且 `freeLeftToday` 递减;超出后必须付费 | ✅ PASS |
|
||||
| PUB-05 | 付费模式保留免费额度 | 周期内前 N 条免费且 `freeQuotaLeft` 递减;超出后必须付费 | ✅ PASS |
|
||||
| PUB-06 | **单条付费金额取后台配置** | 客户端传 `amount: 0.01` 被忽略,订单金额 = 配置值 5 元(BR-14) | ✅ PASS |
|
||||
| PUB-07 | 单条付费缺少支付方式 | 报「支付方式不支持」 | ✅ PASS |
|
||||
| PUB-08 | 月卡/年卡开通发放发布条数 | `M1 → postQuota=30`、`M12 → postQuota=500`,额度可叠加(0 → 30 → 529) | ✅ PASS |
|
||||
@@ -263,26 +263,71 @@
|
||||
| 接口回归 | `node tools/verify-api.mjs` → **187 / 187 通过**(新增 A6 缺文件、A4 空提交) |
|
||||
| 数据清理 | 验证用的探针会员与测试头像文件已删除,会员总数恢复 15 |
|
||||
|
||||
### 2.11 v1.1.0 支付 / 上传 / LBS / 互动 / 优惠券(28 例)
|
||||
|
||||
> 需求背景:本轮补齐「微信支付真实闭环、发布媒体真上传、LBS 距离、举报、收藏关注、余额充值、优惠券、数据总览/系统设置」。
|
||||
> 对应用例文件:`tests/v110.test.mjs`(28 例,Mock 契约层);另有后端端到端 `tools/verify-api.mjs` 新增 39 例、后台 PC 页面 6 个 HTTP 200 实测(见下)。
|
||||
|
||||
| 用例编号 | 用例名称 | 预期结果 | 结果 |
|
||||
| --- | --- | --- | --- |
|
||||
| V110-01 | `manifest.json` 版本号升级到 `1.1.0` | versionName = 1.1.0 | ✅ PASS |
|
||||
| V110-02 | 新增页面注册进 `pages.json`(收藏 / 余额充值) | `pages/favorite/index`、`pages/member/recharge` 已声明且 `.vue` 存在 | ✅ PASS |
|
||||
| V110-03 | 媒体真上传:图片 / 视频返回可持久化地址与类型 | `url` 含 `/uploads/`、`type=image/video`、`size>0` | ✅ PASS |
|
||||
| V110-04 | 未选择文件时上传被拦截 | 报「未接收到上传文件」 | ✅ PASS |
|
||||
| V110-05 | 提交举报成功且后台可查见 | 返回 `reportId`;后台举报列表可见 | ✅ PASS |
|
||||
| V110-06 | 举报参数校验:类型 / 对象 / 原因 | 缺失与非法分别被拦截 | ✅ PASS |
|
||||
| V110-07 | 批量回显收藏 / 关注状态 | `faved`/`followed` 按请求 id 全量回填 | ✅ PASS |
|
||||
| V110-08 | 收藏切换:加入后 `count` +1,再次切换取消 | `faved` 取反 | ✅ PASS |
|
||||
| V110-09 | 关注切换:关注 / 取消关注发布者 | `followed` 取反 | ✅ PASS |
|
||||
| V110-10 | 我的收藏列表项为 Post 结构 + 参数校验 | 列表项含 `title`/`categoryId`;缺参数被拦截 | ✅ PASS |
|
||||
| V110-11 | 余额支付充值被拒绝(防资损:用余额给余额加钱) | 报「余额充值仅支持微信支付」且余额不变 | ✅ PASS |
|
||||
| V110-12 | 微信支付:订单 `pending`,余额不立即变化 | 待回调入账 | ✅ PASS |
|
||||
| V110-13 | 充值校验:金额合法 + 上限 + 支付方式 | 金额非法 / 超上限 / 方式不支持被拦截 | ✅ PASS |
|
||||
| V110-14 | `prepay` 返回 JSAPI 调起参数 | `payParams` 含 `timeStamp/nonceStr/package/signType/paySign` | ✅ PASS |
|
||||
| V110-15 | 缺少订单号 / 插件商户参数未配置时给出中文提示 | 「缺少订单号」/「微信支付未配置」 | ✅ PASS |
|
||||
| V110-16 | `pay()`:余额支付直接成功 | `success=true`、`payType=balance` | ✅ PASS |
|
||||
| V110-17 | `pay()`:微信支付取 prepay 参数 | 无 `requestPayment` 环境按成功返回 | ✅ PASS |
|
||||
| V110-18 | 可领取列表排除停发券并带出已领取标记 | `enabled=false` 不发放;`received` 为布尔 | ✅ PASS |
|
||||
| V110-19 | 领取新券后列表标记已领取、资产张数 +1 | `couponCount` +1 | ✅ PASS |
|
||||
| V110-20 | 重复领取 / 停发 / 不存在分别被拦截 | 三条文案正确 | ✅ PASS |
|
||||
| V110-21 | 带 `lat`/`lng` 时按坐标实时计算距离(km,一位小数) | 距离一位小数且为实时计算 | ✅ PASS |
|
||||
| V110-22 | `sort=nearby`:非置顶项按距离升序,无坐标信息排最后 | 末项 `distance=null` | ✅ PASS |
|
||||
| V110-23 | 不带坐标时距离一律为 null(与后端 `Home::feed` 一致) | 全列表 `distance=null` | ✅ PASS |
|
||||
| V110-24 | `parseDiscountRate`:折扣文案解析为费率 | `'8 折'`→0.8、`'7.5 折'`→0.75、异常→1 | ✅ PASS |
|
||||
| V110-25 | 单条付费按服务端折扣率计价(客户端金额被忽略) | `discountRate=0.8`、订单金额 = 4(5×0.8) | ✅ PASS |
|
||||
| V110-26 | 默认折扣率为 1 时金额等于后台单价 | 订单金额 = 5 | ✅ PASS |
|
||||
| V110-27 | 我的资产带 `couponCount` 且与已领券一致 | `coupons.length === couponCount` | ✅ PASS |
|
||||
| V110-28 | `formatKm`:km 一位小数,空值不展示 | `1.2km`/`0.0km`;`null`/`undefined`/`''` 返回空 | ✅ PASS |
|
||||
|
||||
**后端端到端(`tools/verify-api.mjs`,本地 `FC_BASE=http://127.0.0.1:8899/api/v1`)**:在 v1.0.9 的 187 例基础上新增 39 例,
|
||||
**用例总数 226,通过 226,失败 0**,覆盖:媒体上传(`POST /post/upload`,真实落盘)/ LBS 附近排序与 `distance` / 详情新增字段 / 收藏关注 / 举报(含文案校验)/ 余额充值(**仅微信支付 pending**;`balance` 被拒绝——资损防护)/ **epay 插件下单** `POST /pay/prepay`(返回剔除 `appId` 的调起参数)/ `POST /pay/notify` 公开路由(**插件验签**、XML 应答)/ 优惠券领取 / 会员资产券 / 发布带媒体与坐标回读。
|
||||
|
||||
**后台 PC 页面 HTTP 200 实测(6/6)**:`fc/dashboard/index`、`fc/setting/index`、`fc/coupon/index`、`fc/coupon/add`、`fc/merchant/add`、`fc/merchant/edit`。
|
||||
|
||||
**静态校验**:`node tests/validate.mjs` 错误 0、警告 0;`node tools/check-scss.cjs` 编译通过 19 个、失败 0;`node tools/check-admin-i18n.mjs` 错误 0、警告 0;`node tools/check-theme.mjs` 错误 0、警告 0;全量 PHP 文件 `php -l` 通过、新增后台 JS `node --check` 通过。
|
||||
|
||||
## 三、执行结果汇总
|
||||
|
||||
```
|
||||
=========== 全链路接口测试报告 ===========
|
||||
用例总数: 139 通过: 139 失败: 0
|
||||
用例总数: 167 通过: 167 失败: 0
|
||||
🎉 全部用例通过,前后端接口契约与业务规则校验一致。
|
||||
```
|
||||
|
||||
| 指标 | 数值 |
|
||||
| --- | --- |
|
||||
| 用例总数 | 139 |
|
||||
| 通过 | 139 |
|
||||
| 用例总数 | 167(原 139 + v1.1.0 新增 28) |
|
||||
| 通过 | 167 |
|
||||
| 失败 | 0 |
|
||||
| 通过率 | **100%** |
|
||||
| 覆盖接口 | 64 / 64(用户端 29 + 后台 35) |
|
||||
| 覆盖业务规则 | 15 / 15(BR-01 ~ BR-15,含 v1.0.7 新增 BR-13/14/15) |
|
||||
| 覆盖接口 | `route.php` 73 条路由(用户端 41 + 后台 32);Mock 路由表 77 条 |
|
||||
| 覆盖业务规则 | 16 / 16(BR-01 ~ BR-16,含 v1.1.0 新增 BR-16 折扣计价) |
|
||||
| 内置配图完整性 | 74 / 74(PNG 魔数 + 透明通道 + 尺寸一致) |
|
||||
| 轮播配图完整性 | 3 / 3(192×192 + 真实透明 + 白色插画 + 合计 6.0KB) |
|
||||
| SCSS 编译 | 17 / 17 |
|
||||
| SCSS 编译 | 19 / 19 |
|
||||
| 结构校验错误 | 0 |
|
||||
| 后端端到端 | 226 / 226(`tools/verify-api.mjs`,v1.1.0 新增 39 例) |
|
||||
| 后台 PC 页面 | 6 / 6(HTTP 200 实测) |
|
||||
|
||||
### 3.1 业务规则覆盖矩阵
|
||||
|
||||
@@ -303,6 +348,7 @@
|
||||
| BR-13 | 发布计费模式(免费/付费 + 额度 + 每日免费) | PUB-02、PUB-03、PUB-04、PUB-05 |
|
||||
| BR-14 | 发布金额服务端定价(忽略客户端 amount) | PUB-06 |
|
||||
| BR-15 | 置顶优先展示 | PUB-12、UC-FEED-05、UC-FEED-06 |
|
||||
| BR-16 | 发布折扣计价(服务端折扣率) | V110-24、V110-25、V110-26 |
|
||||
|
||||
---
|
||||
|
||||
@@ -324,8 +370,10 @@ node tests/run.mjs # 全链路接口 + 图标/LOGO 测试
|
||||
| `tests/request.test.mjs` | 请求层单元测试(11 例) |
|
||||
| `tests/icons.test.mjs` | 图标/LOGO 资源完整性与自定义闭环(16 例) |
|
||||
| `tests/banners.test.mjs` | 首页轮播配图资源、取图/金色规则、主题护栏与「亮绿面不得配白字」规则(17 例) |
|
||||
| `tests/api.user.contract.test.mjs` | 用户端接口契约测试(27 例) |
|
||||
| `tests/api.user.contract.test.mjs` | 用户端接口契约测试(33 例) |
|
||||
| `tests/api.admin.contract.test.mjs` | 后台端接口契约测试(28 例) |
|
||||
| `tests/publish.test.mjs` | 发布侧:我的发布 / 置顶 / 免费-付费发布与计费(14 例) |
|
||||
| `tests/v110.test.mjs` | v1.1.0:支付 / 上传 / LBS / 互动 / 优惠券(28 例) |
|
||||
| `tests/e2e.flow.test.mjs` | 端到端业务流 + 边界异常(20 例) |
|
||||
| `tests/validate.mjs` | 结构校验:路由、`.vue` 标签、SCSS 括号、import 依赖、JS 语法、WXML 标签配平 |
|
||||
| `tools/check-scss.cjs` | SCSS 全量编译校验(dart-sass) |
|
||||
@@ -355,8 +403,10 @@ node tests/run.mjs # 全链路接口 + 图标/LOGO 测试
|
||||
| BUG-012 | **高** | 发布计费 / 资损风险 | **发布金额由前端传入、后端直接采信**:`POST /post/create` 取客户端 `amount` 作为订单金额,客户端篡改(如传 `0.01`)即可用一分钱发布 | 早期快速联调时把定价放在前端(`pages/post/create.vue` 内写死 `5 / 19.9`),后端只做余额校验 | ✅ 已修复:改为**服务端定价**——金额一律按后台「发布与费用配置」的 `post.singlePrice` 计算,客户端 `amount` 被忽略(旧客户端 `paid=true` 形态仍兼容但同样按服务端价);前端不再写死任何金额,新增 PUB-06 回归用例 |
|
||||
| BUG-013 | **高** | 手机号绑定 / 会员数据 | **「手机号授权绑定」是假实现**:小程序登录页点击绑定后只在前端拼了 `138 + 时间戳` 的假号并写进本地 store,从未调用后端接口 —— 导致 `fa_user.mobile` 始终为空、后台会员列表手机号列大面积为空,运营拿不到会员联系方式 | 该交互是早期占位实现(`pages/auth/login.vue` 的 `onBindPhone`),后端 `POST /auth/bind-phone` 一直存在但从无调用方 | ✅ 已修复:① 登录页改为 `<button open-type="getPhoneNumber">` 调用新增的 `POST /auth/wx-phone`(后端用 access_token 调微信 `phonenumber.getPhoneNumber` 真实取号并写入 `fa_user.mobile`);② 微信侧不可用(未开通快捷验证/额度用尽/code 失效/用户拒绝)自动回落手动输入 `bind-phone`;③ 后台会员列表对存量用户回落显示「发布信息里的联系电话」并标注来源;新增 2 条回归用例 |
|
||||
| BUG-014 | 中 | 会员资料 / 微信授权 | **会员的微信昵称与头像从未被采集**:微信登录只传 `code`,新会员一律落成占位昵称 `同城用户XXXX`、`avatar` 为空;后台「会员列表」看不到真实微信昵称与头像(只能显示字母头像),运营无法据此识别会员 | 微信 2022 年起已回收 `getUserProfile` 主动拉取资料的能力,需用 `open-type="chooseAvatar"` + `<input type="nickname">` 由用户授权;登录页当时没有这两个组件,后端也没有头像上传接口 | ✅ 已修复:① 登录页新增头像/昵称采集(官方组件)并在登录时提交;② 新增 `POST /auth/avatar`(用户端 multipart 上传,写入 `fa_user.avatar`)与 `POST /auth/profile` 资料更新;③ 新用户落库、老用户带上新值时更新;新增 3 条回归用例 |
|
||||
| BUG-015 | **高** | 微信支付 / 后端兼容性 | **`POST /pay/prepay` 与 `POST /pay/notify` 全部返回 HTTP 500**(微信支付接口整体不可用) | 回调动作方法命名为 `Pay::notify()`,与 V1 基类的 protected `notify($userId,$type,$title,$content)`(发站内信)**同名但签名不兼容** —— PHP 抛兼容性告警,被 ThinkPHP 的错误处理转成 **HTTP 500** | ✅ 已修复:动作方法改名 `notifyCallback()`,并同步 `route.php` 映射 `'api/v1/pay/notify' => 'api/Pay/notifyCallback'`;`notify` 基类站内信方法不受影响 |
|
||||
|
||||
> BUG-008/009 由主题与轮播用例发现;BUG-010/011/012 由本轮「发布侧三件事」的需求评审 + 新增 PUB 用例发现(其中 BUG-012 属资损类,优先级最高)。
|
||||
> BUG-015 由 v1.1.0 微信支付端到端验证发现(`/pay/prepay`、`/pay/notify` 全 500),修复后接口恢复正常。
|
||||
|
||||
## 六、测试结论与建议
|
||||
|
||||
@@ -370,9 +420,9 @@ node tests/run.mjs # 全链路接口 + 图标/LOGO 测试
|
||||
|
||||
| 序号 | 待补测项 | 原因 | 建议 |
|
||||
| --- | --- | --- | --- |
|
||||
| 1 | 微信真机支付链路 | 支付依赖真实商户号与真机环境,自动化无法覆盖 | 使用 `fenleixinxi.gzyakj.com.cn` 生产商户号做真机冒烟 |
|
||||
| 2 | 图片/视频上传 | 当前为端能力占位,未接上传接口 | 补充上传接口后增加文件大小/格式/并发用例 |
|
||||
| 3 | LBS 定位与距离排序 | 需真实定位权限 | 真机测试多坐标下的距离计算与排序 |
|
||||
| 1 | 微信真机支付链路 | v1.1.0 支付能力已改由 **epay 插件**承载(插件下单 + 插件验签,本地业务编排在 `api/Pay`),但**插件商户参数尚未配置**(`wechat.miniapp_id`/`wechat.mch_id`/`wechat.key` 为空),真机无法实测 | 在后台「插件管理 → 微信支付宝整合插件 → 配置」填好商户参数后,用真机对 `/pay/prepay` → `uni.requestPayment` → `/pay/notify` 做冒烟 |
|
||||
| 2 | 图片/视频上传 | v1.1.0 已接真实上传接口 `POST /post/upload`(Mock 契约层已覆盖,图片/视频/缺文件) | 真机补充大文件(图片 >10MB / 视频 >50MB)与格式、并发用例 |
|
||||
| 3 | LBS 定位与距离排序 | v1.1.0 已实现(`fc_post.lat/lng` + `sort=nearby` + `distance`),Mock 层覆盖排序与无坐标兜底 | 真机在多坐标下校验定位授权、距离与排序 |
|
||||
| 4 | 弱网与并发 | 需压测工具 | 建议对 `/home/feed` 与 `/admin/dashboard/overview` 做压测 |
|
||||
| 5 | 安全测试 | 超出本轮范围 | 增加越权访问(普通账号调用 `/admin/**`)、Token 篡改、SQL 注入用例 |
|
||||
| 6 | 前端 UI 兼容性 | 需多机型 | 覆盖 iOS/Android 主流机型与微信基础库版本 |
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
"name" : "fenleixinxi",
|
||||
"appid" : "__UNI__4F5F344",
|
||||
"description" : "",
|
||||
"versionName" : "1.0.0",
|
||||
"versionCode" : "100",
|
||||
"versionName" : "1.1.0",
|
||||
"versionCode" : "110",
|
||||
"transformPx" : false,
|
||||
/* 5+App特有相关 */
|
||||
"app-plus" : {
|
||||
@@ -65,7 +65,10 @@
|
||||
"scope.userLocation" : {
|
||||
"desc" : "位置定位,附近服务匹配需要"
|
||||
}
|
||||
}
|
||||
},
|
||||
/* 隐私接口白名单:getLocation/chooseLocation 仅声明 permission 不够,
|
||||
缺少此项在真机上会直接失败(发布定位、首页「附近」全部不可用) */
|
||||
"requiredPrivateInfos" : [ "getLocation", "chooseLocation" ]
|
||||
},
|
||||
"mp-alipay" : {
|
||||
"usingComponents" : true
|
||||
|
||||
@@ -88,6 +88,22 @@
|
||||
"navigationBarTextStyle": "black"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/member/recharge",
|
||||
"style": {
|
||||
"navigationBarTitleText": "余额充值",
|
||||
"navigationBarBackgroundColor": "#04874a",
|
||||
"navigationBarTextStyle": "white"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/favorite/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "我的收藏",
|
||||
"navigationBarBackgroundColor": "#04874a",
|
||||
"navigationBarTextStyle": "white"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/distribution/index",
|
||||
"style": {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -158,8 +158,9 @@ describe('用户端 · 信息发布与详情', () => {
|
||||
|
||||
it('付费查看:支持微信 / 余额,非法方式被拦截', async () => {
|
||||
const wx = await postApi.payView(101, { payType: 'wxpay' })
|
||||
expect(wx.unlocked).toBe(true)
|
||||
expect(wx.contact.phone).toBeDefined()
|
||||
// 与后端 Post::payView 对齐:微信支付只返回待支付订单(不含 contact/unlocked),解锁由支付回调写入
|
||||
expect(wx.order.orderNo).toBeDefined()
|
||||
expect(wx.unlocked).toBeFalsy()
|
||||
const bal = await postApi.payView(101, { payType: 'balance' })
|
||||
expect(bal.unlocked).toBe(true)
|
||||
await expectReject(() => postApi.payView(101, { payType: 'alipay' }), '支付方式不支持')
|
||||
|
||||
@@ -20,11 +20,18 @@ function resetPublish() {
|
||||
datasets.publishRule.yearPrice = 168
|
||||
datasets.publishRule.yearQuota = 500
|
||||
datasets.publishRule.quotaLeft = 30
|
||||
datasets.publishRule.freePerDay = 2
|
||||
datasets.publishRule.freeUsedToday = 0
|
||||
setFreeQuota(2)
|
||||
datasets.publishRule.isMember = true
|
||||
}
|
||||
|
||||
/** 设置免费发布条数(字段名与后端 Post::publishConfig 对齐:freeQuota/freeQuotaUsed/freeQuotaLeft) */
|
||||
function setFreeQuota(total, used = 0) {
|
||||
datasets.publishRule.freeQuota = total
|
||||
datasets.publishRule.freeQuotaUsed = used
|
||||
datasets.publishRule.freeQuotaLeft = Math.max(0, total - used)
|
||||
datasets.publishRule.freeUnlimited = false
|
||||
}
|
||||
|
||||
describe('发布配置 · 后台开关与价格下发', () => {
|
||||
it('返回发布模式、三档价格与剩余额度', async () => {
|
||||
resetPublish()
|
||||
@@ -66,20 +73,19 @@ describe('发布计费 · 服务端定价与套餐额度', () => {
|
||||
it('额度与每日免费次数都用尽时,免费发布被拦截', async () => {
|
||||
resetPublish()
|
||||
datasets.publishRule.quotaLeft = 0
|
||||
datasets.publishRule.freePerDay = 0 // 关闭每日免费额度,隔离出「必须付费」的场景
|
||||
setFreeQuota(0) // 关闭免费额度,隔离出「必须付费」的场景
|
||||
await expectReject(() => postApi.create({ title: '无额度', content: '内容', plan: 'free' }), '请选择发布方式')
|
||||
})
|
||||
|
||||
it('付费模式下仍保留每日免费额度(避免硬付费墙)', async () => {
|
||||
resetPublish()
|
||||
datasets.publishRule.quotaLeft = 0
|
||||
datasets.publishRule.freePerDay = 2
|
||||
datasets.publishRule.freeUsedToday = 0
|
||||
setFreeQuota(2)
|
||||
const first = await postApi.create({ title: '今日免费第 1 条', content: '内容', plan: 'free' })
|
||||
expect(first.plan).toBe('free')
|
||||
expect(first.order).toBeFalsy()
|
||||
const cfg = await postApi.publishConfig()
|
||||
expect(cfg.freeLeftToday).toBe(1)
|
||||
expect(cfg.freeQuotaLeft).toBe(1)
|
||||
const second = await postApi.create({ title: '今日免费第 2 条', content: '内容', plan: 'free' })
|
||||
expect(second.plan).toBe('free')
|
||||
// 第 3 条超出每日额度 → 必须付费
|
||||
@@ -89,7 +95,7 @@ describe('发布计费 · 服务端定价与套餐额度', () => {
|
||||
it('单条付费:金额取后台配置,忽略客户端传入的 amount', async () => {
|
||||
resetPublish()
|
||||
datasets.publishRule.quotaLeft = 0
|
||||
datasets.publishRule.freePerDay = 0
|
||||
setFreeQuota(0)
|
||||
const res = await postApi.create({
|
||||
title: '单条付费发布',
|
||||
content: '内容',
|
||||
@@ -104,14 +110,14 @@ describe('发布计费 · 服务端定价与套餐额度', () => {
|
||||
it('单条付费缺少支付方式时报错', async () => {
|
||||
resetPublish()
|
||||
datasets.publishRule.quotaLeft = 0
|
||||
datasets.publishRule.freePerDay = 0
|
||||
setFreeQuota(0)
|
||||
await expectReject(() => postApi.create({ title: 'x', content: 'y', plan: 'single' }), '支付方式不支持')
|
||||
})
|
||||
|
||||
it('月卡/年卡走会员开通接口,开通后获得对应发布条数', async () => {
|
||||
resetPublish()
|
||||
datasets.publishRule.quotaLeft = 0
|
||||
datasets.publishRule.freePerDay = 0
|
||||
setFreeQuota(0)
|
||||
const opened = await memberApi.open({ planId: 'M1', payType: 'balance' })
|
||||
expect(opened.postQuota).toBe(30)
|
||||
expect(opened.quotaLeft).toBe(30)
|
||||
|
||||
@@ -14,5 +14,6 @@ await import('./api.user.contract.test.mjs')
|
||||
await import('./api.admin.contract.test.mjs')
|
||||
await import('./publish.test.mjs')
|
||||
await import('./e2e.flow.test.mjs')
|
||||
await import('./v110.test.mjs')
|
||||
|
||||
await run()
|
||||
|
||||
325
uniapp/tests/v110.test.mjs
普通文件
325
uniapp/tests/v110.test.mjs
普通文件
@@ -0,0 +1,325 @@
|
||||
/**
|
||||
* v1.1.0 新增能力用例(契约 §2.1 / §2.5 小程序端)
|
||||
*
|
||||
* 覆盖:
|
||||
* ① 媒体真上传 POST /post/upload(图片 / 视频 / 缺文件)
|
||||
* ② 举报 POST /report(提交 + 后台可见 + 参数校验)
|
||||
* ③ 收藏 / 关注 POST /favorite/toggle、/follow/toggle、/favorite/status、GET /favorite/list
|
||||
* ④ 余额充值 POST /order/recharge(余额即时到账 / 微信 pending / 金额与方式校验)
|
||||
* ⑤ 微信支付 POST /pay/prepay + common/utils/pay.js 分支
|
||||
* ⑥ 优惠券 GET /coupon/list、POST /coupon/receive(停发/重复/不存在校验)
|
||||
* ⑦ LBS:feed 带 lat/lng 实时算距离(km 一位小数)+ sort=nearby 升序、无坐标排最后
|
||||
* ⑧ 会员发布折扣:discountRate 计价 + parseDiscountRate
|
||||
* ⑨ 工具:formatKm / 我的资产 couponCount / 版本与页面注册
|
||||
*/
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import url from 'node:url'
|
||||
import { describe, it, expect, expectReject } from './harness.mjs'
|
||||
import { homeApi, postApi, memberApi, adminApi, favoriteApi, reportApi, orderApi, payApi, couponApi } from '../common/api/index.js'
|
||||
import { REPORT_REASONS } from '../common/constants/report.js'
|
||||
import { datasets } from '../common/mock/data.js'
|
||||
import { parseDiscountRate } from '../common/mock/index.js'
|
||||
import { pay } from '../common/utils/pay.js'
|
||||
import { formatKm } from '../common/utils/format.js'
|
||||
import config from '../common/config/index.js'
|
||||
|
||||
const ROOT = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '..')
|
||||
|
||||
/** 复位计费配置,避免与其它用例互相影响 */
|
||||
function resetPublish() {
|
||||
datasets.publishRule.mode = 'paid'
|
||||
datasets.publishRule.singlePrice = 5
|
||||
datasets.publishRule.discountRate = 1
|
||||
datasets.publishRule.discountText = ''
|
||||
datasets.publishRule.quotaLeft = 30
|
||||
setFreeQuota(2)
|
||||
datasets.publishRule.isMember = true
|
||||
}
|
||||
|
||||
/** 设置免费发布条数(字段名与后端 Post::publishConfig 对齐:freeQuota/freeQuotaUsed/freeQuotaLeft) */
|
||||
function setFreeQuota(total, used = 0) {
|
||||
datasets.publishRule.freeQuota = total
|
||||
datasets.publishRule.freeQuotaUsed = used
|
||||
datasets.publishRule.freeQuotaLeft = Math.max(0, total - used)
|
||||
datasets.publishRule.freeUnlimited = false
|
||||
}
|
||||
|
||||
describe('v1.1.0 · 版本与页面注册', () => {
|
||||
it('manifest 版本号已升级到 1.1.0', () => {
|
||||
const raw = fs.readFileSync(path.join(ROOT, 'manifest.json'), 'utf8')
|
||||
const m = raw.match(/"versionName"\s*:\s*"([^"]+)"/)
|
||||
expect(m && m[1]).toBe('1.1.0')
|
||||
})
|
||||
|
||||
it('新增页面已注册进 pages.json(收藏 / 余额充值)', () => {
|
||||
const raw = fs.readFileSync(path.join(ROOT, 'pages.json'), 'utf8')
|
||||
const json = JSON.parse(raw.replace(/\/\/.*$/gm, ''))
|
||||
const paths = json.pages.map((p) => p.path)
|
||||
expect(paths).toContain('pages/favorite/index')
|
||||
expect(paths).toContain('pages/member/recharge')
|
||||
// 声明的页面文件必须真实存在
|
||||
for (const p of ['pages/favorite/index', 'pages/member/recharge']) {
|
||||
expect(fs.existsSync(path.join(ROOT, p + '.vue'))).toBe(true)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('v1.1.0 · 媒体真上传', () => {
|
||||
it('上传图片 / 视频返回可持久化地址与类型', async () => {
|
||||
const img = await postApi.uploadMedia('/tmp/photo.jpg', 'image')
|
||||
expect(img.url).toContain('/uploads/')
|
||||
expect(img.type).toBe('image')
|
||||
expect(img.size).toBeGreaterThan(0)
|
||||
const video = await postApi.uploadMedia('/tmp/clip.mp4', 'video')
|
||||
expect(video.type).toBe('video')
|
||||
expect(video.url).toContain('.mp4')
|
||||
})
|
||||
|
||||
it('未选择文件时上传被拦截', async () => {
|
||||
await expectReject(() => postApi.uploadMedia('', 'image'), '未接收到上传文件')
|
||||
})
|
||||
})
|
||||
|
||||
describe('v1.1.0 · 举报', () => {
|
||||
it('提交举报成功且后台可查见', async () => {
|
||||
const res = await reportApi.create({ targetType: 'post', targetId: 101, reason: REPORT_REASONS[0] })
|
||||
expect(res.reportId).toBeDefined()
|
||||
const reports = await adminApi.reports()
|
||||
expect(reports.some((r) => r.targetType === 'post' && r.targetId === 101)).toBe(true)
|
||||
expect(REPORT_REASONS.length).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('举报参数校验:类型 / 对象 / 原因', async () => {
|
||||
await expectReject(() => reportApi.create({ targetId: 1, reason: 'x' }), '缺少举报对象类型')
|
||||
await expectReject(() => reportApi.create({ targetType: 'user', targetId: 1, reason: 'x' }), '举报对象类型不合法')
|
||||
await expectReject(() => reportApi.create({ targetType: 'post', reason: 'x' }), '缺少举报对象')
|
||||
await expectReject(() => reportApi.create({ targetType: 'post', targetId: 1 }), '请选择举报原因')
|
||||
})
|
||||
})
|
||||
|
||||
describe('v1.1.0 · 收藏与关注', () => {
|
||||
it('批量回显收藏 / 关注状态', async () => {
|
||||
const res = await favoriteApi.status({ postIds: [101, 102], userIds: [2001, 2002] })
|
||||
expect(res.faved[101]).toBe(true)
|
||||
expect(res.faved[102]).toBe(false)
|
||||
expect(res.followed[2001]).toBe(true)
|
||||
expect(res.followed[2002]).toBe(false)
|
||||
})
|
||||
|
||||
it('收藏切换:加入后 count +1,再次切换取消', async () => {
|
||||
const before = await favoriteApi.status({ postIds: [102] })
|
||||
expect(before.faved[102]).toBe(false)
|
||||
const on = await favoriteApi.toggle({ postId: 102 })
|
||||
expect(on.faved).toBe(true)
|
||||
expect(on.count).toBeGreaterThan(0)
|
||||
const off = await favoriteApi.toggle({ postId: 102 })
|
||||
expect(off.faved).toBe(false)
|
||||
})
|
||||
|
||||
it('关注切换:关注 / 取消关注发布者', async () => {
|
||||
const on = await favoriteApi.follow({ userId: 2002 })
|
||||
expect(on.followed).toBe(true)
|
||||
const off = await favoriteApi.follow({ userId: 2002 })
|
||||
expect(off.followed).toBe(false)
|
||||
})
|
||||
|
||||
it('我的收藏列表项为 Post 结构 + 参数校验', async () => {
|
||||
const list = await favoriteApi.list({ page: 1, size: 10 })
|
||||
expect(list.list.length).toBeGreaterThan(0)
|
||||
expect(list.list[0].title).toBeTruthy()
|
||||
expect(list.list[0].categoryId).toBeDefined()
|
||||
await expectReject(() => favoriteApi.toggle({}), '缺少信息 ID')
|
||||
await expectReject(() => favoriteApi.follow({}), '缺少用户 ID')
|
||||
})
|
||||
})
|
||||
|
||||
describe('v1.1.0 · 余额充值', () => {
|
||||
it('余额支付充值被拒绝(防资损:用余额给余额加钱)', async () => {
|
||||
const before = (await memberApi.assets()).balance
|
||||
await expectReject(() => orderApi.recharge({ amount: 20, payType: 'balance' }), '余额充值仅支持微信支付')
|
||||
const after = (await memberApi.assets()).balance
|
||||
expect(after).toBe(before)
|
||||
})
|
||||
|
||||
it('微信支付:订单 pending,余额不立即变化(待回调入账)', async () => {
|
||||
const before = (await memberApi.assets()).balance
|
||||
const res = await orderApi.recharge({ amount: 30, payType: 'wxpay' })
|
||||
expect(res.status).toBe('pending')
|
||||
const after = (await memberApi.assets()).balance
|
||||
expect(after).toBe(before)
|
||||
})
|
||||
|
||||
it('充值校验:金额合法 + 上限 + 支付方式', async () => {
|
||||
await expectReject(() => orderApi.recharge({ amount: 0, payType: 'wxpay' }), '充值金额不合法')
|
||||
await expectReject(() => orderApi.recharge({ amount: 200000, payType: 'wxpay' }), '充值金额不合法')
|
||||
await expectReject(() => orderApi.recharge({ amount: 10, payType: 'card' }), '支付方式不支持')
|
||||
})
|
||||
})
|
||||
|
||||
describe('v1.1.0 · 微信支付 prepay 与统一支付封装', () => {
|
||||
it('prepay 返回 JSAPI 调起参数', async () => {
|
||||
const res = await payApi.prepay({ orderNo: 'PO_TEST_1' })
|
||||
expect(res.payType).toBe('wxpay')
|
||||
expect(res.payParams.timeStamp).toBeTruthy()
|
||||
expect(res.payParams.nonceStr).toBeTruthy()
|
||||
expect(res.payParams.package).toContain('prepay_id=')
|
||||
expect(res.payParams.signType).toBeDefined()
|
||||
expect(res.payParams.paySign).toBeTruthy()
|
||||
})
|
||||
|
||||
it('缺少订单号 / 商户未配置时给出中文提示', async () => {
|
||||
await expectReject(() => payApi.prepay({}), '缺少订单号')
|
||||
datasets.wxPayConfigured = false
|
||||
await expectReject(() => payApi.prepay({ orderNo: 'PO_X' }), '微信支付未配置')
|
||||
datasets.wxPayConfigured = true
|
||||
})
|
||||
|
||||
it('pay():余额支付直接成功', async () => {
|
||||
const res = await pay({ payType: config.constants.PAY_TYPE.BALANCE, orderNo: 'PO_BAL' })
|
||||
expect(res.success).toBe(true)
|
||||
expect(res.payType).toBe('balance')
|
||||
})
|
||||
|
||||
it('pay():微信支付取 prepay 参数(Node/H5 无 requestPayment 时按成功返回)', async () => {
|
||||
const res = await pay({ payType: config.constants.PAY_TYPE.WXPAY, orderNo: 'PO_WX' })
|
||||
expect(res.success).toBe(true)
|
||||
expect(res.mock).toBe(true)
|
||||
await expectReject(() => pay({ payType: config.constants.PAY_TYPE.WXPAY }), '缺少订单号')
|
||||
})
|
||||
})
|
||||
|
||||
describe('v1.1.0 · 优惠券', () => {
|
||||
it('可领取列表排除停发券并带出已领取标记', async () => {
|
||||
const res = await couponApi.list({ page: 1, size: 20 })
|
||||
expect(res.list.some((c) => c.id === 4)).toBe(false) // enabled:false 不发放
|
||||
const got = res.list.find((c) => c.id === 1)
|
||||
expect(got.received).toBe(true) // 已在 userCoupons 中
|
||||
expect(res.list.every((c) => typeof c.received === 'boolean')).toBe(true)
|
||||
})
|
||||
|
||||
it('领取新券后列表标记已领取、资产张数 +1', async () => {
|
||||
const before = await memberApi.assets()
|
||||
const res = await couponApi.receive(2)
|
||||
expect(res.userCouponId).toBeDefined()
|
||||
const after = await memberApi.assets()
|
||||
expect(after.couponCount).toBe(before.couponCount + 1)
|
||||
const list = await couponApi.list({ page: 1, size: 20 })
|
||||
expect(list.list.find((c) => c.id === 2).received).toBe(true)
|
||||
// 清理:移除本次领取的券,保证重复运行结果一致
|
||||
const idx = datasets.userCoupons.map((u) => u.couponId).indexOf(2)
|
||||
if (idx > -1) datasets.userCoupons.splice(idx, 1)
|
||||
})
|
||||
|
||||
it('重复领取 / 停发 / 不存在分别被拦截', async () => {
|
||||
await expectReject(() => couponApi.receive(1), '您已领取过该优惠券')
|
||||
await expectReject(() => couponApi.receive(4), '该优惠券已停止发放')
|
||||
await expectReject(() => couponApi.receive(999), '优惠券不存在')
|
||||
})
|
||||
})
|
||||
|
||||
describe('v1.1.0 · LBS 距离与附近排序', () => {
|
||||
it('带 lat/lng 时按坐标实时计算距离(km,一位小数)', async () => {
|
||||
const res = await homeApi.feed({ lat: 26.6157, lng: 106.6979, page: 1, size: 20 })
|
||||
res.list.forEach((p) => {
|
||||
expect(typeof p.distance).toBe('number')
|
||||
expect(p.distance).toBeGreaterThan(-1)
|
||||
// 一位小数
|
||||
expect(Math.round(p.distance * 10) / 10).toBe(p.distance)
|
||||
})
|
||||
// 查询点与部分信息重合时为 0,其余信息必须有正距离(说明是实时计算而非取自身 km 值)
|
||||
expect(res.list.filter((p) => p.distance > 0).length).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('sort=nearby:非置顶项按距离升序,无坐标信息排最后', async () => {
|
||||
const tmp = {
|
||||
id: 999999,
|
||||
categoryId: 1,
|
||||
categoryName: '招聘求职',
|
||||
title: '无坐标信息',
|
||||
content: '坐标缺失',
|
||||
cover: '',
|
||||
price: 0,
|
||||
priceUnit: '面议',
|
||||
area: '云岩区',
|
||||
address: '',
|
||||
views: 1,
|
||||
likes: 0,
|
||||
isPaid: false,
|
||||
auditStatus: 1,
|
||||
createdAt: new Date().toISOString(),
|
||||
tags: [],
|
||||
publisher: { id: 900900, name: '测试', avatar: '', isMerchant: false, verified: false },
|
||||
commentCount: 0,
|
||||
lat: null,
|
||||
lng: null,
|
||||
distance: null,
|
||||
}
|
||||
datasets.posts.push(tmp)
|
||||
try {
|
||||
const res = await homeApi.feed({ sort: 'nearby', lat: 26.6157, lng: 106.6979, page: 1, size: 50 })
|
||||
const last = res.list[res.list.length - 1]
|
||||
expect(last.id).toBe(999999)
|
||||
expect(last.distance).toBe(null)
|
||||
const nearby = res.list.filter((p) => !p.isTop && p.distance != null)
|
||||
for (let i = 1; i < nearby.length; i++) {
|
||||
expect(nearby[i - 1].distance).toBeLessThanOrEqual(nearby[i].distance)
|
||||
}
|
||||
} finally {
|
||||
datasets.posts.pop()
|
||||
}
|
||||
})
|
||||
|
||||
it('不带坐标时距离一律为 null(与后端 Home::feed 一致,不回退静态值)', async () => {
|
||||
const res = await homeApi.feed({ page: 1, size: 20 })
|
||||
const p103 = res.list.find((p) => p.id === 103)
|
||||
expect(p103.distance).toBe(null)
|
||||
res.list.forEach((p) => expect(p.distance).toBe(null))
|
||||
})
|
||||
})
|
||||
|
||||
describe('v1.1.0 · 会员发布折扣计价', () => {
|
||||
it('parseDiscountRate:折扣文案解析为费率', () => {
|
||||
expect(parseDiscountRate('8 折')).toBe(0.8)
|
||||
expect(parseDiscountRate('7.5 折')).toBe(0.75)
|
||||
expect(parseDiscountRate('')).toBe(1)
|
||||
expect(parseDiscountRate(null)).toBe(1)
|
||||
expect(parseDiscountRate('乱写的文案')).toBe(1)
|
||||
})
|
||||
|
||||
it('单条付费按服务端折扣率计价(客户端金额被忽略)', async () => {
|
||||
resetPublish()
|
||||
datasets.publishRule.quotaLeft = 0
|
||||
setFreeQuota(0)
|
||||
datasets.publishRule.discountRate = 0.8
|
||||
const res = await postApi.create({ title: '折扣单条发布', content: '内容', plan: 'single', payType: 'balance', amount: 999 })
|
||||
expect(res.discountRate).toBe(0.8)
|
||||
expect(res.order.amount).toBe(4)
|
||||
resetPublish()
|
||||
})
|
||||
|
||||
it('默认折扣率为 1 时金额等于后台单价', async () => {
|
||||
resetPublish()
|
||||
datasets.publishRule.quotaLeft = 0
|
||||
setFreeQuota(0)
|
||||
const res = await postApi.create({ title: '原价单条发布', content: '内容', plan: 'single', payType: 'balance' })
|
||||
expect(res.order.amount).toBe(5)
|
||||
})
|
||||
})
|
||||
|
||||
describe('v1.1.0 · 资产与格式化工具', () => {
|
||||
it('我的资产带 couponCount 且与已领券一致', async () => {
|
||||
const a = await memberApi.assets()
|
||||
expect(a.couponCount).toBeDefined()
|
||||
expect(a.coupons).toBeArray()
|
||||
expect(a.coupons.length).toBe(a.couponCount)
|
||||
})
|
||||
|
||||
it('formatKm:km 一位小数,空值不展示', () => {
|
||||
expect(formatKm(1.2)).toBe('1.2km')
|
||||
expect(formatKm(0)).toBe('0.0km')
|
||||
expect(formatKm(null)).toBe('')
|
||||
expect(formatKm(undefined)).toBe('')
|
||||
expect(formatKm('')).toBe('')
|
||||
})
|
||||
})
|
||||
@@ -1,17 +1,89 @@
|
||||
/**
|
||||
* SCSS 语法校验
|
||||
* 用 HBuilderX 内置 dart-sass 编译每个 .vue 的 <style lang="scss">,
|
||||
* 用 dart-sass 编译每个 .vue 的 <style lang="scss">,
|
||||
* 并注入 uni.scss 变量(模拟 uni-app 的全局注入行为)。
|
||||
* 运行: node tools/check-scss.cjs
|
||||
*
|
||||
* 工具链定位(跨平台):优先 HBuilderX 内置 dart-sass,其次本地 node_modules/sass,
|
||||
* 也可通过环境变量 HBUILDERX_HOME / SASS_PATH(+ 可选 SASS_NODE)显式指定。
|
||||
*/
|
||||
const fs = require('fs')
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
const { execFileSync } = require('child_process')
|
||||
|
||||
const HX = '/Applications/HBuilderX.app/Contents/HBuilderX'
|
||||
const NODE = path.join(HX, 'plugins/node/node')
|
||||
const SASS = path.join(HX, 'plugins/compile-dart-sass/node_modules/sass/sass.js')
|
||||
const ROOT = path.resolve(__dirname, '..')
|
||||
const isWin = process.platform === 'win32'
|
||||
const NODE_BIN = isWin ? 'node.exe' : 'node'
|
||||
|
||||
function exists(p) {
|
||||
try {
|
||||
fs.accessSync(p)
|
||||
return true
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/** HBuilderX 可能的安装根目录(按平台给出常见路径,可被 HBUILDERX_HOME 覆盖) */
|
||||
function hxRoots() {
|
||||
const list = []
|
||||
const envRoot = process.env.HBUILDERX_HOME || process.env.HX_HOME
|
||||
if (envRoot) list.push(envRoot)
|
||||
const home = os.homedir()
|
||||
if (process.platform === 'darwin') {
|
||||
list.push('/Applications/HBuilderX.app/Contents/HBuilderX')
|
||||
} else if (isWin) {
|
||||
const drives = ['C:', 'D:', 'E:', 'F:']
|
||||
for (const d of drives) list.push(`${d}\\HBuilderX`, `${d}\\Softwares\\HBuilderX`, `${d}\\Program Files\\HBuilderX`)
|
||||
list.push(
|
||||
path.join(home, 'HBuilderX'),
|
||||
path.join(home, 'AppData', 'Local', 'HBuilderX'),
|
||||
path.join(home, 'AppData', 'Local', 'Programs', 'HBuilderX'),
|
||||
path.join(home, 'Desktop', 'HBuilderX')
|
||||
)
|
||||
} else {
|
||||
list.push(path.join(home, 'HBuilderX'), '/opt/HBuilderX', '/usr/local/HBuilderX')
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
/** 定位 node 可执行文件与 dart-sass CLI 入口;找不到时返回 null */
|
||||
function locateSass() {
|
||||
if (process.env.SASS_PATH && exists(process.env.SASS_PATH)) {
|
||||
const node = process.env.SASS_NODE && exists(process.env.SASS_NODE) ? process.env.SASS_NODE : process.execPath
|
||||
return { node, sass: process.env.SASS_PATH }
|
||||
}
|
||||
for (const root of hxRoots()) {
|
||||
// HBuilderX 的 dart-sass 目录(新旧版本入口名都探测)
|
||||
const sassCandidates = [
|
||||
path.join(root, 'plugins', 'compile-dart-sass', 'node_modules', 'sass', 'sass.js'),
|
||||
path.join(root, 'plugins', 'compile-dart-sass', 'node_modules', 'sass', 'bin', 'sass.js'),
|
||||
]
|
||||
const sass = sassCandidates.find(exists)
|
||||
if (!sass) continue
|
||||
const node = [path.join(root, 'plugins', 'node', NODE_BIN), path.join(root, 'plugins', 'node', 'node')].find(exists)
|
||||
// 有 dart-sass 就能跑:缺内置 node 时用当前 node
|
||||
return { node: node || process.execPath, sass }
|
||||
}
|
||||
// 兜底:项目/全局装了 dart-sass
|
||||
const local = [
|
||||
path.join(ROOT, 'node_modules', 'sass', 'sass.js'),
|
||||
path.join(ROOT, 'node_modules', 'sass', 'bin', 'sass.js'),
|
||||
path.join(ROOT, 'node_modules', 'sass', 'sass.default.js'),
|
||||
].find(exists)
|
||||
if (local) return { node: process.execPath, sass: local }
|
||||
return null
|
||||
}
|
||||
|
||||
const TOOLCHAIN = locateSass()
|
||||
if (!TOOLCHAIN) {
|
||||
console.error('\n未找到 dart-sass,无法编译 SCSS。')
|
||||
console.error('请安装 HBuilderX,或设置 HBUILDERX_HOME / SASS_PATH 环境变量后重试。')
|
||||
process.exit(1)
|
||||
}
|
||||
console.log(`\nSCSS 校验工具链:${TOOLCHAIN.node}\n sass: ${TOOLCHAIN.sass}\n`)
|
||||
|
||||
const vars = fs.readFileSync(path.join(ROOT, 'uni.scss'), 'utf8')
|
||||
|
||||
const SKIP = ['node_modules', 'unpackage', '.git', 'static', 'tools', 'tests', 'docs']
|
||||
@@ -34,7 +106,7 @@ for (const f of walk(ROOT)) {
|
||||
if (!m) continue
|
||||
const rel = path.relative(ROOT, f)
|
||||
try {
|
||||
execFileSync(NODE, [SASS, '--stdin', '--no-source-map', '--quiet'], {
|
||||
execFileSync(TOOLCHAIN.node, [TOOLCHAIN.sass, '--stdin', '--no-source-map', '--quiet'], {
|
||||
input: vars + '\n' + m[1],
|
||||
stdio: ['pipe', 'ignore', 'pipe'],
|
||||
})
|
||||
|
||||
在新工单中引用
屏蔽一个用户