Your Name před 3 roky
rodič
revize
f15bb1d629

+ 10
- 1
src/main/java/com/yunzhi/shigongli/common/CommUtils.java Zobrazit soubor

@@ -1,5 +1,6 @@
1 1
 package com.yunzhi.shigongli.common;
2 2
 
3
+import com.yunzhi.shigongli.service.ISysConfigService;
3 4
 import com.yunzhi.shigongli.service.ITaHotelAccountService;
4 5
 import org.springframework.beans.factory.annotation.Autowired;
5 6
 import org.springframework.stereotype.Component;
@@ -12,8 +13,16 @@ public class CommUtils {
12 13
     @Autowired
13 14
     ITaHotelAccountService iTaHotelAccountService;
14 15
 
16
+    @Autowired
17
+    ISysConfigService iSysConfigService;
18
+
15 19
     @PostConstruct
16 20
     public void init() {
17
-        iTaHotelAccountService.initSystemAccount();
21
+        try {
22
+            iTaHotelAccountService.initSystemAccount();
23
+            iSysConfigService.initSysConfig();
24
+        } catch (Exception e) {
25
+//            e.printStackTrace();
26
+        }
18 27
     }
19 28
 }

+ 4
- 0
src/main/java/com/yunzhi/shigongli/common/Constants.java Zobrazit soubor

@@ -40,4 +40,8 @@ public class Constants {
40 40
     // 推荐人类型
41 41
     public final static String RECOMMEND_SHOP = "shop";     // 商铺
42 42
     public final static String RECOMMEND_HOTEL = "hotel";   // 民宿
43
+
44
+    // 系统参数
45
+    public final static String CONF_HOTEL_RECOMMEND_VALID_DAYS = "hotel_recommend_valid_days";      // 民宿推广客户有效时间
46
+    public final static String CONF_SHOP_RECOMMEND_VALID_DAYS = "shop_recommend_valid_days";        // 商铺推广客户有效时间
43 47
 }

+ 117
- 122
src/main/java/com/yunzhi/shigongli/controller/WxMaController.java Zobrazit soubor

@@ -1,21 +1,24 @@
1 1
 package com.yunzhi.shigongli.controller;
2 2
 
3 3
 import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
4
+import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
5
+import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
4 6
 import com.yunzhi.shigongli.common.*;
5 7
 import com.yunzhi.shigongli.entity.TaMiniappQrcode;
6 8
 import com.yunzhi.shigongli.entity.TaPerson;
9
+import com.yunzhi.shigongli.entity.TaPersonRole;
7 10
 import com.yunzhi.shigongli.service.ITaMiniappQrcodeService;
11
+import com.yunzhi.shigongli.service.ITaPersonRecommenderService;
12
+import com.yunzhi.shigongli.service.ITaPersonRoleService;
8 13
 import com.yunzhi.shigongli.service.ITaPersonService;
14
+import com.yunzhi.shigongli.vo.WxMaAuthParam;
9 15
 import io.swagger.annotations.Api;
10 16
 import io.swagger.annotations.ApiOperation;
11
-import me.chanjar.weixin.common.error.WxErrorException;
17
+import io.swagger.annotations.ApiParam;
12 18
 import org.springframework.beans.factory.annotation.Autowired;
13 19
 import org.springframework.web.bind.annotation.*;
14 20
 
15
-import java.util.Arrays;
16
-import java.util.HashMap;
17
-import java.util.Map;
18
-import java.util.Optional;
21
+import java.util.*;
19 22
 
20 23
 
21 24
 @Api(tags = "微信小程序")
@@ -32,7 +35,13 @@ public class WxMaController extends BaseController {
32 35
     @Autowired
33 36
     ITaMiniappQrcodeService miniappQrcodeService;
34 37
 
35
-    @GetMapping("prefetch")
38
+    @Autowired
39
+    ITaPersonRecommenderService recommenderService;
40
+
41
+    @Autowired
42
+    ITaPersonRoleService personRoleService;
43
+
44
+    @GetMapping("/prefetch")
36 45
     @ApiOperation(value="微信预拉取数据", notes = "微信预拉取数据", httpMethod = "GET", response = ResponseBean.class)
37 46
     public ResponseBean perfetch(String appid,
38 47
                                  String token,
@@ -44,19 +53,13 @@ public class WxMaController extends BaseController {
44 53
         WxMaJscode2SessionResult info = wxUtils.getService().getUserService().getSessionInfo(code);
45 54
         String openid = info.getOpenid();
46 55
 
47
-        TaPerson taPerson = iTaPersonService.getByOpenid(openid);
48
-        if (null == taPerson) {
49
-            taPerson = new TaPerson();
50
-            taPerson.setOpenid(openid);
51
-            iTaPersonService.save(taPerson);
52
-            // 插入过程会有默认字段写入
53
-            taPerson = iTaPersonService.getById(taPerson.getPersonId());
54
-        }
56
+        TaPerson taPerson = iTaPersonService.getByOpenidOrNot(openid);
55 57
 
56 58
         Map<String, Object> result = new HashMap<>();
57
-        result.put("person", taPerson);
59
+        result.put("personId", taPerson.getPersonId());
60
+        result.put("openid", taPerson.getOpenid());
61
+        result.put("sessionKey", info.getSessionKey());
58 62
 
59
-        // 如果是通过扫码打开
60 63
         if (!StringUtils.isEmpty(query)) {
61 64
             Map<String, String> params = StringUtils.parseQueryString(query);
62 65
 
@@ -83,116 +86,108 @@ public class WxMaController extends BaseController {
83 86
             }
84 87
 
85 88
             // 如果有推广ID, 比如民宿或者商铺
86
-            if (StringUtils.isEmpty(taPerson.getRecommender()) && !StringUtils.isEmpty(recommender)) {
87
-                taPerson.setFromType(fromType);
88
-                taPerson.setRecommender(recommender);
89
-                iTaPersonService.setRecommender(taPerson);
90
-            }
89
+            if (!StringUtils.isEmpty(recommender)) {
90
+                if (StringUtils.isEmpty(taPerson.getRecommender())) {
91
+                    taPerson.setFromType(fromType);
92
+                    taPerson.setRecommender(recommender);
93
+                    iTaPersonService.updateById(taPerson);
94
+                }
91 95
 
96
+                // 写入推荐表
97
+                try {
98
+                    recommenderService.addNewRecommender(taPerson.getPersonId(), fromType, recommender);
99
+                } catch (Exception e) {
100
+                    e.printStackTrace();;
101
+                }
102
+            }
92 103
         }
93 104
 
105
+        // 生成 token
106
+        Map<String, Object> tokenClaims = new HashMap<>();
107
+        tokenClaims.put("userId", taPerson.getPersonId());
108
+        tokenClaims.put("miniApp", true);
109
+        String authToken = JWTUtils.encode(tokenClaims);
110
+        result.put("token", authToken);
111
+
94 112
         return ResponseBean.success(result);
95 113
     }
96 114
 
97
-//    @PostMapping("/login")
98
-//    @ApiOperation(value="登录", notes = "登录", httpMethod = "POST", response = ResponseBean.class)
99
-//    public ResponseBean login(@ApiParam("登录参数") @RequestParam String code) throws Exception {
100
-//        WxMaJscode2SessionResult info = wxUtils.getService().getUserService().getSessionInfo(code);
101
-//
102
-//        String openid = info.getOpenid();
103
-//        TaPerson taPerson = iTaPersonService.getByOpenid(openid);
104
-//        if (null == taPerson) {
105
-//            taPerson = new TaPerson();
106
-//            taPerson.setOpenid(openid);
107
-//            iTaPersonService.save(taPerson);
108
-//
109
-//            TaPersonData taPersonData = new TaPersonData();
110
-//            taPersonData.setPersonId(taPerson.getPersonId());
111
-//            iTaPersonDataService.save(taPersonData);
112
-//        }
113
-//
114
-//        // 查询学生
115
-//        TaStudent taStudent = iTaStudentService.getByPersonId(taPerson.getPersonId());
116
-//        taPerson.setStudent(taStudent);
117
-//
118
-//        Map<String, Object> tokenClaims = new HashMap<>();
119
-//        tokenClaims.put("userId", taPerson.getPersonId());
120
-////        tokenClaims.put("sessionKey", info.getSessionKey());
121
-//        tokenClaims.put("miniApp", true);
122
-//        String token = JWTUtils.encode(tokenClaims);
123
-//
124
-//        Map<String, Object> rtn = new HashMap<>();
125
-//        rtn.put("person", taPerson);
126
-//        rtn.put("sessionKey", info.getSessionKey());
127
-//        rtn.put("token", token);
128
-//
129
-//        return ResponseBean.success(rtn);
130
-//    }
131
-//
132
-//    @PutMapping("/auth-user")
133
-//    @ApiOperation(value="授权头像", notes = "授权头像", httpMethod = "PUT", response = TaPerson.class)
134
-//    public ResponseBean updateUserInfo(@ApiParam("授权头像的参数") @RequestBody WxMaAuthParam params) throws Exception {
135
-//        checkAuthParams(params);
136
-//
137
-//        // 解密用户信息
138
-//        WxMaUserInfo userInfo = wxUtils.getService().getUserService().getUserInfo(params.getSessionKey(), params.getEncryptedData(), params.getIv());
139
-//
140
-//        TaPerson taPerson = getCurrentPerson();
141
-//        if (null == taPerson) {
142
-//            throw new Exception("校验当前人员失败, 请重试");
143
-//        }
144
-//
145
-//        taPerson.setAvatar(userInfo.getAvatarUrl());
146
-//        taPerson.setNickName(userInfo.getNickName());
147
-//        taPerson.setSex(Integer.parseInt(userInfo.getGender()));
148
-//
149
-//        iTaPersonService.updateById(taPerson);
150
-//
151
-//        return ResponseBean.success(taPerson);
152
-//    }
153
-//
154
-//    @ApiOperation(value="授权手机", notes = "授权手机", httpMethod = "PUT", response = TaPerson.class)
155
-//    @PutMapping("/auth-phone")
156
-//    public ResponseBean updateUserPhone(@ApiParam("授权手机的参数") @RequestBody WxMaAuthParam params) throws Exception {
157
-////        checkAuthParams(params);
158
-//
159
-//        // 解密
160
-//        WxMaPhoneNumberInfo phoneNoInfo = wxUtils.getService().getUserService().getPhoneNoInfo(params.getSessionKey(), params.getEncryptedData(), params.getIv());
161
-//
162
-//        TaPerson taPerson = getCurrentPerson();
163
-//        if (null == taPerson) {
164
-//            throw new Exception("校验当前人员失败, 请重试");
165
-//        }
166
-//
167
-//        taPerson.setPhone(phoneNoInfo.getPhoneNumber());
168
-//        iTaPersonService.updateById(taPerson);
169
-//
170
-//        // 查询学生
171
-//        TaStudent taStudent = iTaStudentService.getByPhone(taPerson.getPhone());
172
-//        if (null != taStudent) {
173
-//            taStudent.setPersonId(taPerson.getPersonId());
174
-//            iTaStudentService.updateById(taStudent);
175
-//        }
176
-//
177
-//        return ResponseBean.success(taPerson);
178
-//    }
179
-//
180
-//    private void checkAuthParams(WxMaAuthParam params) throws Exception {
181
-//        String signature = params.getSignature();
182
-//        String rawData = params.getRawData();
183
-//        String encryptedData = params.getEncryptedData();
184
-//        String iv = params.getIv();
185
-//        String sessionKey = params.getSessionKey();
186
-//
187
-//        if (StringUtils.isEmpty(signature) || StringUtils.isEmpty(rawData) || StringUtils.isEmpty(encryptedData) || StringUtils.isEmpty(iv) || StringUtils.isEmpty(sessionKey)) {
188
-//            throw new Exception("缺失授权参数");
189
-//        }
190
-//
191
-//        boolean isValid = wxUtils.getService().getUserService().checkUserInfo(sessionKey, rawData, signature);
192
-//        if (!isValid) {
193
-//            throw new Exception("校验授权参数失败, 请重试");
194
-//        }
195
-//
196
-//        return;
197
-//    }
115
+    @PostMapping("/login")
116
+    @ApiOperation(value="登录", notes = "登录", httpMethod = "POST", response = ResponseBean.class)
117
+    public ResponseBean login(@ApiParam("登录参数") @RequestParam String code) throws Exception {
118
+        WxMaJscode2SessionResult info = wxUtils.getService().getUserService().getSessionInfo(code);
119
+
120
+        String openid = info.getOpenid();
121
+        TaPerson taPerson = iTaPersonService.getByOpenidOrNot(openid);
122
+
123
+        // 查询人员角色
124
+        List<TaPersonRole> roleList = personRoleService.getListByPerson(taPerson.getPersonId());
125
+
126
+        Map<String, Object> rtn = new HashMap<>();
127
+        rtn.put("person", taPerson);
128
+        rtn.put("personRoleList", roleList);
129
+        rtn.put("sessionKey", info.getSessionKey());
130
+
131
+        return ResponseBean.success(rtn);
132
+    }
133
+
134
+    @PutMapping("/auth-user")
135
+    @ApiOperation(value="授权头像", notes = "授权头像", httpMethod = "PUT", response = TaPerson.class)
136
+    public ResponseBean updateUserInfo(@ApiParam("授权头像的参数") @RequestBody WxMaAuthParam params) throws Exception {
137
+        checkAuthParams(params);
138
+
139
+        // 解密用户信息
140
+        WxMaUserInfo userInfo = wxUtils.getService().getUserService().getUserInfo(params.getSessionKey(), params.getEncryptedData(), params.getIv());
141
+
142
+        TaPerson taPerson = getCurrentPerson();
143
+        if (null == taPerson) {
144
+            throw new Exception("校验当前人员失败, 请重试");
145
+        }
146
+
147
+        taPerson.setAvatar(userInfo.getAvatarUrl());
148
+        taPerson.setNickName(userInfo.getNickName());
149
+        taPerson.setSex(Integer.parseInt(userInfo.getGender()));
150
+
151
+        iTaPersonService.updateById(taPerson);
152
+
153
+        return ResponseBean.success(taPerson);
154
+    }
155
+
156
+    @ApiOperation(value="授权手机", notes = "授权手机", httpMethod = "PUT", response = TaPerson.class)
157
+    @PutMapping("/auth-phone")
158
+    public ResponseBean updateUserPhone(@ApiParam("授权手机的参数") @RequestBody WxMaAuthParam params) throws Exception {
159
+        checkAuthParams(params);
160
+
161
+        // 解密
162
+        WxMaPhoneNumberInfo phoneNoInfo = wxUtils.getService().getUserService().getPhoneNoInfo(params.getSessionKey(), params.getEncryptedData(), params.getIv());
163
+
164
+        TaPerson taPerson = getCurrentPerson();
165
+        if (null == taPerson) {
166
+            throw new Exception("校验当前人员失败, 请重试");
167
+        }
168
+
169
+        taPerson.setPhone(phoneNoInfo.getPhoneNumber());
170
+        iTaPersonService.updateById(taPerson);
171
+
172
+        return ResponseBean.success(taPerson);
173
+    }
174
+
175
+    private void checkAuthParams(WxMaAuthParam params) throws Exception {
176
+        String signature = params.getSignature();
177
+        String rawData = params.getRawData();
178
+        String encryptedData = params.getEncryptedData();
179
+        String iv = params.getIv();
180
+        String sessionKey = params.getSessionKey();
181
+
182
+        if (StringUtils.isEmpty(signature) || StringUtils.isEmpty(rawData) || StringUtils.isEmpty(encryptedData) || StringUtils.isEmpty(iv) || StringUtils.isEmpty(sessionKey)) {
183
+            throw new Exception("缺失授权参数");
184
+        }
185
+
186
+        boolean isValid = wxUtils.getService().getUserService().checkUserInfo(sessionKey, rawData, signature);
187
+        if (!isValid) {
188
+            throw new Exception("校验授权参数失败, 请重试");
189
+        }
190
+
191
+        return;
192
+    }
198 193
 }

+ 52
- 0
src/main/java/com/yunzhi/shigongli/entity/SysConfig.java Zobrazit soubor

@@ -0,0 +1,52 @@
1
+package com.yunzhi.shigongli.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import com.baomidou.mybatisplus.annotation.TableField;
5
+import com.baomidou.mybatisplus.annotation.TableId;
6
+import io.swagger.annotations.ApiModel;
7
+import io.swagger.annotations.ApiModelProperty;
8
+import io.swagger.models.auth.In;
9
+import lombok.Data;
10
+import lombok.EqualsAndHashCode;
11
+import lombok.experimental.Accessors;
12
+
13
+import java.io.Serializable;
14
+import java.time.LocalDateTime;
15
+
16
+/**
17
+ * <p>
18
+ * 登录
19
+ * </p>
20
+ *
21
+ * @author yansen
22
+ * @since 2021-08-17
23
+ */
24
+@Data
25
+@EqualsAndHashCode(callSuper = false)
26
+@Accessors(chain = true)
27
+@ApiModel(value="SysConfig对象", description="系统参数表")
28
+public class SysConfig implements Serializable {
29
+
30
+    private static final long serialVersionUID = 1L;
31
+
32
+    @ApiModelProperty(value = "配置编码")
33
+    @TableId(value = "config_code", type = IdType.INPUT)
34
+    private String configCode;
35
+
36
+    @ApiModelProperty(value = "配置名称")
37
+    private String configName;
38
+
39
+    @ApiModelProperty(value = "配置描述")
40
+    @TableField("`description`")
41
+    private String description;
42
+
43
+    @ApiModelProperty(value = "配置值")
44
+    private String configValue;
45
+
46
+    @ApiModelProperty(value = "状态;1已启用,0未启用")
47
+    private Boolean status;
48
+
49
+    @ApiModelProperty(value = "排序")
50
+    private Integer sort;
51
+
52
+}

+ 18
- 0
src/main/java/com/yunzhi/shigongli/mapper/SysConfigMapper.java Zobrazit soubor

@@ -0,0 +1,18 @@
1
+package com.yunzhi.shigongli.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.yunzhi.shigongli.entity.SysConfig;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+/**
8
+ * <p>
9
+ * 登录 Mapper 接口
10
+ * </p>
11
+ *
12
+ * @author yansen
13
+ * @since 2021-08-17
14
+ */
15
+@Mapper
16
+public interface SysConfigMapper extends BaseMapper<SysConfig> {
17
+
18
+}

+ 18
- 0
src/main/java/com/yunzhi/shigongli/mapper/TaPersonRoleMapper.java Zobrazit soubor

@@ -0,0 +1,18 @@
1
+package com.yunzhi.shigongli.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.yunzhi.shigongli.entity.TaPersonRole;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+/**
8
+ * <p>
9
+ * 小程序人员表 Mapper 接口
10
+ * </p>
11
+ *
12
+ * @author yansen
13
+ * @since 2021-08-17
14
+ */
15
+@Mapper
16
+public interface TaPersonRoleMapper extends BaseMapper<TaPersonRole> {
17
+
18
+}

+ 16
- 0
src/main/java/com/yunzhi/shigongli/service/ISysConfigService.java Zobrazit soubor

@@ -0,0 +1,16 @@
1
+package com.yunzhi.shigongli.service;
2
+
3
+
4
+import com.yunzhi.shigongli.entity.SysConfig;
5
+
6
+/**
7
+ * <p>
8
+ * 用户登录 服务类
9
+ * </p>
10
+ *
11
+ * @author yansen
12
+ * @since 2021-04-15
13
+ */
14
+public interface ISysConfigService extends IBaseService<SysConfig> {
15
+    void initSysConfig() throws Exception;
16
+}

+ 1
- 0
src/main/java/com/yunzhi/shigongli/service/ITaPersonRecommenderService.java Zobrazit soubor

@@ -13,4 +13,5 @@ import com.yunzhi.shigongli.entity.TaPersonRecommender;
13 13
  */
14 14
 public interface ITaPersonRecommenderService extends IBaseService<TaPersonRecommender> {
15 15
 
16
+    void addNewRecommender(String personId, String fromType, String recommender) throws Exception;
16 17
 }

+ 19
- 0
src/main/java/com/yunzhi/shigongli/service/ITaPersonRoleService.java Zobrazit soubor

@@ -0,0 +1,19 @@
1
+package com.yunzhi.shigongli.service;
2
+
3
+import com.yunzhi.shigongli.entity.TaPersonRole;
4
+
5
+import java.util.List;
6
+
7
+
8
+/**
9
+ * <p>
10
+ * 小程序人员表 服务类
11
+ * </p>
12
+ *
13
+ * @author yansen
14
+ * @since 2021-08-17
15
+ */
16
+public interface ITaPersonRoleService extends IBaseService<TaPersonRole> {
17
+
18
+    List<TaPersonRole> getListByPerson(String personId);
19
+}

+ 1
- 1
src/main/java/com/yunzhi/shigongli/service/ITaPersonService.java Zobrazit soubor

@@ -15,5 +15,5 @@ public interface ITaPersonService extends IBaseService<TaPerson> {
15 15
 
16 16
     TaPerson getByOpenid(String openid);
17 17
 
18
-    void setRecommender(TaPerson taPerson) throws Exception;
18
+    TaPerson getByOpenidOrNot(String openid);
19 19
 }

+ 57
- 0
src/main/java/com/yunzhi/shigongli/service/impl/SysConfigServiceImpl.java Zobrazit soubor

@@ -0,0 +1,57 @@
1
+package com.yunzhi.shigongli.service.impl;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4
+import com.yunzhi.shigongli.common.Constants;
5
+import com.yunzhi.shigongli.entity.SysConfig;
6
+import com.yunzhi.shigongli.mapper.SysConfigMapper;
7
+import com.yunzhi.shigongli.service.ISysConfigService;
8
+import org.springframework.scheduling.annotation.Async;
9
+import org.springframework.stereotype.Service;
10
+import org.springframework.transaction.annotation.Transactional;
11
+
12
+import java.util.ArrayList;
13
+import java.util.List;
14
+
15
+/**
16
+ * <p>
17
+ * 用户登录 服务实现类
18
+ * </p>
19
+ *
20
+ * @author yansen
21
+ * @since 2021-04-15
22
+ */
23
+@Service
24
+public class SysConfigServiceImpl extends BaseServiceImpl<SysConfigMapper, SysConfig> implements ISysConfigService {
25
+
26
+    @Async
27
+    @Transactional(rollbackFor = Exception.class)
28
+    @Override
29
+    public void initSysConfig() throws Exception {
30
+        if (count() > 0) {
31
+            return;
32
+        }
33
+
34
+        SysConfig config1 = new SysConfig();
35
+        config1.setConfigCode(Constants.CONF_HOTEL_RECOMMEND_VALID_DAYS);
36
+        config1.setConfigName("民宿推广客户有效时间");
37
+        config1.setDescription("单位 天");
38
+        config1.setConfigValue("365");
39
+        config1.setStatus(true);
40
+        config1.setSort(1);
41
+
42
+        SysConfig config2 = new SysConfig();
43
+        config2.setConfigCode(Constants.CONF_SHOP_RECOMMEND_VALID_DAYS);
44
+        config2.setConfigName("商铺推广客户有效时间");
45
+        config2.setDescription("单位 天");
46
+        config2.setConfigValue("12");
47
+        config2.setStatus(true);
48
+        config2.setSort(2);
49
+
50
+        List<SysConfig> configList = new ArrayList<SysConfig>(){{
51
+            add(config1);
52
+            add(config2);
53
+        }};
54
+
55
+        saveBatch(configList);
56
+    }
57
+}

+ 63
- 0
src/main/java/com/yunzhi/shigongli/service/impl/TaPersonRecommenderServiceImpl.java Zobrazit soubor

@@ -1,11 +1,19 @@
1 1
 package com.yunzhi.shigongli.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4
+import com.yunzhi.shigongli.common.Constants;
5
+import com.yunzhi.shigongli.entity.SysConfig;
3 6
 import com.yunzhi.shigongli.entity.TaPersonRecommender;
7
+import com.yunzhi.shigongli.mapper.SysConfigMapper;
4 8
 import com.yunzhi.shigongli.mapper.TaPersonRecommenderMapper;
5 9
 import com.yunzhi.shigongli.service.ITaPersonRecommenderService;
6 10
 
11
+import org.springframework.beans.factory.annotation.Autowired;
12
+import org.springframework.scheduling.annotation.Async;
7 13
 import org.springframework.stereotype.Service;
8 14
 
15
+import java.time.LocalDateTime;
16
+
9 17
 /**
10 18
  * <p>
11 19
  * 用户推广人 服务实现类
@@ -17,4 +25,59 @@ import org.springframework.stereotype.Service;
17 25
 @Service
18 26
 public class TaPersonRecommenderServiceImpl extends BaseServiceImpl<TaPersonRecommenderMapper, TaPersonRecommender> implements ITaPersonRecommenderService {
19 27
 
28
+    @Autowired
29
+    SysConfigMapper sysConfigMapper;
30
+
31
+    @Autowired
32
+    TaPersonRecommenderMapper personRecommenderMapper;
33
+
34
+    @Async
35
+    @Override
36
+    public void addNewRecommender(String personId, String fromType, String recommender) throws Exception {
37
+        if (isExists(personId, fromType, recommender)) {
38
+            throw new Exception("当前客户还有未到期的推荐人");
39
+        }
40
+
41
+        // 读取系统配置
42
+        String configCode = null;
43
+        if (Constants.RECOMMEND_SHOP.equals(fromType)) {
44
+            configCode = Constants.CONF_SHOP_RECOMMEND_VALID_DAYS;
45
+        }
46
+        if (Constants.RECOMMEND_SHOP.equals(fromType)) {
47
+            configCode = Constants.CONF_HOTEL_RECOMMEND_VALID_DAYS;
48
+        }
49
+
50
+        SysConfig config = null == configCode ? null : sysConfigMapper.selectById(configCode);
51
+        Integer validDays = 0;
52
+        if (null != config && config.getStatus()) {
53
+            validDays = Integer.valueOf(config.getConfigValue().trim());
54
+        }
55
+
56
+        LocalDateTime now = LocalDateTime.now();
57
+        LocalDateTime expireDate = now.plusDays(validDays);
58
+
59
+        // 生成推广记录
60
+        TaPersonRecommender personRecommender = new TaPersonRecommender();
61
+        personRecommender.setPersonId(personId);
62
+        personRecommender.setFromType(fromType);
63
+        personRecommender.setRecommender(recommender);
64
+        personRecommender.setCreateDate(now);
65
+        personRecommender.setExpireDate(expireDate);
66
+        personRecommender.setStatus(Constants.STATUS_NORMAL);
67
+
68
+        save(personRecommender);
69
+    }
70
+
71
+    private boolean isExists(String personId, String fromType, String recommender) {
72
+        LocalDateTime now = LocalDateTime.now();
73
+        LambdaQueryWrapper<TaPersonRecommender> queryWrapper = new LambdaQueryWrapper<>();
74
+        queryWrapper.eq(TaPersonRecommender::getPersonId, personId)
75
+                .eq(TaPersonRecommender::getFromType, fromType)
76
+                .eq(TaPersonRecommender::getRecommender, recommender)
77
+                .eq(TaPersonRecommender::getStatus, Constants.STATUS_NORMAL)
78
+                .gt(TaPersonRecommender::getCreateDate, LocalDateTime.now())
79
+                .lt(TaPersonRecommender::getExpireDate, now);
80
+
81
+        return count(queryWrapper) > 0;
82
+    }
20 83
 }

+ 29
- 0
src/main/java/com/yunzhi/shigongli/service/impl/TaPersonRoleServiceImpl.java Zobrazit soubor

@@ -0,0 +1,29 @@
1
+package com.yunzhi.shigongli.service.impl;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4
+import com.yunzhi.shigongli.entity.TaPersonRole;
5
+import com.yunzhi.shigongli.mapper.TaPersonRoleMapper;
6
+import com.yunzhi.shigongli.service.ITaPersonRoleService;
7
+import org.springframework.stereotype.Service;
8
+
9
+import java.util.List;
10
+
11
+/**
12
+ * <p>
13
+ * 小程序人员表 服务实现类
14
+ * </p>
15
+ *
16
+ * @author yansen
17
+ * @since 2021-08-17
18
+ */
19
+@Service
20
+public class TaPersonRoleServiceImpl extends BaseServiceImpl<TaPersonRoleMapper, TaPersonRole> implements ITaPersonRoleService {
21
+
22
+    @Override
23
+    public List<TaPersonRole> getListByPerson(String personId) {
24
+        LambdaQueryWrapper<TaPersonRole> queryWrapper = new LambdaQueryWrapper<>();
25
+        queryWrapper.eq(TaPersonRole::getPersonId, personId);
26
+
27
+        return list(queryWrapper);
28
+    }
29
+}

+ 10
- 6
src/main/java/com/yunzhi/shigongli/service/impl/TaPersonServiceImpl.java Zobrazit soubor

@@ -8,7 +8,6 @@ import com.yunzhi.shigongli.mapper.TaPersonMapper;
8 8
 import com.yunzhi.shigongli.service.ITaPersonService;
9 9
 
10 10
 import org.springframework.stereotype.Service;
11
-import org.springframework.transaction.annotation.Transactional;
12 11
 
13 12
 /**
14 13
  * <p>
@@ -35,12 +34,17 @@ public class TaPersonServiceImpl extends BaseServiceImpl<TaPersonMapper, TaPerso
35 34
         return getOne(queryWrapper);
36 35
     }
37 36
 
38
-    @Transactional(rollbackFor = Exception.class)
39 37
     @Override
40
-    public void setRecommender(TaPerson taPerson) throws Exception {
41
-        updateById(taPerson);
42
-
43
-        // 生成推广记录
38
+    public TaPerson getByOpenidOrNot(String openid) {
39
+        TaPerson taPerson = getByOpenid(openid);
40
+        if (null == taPerson) {
41
+            taPerson = new TaPerson();
42
+            taPerson.setOpenid(openid);
43
+            save(taPerson);
44
+            // 插入过程会有默认字段写入
45
+            taPerson = getById(taPerson.getPersonId());
46
+        }
44 47
 
48
+        return taPerson;
45 49
     }
46 50
 }

+ 2
- 1
src/main/resources/application.yml Zobrazit soubor

@@ -12,7 +12,8 @@ interceptor:
12 12
     exclude-paths:
13 13
       - /admin/login
14 14
       - /admin/logout
15
-      - /ma/login
15
+      - /wx/prefetch
16
+      - /wx/login
16 17
       - /wxpay/notify/order
17 18
       - /swagger-ui/**
18 19
       - /swagger-resources/**

+ 5
- 0
src/main/resources/mapper/SysConfigMapper.xml Zobrazit soubor

@@ -0,0 +1,5 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.yunzhi.shigongli.mapper.SysConfigMapper">
4
+
5
+</mapper>