|
@@ -11,6 +11,7 @@ import com.yunzhi.shigongli.service.ITaMiniappQrcodeService;
|
11
|
11
|
import com.yunzhi.shigongli.service.ITaPersonRecommenderService;
|
12
|
12
|
import com.yunzhi.shigongli.service.ITaPersonRoleService;
|
13
|
13
|
import com.yunzhi.shigongli.service.ITaPersonService;
|
|
14
|
+import com.yunzhi.shigongli.vo.WxLoginParam;
|
14
|
15
|
import com.yunzhi.shigongli.vo.WxMaAuthParam;
|
15
|
16
|
import io.swagger.annotations.Api;
|
16
|
17
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -18,6 +19,7 @@ import io.swagger.annotations.ApiParam;
|
18
|
19
|
import org.springframework.beans.factory.annotation.Autowired;
|
19
|
20
|
import org.springframework.web.bind.annotation.*;
|
20
|
21
|
|
|
22
|
+import java.time.LocalDateTime;
|
21
|
23
|
import java.util.*;
|
22
|
24
|
|
23
|
25
|
|
|
@@ -60,45 +62,62 @@ public class WxMaController extends BaseController {
|
60
|
62
|
result.put("openid", taPerson.getOpenid());
|
61
|
63
|
result.put("sessionKey", info.getSessionKey());
|
62
|
64
|
|
63
|
|
- if (!StringUtils.isEmpty(query)) {
|
64
|
|
- Map<String, String> params = StringUtils.parseQueryString(query);
|
65
|
|
-
|
66
|
|
- String fromType = params.get("fromType");
|
67
|
|
- String recommender = params.get("recommender");
|
68
|
|
- String qrCodeId = params.get("scene");
|
69
|
|
-
|
70
|
|
- // 如果是扫码进入
|
71
|
|
- if (!StringUtils.isEmpty(qrCodeId)) {
|
72
|
|
- TaMiniappQrcode miniappQrcode = miniappQrcodeService.getById(Integer.valueOf(qrCodeId));
|
73
|
|
- if (null != miniappQrcode) {
|
74
|
|
- String qrcodeParamStr = miniappQrcode.getScene();
|
75
|
|
- if (!StringUtils.isEmpty(qrcodeParamStr)) {
|
76
|
|
- // 把真正的参数返回
|
77
|
|
- result.put("qrcode", qrcodeParamStr);
|
78
|
|
- // 如果小程序码中有
|
79
|
|
- Map<String, String> qrcodeParams = StringUtils.parseQueryString(qrcodeParamStr);
|
80
|
|
- if (!StringUtils.isEmpty(qrcodeParams.get("id"))) {
|
81
|
|
- fromType = qrcodeParams.get("type");
|
82
|
|
- recommender = qrcodeParams.get("id");
|
83
|
|
- }
|
|
65
|
+ return ResponseBean.success(result);
|
|
66
|
+ }
|
|
67
|
+
|
|
68
|
+ @PostMapping("/login")
|
|
69
|
+ @ApiOperation(value="登录", notes = "登录", httpMethod = "POST", response = ResponseBean.class)
|
|
70
|
+ public ResponseBean login(@ApiParam("登录参数") @RequestBody WxLoginParam params) throws Exception {
|
|
71
|
+ if (StringUtils.isEmpty(params.getCode()) || StringUtils.isEmpty(params.getPersonId())) {
|
|
72
|
+ return ResponseBean.error("登录参数不能为空", ResponseBean.ERROR_MISSING_PARAMS);
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ // 返回值
|
|
76
|
+ Map<String, Object> rtn = new HashMap<>();
|
|
77
|
+
|
|
78
|
+ WxMaJscode2SessionResult info = wxUtils.getService().getUserService().getSessionInfo(params.getCode());
|
|
79
|
+ rtn.put("sessionKey", info.getSessionKey());
|
|
80
|
+
|
|
81
|
+ TaPerson taPerson = iTaPersonService.getById(params.getPersonId());
|
|
82
|
+ rtn.put("person", taPerson);
|
|
83
|
+
|
|
84
|
+ // 查询人员角色
|
|
85
|
+ List<TaPersonRole> roleList = personRoleService.getListByPerson(taPerson.getPersonId());
|
|
86
|
+ rtn.put("personRoleList", roleList);
|
|
87
|
+
|
|
88
|
+ String fromType = params.getFromType();
|
|
89
|
+ String recommender = params.getRecommender();
|
|
90
|
+ Integer qrCodeId = params.getQrCodeId();
|
|
91
|
+ if (null != qrCodeId && qrCodeId > 0) {
|
|
92
|
+ TaMiniappQrcode miniappQrcode = miniappQrcodeService.getById(qrCodeId);
|
|
93
|
+ if (null != miniappQrcode) {
|
|
94
|
+ String qrcodeParamStr = miniappQrcode.getScene();
|
|
95
|
+ if (!StringUtils.isEmpty(qrcodeParamStr)) {
|
|
96
|
+ // 把真正的参数返回
|
|
97
|
+ rtn.put("qrcode", qrcodeParamStr);
|
|
98
|
+ // 如果小程序码中有
|
|
99
|
+ Map<String, String> qrcodeParams = StringUtils.parseQueryString(qrcodeParamStr);
|
|
100
|
+ if (!StringUtils.isEmpty(qrcodeParams.get("id"))) {
|
|
101
|
+ fromType = qrcodeParams.get("type");
|
|
102
|
+ recommender = qrcodeParams.get("id");
|
84
|
103
|
}
|
85
|
104
|
}
|
86
|
105
|
}
|
|
106
|
+ }
|
87
|
107
|
|
88
|
|
- // 如果有推广ID, 比如民宿或者商铺
|
89
|
|
- if (!StringUtils.isEmpty(recommender)) {
|
90
|
|
- if (StringUtils.isEmpty(taPerson.getRecommender())) {
|
91
|
|
- taPerson.setFromType(fromType);
|
92
|
|
- taPerson.setRecommender(recommender);
|
93
|
|
- iTaPersonService.updateById(taPerson);
|
94
|
|
- }
|
|
108
|
+ // 如果有推广ID, 比如民宿或者商铺
|
|
109
|
+ if (!StringUtils.isEmpty(recommender)) {
|
|
110
|
+ if (StringUtils.isEmpty(taPerson.getRecommender())) {
|
|
111
|
+ taPerson.setFromType(fromType);
|
|
112
|
+ taPerson.setRecommender(recommender);
|
|
113
|
+ iTaPersonService.updateById(taPerson);
|
|
114
|
+ }
|
95
|
115
|
|
96
|
|
- // 写入推荐表
|
97
|
|
- try {
|
98
|
|
- recommenderService.addNewRecommender(taPerson.getPersonId(), fromType, recommender);
|
99
|
|
- } catch (Exception e) {
|
100
|
|
- e.printStackTrace();;
|
101
|
|
- }
|
|
116
|
+ // 写入推荐表
|
|
117
|
+ try {
|
|
118
|
+ recommenderService.addNewRecommender(taPerson.getPersonId(), fromType, recommender);
|
|
119
|
+ } catch (Exception e) {
|
|
120
|
+ e.printStackTrace();;
|
102
|
121
|
}
|
103
|
122
|
}
|
104
|
123
|
|
|
@@ -107,27 +126,7 @@ public class WxMaController extends BaseController {
|
107
|
126
|
tokenClaims.put("userId", taPerson.getPersonId());
|
108
|
127
|
tokenClaims.put("miniApp", true);
|
109
|
128
|
String authToken = JWTUtils.encode(tokenClaims);
|
110
|
|
- result.put("token", authToken);
|
111
|
|
-
|
112
|
|
- return ResponseBean.success(result);
|
113
|
|
- }
|
114
|
|
-
|
115
|
|
- @PostMapping("/login")
|
116
|
|
- @ApiOperation(value="登录", notes = "登录", httpMethod = "POST", response = ResponseBean.class)
|
117
|
|
- public ResponseBean login(@ApiParam("登录参数") @RequestParam String personId) throws Exception {
|
118
|
|
-// WxMaJscode2SessionResult info = wxUtils.getService().getUserService().getSessionInfo(code);
|
119
|
|
-//
|
120
|
|
-// String openid = info.getOpenid();
|
121
|
|
-// TaPerson taPerson = iTaPersonService.getByOpenid(openid);
|
122
|
|
- TaPerson taPerson = iTaPersonService.getById(personId);
|
123
|
|
-
|
124
|
|
- // 查询人员角色
|
125
|
|
- List<TaPersonRole> roleList = personRoleService.getListByPerson(taPerson.getPersonId());
|
126
|
|
-
|
127
|
|
- Map<String, Object> rtn = new HashMap<>();
|
128
|
|
- rtn.put("person", taPerson);
|
129
|
|
- rtn.put("personRoleList", roleList);
|
130
|
|
-// rtn.put("sessionKey", info.getSessionKey());
|
|
129
|
+ rtn.put("token", authToken);
|
131
|
130
|
|
132
|
131
|
return ResponseBean.success(rtn);
|
133
|
132
|
}
|