|
|
|
@@ -16,6 +16,7 @@ import com.iformall.service.WxOrderGroupService; |
|
|
|
import com.iformall.service.WxOrderService; |
|
|
|
import com.iformall.service.WxRefundOrderService; |
|
|
|
import com.iformall.utils.DateUtils; |
|
|
|
import com.iformall.utils.RedisLock; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
@@ -57,6 +58,9 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { |
|
|
|
@Autowired |
|
|
|
WxRefundOrderService WxRefundOrderService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
RedisLock redisLock; |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) |
|
|
|
public void createOrderGroup(WxOrder order, WxCoupon wxCoupon) { |
|
|
|
@@ -64,8 +68,29 @@ 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) { |
|
|
|
//修改订单状态后定时退款 |
|
|
|
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("非首次拼团,更新拼团信息"); |
|
|
|
WxOrderGroup wxOrderGroup = wxOrderGroupMapper.selectByPrimaryKey(orderGroupId); |
|
|
|
int remainPeople = wxOrderGroup.getRemainPeople() - 1; |
|
|
|
int endPeople = 0; |
|
|
|
wxOrderGroup.setStatus(remainPeople == endPeople ? EnumOrderStatus.ORDER_STATUS_COOPERATING_COMPLETE.getCode() : wxOrderGroup.getStatus()); |
|
|
|
@@ -300,13 +325,7 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { |
|
|
|
|| temp.getOrderStatus().equals(EnumOrderStatus.ORDER_STATUS_COOPERATING_CANCEL.getCode())) { |
|
|
|
//去库存 |
|
|
|
wxOrderService.stockBack(temp); |
|
|
|
ResultData resultData = WxRefundOrderService.returnMoney(appinfo, temp.getId()); |
|
|
|
logger.info("拼团不成功时的退款返回信息:" + resultData + "resultData.code == ResultData.SUCCESS" + (resultData.code == ResultData.SUCCESS)); |
|
|
|
// if (resultData.code == ResultData.SUCCESS) { |
|
|
|
// logger.info("修改订单的状态为已退款"); |
|
|
|
// temp.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PENDING_REFUND.getCode()); |
|
|
|
// wxOrderMapper.updateByPrimaryKeySelective(temp); |
|
|
|
// } |
|
|
|
WxRefundOrderService.returnMoney(appinfo, temp.getId()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|