|
@@ -31,277 +31,279 @@ import java.util.List;
|
31
|
31
|
*/
|
32
|
32
|
@Service
|
33
|
33
|
public class TaPointsRecordsServiceImpl extends ServiceImpl<TaPointsRecordsMapper, TaPointsRecords> implements ITaPointsRecordsService {
|
34
|
|
- @Autowired
|
35
|
|
- TaPersonMapper taPersonMapper;
|
36
|
|
-
|
37
|
|
- @Autowired
|
38
|
|
- private TdPointsRulesMapper tdPointsRulesMapper;
|
39
|
|
-
|
40
|
|
- @Autowired
|
41
|
|
- private TaPointsRecordsMapper taPointsRecordsMapper;
|
42
|
|
-
|
43
|
|
- /**
|
44
|
|
- * 获取规则积分, 0 代表未启用
|
45
|
|
- * @param code
|
46
|
|
- * @return
|
47
|
|
- */
|
48
|
|
- @Override
|
49
|
|
- public Integer getRulePoints(String code,Integer orgId) {
|
50
|
|
- QueryWrapper<TdPointsRules> tdPointsRulesQueryWrapper = new QueryWrapper<>();
|
51
|
|
- tdPointsRulesQueryWrapper.eq("code",code);
|
52
|
|
- tdPointsRulesQueryWrapper.eq("org_id",orgId);
|
53
|
|
- tdPointsRulesQueryWrapper.eq("status",CommConstant.STATUS_NORMAL);
|
54
|
|
- TdPointsRules rule = tdPointsRulesMapper.selectOne(tdPointsRulesQueryWrapper);
|
55
|
|
- if (null == rule) {
|
56
|
|
- return 0;
|
57
|
|
- }
|
58
|
|
-
|
59
|
|
- Integer status = rule.getStatus();
|
60
|
|
- return null != status && status.equals(CommConstant.POINTS_RULE_ON) ? rule.getPointsAmount() : 0;
|
61
|
|
- }
|
62
|
|
-
|
63
|
|
- private boolean isPointsRecordsExist(String personId, String changeType, String changeParams) {
|
64
|
|
- QueryWrapper<TaPointsRecords> query = new QueryWrapper<>();
|
65
|
|
- query.eq("person_id", personId)
|
66
|
|
- .eq("change_type", changeType)
|
67
|
|
- .like(!StringUtils.isEmpty(changeParams), "change_params", changeParams)
|
68
|
|
- .eq("status", CommConstant.STATUS_NORMAL);
|
69
|
|
-
|
70
|
|
- Integer count = taPointsRecordsMapper.selectCount(query);
|
71
|
|
- return null != count && count > 0;
|
72
|
|
- }
|
73
|
|
-
|
74
|
|
- @Override
|
75
|
|
- public void sharePoints(TaShare taShare, Integer orgId) {
|
76
|
|
- //
|
77
|
|
- String changeType = CommConstant.POINTS_CHANGE_SHARE_POSTER;
|
78
|
|
-
|
79
|
|
- // 是否开启积分规则
|
80
|
|
- Integer pointsAmount = getRulePoints(changeType,orgId);
|
81
|
|
- if (pointsAmount == 0) {
|
82
|
|
- return;
|
83
|
|
- }
|
84
|
|
-
|
85
|
|
- // 已经领取过的不会再次领取
|
86
|
|
- String[] params = {
|
87
|
|
- "shareId="+String.valueOf(taShare.getShareId()),
|
88
|
|
- "openUser="+taShare.getOpenUser().getPersonId()
|
89
|
|
- };
|
90
|
|
- String changeParams = String.join("&", params);
|
91
|
|
- boolean hasJoined = isPointsRecordsExist(taShare.getPersonId(), changeType, changeParams);
|
92
|
|
- if (hasJoined) {
|
93
|
|
- return;
|
94
|
|
- }
|
95
|
|
-
|
96
|
|
- // 发放积分
|
97
|
|
- TaPerson person = taPersonMapper.selectById(taShare.getPersonId());
|
98
|
|
- if (savePoints(person, changeType, changeParams, pointsAmount, orgId)) {
|
99
|
|
- taPersonMapper.setFieldIncrement(person.getPersonId(), "points", pointsAmount);
|
100
|
|
- }
|
101
|
|
- }
|
102
|
|
-
|
103
|
|
- @Override
|
104
|
|
- public void sharePosterAll(String recommenderId, Integer orgId) {
|
105
|
|
- String changeType = CommConstant.POINTS_CHANGE_SHARE_POSTER;
|
106
|
|
- // 是否开启积分规则
|
107
|
|
- Integer pointsAmount = getRulePoints(changeType,orgId);
|
108
|
|
- if (pointsAmount == 0) {
|
109
|
|
- return;
|
110
|
|
- }
|
111
|
|
-
|
112
|
|
- String[] params = {
|
113
|
|
- "openUser="+recommenderId
|
114
|
|
- };
|
115
|
|
- String changeParams = String.join("&", params);
|
116
|
|
-
|
117
|
|
- // 发放积分
|
118
|
|
- TaPerson person = taPersonMapper.selectById(recommenderId);
|
119
|
|
- if (savePoints(person, changeType, changeParams, pointsAmount, orgId)) {
|
120
|
|
- taPersonMapper.setFieldIncrement(person.getPersonId(), "points", pointsAmount);
|
121
|
|
- }
|
122
|
|
- }
|
123
|
|
-
|
124
|
|
- @Override
|
125
|
|
- public void checkinPoints(TaPersonSign taPersonSign,Integer orgId) {
|
126
|
|
- //
|
127
|
|
- String changeType = CommConstant.POINTS_CHANGE_CHECKIN;
|
128
|
|
-
|
129
|
|
- // 是否开启积分规则
|
130
|
|
- Integer pointsAmount = getRulePoints(changeType,orgId);
|
131
|
|
- if (pointsAmount == 0) {
|
132
|
|
- return;
|
133
|
|
- }
|
134
|
|
-
|
135
|
|
- // 已经领取过的不会再次领取
|
136
|
|
- List<String> params = new ArrayList<String>() {{
|
137
|
|
- add("date="+DateUtils.today());
|
138
|
|
- add("user="+taPersonSign.getPerson().getPersonId());
|
139
|
|
- }};
|
140
|
|
- String changeParams = String.join("&", params);
|
141
|
|
- boolean hasJoined = isPointsRecordsExist(taPersonSign.getPerson().getPersonId(), changeType, changeParams);
|
142
|
|
- if (hasJoined) {
|
143
|
|
- return;
|
144
|
|
- }
|
145
|
|
-
|
146
|
|
- // 添加参数
|
147
|
|
- params.add("recId="+taPersonSign.getRecId());
|
148
|
|
- changeParams = String.join("&", params);
|
149
|
|
-
|
150
|
|
-
|
151
|
|
- // 增加积分
|
152
|
|
- // 1-7 天积分 1-7, 超过7天按 7 个积分算
|
|
34
|
+
|
|
35
|
+ @Autowired
|
|
36
|
+ TaPersonMapper taPersonMapper;
|
|
37
|
+
|
|
38
|
+ @Autowired
|
|
39
|
+ private TdPointsRulesMapper tdPointsRulesMapper;
|
|
40
|
+
|
|
41
|
+ @Autowired
|
|
42
|
+ private TaPointsRecordsMapper taPointsRecordsMapper;
|
|
43
|
+
|
|
44
|
+ /**
|
|
45
|
+ * 获取规则积分, 0 代表未启用
|
|
46
|
+ *
|
|
47
|
+ * @param code
|
|
48
|
+ * @return
|
|
49
|
+ */
|
|
50
|
+ @Override
|
|
51
|
+ public Integer getRulePoints(String code, Integer orgId) {
|
|
52
|
+ QueryWrapper<TdPointsRules> tdPointsRulesQueryWrapper = new QueryWrapper<>();
|
|
53
|
+ tdPointsRulesQueryWrapper.eq("code", code);
|
|
54
|
+ tdPointsRulesQueryWrapper.eq("org_id", orgId);
|
|
55
|
+ tdPointsRulesQueryWrapper.eq("status", CommConstant.STATUS_NORMAL);
|
|
56
|
+ TdPointsRules rule = tdPointsRulesMapper.selectOne(tdPointsRulesQueryWrapper);
|
|
57
|
+ if (null == rule) {
|
|
58
|
+ return 0;
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ Integer status = rule.getStatus();
|
|
62
|
+ return null != status && status.equals(CommConstant.POINTS_RULE_ON) ? rule.getPointsAmount() : 0;
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ private boolean isPointsRecordsExist(String personId, String changeType, String changeParams) {
|
|
66
|
+ QueryWrapper<TaPointsRecords> query = new QueryWrapper<>();
|
|
67
|
+ query.eq("person_id", personId)
|
|
68
|
+ .eq("change_type", changeType)
|
|
69
|
+ .like(!StringUtils.isEmpty(changeParams), "change_params", changeParams)
|
|
70
|
+ .eq("status", CommConstant.STATUS_NORMAL);
|
|
71
|
+
|
|
72
|
+ Integer count = taPointsRecordsMapper.selectCount(query);
|
|
73
|
+ return null != count && count > 0;
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ @Override
|
|
77
|
+ public void sharePoints(TaShare taShare, Integer orgId) {
|
|
78
|
+ //
|
|
79
|
+ String changeType = CommConstant.POINTS_CHANGE_SHARE_POSTER;
|
|
80
|
+
|
|
81
|
+ // 是否开启积分规则
|
|
82
|
+ Integer pointsAmount = getRulePoints(changeType, orgId);
|
|
83
|
+ if (pointsAmount == 0) {
|
|
84
|
+ return;
|
|
85
|
+ }
|
|
86
|
+
|
|
87
|
+ // 已经领取过的不会再次领取
|
|
88
|
+ String[] params = {
|
|
89
|
+ "shareId=" + String.valueOf(taShare.getShareId()),
|
|
90
|
+ "openUser=" + taShare.getOpenUser().getPersonId()
|
|
91
|
+ };
|
|
92
|
+ String changeParams = String.join("&", params);
|
|
93
|
+ boolean hasJoined = isPointsRecordsExist(taShare.getPersonId(), changeType, changeParams);
|
|
94
|
+ if (hasJoined) {
|
|
95
|
+ return;
|
|
96
|
+ }
|
|
97
|
+
|
|
98
|
+ // 发放积分
|
|
99
|
+ TaPerson person = taPersonMapper.selectById(taShare.getPersonId());
|
|
100
|
+ if (savePoints(person, changeType, changeParams, pointsAmount, orgId)) {
|
|
101
|
+ taPersonMapper.setPointsIncrement(person.getPersonId(), pointsAmount);
|
|
102
|
+ }
|
|
103
|
+ }
|
|
104
|
+
|
|
105
|
+ @Override
|
|
106
|
+ public void sharePosterAll(String recommenderId, Integer orgId) {
|
|
107
|
+ String changeType = CommConstant.POINTS_CHANGE_SHARE_POSTER;
|
|
108
|
+ // 是否开启积分规则
|
|
109
|
+ Integer pointsAmount = getRulePoints(changeType, orgId);
|
|
110
|
+ if (pointsAmount == 0) {
|
|
111
|
+ return;
|
|
112
|
+ }
|
|
113
|
+
|
|
114
|
+ String[] params = {
|
|
115
|
+ "openUser=" + recommenderId
|
|
116
|
+ };
|
|
117
|
+ String changeParams = String.join("&", params);
|
|
118
|
+
|
|
119
|
+ // 发放积分
|
|
120
|
+ TaPerson person = taPersonMapper.selectById(recommenderId);
|
|
121
|
+ if (savePoints(person, changeType, changeParams, pointsAmount, orgId)) {
|
|
122
|
+ taPersonMapper.setPointsIncrement(person.getPersonId(), pointsAmount);
|
|
123
|
+ }
|
|
124
|
+ }
|
|
125
|
+
|
|
126
|
+ @Override
|
|
127
|
+ public void checkinPoints(TaPersonSign taPersonSign, Integer orgId) {
|
|
128
|
+ //
|
|
129
|
+ String changeType = CommConstant.POINTS_CHANGE_CHECKIN;
|
|
130
|
+
|
|
131
|
+ // 是否开启积分规则
|
|
132
|
+ Integer pointsAmount = getRulePoints(changeType, orgId);
|
|
133
|
+ if (pointsAmount == 0) {
|
|
134
|
+ return;
|
|
135
|
+ }
|
|
136
|
+
|
|
137
|
+ // 已经领取过的不会再次领取
|
|
138
|
+ List<String> params = new ArrayList<String>() {{
|
|
139
|
+ add("date=" + DateUtils.today());
|
|
140
|
+ add("user=" + taPersonSign.getPerson().getPersonId());
|
|
141
|
+ }};
|
|
142
|
+ String changeParams = String.join("&", params);
|
|
143
|
+ boolean hasJoined = isPointsRecordsExist(taPersonSign.getPerson().getPersonId(), changeType, changeParams);
|
|
144
|
+ if (hasJoined) {
|
|
145
|
+ return;
|
|
146
|
+ }
|
|
147
|
+
|
|
148
|
+ // 添加参数
|
|
149
|
+ params.add("recId=" + taPersonSign.getRecId());
|
|
150
|
+ changeParams = String.join("&", params);
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+ // 增加积分
|
|
154
|
+ // 1-7 天积分 1-7, 超过7天按 7 个积分算
|
153
|
155
|
// Integer durationDays = taPersonSign.getDurationDays();
|
154
|
156
|
// int points = durationDays >= 7 ? 7 : durationDays;
|
155
|
157
|
|
156
|
|
- // 发放积分
|
157
|
|
- TaPerson person = taPersonMapper.selectById(taPersonSign.getPersonId());
|
158
|
|
- if (savePoints(person, changeType, changeParams, pointsAmount, orgId)) {
|
159
|
|
- taPersonMapper.setFieldIncrement(person.getPersonId(), "points", pointsAmount);
|
160
|
|
- }
|
161
|
|
- }
|
162
|
|
-
|
163
|
|
- @Override
|
164
|
|
- public void checkinActivityPoints(TaActivityDynamicEnlist taActivityDynamicEnlist, Integer orgId){
|
165
|
|
- String changeType =CommConstant.POINTS_CHANGE_ACTIVITY_CHECKIN;
|
166
|
|
- // 是否开启积分规则
|
167
|
|
- Integer pointsAmount = getRulePoints(changeType,orgId);
|
168
|
|
- if (pointsAmount == 0) {
|
169
|
|
- return;
|
170
|
|
- }
|
171
|
|
-
|
172
|
|
- // 已经领取过的不会再次领取
|
173
|
|
- List<String> params = new ArrayList<String>() {{
|
174
|
|
- add("user="+taActivityDynamicEnlist.getPersonId());
|
175
|
|
- add("targetId="+taActivityDynamicEnlist.getEnlistId().toString());
|
176
|
|
- }};
|
177
|
|
- String changeParams = String.join("&", params);
|
178
|
|
- boolean hasJoined = isPointsRecordsExist(taActivityDynamicEnlist.getPersonId(), changeType, changeParams);
|
179
|
|
- if (hasJoined) {
|
180
|
|
- return;
|
181
|
|
- }
|
182
|
|
- // 添加参数
|
183
|
|
- params.add("enlistId="+taActivityDynamicEnlist.getEnlistId());
|
184
|
|
- changeParams = String.join("&", params);
|
185
|
|
-
|
186
|
|
- // 发放积分
|
187
|
|
- TaPerson person = taPersonMapper.selectById(taActivityDynamicEnlist.getPersonId());
|
188
|
|
- if (savePoints(person, changeType, changeParams, pointsAmount, orgId)) {
|
189
|
|
- taPersonMapper.setFieldIncrement(person.getPersonId(), "points", pointsAmount);
|
190
|
|
- }
|
191
|
|
- }
|
192
|
|
-
|
193
|
|
- @Override
|
194
|
|
- public void signUpPoints(TaPerson taPerson, Integer orgId) {
|
195
|
|
- //
|
196
|
|
- String changeType = CommConstant.POINTS_CHANGE_SIGNUP_AGENT;
|
197
|
|
- // 是否开启积分规则
|
198
|
|
- Integer pointsAmount = getRulePoints(changeType,orgId);
|
199
|
|
- if (pointsAmount == 0) {
|
200
|
|
- return;
|
201
|
|
- }
|
202
|
|
-
|
203
|
|
- // 已经领取过的不会再次领取
|
204
|
|
- List<String> params = new ArrayList<String>() {{
|
205
|
|
- add("user="+taPerson.getPersonId());
|
206
|
|
- }};
|
207
|
|
- String changeParams = String.join("&", params);
|
208
|
|
- boolean hasJoined = isPointsRecordsExist(taPerson.getPersonId(), changeType, changeParams);
|
209
|
|
- if (hasJoined) {
|
210
|
|
- return;
|
211
|
|
- }
|
212
|
|
-
|
213
|
|
- // 发放积分
|
214
|
|
- if (savePoints(taPerson, changeType, changeParams, pointsAmount, orgId)) {
|
215
|
|
- taPersonMapper.setFieldIncrement(taPerson.getPersonId(), "points", pointsAmount);
|
216
|
|
- }
|
217
|
|
- }
|
218
|
|
-
|
219
|
|
- @Override
|
220
|
|
- public void recommendCustPoints(TaRecommendCustomer taRecommendCustomer, Integer orgId) {
|
221
|
|
- //
|
222
|
|
- String changeType = CommConstant.POINTS_CHANGE_RECOMMEND_CUSTOMER;
|
223
|
|
-
|
224
|
|
- // 是否开启积分规则
|
225
|
|
- Integer pointsAmount = getRulePoints(changeType,orgId);
|
226
|
|
- if (pointsAmount == 0) {
|
227
|
|
- return;
|
228
|
|
- }
|
229
|
|
-
|
230
|
|
- // 已经领取过的不会再次领取
|
231
|
|
- List<String> params = new ArrayList<String>() {{
|
232
|
|
- // 推荐人
|
233
|
|
- add("person="+taRecommendCustomer.getRecommendPerson());
|
234
|
|
- // 推荐客户手机
|
235
|
|
- add("phone="+taRecommendCustomer.getPhone());
|
236
|
|
- }};
|
237
|
|
- String changeParams = String.join("&", params);
|
238
|
|
- boolean hasJoined = isPointsRecordsExist(taRecommendCustomer.getRecommendPerson(), changeType, changeParams);
|
239
|
|
- if (hasJoined) {
|
240
|
|
- return;
|
241
|
|
- }
|
242
|
|
-
|
243
|
|
- // 发放积分
|
244
|
|
- TaPerson taPerson = taPersonMapper.getById(taRecommendCustomer.getRecommendPerson());
|
245
|
|
- if (null != taPerson && savePoints(taPerson, changeType, changeParams, pointsAmount, orgId)) {
|
246
|
|
- taPersonMapper.setFieldIncrement(taPerson.getPersonId(), "points", pointsAmount);
|
247
|
|
- }
|
248
|
|
- }
|
249
|
|
-
|
250
|
|
- @Override
|
251
|
|
- public IPage<TaPointsRecords> getWxRecords(Integer pageNum, Integer pageSize,String personId){
|
252
|
|
- IPage<TaPointsRecords> pg = new Page<>(pageNum, pageSize);
|
253
|
|
- return taPointsRecordsMapper.getCustomerPointsList(pg,personId);
|
254
|
|
- }
|
255
|
|
-
|
256
|
|
- @Override
|
257
|
|
- public void consumeGoodsPoints(TaGoods taGoods, Integer orgId) {
|
258
|
|
- Integer minusPoints = taGoods.getPointPrice();
|
259
|
|
- if (null == minusPoints || minusPoints <= 0) {
|
260
|
|
- return;
|
261
|
|
- }
|
262
|
|
-
|
263
|
|
- TaPerson taPerson = taGoods.getExchanger();
|
264
|
|
- Integer origPoints = taPerson.getPoints();
|
265
|
|
- if (null == origPoints) {
|
266
|
|
- origPoints = 0;
|
267
|
|
- }
|
268
|
|
-
|
269
|
|
- // 积分不足
|
270
|
|
- if (minusPoints > origPoints) {
|
271
|
|
- return;
|
272
|
|
- }
|
273
|
|
-
|
274
|
|
- String[] params = {
|
275
|
|
- "person="+taPerson.getPersonId(),
|
276
|
|
- "goods="+String.valueOf(taGoods.getGoodsId()),
|
277
|
|
- "points="+String.valueOf(minusPoints)
|
278
|
|
- };
|
279
|
|
- String changeParams = String.join("&", params);
|
280
|
|
-
|
281
|
|
- // 发放积分
|
282
|
|
- Integer pointsAmount = 0 - minusPoints;
|
283
|
|
- if (savePoints(taPerson, CommConstant.POINTS_CHANGE_GOODS, changeParams, pointsAmount, orgId)) {
|
284
|
|
- taPersonMapper.setFieldIncrement(taPerson.getPersonId(), "points", pointsAmount);
|
285
|
|
- }
|
286
|
|
- }
|
287
|
|
-
|
288
|
|
- private boolean savePoints(TaPerson person, String changeType, String changeParams, Integer pointsAmount, Integer orgId) {
|
289
|
|
- if (null == person){
|
290
|
|
- return true;
|
291
|
|
- }
|
292
|
|
- TaPointsRecords taPointsRecords = new TaPointsRecords();
|
293
|
|
- taPointsRecords.setPersonId(person.getPersonId());
|
294
|
|
- taPointsRecords.setPersonName(StringUtils.ifNull(person.getName(),person.getNickname()));
|
295
|
|
- taPointsRecords.setPersonType(person.getPersonType());
|
296
|
|
- taPointsRecords.setPointsAmount(pointsAmount);
|
297
|
|
- taPointsRecords.setChangeType(changeType);
|
298
|
|
- taPointsRecords.setChangeParams(changeParams);
|
299
|
|
- taPointsRecords.setStatus(CommConstant.STATUS_NORMAL);
|
300
|
|
- taPointsRecords.setCreateDate(LocalDateTime.now());
|
301
|
|
- taPointsRecords.setOrgId(orgId);
|
302
|
|
-
|
303
|
|
- return taPointsRecordsMapper.insert(taPointsRecords) > 0;
|
304
|
|
- }
|
|
158
|
+ // 发放积分
|
|
159
|
+ TaPerson person = taPersonMapper.selectById(taPersonSign.getPersonId());
|
|
160
|
+ if (savePoints(person, changeType, changeParams, pointsAmount, orgId)) {
|
|
161
|
+ taPersonMapper.setPointsIncrement(person.getPersonId(), pointsAmount);
|
|
162
|
+ }
|
|
163
|
+ }
|
|
164
|
+
|
|
165
|
+ @Override
|
|
166
|
+ public void checkinActivityPoints(TaActivityDynamicEnlist taActivityDynamicEnlist, Integer orgId) {
|
|
167
|
+ String changeType = CommConstant.POINTS_CHANGE_ACTIVITY_CHECKIN;
|
|
168
|
+ // 是否开启积分规则
|
|
169
|
+ Integer pointsAmount = getRulePoints(changeType, orgId);
|
|
170
|
+ if (pointsAmount == 0) {
|
|
171
|
+ return;
|
|
172
|
+ }
|
|
173
|
+
|
|
174
|
+ // 已经领取过的不会再次领取
|
|
175
|
+ List<String> params = new ArrayList<String>() {{
|
|
176
|
+ add("user=" + taActivityDynamicEnlist.getPersonId());
|
|
177
|
+ add("targetId=" + taActivityDynamicEnlist.getEnlistId().toString());
|
|
178
|
+ }};
|
|
179
|
+ String changeParams = String.join("&", params);
|
|
180
|
+ boolean hasJoined = isPointsRecordsExist(taActivityDynamicEnlist.getPersonId(), changeType, changeParams);
|
|
181
|
+ if (hasJoined) {
|
|
182
|
+ return;
|
|
183
|
+ }
|
|
184
|
+ // 添加参数
|
|
185
|
+ params.add("enlistId=" + taActivityDynamicEnlist.getEnlistId());
|
|
186
|
+ changeParams = String.join("&", params);
|
|
187
|
+
|
|
188
|
+ // 发放积分
|
|
189
|
+ TaPerson person = taPersonMapper.selectById(taActivityDynamicEnlist.getPersonId());
|
|
190
|
+ if (savePoints(person, changeType, changeParams, pointsAmount, orgId)) {
|
|
191
|
+ taPersonMapper.setPointsIncrement(person.getPersonId(), pointsAmount);
|
|
192
|
+ }
|
|
193
|
+ }
|
|
194
|
+
|
|
195
|
+ @Override
|
|
196
|
+ public void signUpPoints(TaPerson taPerson, Integer orgId) {
|
|
197
|
+ //
|
|
198
|
+ String changeType = CommConstant.POINTS_CHANGE_SIGNUP_AGENT;
|
|
199
|
+ // 是否开启积分规则
|
|
200
|
+ Integer pointsAmount = getRulePoints(changeType, orgId);
|
|
201
|
+ if (pointsAmount == 0) {
|
|
202
|
+ return;
|
|
203
|
+ }
|
|
204
|
+
|
|
205
|
+ // 已经领取过的不会再次领取
|
|
206
|
+ List<String> params = new ArrayList<String>() {{
|
|
207
|
+ add("user=" + taPerson.getPersonId());
|
|
208
|
+ }};
|
|
209
|
+ String changeParams = String.join("&", params);
|
|
210
|
+ boolean hasJoined = isPointsRecordsExist(taPerson.getPersonId(), changeType, changeParams);
|
|
211
|
+ if (hasJoined) {
|
|
212
|
+ return;
|
|
213
|
+ }
|
|
214
|
+
|
|
215
|
+ // 发放积分
|
|
216
|
+ if (savePoints(taPerson, changeType, changeParams, pointsAmount, orgId)) {
|
|
217
|
+ taPersonMapper.setPointsIncrement(taPerson.getPersonId(), pointsAmount);
|
|
218
|
+ }
|
|
219
|
+ }
|
|
220
|
+
|
|
221
|
+ @Override
|
|
222
|
+ public void recommendCustPoints(TaRecommendCustomer taRecommendCustomer, Integer orgId) {
|
|
223
|
+ //
|
|
224
|
+ String changeType = CommConstant.POINTS_CHANGE_RECOMMEND_CUSTOMER;
|
|
225
|
+
|
|
226
|
+ // 是否开启积分规则
|
|
227
|
+ Integer pointsAmount = getRulePoints(changeType, orgId);
|
|
228
|
+ if (pointsAmount == 0) {
|
|
229
|
+ return;
|
|
230
|
+ }
|
|
231
|
+
|
|
232
|
+ // 已经领取过的不会再次领取
|
|
233
|
+ List<String> params = new ArrayList<String>() {{
|
|
234
|
+ // 推荐人
|
|
235
|
+ add("person=" + taRecommendCustomer.getRecommendPerson());
|
|
236
|
+ // 推荐客户手机
|
|
237
|
+ add("phone=" + taRecommendCustomer.getPhone());
|
|
238
|
+ }};
|
|
239
|
+ String changeParams = String.join("&", params);
|
|
240
|
+ boolean hasJoined = isPointsRecordsExist(taRecommendCustomer.getRecommendPerson(), changeType, changeParams);
|
|
241
|
+ if (hasJoined) {
|
|
242
|
+ return;
|
|
243
|
+ }
|
|
244
|
+
|
|
245
|
+ // 发放积分
|
|
246
|
+ TaPerson taPerson = taPersonMapper.getById(taRecommendCustomer.getRecommendPerson());
|
|
247
|
+ if (null != taPerson && savePoints(taPerson, changeType, changeParams, pointsAmount, orgId)) {
|
|
248
|
+ taPersonMapper.setPointsIncrement(taPerson.getPersonId(), pointsAmount);
|
|
249
|
+ }
|
|
250
|
+ }
|
|
251
|
+
|
|
252
|
+ @Override
|
|
253
|
+ public IPage<TaPointsRecords> getWxRecords(Integer pageNum, Integer pageSize, String personId) {
|
|
254
|
+ IPage<TaPointsRecords> pg = new Page<>(pageNum, pageSize);
|
|
255
|
+ return taPointsRecordsMapper.getCustomerPointsList(pg, personId);
|
|
256
|
+ }
|
|
257
|
+
|
|
258
|
+ @Override
|
|
259
|
+ public void consumeGoodsPoints(TaGoods taGoods, Integer orgId) {
|
|
260
|
+ Integer minusPoints = taGoods.getPointPrice();
|
|
261
|
+ if (null == minusPoints || minusPoints <= 0) {
|
|
262
|
+ return;
|
|
263
|
+ }
|
|
264
|
+
|
|
265
|
+ TaPerson taPerson = taGoods.getExchanger();
|
|
266
|
+ Integer origPoints = taPerson.getPoints();
|
|
267
|
+ if (null == origPoints) {
|
|
268
|
+ origPoints = 0;
|
|
269
|
+ }
|
|
270
|
+
|
|
271
|
+ // 积分不足
|
|
272
|
+ if (minusPoints > origPoints) {
|
|
273
|
+ return;
|
|
274
|
+ }
|
|
275
|
+
|
|
276
|
+ String[] params = {
|
|
277
|
+ "person=" + taPerson.getPersonId(),
|
|
278
|
+ "goods=" + String.valueOf(taGoods.getGoodsId()),
|
|
279
|
+ "points=" + String.valueOf(minusPoints)
|
|
280
|
+ };
|
|
281
|
+ String changeParams = String.join("&", params);
|
|
282
|
+
|
|
283
|
+ // 发放积分
|
|
284
|
+ Integer pointsAmount = 0 - minusPoints;
|
|
285
|
+ if (savePoints(taPerson, CommConstant.POINTS_CHANGE_GOODS, changeParams, pointsAmount, orgId)) {
|
|
286
|
+ taPersonMapper.setPointsIncrement(taPerson.getPersonId(), pointsAmount);
|
|
287
|
+ }
|
|
288
|
+ }
|
|
289
|
+
|
|
290
|
+ private boolean savePoints(TaPerson person, String changeType, String changeParams, Integer pointsAmount, Integer orgId) {
|
|
291
|
+ if (null == person) {
|
|
292
|
+ return true;
|
|
293
|
+ }
|
|
294
|
+ TaPointsRecords taPointsRecords = new TaPointsRecords();
|
|
295
|
+ taPointsRecords.setPersonId(person.getPersonId());
|
|
296
|
+ taPointsRecords.setPersonName(StringUtils.ifNull(person.getName(), person.getNickname()));
|
|
297
|
+ taPointsRecords.setPersonType(person.getPersonType());
|
|
298
|
+ taPointsRecords.setPointsAmount(pointsAmount);
|
|
299
|
+ taPointsRecords.setChangeType(changeType);
|
|
300
|
+ taPointsRecords.setChangeParams(changeParams);
|
|
301
|
+ taPointsRecords.setStatus(CommConstant.STATUS_NORMAL);
|
|
302
|
+ taPointsRecords.setCreateDate(LocalDateTime.now());
|
|
303
|
+ taPointsRecords.setOrgId(orgId);
|
|
304
|
+
|
|
305
|
+ return taPointsRecordsMapper.insert(taPointsRecords) > 0;
|
|
306
|
+ }
|
305
|
307
|
|
306
|
308
|
// @Override
|
307
|
309
|
// public void authPoints(String personId) {
|
|
@@ -316,120 +318,120 @@ public class TaPointsRecordsServiceImpl extends ServiceImpl<TaPointsRecordsMappe
|
316
|
318
|
// sendPoints(person,4,CommConstant.POINTS_AUTHORIZE);
|
317
|
319
|
// }
|
318
|
320
|
// }
|
319
|
|
-
|
320
|
|
- private void sendPoints(TaPerson person,Integer rulesId,String shareType, Integer orgId) {
|
321
|
|
- //发放积分
|
322
|
|
- QueryWrapper<TdPointsRules> queryWrapper = new QueryWrapper<>();
|
323
|
|
- queryWrapper.eq("rule_id",rulesId);
|
324
|
|
- queryWrapper.eq("status", CommConstant.STATUS_NORMAL);
|
325
|
|
- TdPointsRules tdPointsRules = tdPointsRulesMapper.selectOne(queryWrapper);
|
326
|
|
- if (null != tdPointsRules) {
|
327
|
|
- //插入积分消费流水表
|
328
|
|
- TaPointsRecords taPointsRecords = new TaPointsRecords();
|
329
|
|
- taPointsRecords.setPersonId(person.getPersonId());
|
330
|
|
- taPointsRecords.setPersonName(com.huiju.estateagents.common.StringUtils.ifNull(person.getName(),person.getNickname()));
|
331
|
|
- taPointsRecords.setPersonType(person.getPersonType());
|
332
|
|
- taPointsRecords.setPointsAmount(tdPointsRules.getPointsAmount());
|
333
|
|
- taPointsRecords.setChangeType(shareType);
|
334
|
|
- JSONObject jsonObject = new JSONObject();
|
335
|
|
- jsonObject.put("person_id",person.getPersonId());
|
336
|
|
- taPointsRecords.setChangeParams(jsonObject.toJSONString());
|
337
|
|
- taPointsRecords.setCreateDate(LocalDateTime.now());
|
338
|
|
- taPointsRecords.setStatus(CommConstant.STATUS_NORMAL);
|
339
|
|
- taPointsRecords.setOrgId(orgId);
|
340
|
|
- taPointsRecordsMapper.insert(taPointsRecords);
|
341
|
|
- //添加积分
|
342
|
|
- UpdateWrapper<TaPerson> taPersonwrapper = new UpdateWrapper<>();
|
343
|
|
- taPersonwrapper.eq("person_id", person.getPersonId());
|
344
|
|
- taPersonwrapper.setSql("points = IFNULL(points, 0) + " + String.valueOf(tdPointsRules.getPointsAmount()));
|
345
|
|
- taPersonMapper.update(new TaPerson(), taPersonwrapper);
|
346
|
|
- }
|
347
|
|
- }
|
348
|
|
-
|
349
|
|
-
|
350
|
|
- @Override
|
351
|
|
- public void documentVerify(TaDocumentVerify taDocumentVerify, Integer orgId) {
|
352
|
|
- //
|
353
|
|
- String changeType = CommConstant.POINTS_CHANGE_DOCUMENT_VERIFY;
|
354
|
|
- // 是否开启积分规则
|
355
|
|
- Integer pointsAmount = getRulePoints(changeType,orgId);
|
356
|
|
- if (pointsAmount == 0) {
|
357
|
|
- return;
|
358
|
|
- }
|
359
|
|
-
|
360
|
|
- // 已经领取过的不会再次领取
|
361
|
|
- String[] params = {
|
362
|
|
- "shareId="+String.valueOf(taDocumentVerify.getDocumentVerifyId()),
|
363
|
|
- "openUser="+taDocumentVerify.getPersonId()
|
364
|
|
- };
|
365
|
|
- String changeParams = String.join("&", params);
|
366
|
|
- boolean hasJoined = isPointsRecordsExist(taDocumentVerify.getPersonId(), changeType, changeParams);
|
367
|
|
- if (hasJoined) {
|
368
|
|
- return;
|
369
|
|
- }
|
370
|
|
-
|
371
|
|
- // 发放积分
|
372
|
|
- TaPerson person = taPersonMapper.selectById(taDocumentVerify.getPersonId());
|
373
|
|
- if (savePoints(person, changeType, changeParams, pointsAmount, orgId)) {
|
374
|
|
- taPersonMapper.setFieldIncrement(person.getPersonId(), "points", pointsAmount);
|
375
|
|
- }
|
376
|
|
- }
|
377
|
|
-
|
378
|
|
- @Override
|
379
|
|
- public void activityVerificationSign(HelpInitiateRecord helpInitiateRecord, Integer orgId) {
|
380
|
|
- //
|
381
|
|
- String changeType = CommConstant.POINTS_CHANGE_ACTIVITY_VERIFICATION;
|
382
|
|
- // 是否开启积分规则
|
383
|
|
- Integer pointsAmount = getRulePoints(changeType,orgId);
|
384
|
|
- if (pointsAmount == 0) {
|
385
|
|
- return;
|
386
|
|
- }
|
387
|
|
-
|
388
|
|
-
|
389
|
|
-
|
390
|
|
- // 已经领取过的不会再次领取
|
391
|
|
- String[] params = {
|
392
|
|
- "shareId="+String.valueOf(helpInitiateRecord.getHelpRecordInitiateId()),
|
393
|
|
- "openUser="+helpInitiateRecord.getPersonId()
|
394
|
|
- };
|
395
|
|
- String changeParams = String.join("&", params);
|
396
|
|
- boolean hasJoined = isPointsRecordsExist(helpInitiateRecord.getPersonId(), changeType, changeParams);
|
397
|
|
- if (hasJoined) {
|
398
|
|
- return;
|
399
|
|
- }
|
400
|
|
-
|
401
|
|
- // 发放积分
|
402
|
|
- TaPerson person = taPersonMapper.selectById(helpInitiateRecord.getPersonId());
|
403
|
|
- if (savePoints(person, changeType, changeParams, pointsAmount, orgId)) {
|
404
|
|
- taPersonMapper.setFieldIncrement(person.getPersonId(), "points", pointsAmount);
|
405
|
|
- }
|
406
|
|
- }
|
407
|
|
-
|
408
|
|
- /**
|
409
|
|
- * 消费拼团积分
|
410
|
|
- * @param person
|
411
|
|
- * @param integral
|
412
|
|
- * @param buildingId
|
413
|
|
- * @param groupActivityId
|
414
|
|
- */
|
415
|
|
- @Override
|
416
|
|
- public void saveGroupRecord(TaPerson person, Integer integral, String buildingId, Integer groupActivityId) {
|
417
|
|
- TaPointsRecords taPointsRecords = new TaPointsRecords();
|
418
|
|
- taPointsRecords.setPersonId(person.getPersonId());
|
419
|
|
- taPointsRecords.setPersonName(person.getNickname());
|
420
|
|
- taPointsRecords.setPersonType(person.getPersonType());
|
421
|
|
- taPointsRecords.setPointsAmount(-integral);
|
422
|
|
- taPointsRecords.setChangeType(CommConstant.POINTS_CHANGE_GROUP);
|
423
|
|
- taPointsRecords.setChangeParams("{\"group_activity_id\":"+groupActivityId+"}");
|
424
|
|
- taPointsRecords.setCreateDate(LocalDateTime.now());
|
425
|
|
- taPointsRecords.setOrgId(person.getOrgId());
|
426
|
|
- taPointsRecords.setBuildingId(buildingId);
|
427
|
|
- taPointsRecords.setStatus(CommConstant.STATUS_NORMAL);
|
428
|
|
- taPointsRecordsMapper.insert(taPointsRecords);
|
429
|
|
- }
|
430
|
|
-
|
431
|
|
- @Override
|
432
|
|
- public Integer sumPointByPersonId(String personId) {
|
433
|
|
- return taPointsRecordsMapper.sumPointByPersonId(personId);
|
434
|
|
- }
|
|
321
|
+
|
|
322
|
+ private void sendPoints(TaPerson person, Integer rulesId, String shareType, Integer orgId) {
|
|
323
|
+ //发放积分
|
|
324
|
+ QueryWrapper<TdPointsRules> queryWrapper = new QueryWrapper<>();
|
|
325
|
+ queryWrapper.eq("rule_id", rulesId);
|
|
326
|
+ queryWrapper.eq("status", CommConstant.STATUS_NORMAL);
|
|
327
|
+ TdPointsRules tdPointsRules = tdPointsRulesMapper.selectOne(queryWrapper);
|
|
328
|
+ if (null != tdPointsRules) {
|
|
329
|
+ //插入积分消费流水表
|
|
330
|
+ TaPointsRecords taPointsRecords = new TaPointsRecords();
|
|
331
|
+ taPointsRecords.setPersonId(person.getPersonId());
|
|
332
|
+ taPointsRecords.setPersonName(com.huiju.estateagents.common.StringUtils.ifNull(person.getName(), person.getNickname()));
|
|
333
|
+ taPointsRecords.setPersonType(person.getPersonType());
|
|
334
|
+ taPointsRecords.setPointsAmount(tdPointsRules.getPointsAmount());
|
|
335
|
+ taPointsRecords.setChangeType(shareType);
|
|
336
|
+ JSONObject jsonObject = new JSONObject();
|
|
337
|
+ jsonObject.put("person_id", person.getPersonId());
|
|
338
|
+ taPointsRecords.setChangeParams(jsonObject.toJSONString());
|
|
339
|
+ taPointsRecords.setCreateDate(LocalDateTime.now());
|
|
340
|
+ taPointsRecords.setStatus(CommConstant.STATUS_NORMAL);
|
|
341
|
+ taPointsRecords.setOrgId(orgId);
|
|
342
|
+ taPointsRecordsMapper.insert(taPointsRecords);
|
|
343
|
+ //添加积分
|
|
344
|
+ UpdateWrapper<TaPerson> taPersonwrapper = new UpdateWrapper<>();
|
|
345
|
+ taPersonwrapper.eq("person_id", person.getPersonId());
|
|
346
|
+ taPersonwrapper.setSql("points = IFNULL(points, 0) + " + String.valueOf(tdPointsRules.getPointsAmount()));
|
|
347
|
+ taPersonMapper.update(new TaPerson(), taPersonwrapper);
|
|
348
|
+ }
|
|
349
|
+ }
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+ @Override
|
|
353
|
+ public void documentVerify(TaDocumentVerify taDocumentVerify, Integer orgId) {
|
|
354
|
+ //
|
|
355
|
+ String changeType = CommConstant.POINTS_CHANGE_DOCUMENT_VERIFY;
|
|
356
|
+ // 是否开启积分规则
|
|
357
|
+ Integer pointsAmount = getRulePoints(changeType, orgId);
|
|
358
|
+ if (pointsAmount == 0) {
|
|
359
|
+ return;
|
|
360
|
+ }
|
|
361
|
+
|
|
362
|
+ // 已经领取过的不会再次领取
|
|
363
|
+ String[] params = {
|
|
364
|
+ "shareId=" + String.valueOf(taDocumentVerify.getDocumentVerifyId()),
|
|
365
|
+ "openUser=" + taDocumentVerify.getPersonId()
|
|
366
|
+ };
|
|
367
|
+ String changeParams = String.join("&", params);
|
|
368
|
+ boolean hasJoined = isPointsRecordsExist(taDocumentVerify.getPersonId(), changeType, changeParams);
|
|
369
|
+ if (hasJoined) {
|
|
370
|
+ return;
|
|
371
|
+ }
|
|
372
|
+
|
|
373
|
+ // 发放积分
|
|
374
|
+ TaPerson person = taPersonMapper.selectById(taDocumentVerify.getPersonId());
|
|
375
|
+ if (savePoints(person, changeType, changeParams, pointsAmount, orgId)) {
|
|
376
|
+ taPersonMapper.setPointsIncrement(person.getPersonId(), pointsAmount);
|
|
377
|
+ }
|
|
378
|
+ }
|
|
379
|
+
|
|
380
|
+ @Override
|
|
381
|
+ public void activityVerificationSign(HelpInitiateRecord helpInitiateRecord, Integer orgId) {
|
|
382
|
+ //
|
|
383
|
+ String changeType = CommConstant.POINTS_CHANGE_ACTIVITY_VERIFICATION;
|
|
384
|
+ // 是否开启积分规则
|
|
385
|
+ Integer pointsAmount = getRulePoints(changeType, orgId);
|
|
386
|
+ if (pointsAmount == 0) {
|
|
387
|
+ return;
|
|
388
|
+ }
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+ // 已经领取过的不会再次领取
|
|
392
|
+ String[] params = {
|
|
393
|
+ "shareId=" + String.valueOf(helpInitiateRecord.getHelpRecordInitiateId()),
|
|
394
|
+ "openUser=" + helpInitiateRecord.getPersonId()
|
|
395
|
+ };
|
|
396
|
+ String changeParams = String.join("&", params);
|
|
397
|
+ boolean hasJoined = isPointsRecordsExist(helpInitiateRecord.getPersonId(), changeType, changeParams);
|
|
398
|
+ if (hasJoined) {
|
|
399
|
+ return;
|
|
400
|
+ }
|
|
401
|
+
|
|
402
|
+ // 发放积分
|
|
403
|
+ TaPerson person = taPersonMapper.selectById(helpInitiateRecord.getPersonId());
|
|
404
|
+ if (savePoints(person, changeType, changeParams, pointsAmount, orgId)) {
|
|
405
|
+ taPersonMapper.setPointsIncrement(person.getPersonId(), pointsAmount);
|
|
406
|
+ }
|
|
407
|
+ }
|
|
408
|
+
|
|
409
|
+ /**
|
|
410
|
+ * 消费拼团积分
|
|
411
|
+ *
|
|
412
|
+ * @param person
|
|
413
|
+ * @param integral
|
|
414
|
+ * @param buildingId
|
|
415
|
+ * @param groupActivityId
|
|
416
|
+ */
|
|
417
|
+ @Override
|
|
418
|
+ public void saveGroupRecord(TaPerson person, Integer integral, String buildingId, Integer groupActivityId) {
|
|
419
|
+ TaPointsRecords taPointsRecords = new TaPointsRecords();
|
|
420
|
+ taPointsRecords.setPersonId(person.getPersonId());
|
|
421
|
+ taPointsRecords.setPersonName(person.getNickname());
|
|
422
|
+ taPointsRecords.setPersonType(person.getPersonType());
|
|
423
|
+ taPointsRecords.setPointsAmount(-integral);
|
|
424
|
+ taPointsRecords.setChangeType(CommConstant.POINTS_CHANGE_GROUP);
|
|
425
|
+ taPointsRecords.setChangeParams("{\"group_activity_id\":" + groupActivityId + "}");
|
|
426
|
+ taPointsRecords.setCreateDate(LocalDateTime.now());
|
|
427
|
+ taPointsRecords.setOrgId(person.getOrgId());
|
|
428
|
+ taPointsRecords.setBuildingId(buildingId);
|
|
429
|
+ taPointsRecords.setStatus(CommConstant.STATUS_NORMAL);
|
|
430
|
+ taPointsRecordsMapper.insert(taPointsRecords);
|
|
431
|
+ }
|
|
432
|
+
|
|
433
|
+ @Override
|
|
434
|
+ public Integer sumPointByPersonId(String personId) {
|
|
435
|
+ return taPointsRecordsMapper.sumPointByPersonId(personId);
|
|
436
|
+ }
|
435
|
437
|
}
|