huangzhiguo 2 سال پیش
والد
کامیت
1cae58f5e0

+ 6 - 0
pom.xml

@@ -92,6 +92,12 @@
             <artifactId>caimei-common</artifactId>
             <version>0.0.1-SNAPSHOT</version>
         </dependency>
+
+        <dependency>
+            <groupId>com.ckfinder</groupId>
+            <artifactId>ckfinder</artifactId>
+            <version>2.3</version>
+        </dependency>
     </dependencies>
 
     <profiles>

+ 184 - 0
src/main/java/com/caimei365/manager/config/thinkgem/Global.java

@@ -0,0 +1,184 @@
+package com.caimei365.manager.config.thinkgem;
+
+import com.caimei.utils.StringUtils;
+import com.caimei365.manager.config.thinkgem.utils.PropertiesLoader;
+import com.ckfinder.connector.ServletContextFactory;
+import com.google.common.collect.Maps;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.io.DefaultResourceLoader;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * Description
+ * 全局配置类
+ * @author : Charles
+ * @date : 2023/4/10
+ */
+public class Global {
+    private Logger logger = LoggerFactory.getLogger(getClass());
+    /**
+     * 当前对象实例
+     */
+    private static Global global = new Global();
+
+    /**
+     * 保存全局属性值
+     */
+    private static Map<String, String> map = Maps.newHashMap();
+
+    /**
+     * 属性文件加载对象
+     */
+    private static PropertiesLoader loader = new PropertiesLoader("caimei.properties");
+
+    /**
+     * 显示/隐藏
+     */
+    public static final String SHOW = "1";
+    public static final String HIDE = "0";
+
+    /**
+     * 是/否
+     */
+    public static final String YES = "1";
+    public static final String NO = "0";
+
+    /**
+     * 对/错
+     */
+    public static final String TRUE = "true";
+    public static final String FALSE = "false";
+
+    /**
+     * 上传文件基础虚拟路径
+     */
+    public static final String USERFILES_BASE_URL = "userfiles/";
+
+    /**
+     * 获取当前对象实例
+     */
+    public static Global getInstance() {
+        return global;
+    }
+
+    /**
+     * 获取配置
+     * @see ${fns:getConfig('adminPath')}
+     */
+    public static String getConfig(String key) {
+        String value = map.get(key);
+        if (value == null){
+            value = loader.getProperty(key);
+            map.put(key, value != null ? value : StringUtils.EMPTY);
+        }
+        return value;
+    }
+
+    /**
+     * 获取管理端根路径
+     */
+    public static String getAdminPath() {
+        return getConfig("adminPath");
+    }
+
+    /**
+     * 获取前端根路径
+     */
+    public static String getFrontPath() {
+        return getConfig("frontPath");
+    }
+
+    /**
+     * 获取URL后缀
+     */
+    public static String getUrlSuffix() {
+        return getConfig("urlSuffix");
+    }
+
+    /**
+     * 是否是演示模式,演示模式下不能修改用户、角色、密码、菜单、授权
+     */
+    public static Boolean isDemoMode() {
+        String dm = getConfig("demoMode");
+        return "true".equals(dm) || "1".equals(dm);
+    }
+
+    /**
+     * 在修改系统用户和角色时是否同步到Activiti
+     */
+//	public static Boolean isSynActivitiIndetity() {
+//		String dm = getConfig("activiti.isSynActivitiIndetity");
+//		return "true".equals(dm) || "1".equals(dm);
+//	}
+
+    /**
+     * 页面获取常量
+     * @see ${fns:getConst('YES')}
+     */
+    public static Object getConst(String field) {
+        try {
+            return Global.class.getField(field).get(null);
+        } catch (Exception e) {
+            // 异常代表无配置,这里什么也不做
+        }
+        return null;
+    }
+
+    /**
+     * 获取上传文件的根目录
+     * @return
+     */
+    public static String getUserfilesBaseDir() {
+        String dir = getConfig("userfiles.basedir");
+        if (StringUtils.isBlank(dir)){
+            try {
+                dir = ServletContextFactory.getServletContext().getRealPath("/");
+                System.out.println("=====================dir2"+dir);
+            } catch (Exception e) {
+                return "";
+            }
+        }
+        if(!dir.endsWith("/")) {
+            dir += "/";
+        }
+//		System.out.println("userfiles.basedir: " + dir);
+        return dir;
+    }
+
+    /**
+     * 获取工程路径
+     * @return
+     */
+    public static String getProjectPath(){
+        // 如果配置了工程路径,则直接返回,否则自动获取。
+        String projectPath = Global.getConfig("projectPath");
+        if (StringUtils.isNotBlank(projectPath)){
+            return projectPath;
+        }
+        try {
+            File file = new DefaultResourceLoader().getResource("").getFile();
+            if (file != null){
+                while(true){
+                    File f = new File(file.getPath() + File.separator + "src" + File.separator + "main");
+                    if (f == null || f.exists()){
+                        break;
+                    }
+                    if (file.getParentFile() != null){
+                        file = file.getParentFile();
+                    }else{
+                        break;
+                    }
+                }
+                projectPath = file.toString();
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return projectPath;
+    }
+
+}

+ 150 - 0
src/main/java/com/caimei365/manager/config/thinkgem/utils/PropertiesLoader.java

@@ -0,0 +1,150 @@
+package com.caimei365.manager.config.thinkgem.utils;
+
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.io.DefaultResourceLoader;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.NoSuchElementException;
+import java.util.Properties;
+
+/**
+ * Description
+ * Properties文件载入工具类. 可载入多个properties文件, 相同的属性在最后载入的文件中的值将会覆盖之前的值,但以System的Property优先.
+ * @author : Charles
+ * @date : 2023/4/10
+ */
+public class PropertiesLoader {
+
+    private static Logger logger = LoggerFactory.getLogger(PropertiesLoader.class);
+
+    private static ResourceLoader resourceLoader = new DefaultResourceLoader();
+
+    private final Properties properties;
+
+    public PropertiesLoader(String... resourcesPaths) {
+        properties = loadProperties(resourcesPaths);
+    }
+
+    public Properties getProperties() {
+        return properties;
+    }
+
+    /**
+     * 取出Property,但以System的Property优先,取不到返回空字符串.
+     */
+    private String getValue(String key) {
+        String systemProperty = System.getProperty(key);
+        if (systemProperty != null) {
+            return systemProperty;
+        }
+        if (properties.containsKey(key)) {
+            return properties.getProperty(key);
+        }
+        return "";
+    }
+
+    /**
+     * 取出String类型的Property,但以System的Property优先,如果都为Null则抛出异常.
+     */
+    public String getProperty(String key) {
+        String value = getValue(key);
+        if (value == null) {
+            throw new NoSuchElementException();
+        }
+        return value;
+    }
+
+    /**
+     * 取出String类型的Property,但以System的Property优先.如果都为Null则返回Default值.
+     */
+    public String getProperty(String key, String defaultValue) {
+        String value = getValue(key);
+        return value != null ? value : defaultValue;
+    }
+
+    /**
+     * 取出Integer类型的Property,但以System的Property优先.如果都为Null或内容错误则抛出异常.
+     */
+    public Integer getInteger(String key) {
+        String value = getValue(key);
+        if (value == null) {
+            throw new NoSuchElementException();
+        }
+        return Integer.valueOf(value);
+    }
+
+    /**
+     * 取出Integer类型的Property,但以System的Property优先.如果都为Null则返回Default值,如果内容错误则抛出异常
+     */
+    public Integer getInteger(String key, Integer defaultValue) {
+        String value = getValue(key);
+        return value != null ? Integer.valueOf(value) : defaultValue;
+    }
+
+    /**
+     * 取出Double类型的Property,但以System的Property优先.如果都为Null或内容错误则抛出异常.
+     */
+    public Double getDouble(String key) {
+        String value = getValue(key);
+        if (value == null) {
+            throw new NoSuchElementException();
+        }
+        return Double.valueOf(value);
+    }
+
+    /**
+     * 取出Double类型的Property,但以System的Property优先.如果都为Null则返回Default值,如果内容错误则抛出异常
+     */
+    public Double getDouble(String key, Integer defaultValue) {
+        String value = getValue(key);
+        return value != null ? Double.valueOf(value) : defaultValue;
+    }
+
+    /**
+     * 取出Boolean类型的Property,但以System的Property优先.如果都为Null抛出异常,如果内容不是true/false则返回false.
+     */
+    public Boolean getBoolean(String key) {
+        String value = getValue(key);
+        if (value == null) {
+            throw new NoSuchElementException();
+        }
+        return Boolean.valueOf(value);
+    }
+
+    /**
+     * 取出Boolean类型的Property,但以System的Property优先.如果都为Null则返回Default值,如果内容不为true/false则返回false.
+     */
+    public Boolean getBoolean(String key, boolean defaultValue) {
+        String value = getValue(key);
+        return value != null ? Boolean.valueOf(value) : defaultValue;
+    }
+
+    /**
+     * 载入多个文件, 文件路径使用Spring Resource格式.
+     */
+    private Properties loadProperties(String... resourcesPaths) {
+        Properties props = new Properties();
+
+        for (String location : resourcesPaths) {
+
+//			logger.debug("Loading properties file from:" + location);
+
+            InputStream is = null;
+            try {
+                Resource resource = resourceLoader.getResource(location);
+                is = resource.getInputStream();
+                props.load(is);
+            } catch (IOException ex) {
+                logger.info("Could not load properties from path:" + location + ", " + ex.getMessage());
+            } finally {
+                IOUtils.closeQuietly(is);
+            }
+        }
+        return props;
+    }
+}

+ 38 - 0
src/main/java/com/caimei365/manager/controller/caimei/svip/CmSvipHistoryApi.java

@@ -1,12 +1,16 @@
 package com.caimei365.manager.controller.caimei.svip;
 
+import com.caimei.utils.StringUtils;
 import com.caimei365.manager.entity.PaginationVo;
 import com.caimei365.manager.entity.ResponseJson;
+import com.caimei365.manager.entity.caimei.CmUser;
+import com.caimei365.manager.entity.caimei.svip.CmSvipGive;
 import com.caimei365.manager.entity.caimei.svip.CmSvipHistory;
 import com.caimei365.manager.entity.caimei.svip.CmSvipPackage;
 import com.caimei365.manager.entity.caimei.svip.CmSvipProduct;
 import com.caimei365.manager.service.caimei.svip.CmSvipHistoryService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.*;
 
@@ -37,6 +41,40 @@ public class CmSvipHistoryApi {
         return historyService.memberList(vip, pageNum, pageSize);
     }
 
+    /**
+     * 获取机构信息
+     * @param clubId
+     * @param name
+     * @param shortName
+     * @param pageNum
+     * @param pageSize
+     * @return
+     */
+    @GetMapping("/findClubList")
+    public ResponseJson<PaginationVo<CmUser>> findClubList(Integer clubId, String name, String shortName,
+                                                            @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                                            @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
+
+        return historyService.findClubList(clubId, name, shortName, pageNum, pageSize);
+    }
+
+    @PostMapping("/saveSvip")
+    public ResponseJson save(CmSvipGive cmSvipGive) throws Exception {
+        if (StringUtils.isBlank(cmSvipGive.getUserId()) || null == cmSvipGive.getMonth() || null == cmSvipGive.getClubId()) {
+            return ResponseJson.error("参数错误或缺少参数", null);
+        }
+        return historyService.saveGive(cmSvipGive);
+    }
+
+    @GetMapping("/findHistory")
+    public ResponseJson<PaginationVo<CmSvipHistory>> findHistory(CmSvipHistory cmSvipHistory,
+                                                                 @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                                                 @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
+        if (null == cmSvipHistory.getUserId()) {
+            return ResponseJson.error(-1,"",null);
+        }
+        return historyService.findHistory(cmSvipHistory, pageNum, pageSize);
+    }
     /**
      * 超级会员商品列表
      * @param cmSvipProduct

+ 21 - 0
src/main/java/com/caimei365/manager/dao/newOrderDao.java

@@ -0,0 +1,21 @@
+package com.caimei365.manager.dao;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2023/4/10
+ */
+@Mapper
+public interface newOrderDao {
+    /**
+     * 保存短信发送条数
+     *
+     * @param markId
+     * @param num
+     */
+    void updateSendNum(@Param("markId") int markId, @Param("num") int num);
+}

+ 51 - 0
src/main/java/com/caimei365/manager/dao/svip/CmSvipHistoryDao.java

@@ -1,5 +1,7 @@
 package com.caimei365.manager.dao.svip;
 
+import com.caimei365.manager.entity.caimei.CmUser;
+import com.caimei365.manager.entity.caimei.MessageCenter;
 import com.caimei365.manager.entity.caimei.svip.CmSku;
 import com.caimei365.manager.entity.caimei.svip.CmSvipHistory;
 import com.caimei365.manager.entity.caimei.svip.CmSvipPackage;
@@ -32,6 +34,55 @@ public interface CmSvipHistoryDao {
      */
     CmSvipHistory findEndTime(Long userId);
 
+    /**
+     * 机构信息
+     * @param clubId
+     * @param name
+     * @param shortName
+     * @return
+     */
+    List<CmUser> findUserList(@Param("clubId") Integer clubId, @Param("name") String name, @Param("shortName") String shortName);
+
+    /**
+     * 获取用户超级会员数据
+     * @param userId
+     * @return
+     */
+    CmSvipHistory findVipUser(String userId);
+
+    /**
+     * 添加消息
+     * @param messageCenter
+     */
+    void addMessageCenter(MessageCenter messageCenter);
+
+    void insertHistory(CmSvipHistory cmSvipHistory);
+
+    void updateVip(CmSvipHistory cmSvipHistory);
+
+    void giveVip(CmSvipHistory cmSvipHistory);
+
+    /**
+     * 获取购买记录
+     * @param cmSvipHistory
+     * @return
+     */
+    List<CmSvipHistory> findHistory(CmSvipHistory cmSvipHistory);
+
+    /**
+     * 状态
+     * @param packageId
+     * @return
+     */
+    Integer findDuration(Integer packageId);
+
+    /**
+     * 获取时间
+     * @param id
+     * @return
+     */
+    String findMonth(String id);
+
     /**
      * 超级会员优惠商品
      * @param svipProduct

+ 47 - 0
src/main/java/com/caimei365/manager/entity/caimei/CmUser.java

@@ -0,0 +1,47 @@
+package com.caimei365.manager.entity.caimei;
+
+import lombok.Data;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2023/4/10
+ */
+@Data
+public class CmUser {
+    /**
+     * userId
+     */
+    private Integer userId;
+    /**
+     * 用户名
+     */
+    private String userName;
+    /**
+     * 会所Id
+     */
+    private String clubId;
+
+
+    /**
+     * 用户身份
+     */
+    private Integer userIdentity;
+    /**
+     * 企业绑定手机号
+     */
+    private String contractMobile;
+    /**
+     * 机构名称
+     */
+    private String name;
+    /**
+     * 机构简称
+     */
+    private String shortName;
+    /**
+     * 机构联系人
+     */
+    private String linkMan;
+}

+ 94 - 0
src/main/java/com/caimei365/manager/entity/caimei/MessageCenter.java

@@ -0,0 +1,94 @@
+package com.caimei365.manager.entity.caimei;
+
+import lombok.Data;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2023/4/10
+ */
+@Data
+public class MessageCenter {
+    /**
+     *消息id
+     */
+    private String id;
+    /**
+     供应商id
+     */
+    private Integer shopId;
+    /**
+     机构id
+     */
+    private Integer clubId;
+    /**
+     * 订单ID
+     */
+    private Integer orderId;
+    /**
+     用户类型1.机构2.供应商
+     */
+    private Integer userType;
+    /**
+     消息类型1.交易物流2.账户通知3.服务通知4.优惠促销
+     */
+    private Integer messageType;
+    /**
+     * 消息内容
+     */
+    private String content;
+    /**
+     * 操作完成时间
+     */
+    private String time;
+    /**
+     *账户通知类型 1.注册成功通知 2.购买超级会员成功 3.超级会员到期提醒 4.超级会员到期提醒 5.升级资质机构成功 6.升级资质机构失败 7.成为机构运营人员通知
+     */
+    private Integer accountType;
+    /**
+     * 优惠券类型 1.优惠券待领取通知 2.优惠券过期通知
+     */
+    private Integer couponType;
+    /**
+     * 优惠券金额
+     */
+    private Double couponFee;
+    /**
+     * 主图
+     */
+    private String mainImage;
+    /**
+     * 是否能走线上支付 0可以 1不可以 只能线下
+     */
+    private Integer onlinePayFlag;
+    /**
+     * 商品名称
+     */
+    private String productName;
+    /**
+     *供应商消息类型 1,账号审核通知,2.成为公司运营人员通知,3.商品上架审核通知,4.新品展示审核通知,5.上架费到期通知 6.商品资质到期通知
+     */
+    private Integer shopMessType;
+    /**
+     *供应商服务消息类型 1.上架费
+     */
+    private Integer shopTieredType;
+    /**
+     * 交易物流1.下单成功通知  2.订单支付完成 3.退款/货成功通知 4.订单取消通知 5.订单发货通知 6.自动收货通知
+     */
+    private Integer orderMessageType;
+    /**
+     * 0.未读 , 1.已读
+     */
+    private Integer saved;
+    /**
+     * 优惠券类型 1.优惠券待领取通知 2.优惠券过期通知
+     */
+    private Integer couponMessageType;
+
+    /**
+     *商品ID
+     */
+    private Integer productId;
+}

+ 30 - 0
src/main/java/com/caimei365/manager/entity/caimei/svip/CmSvipGive.java

@@ -0,0 +1,30 @@
+package com.caimei365.manager.entity.caimei.svip;
+
+import lombok.Data;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2023/4/10
+ */
+@Data
+public class CmSvipGive {
+    /**
+     * 赠送套餐月份数
+     */
+    private Integer month;
+    /**
+     * 机构id
+     */
+    private Integer clubId;
+
+    /**
+     * 用户id
+     */
+    private String userId;
+    /**
+     * 机构手机号
+     */
+    private String contractMobile;
+}

+ 7 - 3
src/main/java/com/caimei365/manager/entity/caimei/svip/CmSvipHistory.java

@@ -14,6 +14,7 @@ import java.util.Date;
 @Data
 public class CmSvipHistory {
 
+    private String id;
     /**
      * 用户ID
      */
@@ -25,11 +26,13 @@ public class CmSvipHistory {
     /**
      * 生效时间
      */
-    private String beginTime;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date beginTime;
     /**
      * 到期时间
      */
-    private String endTime;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date endTime;
     private String updateTime;
     /**
      * 用户付款方式:1线上,2线下,3余额抵扣,4采美豆抵扣
@@ -50,7 +53,8 @@ public class CmSvipHistory {
     /**
      * 购买时间
      */
-    private String payTime;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date payTime;
     /**
      * jsp页面虚拟字段
      */

+ 66 - 0
src/main/java/com/caimei365/manager/service/SendSmsService.java

@@ -0,0 +1,66 @@
+package com.caimei365.manager.service;
+
+import com.alibaba.fastjson.JSONObject;
+import com.caimei.utils.HttpRequest;
+import com.caimei.utils.StringUtils;
+import com.caimei365.manager.config.thinkgem.Global;
+import com.caimei365.manager.dao.newOrderDao;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2023/4/10
+ */
+@Slf4j
+@Service
+public class SendSmsService {
+
+    @Autowired private newOrderDao orderDao;
+
+    public boolean getSendSms(int markId, String mobile, String content) throws Exception {
+        String config = Global.getConfig("cm.config");
+        //测试环境手机号允许发短信
+        List<String> list = new ArrayList<>();
+        list.add("15917362709");
+        list.add("15814011616");
+        list.add("13100721916");
+        list.add("15113936829");
+        list.add("18175515644");
+        list.add("18476937515");
+        if (config.equals("product") || 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()) {
+                    Map<String, Object> map = new HashMap<>(2);
+                    map.put("content", content);
+                    map.put("mobile", mobile);
+                    String coreServer = Global.getConfig("caimei.core");
+                    String url = coreServer + "/tools/sms/send";
+                    String result = HttpRequest.sendPost(url, map);
+                    JSONObject parseObject = JSONObject.parseObject(result);
+                    Integer code = parseObject.getInteger("code");
+                    if (code != 0) {
+                        log.info("短信发送失败,手机号>>>>" + mobile);
+                    } else {
+                        orderDao.updateSendNum(markId, 1);
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+}

+ 27 - 0
src/main/java/com/caimei365/manager/service/caimei/svip/CmSvipHistoryService.java

@@ -2,6 +2,8 @@ package com.caimei365.manager.service.caimei.svip;
 
 import com.caimei365.manager.entity.PaginationVo;
 import com.caimei365.manager.entity.ResponseJson;
+import com.caimei365.manager.entity.caimei.CmUser;
+import com.caimei365.manager.entity.caimei.svip.CmSvipGive;
 import com.caimei365.manager.entity.caimei.svip.CmSvipHistory;
 import com.caimei365.manager.entity.caimei.svip.CmSvipPackage;
 import com.caimei365.manager.entity.caimei.svip.CmSvipProduct;
@@ -23,6 +25,31 @@ public interface CmSvipHistoryService {
      */
     ResponseJson<PaginationVo<CmSvipHistory>> memberList(CmSvipHistory vip, Integer pageNum, Integer pageSize);
 
+    /**
+     * 获取机构信息
+     * @param clubId
+     * @param name
+     * @param shortName
+     * @param pageNum
+     * @param pageSize
+     * @return
+     */
+    ResponseJson<PaginationVo<CmUser>> findClubList(Integer clubId, String name, String shortName, Integer pageNum, Integer pageSize);
+
+    /**
+     * 赠送超级会员
+     * @param cmSvipGive
+     * @return
+     */
+    ResponseJson saveGive(CmSvipGive cmSvipGive) throws Exception ;
+
+    /**
+     * 获取购买记录
+     * @param cmSvipHistory
+     * @return
+     */
+    ResponseJson<PaginationVo<CmSvipHistory>> findHistory(CmSvipHistory cmSvipHistory, int pageNum, int pageSize);
+
     /**
      *超级会员优惠商品
      * @param svipProduct

+ 131 - 5
src/main/java/com/caimei365/manager/service/caimei/svip/impl/CmSvipHistoryServiceImpl.java

@@ -5,17 +5,20 @@ import com.caimei.utils.StringUtil;
 import com.caimei365.manager.dao.svip.CmSvipHistoryDao;
 import com.caimei365.manager.entity.PaginationVo;
 import com.caimei365.manager.entity.ResponseJson;
-import com.caimei365.manager.entity.caimei.svip.CmSku;
-import com.caimei365.manager.entity.caimei.svip.CmSvipHistory;
-import com.caimei365.manager.entity.caimei.svip.CmSvipPackage;
-import com.caimei365.manager.entity.caimei.svip.CmSvipProduct;
+import com.caimei365.manager.entity.caimei.CmUser;
+import com.caimei365.manager.entity.caimei.MessageCenter;
+import com.caimei365.manager.entity.caimei.svip.*;
+import com.caimei365.manager.service.SendSmsService;
 import com.caimei365.manager.service.caimei.svip.CmSvipHistoryService;
 import com.github.pagehelper.PageHelper;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.math.BigDecimal;
-import java.util.List;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 /**
  * Description
@@ -23,10 +26,12 @@ import java.util.List;
  * @author : Charles
  * @date : 2023/4/7
  */
+@Slf4j
 @Service
 public class CmSvipHistoryServiceImpl implements CmSvipHistoryService {
 
     @Autowired private CmSvipHistoryDao historyDao;
+    @Resource private SendSmsService sendSmsService;
 
     @Override
     public ResponseJson<PaginationVo<CmSvipHistory>> memberList(CmSvipHistory vip, Integer pageNum, Integer pageSize) {
@@ -44,6 +49,127 @@ public class CmSvipHistoryServiceImpl implements CmSvipHistoryService {
         return ResponseJson.success(page);
     }
 
+    @Override
+    public ResponseJson<PaginationVo<CmUser>> findClubList(Integer clubId, String name, String shortName, Integer pageNum, Integer pageSize) {
+        PageHelper.startPage(pageNum, pageSize);
+        List<CmUser> clubList = historyDao.findUserList(clubId, name, shortName);
+        PaginationVo<CmUser> page = new PaginationVo<>(clubList);
+        return ResponseJson.success(page);
+    }
+
+    @Override
+    public ResponseJson saveGive(CmSvipGive cmSvipGive) throws Exception {
+        //cm_svip_user加用户,cm_svip_history插入一条记录
+        CmSvipHistory cmSvipHistory = new CmSvipHistory();
+        Date now = new Date();
+        Calendar c = Calendar.getInstance();
+        c.setTime(now);
+        c.add(Calendar.MONTH, cmSvipGive.getMonth());
+        Date endTime = c.getTime();
+        cmSvipHistory.setBeginTime(now);
+        cmSvipHistory.setEndTime(endTime);
+        cmSvipHistory.setUserId(Long.valueOf(cmSvipGive.getUserId()));
+        // 5 系统赠送
+        cmSvipHistory.setPayWay("5");
+        cmSvipHistory.setPayTime(now);
+        CmSvipHistory user = historyDao.findVipUser(cmSvipGive.getUserId());
+//        Integer clubID = messageCenterDao.clubIdCule(Integer.parseInt(cmSvipGive.getUserId()));
+        Date date=new Date();
+        String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
+        MessageCenter messageCenter = new MessageCenter();
+        messageCenter.setShopId(null);
+        messageCenter.setClubId(cmSvipGive.getClubId());
+        messageCenter.setUserType(1);
+        messageCenter.setMessageType(2);
+        messageCenter.setAccountType(4);
+        messageCenter.setContent(cmSvipGive.getMonth().toString()+"个月");
+        messageCenter.setTime(curDateStr);
+        historyDao.addMessageCenter(messageCenter);
+
+//        String bindMobile= messageCenterDao.contractMobile(cmSvipGive.getUserId());
+
+        String content = "【采美365】您已获得采美平台赠送的"+cmSvipGive.getMonth()+"个月超级会员服务,快戳采美网站链接www.caimei365.com/M2Tr98CG 或微信搜索“采美采购商城”小程序登录采美平台畅享会员特权吧。关注公众号“采美网”可获取更多优惠和精彩资讯。";
+        if (null == cmSvipGive.getContractMobile()) {
+            return ResponseJson.error(-1,"手机号为空,无法发送短信",null);
+        }
+        boolean sendSms = sendSmsService.getSendSms(9, cmSvipGive.getContractMobile(), content);
+        if(sendSms){
+            log.info(">>>>>>>获得采美平台赠送的超级会员短信推送成功");
+        }
+        if (null != user) {
+            //不为空update
+            CmSvipHistory endTimeFlag = historyDao.findEndTime(Long.valueOf(cmSvipGive.getUserId()));
+            if (null != endTimeFlag) {
+                //不为空begintime不改,续期,否则正常update
+                Date beginTime = endTimeFlag.getEndTime();
+                cmSvipHistory.setBeginTime(beginTime);
+                c.setTime(beginTime);
+                c.add(Calendar.MONTH,cmSvipGive.getMonth());
+                cmSvipHistory.setEndTime(c.getTime());
+                historyDao.insertHistory(cmSvipHistory);
+                //cm_svip_user的begintime不变
+                cmSvipHistory.setBeginTime(null);
+                historyDao.updateVip(cmSvipHistory);
+            }else{
+                historyDao.insertHistory(cmSvipHistory);
+                //正常update
+                historyDao.updateVip(cmSvipHistory);
+            }
+        } else {
+            //cm_svip_history插入一条记录
+            historyDao.giveVip(cmSvipHistory);
+            //cm_svip_user无则新增
+            historyDao.insertHistory(cmSvipHistory);
+        }
+        return ResponseJson.success(1,"超级会员赠送成功",null);
+    }
+
+    /**
+     * 获取购买记录
+     *
+     * @param cmSvipHistory
+     * @return
+     */
+    @Override
+    public ResponseJson<PaginationVo<CmSvipHistory>> findHistory(CmSvipHistory cmSvipHistory, int pageNum, int pageSize) {
+        PageHelper.startPage(pageNum, pageSize);
+        List<CmSvipHistory> history = historyDao.findHistory(cmSvipHistory);
+        Map<String,Object> map = new HashMap<>();
+        //1生效2过期3未生效
+        for (CmSvipHistory svipHistory : history) {
+            Integer packageID = svipHistory.getPackageId();
+            Integer duration = historyDao.findDuration(packageID);
+            if (null != duration && duration.equals(3)) {
+                svipHistory.setPackageId(3);
+            }
+            if (null != duration && duration.equals(1)) {
+                svipHistory.setPackageId(1);
+            }
+            if (null != duration && duration.equals(12)) {
+                svipHistory.setPackageId(12);
+            }
+            if(0==packageID){
+                svipHistory.setGiveMonth(historyDao.findMonth(svipHistory.getId()));
+            }
+            Date beginTime = svipHistory.getBeginTime();
+            Date endTime = svipHistory.getEndTime();
+            //开始时间<现在
+            Date now = new Date();
+            if (beginTime.after(now)) {
+                svipHistory.setStatus("3");
+            }
+            if (beginTime.before(now) && endTime.after(now)) {
+                svipHistory.setStatus("1");
+            }
+            //终止时间>现在
+            if (endTime.before(now)) {
+                svipHistory.setStatus("2");
+            }
+        }
+        PaginationVo<CmSvipHistory> page = new PaginationVo<>(history);
+        return ResponseJson.success(page);
+    }
+
     /**
      * 超级会员优惠商品
      *

+ 9 - 0
src/main/resources/mapper/newOrderDao.xml

@@ -0,0 +1,9 @@
+<?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.manager.dao.newOrderDao">
+    <update id="updateSendNum">
+        UPDATE cm_sms_statistics
+        SET sendNum = (sendNum + #{num})
+        WHERE markId = #{markId}
+    </update>
+</mapper>

+ 106 - 0
src/main/resources/mapper/svip/CmSvipHistoryDao.xml

@@ -48,6 +48,112 @@
         where userId = #{userId}
           and endTime > now()
     </select>
+    <select id="findUserList" resultType="com.caimei365.manager.entity.caimei.CmUser">
+        SELECT
+        clubID as clubId,
+        userID as userId,
+        name,
+        sname AS shortName,
+        linkMan,
+        contractMobile as contractMobile
+        FROM
+        club
+        WHERE
+        status IN (1, 90)
+        <if test="clubId != null and clubId != ''">
+            AND clubId = #{clubId}
+        </if>
+        <if test="name != null and name != ''">
+            AND name LIKE CONCAT('%',#{name},'%')
+        </if>
+        <if test="shortName != null and shortName != ''">
+            AND sname LIKE CONCAT('%',#{shortName},'%')
+        </if>
+        ORDER BY clubId ASC
+    </select>
+    <select id="findVipUser" resultType="com.caimei365.manager.entity.caimei.svip.CmSvipHistory">
+        select beginTime, endTime, updateTime, userId
+        from cm_svip_user
+        where userId = #{userId}
+          and delflag = 0
+    </select>
+    <insert id="addMessageCenter">
+        INSERT INTO message_center (shopID, clubID, userType, messageType, content, time, accountType, couponType,
+                                    couponFee, couponMessageType, orderID, orderMessageType, shopMessType, productID)
+        VALUES (#{shopId}, #{clubId}, #{userType}, #{messageType}, #{content}, #{time}, #{accountType}, #{couponType},
+                #{couponFee}, #{couponMessageType}, #{orderId}, #{orderMessageType}, #{shopMessType}, #{productId})
+    </insert>
+    <insert id="insertHistory">
+        insert into cm_svip_history(userId, packageId, beginTime, endTime, payStatus, payWay, price, userBeans, payTime)
+        values (#{userId}, 0, #{beginTime}, #{endTime}, 1, #{payWay}, 0, 0, #{payTime})
+    </insert>
+    <update id="updateVip">
+        UPDATE cm_svip_user
+        SET
+        <if test="beginTime != null">
+            beginTime  = #{beginTime},
+        </if>
+        endTime    = #{endTime},
+        updateTime = now()
+        WHERE userId = #{userId}
+    </update>
+    <insert id="giveVip">
+        insert into cm_svip_user (userId, beginTime, endTime, delFlag, updateTime)
+        values (#{userId}, #{beginTime}, #{endTime}, 0, #{beginTime})
+    </insert>
+    <select id="findHistory" resultType="com.caimei365.manager.entity.caimei.svip.CmSvipHistory">
+        select
+        cs.id,
+        cs.userId,
+        cs.packageId,
+        u.name as clubName,
+        u.userName as linkMan,
+        u.bindMobile as mobile,
+        cs.beginTime,
+        cs.price,
+        cs.payWay,
+        cs.payType,
+        cs.userBeans,
+        cs.payTime,
+        cs.endTime
+        from cm_svip_history cs
+        LEFT JOIN club cb ON cs.userId = cb.userId
+        left join user u on cs.userId = u.userID
+        left join cm_svip_package cp on cp.id = cs.packageId
+        where cs.userId = #{userId}
+        AND cs.payStatus = '1'
+        <if test="startPayTime != null and startPayTime != '' and endPayTime != null and endPayTime != ''">
+            and (cs.payTime between #{startPayTime} and #{endPayTime})
+        </if>
+        <if test="startEndTime != null and startEndTime != '' and endEndTime != null and endEndTime != ''">
+            and (cs.endTime between #{startEndTime} and #{endEndTime})
+        </if>
+        <if test="packageId != null and packageId != 0">
+            and cp.duration = #{packageId}
+        </if>
+        <if test="packageId == 0">
+            and cs.packageId = 0
+        </if>
+        <if test='status == "1"'>
+            and (NOW() between cs.beginTime and cs.endTime)
+        </if>
+        <if test='status == "2"'>
+            and NOW() > cs.endTime
+        </if>
+        <if test='status == "3"'>
+            and cs.beginTime > NOW()
+        </if>
+        order by cs.payTime desc
+    </select>
+    <select id="findDuration" resultType="java.lang.Integer">
+        select duration
+        from cm_svip_package
+        where id = #{packageId}
+    </select>
+    <select id="findMonth" resultType="java.lang.String">
+        SELECT TIMESTAMPDIFF(MONTH, cs.beginTime, cs.endTime) FROM cm_svip_history cs
+        where id = #{id}
+    </select>
     <select id="findProductList" resultType="com.caimei365.manager.entity.caimei.svip.CmSvipProduct">
         SELECT
         a.id AS "id",