|
|
|
@@ -33,6 +33,8 @@ import com.iformall.service.excel.WxPressDataExporter; |
|
|
|
|
|
|
|
import com.iformall.service.pay.PayServiceFactory; |
|
|
|
import com.iformall.service.pay.service.share.PayShareAdapterService; |
|
|
|
import com.iformall.utils.Constant; |
|
|
|
import com.iformall.utils.DateUtils; |
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
@@ -102,6 +104,9 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxPayAccountMapper payAccountMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxPayAccountService payAccountService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxCouponOrderMapper wxCouponOrderMapper; |
|
|
|
@@ -353,7 +358,7 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
@Override |
|
|
|
@Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) |
|
|
|
public ResultData saveOrUpdate(WxCoupon record) { |
|
|
|
|
|
|
|
//金额处理 |
|
|
|
if (StringUtils.isNotEmpty(record.getSalePriceStr())) { |
|
|
|
record.setSalePrice(new BigDecimal(record.getSalePriceStr()).multiply(new BigDecimal(100)).intValue()); |
|
|
|
} |
|
|
|
@@ -375,16 +380,36 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
if (StringUtils.isNotEmpty(record.getSubsidyNumStr())) { |
|
|
|
record.setSubsidyNum(new BigDecimal(record.getSubsidyNumStr()).multiply(new BigDecimal(100)).intValue()); |
|
|
|
} |
|
|
|
// if (EnumCouponType.COUPON_DOUYIN.getCode().equals(record.getType())){ |
|
|
|
// if(StringUtils.isBlank(record.getItemGroup())){ |
|
|
|
// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"团购详情不能为"); |
|
|
|
// } |
|
|
|
// try{ |
|
|
|
// JSON.parseArray(record.getItemGroup()); |
|
|
|
// }catch(Exception e){ |
|
|
|
// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"团购详情格式不正确"); |
|
|
|
// } |
|
|
|
// } |
|
|
|
//补贴处理 |
|
|
|
if(record.getSubsidyType() == null){ |
|
|
|
record.setSubsidyType(EnumCouponSubsidyType.NO_SUBSIDY.getCode()); |
|
|
|
} |
|
|
|
if(record.getSubsidyNum() == null || record.getSubsidyNum().intValue() == 0){ |
|
|
|
record.setSubsidyType(EnumCouponSubsidyType.NO_SUBSIDY.getCode()); |
|
|
|
record.setSubsidyNum(0); |
|
|
|
} |
|
|
|
if (EnumCouponSubsidyType.WECHAT_COUPON.getCode().equals(record.getSubsidyType())) { |
|
|
|
// 微信 立减 |
|
|
|
if (record.getSubsidyNum() > record.getSalePrice()) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "补贴额大于售价"); |
|
|
|
} |
|
|
|
} else if (EnumCouponSubsidyType.OFFLINE_SUBSIDY.getCode().equals(record.getSubsidyType())) { |
|
|
|
// 线下补贴 |
|
|
|
int subsidy_num = record.getPrice() - record.getSalePrice(); |
|
|
|
if (record.getSubsidyNum() > subsidy_num) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "补贴额大于面额与售价的差值"); |
|
|
|
} |
|
|
|
} else if (EnumCouponSubsidyType.WECHAT_MCHPAY.getCode().equals(record.getSubsidyType())) { |
|
|
|
// TODO 微信转账到银行卡 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (EnumCouponContentType.HTML.getCode().equals(record.getContentType())) { |
|
|
|
if (StringUtils.isEmpty(record.getHtml())) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请填写富文本内容"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (StringUtils.isBlank(record.getCoverPicture())) { |
|
|
|
List<String> strList = new ArrayList<String>(); |
|
|
|
if (StringUtils.isNotBlank(record.getCoverImg())) { |
|
|
|
@@ -405,133 +430,62 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请填写有效时间类型"); |
|
|
|
} |
|
|
|
if(!this.validCouponDate(record)) { |
|
|
|
return new ResultData(ResultData.ERROR,"券有效使用日期必须在30天以内。"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(EnumCouponType.COUPON_GIFT.getCode().equals(record.getType()) && EnumCouponValidType.BETWEEN_TWO_TIME.getCode().equals(record.getValidType())){ |
|
|
|
//券礼包时间判断 |
|
|
|
WxCoupon couponQ = new WxCoupon(); |
|
|
|
couponQ.updateTenantInfo(record); |
|
|
|
List<Long> longs = JSON.parseArray(record.getGiftList(), Long.class); |
|
|
|
if(longs != null && longs.size() > 0){ |
|
|
|
couponQ.setIds(longs); |
|
|
|
List<WxCoupon> list = wxCouponMapper.findList(couponQ); |
|
|
|
if(list != null && list.size() > 0){ |
|
|
|
for (WxCoupon wc:list) { |
|
|
|
if(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode().equals(wc.getStatus())){ |
|
|
|
return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF_GIFT); |
|
|
|
} |
|
|
|
if(EnumCouponValidType.BETWEEN_TWO_TIME.getCode().equals(wc.getValidType()) && wc.getValidEndDate().before(record.getValidEndDate())){ |
|
|
|
return new ResultData(ErrorCode.COUPON_VALID_DATE_ERR_GIFT); |
|
|
|
} |
|
|
|
} |
|
|
|
}else{ |
|
|
|
return new ResultData(ErrorCode.COUPON_IS_EMPTY_GIFT); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
return new ResultData(ErrorCode.COUPON_IS_EMPTY_GIFT); |
|
|
|
return new ResultData(ResultData.ERROR,"券有效结束日期必须在30天以内。"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (EnumCouponContentType.HTML.getCode().equals(record.getContentType())) { |
|
|
|
if (StringUtils.isEmpty(record.getHtml())) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请填写富文本内容"); |
|
|
|
} |
|
|
|
ResultData giftResult = this.validGiftCouponDate(record); |
|
|
|
if(Result.SUCCESS != giftResult.code){ |
|
|
|
return giftResult; |
|
|
|
} |
|
|
|
|
|
|
|
ResultData resultData = checkCouponMerchantReceiver(record); |
|
|
|
if(resultData.code != 200){ |
|
|
|
return resultData; |
|
|
|
ResultData receiverResult = checkCouponMerchantReceiver(record); |
|
|
|
if(Result.SUCCESS != giftResult.code){ |
|
|
|
return receiverResult; |
|
|
|
} |
|
|
|
|
|
|
|
List<JSONObject> merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); |
|
|
|
|
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
if (record.getId() == null) { |
|
|
|
|
|
|
|
// check 卡券补贴设置 |
|
|
|
Integer subsidyType = record.getSubsidyType(); |
|
|
|
Integer subsidyNum = record.getSubsidyNum(); |
|
|
|
if(subsidyType != null && subsidyNum != null) { |
|
|
|
if (subsidyType.equals(EnumCouponSubsidyType.WECHAT_COUPON.getCode())) { |
|
|
|
// 微信 立减 |
|
|
|
if (subsidyNum > record.getSalePrice()) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "补贴额大于售价"); |
|
|
|
} |
|
|
|
} else if (subsidyType.equals(EnumCouponSubsidyType.OFFLINE_SUBSIDY.getCode())) { |
|
|
|
// 线下补贴 |
|
|
|
int subsidy_num = record.getPrice() - record.getSalePrice(); |
|
|
|
if (subsidyNum > subsidy_num) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "补贴额大于面额与售价的差值"); |
|
|
|
} |
|
|
|
} else if (subsidyType.equals(EnumCouponSubsidyType.WECHAT_MCHPAY.getCode())) { |
|
|
|
// TODO 微信转账到银行卡 |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
record.setId(idWorker.nextId()); |
|
|
|
|
|
|
|
if (merchantParamList != null && merchantParamList.size() > 0) { |
|
|
|
List<WxCouponMerchantDto> wxCouponMerchantDtoList = new ArrayList<>(); |
|
|
|
merchantParamList.forEach(merchantParam -> { |
|
|
|
WxCouponMerchant cm = new WxCouponMerchant(); |
|
|
|
WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam); |
|
|
|
cm.setId(idWorker.nextId()); |
|
|
|
cm.updateTenantInfo(record); |
|
|
|
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()); |
|
|
|
wxCouponMerchantDtoList.add(wxCouponMerchantDto); |
|
|
|
wxCouponMerchantMapper.insert(cm); |
|
|
|
}); |
|
|
|
if (wxCouponMerchantDtoList.stream() |
|
|
|
.mapToInt(WxCouponMerchantDto::getBusiness).distinct().count() > 1) { |
|
|
|
record.setBusiness(EnumBusiness.BUSINESS_ID6.getCode()); |
|
|
|
} else if (wxCouponMerchantDtoList.size() > 1){ |
|
|
|
record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness()); |
|
|
|
} else { |
|
|
|
record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness()); |
|
|
|
record.setSubBusiness(wxCouponMerchantDtoList.get(0).getSubBusiness()); |
|
|
|
} |
|
|
|
|
|
|
|
} else{ |
|
|
|
if (!EnumCouponType.COUPON_GIFT.getCode().equals(record.getType())){ |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); |
|
|
|
} |
|
|
|
List<WxCouponMerchantDto> wxCouponMerchantDtoList = new ArrayList<>(); |
|
|
|
merchantParamList.forEach(merchantParam -> { |
|
|
|
WxCouponMerchant cm = new WxCouponMerchant(); |
|
|
|
WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam); |
|
|
|
cm.setId(idWorker.nextId()); |
|
|
|
cm.updateTenantInfo(record); |
|
|
|
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()); |
|
|
|
wxCouponMerchantDtoList.add(wxCouponMerchantDto); |
|
|
|
wxCouponMerchantMapper.insert(cm); |
|
|
|
}); |
|
|
|
if (wxCouponMerchantDtoList.stream() |
|
|
|
.mapToInt(WxCouponMerchantDto::getBusiness).distinct().count() > 1) { |
|
|
|
record.setBusiness(EnumBusiness.BUSINESS_ID6.getCode()); |
|
|
|
} else if (wxCouponMerchantDtoList.size() > 1){ |
|
|
|
record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness()); |
|
|
|
} else { |
|
|
|
record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness()); |
|
|
|
record.setSubBusiness(wxCouponMerchantDtoList.get(0).getSubBusiness()); |
|
|
|
} |
|
|
|
|
|
|
|
if (record.getPasswordSupport() != null && record.getPasswordSupport().equals(EnumCouponPasswordSupport.SUPPORTED.getCode())) { |
|
|
|
// 如果用户启用卡密,生成数据并保存 |
|
|
|
// todo 生成卡密无法修改, 调整 |
|
|
|
couponPasswordService.mkPasswords(record, record.getId(), record.getInventory()); |
|
|
|
} |
|
|
|
|
|
|
|
record.setId(idWorker.nextId()); |
|
|
|
record.setCreateDate(new Date()); |
|
|
|
record.setUpdateDate(new Date()); |
|
|
|
wxCouponMapper.insert(record); |
|
|
|
|
|
|
|
} else { |
|
|
|
if(EnumCouponSendType.GIFT.getCode().equals(record.getSendType())){ |
|
|
|
//券礼包子券类型判断时间 |
|
|
|
WxCoupon couponQ = new WxCoupon(); |
|
|
|
couponQ.updateTenantInfo(record); |
|
|
|
couponQ.setStatus(EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode()); |
|
|
|
couponQ.setGiftList(Long.toString(record.getId())); |
|
|
|
List<WxCoupon> couponList = wxCouponMapper.findCouponList(couponQ); |
|
|
|
if(couponList != null && couponList.size() > 0){ |
|
|
|
for (WxCoupon wc:couponList) { |
|
|
|
if(EnumCouponType.COUPON_GIFT.getCode().equals(wc.getType()) |
|
|
|
&& EnumCouponValidType.BETWEEN_TWO_TIME.getCode().equals(record.getValidType()) |
|
|
|
&& record.getValidEndDate().before(wc.getValidEndDate())){ |
|
|
|
return new ResultData(ErrorCode.COUPON_VALID_DATE_ERR_GIFT); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(record.getInventory() != null && record.getRemainInventory() != null) { |
|
|
|
// 库存修改检查 |
|
|
|
WxCoupon oldCoupon = wxCouponMapper.selectById(record.getId(),record.getTenantId()); |
|
|
|
@@ -547,86 +501,56 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
record.setInventory(oldCoupon.getInventory() + record.getRemainInventory() - oldCoupon.getRemainInventory()); |
|
|
|
} |
|
|
|
} |
|
|
|
if (merchantParamList != null && merchantParamList.size() > 0) { |
|
|
|
WxCouponMerchant cmParam = new WxCouponMerchant(); |
|
|
|
cmParam.updateTenantInfo(record); |
|
|
|
cmParam.setProductId(record.getId()); |
|
|
|
List<WxCouponMerchant> oldList = wxCouponMerchantMapper.findList(cmParam); |
|
|
|
List<WxCouponMerchantDto> wxCouponMerchantDtoList = new ArrayList<>(); |
|
|
|
merchantParamList.stream().forEach(merchantParam -> { |
|
|
|
WxCouponMerchant cm = new WxCouponMerchant(); |
|
|
|
WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam); |
|
|
|
cm.updateTenantInfo(record); |
|
|
|
cm.setMerchantId(wxCouponMerchantDto.getMerchantId()); |
|
|
|
cm.setProductId(record.getId()); |
|
|
|
WxCouponMerchant rcm = wxCouponMerchantMapper.selectOne(new QueryWrapper<>(cm)); |
|
|
|
if (rcm != null) { |
|
|
|
rcm.setParameter(wxCouponMerchantDto.getParameter()); |
|
|
|
rcm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); |
|
|
|
rcm.setUpdateDate(new Date()); |
|
|
|
wxCouponMerchantMapper.updateById(rcm); |
|
|
|
}else { |
|
|
|
cm.setId(idWorker.nextId()); |
|
|
|
cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); |
|
|
|
cm.setParameter(wxCouponMerchantDto.getParameter()); |
|
|
|
cm.setCreateDate(new Date()); |
|
|
|
cm.setUpdateDate(new Date()); |
|
|
|
wxCouponMerchantMapper.insert(cm); |
|
|
|
} |
|
|
|
wxCouponMerchantDtoList.add(wxCouponMerchantDto); |
|
|
|
oldList.removeIf( |
|
|
|
old->old.getProductId().equals(record.getId()) && |
|
|
|
old.getMerchantId().equals(wxCouponMerchantDto.getMerchantId())); |
|
|
|
}); |
|
|
|
|
|
|
|
oldList.stream().forEach(old->{ |
|
|
|
old.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_INVALID.getCode()); |
|
|
|
old.setUpdateDate(new Date()); |
|
|
|
wxCouponMerchantMapper.updateById(old); |
|
|
|
}); |
|
|
|
|
|
|
|
if (wxCouponMerchantDtoList.stream() |
|
|
|
.mapToInt(WxCouponMerchantDto::getBusiness).distinct().count() > 1) { |
|
|
|
record.setBusiness(EnumBusiness.BUSINESS_ID6.getCode()); |
|
|
|
} else if (wxCouponMerchantDtoList.size() > 1){ |
|
|
|
record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness()); |
|
|
|
} else { |
|
|
|
record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness()); |
|
|
|
record.setSubBusiness(wxCouponMerchantDtoList.get(0).getSubBusiness()); |
|
|
|
|
|
|
|
WxCouponMerchant cmParam = new WxCouponMerchant(); |
|
|
|
cmParam.updateTenantInfo(record); |
|
|
|
cmParam.setProductId(record.getId()); |
|
|
|
List<WxCouponMerchant> oldList = wxCouponMerchantMapper.findList(cmParam); |
|
|
|
List<WxCouponMerchantDto> wxCouponMerchantDtoList = new ArrayList<>(); |
|
|
|
merchantParamList.stream().forEach(merchantParam -> { |
|
|
|
WxCouponMerchant cm = new WxCouponMerchant(); |
|
|
|
WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam); |
|
|
|
cm.updateTenantInfo(record); |
|
|
|
cm.setMerchantId(wxCouponMerchantDto.getMerchantId()); |
|
|
|
cm.setProductId(record.getId()); |
|
|
|
WxCouponMerchant rcm = wxCouponMerchantMapper.selectOne(new QueryWrapper<>(cm)); |
|
|
|
if (rcm != null) { |
|
|
|
rcm.setParameter(wxCouponMerchantDto.getParameter()); |
|
|
|
rcm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); |
|
|
|
rcm.setUpdateDate(new Date()); |
|
|
|
wxCouponMerchantMapper.updateById(rcm); |
|
|
|
}else { |
|
|
|
cm.setId(idWorker.nextId()); |
|
|
|
cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); |
|
|
|
cm.setParameter(wxCouponMerchantDto.getParameter()); |
|
|
|
cm.setCreateDate(new Date()); |
|
|
|
cm.setUpdateDate(new Date()); |
|
|
|
wxCouponMerchantMapper.insert(cm); |
|
|
|
} |
|
|
|
wxCouponMerchantDtoList.add(wxCouponMerchantDto); |
|
|
|
oldList.removeIf( |
|
|
|
old->old.getProductId().equals(record.getId()) && |
|
|
|
old.getMerchantId().equals(wxCouponMerchantDto.getMerchantId())); |
|
|
|
}); |
|
|
|
|
|
|
|
oldList.stream().forEach(old->{ |
|
|
|
old.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_INVALID.getCode()); |
|
|
|
old.setUpdateDate(new Date()); |
|
|
|
wxCouponMerchantMapper.updateById(old); |
|
|
|
}); |
|
|
|
|
|
|
|
if (wxCouponMerchantDtoList.stream() |
|
|
|
.mapToInt(WxCouponMerchantDto::getBusiness).distinct().count() > 1) { |
|
|
|
record.setBusiness(EnumBusiness.BUSINESS_ID6.getCode()); |
|
|
|
} else if (wxCouponMerchantDtoList.size() > 1){ |
|
|
|
record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness()); |
|
|
|
} else { |
|
|
|
record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness()); |
|
|
|
record.setSubBusiness(wxCouponMerchantDtoList.get(0).getSubBusiness()); |
|
|
|
} |
|
|
|
|
|
|
|
if (record.getStatus() != null && |
|
|
|
(record.getStatus().equals(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode()))) { |
|
|
|
|
|
|
|
//下架所有投放频道 |
|
|
|
wxCouponChannelService.updateStatusByCouponId(record.getId(), record, EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()); |
|
|
|
//下架所有场景投放 |
|
|
|
wxCouponSendService.updateStatusByCouponId(record.getId(), record, EnumCouponSendStatus.INVALID.getCode()); |
|
|
|
//下架所有已砍价券 |
|
|
|
wxOrderService.updateStatusByPressCouponId(record.getId(), record, EnumOrderStatus.ORDER_STATUS_PRESS_CANCEL.getCode()); |
|
|
|
//下架所有相关广告 |
|
|
|
wxScreenAdService.updateStatusByCouponId(record.getId(), record, EnumScreenAdStatus.INVALID.getCode()); |
|
|
|
//下架拼团券 |
|
|
|
wxOrderService.updateOrderGroupStatusByCouponId(record.getId(), record, EnumOrderStatus.ORDER_STATUS_COOPERATING_CANCEL.getCode()); |
|
|
|
// 卡下架后,转赠找不到卡相关信息,所以修改卡转赠状态为不可转赠 |
|
|
|
wxCardInfoMapper.updateTransferStatusByCouponId(record.getId()); |
|
|
|
// 卡券下架,未使用的卡密要下架 |
|
|
|
couponPasswordMapper.disableByCouponId(record.getId()); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
record.setUpdateDate(new Date()); |
|
|
|
wxCouponMapper.updateById(record); |
|
|
|
|
|
|
|
try{ |
|
|
|
if(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode().equals(record.getStatus())){ |
|
|
|
//同步抖音状态 |
|
|
|
wxCouponChannelService.spuStatusSyncByCoupon(record,record.getId()); |
|
|
|
} |
|
|
|
}catch(Exception e){ |
|
|
|
logger.error("send spuStatusSync error: " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//清空缓存 |
|
|
|
@@ -636,46 +560,24 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
|
|
|
|
private ResultData checkCouponMerchantReceiver(WxCoupon record){ |
|
|
|
List<JSONObject> merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); |
|
|
|
// if(EnumCouponType.COUPON_GIFT.getCode().equals(record.getType())){ |
|
|
|
// return new ResultData(); |
|
|
|
// } |
|
|
|
|
|
|
|
if(merchantParamList == null || merchantParamList.isEmpty()){ |
|
|
|
return new ResultData(); |
|
|
|
return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空"); |
|
|
|
} |
|
|
|
if(record.getSalePrice() != null && record.getSalePrice() > 0) { |
|
|
|
WxAppinfo cAppInfo = wxAppinfoService.getCouponAppInfo(record); |
|
|
|
EnumAppPlat plat = EnumCouponType.getAppPlat(record.getType()); |
|
|
|
EnumPayWay payWay = EnumAppPlat.getPayWay(plat); |
|
|
|
WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(record,plat); |
|
|
|
if (cAppInfo == null) { |
|
|
|
return new ResultData(ErrorCode.APP_ID_NOT_FOUND); |
|
|
|
} |
|
|
|
EnumAppPlat plat = EnumAppPlat.WX; |
|
|
|
EnumAppPlat platEnum = EnumAppPlat.getByCode(cAppInfo.getPlat()); |
|
|
|
if (platEnum != null) { |
|
|
|
plat = platEnum; |
|
|
|
} |
|
|
|
EnumPayWay payWay = EnumPayWay.PAY_WAY_WECHAT; |
|
|
|
if(EnumAppPlat.TOUTIAO.equals(plat)){ |
|
|
|
payWay = EnumPayWay.PAY_WAY_TT; |
|
|
|
} |
|
|
|
|
|
|
|
WxPayAccount payAccount = payAccountMapper.selectById(cAppInfo.getPayId()); |
|
|
|
if (payAccount == null) { |
|
|
|
return new ResultData(ErrorCode.APP_ID_NOT_FOUND); |
|
|
|
} |
|
|
|
EnumPayMchType payMchType = EnumPayMchType.TOTAL; |
|
|
|
EnumPayShare isShare = EnumPayShare.NO; |
|
|
|
|
|
|
|
EnumPayMchType payMchTypeEnum = EnumPayMchType.getEnum(payAccount.getMchType()); |
|
|
|
if (payMchTypeEnum != null) { |
|
|
|
payMchType = payMchTypeEnum; |
|
|
|
} |
|
|
|
if (EnumPayMchType.DIRECT.equals(payMchType)) { |
|
|
|
isShare = EnumPayShare.NO; |
|
|
|
} else { |
|
|
|
EnumPayShare paySHareEnum = EnumPayShare.getEnum(payAccount.getShare()); |
|
|
|
if (paySHareEnum != null) { |
|
|
|
isShare = paySHareEnum; |
|
|
|
} |
|
|
|
} |
|
|
|
EnumPayMchType payMchType = EnumPayMchType.getEnum(payAccount.getMchType()); |
|
|
|
EnumPayShare isShare = EnumPayShare.getEnum(payAccount.getShare()); |
|
|
|
|
|
|
|
PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion()); |
|
|
|
List<Long> merchantIds = new ArrayList<>(); |
|
|
|
@@ -708,7 +610,7 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
merchantId = merchantIds.get(0); |
|
|
|
} |
|
|
|
record.setMakeMerchantId(merchantId); |
|
|
|
WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchantId, null, payMchTypeEnum.getCode()); |
|
|
|
WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchantId, null, payMchType.getCode()); |
|
|
|
|
|
|
|
if (receiver == null) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "["+idAndNamesMap.get(merchantId)+"]未配置收款账户"); |
|
|
|
@@ -723,7 +625,7 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
} else if (EnumPayShare.YES.equals(isShare)) { |
|
|
|
List<String> merchantNames = new ArrayList(); |
|
|
|
for (Long merchantId:merchantIds) { |
|
|
|
WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchantId, null, payMchTypeEnum.getCode()); |
|
|
|
WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchantId, null, payMchType.getCode()); |
|
|
|
if (receiver == null) { |
|
|
|
merchantNames.add(idAndNamesMap.get(merchantId)); |
|
|
|
continue; |
|
|
|
@@ -1232,33 +1134,75 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
|
|
|
|
//有价券开启了分账,必须在30天以内。,停车券,积分券,积分停车券,卡无次限制 |
|
|
|
/** |
|
|
|
* 1.有价券 |
|
|
|
* 2.微信 |
|
|
|
* 3.分账 (因微信支付线上分账30天限制) 需要限制有效期30天 |
|
|
|
* @param wxCoupon |
|
|
|
* @return boolean 有效期结束时间需要当前时间的30天限制 验证是否通过 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public boolean validCouponDate(WxCoupon wxCoupon) { |
|
|
|
if(wxCoupon.getType().equals(EnumCouponType.COUPON_DOUYIN.getCode())){ |
|
|
|
if(wxCoupon.checkIsFree()){ |
|
|
|
return true; |
|
|
|
} |
|
|
|
if(wxCoupon.getSalePrice() == 0){ |
|
|
|
if(!EnumCouponType.getWeiXinType().contains(wxCoupon.getType())){ |
|
|
|
return true; |
|
|
|
} |
|
|
|
if(wxCoupon.checkIsCard()){ |
|
|
|
if(EnumCouponType.getPlatType().contains(wxCoupon.getType())){ |
|
|
|
return true; |
|
|
|
} |
|
|
|
EnumPayShare isShare = EnumPayShare.NO; |
|
|
|
WxAppinfo appinfo = wxAppinfoService.getCouponAppInfo(wxCoupon); |
|
|
|
if (null == appinfo) { |
|
|
|
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(), "券未查询到appInfo"); |
|
|
|
|
|
|
|
WxPayAccount payAccount = payAccountService.getPayAccount(wxCoupon, EnumAppPlat.WX); |
|
|
|
if(payAccount == null){ |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "未找到支付配置"); |
|
|
|
} |
|
|
|
WxPayAccount payAccount = payAccountMapper.selectById(appinfo.getPayId()); |
|
|
|
EnumPayShare paySHareEnum = EnumPayShare.getEnum(payAccount.getShare()); |
|
|
|
if (paySHareEnum != null) { |
|
|
|
isShare = paySHareEnum; |
|
|
|
if(EnumPayShare.YES.getCode().equals(payAccount.getShare())){ |
|
|
|
Date now = new Date(); |
|
|
|
Date realValidDate = wxCoupon.getOuterRealValidDate(now); |
|
|
|
Date limit_date = DateUtils.getTimeAfterDays(Constant.WX_LIMIT_DAYS, now); |
|
|
|
if (realValidDate.after(limit_date)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
if (EnumPayShare.YES.equals(isShare)) { |
|
|
|
return wxCoupon.validDate(true,new Date()); |
|
|
|
}else{ |
|
|
|
return wxCoupon.validDate(false,new Date()); |
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 礼包券判断子券有效期 |
|
|
|
* @param wxCoupon |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public ResultData validGiftCouponDate(WxCoupon wxCoupon){ |
|
|
|
if(!EnumCouponType.COUPON_GIFT.getCode().equals(wxCoupon.getType())){ |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
//获取子券 |
|
|
|
List<Long> giftIds = JSON.parseArray(wxCoupon.getGiftList(), Long.class); |
|
|
|
if(giftIds == null || giftIds.isEmpty()){ |
|
|
|
return new ResultData(ErrorCode.COUPON_IS_EMPTY_GIFT.getCode(),"未添加子券"); |
|
|
|
} |
|
|
|
WxCoupon couponQ = new WxCoupon(); |
|
|
|
couponQ.updateTenantInfo(wxCoupon); |
|
|
|
couponQ.setIds(giftIds); |
|
|
|
List<WxCoupon> giftList = wxCouponMapper.findList(couponQ); |
|
|
|
if(giftList == null || giftList.isEmpty()){ |
|
|
|
throw new MallinkException(ErrorCode.COUPON_IS_EMPTY_GIFT.getCode(), "未找到相应子券"); |
|
|
|
} |
|
|
|
for (WxCoupon gift:giftList) { |
|
|
|
if(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode().equals(gift.getStatus())){ |
|
|
|
return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF_GIFT.getCode(),"存在已作废的子券"); |
|
|
|
} |
|
|
|
if(EnumCouponValidType.BETWEEN_TWO_TIME.getCode().equals(wxCoupon.getValidType()) |
|
|
|
&& EnumCouponValidType.BETWEEN_TWO_TIME.getCode().equals(gift.getValidType()) |
|
|
|
&& gift.getValidEndDate().before(wxCoupon.getValidEndDate())){ |
|
|
|
return new ResultData(ErrorCode.COUPON_VALID_DATE_ERR_GIFT); |
|
|
|
} |
|
|
|
} |
|
|
|
return new ResultData(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@@ -1341,4 +1285,35 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
return merchantList; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) |
|
|
|
public ResultData disable(TenantEntity tenantInfo, Long couponId) { |
|
|
|
WxCoupon couponUpd = new WxCoupon(); |
|
|
|
couponUpd.updateTenantInfo(tenantInfo); |
|
|
|
couponUpd.setId(couponId); |
|
|
|
couponUpd.setStatus(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode()); |
|
|
|
couponUpd.setUpdateDate(new Date()); |
|
|
|
int upd = wxCouponMapper.updateById(couponUpd); |
|
|
|
if(upd == 1){ |
|
|
|
//下架所有投放频道 |
|
|
|
wxCouponChannelService.updateStatusByCouponId(couponId, tenantInfo, EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()); |
|
|
|
//下架所有场景投放 |
|
|
|
wxCouponSendService.updateStatusByCouponId(couponId, tenantInfo, EnumCouponSendStatus.INVALID.getCode()); |
|
|
|
//下架所有已砍价券 |
|
|
|
wxOrderService.updateStatusByPressCouponId(couponId, tenantInfo, EnumOrderStatus.ORDER_STATUS_PRESS_CANCEL.getCode()); |
|
|
|
//下架所有相关广告 |
|
|
|
wxScreenAdService.updateStatusByCouponId(couponId, tenantInfo, EnumScreenAdStatus.INVALID.getCode()); |
|
|
|
//下架拼团券 |
|
|
|
wxOrderService.updateOrderGroupStatusByCouponId(couponId, tenantInfo, EnumOrderStatus.ORDER_STATUS_COOPERATING_CANCEL.getCode()); |
|
|
|
// 卡下架后,转赠找不到卡相关信息,所以修改卡转赠状态为不可转赠 |
|
|
|
wxCardInfoMapper.updateTransferStatusByCouponId(couponId); |
|
|
|
// 卡券下架,未使用的卡密要下架 |
|
|
|
couponPasswordMapper.disableByCouponId(couponId); |
|
|
|
|
|
|
|
//同步抖音状态 |
|
|
|
wxCouponChannelService.spuStatusSyncByCoupon(tenantInfo,couponId); |
|
|
|
} |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
|
|
|
|
} |