提交 | 用户 | age
|
689637
|
1 |
package com.hx.phip.service.userMoney.impl; |
A |
2 |
|
|
3 |
import javax.annotation.Resource; |
|
4 |
|
fe8b6c
|
5 |
import com.alibaba.fastjson.JSON; |
34f071
|
6 |
import com.alibaba.fastjson.JSONArray; |
fe8b6c
|
7 |
import com.alibaba.fastjson.JSONObject; |
689637
|
8 |
import com.hx.common.service.CommonService; |
fe8b6c
|
9 |
import com.hx.phiappt.common.OperationReasonConstants; |
A |
10 |
import com.hx.phiappt.common.OriginChannelConstants; |
34f071
|
11 |
import com.hx.phiappt.constants.tool.UserInfoTool; |
0798f6
|
12 |
import com.hx.phiappt.constants.tool.money.UserMoneyTool; |
689637
|
13 |
import com.hx.phiappt.model.*; |
fe8b6c
|
14 |
import com.hx.phip.common.wx.corp.WeiXinMpUtil; |
bf83fa
|
15 |
import com.hx.phip.config.CustomParameter; |
689637
|
16 |
import com.hx.phip.dao.mapper.*; |
fe8b6c
|
17 |
import com.hx.phip.model.ApplyParameter; |
A |
18 |
import com.hx.phip.model.SysParameter; |
07e691
|
19 |
import com.hx.phip.service.UserIntegralRecordService; |
689637
|
20 |
import com.hx.phip.service.UserMoneyService; |
07e691
|
21 |
import com.hx.phip.service.UserValueAddedFundRecordService; |
fe8b6c
|
22 |
import com.hx.phip.tool.ApplyParameterTool; |
A |
23 |
import com.hx.phip.tool.SendSMSTool; |
|
24 |
import com.hx.util.AesUtil; |
689637
|
25 |
import com.hx.util.StringUtils; |
bf83fa
|
26 |
import com.platform.constants.PlatformPattern; |
689637
|
27 |
import com.platform.exception.PlatTipsException; |
A |
28 |
import com.platform.resultTool.PlatformCode; |
fe8b6c
|
29 |
import com.platform.resultTool.SystemCode; |
ac698b
|
30 |
import org.slf4j.Logger; |
A |
31 |
import org.slf4j.LoggerFactory; |
689637
|
32 |
import org.springframework.stereotype.Service; |
4e4e09
|
33 |
import org.springframework.transaction.annotation.Propagation; |
689637
|
34 |
import org.springframework.transaction.annotation.Transactional; |
A |
35 |
|
|
36 |
import com.hx.exception.TipsException; |
|
37 |
import com.hx.phiappt.model.userMoney.UserMoneyUnclaimed; |
|
38 |
import com.hx.phip.service.userMoney.UserMoneyUnclaimedService; |
|
39 |
import com.hx.mybatisTool.SqlSentence; |
|
40 |
|
fe8b6c
|
41 |
import java.lang.reflect.Field; |
A |
42 |
import java.lang.reflect.Modifier; |
689637
|
43 |
import java.math.BigDecimal; |
ffbf05
|
44 |
import java.util.*; |
689637
|
45 |
|
A |
46 |
@Transactional |
|
47 |
@Service |
|
48 |
public class UserMoneyUnclaimedServiceImpl implements UserMoneyUnclaimedService { |
ac698b
|
49 |
|
A |
50 |
private static final Logger logger = LoggerFactory.getLogger(UserMoneyUnclaimedServiceImpl.class); |
689637
|
51 |
|
34f071
|
52 |
@Resource |
A |
53 |
private UserMapper userMapper; |
689637
|
54 |
@Resource |
A |
55 |
private CommonService commonService; |
bf83fa
|
56 |
@Resource |
A |
57 |
private CustomParameter customParameter; |
ffbf05
|
58 |
@Resource |
A |
59 |
private UserInfoMapper userInfoMapper; |
689637
|
60 |
@Resource |
A |
61 |
private UserMoneyService userMoneyService; |
07e691
|
62 |
@Resource |
689637
|
63 |
private UserMoneyUnclaimedMapper userMoneyUnclaimedMapper; |
A |
64 |
@Resource |
07e691
|
65 |
private UserIntegralRecordService userIntegralRecordService; |
A |
66 |
@Resource |
|
67 |
private UserValueAddedFundRecordService userValueAddedFundRecordService; |
689637
|
68 |
|
A |
69 |
/** |
|
70 |
* 查询列表 |
|
71 |
*/ |
|
72 |
@Override |
|
73 |
public List<UserMoneyUnclaimed> selectList(SqlSentence sqlSentence) { |
|
74 |
return userMoneyUnclaimedMapper.selectList(sqlSentence); |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* 查询列表 |
|
79 |
*/ |
|
80 |
@Override |
|
81 |
public List<Map<String, Object>> selectListMap(SqlSentence sqlSentence) { |
|
82 |
return userMoneyUnclaimedMapper.selectListMap(sqlSentence); |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* 查询单个 |
|
87 |
*/ |
|
88 |
@Override |
|
89 |
public UserMoneyUnclaimed selectOne(SqlSentence sqlSentence) { |
|
90 |
return userMoneyUnclaimedMapper.selectOne(sqlSentence); |
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* 查询单个 |
|
95 |
*/ |
|
96 |
@Override |
|
97 |
public Map<String, Object> selectOneMap(SqlSentence sqlSentence) { |
|
98 |
return userMoneyUnclaimedMapper.selectOneMap(sqlSentence); |
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* 查询单个,大数据不拿取 |
|
103 |
*/ |
|
104 |
@Override |
|
105 |
public UserMoneyUnclaimed selectOneByKey(Object object) { |
|
106 |
return userMoneyUnclaimedMapper.selectOneByKey(object); |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* 查询单个,大数据拿取 |
|
111 |
*/ |
|
112 |
@Override |
|
113 |
public UserMoneyUnclaimed selectOneByKeyBlob(Object object) { |
|
114 |
return userMoneyUnclaimedMapper.selectOneByKeyBlob(object); |
|
115 |
} |
|
116 |
|
|
117 |
/** |
34f071
|
118 |
* 获取操作用户资金信息消息 |
A |
119 |
* @param userMoneyUnclaimed 参数 |
|
120 |
* @param type 是否领取资金 |
|
121 |
* @return 返回 |
|
122 |
*/ |
|
123 |
private JSONObject getOpInfo(UserMoneyUnclaimed userMoneyUnclaimed, Integer type) { |
|
124 |
BigDecimal before = BigDecimal.ZERO; |
|
125 |
BigDecimal after = BigDecimal.ZERO; |
|
126 |
JSONObject jsonObject = new JSONObject(); |
|
127 |
// 获取处理信息 |
|
128 |
StringBuilder info = new StringBuilder(); |
|
129 |
info.append(userMoneyUnclaimed.getOriginSubject()); |
|
130 |
// 查询用户资金信息 |
|
131 |
UserMoney userMoney = userMoneyService.selectUserIdDecrypt(userMoneyUnclaimed.getUserId()); |
|
132 |
switch (userMoneyUnclaimed.getFundType()) { |
|
133 |
case UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND: |
eb4b67
|
134 |
info.append(", 储值金"); |
34f071
|
135 |
before = new BigDecimal(userMoney.getStoredValueFund()); |
A |
136 |
after = before.add(userMoneyUnclaimed.getOpNumber()); |
|
137 |
break; |
|
138 |
case UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND: |
eb4b67
|
139 |
info.append(", 增值金"); |
34f071
|
140 |
before = new BigDecimal(userMoney.getValueAddedFund()); |
A |
141 |
after = before.add(userMoneyUnclaimed.getOpNumber()); |
|
142 |
break; |
|
143 |
case UserMoneyUnclaimed.FUND_TYPE_INTEGRAL: |
eb4b67
|
144 |
info.append(", 积分"); |
34f071
|
145 |
before = new BigDecimal(userMoney.getIntegral()); |
A |
146 |
after = before.add(userMoneyUnclaimed.getOpNumber()); |
|
147 |
break; |
|
148 |
case UserMoneyUnclaimed.FUND_TYPE_DEPOSIT: |
eb4b67
|
149 |
info.append(", 预定金"); |
34f071
|
150 |
before = new BigDecimal(userMoney.getDeposit()); |
A |
151 |
after = before.add(userMoneyUnclaimed.getOpNumber()); |
|
152 |
break; |
|
153 |
} |
eb4b67
|
154 |
info.append(", 操作数量:").append(userMoneyUnclaimed.getOpNumber()); |
34f071
|
155 |
if (UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND == userMoneyUnclaimed.getFundType()) { |
A |
156 |
// 增值金添加是否需要领取 |
|
157 |
int opType = userMoneyUnclaimed.getOpType() == null ? BaseEntity.YES : userMoneyUnclaimed.getOpType(); |
eb4b67
|
158 |
info.append(", 是否需要领取:").append(BaseEntity.YES.equals(opType) ? "是" : "否"); |
A |
159 |
if (BaseEntity.YES.equals(opType)){ |
|
160 |
before = null; |
|
161 |
after = null; |
|
162 |
} |
34f071
|
163 |
} |
A |
164 |
if (BaseEntity.YES.equals(type)){ |
eb4b67
|
165 |
info.append(", 领取资金: ").append(userMoneyUnclaimed.getOpNumber()); |
A |
166 |
} |
|
167 |
if (3 == type){ |
|
168 |
info.append(", 作废待领取资金: ").append(userMoneyUnclaimed.getOpNumber()); |
|
169 |
before = null; |
|
170 |
after = null; |
34f071
|
171 |
} |
A |
172 |
jsonObject.put("key", info.toString()); |
|
173 |
jsonObject.put("before", before); |
|
174 |
jsonObject.put("after", after); |
|
175 |
return jsonObject; |
|
176 |
} |
|
177 |
|
|
178 |
/** |
|
179 |
* 添加用户日志 |
|
180 |
* @param userMoneyUnclaimed 用户资金对象 |
|
181 |
* @param type 是否领取资金 |
|
182 |
*/ |
|
183 |
private void addUserLog(UserMoneyUnclaimed userMoneyUnclaimed, Integer type){ |
|
184 |
// 处理用户日志 |
|
185 |
User user = userMapper.selectOneByKey(userMoneyUnclaimed.getUserId()); |
|
186 |
if (user != null) { |
|
187 |
// 用户日志 |
|
188 |
JSONArray logArray = new JSONArray(); |
|
189 |
JSONObject jsonObject = getOpInfo(userMoneyUnclaimed, type); |
|
190 |
logArray.add(jsonObject); |
|
191 |
// 操作人转换 |
|
192 |
UserUpdateLog userUpdateLog = new UserUpdateLog(); |
|
193 |
switch (userMoneyUnclaimed.getOperatorType()) { |
|
194 |
case UserMoneyUnclaimed.OPERATOR_TYPE_USER: |
|
195 |
userUpdateLog.setOperatorType(UserUpdateLog.OPERATOR_TYPE_USER); |
|
196 |
userUpdateLog.setOperatorId(userMoneyUnclaimed.getOperatorId()); |
|
197 |
userUpdateLog.setOperatorName(userMoneyUnclaimed.getOperatorName()); |
|
198 |
break; |
|
199 |
case UserMoneyUnclaimed.OPERATOR_TYPE_EMPLOYEE: |
|
200 |
userUpdateLog.setOperatorType(UserUpdateLog.OPERATOR_TYPE_EMPLOYEE); |
|
201 |
userUpdateLog.setOperatorId(userMoneyUnclaimed.getOperatorId()); |
|
202 |
userUpdateLog.setOperatorName(userMoneyUnclaimed.getOperatorName()); |
|
203 |
break; |
|
204 |
case UserMoneyUnclaimed.OPERATOR_TYPE_ADMIN: |
|
205 |
userUpdateLog.setOperatorType(UserUpdateLog.OPERATOR_TYPE_ADMIN); |
|
206 |
userUpdateLog.setOperatorId(userMoneyUnclaimed.getOperatorId()); |
|
207 |
userUpdateLog.setOperatorName(userMoneyUnclaimed.getOperatorName()); |
|
208 |
break; |
|
209 |
case UserMoneyUnclaimed.OPERATOR_TYPE_SYSTEM: |
|
210 |
userUpdateLog.setOperatorType(UserUpdateLog.OPERATOR_TYPE_SYSTEM); |
|
211 |
break; |
|
212 |
} |
|
213 |
// 添加用户日志 |
|
214 |
UserInfoTool.addUserUpdateLogOp(commonService, user, user.getShopId(), userUpdateLog, "用户资金调整", logArray, userMoneyUnclaimed.getRemarks()); |
|
215 |
} |
|
216 |
} |
|
217 |
|
|
218 |
/** |
689637
|
219 |
* 新增 |
A |
220 |
*/ |
|
221 |
@Override |
4e4e09
|
222 |
@Transactional(propagation = Propagation.REQUIRES_NEW) |
689637
|
223 |
public void insert(UserMoneyUnclaimed userMoneyUnclaimed) { |
A |
224 |
int count = userMoneyUnclaimedMapper.insert(userMoneyUnclaimed); |
|
225 |
if (count != 1) { |
|
226 |
throw new TipsException("新增失败!"); |
45739e
|
227 |
} else { |
A |
228 |
// 重新获取下数据 |
|
229 |
UserMoneyUnclaimed checkUserMoneyUnclaimed = userMoneyUnclaimedMapper.selectOneByKey(userMoneyUnclaimed.getId()); |
|
230 |
if(checkUserMoneyUnclaimed != null) { |
|
231 |
// 过滤待领取的数据 |
|
232 |
this.handlerReceiveData(checkUserMoneyUnclaimed, BaseEntity.YES); |
34f071
|
233 |
// 添加用户日志 |
A |
234 |
addUserLog(userMoneyUnclaimed, BaseEntity.NO); |
45739e
|
235 |
} |
34f071
|
236 |
|
689637
|
237 |
} |
A |
238 |
} |
|
239 |
|
|
240 |
/** |
|
241 |
* 修改 |
|
242 |
*/ |
|
243 |
@Override |
|
244 |
public void updateAll(UserMoneyUnclaimed userMoneyUnclaimed) { |
eb4b67
|
245 |
if(BaseEntity.YES.equals(userMoneyUnclaimed.getIsDel())){ |
A |
246 |
// 添加用户日志 |
|
247 |
addUserLog(userMoneyUnclaimed, 3); |
|
248 |
} |
689637
|
249 |
int count = userMoneyUnclaimedMapper.updateAll(userMoneyUnclaimed); |
A |
250 |
if (count != 1) { |
|
251 |
throw new TipsException("保存失败!"); |
|
252 |
} |
|
253 |
} |
|
254 |
|
|
255 |
/** |
|
256 |
* 修改 |
|
257 |
*/ |
|
258 |
@Override |
|
259 |
public void updateWhere(SqlSentence sqlSentence) { |
|
260 |
int count = userMoneyUnclaimedMapper.updateWhere(sqlSentence); |
|
261 |
if (count != 1) { |
|
262 |
throw new TipsException("保存失败!"); |
|
263 |
} |
|
264 |
} |
|
265 |
|
|
266 |
/** |
|
267 |
* 删除一个 |
|
268 |
*/ |
|
269 |
@Override |
|
270 |
public void deleteOne(String delId) { |
|
271 |
int count = userMoneyUnclaimedMapper.deleteById(delId); |
|
272 |
if (count != 1) { |
|
273 |
throw new TipsException("删除失败!"); |
|
274 |
} |
|
275 |
} |
|
276 |
|
|
277 |
/** |
|
278 |
* 查询条数 |
|
279 |
*/ |
|
280 |
@Override |
|
281 |
public int selectCount(SqlSentence sqlSentence) { |
|
282 |
int count = userMoneyUnclaimedMapper.selectCount(sqlSentence); |
|
283 |
return count; |
|
284 |
} |
|
285 |
|
|
286 |
/** |
|
287 |
* 校验参数 |
|
288 |
* |
|
289 |
* @param userMoneyUnclaimed 用户待领取列表 |
|
290 |
*/ |
07e691
|
291 |
@Override |
4e4e09
|
292 |
@Transactional(propagation = Propagation.REQUIRES_NEW) |
07e691
|
293 |
public void checkParam(UserMoneyUnclaimed userMoneyUnclaimed) { |
689637
|
294 |
// 用户校验 |
A |
295 |
if (StringUtils.isEmpty(userMoneyUnclaimed.getUserId())) { |
|
296 |
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "用户id不能为空"); |
|
297 |
} |
|
298 |
|
|
299 |
// 资金类型判断 |
|
300 |
if (userMoneyUnclaimed.getFundType() == null) { |
|
301 |
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "资金类型不能为空"); |
|
302 |
} else { |
|
303 |
// 资金类型判断是否匹配 |
|
304 |
switch (userMoneyUnclaimed.getFundType()) { |
|
305 |
case UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND: |
|
306 |
case UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND: |
|
307 |
case UserMoneyUnclaimed.FUND_TYPE_INTEGRAL: |
|
308 |
case UserMoneyUnclaimed.FUND_TYPE_DEPOSIT: |
|
309 |
break; |
|
310 |
default: |
fe8b6c
|
311 |
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "资金类型错误,类型不存在"); |
689637
|
312 |
} |
A |
313 |
} |
|
314 |
|
|
315 |
// 来源渠道 |
|
316 |
if (StringUtils.isEmpty(userMoneyUnclaimed.getOriginChannel())) { |
|
317 |
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "来源渠道不能为空"); |
fe8b6c
|
318 |
} else { |
A |
319 |
if (checkConstantNotHaveValue(OriginChannelConstants.class, userMoneyUnclaimed.getOriginChannel())) { |
|
320 |
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "来源渠道错误,渠道不存在"); |
|
321 |
} |
|
322 |
} |
|
323 |
|
|
324 |
// 操作原因 |
ffbf05
|
325 |
if (StringUtils.isEmpty(userMoneyUnclaimed.getOperationReason())) { |
fe8b6c
|
326 |
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作原因不能为空"); |
A |
327 |
} else { |
|
328 |
if (checkConstantNotHaveValue(OperationReasonConstants.class, userMoneyUnclaimed.getOperationReason())) { |
|
329 |
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作原因错误,渠道不存在"); |
|
330 |
} |
689637
|
331 |
} |
A |
332 |
|
0c0f9a
|
333 |
// 操作类型 |
A |
334 |
if (userMoneyUnclaimed.getOpType() == null) { |
07e691
|
335 |
// 默认为系统处理 |
0c0f9a
|
336 |
userMoneyUnclaimed.setOpType(UserMoneyUnclaimed.OP_TYPE_SYSTEM); |
07e691
|
337 |
// 增值金默认需要领取 |
A |
338 |
if (UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND == userMoneyUnclaimed.getFundType()) { |
|
339 |
// 增值金默认需要领取 负数不用用户领取和判断是否需要发送短信提醒领取 |
ffbf05
|
340 |
if (BigDecimal.ZERO.compareTo(userMoneyUnclaimed.getOpNumber()) < 0) { |
07e691
|
341 |
userMoneyUnclaimed.setOpType(UserMoneyUnclaimed.OP_TYPE_RECEIVE); |
A |
342 |
} |
|
343 |
} |
0c0f9a
|
344 |
} else { |
A |
345 |
// 判断是否是支持的类型 |
|
346 |
if (UserMoneyUnclaimed.OP_TYPE_SYSTEM != userMoneyUnclaimed.getOpType() && UserMoneyUnclaimed.OP_TYPE_RECEIVE != userMoneyUnclaimed.getOpType()) { |
|
347 |
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作类型错误"); |
|
348 |
} |
04477c
|
349 |
} |
A |
350 |
|
|
351 |
// 是否发送短信 |
ffbf05
|
352 |
if (UserMoneyUnclaimed.OP_TYPE_RECEIVE == userMoneyUnclaimed.getOpType()) { |
A |
353 |
boolean flag = true; |
|
354 |
// 查询用户设置是否领取状态 |
|
355 |
UserInfo userInfo = userInfoMapper.selectOneByUserId(userMoneyUnclaimed.getUserId()); |
|
356 |
if (userInfo != null) { |
|
357 |
// 不需要领取处理数据 |
|
358 |
if (userInfo.getIsReceiveValueAddedFund() != null && BaseEntity.NO.equals(userInfo.getIsReceiveValueAddedFund())) { |
|
359 |
flag = false; |
|
360 |
userMoneyUnclaimed.setOpType(UserMoneyUnclaimed.OP_TYPE_SYSTEM); |
|
361 |
// 用户设置了不用再领取增值金 |
|
362 |
logger.info("操作用户资金(待领取记录)-用户设置是否需要领取状态:{}", userInfo.getIsReceiveValueAddedFund()); |
|
363 |
} |
|
364 |
} |
04477c
|
365 |
// 校验是否要发送短信 |
ffbf05
|
366 |
if (flag) { |
A |
367 |
checkIsNeedSentSMS(userMoneyUnclaimed); |
|
368 |
} |
0c0f9a
|
369 |
} |
A |
370 |
|
689637
|
371 |
// 判断操作数量或金额 |
A |
372 |
if (userMoneyUnclaimed.getOpNumber() == null) { |
|
373 |
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作数量或金额不能为空"); |
|
374 |
} else { |
|
375 |
// 判断操作数量或金额 是否为 0 |
|
376 |
if (BigDecimal.ZERO.compareTo(userMoneyUnclaimed.getOpNumber()) == 0) { |
|
377 |
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作数量或金额不能为0"); |
|
378 |
} else if (BigDecimal.ZERO.compareTo(userMoneyUnclaimed.getOpNumber()) < 0) { |
|
379 |
// 资金操作类型-增加 |
|
380 |
userMoneyUnclaimed.setFundOpType(UserMoneyUnclaimed.FUND_OP_TYPE_INCREASE); |
|
381 |
} else if (BigDecimal.ZERO.compareTo(userMoneyUnclaimed.getOpNumber()) > 0) { |
|
382 |
// 资金操作类型-减少 |
|
383 |
userMoneyUnclaimed.setFundOpType(UserMoneyUnclaimed.FUND_OP_TYPE_REDUCE); |
|
384 |
} |
|
385 |
|
|
386 |
// 用户资金数据校验 |
|
387 |
UserMoney userMoney = userMoneyService.selectUserIdDecrypt(userMoneyUnclaimed.getUserId()); |
|
388 |
if (userMoney == null) { |
|
389 |
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "用户的资产数据不存在"); |
|
390 |
} else { |
|
391 |
// 判断数量减扣数量是否充足 |
|
392 |
if (UserMoneyUnclaimed.FUND_OP_TYPE_REDUCE == userMoneyUnclaimed.getFundOpType()) { |
|
393 |
// 资金类型判断是否匹配 |
|
394 |
switch (userMoneyUnclaimed.getFundType()) { |
|
395 |
case UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND: |
|
396 |
// 金额操作 |
|
397 |
BigDecimal storedValueFund = new BigDecimal(userMoney.getStoredValueFund()); |
07e691
|
398 |
checkCanOperation(storedValueFund, userMoneyUnclaimed.getOpNumber()); |
689637
|
399 |
break; |
A |
400 |
case UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND: |
07e691
|
401 |
// 金额操作 不做校验可以减成负数 |
34f071
|
402 |
BigDecimal valueAddedFund = new BigDecimal(userMoney.getValueAddedFund()); |
A |
403 |
checkCanOperation(valueAddedFund, userMoneyUnclaimed.getOpNumber()); |
689637
|
404 |
break; |
A |
405 |
case UserMoneyUnclaimed.FUND_TYPE_INTEGRAL: |
fecaea
|
406 |
// 积分操作 |
689637
|
407 |
BigDecimal integral = new BigDecimal(userMoney.getIntegral()); |
07e691
|
408 |
checkCanOperation(integral, userMoneyUnclaimed.getOpNumber()); |
689637
|
409 |
break; |
A |
410 |
case UserMoneyUnclaimed.FUND_TYPE_DEPOSIT: |
|
411 |
// 金额操作 |
|
412 |
BigDecimal deposit = new BigDecimal(userMoney.getDeposit()); |
07e691
|
413 |
checkCanOperation(deposit, userMoneyUnclaimed.getOpNumber()); |
689637
|
414 |
break; |
A |
415 |
} |
|
416 |
} |
|
417 |
} |
|
418 |
} |
|
419 |
|
|
420 |
// 操作人信息判断 |
|
421 |
if (userMoneyUnclaimed.getOperatorType() == null) { |
|
422 |
// 操作人类型默认为员工 |
|
423 |
userMoneyUnclaimed.setOperatorType(UserMoneyUnclaimed.OPERATOR_TYPE_EMPLOYEE); |
|
424 |
} else { |
|
425 |
// 操作人类型判断是否匹配 |
|
426 |
switch (userMoneyUnclaimed.getOperatorType()) { |
|
427 |
case UserMoneyUnclaimed.OPERATOR_TYPE_ADMIN: |
|
428 |
case UserMoneyUnclaimed.OPERATOR_TYPE_USER: |
|
429 |
case UserMoneyUnclaimed.OPERATOR_TYPE_EMPLOYEE: |
|
430 |
break; |
|
431 |
default: |
|
432 |
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作人类型错误"); |
|
433 |
} |
|
434 |
} |
|
435 |
|
|
436 |
// 判断是否传了操作人id |
|
437 |
if (StringUtils.isEmpty(userMoneyUnclaimed.getOperatorId())) { |
|
438 |
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作人id不能为空"); |
|
439 |
} |
|
440 |
|
|
441 |
// 操作人为员工 |
|
442 |
if (UserMoneyUnclaimed.OPERATOR_TYPE_EMPLOYEE == userMoneyUnclaimed.getOperatorType()) { |
|
443 |
Employee employee = commonService.selectOneByKey(EmployeeMapper.class, userMoneyUnclaimed.getOperatorId()); |
|
444 |
if (employee == null) { |
|
445 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "操作人的信息不存在"); |
|
446 |
} else { |
|
447 |
// 填充名称 |
|
448 |
userMoneyUnclaimed.setOperatorName(employee.getCnName()); |
|
449 |
} |
|
450 |
} |
|
451 |
|
|
452 |
// 操作人为后台用户 |
|
453 |
if (UserMoneyUnclaimed.OPERATOR_TYPE_ADMIN == userMoneyUnclaimed.getOperatorType()) { |
|
454 |
SysAdmin sysAdmin = commonService.selectOneByKey(SysAdminMapper.class, userMoneyUnclaimed.getOperatorId()); |
|
455 |
if (sysAdmin == null) { |
|
456 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "操作人的信息不存在"); |
|
457 |
} else { |
|
458 |
// 填充名称 |
|
459 |
userMoneyUnclaimed.setOperatorName(sysAdmin.getName()); |
|
460 |
} |
|
461 |
} |
|
462 |
|
|
463 |
// 操作人为用户 |
fc1e34
|
464 |
if (UserMoneyUnclaimed.OPERATOR_TYPE_USER == userMoneyUnclaimed.getOperatorType()) { |
689637
|
465 |
User user = commonService.selectOneByKey(UserMapper.class, userMoneyUnclaimed.getOperatorId()); |
A |
466 |
if (user == null) { |
|
467 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "操作人的信息不存在"); |
|
468 |
} else { |
|
469 |
// 填充名称 |
|
470 |
userMoneyUnclaimed.setOperatorName(user.getName()); |
0c0f9a
|
471 |
} |
A |
472 |
} |
|
473 |
|
839339
|
474 |
/*// 判断订单 先不判断订单 |
45739e
|
475 |
if(!StringUtils.isEmpty(userMoneyUnclaimed.getOrderId())){ |
0c0f9a
|
476 |
OrdersTotal ordersTotal = commonService.selectOneByKey(OrdersTotalMapper.class, userMoneyUnclaimed.getOrderId()); |
A |
477 |
if(ordersTotal == null){ |
|
478 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "主订单的信息不存在"); |
|
479 |
} |
|
480 |
} |
|
481 |
|
|
482 |
// 判断子订单 |
|
483 |
if(!StringUtils.isEmpty(userMoneyUnclaimed.getOrderItemId())){ |
|
484 |
if(StringUtils.isEmpty(userMoneyUnclaimed.getOrderId())){ |
|
485 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "主订单id不能为空!"); |
|
486 |
} |
|
487 |
OrderItem orderItem = commonService.selectOneByKey(OrderItemMapper.class, userMoneyUnclaimed.getOrderItemId()); |
|
488 |
if(orderItem == null){ |
|
489 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "子订单的信息不存在"); |
|
490 |
} else { |
|
491 |
if(!orderItem.getOrderId().equals(userMoneyUnclaimed.getOrderId())){ |
|
492 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "子订单的信息与主订单的信息不匹配"); |
|
493 |
} |
689637
|
494 |
} |
839339
|
495 |
}*/ |
689637
|
496 |
|
A |
497 |
// 获取有效期时间配置 待领取默认30天领取 |
0798f6
|
498 |
Date validityTime = UserMoneyTool.getUnclaimedValidityTime(commonService); |
689637
|
499 |
// 设置有效期时间 |
A |
500 |
userMoneyUnclaimed.setLimitEndTime(validityTime); |
|
501 |
} |
|
502 |
|
|
503 |
/** |
fe8b6c
|
504 |
* 校验常量值是否存在 |
A |
505 |
* @param classObj 类对象 |
|
506 |
* @param value 校验值 |
|
507 |
* @return 返回 |
|
508 |
*/ |
565a37
|
509 |
@Override |
A |
510 |
public boolean checkConstantNotHaveValue(Class classObj, String value) { |
fe8b6c
|
511 |
boolean flag = true; |
A |
512 |
// 判断是否存在这个来源渠道 |
|
513 |
Field[] fields = classObj.getDeclaredFields(); |
|
514 |
for (Field field : fields) { |
|
515 |
field.setAccessible(true); |
|
516 |
// 获取常量名称 |
|
517 |
String fieldName = field.getName(); |
|
518 |
// 判断常量值是否存在 |
|
519 |
if (field.getType().toString().endsWith("java.lang.String") && Modifier.isStatic(field.getModifiers())) { |
|
520 |
try { |
|
521 |
// 获取常量值 |
|
522 |
String fieldValue = field.get(classObj).toString(); |
|
523 |
if (fieldValue.equals(value)) { |
|
524 |
flag = false; |
|
525 |
break; |
|
526 |
} |
|
527 |
}catch (Exception ex){ |
|
528 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "常量获取配置出现错误"); |
|
529 |
|
|
530 |
} |
|
531 |
} |
|
532 |
} |
|
533 |
return flag; |
|
534 |
} |
|
535 |
|
|
536 |
/** |
689637
|
537 |
* 判断数据是否支持减扣 |
A |
538 |
*/ |
|
539 |
private void checkCanOperation(BigDecimal value, BigDecimal opNumber) { |
|
540 |
// 负数取反计算 |
|
541 |
if(BigDecimal.ZERO.compareTo(opNumber) > 0){ |
|
542 |
opNumber = opNumber.negate(); |
|
543 |
} |
|
544 |
|
|
545 |
// 计算账户余额是否支持减扣 |
|
546 |
BigDecimal subtractValue = value.subtract(opNumber); |
|
547 |
if (subtractValue.compareTo(BigDecimal.ZERO) < 0) { |
|
548 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "您的数量不足已减扣!"); |
fe8b6c
|
549 |
} |
A |
550 |
} |
|
551 |
|
|
552 |
/** |
|
553 |
* 根据平台判断是否需要发送短信 |
|
554 |
* @param userMoneyUnclaimed 用户待领取信息 |
|
555 |
*/ |
04477c
|
556 |
private void checkIsNeedSentSMS(UserMoneyUnclaimed userMoneyUnclaimed) { |
A |
557 |
// CRM不用发送短信领取其他平台需要发送短信领取 |
|
558 |
// if(!OriginChannelConstants.ORIGIN_CHANNEL_CRM.equals(userMoneyUnclaimed.getOriginChannel())) { |
|
559 |
userMoneyUnclaimed.setIsSentSMS(BaseEntity.YES); |
|
560 |
String url = getSMSUrl(); |
|
561 |
if (StringUtils.isEmpty(url)) { |
|
562 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "获取发送短信链接地址出现异常!"); |
689637
|
563 |
} |
04477c
|
564 |
userMoneyUnclaimed.setSMSUrl(url); |
A |
565 |
//} |
689637
|
566 |
} |
A |
567 |
|
|
568 |
/** |
fe8b6c
|
569 |
* 生成需要发送短信的地址 |
A |
570 |
* @return 返回 |
|
571 |
*/ |
bf83fa
|
572 |
private String getSMSUrl() { |
A |
573 |
// 生成小程序链接 |
fe8b6c
|
574 |
String urlLink = null; |
bf83fa
|
575 |
// 正式区在拿取链接 |
47e70d
|
576 |
if (PlatformPattern.PROD.equals(customParameter.getPlatformPatternMoney())) { |
bf83fa
|
577 |
//获取用户CRM小程序token |
A |
578 |
ApplyParameter applyParameter = ApplyParameterTool.getMpParameter("wx71e6babac80abcee", commonService); |
|
579 |
if (applyParameter == null) { |
|
580 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "mpId is error"); |
fe8b6c
|
581 |
} |
bf83fa
|
582 |
|
A |
583 |
SysParameter sysParameter = WeiXinMpUtil.getAccessToken(commonService, applyParameter.getMpAppId(), AesUtil.aesDecryp(applyParameter.getMpSecretKey())); |
|
584 |
if (sysParameter == null) { |
|
585 |
throw new PlatTipsException(PlatformCode.ERROR_SYSTEM, "服务错误" + SystemCode.ERROR_GET_CORP_TOKEN); |
|
586 |
} |
|
587 |
|
deb885
|
588 |
// 更换链接 原CRM 1.0 /pages/recharge/incrementInfo |
A |
589 |
String result = SendSMSTool.getAooLetUrl(sysParameter.getParamValue(), "/pages/portClient_me/incrementValue/incrementValue", "", "release"); |
bf83fa
|
590 |
if (!StringUtils.isEmpty(result)) { |
A |
591 |
JSONObject jsonObject = JSON.parseObject(result); |
|
592 |
if (jsonObject.getInteger("errcode") != 0) { |
|
593 |
throw new PlatTipsException(PlatformCode.ERROR_SYSTEM, "生成短信小程序路径错误:" + jsonObject.getString("msg") + SystemCode.ERROR_GET_CORP_TOKEN); |
|
594 |
} |
|
595 |
urlLink = jsonObject.getString("url_link"); |
|
596 |
} |
|
597 |
} else { |
|
598 |
// 测试区跳转百度 |
2d878f
|
599 |
urlLink = "https://wxaurl.cn/6666"; |
fe8b6c
|
600 |
} |
A |
601 |
return urlLink; |
|
602 |
} |
0c0f9a
|
603 |
|
A |
604 |
/** |
07e691
|
605 |
* 待领取资产处理 |
fecaea
|
606 |
* @param userMoneyUnclaimed 待领取数据 |
fc1e34
|
607 |
* @param isReceive 是否过滤领取数据 0 否 1 是 |
0c0f9a
|
608 |
*/ |
A |
609 |
@Override |
fc1e34
|
610 |
public void handlerReceiveData(UserMoneyUnclaimed userMoneyUnclaimed, Integer isReceive) { |
07e691
|
611 |
if (userMoneyUnclaimed != null) { |
A |
612 |
// 多线程添加锁 |
|
613 |
synchronized (this) { |
31051b
|
614 |
// 判断是不是要领取的数据 |
fc1e34
|
615 |
if(BaseEntity.YES.equals(isReceive)) { |
A |
616 |
if (UserMoneyUnclaimed.OP_TYPE_RECEIVE == userMoneyUnclaimed.getOpType()) { |
ac698b
|
617 |
logger.info("待领取资产处理跳过,数据id:{},原因:需要领取数据", userMoneyUnclaimed.getId()); |
fc1e34
|
618 |
return; |
A |
619 |
} |
31051b
|
620 |
} |
A |
621 |
// 判断是否处理了 |
|
622 |
if(UserMoneyUnclaimed.STATUS_SUCCEED == userMoneyUnclaimed.getStatus()){ |
ac698b
|
623 |
logger.info("待领取资产处理跳过,数据id:{},原因:数据已领取不需要再处理", userMoneyUnclaimed.getId()); |
31051b
|
624 |
return; |
A |
625 |
} |
|
626 |
// 判断数据是否有效 |
|
627 |
if(UserMoneyUnclaimed.NO.equals(userMoneyUnclaimed.getIsValid())){ |
ac698b
|
628 |
logger.info("待领取资产处理跳过,数据id:{},原因:数据已失效无法领取", userMoneyUnclaimed.getId()); |
31051b
|
629 |
return; |
A |
630 |
} |
07e691
|
631 |
// 操作资金处理 |
A |
632 |
switch (userMoneyUnclaimed.getFundType()) { |
|
633 |
case UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND: |
|
634 |
case UserMoneyUnclaimed.FUND_TYPE_DEPOSIT: |
|
635 |
// 储值金和预定金只处理总资金信息 |
|
636 |
userMoneyService.handleMoneyData(userMoneyUnclaimed); |
|
637 |
break; |
|
638 |
case UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND: |
|
639 |
// 处理增值金 |
|
640 |
userValueAddedFundRecordService.handleData(userMoneyUnclaimed); |
|
641 |
break; |
|
642 |
case UserMoneyUnclaimed.FUND_TYPE_INTEGRAL: |
|
643 |
// 处理积分 |
|
644 |
userIntegralRecordService.handleData(userMoneyUnclaimed); |
|
645 |
break; |
|
646 |
} |
|
647 |
|
|
648 |
// 更新状态成已处理 |
|
649 |
SqlSentence sqlSentence = new SqlSentence(); |
|
650 |
Map<String, Object> sqlValue = new HashMap<>(); |
89e4d1
|
651 |
String sql = " status=#{m.status},receiveTime=#{m.nowTime},limitEndTime=#{m.limitEndTime},editTime=#{m.nowTime} WHERE id=#{m.id}"; |
07e691
|
652 |
sqlValue.put("id", userMoneyUnclaimed.getId()); |
A |
653 |
sqlValue.put("status", UserMoneyUnclaimed.STATUS_SUCCEED); |
89e4d1
|
654 |
// 已领取调整领取时间 |
0798f6
|
655 |
Date receivedValidityTime = UserMoneyTool.getReceivedValidityTime(commonService); |
89e4d1
|
656 |
sqlValue.put("limitEndTime", receivedValidityTime); |
A |
657 |
sqlValue.put("nowTime",new Date()); |
07e691
|
658 |
sqlSentence.sqlSentence(sql, sqlValue); |
A |
659 |
commonService.updateWhere(UserMoneyUnclaimedMapper.class, sqlSentence); |
34f071
|
660 |
|
A |
661 |
// 添加用户日志 |
|
662 |
if(BaseEntity.NO.equals(isReceive)) { |
|
663 |
addUserLog(userMoneyUnclaimed, BaseEntity.YES); |
|
664 |
} |
07e691
|
665 |
} |
A |
666 |
} |
0c0f9a
|
667 |
} |
689637
|
668 |
} |