|
@@ -1,5 +1,6 @@
|
|
|
package com.caimei365.user.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.caimei365.user.components.CommonService;
|
|
|
import com.caimei365.user.components.RedisService;
|
|
|
import com.caimei365.user.components.WeChatService;
|
|
@@ -10,13 +11,11 @@ import com.caimei365.user.model.dto.*;
|
|
|
import com.caimei365.user.model.po.*;
|
|
|
import com.caimei365.user.model.vo.*;
|
|
|
import com.caimei365.user.service.RegisterService;
|
|
|
-import com.caimei365.user.utils.AliyunSmsUtil;
|
|
|
-import com.caimei365.user.utils.CodeUtil;
|
|
|
-import com.caimei365.user.utils.Md5Util;
|
|
|
-import com.caimei365.user.utils.ValidateUtil;
|
|
|
+import com.caimei365.user.utils.*;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -25,9 +24,10 @@ import javax.annotation.Resource;
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.Calendar;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
* Description
|
|
@@ -39,6 +39,8 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class RegisterServiceImpl implements RegisterService {
|
|
|
|
|
|
+ @Value("${spring.cloud.config.profile}")
|
|
|
+ private String profile;
|
|
|
@Resource
|
|
|
private SuperVipMapper vipMapper;
|
|
|
@Resource
|
|
@@ -55,6 +57,8 @@ public class RegisterServiceImpl implements RegisterService {
|
|
|
private SellerMapper sellerMapper;
|
|
|
@Resource
|
|
|
private ToolsFeign smsFeign;
|
|
|
+ @Resource
|
|
|
+ private MessagePushMapper messagePushMapper;
|
|
|
|
|
|
/**
|
|
|
* 检查账号可以注册
|
|
@@ -1115,13 +1119,15 @@ public class RegisterServiceImpl implements RegisterService {
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
if (repayFlag == 0) {
|
|
|
SuperVipPo superVip = new SuperVipPo();
|
|
|
- beginTime = new Date();
|
|
|
+ //当天0点到期时间
|
|
|
+ beginTime = DateUtil.getNowTime();
|
|
|
superVip.setPrice(pac.getPrice());
|
|
|
superVip.setPackageId(packageId);
|
|
|
superVip.setBeginTime(beginTime);
|
|
|
superVip.setUpdateTime(beginTime);
|
|
|
superVip.setDelFlag(0);
|
|
|
superVip.setUserId(userId);
|
|
|
+ //计算存svip表的到期时间
|
|
|
cal.setTime(beginTime);
|
|
|
Integer userPackageTime = vipMapper.findUserPackageTime(packageId);
|
|
|
cal.add(Calendar.MONTH, userPackageTime);
|
|
@@ -1131,13 +1137,14 @@ public class RegisterServiceImpl implements RegisterService {
|
|
|
//购买记录表加数据
|
|
|
superVip.setPayStatus(1);
|
|
|
superVip.setPayWay(4);
|
|
|
- setHistory(superVip);
|
|
|
+ //新会员开通,开始时间作为历史表的本次购买套餐的开始时间
|
|
|
+ setHistory(superVip, beginTime);
|
|
|
//发短信
|
|
|
message = "【采美365】恭喜您成功开通采美平台超级会员,为期" + userPackageTime + "个月,快戳采美网站链接 www.caimei365.com 或微信搜索“采美采购商城”小程序登录采美平台畅享会员特权吧。关注公众号“采美365网”可获取更多优惠和精彩资讯。";
|
|
|
String mobile = vipMapper.findMobile(userId);
|
|
|
if (mobile != null && mobile != "") {
|
|
|
try {
|
|
|
- smsFeign.getSendSms(mobile, message);
|
|
|
+ sendSms(2, mobile, message);
|
|
|
} catch (Exception e) {
|
|
|
log.error("短信发送异常" + e);
|
|
|
}
|
|
@@ -1158,13 +1165,14 @@ public class RegisterServiceImpl implements RegisterService {
|
|
|
//购买记录表加数据
|
|
|
superVip.setPayStatus(1);
|
|
|
superVip.setPayWay(4);
|
|
|
- setHistory(superVip);
|
|
|
+ //需费时历史记录开始时间为svipuser改变前的终止时间
|
|
|
+ setHistory(superVip, beginTime);
|
|
|
//发短信
|
|
|
message = "【采美365】恭喜您成功续费采美平台超级会员,为期" + userPackageTime + "个月,快戳采美网站链接 www.caimei365.com 或微信搜索“采美采购商城”小程序登录采美平台畅享会员特权吧。关注公众号“采美365网”可获取更多优惠和精彩资讯。";
|
|
|
String mobile = vipMapper.findMobile(userId);
|
|
|
if (mobile != null && mobile != "") {
|
|
|
try {
|
|
|
- smsFeign.getSendSms(mobile, message);
|
|
|
+ sendSms(2, mobile, message);
|
|
|
} catch (Exception e) {
|
|
|
log.error("短信发送异常" + e);
|
|
|
}
|
|
@@ -1176,7 +1184,8 @@ public class RegisterServiceImpl implements RegisterService {
|
|
|
superVip.setPackageId(packageId);
|
|
|
superVip.setPrice(pac.getPrice());
|
|
|
//重设生效起始时间
|
|
|
- beginTime = new Date();
|
|
|
+ beginTime = DateUtil.getNowTime();
|
|
|
+ ;
|
|
|
superVip.setBeginTime(beginTime);
|
|
|
//到期时间现在时间+套餐时间
|
|
|
cal.setTime(beginTime);
|
|
@@ -1188,13 +1197,14 @@ public class RegisterServiceImpl implements RegisterService {
|
|
|
//购买记录表加数据
|
|
|
superVip.setPayStatus(1);
|
|
|
superVip.setPayWay(4);
|
|
|
- setHistory(superVip);
|
|
|
+ //过期再买,历史表开始时间是现在时间/支付时间
|
|
|
+ setHistory(superVip, beginTime);
|
|
|
//发短信
|
|
|
message = "【采美365】恭喜您成功续费采美平台超级会员,为期" + userPackageTime + "个月,快戳采美网站链接 www.caimei365.com 或微信搜索“采美采购商城”小程序登录采美平台畅享会员特权吧。关注公众号“采美365网”可获取更多优惠和精彩资讯。";
|
|
|
String mobile = vipMapper.findMobile(userId);
|
|
|
if (mobile != null && mobile != "") {
|
|
|
try {
|
|
|
- smsFeign.getSendSms(mobile, message);
|
|
|
+ sendSms(2, mobile, message);
|
|
|
} catch (Exception e) {
|
|
|
log.error("短信发送异常" + e);
|
|
|
}
|
|
@@ -1206,7 +1216,7 @@ public class RegisterServiceImpl implements RegisterService {
|
|
|
/**
|
|
|
* 增加sviphistory记录
|
|
|
*/
|
|
|
- private void setHistory(SuperVipPo vip) {
|
|
|
+ private void setHistory(SuperVipPo vip, Date beginTime) {
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
VipPayHistoryPo payHistory = new VipPayHistoryPo();
|
|
|
VipPackage pac = vipMapper.findUserPackage(vip.getPackageId());
|
|
@@ -1217,11 +1227,44 @@ public class RegisterServiceImpl implements RegisterService {
|
|
|
payHistory.setPayWay(vip.getPayWay());
|
|
|
payHistory.setPackageId(vip.getPackageId());
|
|
|
payHistory.setPrice(0.00);
|
|
|
- payHistory.setBeginTime(vip.getUpdateTime());
|
|
|
- cal.setTime(vip.getUpdateTime());
|
|
|
+ //开始时间是上一次的结束时间,结束时间是cal+这次买的时间
|
|
|
+ payHistory.setBeginTime(beginTime);
|
|
|
+ cal.setTime(beginTime);
|
|
|
cal.add(Calendar.MONTH, pac.getDuration());
|
|
|
payHistory.setEndTime(cal.getTime());
|
|
|
vipMapper.addPayHistory(payHistory);
|
|
|
}
|
|
|
+
|
|
|
+ public boolean sendSms(int markId, String mobile, String message) {
|
|
|
+ AtomicBoolean returnValue = new AtomicBoolean(false);
|
|
|
+ try {
|
|
|
+ //测试环境手机号允许发短信
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ list.add("15917362709");
|
|
|
+ list.add("15814011616");
|
|
|
+ list.add("13100721916");
|
|
|
+ list.add("15113936829");
|
|
|
+ if ("prod".equals(profile) || list.contains(mobile)) {
|
|
|
+ if (StringUtils.isNotBlank(mobile) && mobile.length() == 11) {
|
|
|
+ String regex = "^(1[3-9]\\d{9}$)";
|
|
|
+ Pattern pattern = Pattern.compile(regex);
|
|
|
+ Matcher matcher = pattern.matcher(mobile);
|
|
|
+ if (matcher.matches()) {
|
|
|
+ // 调用 ToolsFeign 发送短信
|
|
|
+ String jsonStr = smsFeign.getSendSms(mobile, message);
|
|
|
+ JSONObject parseObject = JSONObject.parseObject(jsonStr);
|
|
|
+ if (0 == parseObject.getInteger("code")) {
|
|
|
+ // 保存短信发送条数+count
|
|
|
+ messagePushMapper.updateSmsSendCount(markId, 1);
|
|
|
+ returnValue.set(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("短信推送异常:", e);
|
|
|
+ }
|
|
|
+ return returnValue.get();
|
|
|
+ }
|
|
|
}
|
|
|
|