feat: 新增地址选择插件及订阅消息等多项功能优化
- 新增地址选择插件,支持地图位置选择并返回地址和经纬度 - 新增微信订阅消息发送功能,支持审核结果、提现通知等场景 - 新增订单支付状态查询、提现收款人姓名保存等接口 - 新增服务区域管理,支持按省市区划分并同步到信息发布 - 新增资金流水和营收报表导出功能 - 新增可用优惠券查询、订单退款拆分处理等功能 - 优化后台角标显示、首页数据统计、UI配置下发等 - 修复订单支付并发问题、地区管理逻辑等
这个提交包含在:
@@ -103,54 +103,97 @@ class Member extends V1
|
||||
$this->fail('套餐不存在');
|
||||
}
|
||||
|
||||
$amount = round((float)$plan['price'], 2);
|
||||
$originAmount = round((float)$plan['price'], 2);
|
||||
$userCouponId = (int)$this->input('userCouponId', 0);
|
||||
|
||||
// 优惠券:先试算(事务外只校验,真正锁定在事务内)
|
||||
$couponAmount = 0;
|
||||
$hasCoupon = false;
|
||||
if ($userCouponId > 0) {
|
||||
try {
|
||||
$couponInfo = \app\common\library\CouponService::preview($user['id'], $userCouponId, $originAmount);
|
||||
} catch (\Throwable $e) {
|
||||
$this->fail($e->getMessage());
|
||||
}
|
||||
$couponAmount = $couponInfo['discount'];
|
||||
$hasCoupon = true;
|
||||
}
|
||||
|
||||
$amount = round($originAmount - $couponAmount, 2);
|
||||
$now = time();
|
||||
$isBalance = $payType === 'balance';
|
||||
|
||||
// 余额校验必须在落订单之前:否则余额不足时已插入一条 status=paid 的假订单
|
||||
$balance = (float)$user['money'];
|
||||
if ($isBalance && $balance < $amount) {
|
||||
if ($isBalance && (float)$user['money'] < $amount) {
|
||||
$this->fail('余额不足');
|
||||
}
|
||||
|
||||
$orderNo = $this->orderNo('MO');
|
||||
$orderId = Db::name('fc_order')->insertGetId([
|
||||
'order_no' => $orderNo,
|
||||
'user_id' => $user['id'],
|
||||
'type' => 'member',
|
||||
'title' => (string)$plan['name'],
|
||||
'amount' => $amount,
|
||||
'pay_type' => $payType,
|
||||
'status' => $isBalance ? 'paid' : 'pending',
|
||||
'paytime' => $isBalance ? $now : null,
|
||||
// related_id 存套餐主键:支付回调 /pay/notify 据此复用 grantMembership(),回调可独立完成
|
||||
'related_id' => (int)$plan['id'],
|
||||
'createtime' => $now,
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
$grant = null;
|
||||
|
||||
if ($isBalance) {
|
||||
$balance = round($balance - $amount, 2);
|
||||
Db::name('user')->where('id', $user['id'])->update([
|
||||
'money' => $balance,
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
// 余额支付:立即发放会员(微信支付等待回调发放)
|
||||
$grant = $this->grantMembership(Db::name('fc_order')->where('id', $orderId)->find());
|
||||
} else {
|
||||
$grant = null;
|
||||
try {
|
||||
// 扣款 + 落订单 + 发放会员 同一事务:任一步失败整体回滚
|
||||
Db::transaction(function () use (&$grant, $isBalance, $amount, $originAmount, $couponAmount, $hasCoupon, $userCouponId, $user, $plan, $payType, $orderNo, $now) {
|
||||
// 锁券(与订单同事务,失败则整体回滚)
|
||||
if ($hasCoupon) {
|
||||
\app\common\library\CouponService::lock($user['id'], $userCouponId, $originAmount, $orderNo);
|
||||
}
|
||||
|
||||
if ($isBalance) {
|
||||
// 条件扣款:并发下不会扣成负数
|
||||
$affected = Db::name('user')
|
||||
->where('id', (int)$user['id'])
|
||||
->where('money', '>=', $amount)
|
||||
->setDec('money', $amount);
|
||||
if (!$affected) {
|
||||
throw new \RuntimeException('余额不足');
|
||||
}
|
||||
}
|
||||
|
||||
$orderId = Db::name('fc_order')->insertGetId([
|
||||
'order_no' => $orderNo,
|
||||
'user_id' => $user['id'],
|
||||
'type' => 'member',
|
||||
'title' => (string)$plan['name'],
|
||||
'amount' => $amount,
|
||||
'origin_amount' => $originAmount,
|
||||
'coupon_amount' => $couponAmount,
|
||||
'coupon_id' => $hasCoupon ? $userCouponId : 0,
|
||||
'pay_type' => $payType,
|
||||
'status' => $isBalance ? 'paid' : 'pending',
|
||||
'paytime' => $isBalance ? $now : null,
|
||||
// related_id 存套餐主键:支付回调 /pay/notify 据此复用 grantMembership(),回调可独立完成
|
||||
'related_id' => (int)$plan['id'],
|
||||
'createtime' => $now,
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
|
||||
if ($isBalance) {
|
||||
// 余额支付:立即发放会员(微信支付等待回调发放)
|
||||
$grant = $this->grantMembership(Db::name('fc_order')->where('id', $orderId)->find());
|
||||
// 券核销(微信支付在 OrderFulfill 里核销)
|
||||
\app\common\library\CouponService::markUsed($orderNo);
|
||||
}
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
$this->fail($e->getMessage() ?: '开通失败,请重试');
|
||||
}
|
||||
|
||||
$quota = isset($plan['post_quota']) ? max(0, (int)$plan['post_quota']) : 0;
|
||||
$this->ok([
|
||||
'orderNo' => $orderNo,
|
||||
'status' => $isBalance ? 'paid' : 'pending',
|
||||
'amount' => $amount,
|
||||
'originAmount' => $originAmount,
|
||||
'couponAmount' => $couponAmount,
|
||||
// 微信支付:前端拿到 orderNo 后调 /pay/prepay;余额支付无需再支付(order=null)
|
||||
'order' => $isBalance ? null : [
|
||||
'orderNo' => $orderNo,
|
||||
'amount' => $amount,
|
||||
'payType' => 'wxpay',
|
||||
'status' => 'pending',
|
||||
'orderNo' => $orderNo,
|
||||
'amount' => $amount,
|
||||
'originAmount' => $originAmount,
|
||||
'couponAmount' => $couponAmount,
|
||||
'payType' => 'wxpay',
|
||||
'status' => 'pending',
|
||||
],
|
||||
'expireAt' => $grant ? $this->iso($grant['expireAt']) : null,
|
||||
'postQuota' => $quota,
|
||||
|
||||
在新工单中引用
屏蔽一个用户