UserKitingBiz.java
7.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
package com.cjs.site.biz.user.fund;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cjs.site.biz.pub.CommonBiz;
import com.cjs.site.biz.pub.SendMessageBiz;
import com.cjs.site.dao.pub.SysParamValueDao;
import com.cjs.site.dao.user.account.ClientInfoDao;
import com.cjs.site.dao.user.fund.FundRealDao;
import com.cjs.site.dao.user.fund.UserKitingDao;
import com.cjs.site.model.pub.ConstInfo;
import com.cjs.site.model.user.account.UserInfo;
import com.cjs.site.model.user.fund.UserKitingInfo;
import com.cjs.site.util.lang.DateEnum;
import com.cjs.site.util.lang.DateUtil;
import com.cjs.site.util.t2.T2Result;
import com.cjs.site.util.t2.T2Util;
import com.cjs.site.util.web.ActionUtil;
/**
* 客户提现
*
* @author tongyufu
*
*/
@Service
public class UserKitingBiz {
Logger log = LogManager.getLogger();
@Autowired
private FundRealDao fundRealDao;
@Autowired
private UserKitingDao userKitingDao;
@Autowired
private ClientInfoDao clientInfoDao;
@Autowired
private SendMessageBiz sendMessageBiz;
@Autowired
private CommonBiz commonBiz;
@Autowired
private SysParamValueDao sysParamDao;
/**
* 取现
* @param userId
* @param amount
* @param validCode 短信验证码
*/
public String kiting(String subBranch, Double amount, String validCode, HttpSession session) {
UserInfo userInfo = ActionUtil.getUser();
String userId = userInfo.getClient_id();
if (!this.commonBiz.checkTime(true, 10, 11)) {
String beginTime = DateUtil.parseDate(
DateUtil.parseDate(this.sysParamDao.getParamValue("begin_time_fund"), DateEnum.UNSIGNED_TIME),
DateEnum.TIME);
String endTime = DateUtil.parseDate(DateUtil.parseDate(
this.sysParamDao.getParamValue("end_time_fund"), DateEnum.UNSIGNED_TIME), DateEnum.TIME);
return "请于交易日的" + beginTime + " - " + endTime + "进行提现操作。";
}
//验证短信验证码
if (!sendMessageBiz.compareValidCode(validCode, session)) {
return "短信验证码不正确";
}
Map<String, Object> balance = fundRealDao.queryByUserId(userId);
Double enableBalance = Double.valueOf(balance.get("ENABLE_BALANCE").toString());
if (StringUtils.isBlank(subBranch)) {
return "支行名称不能为空";
}
if (amount < 10) {
return "提现金额不能小于10元";
}
if (amount > 2000000) {
return "提现金额不能大于2,000,000元";
}
if (enableBalance < amount) {
return "提现金额不能超过可用金额,当前可用金额:" + enableBalance;
}
Map<String, Object> params = new HashMap<String, Object>();
if (amount > 0) {
amount *= -1;
}
Map<String, String> bankInfo = clientInfoDao.queryForPnr(userId);
params.put("op_branch_no", "11");
params.put("operator_no", "2001");
params.put("user_type", "");
params.put("op_password", "111111");
params.put("op_station", "");
params.put("op_entrust_way", "7");
params.put("menu_id", "");
params.put("function_id", "");
params.put("branch_no", "11");
params.put("audit_action", "1");
params.put("action_in", "");
params.put("fund_account", userId);
params.put("money_type", "0");
params.put("occur_date", DateUtil.getNow(DateEnum.UNSIGNED_DATE));
params.put("occur_balance", amount);
params.put("bank_no", "");
//params.put("join_info", "存管内部附加信息");
params.put("remark", ConstInfo.Fund.USER_KITING_REMARK);
T2Result result = null;
String msg = "提现申请成功";
try {
// result = T2Util.request(params, "202101");
result = this.ducureFund(userId, amount);
} finally {
UserKitingInfo kitInfo = new UserKitingInfo();
kitInfo.setUserId(userId);
kitInfo.setUserName(bankInfo.get("CLIENT_NAME").toString());
kitInfo.setMobile(bankInfo.get("MOBILE_TEL").toString());
kitInfo.setBankName(bankInfo.get("OPEN_BANK_NAME").toString());
kitInfo.setBankNo(bankInfo.get("BANK_ACCOUNT").toString());
kitInfo.setProvince(bankInfo.get("PROVINCE_NAME"));
kitInfo.setCity(bankInfo.get("CITY_NAME"));
kitInfo.setSubBranch(subBranch);
amount *= -1;
kitInfo.setKitAmount(amount);
double kitFare = amount * 0.3 / 100;
if (kitFare < 2) {
kitFare = 2;
} else if (kitFare > 200) {
kitFare = 200;
}
kitInfo.setKitFare(kitFare);
kitInfo.setPayableAmount(amount - kitFare);
if (result == null) {
kitInfo.setKitStatus("0");
msg = "提现失败";
} else if (result.getCode() != 0) {
kitInfo.setKitStatus("0");
msg = "提现失败:" + result.getError().getErrorInfo();
} else {
kitInfo.setKitStatus("1");
}
log.info("客户[" + userId + "]提现结果:" + result);
userKitingDao.save(kitInfo);
session.removeAttribute(SendMessageBiz.RANDOM_NUM);
}
log.info(msg);
return msg;
}
private T2Result ducureFund(String userId,Double amount){
T2Result result = new T2Result();
fundRealDao.freezeAmount(userId, Math.abs(amount));
result.setCode(0);
return result;
}
/**
* 查询用户提现列表
* @param params
* @return
*/
public List<Map<String, Object>> search(Map<String, Object> params) {
List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
params.put("userId", ActionUtil.getUser().getClient_id());
List<UserKitingInfo> list = userKitingDao.searchByUserId(params);
for (UserKitingInfo userKitingInfo : list) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("kitAt", DateUtil.parseDate(userKitingInfo.getKitAt(), DateEnum.DATETIME));
map.put("kitAmount", userKitingInfo.getKitAmount());
map.put("kitFare", userKitingInfo.getKitFare());
map.put("payableAmount", userKitingInfo.getPayableAmount());
switch (Integer.parseInt(userKitingInfo.getKitStatus())) {
case 0:
map.put("kitStatus", "申请失败");
break;
case 1:
map.put("kitStatus", "已申请");
break;
case 2:
map.put("kitStatus", "处理中");
break;
case 3:
map.put("kitStatus", "已成功");
break;
case 4:
map.put("kitStatus", "申请否决");
break;
default:
break;
}
returnList.add(map);
}
return returnList;
}
/**
* 查询最近一条提现记录的支行名称
* @return
*/
public String querySubBranch() {
UserKitingInfo kitingInfo = userKitingDao
.queryLastKitingInfo(ActionUtil.getUser().getClient_id());
if (kitingInfo == null) {
return "";
}
if (StringUtils.isBlank(kitingInfo.getSubBranch())) {
return "";
}
return kitingInfo.getSubBranch();
}
}