/
zj
2025-05-02 9102aa7e0b42ce5b9667fa3b67fede889df60fc0
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
package project.withdraw.internal;
 
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.security.providers.encoding.PasswordEncoder;
 
import kernel.bo.RecordObjectMapper;
import kernel.exception.BusinessException;
import kernel.util.Arith;
import kernel.util.StringUtils;
import kernel.web.ApplicationUtil;
import kernel.web.Page;
import kernel.web.PagedQueryDao;
import project.Constants;
import project.log.Log;
import project.log.LogService;
import project.log.MoneyLog;
import project.log.MoneyLogService;
import project.party.recom.UserRecomService;
import project.tip.TipService;
import project.user.UserDataService;
import project.wallet.*;
import project.withdraw.AdminWithdrawService;
import project.withdraw.Withdraw;
import security.SecUser;
import security.internal.SecUserService;
import project.web.api.HttpsTransport;
import project.web.api.JsonUtils;
 
public class AdminWithdrawServiceImpl implements AdminWithdrawService {
    
    private JdbcTemplate jdbcTemplate;
    private WalletService walletService;
    private MoneyLogService moneyLogService;
    private PagedQueryDao pagedQueryDao;
    private UserRecomService userRecomService;
    private WalletLogService walletLogService;
    private PasswordEncoder passwordEncoder;
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
    private UserDataService userDataService;
    private LogService logService;
    private SecUserService secUserService;
    private TipService tipService;
    
    @Override
    public void saveReject(String id, String failure_msg, String userName, String partyId) {
        Withdraw withdraw = this.get(id);
 
        if (withdraw.getSucceeded() == 2 ) {// 通过后不可驳回
            return;
        }
        Date date = new Date();
        withdraw.setReviewTime(date);
 
        withdraw.setFailure_msg(failure_msg);
        withdraw.setSucceeded(2);
 
        this.updateWithdraw(withdraw);
 
        String symbol = "";
        if (withdraw.getMethod().indexOf("BTC") != -1) {
            symbol = "btc";
        } else if (withdraw.getMethod().indexOf("ETH") != -1) {
            symbol = "eth";
        } else {
            symbol = "usdt";
        }
        if ("usdt".equals(symbol)) {
            Wallet wallet = walletService.saveWalletByPartyId(withdraw.getPartyId());
 
            double amount_before = wallet.getMoney();
 
            walletService.update(wallet.getPartyId().toString(),
                    Arith.add(withdraw.getAmount(), withdraw.getAmount_fee()));
 
            /*
             * 保存资金日志
             */
            MoneyLog moneyLog = new MoneyLog();
            moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_COIN);
            moneyLog.setAmount_before(amount_before);
            moneyLog.setAmount(Arith.add(withdraw.getAmount(), withdraw.getAmount_fee()));
            moneyLog.setAmount_after(
                    Arith.add(amount_before, Arith.add(withdraw.getAmount(), withdraw.getAmount_fee())));
 
            moneyLog.setLog("驳回提现[" + withdraw.getOrder_no() + "]");
            // moneyLog.setExtra(withdraw.getOrder_no());
            moneyLog.setPartyId(withdraw.getPartyId());
            moneyLog.setWallettype(Constants.WALLET);
            moneyLog.setContent_type(Constants.MONEYLOG_CONTENT_WITHDRAW);
 
            moneyLogService.save(moneyLog);
        } else {
            WalletExtend walletExtend = walletService.saveExtendByPara(withdraw.getPartyId(), symbol);
            double amount_before = walletExtend.getAmount();
            walletService.updateExtend(withdraw.getPartyId().toString(), symbol, withdraw.getVolume());
 
            /*
             * 保存资金日志
             */
            MoneyLog moneyLog = new MoneyLog();
            moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_COIN);
            moneyLog.setAmount_before(amount_before);
            moneyLog.setAmount(withdraw.getVolume());
            moneyLog.setAmount_after(Arith.add(amount_before, withdraw.getVolume()));
 
            moneyLog.setLog("驳回提现[" + withdraw.getOrder_no() + "]");
            // moneyLog.setExtra(withdraw.getOrder_no());
            moneyLog.setPartyId(withdraw.getPartyId());
            moneyLog.setWallettype(symbol.toUpperCase());
            moneyLog.setContent_type(Constants.MONEYLOG_CONTENT_WITHDRAW);
 
            moneyLogService.save(moneyLog);
        }
        this.walletLogService.updateStatus(withdraw.getOrder_no(), withdraw.getSucceeded());
 
        SecUser SecUser = secUserService.findUserByPartyId(withdraw.getPartyId());
        Log log = new Log();
        log.setCategory(Constants.LOG_CATEGORY_OPERATION);
        log.setExtra(withdraw.getOrder_no());
        log.setOperator(userName);
        log.setPartyId(withdraw.getPartyId());
        log.setUsername(SecUser.getUsername());
        log.setLog("驳回提现申请。原因[" + withdraw.getFailure_msg() + "],订单号[" + withdraw.getOrder_no() + "]");
 
        logService.saveSync(log);
        tipService.deleteTip(withdraw.getId().toString());
    }
 
 
    @Override
    public void saveSucceeded(String id, String safeword, String userName, String partyId) {
        SecUser var5 = this.secUserService.findUserByLoginName(userName);
        String var6 = var5.getSafeword();
        String var7 = this.passwordEncoder.encodePassword(safeword, userName);
        if (!var7.equals(var6)) {
            throw new BusinessException("资金密码错误");
        } else {
            Withdraw var8 = this.get(id);
            Date var9 = new Date();
            var8.setReviewTime(var9);
            if (var8 != null && var8.getSucceeded() == 0) {
                String var10 = "";
                if (var8.getMethod().indexOf("BTC") != -1) {
                    var10 = "btc";
                } else if (var8.getMethod().indexOf("ETH") != -1) {
                    var10 = "eth";
                } else {
                    var10 = "usdt";
                }
 
                var8.setSucceeded(1);
                this.updateWithdraw(var8);
                this.walletLogService.updateStatus(var8.getOrder_no(), var8.getSucceeded());
                this.userDataService.saveWithdrawHandle(var8.getPartyId(), var8.getAmount(), var8.getAmount_fee(), var10);
                SecUser var11 = this.secUserService.findUserByPartyId(var8.getPartyId());
                Log var12 = new Log();
                var12.setCategory("operation");
                var12.setExtra(var8.getOrder_no());
                var12.setOperator(userName);
                var12.setUsername(var11.getUsername());
                var12.setPartyId(var11.getPartyId());
                var12.setLog("通过提现申请。订单号[" + var8.getOrder_no() + "]。");
                this.logService.saveSync(var12);
                this.tipService.deleteTip(var8.getId().toString());
            }
 
        }
    }
 
    /**
     * 修改提现描述
     */
    public void updateWithdraw(String id,String partyId,String remark) {
        Withdraw withdraw = this.get(id);
        if (withdraw != null ) {
            withdraw.setFailure_msg(remark);
            this.updateWithdraw(withdraw);
        }
    }
    
    /**
     * 修改用户提现地址
     */
    public void saveAddress(String id,String safeword,String userName,String partyId,String newAddress) {
        SecUser sec = this.secUserService.findUserByLoginName(userName);
        String sysSafeword = sec.getSafeword();
 
        String safeword_md5 = passwordEncoder.encodePassword(safeword, userName);
        if (!safeword_md5.equals(sysSafeword)) {
            throw new BusinessException("资金密码错误");
        }
 
        Withdraw withdraw = this.get(id);
 
        if (withdraw != null ) {
            String oldaddres = withdraw.getAddress();
            withdraw.setAddress(newAddress);
 
            this.updateWithdraw(withdraw);
 
            SecUser SecUser = secUserService.findUserByPartyId(withdraw.getPartyId());
            Log log = new Log();
            log.setCategory(Constants.LOG_CATEGORY_OPERATION);
            log.setExtra(withdraw.getOrder_no());
            log.setOperator(userName);
            log.setUsername(SecUser.getUsername());
            log.setPartyId(SecUser.getPartyId());
            log.setLog("后台手动修改用户提现订单提现地址。提现订单号[" + withdraw.getOrder_no() + "],旧提现地址["+oldaddres+"],修改后提现订单新提现地址["+newAddress+"]");
 
            logService.saveSync(log);
        }
 
    }
    
    
//    public void saveSucceededThird(String id, String safeword, String userName, String partyId) {
//        SecUser sec = this.secUserService.findUserByLoginName(userName);
//        String sysSafeword = sec.getSafeword();
//
//        String safeword_md5 = passwordEncoder.encodePassword(safeword, userName);
//        if (!safeword_md5.equals(sysSafeword)) {
//            throw new BusinessException("资金密码错误");
//        }
//
//        Withdraw withdraw = this.get(id);
//        Date date = new Date();
//        withdraw.setReviewTime(date);
//
//        /**
//         * 
//         */
//
//        if (withdraw != null && withdraw.getSucceeded() == 0) {
//            //三方提现处理
//            thirdHandle(withdraw);
//            String symbol = "";
//            if (withdraw.getMethod().indexOf("BTC") != -1) {
//                symbol = "btc";
//            } else if (withdraw.getMethod().indexOf("ETH") != -1) {
//                symbol = "eth";
//            } else {
//                symbol = "usdt";
//            }
//
//            withdraw.setSucceeded(1);
//            this.getHibernateTemplate().update(withdraw);
//
//            this.walletLogService.updateStatus(withdraw.getOrder_no(), withdraw.getSucceeded());
//            /**
//             * 提现订单加入userdate
//             */
//            this.userDataService.saveWithdrawHandle(withdraw.getPartyId(), withdraw.getAmount(),
//                    withdraw.getAmount_fee(), symbol);
//
//            SecUser SecUser = secUserService.findUserByPartyId(withdraw.getPartyId());
//            Log log = new Log();
//            log.setCategory(Constants.LOG_CATEGORY_OPERATION);
//            log.setExtra(withdraw.getOrder_no());
//            log.setOperator(userName);
//            log.setUsername(SecUser.getUsername());
//            log.setPartyId(SecUser.getPartyId());
//            log.setLog("通过提现申请。订单号[" + withdraw.getOrder_no() + "]。");
//
//            logService.saveSync(log);
//            tipService.deleteTip(withdraw.getId().toString());
//        }
//
//    }
//    /**
//     * 三方区块链提现处理
//     * @param withdraw
//     */
//    public void thirdHandle(Withdraw withdraw) {
//        String method = withdraw.getMethod();
//        String[] methodArr = method.split("_");
//        String symbol = methodArr[0];
//        String blockchain = methodArr.length==2?methodArr[1]:"";
//        Map<String,Object> param = new HashMap<String, Object>();
//        param.put("address", withdraw.getAddress());
//        param.put("order_no", withdraw.getOrder_no());
//        param.put("symbol", symbol);
//        param.put("blockchain", blockchain);
//        param.put("amount", withdraw.getAmount());
//        thirdBlockChainService.initThirdBlockChainBusinessService();
//        thirdBlockChainService.withdraw(param);
//    }
    @Override
    public Page pagedQuery(int pageNo, int pageSize, String name_para, Integer succeeded, String loginPartyId,
            String orderNo, String rolename_para) {
 
        StringBuffer queryString = new StringBuffer();
        queryString.append("SELECT");
        queryString.append(
                " party.USERNAME username,party.ROLENAME rolename,party.USERCODE usercode, party.REMARKS userRemarks,");
        queryString.append(
                " withdraw.UUID id,withdraw.ORDER_NO order_no,withdraw.CREATE_TIME createTime,withdraw.FAILURE_MSG failure_msg,");
        queryString.append(" withdraw.AMOUNT amount,withdraw.SUCCEEDED succeeded,withdraw.REVIEWTIME reviewTime, withdraw.REMARKS remarks, ");
        queryString.append(
                " withdraw.CURRENCY currency,withdraw.AMOUNT_FEE amount_fee,withdraw.DEVICE_IP deviceIp, ");
        queryString.append(
                " withdraw.METHOD method, withdraw.QDCODE qdcode, withdraw.CHAIN_ADDRESS address,withdraw.TIME_SETTLE time_settle,"
                        + " withdraw.VOLUME volume, party_parent.USERNAME username_parent ");
        queryString.append(" FROM");
        queryString
                .append(" T_WITHDRAW_ORDER withdraw  " + " LEFT JOIN PAT_PARTY party ON withdraw.PARTY_ID = party.UUID "
                        + " LEFT JOIN PAT_USER_RECOM user ON user.PARTY_ID = party.UUID  "
                        + "  LEFT JOIN PAT_PARTY party_parent ON user.RECO_ID = party_parent.UUID   " + "");
        queryString.append(" WHERE 1=1 ");
 
        Map<String, Object> parameters = new HashMap<String, Object>();
 
        if (!StringUtils.isNullOrEmpty(loginPartyId)) {
            List children = this.userRecomService.findChildren(loginPartyId);
            if (children.size() == 0) {
//                return Page.EMPTY_PAGE;
                return new Page();
            }
            queryString.append(" and withdraw.PARTY_ID in (:children) ");
            parameters.put("children", children);
        }
 
//        if (!StringUtils.isNullOrEmpty(name_para)) {
//            queryString.append(" and (party.USERNAME like :name_para or party.USERCODE =:usercode) ");
//            parameters.put("name_para", "%" + name_para + "%");
//            parameters.put("usercode", name_para);
//
//        }
 
        if (succeeded != null) {
            queryString.append(" and withdraw.SUCCEEDED = :succeeded  ");
            parameters.put("succeeded", succeeded);
 
        }
        if (!StringUtils.isNullOrEmpty(name_para)) {
            queryString.append("AND (party.USERNAME like:username OR party.USERCODE like:username ) ");
            parameters.put("username", "%" + name_para + "%");
        }
        if (!StringUtils.isNullOrEmpty(rolename_para)) {
            queryString.append(" and   party.ROLENAME =:rolename");
            parameters.put("rolename", rolename_para);
        }
        if (!StringUtils.isNullOrEmpty(orderNo)) {
            queryString.append(" and withdraw.ORDER_NO = :orderNo  ");
            parameters.put("orderNo", orderNo);
 
        }
 
        queryString.append(" order by withdraw.CREATE_TIME desc ");
 
        Page page = pagedQueryDao.pagedQuerySQL(pageNo, pageSize, queryString.toString(), parameters);
 
        return page;
    }
 
    public int getCount(Integer state_para, String loginPartyId) {
        StringBuffer queryString = new StringBuffer();
        queryString.append("SELECT ");
        queryString.append(" count(withdraw.UUID) id_count");
 
        queryString.append(" FROM");
        queryString.append(" T_WITHDRAW_ORDER withdraw   ");
        queryString.append(" WHERE 1=1");
 
        Map parameters = new HashMap();
        if (state_para != null) {
            queryString.append(" and withdraw.SUCCEEDED = :state_para");
            parameters.put("state_para", state_para);
        }
        if (!StringUtils.isNullOrEmpty(loginPartyId)) {
            queryString.append(" and withdraw.PARTY_ID  = :loginPartyId");
            parameters.put("loginPartyId", loginPartyId);
        }
        List list = this.namedParameterJdbcTemplate.queryForList(queryString.toString(), parameters);
 
        Map map = new HashMap();
        if (list.size() > 0) {
            Object obj = ((Map) list.get(0)).get("id_count");
            if (obj != null) {
                return Integer.valueOf(String.valueOf(obj));
            } else {
                return 0;
            }
        } else {
            return 0;
        }
 
    }
    
    public Withdraw get(String id) {
        List<Withdraw> list = jdbcTemplate.query("SELECT * FROM T_WITHDRAW_ORDER WHERE UUID=?", RecordObjectMapper.newInstance(Withdraw.class), id);
        if (null != list && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
    
    public void insertWithdraw(Withdraw withdraw) {
        Object[] jdbcParams = ApplicationUtil.getInsertStatement(withdraw);
        String insertUserSql = (String)jdbcParams[0];
        Object[] sqlParameters = (Object[])jdbcParams[1];
        jdbcTemplate.update(insertUserSql, sqlParameters);
    }
 
 
    public void updateWithdraw(Withdraw withdraw) {
        Object[] jdbcParams = ApplicationUtil.getUpdateStatement(withdraw,"WHERE UUID=?",new Object[] {withdraw.getId()});
        String updateUserSql = (String)jdbcParams[0];
        Object[] sqlParameters = (Object[])jdbcParams[1];
        jdbcTemplate.update(updateUserSql, sqlParameters);
    }
    
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
    
    public void setWalletService(WalletService walletService) {
        this.walletService = walletService;
    }
 
    public void setMoneyLogService(MoneyLogService moneyLogService) {
        this.moneyLogService = moneyLogService;
    }
 
    public void setPagedQueryDao(PagedQueryDao pagedQueryDao) {
        this.pagedQueryDao = pagedQueryDao;
    }
 
    public void setUserRecomService(UserRecomService userRecomService) {
        this.userRecomService = userRecomService;
    }
 
    public void setWalletLogService(WalletLogService walletLogService) {
        this.walletLogService = walletLogService;
    }
 
    public void setPasswordEncoder(PasswordEncoder passwordEncoder) {
        this.passwordEncoder = passwordEncoder;
    }
 
    public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() {
        return namedParameterJdbcTemplate;
    }
 
    public void setNamedParameterJdbcTemplate(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
        this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
    }
 
    public void setUserDataService(UserDataService userDataService) {
        this.userDataService = userDataService;
    }
 
    public void setLogService(LogService logService) {
        this.logService = logService;
    }
 
    public void setSecUserService(SecUserService secUserService) {
        this.secUserService = secUserService;
    }
 
    public void setTipService(TipService tipService) {
        this.tipService = tipService;
    }
    
}