浏览代码

Merge remote-tracking branch 'origin/master' into master

zlisen 4 年前
父节点
当前提交
fbfdffc5e7

+ 36
- 27
src/main/java/com/shigongli/controller/TaPersonController.java 查看文件

@@ -1,14 +1,17 @@
1 1
 package com.shigongli.controller;
2 2
 
3
+import cn.binarywang.wx.miniapp.api.WxMaService;
4
+import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
3 5
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 6
 import com.baomidou.mybatisplus.core.metadata.IPage;
5 7
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
-import com.shigongli.common.BaseController;
7
-import com.shigongli.common.JWTUtils;
8
-import com.shigongli.common.ResponseBean;
8
+import com.shigongli.common.*;
9
+import com.shigongli.service.ITaShopKeeperService;
10
+import com.shigongli.vo.AuthPhoneParams;
9 11
 import io.swagger.annotations.Api;
10 12
 import io.swagger.annotations.ApiOperation;
11 13
 import io.swagger.annotations.ApiParam;
14
+import me.chanjar.weixin.mp.api.WxMpService;
12 15
 import org.slf4j.Logger;
13 16
 import org.slf4j.LoggerFactory;
14 17
 import org.springframework.beans.factory.annotation.Autowired;
@@ -39,30 +42,36 @@ public class TaPersonController extends BaseController {
39 42
     @Autowired
40 43
     public ITaPersonService iTaPersonService;
41 44
 
42
-//    @PostMapping("/ma/login")
43
-//    public ResponseBean login(String code) {
44
-//        // 用 code 去换 openid
45
-//        String openid = "";
46
-//
47
-//        // 先查询人员是否存在
48
-//        TaPerson taPerson = iTaPersonService.getByOpenId(openid);
49
-//
50
-//        // 如果人员不存在, 则新增
51
-//        if (null == taPerson) {
52
-//            taPerson = new TaPerson();
53
-//            taPerson.setOpenid(openid);
54
-//            iTaPersonService.save(taPerson);
55
-////            taPerson = iTaPersonService.getById(taPerson.getPersonId());
56
-//        }
57
-//
58
-//        // 生成 token
59
-//        Map<String, Object> claims = new HashMap<>();
60
-//        claims.put("personId", taPerson.getPersonId());
61
-//        String token = JWTUtils.encode(claims);
62
-//        taPerson.setToken(token);
63
-//
64
-//        return ResponseBean.success(taPerson);
65
-//    }
45
+    @Autowired
46
+    private ITaShopKeeperService iTaShopKeeperService;
47
+
48
+    @Autowired
49
+    private WxUtils wxUtils;
50
+
51
+    @ApiOperation(value="授权手机", notes = "授权手机", httpMethod = "POST", response = ResponseBean.class)
52
+    @PostMapping("/ma/taPerson/phone")
53
+    public ResponseBean phone(@ApiParam("授权手机参数") @RequestBody AuthPhoneParams authPhoneParams,
54
+                              HttpServletRequest request) {
55
+        if (null == authPhoneParams) {
56
+            return ResponseBean.error("请设置授权手机号的参数", ResponseBean.ERROR_UNAVAILABLE);
57
+        }
58
+        TaPerson taPerson = getPerson(request);
59
+        if (null == taPerson) {
60
+            return ResponseBean.error("校验用户失败, 请退出重新进入", ResponseBean.ERROR_UNAVAILABLE);
61
+        }
62
+
63
+        WxMaService maService = wxUtils.getMaService();
64
+        WxMaPhoneNumberInfo phoneNoInfo = maService.getUserService().getPhoneNoInfo(authPhoneParams.getSessionKey(), authPhoneParams.getEncryptedData(), authPhoneParams.getIv());
65
+
66
+        String phone = phoneNoInfo.getPhoneNumber();
67
+        taPerson.setPhone(phone);
68
+        iTaPersonService.updateById(taPerson);
69
+
70
+        // 绑定店主
71
+        iTaShopKeeperService.bindPerson(taPerson);
72
+
73
+        return ResponseBean.success(taPerson);
74
+    }
66 75
 
67 76
 
68 77
     /**

+ 15
- 0
src/main/java/com/shigongli/controller/TaShopKeeperController.java 查看文件

@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.shigongli.common.BaseController;
7 7
 import com.shigongli.common.ResponseBean;
8 8
 import com.shigongli.constants.StatusConstant;
9
+import com.shigongli.entity.TaPerson;
10
+import com.shigongli.service.ITaPersonService;
9 11
 import io.swagger.annotations.Api;
10 12
 import io.swagger.annotations.ApiOperation;
11 13
 import io.swagger.annotations.ApiParam;
@@ -40,6 +42,9 @@ public class TaShopKeeperController extends BaseController {
40 42
     @Autowired
41 43
     public ITaShopKeeperService iTaShopKeeperService;
42 44
 
45
+    @Autowired
46
+    public ITaPersonService iTaPersonService;
47
+
43 48
 
44 49
     /**
45 50
      * 分页查询列表
@@ -72,6 +77,11 @@ public class TaShopKeeperController extends BaseController {
72 77
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
73 78
     public ResponseBean taShopKeeperAdd(@ApiParam("保存内容") @RequestBody TaShopKeeper taShopKeeper) throws Exception{
74 79
 
80
+        TaPerson taPerson = iTaPersonService.getByPhone(taShopKeeper.getPhone());
81
+        if (null != taPerson) {
82
+            taShopKeeper.setPersonId(taPerson.getPersonId());
83
+        }
84
+
75 85
         if (iTaShopKeeperService.save(taShopKeeper)){
76 86
             return ResponseBean.success(taShopKeeper);
77 87
         }else {
@@ -106,6 +116,11 @@ public class TaShopKeeperController extends BaseController {
106 116
     public ResponseBean taShopKeeperUpdate(@ApiParam("对象ID") @PathVariable String id,
107 117
                                         @ApiParam("更新内容") @RequestBody TaShopKeeper taShopKeeper) throws Exception{
108 118
 
119
+        TaPerson taPerson = iTaPersonService.getByPhone(taShopKeeper.getPhone());
120
+        if (null != taPerson) {
121
+            taShopKeeper.setPersonId(taPerson.getPersonId());
122
+        }
123
+
109 124
         if (iTaShopKeeperService.updateById(taShopKeeper)){
110 125
             return ResponseBean.success(iTaShopKeeperService.getById(id));
111 126
         }else {

+ 3
- 0
src/main/java/com/shigongli/service/ITaPersonService.java 查看文件

@@ -2,6 +2,7 @@ package com.shigongli.service;
2 2
 
3 3
 import com.shigongli.entity.TaPerson;
4 4
 import com.baomidou.mybatisplus.extension.service.IService;
5
+import com.shigongli.entity.TaShopKeeper;
5 6
 
6 7
 /**
7 8
  * <p>
@@ -14,4 +15,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
14 15
 public interface ITaPersonService extends IService<TaPerson> {
15 16
 
16 17
     TaPerson getByOpenId(String openid);
18
+
19
+    TaPerson getByPhone(String phone);
17 20
 }

+ 6
- 0
src/main/java/com/shigongli/service/ITaShopKeeperService.java 查看文件

@@ -1,8 +1,11 @@
1 1
 package com.shigongli.service;
2 2
 
3
+import com.shigongli.entity.TaPerson;
3 4
 import com.shigongli.entity.TaShopKeeper;
4 5
 import com.baomidou.mybatisplus.extension.service.IService;
5 6
 
7
+import java.util.List;
8
+
6 9
 /**
7 10
  * <p>
8 11
  * 店主 服务类
@@ -13,4 +16,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
13 16
  */
14 17
 public interface ITaShopKeeperService extends IService<TaShopKeeper> {
15 18
 
19
+    void bindPerson(TaPerson taPerson);
20
+
21
+    List<TaShopKeeper> getByPhone(String phone);
16 22
 }

+ 17
- 0
src/main/java/com/shigongli/service/impl/TaPersonServiceImpl.java 查看文件

@@ -1,6 +1,10 @@
1 1
 package com.shigongli.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.shigongli.common.StringUtils;
5
+import com.shigongli.constants.StatusConstant;
3 6
 import com.shigongli.entity.TaPerson;
7
+import com.shigongli.entity.TaShopKeeper;
4 8
 import com.shigongli.mapper.TaPersonMapper;
5 9
 import com.shigongli.service.ITaPersonService;
6 10
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -25,4 +29,17 @@ public class TaPersonServiceImpl extends ServiceImpl<TaPersonMapper, TaPerson> i
25 29
     public TaPerson getByOpenId(String openid) {
26 30
         return taPersonMapper.getByOpenId(openid);
27 31
     }
32
+
33
+    @Override
34
+    public TaPerson getByPhone(String phone) {
35
+        if (StringUtils.isEmpty(phone)) {
36
+            return null;
37
+        }
38
+
39
+        QueryWrapper<TaPerson> queryWrapper = new QueryWrapper<TaPerson>()
40
+                .eq("phone", phone)
41
+                .eq("status", StatusConstant.NORMAL);
42
+
43
+        return getOne(queryWrapper);
44
+    }
28 45
 }

+ 27
- 0
src/main/java/com/shigongli/service/impl/TaShopKeeperServiceImpl.java 查看文件

@@ -1,11 +1,16 @@
1 1
 package com.shigongli.service.impl;
2 2
 
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.shigongli.constants.StatusConstant;
5
+import com.shigongli.entity.TaPerson;
3 6
 import com.shigongli.entity.TaShopKeeper;
4 7
 import com.shigongli.mapper.TaShopKeeperMapper;
5 8
 import com.shigongli.service.ITaShopKeeperService;
6 9
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7 10
 import org.springframework.stereotype.Service;
8 11
 
12
+import java.util.List;
13
+
9 14
 /**
10 15
  * <p>
11 16
  * 店主 服务实现类
@@ -17,4 +22,26 @@ import org.springframework.stereotype.Service;
17 22
 @Service
18 23
 public class TaShopKeeperServiceImpl extends ServiceImpl<TaShopKeeperMapper, TaShopKeeper> implements ITaShopKeeperService {
19 24
 
25
+    @Override
26
+    public void bindPerson(TaPerson taPerson) {
27
+        List<TaShopKeeper> shopKeeperList = getByPhone(taPerson.getPhone());
28
+
29
+        if (null == shopKeeperList) {
30
+            return ;
31
+        }
32
+
33
+        for (TaShopKeeper shopKeeper: shopKeeperList) {
34
+            shopKeeper.setPersonId(taPerson.getPersonId());
35
+            updateById(shopKeeper);
36
+        }
37
+    }
38
+
39
+    @Override
40
+    public List<TaShopKeeper> getByPhone(String phone) {
41
+        QueryWrapper<TaShopKeeper> queryWrapper = new QueryWrapper<TaShopKeeper>()
42
+                .eq("phone", phone)
43
+                .eq("status", StatusConstant.NORMAL);
44
+
45
+        return list(queryWrapper);
46
+    }
20 47
 }

+ 20
- 0
src/main/java/com/shigongli/vo/AuthPhoneParams.java 查看文件

@@ -0,0 +1,20 @@
1
+package com.shigongli.vo;
2
+
3
+
4
+import io.swagger.annotations.ApiModel;
5
+import io.swagger.annotations.ApiModelProperty;
6
+import lombok.Data;
7
+
8
+@ApiModel(description = "授权手机参数")
9
+@Data
10
+public class AuthPhoneParams {
11
+
12
+    @ApiModelProperty("sessionKey")
13
+    String sessionKey;
14
+
15
+    @ApiModelProperty("encryptedData")
16
+    String encryptedData;
17
+
18
+    @ApiModelProperty("iv")
19
+    String iv;
20
+}

+ 1
- 1
src/main/java/com/shigongli/vo/ImageTagUpdateParams.java 查看文件

@@ -5,7 +5,7 @@ import io.swagger.annotations.ApiModel;
5 5
 import io.swagger.annotations.ApiModelProperty;
6 6
 import lombok.Data;
7 7
 
8
-@ApiModel(description = "登录参数")
8
+@ApiModel(description = "修改标签图片参数")
9 9
 @Data
10 10
 public class ImageTagUpdateParams {
11 11