|
|
|
@@ -7,6 +7,7 @@ import com.github.pagehelper.PageInfo; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.IdWorker; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.domain.dto.WxCouponMerchantDto; |
|
|
|
import com.iformall.domain.po.WxCoupon; |
|
|
|
import com.iformall.domain.po.WxCouponChannel; |
|
|
|
import com.iformall.domain.po.WxCouponMerchant; |
|
|
|
@@ -14,6 +15,7 @@ import com.iformall.domain.vo.WxCouponCVo; |
|
|
|
import com.iformall.domain.vo.WxCouponStatisVo; |
|
|
|
import com.iformall.domain.vo.WxMerchantVo; |
|
|
|
import com.iformall.enums.*; |
|
|
|
import com.iformall.exception.MallinkException; |
|
|
|
import com.iformall.mapper.WxCouponChannelMapper; |
|
|
|
import com.iformall.mapper.WxCouponMapper; |
|
|
|
import com.iformall.mapper.WxCouponMerchantMapper; |
|
|
|
@@ -157,6 +159,22 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
return Integer.valueOf(merchantParam.getString("businessId")); |
|
|
|
} |
|
|
|
|
|
|
|
private WxCouponMerchantDto parseMerchantParam(JSONObject merchantParam){ |
|
|
|
WxCouponMerchantDto wxCouponMerchantDto = new WxCouponMerchantDto(); |
|
|
|
try { |
|
|
|
wxCouponMerchantDto.setMerchantId(parseMerchantId(merchantParam)); |
|
|
|
wxCouponMerchantDto.setParameter(parseParameter(merchantParam)); |
|
|
|
wxCouponMerchantDto.setBusiness(parseBusiness(merchantParam)); |
|
|
|
}catch (Exception e) { |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); |
|
|
|
} |
|
|
|
if (wxCouponMerchantDto.getBusiness()==null || wxCouponMerchantDto.getMerchantId()==null) { |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); |
|
|
|
} |
|
|
|
return wxCouponMerchantDto; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) |
|
|
|
public ResultData saveOrUpdate(WxCoupon record) { |
|
|
|
@@ -190,47 +208,44 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
if (record.getId() == null) { |
|
|
|
|
|
|
|
// check 卡券补贴设置 |
|
|
|
if(record.getType().equals(EnumCouponType.COUPON_MULTIMCH.getCode()) || |
|
|
|
record.getType().equals(EnumCouponType.CARD_MULTIMCH.getCode())) { |
|
|
|
Integer subsidyType = record.getSubsidyType(); |
|
|
|
Integer subsidyNum = record.getSubsidyNum(); |
|
|
|
if(subsidyType == null) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请填写补贴类型"); |
|
|
|
} |
|
|
|
if(subsidyNum == null) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请填写补贴金额"); |
|
|
|
} |
|
|
|
if(subsidyType.equals(EnumCouponSubsidyType.WECHAT_COUPON.getCode())) { |
|
|
|
Integer subsidyType = record.getSubsidyType(); |
|
|
|
Integer subsidyNum = record.getSubsidyNum(); |
|
|
|
if(subsidyType != null && subsidyNum != null) { |
|
|
|
if (subsidyType.equals(EnumCouponSubsidyType.WECHAT_COUPON.getCode())) { |
|
|
|
// 微信 立减 |
|
|
|
if(subsidyNum > record.getSalePrice()) { |
|
|
|
if (subsidyNum > record.getSalePrice()) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "补贴额大于售价"); |
|
|
|
} |
|
|
|
} else if(subsidyType.equals(EnumCouponSubsidyType.OFFLINE_SUBSIDY.getCode())) { |
|
|
|
} else if (subsidyType.equals(EnumCouponSubsidyType.OFFLINE_SUBSIDY.getCode())) { |
|
|
|
// 线下补贴 |
|
|
|
int subsidy_num = record.getPrice() - record.getSalePrice(); |
|
|
|
if(subsidyNum > subsidy_num) { |
|
|
|
if (subsidyNum > subsidy_num) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "补贴额大于面额与售价的差值"); |
|
|
|
} |
|
|
|
} else if(subsidyType.equals(EnumCouponSubsidyType.WECHAT_MCHPAY.getCode())) { |
|
|
|
} else if (subsidyType.equals(EnumCouponSubsidyType.WECHAT_MCHPAY.getCode())) { |
|
|
|
// TODO 微信转账到银行卡 |
|
|
|
|
|
|
|
} |
|
|
|
} else if ((subsidyType == null && subsidyNum != null) |
|
|
|
|| (subsidyType != null && subsidyNum == null)){ |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); |
|
|
|
} |
|
|
|
|
|
|
|
record.setId(idWorker.nextId()); |
|
|
|
if (record.getMerchantParams() != null) { |
|
|
|
List<JSONObject> merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); |
|
|
|
List<JSONObject> merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); |
|
|
|
if (merchantParamList != null) { |
|
|
|
List<Integer> businessList= new ArrayList<>(); |
|
|
|
merchantParamList.forEach(merchantParam -> { |
|
|
|
WxCouponMerchant cm = new WxCouponMerchant(); |
|
|
|
WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam); |
|
|
|
cm.setId(idWorker.nextId()); |
|
|
|
cm.setMerchantId(parseMerchantId(merchantParam)); |
|
|
|
cm.setParameter(parseParameter(merchantParam)); |
|
|
|
cm.setMerchantId(wxCouponMerchantDto.getMerchantId()); |
|
|
|
cm.setParameter(wxCouponMerchantDto.getParameter()); |
|
|
|
cm.setProductId(record.getId()); |
|
|
|
cm.setCreateDate(new Date()); |
|
|
|
cm.setUpdateDate(new Date()); |
|
|
|
cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); |
|
|
|
businessList.add(parseBusiness(merchantParam)); |
|
|
|
businessList.add(wxCouponMerchantDto.getBusiness()); |
|
|
|
wxCouponMerchantMapper.insertSelective(cm); |
|
|
|
}); |
|
|
|
if (businessList.stream().distinct().count() > 1) { |
|
|
|
@@ -257,27 +272,27 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
List<Integer> businessList= new ArrayList<>(); |
|
|
|
merchantParamList.stream().forEach(merchantParam -> { |
|
|
|
WxCouponMerchant cm = new WxCouponMerchant(); |
|
|
|
cm.setMerchantId(parseMerchantId(merchantParam)); |
|
|
|
WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam); |
|
|
|
cm.setMerchantId(wxCouponMerchantDto.getMerchantId()); |
|
|
|
cm.setProductId(record.getId()); |
|
|
|
WxCouponMerchant rcm = wxCouponMerchantMapper.selectOne(cm); |
|
|
|
if (rcm != null) { |
|
|
|
rcm.setMerchantId(Long.valueOf(parseMerchantId(merchantParam))); |
|
|
|
rcm.setParameter(parseParameter(merchantParam)); |
|
|
|
rcm.setParameter(wxCouponMerchantDto.getParameter()); |
|
|
|
rcm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); |
|
|
|
rcm.setUpdateDate(new Date()); |
|
|
|
wxCouponMerchantMapper.updateByPrimaryKeySelective(rcm); |
|
|
|
}else { |
|
|
|
cm.setId(idWorker.nextId()); |
|
|
|
cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); |
|
|
|
cm.setParameter(parseParameter(merchantParam)); |
|
|
|
cm.setParameter(wxCouponMerchantDto.getParameter()); |
|
|
|
cm.setCreateDate(new Date()); |
|
|
|
cm.setUpdateDate(new Date()); |
|
|
|
wxCouponMerchantMapper.insertSelective(cm); |
|
|
|
} |
|
|
|
businessList.add(Integer.valueOf(parseBusiness(merchantParam))); |
|
|
|
businessList.add(Integer.valueOf(wxCouponMerchantDto.getBusiness())); |
|
|
|
oldList.removeIf( |
|
|
|
old->old.getProductId().equals(record.getId()) && |
|
|
|
old.getMerchantId().equals(Long.valueOf(parseMerchantId(merchantParam)))); |
|
|
|
old.getMerchantId().equals(wxCouponMerchantDto.getMerchantId())); |
|
|
|
}); |
|
|
|
|
|
|
|
oldList.stream().forEach(old->{ |
|
|
|
|