|
|
|
@@ -68,39 +68,27 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { |
|
|
|
Long notOrderGroupId = 0L; |
|
|
|
//查看是否首次拼团,orderGroupId不等于0代表不是首次拼团,因为第二个加入的拼团者肯定有团单号 |
|
|
|
if (!orderGroupId.equals(notOrderGroupId)) { |
|
|
|
long time = System.currentTimeMillis() + RedisLock.TIMEOUT; |
|
|
|
String timeStr = String.valueOf(time); |
|
|
|
// 团单加锁 |
|
|
|
String orderGroupIdStr = String.valueOf(orderGroupId); |
|
|
|
WxOrderGroup wxOrderGroup = null; |
|
|
|
while (!redisLock.lock(orderGroupIdStr, timeStr)) { |
|
|
|
try { |
|
|
|
Thread.sleep(1000); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
logger.error("订单休眠失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
wxOrderGroup = wxOrderGroupMapper.selectByPrimaryKey(orderGroupId); |
|
|
|
if (wxOrderGroup.getRemainPeople() == 0) { |
|
|
|
//修改订单状态后定时退款 |
|
|
|
WxOrderGroup wxOrderGroup = new WxOrderGroup(); |
|
|
|
wxOrderGroup.setId(orderGroupId); |
|
|
|
wxOrderGroup.setUpdateDate(new Date()); |
|
|
|
logger.info("非首次拼团,更新拼团信息"); |
|
|
|
int row = wxOrderMapper.updateOrderGroup(wxOrderGroup); |
|
|
|
if (row == 0) { |
|
|
|
//参团失败 修改订单状态后定时退款 |
|
|
|
order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_FAILD.getCode()); |
|
|
|
wxOrderMapper.updateByPrimaryKeySelective(order); |
|
|
|
redisLock.unlock(orderGroupIdStr, timeStr); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD); |
|
|
|
} |
|
|
|
redisLock.unlock(orderGroupIdStr, timeStr); |
|
|
|
|
|
|
|
logger.info("非首次拼团,更新拼团信息"); |
|
|
|
int remainPeople = wxOrderGroup.getRemainPeople() - 1; |
|
|
|
wxOrderGroup = wxOrderGroupMapper.selectByPrimaryKey(orderGroupId); |
|
|
|
Integer remainPeople = wxOrderGroup.getRemainPeople(); |
|
|
|
int endPeople = 0; |
|
|
|
wxOrderGroup.setStatus(remainPeople == endPeople ? EnumOrderStatus.ORDER_STATUS_COOPERATING_COMPLETE.getCode() : wxOrderGroup.getStatus()); |
|
|
|
wxOrderGroup.setRemainPeople(remainPeople); |
|
|
|
wxOrderGroup.setUpdateDate(new Date()); |
|
|
|
try { |
|
|
|
wxOrderGroupMapper.updateByPrimaryKeySelective(wxOrderGroup); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("更新拼团信息失败", e); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD); |
|
|
|
} |
|
|
|
//更新order |
|
|
|
order.setOrderStatus(wxOrderGroup.getStatus()); |
|
|
|
@@ -110,7 +98,7 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { |
|
|
|
wxOrderMapper.updateByPrimaryKey(order); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("更新订单信息失败", e); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD); |
|
|
|
} |
|
|
|
if (remainPeople == endPeople) { |
|
|
|
//得到所有拼团的order |
|
|
|
@@ -127,7 +115,7 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { |
|
|
|
wxOrderService.couponOrderSuccess(temp); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("创建COUPON_ORDER失败", e); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@@ -155,7 +143,7 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { |
|
|
|
wxOrderGroupMapper.insertSelective(wxOrderGroup); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("创建拼团信息失败", e); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD); |
|
|
|
} |
|
|
|
//更新order |
|
|
|
order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING.getCode()); |
|
|
|
@@ -165,7 +153,7 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { |
|
|
|
wxOrderMapper.updateByPrimaryKeySelective(order); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("更新订单信息失败", e); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|