|
|
|
@@ -125,16 +125,17 @@ public class CouponInjectServiceImpl implements CouponInjectService { |
|
|
|
record.setSendAmount(cUsers.size()); |
|
|
|
couponInjectMapper.insertSelective(record); |
|
|
|
if(record.getSendType().equals(EnumCouponInjectSendType.IMMEDIATE.getCode())) { |
|
|
|
sendNow(wxCoupon,cUsers,record.getId()); |
|
|
|
sendNow(wxCoupon,cUsers,record); |
|
|
|
} |
|
|
|
|
|
|
|
//发送短信 |
|
|
|
sendMsg(record,cUsers); |
|
|
|
|
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
|
|
|
|
private void sendMsg(CouponInject record, List<WxCUser> cUsers) { |
|
|
|
if (!pushLimitService.checkMsg(record.getTenantId())) { |
|
|
|
logger.error("发送短信时间在疲劳度允许时间范围外"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
//根据模板ID查询短信信息 |
|
|
|
WxMsgModel model = wxMsgModelService.getById(record.getModelId()); |
|
|
|
@@ -161,6 +162,7 @@ public class CouponInjectServiceImpl implements CouponInjectService { |
|
|
|
if(wxMsgConfig.getRemains()<cUsers.size()){ |
|
|
|
logger.info("短信数量不足"); |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//获取手机号 |
|
|
|
@@ -205,20 +207,24 @@ public class CouponInjectServiceImpl implements CouponInjectService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void sendNow(WxCoupon wxCoupon,List<WxCUser> cUsers,Long couponInjectId){ |
|
|
|
private void sendNow(WxCoupon wxCoupon,List<WxCUser> cUsers,CouponInject record){ |
|
|
|
//查询标签用户 |
|
|
|
|
|
|
|
int sendRealAmount=0; |
|
|
|
List<WxCUser> sentUsers = new ArrayList<WxCUser>(); |
|
|
|
for (WxCUser tempCUser : cUsers) { |
|
|
|
int result = sendCouponToUser(tempCUser,wxCoupon,couponInjectId); |
|
|
|
sendRealAmount=sendRealAmount+result; |
|
|
|
boolean bResult = sendCouponToUser(tempCUser,wxCoupon,record.getId()); |
|
|
|
if (bResult) { |
|
|
|
sentUsers.add(tempCUser); |
|
|
|
sendRealAmount += 1; |
|
|
|
} |
|
|
|
} |
|
|
|
//修改卡券存库 |
|
|
|
wxCoupon.setRemainInventory(wxCoupon.getRemainInventory()-sendRealAmount); |
|
|
|
wxCouponService.saveOrUpdate(wxCoupon); |
|
|
|
|
|
|
|
//发送短信 |
|
|
|
sendMsg(record,sentUsers); |
|
|
|
} |
|
|
|
private int sendCouponToUser(WxCUser tempCUser,WxCoupon wxCoupon,Long couponInjectId) { |
|
|
|
int injectResult = 0;//0注入不成功,1注入卡包成功 |
|
|
|
|
|
|
|
|
|
|
|
private boolean sendCouponToUser(WxCUser tempCUser,WxCoupon wxCoupon,Long couponInjectId) { |
|
|
|
boolean checkLimit = false; |
|
|
|
// 检查疲劳度 |
|
|
|
try { |
|
|
|
@@ -227,16 +233,14 @@ public class CouponInjectServiceImpl implements CouponInjectService { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
} |
|
|
|
if (!checkLimit) { |
|
|
|
return injectResult; |
|
|
|
return false; |
|
|
|
} |
|
|
|
// 发放免费券 |
|
|
|
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; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|