Sfoglia il codice sorgente

1,短信统计/限制
2,超级会员历史记录bugfix

zhijiezhao 3 anni fa
parent
commit
cbfbd7eb7d

+ 32 - 0
src/main/java/com/caimei365/user/mapper/MessagePushMapper.java

@@ -0,0 +1,32 @@
+package com.caimei365.user.mapper;
+
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/7/15
+ */
+@Mapper
+public interface MessagePushMapper {
+    /**
+     * 查询短链接是否存在
+     */
+    Integer findIdByShortLink(String shortLink);
+    /**
+     * 保存短链接信息
+     *
+     * @param markId    短信类型
+     * @param shortLink 短链接
+     * @param url       跳转地址
+     */
+    void insertShortLink(int markId, String shortLink, String url);
+    /**
+     * 保存短信发送条数+count
+     *
+     * @param markId 短信类型
+     * @param count  增加条数
+     */
+    void updateSmsSendCount(int markId, int count);
+}

+ 6 - 0
src/main/java/com/caimei365/user/mapper/SuperVipMapper.java

@@ -151,5 +151,11 @@ public interface SuperVipMapper {
      */
     Integer getVipHistoryId(Integer userId, Integer packageId);
 
+    /**
+     * 查是否有已使用的超级会员优惠券
+     * @param userId
+     * @param useTime
+     * @return
+     */
     List<Integer> findCouponUse(@Param("userId") Integer userId,@Param("useTime")String useTime);
 }

+ 60 - 17
src/main/java/com/caimei365/user/service/impl/RegisterServiceImpl.java

@@ -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+这次买的时间
+        payHistory.setBeginTime(beginTime);
         cal.setTime(vip.getUpdateTime());
         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();
+    }
 }
 

+ 28 - 6
src/main/java/com/caimei365/user/utils/DateUtil.java

@@ -26,7 +26,7 @@ public class DateUtil {
     }
 
     /*
-    输入日期字符串,返回月底0点
+    输入日期字符串,返回下个月1号0点
     */
     public static Date getMaxDay(String month) {
         try {
@@ -34,6 +34,7 @@ public class DateUtil {
             calendar = Calendar.getInstance();
             calendar.setTime(nowDate);
             calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
+            calendar.add(Calendar.DAY_OF_MONTH,1);
             return calendar.getTime();
         } catch (ParseException e) {
             e.printStackTrace();
@@ -43,18 +44,39 @@ public class DateUtil {
 
     /**
      * 返回现在时间yyyy-mm格式
+     *
      * @return
      */
-    public static String getNowMonth(){
+    public static String getNowMonth() {
         Date date = new Date();
         String format = new SimpleDateFormat("yyyy-MM").format(date);
         return format;
     }
-//    public static void main(String[] args) throws ParseException {
-//        String month = "2020-02";
-//        System.out.println(getMinDateMonth(month));
-//        System.out.println(getMaxDateMonth(month));
+
+//    public static void main(String[] args) {
+//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+//        Date date = new Date();
+//        Date nowTime = getNowTime();
+//        date=nowTime;
+//        calendar.setTime(date);
+//        calendar.add(Calendar.DAY_OF_MONTH,6);
+//        String up = format.format(calendar.getTime());
+//        System.out.println("原来时间"+format.format(date));
+//        System.out.println("================================");
+//        System.out.println(up);
+//        System.out.println("==================");
+//        System.out.println(format.format(nowTime));
 //    }
 
+    /**
+     * 获取现在时间的00:00
+     *
+     * @return
+     */
+    public static Date getNowTime() {
+        Calendar cal = Calendar.getInstance();
+        cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
+        return cal.getTime();
+    }
 
 }

+ 14 - 0
src/main/resources/mapper/MessagePushMapper.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.caimei365.user.mapper.MessagePushMapper">
+    <insert id="insertShortLink">
+        INSERT INTO cm_short_link (markId, shortLink, jumpLink, createTime)
+        VALUES (#{markId}, #{shortLink}, #{url},NOW())
+    </insert>
+    <update id="updateSmsSendCount">
+        UPDATE cm_sms_statistics SET sendNum = (sendNum + #{count}) WHERE markId = #{markId}
+    </update>
+    <select id="findIdByShortLink" resultType="java.lang.Integer">
+        SELECT id FROM cm_short_link WHERE shortLink = #{shortLink}
+    </select>
+</mapper>

+ 1 - 1
src/main/resources/mapper/SuperVipMapper.xml

@@ -146,7 +146,7 @@
     <select id="findCouponUse" resultType="java.lang.Integer">
         select ccb.couponId from cm_coupon_club ccb
         inner join cm_svip_coupon cs ON cs.couponId = ccb.couponId
-        where ccb.userId=#{userId} and ccb.status=2
+        where ccb.userId=#{userId} and ccb.status=2 AND ccb.delFlag=0
         <if test="useTime != null and useTime !=''">
             and cs.useTime=#{useTime}
         </if>