fix(mcwl-pay): 修复订单问题
parent
a87d8c2295
commit
a97285ba3c
|
@ -3,6 +3,7 @@ package com.mcwl.memberCenter.domain.vo;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.mcwl.common.core.domain.BaseEntity;
|
import com.mcwl.common.core.domain.BaseEntity;
|
||||||
import com.mcwl.memberCenter.enums.MemberEnum;
|
import com.mcwl.memberCenter.enums.MemberEnum;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
|
@ -34,12 +35,14 @@ public class MemberVo{
|
||||||
/**
|
/**
|
||||||
* 会员开始时间
|
* 会员开始时间
|
||||||
*/
|
*/
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
|
||||||
@ApiModelProperty(value = "会员开始时间")
|
@ApiModelProperty(value = "会员开始时间")
|
||||||
private Date startDate;
|
private Date startDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 会员结束时间
|
* 会员结束时间
|
||||||
*/
|
*/
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
|
||||||
@ApiModelProperty(value = "会员结束时间")
|
@ApiModelProperty(value = "会员结束时间")
|
||||||
private Date endDate;
|
private Date endDate;
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import com.mcwl.resource.domain.dto.ProductRes;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author:ChenYan
|
* @Author:ChenYan
|
||||||
|
@ -30,7 +31,7 @@ public interface OrderTradeService extends IService<OrderTrade> {
|
||||||
int updateMallProduct(OrderTrade orderTrade);
|
int updateMallProduct(OrderTrade orderTrade);
|
||||||
|
|
||||||
|
|
||||||
void orderHandler(OrderTrade orderTrade, String suffix, Map<String, String> params);
|
void orderHandler(OrderTrade orderTrade, String suffix, Map<String, String> params) throws ExecutionException;
|
||||||
|
|
||||||
void productHandler(ProductRes productRes);
|
void productHandler(ProductRes productRes);
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,15 @@ import cn.hutool.core.date.DateUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.google.common.cache.Cache;
|
||||||
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.mcwl.common.constant.HttpStatus;
|
import com.mcwl.common.constant.HttpStatus;
|
||||||
import com.mcwl.common.core.domain.entity.SysUser;
|
import com.mcwl.common.core.domain.entity.SysUser;
|
||||||
import com.mcwl.common.core.page.PageDomain;
|
import com.mcwl.common.core.page.PageDomain;
|
||||||
import com.mcwl.common.core.page.TableDataInfo;
|
import com.mcwl.common.core.page.TableDataInfo;
|
||||||
import com.mcwl.common.core.redis.RedisCache;
|
import com.mcwl.common.core.redis.RedisCache;
|
||||||
import com.mcwl.common.domain.IdsParam;
|
import com.mcwl.common.domain.IdsParam;
|
||||||
|
import com.mcwl.common.exception.ServiceException;
|
||||||
import com.mcwl.common.utils.DateUtils;
|
import com.mcwl.common.utils.DateUtils;
|
||||||
import com.mcwl.common.utils.SecurityUtils;
|
import com.mcwl.common.utils.SecurityUtils;
|
||||||
import com.mcwl.common.utils.StringUtils;
|
import com.mcwl.common.utils.StringUtils;
|
||||||
|
@ -50,7 +53,11 @@ import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.locks.Lock;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author:ChenYan
|
* @Author:ChenYan
|
||||||
|
@ -101,6 +108,10 @@ public class OrderTradeServiceImpl extends ServiceImpl<OrderTradeMapper, OrderTr
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisCache redisCache;
|
private RedisCache redisCache;
|
||||||
|
|
||||||
|
private static final Cache<String, Object> USER_LOCKS = CacheBuilder.newBuilder()
|
||||||
|
.expireAfterAccess(3, TimeUnit.MINUTES)
|
||||||
|
.build();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void productHandler(ProductRes productRes) {
|
public void productHandler(ProductRes productRes) {
|
||||||
|
@ -325,6 +336,7 @@ public class OrderTradeServiceImpl extends ServiceImpl<OrderTradeMapper, OrderTr
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取收入趋势
|
* 获取收入趋势
|
||||||
|
*
|
||||||
* @return IncomeVo
|
* @return IncomeVo
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@ -394,31 +406,36 @@ public class OrderTradeServiceImpl extends ServiceImpl<OrderTradeMapper, OrderTr
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void orderHandler(OrderTrade orderTrade, String suffix, Map<String, String> params) {
|
public void orderHandler(OrderTrade orderTrade, String suffix, Map<String, String> params) throws ExecutionException {
|
||||||
|
Object objLock = USER_LOCKS.get(orderTrade.getCode(), () -> new Object());
|
||||||
|
synchronized (objLock) {
|
||||||
|
orderTrade = orderTradeService.getById(orderTrade.getId());
|
||||||
|
if (orderTrade.getPayStatus() == 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String buyerPayAmountStr = params.get("buyer_pay_amount");
|
||||||
|
if (buyerPayAmountStr != null && !buyerPayAmountStr.isEmpty()) {
|
||||||
|
BigDecimal buyerPayAmount = new BigDecimal(buyerPayAmountStr);
|
||||||
|
orderTrade.setPaymentAmount(buyerPayAmount.intValue());
|
||||||
|
}
|
||||||
|
|
||||||
String buyerPayAmountStr = params.get("buyer_pay_amount");
|
// 根据订单类型进行处理
|
||||||
if (buyerPayAmountStr != null && !buyerPayAmountStr.isEmpty()) {
|
if (OrderTypeEnum.POINTS.getName().equals(suffix)) {
|
||||||
BigDecimal buyerPayAmount = new BigDecimal(buyerPayAmountStr);
|
pointsHandler(orderTrade, params);
|
||||||
orderTrade.setPaymentAmount(buyerPayAmount.intValue());
|
} else if (OrderTypeEnum.MEMBER.getName().equals(suffix)) {
|
||||||
|
Long promotionId = redisCache.getCacheObject(params.get("out_trade_no") + "_promotionId");
|
||||||
|
memberHandler(orderTrade, promotionId);
|
||||||
|
redisCache.deleteObject(params.get("out_trade_no") + "_promotionId");
|
||||||
|
} else if (OrderTypeEnum.WALLET.getName().equals(suffix)) {
|
||||||
|
walletHandler(orderTrade, params);
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("订单类型错误");
|
||||||
|
}
|
||||||
|
// 处理订单
|
||||||
|
this.orderHandler(orderTrade, params);
|
||||||
|
// 删除redis缓存
|
||||||
|
redisCache.deleteObject(orderTrade.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据订单类型进行处理
|
|
||||||
if (OrderTypeEnum.POINTS.getName().equals(suffix)) {
|
|
||||||
pointsHandler(orderTrade, params);
|
|
||||||
} else if (OrderTypeEnum.MEMBER.getName().equals(suffix)) {
|
|
||||||
Long promotionId = redisCache.getCacheObject(params.get("out_trade_no") + "_promotionId");
|
|
||||||
memberHandler(orderTrade, promotionId);
|
|
||||||
redisCache.deleteObject(params.get("out_trade_no") + "promotionId");
|
|
||||||
} else if (OrderTypeEnum.WALLET.getName().equals(suffix)) {
|
|
||||||
walletHandler(orderTrade, params);
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException("订单类型错误");
|
|
||||||
}
|
|
||||||
// 处理订单
|
|
||||||
this.orderHandler(orderTrade, params);
|
|
||||||
// 删除redis缓存
|
|
||||||
redisCache.deleteObject(orderTrade.getCode());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pointsHandler(OrderTrade orderTrade, Map<String, String> params) {
|
private void pointsHandler(OrderTrade orderTrade, Map<String, String> params) {
|
||||||
|
@ -595,6 +612,12 @@ public class OrderTradeServiceImpl extends ServiceImpl<OrderTradeMapper, OrderTr
|
||||||
* @return Map<String, Double> 商品价格(price) 邀请人提成(amount)
|
* @return Map<String, Double> 商品价格(price) 邀请人提成(amount)
|
||||||
*/
|
*/
|
||||||
private Map<String, Double> getStringDoubleMap(Long productUserId, SysUser sysUser, Double price) {
|
private Map<String, Double> getStringDoubleMap(Long productUserId, SysUser sysUser, Double price) {
|
||||||
|
|
||||||
|
Double wallet = sysUser.getWallet();
|
||||||
|
if (wallet < price) {
|
||||||
|
throw new ServiceException("钱包余额不足,请充值", HttpStatus.SHOW_ERROR_MSG);
|
||||||
|
}
|
||||||
|
|
||||||
// 从redis获取提成比例
|
// 从redis获取提成比例
|
||||||
// 抽取商家金额比例
|
// 抽取商家金额比例
|
||||||
String CommissionRationMerchant = redisCache.getCacheObject(CommissionRationEnum.COMMISSION_RATION_MERCHANT.getName());
|
String CommissionRationMerchant = redisCache.getCacheObject(CommissionRationEnum.COMMISSION_RATION_MERCHANT.getName());
|
||||||
|
|
Loading…
Reference in New Issue