| @@ -8,9 +8,9 @@ import com.iformall.common.IdWorker; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.CouponInjectMapper; | |||
| import com.iformall.service.*; | |||
| import org.apache.commons.lang3.time.DateUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| @@ -42,6 +42,12 @@ public class CouponInjectServiceImpl implements CouponInjectService { | |||
| @Autowired | |||
| WxMsgConfigService wxMsgConfigService; | |||
| @Autowired | |||
| PushLimitService pushLimitService; | |||
| @Autowired | |||
| WxOrderService wxOrderService; | |||
| @Override | |||
| public PageInfo<CouponInject> listAsPage(CouponInject record, Integer pageIndex, Integer pageSize) { | |||
| @@ -212,33 +218,24 @@ public class CouponInjectServiceImpl implements CouponInjectService { | |||
| } | |||
| private int sendCouponToUser(WxCUser tempCUser,WxCoupon wxCoupon,Long couponInjectId) { | |||
| int injectResult = 0;//0注入不成功,1注入卡包成功 | |||
| boolean checkLimit = false; | |||
| // 检查疲劳度 | |||
| try { | |||
| WxCouponOrder wxCouponOrder = new WxCouponOrder(); | |||
| wxCouponOrder.setCouponId(wxCoupon.getId()); | |||
| wxCouponOrder.setCouponOrderStatus(0); | |||
| wxCouponOrder.setCUserId(tempCUser.getId()); | |||
| wxCouponOrder.setCouponPrice(0); | |||
| wxCouponOrder.setCreateDate(new Date()); | |||
| if (wxCoupon.getValidType().equals(EnumCouponValidType.BETWEEN_TWO_TIME.getCode())) { //时间范围区间 | |||
| wxCouponOrder.setExpiredTime(wxCoupon.getValidEndDate()); | |||
| } else { | |||
| Date date = DateUtils.addDays(new Date(), wxCoupon.getValidDays()); | |||
| wxCouponOrder.setExpiredTime(date); | |||
| } | |||
| wxCouponOrder.setTenantId(wxCoupon.getTenantId()); | |||
| Long couponOrderId = wxCouponOrderService.insertOne(wxCouponOrder); | |||
| injectResult = 1; | |||
| wxCouponActionLogService.addOne(wxCoupon.getTenantId(), wxCoupon.getId(), couponOrderId, 0, couponInjectId); | |||
| return injectResult; | |||
| //短信通知 | |||
| } catch (Exception e) { | |||
| if(injectResult==0) { | |||
| logger.error("注入用户券包异常 :"+tempCUser.getId()+"|"+e.getMessage()); | |||
| return injectResult; | |||
| } | |||
| logger.error("调用短信接口异常 :"+tempCUser.getId()+"|"+e.getMessage()); | |||
| checkLimit = pushLimitService.checkCoupon(tempCUser.getTenantId(), tempCUser.getId(), wxCoupon.getId()); | |||
| } catch (MallinkException e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| if (!checkLimit) { | |||
| return injectResult; | |||
| } | |||
| // 发放免费券 | |||
| WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(tempCUser.getId(), wxCoupon.getId()); | |||
| if (couponOrder != null) { | |||
| wxCouponActionLogService.addOne(tempCUser.getTenantId(), wxCoupon.getId(), couponOrder.getId(), EnumCouponSendSendType.INJECT.getCode(), couponInjectId); | |||
| } | |||
| injectResult = 1; | |||
| return injectResult; | |||
| } | |||