Files
shaguabijia-app-server/docs/api/admin/users/admin-user-cash.md
T
guke b23335d5fb @
docs: reorganize api docs into categorized subdirectories and fill missing docs

- Categorize 77 existing api docs into 16 business-domain subdirectories
  (auth/ad/wallet/coupon/compare/savings/signin/tasks/invite/user/
   device/platform/intent/meituan/other) plus admin/ and internal/
- Split admin/ into 7 sub-resource subdirectories (auth/users/wallet/
  withdraws/feedbacks/admins/ad) with 4 single-file docs at root
- Create 21 new docs covering 28 previously undocumented endpoints:
  ad/watch-report, wallet/transfer-auth (3 endpoints), coupon/session+
  stats+completed-today+prompt (7), invite/me+invitees+bind+landing-track,
  user/onboarding (2), platform/flags+ad-config+app-version,
  intent/step+precoupon/step, analytics/events, order/report,
  report/submit+records, feedback/config+records, trace/finalize
- Add mock request/response JSON examples to all new docs
- Create docs/README.md with full category index for LLM navigation
- Update docs/api/README.md: fix all links, add new endpoint rows,
  replace "no doc" markers with actual links
- Fix back-navigation links (./README.md -> ../README.md or
  ../../README.md) in all moved files
@
2026-07-03 14:56:50 +08:00

2.7 KiB
Raw Blame History

POST /admin/api/users/{user_id}/cash — 手动增减/设值现金(带审计)

所属:Admin·用户 组(前缀 /admin/api/users | 鉴权:Bearer admin_token(角色:finance,super_admin 恒通过) | ← 返回 API 索引

主要用于给无现金用户直接发钱、好让其测试提现链路。

入参

  • 路径:user_id(int)
  • application/json:
    字段 类型 必填 说明
    mode string delta(默认)=增减 / set=设为指定值
    amount_cents int delta 模式:现金变动(分,正=发放,负=扣减,不可为 0);set 模式:目标现金值(分,须 ≥ 0)
    reason string 操作原因,1–128 字(必填,入审计与流水备注)

出参

响应 200:OkResponse = { "ok": true }

错误码

  • 400(delta)amount_cents == 0(detail: "amount_cents 不能为 0");或负数扣减后余额会变负(detail: "扣减后现金为负(当前余额 N 分)")
  • 400(set)目标值为负(detail: "目标现金值不能为负");或目标值等于当前余额(detail: "当前现金已为 N 分,无需调整")
  • 401 未带/无效/过期 admin token、管理员被禁用(头带 WWW-Authenticate: Bearer)
  • 403 角色不足(需 financesuper_admin)
  • 404 用户不存在(detail: "用户不存在")
  • 422amount_cents/reasonreason 长度不在 1128、modedelta/set、字段类型不合法 / user_id 非整数

说明

  • 金额单位一律为(*_cents);本接口只动现金余额,不涉及金币。
  • set 模式:读当前余额算出差值 delta = target - 当前余额,再复用同一套写入逻辑(故只写一笔差值流水)。目标值须 ≥ 0;差值为 0(已等于目标)直接拒绝。
  • 扣减保护:实际写入的 delta < 0 时若扣减后现金余额 < 0 直接拒绝(运营误操作保护);set 模式目标值 ≥ 0 天然不会扣成负。
  • 现金变动写流水 cash_transaction:biz_type 实际差值为正记 admin_grant、为负记 admin_deduct(set 模式同理,不新增流水类型),remark = admin:<reason>(截断至 128 字)。
  • 写操作记审计 admin_audit_log:action = user.cash.grant,target_type = user,target_id = user_id,detail = {amount_cents(=实际差值), balance_after_cents, reason};set 模式额外带 {mode:"set", target_cents, before_cents}。并记录操作 IP。
  • 现金变动 + 审计在同一事务原子提交(改钱必留痕)。
  • 关联用户表 user;现金账户 coin_account;现金流水 cash_transaction