feat:
1. add paymentType USER_POINT
This commit is contained in:
@@ -8,6 +8,7 @@ import org.springblade.common.utils.date.DateUtil;
|
|||||||
import org.springblade.core.redis.cache.BladeRedis;
|
import org.springblade.core.redis.cache.BladeRedis;
|
||||||
import org.springblade.modules.auth.provider.UserType;
|
import org.springblade.modules.auth.provider.UserType;
|
||||||
import org.springblade.modules.common.eums.BusinessModule;
|
import org.springblade.modules.common.eums.BusinessModule;
|
||||||
|
import org.springblade.modules.common.eums.PaymentType;
|
||||||
import org.springblade.modules.common.pojo.entity.CommonOrderConfirmLogEntity;
|
import org.springblade.modules.common.pojo.entity.CommonOrderConfirmLogEntity;
|
||||||
import org.springblade.modules.common.service.ICommonOrderConfirmLogService;
|
import org.springblade.modules.common.service.ICommonOrderConfirmLogService;
|
||||||
import org.springblade.modules.market.pojo.entity.MarketBenefitPackageEntity;
|
import org.springblade.modules.market.pojo.entity.MarketBenefitPackageEntity;
|
||||||
@@ -96,7 +97,7 @@ public class InitPerformanceDayLogProcessor implements BasicProcessor {
|
|||||||
String orderType = BusinessModule.SELF_OPERATED_MALL.getCode().toUpperCase();
|
String orderType = BusinessModule.SELF_OPERATED_MALL.getCode().toUpperCase();
|
||||||
List<CommonOrderConfirmLogEntity> orderConfirmLogList = commonOrderConfirmLogService.list(
|
List<CommonOrderConfirmLogEntity> orderConfirmLogList = commonOrderConfirmLogService.list(
|
||||||
Wrappers.lambdaQuery(CommonOrderConfirmLogEntity.class)
|
Wrappers.lambdaQuery(CommonOrderConfirmLogEntity.class)
|
||||||
.in(CommonOrderConfirmLogEntity::getPaymentType, List.of(1, 2))
|
.in(CommonOrderConfirmLogEntity::getPaymentType, List.of(PaymentType.ALI.getCode() , PaymentType.WECHAT.getCode()))
|
||||||
.func(queryWrapper -> queryWrapper.apply("UPPER(order_type) = {0}", orderType))
|
.func(queryWrapper -> queryWrapper.apply("UPPER(order_type) = {0}", orderType))
|
||||||
.le(CommonOrderConfirmLogEntity::getCreateTime, today)
|
.le(CommonOrderConfirmLogEntity::getCreateTime, today)
|
||||||
.orderByAsc(CommonOrderConfirmLogEntity::getId)
|
.orderByAsc(CommonOrderConfirmLogEntity::getId)
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class StatsCalculatorCashProcessor implements BasicProcessor {
|
|||||||
|
|
||||||
List<CommonOrderConfirmLogEntity> orderPageList = orderConfirmLogService.list(
|
List<CommonOrderConfirmLogEntity> orderPageList = orderConfirmLogService.list(
|
||||||
Wrappers.lambdaQuery(CommonOrderConfirmLogEntity.class)
|
Wrappers.lambdaQuery(CommonOrderConfirmLogEntity.class)
|
||||||
.in(CommonOrderConfirmLogEntity::getPaymentType, List.of(PaymentType.ALI.getCode() , PaymentType.WECHAT.getCode() , PaymentType.OFFLINE.getCode()))
|
.in(CommonOrderConfirmLogEntity::getPaymentType, List.of(PaymentType.ALI.getCode() , PaymentType.WECHAT.getCode() , PaymentType.OFFLINE.getCode(), PaymentType.USER_POINT.getCode()))
|
||||||
.func(queryWrapper -> queryWrapper.apply("UPPER(order_type) = {0}", orderType))
|
.func(queryWrapper -> queryWrapper.apply("UPPER(order_type) = {0}", orderType))
|
||||||
.ge(CommonOrderConfirmLogEntity::getCreateTime, startDate)
|
.ge(CommonOrderConfirmLogEntity::getCreateTime, startDate)
|
||||||
.le(CommonOrderConfirmLogEntity::getCreateTime, endDate)
|
.le(CommonOrderConfirmLogEntity::getCreateTime, endDate)
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public class APPUserController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/ali-pay")
|
@PostMapping("/ali-pay")
|
||||||
@ApiOperationSupport(order = 4)
|
@ApiOperationSupport(order = 4)
|
||||||
@Operation(summary = "支付", description = "传入PaymentRequest")
|
@Operation(summary = "支付宝支付", description = "传入PaymentRequest")
|
||||||
public R<PaymentResponse> aliPay(@Valid @RequestBody PaymentRequest request) {
|
public R<PaymentResponse> aliPay(@Valid @RequestBody PaymentRequest request) {
|
||||||
return R.data(paymentService.aliAppPay(request));
|
return R.data(paymentService.aliAppPay(request));
|
||||||
}
|
}
|
||||||
@@ -98,11 +98,21 @@ public class APPUserController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/wx-pay")
|
@PostMapping("/wx-pay")
|
||||||
@ApiOperationSupport(order = 5)
|
@ApiOperationSupport(order = 5)
|
||||||
@Operation(summary = "支付", description = "传入PaymentRequest")
|
@Operation(summary = "微信支付", description = "传入PaymentRequest")
|
||||||
public R<PaymentResponse> wxPay(@Valid @RequestBody PaymentRequest request) {
|
public R<PaymentResponse> wxPay(@Valid @RequestBody PaymentRequest request) {
|
||||||
return R.data(paymentService.wxAppPay(request));
|
return R.data(paymentService.wxAppPay(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户积分支付
|
||||||
|
*/
|
||||||
|
@PostMapping("/user-point-pay")
|
||||||
|
@ApiOperationSupport(order = 5)
|
||||||
|
@Operation(summary = "用户积分支付", description = "传入PaymentRequest")
|
||||||
|
public R userPointPay(@Valid @RequestBody PaymentRequest request) {
|
||||||
|
return R.status(paymentService.userPointPay(request.getPaymentType(), Long.valueOf(request.getOrderId()), AuthUtil.getUserId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户订单列表
|
* 用户订单列表
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.springblade.modules.api.request;
|
package org.springblade.modules.api.request;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@@ -7,8 +9,10 @@ import java.io.Serializable;
|
|||||||
@Data
|
@Data
|
||||||
public class PaymentRequest implements Serializable {
|
public class PaymentRequest implements Serializable {
|
||||||
|
|
||||||
|
@NotEmpty(message = "无效订单号")
|
||||||
private String orderId;
|
private String orderId;
|
||||||
|
|
||||||
|
@NotNull(message = "无效支付类型")
|
||||||
private Integer paymentType;
|
private Integer paymentType;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,4 +19,6 @@ public interface IPaymentService {
|
|||||||
PaymentResponse wxAppPay(PaymentRequest request);
|
PaymentResponse wxAppPay(PaymentRequest request);
|
||||||
|
|
||||||
List<CommonModulePayTypeApiVO> modulePayTypeList(String moduleCode);
|
List<CommonModulePayTypeApiVO> modulePayTypeList(String moduleCode);
|
||||||
|
|
||||||
|
Boolean userPointPay(Integer paymentType, Long orderId, Long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package org.springblade.modules.api.service.impl;
|
|||||||
|
|
||||||
import com.alipay.api.response.AlipayTradeCloseResponse;
|
import com.alipay.api.response.AlipayTradeCloseResponse;
|
||||||
import com.alipay.api.response.AlipayTradeQueryResponse;
|
import com.alipay.api.response.AlipayTradeQueryResponse;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springblade.common.cache.DictBizCache;
|
|
||||||
import org.springblade.common.cache.DictCache;
|
import org.springblade.common.cache.DictCache;
|
||||||
import org.springblade.common.cache.PaymentCache;
|
import org.springblade.common.cache.PaymentCache;
|
||||||
import org.springblade.core.log.exception.ServiceException;
|
import org.springblade.core.log.exception.ServiceException;
|
||||||
@@ -13,22 +13,27 @@ import org.springblade.core.tool.utils.StringUtil;
|
|||||||
import org.springblade.modules.api.request.PaymentRequest;
|
import org.springblade.modules.api.request.PaymentRequest;
|
||||||
import org.springblade.modules.api.response.PaymentResponse;
|
import org.springblade.modules.api.response.PaymentResponse;
|
||||||
import org.springblade.modules.api.vo.CommonModulePayTypeApiVO;
|
import org.springblade.modules.api.vo.CommonModulePayTypeApiVO;
|
||||||
|
import org.springblade.modules.common.convert.AppCommonConvert;
|
||||||
import org.springblade.modules.common.eums.BusinessModule;
|
import org.springblade.modules.common.eums.BusinessModule;
|
||||||
|
import org.springblade.modules.common.eums.OrderStatus;
|
||||||
|
import org.springblade.modules.common.eums.PaymentStatus;
|
||||||
import org.springblade.modules.common.eums.PaymentType;
|
import org.springblade.modules.common.eums.PaymentType;
|
||||||
import org.springblade.modules.api.service.IPaymentService;
|
import org.springblade.modules.api.service.IPaymentService;
|
||||||
|
import org.springblade.modules.common.event.PaymentSuccessEvent;
|
||||||
import org.springblade.modules.common.pojo.entity.CommonUserOrderEntity;
|
import org.springblade.modules.common.pojo.entity.CommonUserOrderEntity;
|
||||||
import org.springblade.modules.common.service.ICommonUserOrderService;
|
import org.springblade.modules.common.service.ICommonUserOrderService;
|
||||||
|
import org.springblade.modules.common.service.ICommonUserPointService;
|
||||||
import org.springblade.modules.system.pojo.entity.Dict;
|
import org.springblade.modules.system.pojo.entity.Dict;
|
||||||
import org.springblade.modules.system.pojo.entity.DictBiz;
|
|
||||||
import org.springblade.plugin.pay.api.alipay.IAliPayApiService;
|
import org.springblade.plugin.pay.api.alipay.IAliPayApiService;
|
||||||
import org.springblade.plugin.pay.constant.PayConstant;
|
import org.springblade.plugin.pay.constant.PayConstant;
|
||||||
import org.springblade.plugin.pay.entity.AliPayAccountConfig;
|
import org.springblade.plugin.pay.entity.AliPayAccountConfig;
|
||||||
import org.springblade.plugin.pay.entity.Order;
|
import org.springblade.plugin.pay.entity.Order;
|
||||||
import org.springblade.plugin.pay.service.IOrderService;
|
import org.springblade.plugin.pay.service.IOrderService;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -43,6 +48,10 @@ public class IPaymentServiceImpl implements IPaymentService {
|
|||||||
|
|
||||||
private final IAliPayApiService aliPayApiService;
|
private final IAliPayApiService aliPayApiService;
|
||||||
|
|
||||||
|
private final ICommonUserPointService userPointService;
|
||||||
|
|
||||||
|
private final ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
private final static String PAY_TYPE_CODE_PREFIX = "app_pay_type_";
|
private final static String PAY_TYPE_CODE_PREFIX = "app_pay_type_";
|
||||||
|
|
||||||
|
|
||||||
@@ -114,14 +123,42 @@ public class IPaymentServiceImpl implements IPaymentService {
|
|||||||
BusinessModule businessModule = BusinessModule.fromCodeIgnoreCase(moduleCode);
|
BusinessModule businessModule = BusinessModule.fromCodeIgnoreCase(moduleCode);
|
||||||
String code = PAY_TYPE_CODE_PREFIX + businessModule.getCode();
|
String code = PAY_TYPE_CODE_PREFIX + businessModule.getCode();
|
||||||
List<Dict> appPayType = DictCache.getList(code);
|
List<Dict> appPayType = DictCache.getList(code);
|
||||||
List<CommonModulePayTypeApiVO> result = new ArrayList<>(appPayType.size());
|
return AppCommonConvert.INSTANCE.convertDictListToCommonModulePayTypeApiVOList(appPayType);
|
||||||
for (Dict dict : appPayType) {
|
}
|
||||||
CommonModulePayTypeApiVO vo = new CommonModulePayTypeApiVO();
|
|
||||||
vo.setDictKey(dict.getDictKey());
|
@Override
|
||||||
vo.setDictValue(dict.getDictValue());
|
@Transactional(rollbackFor = Exception.class)
|
||||||
vo.setSort(dict.getSort());
|
public Boolean userPointPay(Integer paymentType, Long orderId, Long userId) {
|
||||||
result.add(vo);
|
if (Objects.isNull(paymentType) || Objects.isNull(orderId) || Objects.isNull(userId)) {
|
||||||
|
throw new ServiceException("无效参数");
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
|
if (!paymentType.equals(PaymentType.USER_POINT.getCode())) {
|
||||||
|
throw new ServiceException("请选择正确的支付方式");
|
||||||
|
}
|
||||||
|
CommonUserOrderEntity userOrder = commonUserOrderService.getById(orderId);
|
||||||
|
if (userOrder == null) {
|
||||||
|
throw new ServiceException("无效订单");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!userOrder.getPaymentType().equals(paymentType)) {
|
||||||
|
throw new ServiceException("无效订单");
|
||||||
|
}
|
||||||
|
|
||||||
|
userPointService.spendPointForOrder(userOrder);
|
||||||
|
boolean updated = commonUserOrderService.update(Wrappers.lambdaUpdate(CommonUserOrderEntity.class)
|
||||||
|
.set(CommonUserOrderEntity::getOrderStatus, OrderStatus.PAID.getCode())
|
||||||
|
.set(CommonUserOrderEntity::getPaymentStatus, PaymentStatus.PAID.getCode())
|
||||||
|
.set(CommonUserOrderEntity::getPaymentTime, new Date())
|
||||||
|
.eq(CommonUserOrderEntity::getId, userOrder.getId())
|
||||||
|
.eq(CommonUserOrderEntity::getPaymentType, PaymentType.USER_POINT.getCode())
|
||||||
|
.eq(CommonUserOrderEntity::getOrderStatus, OrderStatus.PENDING_PAYMENT.getCode())
|
||||||
|
.eq(CommonUserOrderEntity::getPaymentStatus, PaymentStatus.UNPAID.getCode())
|
||||||
|
.eq(CommonUserOrderEntity::getIsDeleted, 0));
|
||||||
|
if (!updated){
|
||||||
|
throw new ServiceException("支付失败");
|
||||||
|
}
|
||||||
|
eventPublisher.publishEvent(new PaymentSuccessEvent(orderId, userId, BusinessModule.fromCodeIgnoreCaseOrNull(userOrder.getOrderType())));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import org.springblade.modules.common.pojo.entity.*;
|
|||||||
import org.springblade.modules.common.pojo.vo.AppCommonRegionsInfoVO;
|
import org.springblade.modules.common.pojo.vo.AppCommonRegionsInfoVO;
|
||||||
import org.springblade.modules.common.pojo.vo.CommonUserOrderVO;
|
import org.springblade.modules.common.pojo.vo.CommonUserOrderVO;
|
||||||
import org.springblade.modules.mall.pojo.entity.MallProductEntity;
|
import org.springblade.modules.mall.pojo.entity.MallProductEntity;
|
||||||
|
import org.springblade.modules.system.pojo.entity.Dict;
|
||||||
import org.springblade.modules.tour.pojo.entity.TourOrderDetailEntity;
|
import org.springblade.modules.tour.pojo.entity.TourOrderDetailEntity;
|
||||||
import org.springblade.modules.tour.pojo.entity.TourProductEntity;
|
import org.springblade.modules.tour.pojo.entity.TourProductEntity;
|
||||||
|
|
||||||
@@ -94,4 +95,9 @@ public interface AppCommonConvert {
|
|||||||
CommonModulePayTypeApiVO convertModulePayTypeToApiVO(BusinessModulePayTypeDTO.PayType dto);
|
CommonModulePayTypeApiVO convertModulePayTypeToApiVO(BusinessModulePayTypeDTO.PayType dto);
|
||||||
|
|
||||||
List<CommonModulePayTypeApiVO> convertModulePayTypeListToApiVO(List<BusinessModulePayTypeDTO.PayType> list);
|
List<CommonModulePayTypeApiVO> convertModulePayTypeListToApiVO(List<BusinessModulePayTypeDTO.PayType> list);
|
||||||
|
|
||||||
|
CommonModulePayTypeApiVO convertDictToCommonModulePayTypeApiVO(Dict dict);
|
||||||
|
|
||||||
|
List<CommonModulePayTypeApiVO> convertDictListToCommonModulePayTypeApiVOList(List<Dict> dictList);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,10 @@ import java.util.stream.Stream;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public enum PaymentType {
|
public enum PaymentType {
|
||||||
|
|
||||||
ALI(1, "支付宝" , "A"),
|
ALI(1, "支付宝", "A"),
|
||||||
WECHAT(2, "微信" , "W"),
|
WECHAT(2, "微信", "W"),
|
||||||
OFFLINE(99, "线下支付" , "O");
|
USER_POINT(3, "用户积分", "U"),
|
||||||
|
OFFLINE(99, "线下支付", "O");
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final int code;
|
private final int code;
|
||||||
@@ -23,7 +24,6 @@ public enum PaymentType {
|
|||||||
private final String abbr;
|
private final String abbr;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ========== 静态映射:code -> enum ==========
|
// ========== 静态映射:code -> enum ==========
|
||||||
|
|
||||||
private static final Map<Integer, PaymentType> BY_CODE = Stream.of(values())
|
private static final Map<Integer, PaymentType> BY_CODE = Stream.of(values())
|
||||||
|
|||||||
@@ -17,12 +17,19 @@ public enum UserPointFlowType {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
SPEND(2, "🎰 您已使用 %s 积分 参与幸运大抽奖,祝您好运连连,大奖抱回家!") {
|
SPEND_FOR_LOTTERY(2, "🎰 您已使用 %s 积分 参与幸运大抽奖,祝您好运连连,大奖抱回家!") {
|
||||||
@Override
|
@Override
|
||||||
public String formatUserMessage(String orderId, String points) {
|
public String formatUserMessage(String orderId, String points) {
|
||||||
// 注意:SPEND 不使用 orderId,但为了统一接口保留参数
|
// 注意:SPEND 不使用 orderId,但为了统一接口保留参数
|
||||||
return String.format(this.getUserMessageTemplate(), points);
|
return String.format(this.getUserMessageTemplate(), points);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
SPEND_FOR_ORDER(3, "🎰 积分支付成功!订单 %s 已使用 %s 积分完成兑换,无需额外付款。") {
|
||||||
|
@Override
|
||||||
|
public String formatUserMessage(String orderId, String points) {
|
||||||
|
return String.format(this.getUserMessageTemplate(), orderId, points);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final int code;
|
private final int code;
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import java.math.BigDecimal;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class SpendUserPointEvent {
|
public class SpendUserPointEvent {
|
||||||
|
|
||||||
|
private Long orderId;
|
||||||
|
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
private BigDecimal point;
|
private BigDecimal point;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import org.springframework.transaction.event.TransactionPhase;
|
|||||||
import org.springframework.transaction.event.TransactionalEventListener;
|
import org.springframework.transaction.event.TransactionalEventListener;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -68,7 +69,11 @@ public class NoticeListener {
|
|||||||
notice.setNoticeType(NoticeType.APP_USER.getCode());
|
notice.setNoticeType(NoticeType.APP_USER.getCode());
|
||||||
notice.setModuleType(event.getBusinessModule().getCode());
|
notice.setModuleType(event.getBusinessModule().getCode());
|
||||||
notice.setTitle(event.getBusinessModule().getDisplayName());
|
notice.setTitle(event.getBusinessModule().getDisplayName());
|
||||||
notice.setContent(UserPointFlowType.SPEND.formatUserMessage(null, String.valueOf(event.getPoint())));
|
if (Objects.isNull(event.getOrderId())) {
|
||||||
|
notice.setContent(UserPointFlowType.SPEND_FOR_LOTTERY.formatUserMessage(null, String.valueOf(event.getPoint())));
|
||||||
|
} else {
|
||||||
|
notice.setContent(UserPointFlowType.SPEND_FOR_ORDER.formatUserMessage(String.valueOf(event.getOrderId()), String.valueOf(event.getPoint())));
|
||||||
|
}
|
||||||
noticeService.save(notice);
|
noticeService.save(notice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,4 +30,6 @@ public interface ICommonUserPointService extends BaseService<CommonUserPointEnti
|
|||||||
void grantPointsByUserOrder(CommonUserOrderEntity order);
|
void grantPointsByUserOrder(CommonUserOrderEntity order);
|
||||||
|
|
||||||
void spendPointsForLottery(BigDecimal amount, Long userId);
|
void spendPointsForLottery(BigDecimal amount, Long userId);
|
||||||
|
|
||||||
|
void spendPointForOrder(CommonUserOrderEntity order);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -400,7 +400,7 @@ public class CommonUserOrderServiceImpl extends ServiceImpl<CommonUserOrderMappe
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean confirmPayment(Long id) {
|
public boolean confirmPayment(Long id) {
|
||||||
boolean updated = update(Wrappers.<CommonUserOrderEntity>lambdaUpdate()
|
boolean updated = update(Wrappers.lambdaUpdate(CommonUserOrderEntity.class)
|
||||||
.set(CommonUserOrderEntity::getOrderStatus, OrderStatus.PAID.getCode())
|
.set(CommonUserOrderEntity::getOrderStatus, OrderStatus.PAID.getCode())
|
||||||
.set(CommonUserOrderEntity::getPaymentStatus, PaymentStatus.PAID.getCode())
|
.set(CommonUserOrderEntity::getPaymentStatus, PaymentStatus.PAID.getCode())
|
||||||
.set(CommonUserOrderEntity::getPaymentTime, new Date())
|
.set(CommonUserOrderEntity::getPaymentTime, new Date())
|
||||||
@@ -467,7 +467,7 @@ public class CommonUserOrderServiceImpl extends ServiceImpl<CommonUserOrderMappe
|
|||||||
throw new ServiceException("无效订单");
|
throw new ServiceException("无效订单");
|
||||||
}
|
}
|
||||||
if (order.getOrderType().equalsIgnoreCase(BusinessModule.SELF_OPERATED_MALL.getCode())) {
|
if (order.getOrderType().equalsIgnoreCase(BusinessModule.SELF_OPERATED_MALL.getCode())) {
|
||||||
if (!order.getPaymentType().equals(PaymentType.OFFLINE.getCode())) {
|
if (order.getPaymentType().equals(PaymentType.ALI.getCode()) || order.getPaymentType().equals(PaymentType.WECHAT.getCode())) {
|
||||||
userPointService.grantPointsByUserOrder(order);
|
userPointService.grantPointsByUserOrder(order);
|
||||||
MarketInfoEntity marketInfo = marketInfoService.getById(AuthUtil.getUserId());
|
MarketInfoEntity marketInfo = marketInfoService.getById(AuthUtil.getUserId());
|
||||||
if (marketInfo == null) {
|
if (marketInfo == null) {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.springblade.modules.common.service.impl;
|
package org.springblade.modules.common.service.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import io.jsonwebtoken.lang.Assert;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springblade.core.log.exception.ServiceException;
|
import org.springblade.core.log.exception.ServiceException;
|
||||||
@@ -23,6 +22,7 @@ import org.springblade.core.mp.base.BaseServiceImpl;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import static org.springblade.modules.common.eums.BusinessModule.LOTTERY;
|
import static org.springblade.modules.common.eums.BusinessModule.LOTTERY;
|
||||||
import static org.springblade.modules.common.eums.BusinessModule.SELF_OPERATED_MALL;
|
import static org.springblade.modules.common.eums.BusinessModule.SELF_OPERATED_MALL;
|
||||||
@@ -56,9 +56,15 @@ public class CommonUserPointServiceImpl extends BaseServiceImpl<CommonUserPointM
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void grantPointsByUserOrder(CommonUserOrderEntity order) {
|
public void grantPointsByUserOrder(CommonUserOrderEntity order) {
|
||||||
Assert.notNull(order, "无效订单");
|
if (Objects.isNull(order)) {
|
||||||
Assert.isTrue(order.getId() != null && order.getUserId() != null && order.getActualAmount() != null && order.getActualAmount().compareTo(BigDecimal.ZERO) > 0, "无效订单");
|
throw new ServiceException("无效订单");
|
||||||
Assert.isTrue(order.getOrderType().equalsIgnoreCase(SELF_OPERATED_MALL.getCode()), "无效类型");
|
}
|
||||||
|
if (Objects.isNull(order.getId()) || Objects.isNull(order.getUserId()) || Objects.isNull(order.getActualAmount()) || order.getActualAmount().compareTo(BigDecimal.ZERO) < 1) {
|
||||||
|
throw new ServiceException("无效订单");
|
||||||
|
}
|
||||||
|
if (!order.getOrderType().equalsIgnoreCase(SELF_OPERATED_MALL.getCode())) {
|
||||||
|
throw new ServiceException("无效订单类型");
|
||||||
|
}
|
||||||
BigDecimal pointsAmount = order.getActualAmount().multiply(BigDecimal.valueOf(0.3));
|
BigDecimal pointsAmount = order.getActualAmount().multiply(BigDecimal.valueOf(0.3));
|
||||||
String sourceType = SELF_OPERATED_MALL.getCode();
|
String sourceType = SELF_OPERATED_MALL.getCode();
|
||||||
CommonUserPointEntity userPoint = getById(order.getUserId());
|
CommonUserPointEntity userPoint = getById(order.getUserId());
|
||||||
@@ -77,14 +83,36 @@ public class CommonUserPointServiceImpl extends BaseServiceImpl<CommonUserPointM
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void spendPointsForLottery(BigDecimal amount, Long userId) {
|
public void spendPointsForLottery(BigDecimal amount, Long userId) {
|
||||||
CommonUserPointEntity userPoint = getById(userId);
|
CommonUserPointEntity userPoint = getById(userId);
|
||||||
if (userPoint.getAmount().compareTo(amount) < 0){
|
if (userPoint.getAmount().compareTo(amount) < 0) {
|
||||||
throw new ServiceException("积分不足");
|
throw new ServiceException("积分不足");
|
||||||
}
|
}
|
||||||
BigDecimal lastAmount = userPoint.getAmount();
|
BigDecimal lastAmount = userPoint.getAmount();
|
||||||
int i = baseMapper.deductUserPoint(userId, amount, userPoint.getVersion());
|
int i = baseMapper.deductUserPoint(userId, amount, userPoint.getVersion());
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
if (userPointLogService.recordPointChangeLog(userPoint, lastAmount, LOTTERY.getCode().toUpperCase(), amount.negate(), UserPointFlowType.SPEND.getCode(), null, null)) {
|
if (userPointLogService.recordPointChangeLog(userPoint, lastAmount, LOTTERY.getCode().toUpperCase(), amount.negate(), UserPointFlowType.SPEND_FOR_LOTTERY.getCode(), null, null)) {
|
||||||
eventPublisher.publishEvent(new SpendUserPointEvent(userId, amount, LOTTERY));
|
eventPublisher.publishEvent(new SpendUserPointEvent(null, userId, amount, LOTTERY));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new ServiceException("消费用户积分失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void spendPointForOrder(CommonUserOrderEntity order) {
|
||||||
|
if (Objects.isNull(order)) {
|
||||||
|
throw new ServiceException("无效订单");
|
||||||
|
}
|
||||||
|
if (Objects.isNull(order.getId()) || Objects.isNull(order.getUserId()) || Objects.isNull(order.getActualAmount()) || order.getActualAmount().compareTo(BigDecimal.ZERO) < 1) {
|
||||||
|
throw new ServiceException("无效订单");
|
||||||
|
}
|
||||||
|
BigDecimal pointsAmount = order.getActualAmount().multiply(BigDecimal.valueOf(0.3));
|
||||||
|
BusinessModule sourceType = BusinessModule.fromCodeIgnoreCase(order.getOrderType());
|
||||||
|
CommonUserPointEntity userPoint = getById(order.getUserId());
|
||||||
|
BigDecimal lastAmount = userPoint.getAmount();
|
||||||
|
int i = baseMapper.deductUserPoint(order.getUserId(), pointsAmount, userPoint.getVersion());
|
||||||
|
if (i > 0) {
|
||||||
|
if (userPointLogService.recordPointChangeLog(userPoint, lastAmount, sourceType.getCode().toUpperCase(), pointsAmount, UserPointFlowType.SPEND_FOR_ORDER.getCode(), order.getId(), JSON.toJSONString(order))) {
|
||||||
|
eventPublisher.publishEvent(new SpendUserPointEvent(order.getId(), order.getUserId(), pointsAmount, sourceType));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user