From 3f45e8fdfa31d7b764d60a7c0cb5dd11944ed418 Mon Sep 17 00:00:00 2001
From: 刘帅 <rr.iii@qq.com>
Date: 星期一, 21 九月 2026 23:38:59 +0800
Subject: [PATCH] bug:统计数据修正
---
cloud-server-activity/src/main/java/com/dsh/activity/controller/HuiminController.java | 40 ++++++++++++++++++++++++++++++++--------
1 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/cloud-server-activity/src/main/java/com/dsh/activity/controller/HuiminController.java b/cloud-server-activity/src/main/java/com/dsh/activity/controller/HuiminController.java
index b525610..922aa87 100644
--- a/cloud-server-activity/src/main/java/com/dsh/activity/controller/HuiminController.java
+++ b/cloud-server-activity/src/main/java/com/dsh/activity/controller/HuiminController.java
@@ -106,7 +106,7 @@
@ApiImplicitParam(value = "用户优惠券领取记录id;不使用时不传", name = "couponId", dataType = "long", required = false),
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
})
- public ResultUtil<THuiminCard> payHuiminCard(Integer id, Integer payType, String studentIds, Long couponId) {
+ public ResultUtil<?> payHuiminCard(Integer id, Integer payType, String studentIds, Long couponId) {
try {
Integer uid = tokenUtil.getUserIdFormRedis();
if (null == uid) {
@@ -207,8 +207,17 @@
System.err.println("支付数据" + tPayHuimin);
payHuiminService.save(tPayHuimin);
if (userCoupon != null) {
- userCoupon.setStatus(2);
- userCouponService.updateById(userCoupon);
+ // t_user_coupon 以 userId 分片;updateById 会把 userId 放入 SET,
+ // ShardingSphere 会拒绝更新分片键。只更新状态,并在 WHERE 中带上 userId。
+ boolean couponUpdated = userCouponService.lambdaUpdate()
+ .set(UserCoupon::getStatus, 2)
+ .eq(UserCoupon::getId, userCoupon.getId())
+ .eq(UserCoupon::getUserId, uid)
+ .eq(UserCoupon::getStatus, 1)
+ .update();
+ if (!couponUpdated) {
+ return ResultUtil.error("优惠券已被使用");
+ }
}
BigDecimal bigDecimal = new BigDecimal(studentIds.split(",").length);
if (tPayHuimin.getSalesMoney().compareTo(BigDecimal.ZERO)==0){
@@ -216,19 +225,21 @@
tPayHuimin.setStatus(2);
tPayHuimin.setPaymentTime(new Date());
payHuiminService.updateById(tPayHuimin);
- return ResultUtil.success();
+ JSONObject data = new JSONObject();
+ data.put("paySuccess", true);
+ return ResultUtil.success(data);
}
switch (payType) {
case 1:
// todo 惠民卡收入属于平台商户 定死
- return payMoneyUtil.weixinpay("购买玩湃惠民卡", "", tPayHuimin.getCode(), tPayHuimin.getSalesMoney().toString(),
- "/base/huimin/callBack/weixinPayHuiminCallback", "APP", "");
+ return appendPaySuccess(payMoneyUtil.weixinpay("购买玩湃惠民卡", "", tPayHuimin.getCode(), tPayHuimin.getSalesMoney().toString(),
+ "/base/huimin/callBack/weixinPayHuiminCallback", "APP", ""));
// return payMoneyUtil.weixinpayV3("1720719391","购买玩湃惠民卡",tPayHuimin.getCode(),
// "/base/huimin/callBack/weixinPayHuiminCallback1",tPayHuimin.getSalesMoney().toString());
case 2:
String string = tPayHuimin.getSalesMoney().toString();
- return payMoneyUtil.alipay(smid, "购买玩湃惠民卡", "购买玩湃惠民卡", "", tPayHuimin.getCode(), string,
- "/base/huimin/callBack/aliPayHuiminCallback");
+ return appendPaySuccess(payMoneyUtil.alipay(smid, "购买玩湃惠民卡", "购买玩湃惠民卡", "", tPayHuimin.getCode(), string,
+ "/base/huimin/callBack/aliPayHuiminCallback"));
}
} catch (Exception e) {
@@ -238,6 +249,19 @@
return ResultUtil.success();
}
+ /**
+ * 支付参数生成成功不代表实际支付成功,前端仍需拉起第三方支付。
+ */
+ private ResultUtil<?> appendPaySuccess(ResultUtil<?> paymentResult) {
+ JSONObject data = paymentResult.getData() == null ? new JSONObject()
+ : JSON.parseObject(JSON.toJSONString(paymentResult.getData()));
+ if (data == null) {
+ data = new JSONObject();
+ }
+ data.put("paySuccess", false);
+ return ResultUtil.getResult(paymentResult.getCode(), paymentResult.getMsg(), data);
+ }
+
/**
* 查看玩湃惠民卡详情
--
Gitblit v1.7.1