feat(pay): 余额支付打通 + 后台一键充值余额
一、修复两处真实缺陷
- Post::create:付费发布只创建 pending 订单,从不扣余额、也不置为已支付
→ 余额不足校验提前到落库前(避免残留 is_paid=1 的无效发布);
余额支付改为「下单即扣款」,订单直接 paid + paytime,并记资金流水;
微信支付保持 pending 由收银台回调置为 paid;补支付方式白名单校验
- Member::open:余额校验在 insertGetId(fc_order) 之后,余额不足时
会插入一条 status=paid 的假订单 → 校验前置,先判余额再落单
二、后台一键充值余额(FastAdmin PC)
- fc/userext 新增 recharge() 动作:批量给选中用户加余额
(金额需 >0 且 <=100000;同步写资金流水 fa_fc_finance_flow
与站内通知 fa_fc_message;后台操作留痕由 Backend 自动记录)
- fc/userext 的 index() 改为 JOIN fa_user,列表直接显示
昵称 / 手机号 / 账户余额(原列表只有扩展字段,看不出余额)
- 列表页新增「余额充值」工具栏按钮 + Layer.prompt 金额输入
三、验证
- 后端 API 178/178、前端 102/102 均无回归
这个提交包含在:
@@ -57,11 +57,18 @@ class Post extends V1
|
||||
$payType = (string)$this->input('payType', '');
|
||||
$amount = 0;
|
||||
if ($paid) {
|
||||
if (!in_array($payType, ['wxpay', 'balance'], true)) {
|
||||
$this->fail('支付方式不支持');
|
||||
}
|
||||
$amount = $this->input('amount', null);
|
||||
if ($amount === null || $amount === '') {
|
||||
$amount = $this->cfg('fee.singlePost', 5);
|
||||
}
|
||||
$amount = round((float)$amount, 2);
|
||||
// 余额校验须在落库之前:否则余额不足时会残留一条 is_paid=1 的无效发布
|
||||
if ($payType === 'balance' && (float)$user['money'] < $amount) {
|
||||
$this->fail('余额不足');
|
||||
}
|
||||
}
|
||||
|
||||
$now = time();
|
||||
@@ -94,6 +101,9 @@ class Post extends V1
|
||||
|
||||
$order = null;
|
||||
if ($paid) {
|
||||
// 余额支付为「即时支付」:下单即扣款、订单直接置为已支付;
|
||||
// 微信支付需要前端调起收银台,保持 pending 由支付回调置为 paid。
|
||||
$paidNow = $payType === 'balance';
|
||||
$orderNo = $this->orderNo('PO');
|
||||
Db::name('fc_order')->insert([
|
||||
'order_no' => $orderNo,
|
||||
@@ -102,12 +112,28 @@ class Post extends V1
|
||||
'title' => $title,
|
||||
'amount' => $amount,
|
||||
'pay_type' => $payType,
|
||||
'status' => 'pending',
|
||||
'status' => $paidNow ? 'paid' : 'pending',
|
||||
'paytime' => $paidNow ? $now : null,
|
||||
'related_id' => $postId,
|
||||
'createtime' => $now,
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
$order = ['orderNo' => $orderNo, 'amount' => $amount, 'payType' => $payType];
|
||||
|
||||
if ($paidNow) {
|
||||
$balance = round((float)$user['money'] - $amount, 2);
|
||||
Db::name('user')->where('id', $user['id'])->update([
|
||||
'money' => $balance,
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
$this->flow('income', '发布付费', $amount, $balance, $postId);
|
||||
}
|
||||
|
||||
$order = [
|
||||
'orderNo' => $orderNo,
|
||||
'amount' => $amount,
|
||||
'payType' => $payType,
|
||||
'status' => $paidNow ? 'paid' : 'pending',
|
||||
];
|
||||
}
|
||||
|
||||
$this->ok([
|
||||
|
||||
在新工单中引用
屏蔽一个用户