完成积分支付和余额支付
This commit is contained in:
@@ -45,7 +45,7 @@ public class OmsOrder implements Serializable {
|
|||||||
@ApiModelProperty(value = "管理员后台调整订单使用的折扣金额")
|
@ApiModelProperty(value = "管理员后台调整订单使用的折扣金额")
|
||||||
private BigDecimal discountAmount;
|
private BigDecimal discountAmount;
|
||||||
|
|
||||||
@ApiModelProperty(value = "支付方式:0->未支付;1->支付宝;2->微信;3->线下支付")
|
@ApiModelProperty(value = "支付方式:0->未支付;1->支付宝;2->微信;3->线下支付;4->积分支付;5—>余额支付")
|
||||||
private Integer payType;
|
private Integer payType;
|
||||||
|
|
||||||
@ApiModelProperty(value = "订单来源:0->PC订单;1->app订单")
|
@ApiModelProperty(value = "订单来源:0->PC订单;1->app订单")
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class OmsOrderItem implements Serializable {
|
|||||||
@ApiModelProperty(value = "该商品经过优惠后的分解金额")
|
@ApiModelProperty(value = "该商品经过优惠后的分解金额")
|
||||||
private BigDecimal realAmount;
|
private BigDecimal realAmount;
|
||||||
|
|
||||||
private Integer giftIntegration;
|
private BigDecimal giftIntegration;
|
||||||
|
|
||||||
private Integer giftGrowth;
|
private Integer giftGrowth;
|
||||||
|
|
||||||
@@ -239,11 +239,11 @@ public class OmsOrderItem implements Serializable {
|
|||||||
this.realAmount = realAmount;
|
this.realAmount = realAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getGiftIntegration() {
|
public BigDecimal getGiftIntegration() {
|
||||||
return giftIntegration;
|
return giftIntegration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGiftIntegration(Integer giftIntegration) {
|
public void setGiftIntegration(BigDecimal giftIntegration) {
|
||||||
this.giftIntegration = giftIntegration;
|
this.giftIntegration = giftIntegration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -137,11 +137,19 @@ public class OmsPortalOrderController {
|
|||||||
|
|
||||||
@ApiOperation("积分支付")
|
@ApiOperation("积分支付")
|
||||||
@ApiImplicitParam(name = "orderId", value = "订单ID", paramType = "query")
|
@ApiImplicitParam(name = "orderId", value = "订单ID", paramType = "query")
|
||||||
|
@RequestMapping(value = "/pointPayment", method = RequestMethod.POST)
|
||||||
|
public CommonResult pointPayment(@RequestParam Long orderId) {
|
||||||
|
return portalOrderService.pointPayment(orderId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("余额支付")
|
||||||
|
@ApiImplicitParam(name = "orderId", value = "订单ID", paramType = "query")
|
||||||
@RequestMapping(value = "/balancePayment", method = RequestMethod.POST)
|
@RequestMapping(value = "/balancePayment", method = RequestMethod.POST)
|
||||||
public CommonResult balancePayment(@RequestParam Long orderId) {
|
public CommonResult balancePayment(@RequestParam Long orderId) {
|
||||||
return portalOrderService.balancePayment(orderId);
|
return portalOrderService.balancePayment(orderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation("微信预支付")
|
@ApiOperation("微信预支付")
|
||||||
@ApiImplicitParam(name = "orderId", value = "订单ID", paramType = "query")
|
@ApiImplicitParam(name = "orderId", value = "订单ID", paramType = "query")
|
||||||
@RequestMapping(value = "/wxPrePay", method = RequestMethod.POST)
|
@RequestMapping(value = "/wxPrePay", method = RequestMethod.POST)
|
||||||
|
|||||||
@@ -80,10 +80,15 @@ public interface OmsPortalOrderService {
|
|||||||
CommonResult confirmReceiving(Long orderId);
|
CommonResult confirmReceiving(Long orderId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 余额支付
|
* 积分支付
|
||||||
* @param orderId
|
* @param orderId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
CommonResult pointPayment(Long orderId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 余额支付
|
||||||
|
*/
|
||||||
CommonResult balancePayment(Long orderId);
|
CommonResult balancePayment(Long orderId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -599,7 +599,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|||||||
orderItem.setSp3(cartItem.getSp3());
|
orderItem.setSp3(cartItem.getSp3());
|
||||||
orderItem.setPromotionName("无优惠");
|
orderItem.setPromotionName("无优惠");
|
||||||
orderItem.setPromotionAmount(zero);
|
orderItem.setPromotionAmount(zero);
|
||||||
orderItem.setGiftIntegration(0);
|
orderItem.setGiftIntegration(zero);
|
||||||
orderItem.setGiftGrowth(0);
|
orderItem.setGiftGrowth(0);
|
||||||
orderItem.setCouponAmount(zero);
|
orderItem.setCouponAmount(zero);
|
||||||
orderItem.setIntegrationAmount(zero);
|
orderItem.setIntegrationAmount(zero);
|
||||||
@@ -757,10 +757,21 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|||||||
return CommonResult.validateFailed("未查询到商品信息");
|
return CommonResult.validateFailed("未查询到商品信息");
|
||||||
}
|
}
|
||||||
|
|
||||||
PmsProduct product = new PmsProduct();
|
PmsProduct product = productMapper.selectByPrimaryKey(skuStock.getProductId());
|
||||||
|
|
||||||
// 判断商品是否属于积分兑换区
|
|
||||||
boolean isPointsExchangeStatus = product.getPointsExchangeStatus() == 1;
|
// 判断商品是否属于积分兑换区
|
||||||
|
boolean isPointsExchangeStatus = product.getPointsExchangeStatus() == 1;
|
||||||
|
BigDecimal totalPointsAmount = new BigDecimal(0);
|
||||||
|
BigDecimal price = new BigDecimal(skuStock.getPrice().doubleValue());
|
||||||
|
|
||||||
|
if (isPointsExchangeStatus) {
|
||||||
|
// 积分兑换专区商品,设置积分价格
|
||||||
|
//获取商品的积分价格
|
||||||
|
BigDecimal pointsPrice = new BigDecimal(product.getintergrationPrice());
|
||||||
|
// 积分兑换商品的总金额
|
||||||
|
totalPointsAmount = pointsPrice.multiply(new BigDecimal(orderParam.getQuantity()));
|
||||||
|
}
|
||||||
|
|
||||||
//判断商品是否都有库存 (库存 - 锁定库存 = 真实库存)
|
//判断商品是否都有库存 (库存 - 锁定库存 = 真实库存)
|
||||||
if ((skuStock.getStock() - skuStock.getLockStock()) < orderParam.getQuantity()) {
|
if ((skuStock.getStock() - skuStock.getLockStock()) < orderParam.getQuantity()) {
|
||||||
@@ -771,9 +782,8 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|||||||
if(product != null) {
|
if(product != null) {
|
||||||
|
|
||||||
UmsMember member = memberMapper.selectByPrimaryKey(memberService.getCurrentMember().getId());
|
UmsMember member = memberMapper.selectByPrimaryKey(memberService.getCurrentMember().getId());
|
||||||
|
|
||||||
BigDecimal discount = commonService.getDiscount(member.getId());
|
BigDecimal discount = commonService.getDiscount(member.getId());
|
||||||
BigDecimal price = new BigDecimal(skuStock.getPrice().doubleValue());
|
|
||||||
if(discount != null) {
|
if(discount != null) {
|
||||||
price = skuStock.getPrice().multiply(discount).setScale(2, BigDecimal.ROUND_HALF_UP);
|
price = skuStock.getPrice().multiply(discount).setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||||
}
|
}
|
||||||
@@ -782,24 +792,6 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|||||||
BigDecimal zero = new BigDecimal(0);
|
BigDecimal zero = new BigDecimal(0);
|
||||||
totalAmount = price.multiply(new BigDecimal(orderParam.getQuantity()));
|
totalAmount = price.multiply(new BigDecimal(orderParam.getQuantity()));
|
||||||
|
|
||||||
// 如果是积分兑换区商品
|
|
||||||
if (isPointsExchangeStatus) {
|
|
||||||
// 直接使用积分支付,不进行实际支付金额的处理
|
|
||||||
BigDecimal integrationAmount = totalAmount;
|
|
||||||
// 确保会员有足够的积分
|
|
||||||
if (member.getIntegration() < integrationAmount.intValue()) {
|
|
||||||
return CommonResult.validateFailed("积分不足,无法兑换");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 冻结会员积分
|
|
||||||
member.setIntegration(member.getIntegration() - integrationAmount.intValue()); // 扣除积分
|
|
||||||
member.setFreeze(member.getFreeze().add(new BigDecimal(integrationAmount.intValue()))); // 冻结积分
|
|
||||||
memberMapper.updateByPrimaryKey(member);
|
|
||||||
|
|
||||||
totalAmount = zero; // 设置支付金额为零
|
|
||||||
orderParam.setIntegration(integrationAmount); // 设置积分金额
|
|
||||||
}
|
|
||||||
|
|
||||||
if(orderParam.getIntegration() == null) {
|
if(orderParam.getIntegration() == null) {
|
||||||
orderParam.setIntegration(zero);
|
orderParam.setIntegration(zero);
|
||||||
}
|
}
|
||||||
@@ -840,6 +832,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|||||||
//生成订单信息
|
//生成订单信息
|
||||||
OmsOrder order = new OmsOrder();
|
OmsOrder order = new OmsOrder();
|
||||||
order.setTotalAmount(totalAmount); // 订单总金额
|
order.setTotalAmount(totalAmount); // 订单总金额
|
||||||
|
order.setIntegrationAmount(zero); // 积分部分金额设为零
|
||||||
order.setIntegrationAmount(orderParam.getIntegration() == null ? zero : orderParam.getIntegration());
|
order.setIntegrationAmount(orderParam.getIntegration() == null ? zero : orderParam.getIntegration());
|
||||||
if(integerationFlag == 1) {
|
if(integerationFlag == 1) {
|
||||||
int flag = orderParam.getIntegration().compareTo(totalAmount);
|
int flag = orderParam.getIntegration().compareTo(totalAmount);
|
||||||
@@ -941,7 +934,8 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|||||||
orderItem.setSp3(skuStock.getSp3());
|
orderItem.setSp3(skuStock.getSp3());
|
||||||
orderItem.setPromotionName("无优惠");
|
orderItem.setPromotionName("无优惠");
|
||||||
orderItem.setPromotionAmount(new BigDecimal(0));
|
orderItem.setPromotionAmount(new BigDecimal(0));
|
||||||
orderItem.setGiftIntegration(0);
|
//积分价格
|
||||||
|
orderItem.setGiftIntegration(totalPointsAmount);
|
||||||
orderItem.setGiftGrowth(0);
|
orderItem.setGiftGrowth(0);
|
||||||
orderItem.setCouponAmount(new BigDecimal(0));
|
orderItem.setCouponAmount(new BigDecimal(0));
|
||||||
orderItem.setIntegrationAmount(new BigDecimal(0));
|
orderItem.setIntegrationAmount(new BigDecimal(0));
|
||||||
@@ -956,6 +950,9 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|||||||
|
|
||||||
result.put("orderId", order.getId());
|
result.put("orderId", order.getId());
|
||||||
result.put("totalAmount", order.getPayAmount());
|
result.put("totalAmount", order.getPayAmount());
|
||||||
|
if (isPointsExchangeStatus) {
|
||||||
|
result.put("pointsPrice", totalPointsAmount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return CommonResult.success(result, "下单成功");
|
return CommonResult.success(result, "下单成功");
|
||||||
@@ -1326,7 +1323,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResult balancePayment(Long orderId) {
|
public CommonResult pointPayment(Long orderId) {
|
||||||
|
|
||||||
OmsOrder order = orderMapper.selectByPrimaryKey(orderId);
|
OmsOrder order = orderMapper.selectByPrimaryKey(orderId);
|
||||||
if (order == null) {
|
if (order == null) {
|
||||||
@@ -1337,123 +1334,213 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|||||||
return CommonResult.validateFailed("未查询到订单信息");
|
return CommonResult.validateFailed("未查询到订单信息");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 支付方式:0->未支付;1->支付宝;2->微信;3->线下支付;4->余额支付
|
// 判断是否使用积分支付
|
||||||
// 支付方式为0才允许支付
|
|
||||||
if (order.getPayType() != 0) {
|
|
||||||
return CommonResult.validateFailed("订单已支付");
|
|
||||||
}
|
|
||||||
|
|
||||||
UmsMember member = memberMapper.selectByPrimaryKey(currentMember.getId());
|
UmsMember member = memberMapper.selectByPrimaryKey(currentMember.getId());
|
||||||
|
|
||||||
//如果实际支付金额等于0表示积分支付
|
|
||||||
//如果不是使用积分支付,返回错误信息
|
|
||||||
BigDecimal zero = new BigDecimal(0);
|
BigDecimal zero = new BigDecimal(0);
|
||||||
|
// 只要订单的支付金额为0,即表示使用积分支付
|
||||||
int flag = order.getPayAmount().compareTo(zero);
|
int flag = order.getPayAmount().compareTo(zero);
|
||||||
//flag = -1,表示PayAmount小于zero;flag = 0,表示PayAmount等于zero;flag = 1,表示PayAmount大于zero;
|
if (flag == 0) { // 如果实际支付金额为0,表示使用积分支付
|
||||||
if (flag == 0) {
|
|
||||||
|
|
||||||
//写入会员交易记录表
|
// 获取积分兑换价格
|
||||||
DmsMemberTradeRecord tradeRecord = new DmsMemberTradeRecord();
|
BigDecimal totalPointsAmount = order.getIntegrationAmount(); // 使用订单中的积分字段
|
||||||
tradeRecord.setMemberId(member.getId());
|
BigDecimal memberPoints = BigDecimal.valueOf(member.getIntegration()); // 获取当前用户积分
|
||||||
tradeRecord.setItemType(ItemType.IntegralShopping); //积分购物
|
|
||||||
tradeRecord.setNote("积分抵扣");
|
|
||||||
tradeRecord.setTitle("积分抵扣");
|
|
||||||
tradeRecord.setValue(order.getIntegrationAmount());
|
|
||||||
tradeRecord.setType(1); //收支类型:0->收入;1->支出
|
|
||||||
tradeRecord.setCreateTime(new Date());
|
|
||||||
memberTradeRecordMapper.insert(tradeRecord);
|
|
||||||
|
|
||||||
while (true) {
|
// 判断用户积分是否足够
|
||||||
long time = System.currentTimeMillis() + RedisLock.TIMEOUT;
|
if (memberPoints.compareTo(totalPointsAmount) < 0) {
|
||||||
if (redisLock.lock(String.valueOf(member.getId()), String.valueOf(time))) {
|
return CommonResult.validateFailed("积分不足,无法完成兑换");
|
||||||
member = memberMapper.selectByPrimaryKey(member.getId());
|
|
||||||
member.setFreeze(member.getFreeze().add(order.getIntegrationAmount())); //修改冻结金额,增加冻结资金
|
|
||||||
memberMapper.updateByPrimaryKey(member);
|
|
||||||
redisLock.unlock(String.valueOf(member.getId()), String.valueOf(time));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
// 扣除用户积分,并记录积分变动
|
||||||
return CommonResult.validateFailed("无效订单");
|
member.setIntegration(memberPoints.subtract(totalPointsAmount).intValue()); // 扣除积分
|
||||||
}
|
member.setFreeze(member.getFreeze().add(totalPointsAmount)); // 冻结积分
|
||||||
|
memberMapper.updateByPrimaryKey(member);
|
||||||
|
|
||||||
Date date = new Date();
|
// 支付方式:0->未支付;1->支付宝;2->微信;3->线下支付;4->积分支付支付
|
||||||
|
// 支付方式为0才允许支付
|
||||||
|
if (order.getPayType() != 0) {
|
||||||
|
return CommonResult.validateFailed("订单已支付");
|
||||||
|
}
|
||||||
|
|
||||||
//支付方式:0->未支付;1->支付宝;2->微信;3->线下支付;4->余额支付
|
|
||||||
order.setPayType(4);
|
|
||||||
|
|
||||||
//提货方式:0->自提;1->物流
|
if (flag == 0) {
|
||||||
if (order.getDeliveryType() == 0) {
|
//写入会员交易记录表
|
||||||
//订单状态:0->待付款;1->待发货;2->已发货;3->已完成;4->已关闭;5->无效订单
|
DmsMemberTradeRecord tradeRecord = new DmsMemberTradeRecord();
|
||||||
order.setStatus(2);
|
tradeRecord.setMemberId(member.getId());
|
||||||
} else {
|
tradeRecord.setItemType(ItemType.IntegralShopping); //积分购物
|
||||||
//订单状态:0->待付款;1->待发货;2->已发货;3->已完成;4->已关闭;5->无效订单
|
tradeRecord.setNote("积分抵扣");
|
||||||
order.setStatus(1);
|
tradeRecord.setTitle("积分抵扣");
|
||||||
}
|
tradeRecord.setValue(totalPointsAmount);
|
||||||
|
tradeRecord.setType(1); //收支类型:0->收入;1->支出
|
||||||
|
tradeRecord.setCreateTime(new Date());
|
||||||
|
memberTradeRecordMapper.insert(tradeRecord);
|
||||||
|
|
||||||
order.setModifyTime(date);
|
while (true) {
|
||||||
order.setPaymentTime(date);
|
long time = System.currentTimeMillis() + RedisLock.TIMEOUT;
|
||||||
orderMapper.updateByPrimaryKey(order);
|
if (redisLock.lock(String.valueOf(member.getId()), String.valueOf(time))) {
|
||||||
|
member = memberMapper.selectByPrimaryKey(member.getId());
|
||||||
|
member.setFreeze(member.getFreeze().add(order.getIntegrationAmount())); //修改冻结金额,增加冻结资金
|
||||||
|
memberMapper.updateByPrimaryKey(member);
|
||||||
|
redisLock.unlock(String.valueOf(member.getId()), String.valueOf(time));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//修改商品库存信息需要加锁,影响前台响应,所以用线程来处理
|
} else {
|
||||||
executorService.execute(new Runnable() {
|
return CommonResult.validateFailed("无效订单");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
Date date = new Date();
|
||||||
public void run() {
|
|
||||||
//库存变动
|
//支付方式:0->未支付;1->支付宝;2->微信;3->线下支付;4->余额支付
|
||||||
//查询订单商品项
|
order.setPayType(4);
|
||||||
OmsOrderItemExample example = new OmsOrderItemExample();
|
|
||||||
example.createCriteria().andOrderIdEqualTo(order.getId());
|
//提货方式:0->自提;1->物流
|
||||||
List<OmsOrderItem> orderItemList = orderItemMapper.selectByExample(example);
|
if (order.getDeliveryType() == 0) {
|
||||||
PmsSkuStock skuStock = null;
|
//订单状态:0->待付款;1->待发货;2->已发货;3->已完成;4->已关闭;5->无效订单
|
||||||
PmsProduct product = null;
|
order.setStatus(2);
|
||||||
for (OmsOrderItem orderItem : orderItemList) {
|
} else {
|
||||||
while (true) {
|
//订单状态:0->待付款;1->待发货;2->已发货;3->已完成;4->已关闭;5->无效订单
|
||||||
long time = System.currentTimeMillis() + RedisLock.TIMEOUT;
|
order.setStatus(1);
|
||||||
if (redisLock.lock(orderItem.getProductId().toString(), String.valueOf(time))) {
|
}
|
||||||
skuStock = skuStockMapper.selectByPrimaryKey(orderItem.getProductSkuId());
|
|
||||||
if (skuStock != null) {
|
order.setModifyTime(date);
|
||||||
skuStock.setLockStock(skuStock.getLockStock() - orderItem.getProductQuantity());
|
order.setPaymentTime(date);
|
||||||
skuStock.setStock(skuStock.getStock() - orderItem.getProductQuantity());
|
orderMapper.updateByPrimaryKey(order);
|
||||||
skuStock.setSale((skuStock.getSale() == null ? 0 : skuStock.getSale()) + orderItem.getProductQuantity());
|
|
||||||
skuStockMapper.updateByPrimaryKey(skuStock);
|
//修改商品库存信息需要加锁,影响前台响应,所以用线程来处理
|
||||||
|
executorService.execute(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
//库存变动
|
||||||
|
//查询订单商品项
|
||||||
|
OmsOrderItemExample example = new OmsOrderItemExample();
|
||||||
|
example.createCriteria().andOrderIdEqualTo(order.getId());
|
||||||
|
List<OmsOrderItem> orderItemList = orderItemMapper.selectByExample(example);
|
||||||
|
PmsSkuStock skuStock = null;
|
||||||
|
PmsProduct product = null;
|
||||||
|
for (OmsOrderItem orderItem : orderItemList) {
|
||||||
|
while (true) {
|
||||||
|
long time = System.currentTimeMillis() + RedisLock.TIMEOUT;
|
||||||
|
if (redisLock.lock(orderItem.getProductId().toString(), String.valueOf(time))) {
|
||||||
|
skuStock = skuStockMapper.selectByPrimaryKey(orderItem.getProductSkuId());
|
||||||
|
if (skuStock != null) {
|
||||||
|
skuStock.setLockStock(skuStock.getLockStock() - orderItem.getProductQuantity());
|
||||||
|
skuStock.setStock(skuStock.getStock() - orderItem.getProductQuantity());
|
||||||
|
skuStock.setSale((skuStock.getSale() == null ? 0 : skuStock.getSale()) + orderItem.getProductQuantity());
|
||||||
|
skuStockMapper.updateByPrimaryKey(skuStock);
|
||||||
|
}
|
||||||
|
|
||||||
|
product = productMapper.selectByPrimaryKey(orderItem.getProductId());
|
||||||
|
if (product != null) {
|
||||||
|
product.setStock(product.getStock() - orderItem.getProductQuantity());
|
||||||
|
product.setSale((product.getSale() == null ? 0 : product.getSale()) + orderItem.getProductQuantity());
|
||||||
|
productMapper.updateByPrimaryKey(product);
|
||||||
|
}
|
||||||
|
redisLock.unlock(orderItem.getProductId().toString(), String.valueOf(time));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
product = productMapper.selectByPrimaryKey(orderItem.getProductId());
|
|
||||||
if (product != null) {
|
|
||||||
product.setStock(product.getStock() - orderItem.getProductQuantity());
|
|
||||||
product.setSale((product.getSale() == null ? 0 : product.getSale()) + orderItem.getProductQuantity());
|
|
||||||
productMapper.updateByPrimaryKey(product);
|
|
||||||
}
|
|
||||||
redisLock.unlock(orderItem.getProductId().toString(), String.valueOf(time));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
boolean distributionFlag = true;
|
||||||
|
OmsOrderItemExample example = new OmsOrderItemExample();
|
||||||
|
example.createCriteria().andOrderIdEqualTo(order.getId());
|
||||||
|
List<OmsOrderItem> orderItemList = orderItemMapper.selectByExample(example);
|
||||||
|
PmsProduct product = null;
|
||||||
|
for (OmsOrderItem orderItem : orderItemList) {
|
||||||
|
product = productMapper.selectByPrimaryKey(orderItem.getProductId());
|
||||||
|
if (product.getDistributionFlag().equals(0)) { //分销标志(0->不参与;1->参与)
|
||||||
|
distributionFlag = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//分销处理
|
||||||
|
if (distributionFlag) {
|
||||||
|
distributeSender.sendMessage(order.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CommonResult.success(null, "支付成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 余额支付
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public CommonResult balancePayment(Long orderId) {
|
||||||
|
// 获取订单详情
|
||||||
|
OrderResult orderResult = getMemberOrderDetailInfo(orderId);
|
||||||
|
if (orderResult == null) {
|
||||||
|
return CommonResult.validateFailed("未查询到订单信息");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取订单的支付金额
|
||||||
|
BigDecimal payAmount = orderResult.getPayAmount();
|
||||||
|
if (payAmount == null || payAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
|
return CommonResult.validateFailed("无效的支付金额");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取当前用户信息
|
||||||
|
UmsMember currentMember = memberService.getCurrentMember();
|
||||||
|
UmsMember member = memberMapper.selectByPrimaryKey(currentMember.getId());
|
||||||
|
|
||||||
|
// 获取用户余额
|
||||||
|
BigDecimal currentBalance = member.getBalance();
|
||||||
|
|
||||||
|
// 判断余额是否足够支付
|
||||||
|
if (currentBalance.compareTo(payAmount) < 0) {
|
||||||
|
return CommonResult.validateFailed("余额不足,无法支付");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 扣除余额
|
||||||
|
member.setBalance(currentBalance.subtract(payAmount));
|
||||||
|
|
||||||
|
// 更新用户余额
|
||||||
|
memberMapper.updateByPrimaryKey(member);
|
||||||
|
|
||||||
|
|
||||||
|
// 更新订单状态为已支付
|
||||||
|
OmsOrder order = orderMapper.selectByPrimaryKey(orderId);
|
||||||
|
// 设置为余额支付
|
||||||
|
order.setPayType(5);
|
||||||
|
// 设置订单状态为已支付
|
||||||
|
order.setStatus(2);
|
||||||
|
order.setPaymentTime(new Date());
|
||||||
|
orderMapper.updateByPrimaryKey(order);
|
||||||
|
|
||||||
|
// 处理库存、分销等后续操作
|
||||||
|
executorService.execute(() -> {
|
||||||
|
// 处理库存
|
||||||
|
updateStock(orderId);
|
||||||
});
|
});
|
||||||
|
|
||||||
boolean distributionFlag = true;
|
|
||||||
OmsOrderItemExample example = new OmsOrderItemExample();
|
|
||||||
example.createCriteria().andOrderIdEqualTo(order.getId());
|
|
||||||
List<OmsOrderItem> orderItemList = orderItemMapper.selectByExample(example);
|
|
||||||
PmsProduct product = null;
|
|
||||||
for (OmsOrderItem orderItem : orderItemList) {
|
|
||||||
product = productMapper.selectByPrimaryKey(orderItem.getProductId());
|
|
||||||
if (product.getDistributionFlag().equals(0)) { //分销标志(0->不参与;1->参与)
|
|
||||||
distributionFlag = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//分销处理
|
|
||||||
if (distributionFlag) {
|
|
||||||
distributeSender.sendMessage(order.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
return CommonResult.success(null, "支付成功");
|
return CommonResult.success(null, "支付成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*处理库存的逻辑
|
||||||
|
*/
|
||||||
|
private void updateStock(Long orderId) {
|
||||||
|
// 查询订单商品信息,进行库存更新等操作
|
||||||
|
OmsOrderItemExample example = new OmsOrderItemExample();
|
||||||
|
example.createCriteria().andOrderIdEqualTo(orderId);
|
||||||
|
List<OmsOrderItem> orderItemList = orderItemMapper.selectByExample(example);
|
||||||
|
for (OmsOrderItem orderItem : orderItemList) {
|
||||||
|
PmsSkuStock skuStock = skuStockMapper.selectByPrimaryKey(orderItem.getProductSkuId());
|
||||||
|
if (skuStock != null) {
|
||||||
|
// 更新库存
|
||||||
|
skuStock.setStock(skuStock.getStock() - orderItem.getProductQuantity());
|
||||||
|
skuStockMapper.updateByPrimaryKey(skuStock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信预支付
|
* 微信预支付
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user