Просмотр исходного кода

更新拼团bug

release_toaliyun_real
xiaohanzi 6 лет назад
Родитель
Сommit
4f7e506eee
3 измененных файлов: 89 добавлений и 35 удалений
  1. +31
    -9
      mallinkCApi/src/main/java/com/iformall/controller/WxPayOrderController.java
  2. +5
    -0
      mallinkService/src/main/java/com/iformall/service/WxOrderGroupService.java
  3. +53
    -26
      mallinkService/src/main/java/com/iformall/service/impl/WxOrderGroupServiceImpl.java

+ 31
- 9
mallinkCApi/src/main/java/com/iformall/controller/WxPayOrderController.java Просмотреть файл

@@ -1,32 +1,47 @@
package com.iformall.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.iformall.common.ErrorCode;
import com.iformall.common.IdWorker;
import com.iformall.common.Result;
import com.iformall.common.ResultData;
import com.iformall.domain.po.*;
import com.iformall.domain.po.WxAppinfo;
import com.iformall.domain.po.WxCUser;
import com.iformall.domain.po.WxCUserBasicInfo;
import com.iformall.domain.po.WxOrder;
import com.iformall.domain.po.WxPayAccount;
import com.iformall.domain.po.WxPayOrder;
import com.iformall.enums.EnumCreditLockedStatus;
import com.iformall.enums.EnumPayStatus;
import com.iformall.enums.EnumPayWay;
import com.iformall.exception.MallinkException;
import com.iformall.service.WxCUserBasicInfoService;
import com.iformall.service.WxOrderGroupService;
import com.iformall.service.WxOrderService;
import com.iformall.service.WxPayAccountService;
import com.iformall.service.WxPayOrderService;
import com.iformall.utils.IPUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/api/pay")
@@ -45,6 +60,9 @@ public class WxPayOrderController extends BaseController {
@Autowired
private WxPayAccountService wxPayAccountService;
@Autowired
private WxOrderGroupService orderGroupService;

//@ApiOperation(value = "发起微信小程序支付订单", notes = "{\"orderId\":\"string\"}")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@@ -142,6 +160,10 @@ public class WxPayOrderController extends BaseController {
}
if (payOrder.getPayOrderStatus().equals(EnumPayStatus.PAY_STATUS_SUCCESS.getCode())) {
order = wxOrderService.getById(orderId);
//如果是拼团,需要处理拼团状态和人数
if(order.getOrderGroupId() != null && !order.getOrderGroupId().equals(0L)) {
orderGroupService.afterPaySuccessUpdate(order);
}
return new ResultData(Result.SUCCESS, "支付状态更新成功", order);
} else{
//查询微信订单状态并更新


+ 5
- 0
mallinkService/src/main/java/com/iformall/service/WxOrderGroupService.java Просмотреть файл

@@ -32,5 +32,10 @@ public interface WxOrderGroupService {
List<WxOrderGroup> findList(WxOrderGroup group);

PageInfo<WxOrderGroupMarketing> queryOrderGroupMarketingList(WxOrderGroupMarketing marketing, Integer pageNum, Integer pageSize);
/**
* 支付成功之后,更新接口调用
*/
void afterPaySuccessUpdate(WxOrder order);

}

+ 53
- 26
mallinkService/src/main/java/com/iformall/service/impl/WxOrderGroupServiceImpl.java Просмотреть файл

@@ -65,6 +65,56 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService {
@Autowired
WxCouponChannelMapper wxCouponChannelMapper;

@Override
public void afterPaySuccessUpdate(WxOrder order) {
// 参与拼团
WxOrderGroup wxOrderGroup = wxOrderGroupMapper.selectById(order.getOrderGroupId());
if (null == wxOrderGroup) {
//错误,更新状态,定时任务会发起退款,回滚库存
order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_UNPAID.getCode());
wxOrderMapper.updateById(order);
throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD.getCode(),"WxOrderGroup is null."+order.getOrderGroupId());
}
WxCoupon wxCoupon = wxCouponMapper.selectById(order.getProductId());
if (null == wxCoupon) {
throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD.getCode(),"WxCoupon is null. orderId:"+order.getId());
}
int remainPeople = updateOrderGroup(wxOrderGroup,order,wxCoupon);
if (remainPeople == 0) {
actionAfterOrderGroupSuccess(order, order.getOrderGroupId());
}
}
private int updateOrderGroup(WxOrderGroup wxOrderGroup,WxOrder order, WxCoupon wxCoupon) {
//锁住人数
long time = System.currentTimeMillis() + RedisLock.LONG_TIMEOUT;
String timeStr = String.valueOf(time);
boolean grouppeopleLock = redisLock.lock("grouppeopleLock_"+order.getOrderGroupId(), timeStr);
if (!grouppeopleLock) {
throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD.getCode(),"参团锁定失败,请稍后再试。");
}
//此处拼团数量应从订单总数查询
int ordercount = wxOrderService.countGroupOrder(order.getOrderGroupId(),true);
Integer remainPeople = wxCoupon.getPressLimitNum()-ordercount;
//Integer remainPeople = wxOrderGroup.getRemainPeople()-1;
wxOrderGroup.setStatus(remainPeople <= 0 ? EnumOrderStatus.ORDER_STATUS_COOPERATING_COMPLETE.getCode() : wxOrderGroup.getStatus());
wxOrderGroup.setUpdateDate(new Date());
wxOrderGroup.setRemainPeople(remainPeople);
logger.info("非首次拼团,更新拼团信息, 剩余人数-1");
int row = wxOrderGroupMapper.updateOrderGroup(wxOrderGroup);
if (row != 1) {
//错误,更新状态,定时任务会发起退款,回滚库存
order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_UNPAID.getCode());
wxOrderMapper.updateById(order);
redisLock.unlock("grouppeopleLock_"+order.getOrderGroupId(), timeStr);
throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD.getCode(),"参团失败,将稍后退款.");
}else {
redisLock.unlock("grouppeopleLock_"+order.getOrderGroupId(), timeStr);
}
return remainPeople;
}
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
public void createOrderGroup(WxOrder order, WxCoupon wxCoupon) {
@@ -87,32 +137,8 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService {
throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD.getCode(),"参团人数已满,将稍后退款。");
}
//锁住人数
long time = System.currentTimeMillis() + RedisLock.LONG_TIMEOUT;
String timeStr = String.valueOf(time);
boolean grouppeopleLock = redisLock.lock("grouppeopleLock_"+orderGroupId, timeStr);
if (!grouppeopleLock) {
throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD.getCode(),"参团锁定失败,请稍后再试。");
}
//此处拼团数量应从订单总数查询
int ordercount = wxOrderService.countGroupOrder(orderGroupId,true);
Integer remainPeople = wxCoupon.getPressLimitNum()-ordercount;
//Integer remainPeople = wxOrderGroup.getRemainPeople()-1;
wxOrderGroup.setStatus(remainPeople <= 0 ? EnumOrderStatus.ORDER_STATUS_COOPERATING_COMPLETE.getCode() : wxOrderGroup.getStatus());
wxOrderGroup.setUpdateDate(new Date());
wxOrderGroup.setRemainPeople(remainPeople);
logger.info("非首次拼团,更新拼团信息, 剩余人数-1");
int row = wxOrderGroupMapper.updateOrderGroup(wxOrderGroup);
if (row != 1) {
//错误,更新状态,定时任务会发起退款,回滚库存
order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_UNPAID.getCode());
wxOrderMapper.updateById(order);
redisLock.unlock("grouppeopleLock_"+orderGroupId, timeStr);
throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD.getCode(),"参团失败,将稍后退款.");
}else {
redisLock.unlock("grouppeopleLock_"+orderGroupId, timeStr);
}

int remainPeople = updateOrderGroup(wxOrderGroup,order,wxCoupon);
// 更新订单信息
order.setOrderStatus(wxOrderGroup.getStatus());
order.setPressEndDate(wxOrderGroup.getExpiredDate());
@@ -399,4 +425,5 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService {
}
}
}

}

Загрузка…
Отмена
Сохранить