| @@ -10,6 +10,7 @@ import com.iformall.domain.po.WxCUserBasicInfo; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxCouponChannel; | |||
| import com.iformall.domain.po.WxCouponPassword; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.vo.WxCouponStatisVo; | |||
| import com.iformall.enums.*; | |||
| @@ -18,6 +19,7 @@ import com.iformall.service.WxCouponPasswordService; | |||
| import com.iformall.service.WxCouponService; | |||
| import com.iformall.service.WxFlowService; | |||
| import com.iformall.service.WxMallService; | |||
| import com.iformall.service.WxPayAccountService; | |||
| import com.iformall.utils.DateUtils; | |||
| import com.iformall.utils.RedisLock; | |||
| @@ -55,6 +57,9 @@ public class WxCouponController extends BaseController { | |||
| private WxMallService wxMallService; | |||
| @Autowired | |||
| RedisLock redisLock; | |||
| @Autowired | |||
| private WxPayAccountService wxPayAccountService; | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("list") | |||
| @@ -136,6 +141,16 @@ public class WxCouponController extends BaseController { | |||
| return wxCouponService.list(wxCoupon,wxCoupon, pageNum, pageSize); //全列表 | |||
| } | |||
| //有价券开启了分账,必须在30天以内。,停车券,积分券,积分停车券,卡无次限制 | |||
| private boolean validCouponDate(TenantEntity tenantEntity,WxCoupon wxCoupon) { | |||
| WxPayAccount payAccount = wxPayAccountService.getByTenantId(tenantEntity.getTenantId()); | |||
| boolean isShare = false; | |||
| if (payAccount.checkShare()) { | |||
| isShare = true; | |||
| } | |||
| return wxCoupon.validDate(isShare,true,new Date()); | |||
| } | |||
| @ApiOperation("新增接口") | |||
| @PostMapping("add") | |||
| @SystemControllerLog(description = "券投放-新增") | |||
| @@ -148,6 +163,10 @@ public class WxCouponController extends BaseController { | |||
| wxCoupon.setSourceType(EnumCouponSourceType.COUPONSource_Admin.getCode()); | |||
| } | |||
| if(!validCouponDate(this.getTenantInfo(),wxCoupon)) { | |||
| return new ResultData(ResultData.ERROR,"券有效使用日期必须在30天以内。"); | |||
| } | |||
| ResultData resultData = wxCouponService.saveOrUpdate(wxCoupon); | |||
| if (resultData.code != 200) { | |||
| return resultData; | |||
| @@ -171,6 +190,11 @@ public class WxCouponController extends BaseController { | |||
| if (wxCoupon.getId() == null) { | |||
| return new ResultData(ResultData.ERROR, "缺少id"); | |||
| } | |||
| if(!validCouponDate(this.getTenantInfo(),wxCoupon)) { | |||
| return new ResultData(ResultData.ERROR,"券有效使用日期必须在30天以内。"); | |||
| } | |||
| wxCoupon.updateTenantInfo(getTenantInfo()); | |||
| if(EnumDelFlag.YES.getCode().equals(wxCoupon.getIsDel())){ | |||
| WxCouponChannel query = new WxCouponChannel(); | |||
| @@ -241,6 +265,11 @@ public class WxCouponController extends BaseController { | |||
| return new ResultData(ErrorCode.COUPON_VALID_DATE_ERR); | |||
| } | |||
| } | |||
| if(!validCouponDate(this.getTenantInfo(),wxCoupon)) { | |||
| return new ResultData(ResultData.ERROR,"券有效使用日期必须在30天以内。"); | |||
| } | |||
| if (wxCoupon.getType().equals(EnumCouponType.COUPON_TINGCHE.getCode()) || | |||
| wxCoupon.getType().equals(EnumCouponType.COUPON_CREDIT_PARK.getCode())) { | |||
| logger.error("券库存有效期不支持停车券"); | |||
| @@ -6,6 +6,9 @@ import com.iformall.common.SortColumn; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.vo.WxCouponStatisVo; | |||
| import com.iformall.enums.EnumCouponType; | |||
| import com.iformall.enums.EnumValidStatus; | |||
| import com.iformall.utils.Constant; | |||
| import com.iformall.utils.DateUtils; | |||
| import cn.afterturn.easypoi.excel.annotation.Excel; | |||
| import lombok.Data; | |||
| @@ -15,6 +18,7 @@ import lombok.ToString; | |||
| import java.math.BigDecimal; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| @@ -363,4 +367,86 @@ public class WxCoupon extends TenantEntity { | |||
| } | |||
| return false; | |||
| } | |||
| public boolean validDate(boolean isShare,boolean hasShareAmount,Date curr) { | |||
| Map retMap = calcuteValidDate(isShare, hasShareAmount, curr); | |||
| int success = (int) retMap.get("success"); | |||
| if (success > 0) { | |||
| return true; | |||
| }else { | |||
| return false; | |||
| } | |||
| } | |||
| public Date getRealValidDate(boolean isShare,boolean hasShareAmount,Date curr) { | |||
| Map retMap = calcuteValidDate(isShare,hasShareAmount,curr); | |||
| return (Date) retMap.get("realDate"); | |||
| } | |||
| private Map calcuteValidDate(boolean isShare,boolean hasShareAmount,Date curr) { | |||
| int limit_days = Constant.WX_LIMIT_DAYS; | |||
| int success = 1; | |||
| Date valid_date = null; | |||
| if (this.getValidType().equals(EnumValidStatus.VALID_RANGE.getCode()) || | |||
| this.getType().equals(EnumCouponType.COUPON_TINGCHE.getCode())) { | |||
| if( this.getType().equals(EnumCouponType.COUPON_PREORDER.getCode())){ | |||
| valid_date = this.getPickEndDate(); | |||
| }else{ | |||
| valid_date = this.getValidEndDate(); | |||
| } | |||
| if (this.getSalePrice() > 0 && !this.checkIsCard()) { | |||
| if (hasShareAmount) { | |||
| if (isShare) { | |||
| // 分账有价券核销有效期不能大于分账过期时间 | |||
| Date limit_date = DateUtils.getTimeAfterDays(limit_days, curr); | |||
| if (valid_date.after(limit_date)) { | |||
| valid_date = limit_date; | |||
| success = 0; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } else { | |||
| if (this.getSalePrice() > 0 && !this.checkIsCard()) { | |||
| if (hasShareAmount) { | |||
| // 分账有价券核销有效期不能大于分账过期时间 | |||
| if (isShare) { | |||
| if (this.getValidDays() < Constant.WX_LIMIT_DAYS) { | |||
| limit_days = this.getValidDays(); | |||
| }else { | |||
| success = 0; | |||
| } | |||
| }else { | |||
| limit_days = this.getValidDays(); | |||
| } | |||
| } | |||
| } else { | |||
| limit_days = this.getValidDays(); | |||
| } | |||
| valid_date = DateUtils.getTimeAfterDays(limit_days, curr); | |||
| } | |||
| Map retMap = new HashMap(); | |||
| retMap.put("success", success); | |||
| retMap.put("realDate", valid_date); | |||
| return retMap; | |||
| } | |||
| public Date getOuterRealValidDate(Date curr) { | |||
| int limit_days = Constant.WX_LIMIT_DAYS; | |||
| Date valid_date = null; | |||
| if (this.getValidType().equals(EnumValidStatus.VALID_RANGE.getCode())) { | |||
| if( this.getType().equals(EnumCouponType.COUPON_PREORDER.getCode())){ | |||
| valid_date = this.getPickEndDate(); | |||
| }else{ | |||
| valid_date = this.getValidEndDate(); | |||
| } | |||
| } else { | |||
| limit_days = this.getValidDays(); | |||
| valid_date = DateUtils.getTimeAfterDays(limit_days, curr); | |||
| } | |||
| return valid_date; | |||
| } | |||
| } | |||
| @@ -995,7 +995,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| public WxCouponOrder createCouponOrder(WxOrder order, WxCUserBasicInfo user, WxCoupon coupon, Long couponPasswordId,EnumPayWay payWay,Long merchantId,Long bUserId,Long parentCouponOrderId) { | |||
| Date curr = new Date(); | |||
| Date valid_date = null; | |||
| int limit_days = Constant.WX_LIMIT_DAYS; | |||
| //int limit_days = Constant.WX_LIMIT_DAYS; | |||
| WxPayAccount payAccount = null; | |||
| WxPayAccount payAccountQ = new WxPayAccount(); | |||
| payAccountQ.updateTenantInfo(order); | |||
| @@ -1018,36 +1018,16 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| } | |||
| } | |||
| if (coupon.getValidType().equals(EnumValidStatus.VALID_RANGE.getCode()) || | |||
| coupon.getType().equals(EnumCouponType.COUPON_TINGCHE.getCode())) { | |||
| if( coupon.getType().equals(EnumCouponType.COUPON_PREORDER.getCode())){ | |||
| valid_date = coupon.getPickEndDate(); | |||
| }else{ | |||
| valid_date = coupon.getValidEndDate(); | |||
| } | |||
| if (coupon.getSalePrice() > 0 && !coupon.checkIsCard()) { | |||
| if (payOrder != null && payOrder.getShareAmount() != null) { | |||
| // 分账有价券核销有效期不能大于分账过期时间 | |||
| Date limit_date = DateUtils.getTimeAfterDays(limit_days, curr); | |||
| if (valid_date.after(limit_date)) { | |||
| valid_date = limit_date; | |||
| } | |||
| } | |||
| } | |||
| } else { | |||
| if (coupon.getSalePrice() > 0 && !coupon.checkIsCard()) { | |||
| if (payOrder != null && payOrder.getShareAmount() != null) { | |||
| // 分账有价券核销有效期不能大于分账过期时间 | |||
| if (coupon.getValidDays() < Constant.WX_LIMIT_DAYS) { | |||
| limit_days = coupon.getValidDays(); | |||
| } | |||
| } | |||
| } else { | |||
| limit_days = coupon.getValidDays(); | |||
| } | |||
| valid_date = DateUtils.getTimeAfterDays(limit_days, curr); | |||
| boolean hasShareAmount = false; | |||
| if (payOrder != null && payOrder.getShareAmount() != null) { | |||
| hasShareAmount = true; | |||
| } | |||
| boolean isShare = false; | |||
| if (null != payOrder && null != payOrder.getShare() && payOrder.getShare().intValue() > 0) { | |||
| isShare = true; | |||
| } | |||
| valid_date = coupon.getRealValidDate(isShare,hasShareAmount,curr); | |||
| boolean isCard = false; | |||
| // 检查是否是储值卡 | |||
| if (coupon.getType().equals(EnumCouponType.CARD_MULTIMCH.getCode())) { | |||
| @@ -1187,17 +1167,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| private WxCouponOrder createCouponOrderForOuter(WxOrder order, WxCUserBasicInfo user, WxCoupon coupon, Long couponPasswordId) { | |||
| Date curr = new Date(); | |||
| Date valid_date = null; | |||
| int limit_days = Constant.WX_LIMIT_DAYS; | |||
| if (coupon.getValidType().equals(EnumValidStatus.VALID_RANGE.getCode())) { | |||
| if( coupon.getType().equals(EnumCouponType.COUPON_PREORDER.getCode())){ | |||
| valid_date = coupon.getPickEndDate(); | |||
| }else{ | |||
| valid_date = coupon.getValidEndDate(); | |||
| } | |||
| } else { | |||
| limit_days = coupon.getValidDays(); | |||
| valid_date = DateUtils.getTimeAfterDays(limit_days, curr); | |||
| } | |||
| valid_date = coupon.getOuterRealValidDate(curr); | |||
| boolean isCard = false; | |||
| // 检查是否是储值卡 | |||
| if (coupon.getType().equals(EnumCouponType.CARD_MULTIMCH.getCode())) { | |||