|
@@ -10,10 +10,8 @@ import com.cyksj.mapper.GoodsDonMapper;
|
|
|
import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
|
import com.cyksj.mapper.UserMapper;
|
|
import com.cyksj.mapper.UserMapper;
|
|
|
import com.cyksj.mapper.UserSubscribeAlertGoodsRecordMapper;
|
|
import com.cyksj.mapper.UserSubscribeAlertGoodsRecordMapper;
|
|
|
-import com.cyksj.model.entity.GoodsDon;
|
|
|
|
|
-import com.cyksj.model.entity.GoodsDonSku;
|
|
|
|
|
-import com.cyksj.model.entity.User;
|
|
|
|
|
-import com.cyksj.model.entity.UserSubscribeAlertGoodsRecord;
|
|
|
|
|
|
|
+import com.cyksj.mapper.market.task.UserBindDetailMapper;
|
|
|
|
|
+import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.redis.RedisService;
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.goods.GoodsSubscribeAlertService;
|
|
import com.cyksj.service.goods.GoodsSubscribeAlertService;
|
|
|
import com.cyksj.service.mail.MailService;
|
|
import com.cyksj.service.mail.MailService;
|
|
@@ -51,6 +49,8 @@ public class GoodsSubscribeAlertServiceImpl implements GoodsSubscribeAlertServic
|
|
|
|
|
|
|
|
private final RedisService redisService;
|
|
private final RedisService redisService;
|
|
|
|
|
|
|
|
|
|
+ private final UserBindDetailMapper userBindDetailMapper;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void alertBeforeSubscribeByGoodsId(Long goodsId) {
|
|
public void alertBeforeSubscribeByGoodsId(Long goodsId) {
|
|
|
DateTime now = DateTime.now();
|
|
DateTime now = DateTime.now();
|
|
@@ -76,22 +76,23 @@ public class GoodsSubscribeAlertServiceImpl implements GoodsSubscribeAlertServic
|
|
|
//微信用户
|
|
//微信用户
|
|
|
if (StrUtil.isNotBlank(user.getUnionid())) {
|
|
if (StrUtil.isNotBlank(user.getUnionid())) {
|
|
|
//发送微信通知模板
|
|
//发送微信通知模板
|
|
|
- templateCommonService.sendUserSubscribeAlertMsg(user, String.format(Constant.GOODS_SUBSCRIBE_ALERT_WX_MSG, goodsDon.getTitle()));
|
|
|
|
|
|
|
+ Boolean success = templateCommonService.sendUserSubscribeAlertMsg(user, String.format(Constant.GOODS_SUBSCRIBE_ALERT_WX_MSG, goodsDon.getTitle()), goodsId);
|
|
|
|
|
+ if (!success) {
|
|
|
|
|
+ //失败后发送手机
|
|
|
|
|
+ sendPhoneNotifySubscribe(goodsDon.getTitle(), goodsId, userId);
|
|
|
|
|
+ }
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- //手机用户
|
|
|
|
|
- if (StrUtil.isNotBlank(user.getLoginPhone())) {
|
|
|
|
|
- String msg = String.format(Constant.GOODS_SUBSCRIBE_ALERT_MSG, goodsDon.getTitle(), goodsDon.getId());
|
|
|
|
|
- try {
|
|
|
|
|
- smsService.sendSmsToRelationUser(user.getId(), msg);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("发送商品订阅通知短信失败:{}", StringUtil.getErrorText(e));
|
|
|
|
|
|
|
+ //手机用户 或邮箱用户 首先用发手机号
|
|
|
|
|
+ Boolean success = sendPhoneNotifySubscribe(goodsDon.getTitle(), goodsId, userId);
|
|
|
|
|
+ if (!success) {
|
|
|
|
|
+ //失败 并且是邮箱用户
|
|
|
|
|
+ if (StrUtil.isNotBlank(user.getEmail())) {
|
|
|
|
|
+ //邮箱用户
|
|
|
|
|
+ String msg = String.format(Constant.GOODS_SUBSCRIBE_ALERT_EMAIL_MSG, goodsDon.getTitle(), goodsDon.getId());
|
|
|
|
|
+ mailService.sendGoodsSubscribeAlertEmail(msg, user.getEmail());
|
|
|
}
|
|
}
|
|
|
- continue;
|
|
|
|
|
}
|
|
}
|
|
|
- //邮箱用户
|
|
|
|
|
- String msg = String.format(Constant.GOODS_SUBSCRIBE_ALERT_EMAIL_MSG, goodsDon.getTitle(), goodsDon.getId());
|
|
|
|
|
- mailService.sendGoodsSubscribeAlertEmail(msg, user.getEmail());
|
|
|
|
|
}
|
|
}
|
|
|
} finally {
|
|
} finally {
|
|
|
if (redisService.hasKey(key)) {
|
|
if (redisService.hasKey(key)) {
|
|
@@ -127,22 +128,23 @@ public class GoodsSubscribeAlertServiceImpl implements GoodsSubscribeAlertServic
|
|
|
//微信用户
|
|
//微信用户
|
|
|
if (StrUtil.isNotBlank(user.getUnionid())) {
|
|
if (StrUtil.isNotBlank(user.getUnionid())) {
|
|
|
//发送微信通知模板
|
|
//发送微信通知模板
|
|
|
- templateCommonService.sendUserSubscribeAlertMsg(user, String.format(Constant.GOODS_SUBSCRIBE_ALERT_WX_MSG, title));
|
|
|
|
|
|
|
+ Boolean success = templateCommonService.sendUserSubscribeAlertMsg(user, String.format(Constant.GOODS_SUBSCRIBE_ALERT_WX_MSG, title), goodsDon.getId());
|
|
|
|
|
+ if (!success) {
|
|
|
|
|
+ //未成功 查看其他绑定信息
|
|
|
|
|
+ sendPhoneNotifySubscribe(title, goodsDon.getId(), userId);
|
|
|
|
|
+ }
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- //手机用户
|
|
|
|
|
- if (StrUtil.isNotBlank(user.getLoginPhone())) {
|
|
|
|
|
- String msg = String.format(Constant.GOODS_SUBSCRIBE_ALERT_MSG, title, goodsDon.getId());
|
|
|
|
|
- try {
|
|
|
|
|
- smsService.sendSmsToRelationUser(user.getId(), msg);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("发送商品规格订阅通知短信失败:{}", StringUtil.getErrorText(e));
|
|
|
|
|
|
|
+ //手机用户 或邮箱用户 首先用发手机号
|
|
|
|
|
+ Boolean success = sendPhoneNotifySubscribe(title, goodsDon.getId(), userId);
|
|
|
|
|
+ if (!success) {
|
|
|
|
|
+ //失败 并且是邮箱用户
|
|
|
|
|
+ if (StrUtil.isNotBlank(user.getEmail())) {
|
|
|
|
|
+ //邮箱用户
|
|
|
|
|
+ String msg = String.format(Constant.GOODS_SUBSCRIBE_ALERT_EMAIL_MSG, title, goodsDon.getId());
|
|
|
|
|
+ mailService.sendGoodsSubscribeAlertEmail(msg, user.getEmail());
|
|
|
}
|
|
}
|
|
|
- continue;
|
|
|
|
|
}
|
|
}
|
|
|
- //邮箱用户
|
|
|
|
|
- String msg = String.format(Constant.GOODS_SUBSCRIBE_ALERT_EMAIL_MSG, title, goodsDon.getId());
|
|
|
|
|
- mailService.sendGoodsSubscribeAlertEmail(msg, user.getEmail());
|
|
|
|
|
}
|
|
}
|
|
|
} finally {
|
|
} finally {
|
|
|
if (redisService.hasKey(key)) {
|
|
if (redisService.hasKey(key)) {
|
|
@@ -150,4 +152,15 @@ public class GoodsSubscribeAlertServiceImpl implements GoodsSubscribeAlertServic
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public Boolean sendPhoneNotifySubscribe(String title, Long goodsId, Long userId) {
|
|
|
|
|
+ String msg = String.format(Constant.GOODS_SUBSCRIBE_ALERT_MSG, title, goodsId);
|
|
|
|
|
+ try {
|
|
|
|
|
+ smsService.sendSmsToRelationUser(userId, msg);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("发送商品订阅通知短信失败:{}", StringUtil.getErrorText(e));
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|