Explorar el Código

商户注券->过滤商户信息

release_toaliyun_real
Burce hace 6 años
padre
commit
075bcbe513
Se han modificado 2 ficheros con 50 adiciones y 72 borrados
  1. +1
    -1
      mallinkService/src/main/java/com/iformall/service/WxCouponService.java
  2. +49
    -71
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java

+ 1
- 1
mallinkService/src/main/java/com/iformall/service/WxCouponService.java Ver fichero

@@ -213,7 +213,7 @@ public interface WxCouponService {
void reduceRemainInventory(Long id, Integer remainInventory, Integer number); void reduceRemainInventory(Long id, Integer remainInventory, Integer number);


/** /**
* 库存退
* 库存退
* *
* @param id 券ID * @param id 券ID
* @param remainInventory 当前库存 * @param remainInventory 当前库存


+ 49
- 71
mallinkService/src/main/java/com/iformall/service/impl/WxCouponSendServiceImpl.java Ver fichero

@@ -32,7 +32,7 @@ import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;


@Service @Service
public class WxCouponSendServiceImpl implements WxCouponSendService {
public class WxCouponSendServiceImpl implements WxCouponSendService {
private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final Logger logger = LoggerFactory.getLogger(this.getClass());


@Autowired @Autowired
@@ -96,22 +96,23 @@ public class WxCouponSendServiceImpl implements WxCouponSendService {
record.setConditions(config.getConditions()); record.setConditions(config.getConditions());
} }
} }

//商户卡库存校验 //商户卡库存校验
if(Objects.equals(record.getSendType(),EnumCouponSendSendType.MERCHANT.getCode())) { if(Objects.equals(record.getSendType(),EnumCouponSendSendType.MERCHANT.getCode())) {
JSONObject jo = JSONObject.parseObject(record.getConditions()) ; JSONObject jo = JSONObject.parseObject(record.getConditions()) ;
if(Objects.isNull(jo)||!jo.containsKey(WxCouponSend.KEY_MERCHANT_LNVENTORY)) { if(Objects.isNull(jo)||!jo.containsKey(WxCouponSend.KEY_MERCHANT_LNVENTORY)) {
throw new BizMessageException(ErrorCode.COUPON_SEND_LIMIT_VERIFY.getMessage()) ;
throw new MallinkException(ErrorCode.COUPON_SEND_LIMIT_VERIFY) ;
} }
//查询总库存
WxCoupon queryById = new WxCoupon() ; WxCoupon queryById = new WxCoupon() ;
queryById.setId(record.getId());
queryById.setId(record.getCouponId());
WxCoupon wxCouponOfDb = wxCouponService.findById(queryById); WxCoupon wxCouponOfDb = wxCouponService.findById(queryById);
if(Objects.isNull(wxCouponOfDb)) { if(Objects.isNull(wxCouponOfDb)) {
throw new BizMessageException(ErrorCode.COUPON_IS_EMPTY.getMessage()) ;
throw new MallinkException(ErrorCode.COUPON_IS_EMPTY) ;
} }
int merchantLnventory = jo.getInteger(WxCouponSend.KEY_MERCHANT_LNVENTORY) ; int merchantLnventory = jo.getInteger(WxCouponSend.KEY_MERCHANT_LNVENTORY) ;
//商家购券数不能大于总库存
if(merchantLnventory > wxCouponOfDb.getRemainInventory()) { if(merchantLnventory > wxCouponOfDb.getRemainInventory()) {
throw new BizMessageException(ErrorCode.REMAIN_IS_EMPTY.getMessage()) ;
throw new MallinkException(ErrorCode.REMAIN_IS_EMPTY) ;
} }
//更新库存 //更新库存
wxCouponService.reduceRemainInventory(wxCouponOfDb.getId(),wxCouponOfDb.getRemainInventory(),merchantLnventory); wxCouponService.reduceRemainInventory(wxCouponOfDb.getId(),wxCouponOfDb.getRemainInventory(),merchantLnventory);
@@ -126,52 +127,29 @@ public class WxCouponSendServiceImpl implements WxCouponSendService {
} }
} }


/**
* 会员生日券处理
*
* @param record
* @return
*/
private WxCouponSend buildConditions(WxCouponSend record) {
if (!Objects.equals(record.getSendType(), EnumCouponSendSendType.BIRTHDAY.getCode())) {
return record;
}

//添加会员生日券
JSONObject conditions = JSONObject.parseObject(record.getConditions());
Long couponId = record.getCouponId();
if (Objects.nonNull(couponId)) {
JSONArray couponIds;
if (Objects.isNull(record.getId())) {
//添加默认值
if (Objects.isNull(record.getTitle())) {
record.setTitle("");
}
if (Objects.isNull(record.getCouponId())) {
record.setCouponId(0L);
}
//添加新卡券
couponIds = new JSONArray();
couponIds.add(couponId);
} else {
//更新卡券列表
WxCouponSend couponSend = wxCouponSendMapper.selectByPrimaryKey(record.getId());
conditions = JSONObject.parseObject(couponSend.getConditions());
couponIds = conditions.getJSONArray(WxCouponSend.KEY_COUPONIDS);
if (Objects.isNull(couponIds)) {
couponIds = new JSONArray();
couponIds.add(couponId);
} else {
//添加新卡券
if (!couponIds.contains(couponId)) {
couponIds.add(couponId);
}
}
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
public void updateInvalid(WxCouponSend record) {
record.setStatus(EnumCouponSendStatus.INVALID.getCode());
record.setUpdateDate(new Date());
if(Objects.equals(record.getSendType(),EnumCouponSendSendType.MERCHANT.getCode())) {
//查询总库存
WxCoupon queryById = new WxCoupon() ;
queryById.setId(record.getCouponId());
WxCoupon wxCouponOfDb = wxCouponService.findById(queryById);
if(Objects.isNull(wxCouponOfDb)) {
throw new MallinkException(ErrorCode.COUPON_IS_EMPTY) ;
}
//查询商家
JSONObject jo = JSONObject.parseObject(record.getConditions()) ;
if(Objects.isNull(jo)||!jo.containsKey(WxCouponSend.KEY_MERCHANT_LNVENTORY)) {
throw new MallinkException(ErrorCode.COUPON_SEND_LIMIT_VERIFY) ;
} }
conditions.put(WxCouponSend.KEY_COUPONIDS, couponIds);
int merchantLnventory = jo.getInteger(WxCouponSend.KEY_MERCHANT_LNVENTORY) ;
//退回库存
wxCouponService.backRemainInventory(queryById.getId(),wxCouponOfDb.getRemainInventory(),merchantLnventory);
} }
record.setConditions(conditions.toJSONString());
return record;
wxCouponSendMapper.updateByPrimaryKeySelective(record);
} }


@Override @Override
@@ -494,34 +472,30 @@ public class WxCouponSendServiceImpl implements WxCouponSendService {


@Override @Override
public void saveOrUpdateConfig(Integer beforeDays, Integer sendType, String tenantId) { public void saveOrUpdateConfig(Integer beforeDays, Integer sendType, String tenantId) {
WxCouponSend couponSendQuery = new WxCouponSend();
couponSendQuery.setSendType(sendType);
couponSendQuery.setTenantId(tenantId);
List<WxCouponSend> wxCouponSendList = wxCouponSendMapper.select(couponSendQuery);
if (CollectionUtils.isEmpty(wxCouponSendList)) {
WxCouponSend couponSend = new WxCouponSend();
couponSend.setTitle(EnumCouponSendSendType.BIRTHDAY.getMessage()+"配置信息 ");
couponSend.setCouponId(0L);
couponSend.setSendType(sendType);
WxCouponSend config = getConfig(sendType, tenantId) ;
if (Objects.isNull(config)) {
WxCouponSend couponSendQuery = new WxCouponSend();
couponSendQuery.setSendType(sendType);
couponSendQuery.setTenantId(tenantId);
couponSendQuery.setCouponId(0L);
couponSendQuery.setTitle(EnumCouponSendSendType.BIRTHDAY.getMessage()+"配置信息 ");
final IdWorker idWorker = IdWorker.get(); final IdWorker idWorker = IdWorker.get();
couponSend.setId(idWorker.nextId());
couponSend.setTenantId(tenantId);
couponSend.setStatus(EnumCouponSendStatus.INVALID.getCode());
couponSend.setCreateDate(new Date());
couponSendQuery.setId(idWorker.nextId());
couponSendQuery.setStatus(EnumCouponSendStatus.INVALID.getCode());
couponSendQuery.setCreateDate(new Date());
JSONObject couponSendJo = new JSONObject(); JSONObject couponSendJo = new JSONObject();
couponSendJo.put(WxCouponSend.KEY_BEFOREDAYS, beforeDays); couponSendJo.put(WxCouponSend.KEY_BEFOREDAYS, beforeDays);
couponSend.setConditions(couponSendJo.toJSONString());
wxCouponSendMapper.insertSelective(couponSend);
couponSendQuery.setConditions(couponSendJo.toJSONString());
wxCouponSendMapper.insertSelective(couponSendQuery);
} else { } else {
WxCouponSend couponSend = wxCouponSendList.get(0);
JSONObject couponSendJo = JSONObject.parseObject(couponSend.getConditions());
JSONObject couponSendJo = JSONObject.parseObject(config.getConditions());
if(Objects.isNull(couponSendJo)) { if(Objects.isNull(couponSendJo)) {
couponSendJo = new JSONObject(); couponSendJo = new JSONObject();
} }
couponSendJo.put(WxCouponSend.KEY_BEFOREDAYS, beforeDays); couponSendJo.put(WxCouponSend.KEY_BEFOREDAYS, beforeDays);
couponSend.setConditions(couponSendJo.toJSONString());
couponSend.setUpdateDate(new Date());
wxCouponSendMapper.updateBirthdayConfig(couponSend);
config.setConditions(couponSendJo.toJSONString());
config.setUpdateDate(new Date());
wxCouponSendMapper.updateBirthdayConfig(config);
} }
} }


@@ -535,7 +509,11 @@ public class WxCouponSendServiceImpl implements WxCouponSendService {
couponSendQuery.setStatus(EnumCouponSendStatus.INVALID.getCode()); couponSendQuery.setStatus(EnumCouponSendStatus.INVALID.getCode());
List<WxCouponSend> wxCouponSendList = wxCouponSendMapper.select(couponSendQuery); List<WxCouponSend> wxCouponSendList = wxCouponSendMapper.select(couponSendQuery);
if (CollectionUtils.isEmpty(wxCouponSendList)) { if (CollectionUtils.isEmpty(wxCouponSendList)) {
return null;
//默认配置
JSONObject couponSendJo = new JSONObject();
couponSendJo.put(WxCouponSend.KEY_BEFOREDAYS, 0);
couponSendQuery.setConditions(couponSendJo.toJSONString());
return couponSendQuery;
} }
return wxCouponSendList.get(0); return wxCouponSendList.get(0);
} }


Cargando…
Cancelar
Guardar