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

[支付][修复]:找不到券,检查提示

release_toaliyun_real
Stormeye.Wu 7 лет назад
Родитель
Сommit
6335207f8f
1 измененных файлов: 40 добавлений и 23 удалений
  1. +40
    -23
      mallinkService/src/main/java/com/simple/service/impl/WxOrderServiceImpl.java

+ 40
- 23
mallinkService/src/main/java/com/simple/service/impl/WxOrderServiceImpl.java Просмотреть файл

@@ -1,11 +1,13 @@
package com.simple.service.impl;

import java.util.*;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.simple.common.ErrorCode;
import com.simple.domain.po.*;
import com.simple.common.IdWorker;
import com.simple.domain.po.WxCUser;
import com.simple.domain.po.WxCoupon;
import com.simple.domain.po.WxCouponOrder;
import com.simple.domain.po.WxOrder;
import com.simple.domain.vo.OrderVo;
import com.simple.enums.*;
import com.simple.exception.MallinkException;
@@ -15,10 +17,13 @@ import com.simple.utils.RedisLock;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.simple.common.IdWorker;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class WxOrderServiceImpl implements WxOrderService {

@@ -42,13 +47,13 @@ public class WxOrderServiceImpl implements WxOrderService {
@Autowired
WxCUserMapper wxCUserMapper;

@Autowired
@Autowired
WxCouponMapper wxCouponMapper;

@Autowired
@Autowired
WxOrderMapper wxOrderMapper;

@Autowired
@Autowired
WxCouponOrderMapper wxCouponOrderMapper;

@Override
@@ -57,12 +62,12 @@ public class WxOrderServiceImpl implements WxOrderService {
}

@Override
public PageInfo<Map<String,Object>> bQueryListMap(OrderVo orderVo, Integer pageIndex, Integer pageSize) {
return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(()->wxOrderMapper.queryListMap(orderVo));
public PageInfo<Map<String, Object>> bQueryListMap(OrderVo orderVo, Integer pageIndex, Integer pageSize) {
return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxOrderMapper.queryListMap(orderVo));
}

@Override
public Map<String,Object> queryObject(OrderVo orderVo) {
public Map<String, Object> queryObject(OrderVo orderVo) {
return wxOrderMapper.queryObject(orderVo);
}

@@ -77,7 +82,7 @@ public class WxOrderServiceImpl implements WxOrderService {
orderQ.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode());
try {
countOrder = wxOrderMapper.selectCount(orderQ);
}catch (Exception e) {
} catch (Exception e) {
logger.error("购买是否超限-DB, couponId: " + counpon.getId() + ", e:" + e.getMessage());
throw new MallinkException(ErrorCode.ORDER_IS_FAIL);
}
@@ -88,7 +93,7 @@ public class WxOrderServiceImpl implements WxOrderService {
couponOrderQ.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode());
try {
countCouponOrder = wxCouponOrderMapper.selectCount(couponOrderQ);
}catch (Exception e) {
} catch (Exception e) {
logger.error("购买是否超限-DB, couponId: " + counpon.getId() + ", e:" + e.getMessage());
throw new MallinkException(ErrorCode.ORDER_IS_FAIL);
}
@@ -100,7 +105,7 @@ public class WxOrderServiceImpl implements WxOrderService {
long time = System.currentTimeMillis() + RedisLock.TIMEOUT;
String timeStr = String.valueOf(time);
// 库存加锁
if(!redisLock.lock(couponIdStr, timeStr)) {
if (!redisLock.lock(couponIdStr, timeStr)) {
logger.error("此券被锁定, couponId: " + couponIdStr);
throw new MallinkException(ErrorCode.TOO_MANY_REQUEST);
}
@@ -153,13 +158,25 @@ public class WxOrderServiceImpl implements WxOrderService {
long time = System.currentTimeMillis() + RedisLock.TIMEOUT;
String timeStr = String.valueOf(time);

if(!redisLock.lock(couponIdStr, timeStr)) {
if (!redisLock.lock(couponIdStr, timeStr)) {
logger.error("此券被锁定, couponId: " + couponIdStr);
throw new MallinkException(ErrorCode.TOO_MANY_REQUEST);
}
WxCoupon coupon = null;
try {
coupon = wxCouponMapper.selectByPrimaryKey(couponId);
} catch (Exception e) {
logger.error("券未找到, e:" + e.getMessage());
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL.getCode(), "券未找到:" + couponIdStr);
}
if (coupon == null) {
logger.error("券未找到, " + couponIdStr);
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL.getCode(), "券未找到:" + couponIdStr);
}

coupon.setRemainInventory(coupon.getRemainInventory() + 1);

try {
WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(couponId);
coupon.setRemainInventory(coupon.getRemainInventory() + 1);
wxCouponMapper.updateByPrimaryKeySelective(coupon);
} catch (Exception e) {
logger.error("库存+1失败, e:" + e.getMessage());
@@ -249,15 +266,16 @@ public class WxOrderServiceImpl implements WxOrderService {

/**
* 创建 couponOrder
*
* @param user
* @param order
* @param coupon
*/
private void createCouponOrder(WxCUser user, WxOrder order, WxCoupon coupon) {
Date curr = new Date();
Date valid_date = (coupon.getValidType() == EnumValidStatus.VALID_RANGE.getCode())?
coupon.getValidEndDate():
new Date((curr.getTime()/1000+coupon.getValidDays()*24*60*60)*1000);
Date valid_date = (coupon.getValidType() == EnumValidStatus.VALID_RANGE.getCode()) ?
coupon.getValidEndDate() :
new Date((curr.getTime() / 1000 + coupon.getValidDays() * 24 * 60 * 60) * 1000);
final IdWorker idWorker = IdWorker.get();
try {
WxCouponOrder couponOrder = new WxCouponOrder();
@@ -400,8 +418,7 @@ public class WxOrderServiceImpl implements WxOrderService {
Date currentDate = new Date();
switch (enumOrderStatus) {
case ORDER_STATUS_OVERTIME_CANCEL:
case ORDER_STATUS_REFUND_SUCCESS:
{
case ORDER_STATUS_REFUND_SUCCESS: {
try {
stockBack(updateOrder);
} catch (Exception e) {
@@ -416,7 +433,7 @@ public class WxOrderServiceImpl implements WxOrderService {
updateOrder.setOrderStatus(enumOrderStatus.getCode());
updateOrder.setUpdateDate(currentDate);
ret = wxOrderMapper.updateByPrimaryKey(updateOrder);
}catch (Exception e) {
} catch (Exception e) {
logger.error("订单状态更新失败, e:" + e.getMessage());
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "订单状态更新失败, e:" + e.getMessage());
}
@@ -433,7 +450,7 @@ public class WxOrderServiceImpl implements WxOrderService {
if (record.getId() == null) {
//record.setId(UUID.randomUUID().toString().replaceAll("-", ""));
final IdWorker idWorker = IdWorker.get();
record.setId(idWorker.nextId());
record.setId(idWorker.nextId());
wxOrderMapper.insertSelective(record);
} else {
wxOrderMapper.updateByPrimaryKeySelective(record);


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