diff --git a/src/main/java/com/cultural/heritage/constant/UserConstant.java b/src/main/java/com/cultural/heritage/constant/UserConstant.java index b5e8006..41b4ca1 100644 --- a/src/main/java/com/cultural/heritage/constant/UserConstant.java +++ b/src/main/java/com/cultural/heritage/constant/UserConstant.java @@ -14,7 +14,7 @@ public interface UserConstant { /** * 用户默认头像 */ - String USER_DEFAULT_AVATAR = "https://carbon2.obs.cn-north-4.myhuaweicloud.com/feiyi/default/avator.png"; + String USER_DEFAULT_AVATAR = "https://carbon2.obs.cn-north-4.myhuaweicloud.com:443/feiyi%2Ftest%2F0%2FQbtEasUN-VCG211285566731.png"; /** * 用户登录键 diff --git a/src/main/java/com/cultural/heritage/service/user/UserService.java b/src/main/java/com/cultural/heritage/service/user/UserService.java index 6fbcd0e..701c32c 100644 --- a/src/main/java/com/cultural/heritage/service/user/UserService.java +++ b/src/main/java/com/cultural/heritage/service/user/UserService.java @@ -59,4 +59,10 @@ public interface UserService extends IService { * 用户登录(微信小程序) */ UserVO userLoginByMpOpen(WxMaJscode2SessionResult sessionInfo, HttpServletRequest request); + + + /** + * 用户添加(扣除)积分 + */ + void addOrSubUserPoints(Long userId, boolean isAdd, Integer points); } diff --git a/src/main/java/com/cultural/heritage/service/user/impl/UserServiceImpl.java b/src/main/java/com/cultural/heritage/service/user/impl/UserServiceImpl.java index 8c3658d..ea3e5e8 100644 --- a/src/main/java/com/cultural/heritage/service/user/impl/UserServiceImpl.java +++ b/src/main/java/com/cultural/heritage/service/user/impl/UserServiceImpl.java @@ -190,8 +190,9 @@ public class UserServiceImpl extends ServiceImpl implements Us user.setUserAccount(userAccount); user.setUserPassword(userPassword); user.setMiniOpenId(openid); - user.setUserName("普通用户"); + user.setUserName("非遗雅士"); user.setUserRole("user"); + user.setPoints(10000); user.setUserAvatar(UserConstant.USER_DEFAULT_AVATAR); boolean result = this.save(user); ThrowUtils.throwIf(!result, ErrorCode.SYSTEM_ERROR, "登录失败"); @@ -202,4 +203,20 @@ public class UserServiceImpl extends ServiceImpl implements Us } } + + /** + * 用户添加(扣除)积分 + */ + @Override + public void addOrSubUserPoints(Long userId, boolean isAdd, Integer points) { + User user = this.getById(userId); + if (isAdd) { + user.setPoints(user.getPoints() + points); + } else { + user.setPoints(Math.max(user.getPoints() - points, 0)); + } + boolean update = this.updateById(user); + ThrowUtils.throwIf(!update, ErrorCode.OPERATION_ERROR, "积分更新失败"); + } + } diff --git a/src/main/java/com/cultural/heritage/service/wx/impl/WeChatServiceImpl.java b/src/main/java/com/cultural/heritage/service/wx/impl/WeChatServiceImpl.java index d8f60c0..88ed53a 100644 --- a/src/main/java/com/cultural/heritage/service/wx/impl/WeChatServiceImpl.java +++ b/src/main/java/com/cultural/heritage/service/wx/impl/WeChatServiceImpl.java @@ -19,6 +19,7 @@ import com.cultural.heritage.service.order.OrderItemService; import com.cultural.heritage.service.order.OrderService; import com.cultural.heritage.service.order.PendingServiceOrderService; import com.cultural.heritage.service.order.RefundRecordService; +import com.cultural.heritage.service.user.UserService; import com.cultural.heritage.service.wx.WeChatService; import com.cultural.heritage.utils.RefundUtils; import com.wechat.pay.java.core.notification.NotificationParser; @@ -78,6 +79,8 @@ public class WeChatServiceImpl implements WeChatService { @Resource private AdvanceOrderService advanceOrderService; + @Resource + private UserService userService; /** * 请求参数 @@ -175,6 +178,9 @@ public class WeChatServiceImpl implements WeChatService { updatePendingServiceOrder(orderNumber, OrderStatusConstant.PENDING_SHIPMENT); } + // 增加用户积分 + dealUserPointsByGood(order, true); + System.out.println("---------------------------微信支付回调(结束)-------------------------------"); return true; } @@ -192,6 +198,9 @@ public class WeChatServiceImpl implements WeChatService { // 修改订单状态 modifyAdvanceOrderStatus(advanceOrder, OrderStatusConstant.PENDING_SHIPMENT); + + // 增加用户积分 + dealUserPointsByPhoto(advanceOrder, true); System.out.println("---------------------------微信支付回调(结束)-------------------------------"); return true; } @@ -294,6 +303,8 @@ public class WeChatServiceImpl implements WeChatService { // 恢复商品库存 recoverGoodInventory(order); } + // 扣除用户积分 + dealUserPointsByGood(order, false); System.out.println("---------------------------微信退款回调(结束)-------------------------------"); return true; } @@ -316,6 +327,8 @@ public class WeChatServiceImpl implements WeChatService { // 生成退款记录 createRefundRecord(refundNotification); + // 扣除用户积分 + dealUserPointsByPhoto(advanceOrder, false); System.out.println("---------------------------微信退款回调(结束)-------------------------------"); return true; } @@ -384,6 +397,10 @@ public class WeChatServiceImpl implements WeChatService { String orderNumber = refundNotification.getOutTradeNo(); Order order = getOrderInfoByOrderNumber(orderNumber); + // 扣除用户积分 + int amount = refundNotification.getAmount().getRefund().intValue(); + userService.addOrSubUserPoints(order.getUserId(), false, amount); + // 解析出订单明细id String outRefundNo = refundNotification.getOutRefundNo(); String orderItemId = RefundUtils.parseRefundNoToItemId(outRefundNo); @@ -485,18 +502,29 @@ public class WeChatServiceImpl implements WeChatService { + /** + * (商品类订单)更新用户积分 + */ + private void dealUserPointsByGood(Order order, boolean isAdd) { + BigDecimal totalAmount = order.getTotalAmount(); + CouponSnapshot couponSnapshot = order.getCouponSnapshot(); + if (isAdd) { + if (couponSnapshot != null) { + BigDecimal conditionAmount = couponSnapshot.getConditionAmount(); + totalAmount = totalAmount.add(conditionAmount); + } + } + userService.addOrSubUserPoints(order.getUserId(), isAdd, totalAmount.intValue()); + } - - - - - - - - - - + /** + * (写真预约类)更新用户积分 + */ + private void dealUserPointsByPhoto(AdvanceOrder advanceOrder, boolean isAdd) { + BigDecimal totalAmount = advanceOrder.getTotalAmount(); + userService.addOrSubUserPoints(advanceOrder.getUserId(), isAdd, totalAmount.intValue()); + }