zj
2024-06-03 3603ecb207f7e712c635f19531e05fac4d19e53f
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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
package project.blockchain.internal;
 
import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
 
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.jdbc.core.JdbcTemplate;
 
import kernel.bo.RecordObjectMapper;
import kernel.exception.BusinessException;
import kernel.util.Arith;
import kernel.web.ApplicationUtil;
import project.Constants;
import project.blockchain.ChannelBlockchain;
import project.blockchain.ChannelBlockchainService;
import project.blockchain.RechargeBlockchain;
import project.blockchain.RechargeBlockchainService;
import project.bonus.RechargeBonusService;
import project.data.DataService;
import project.data.model.Realtime;
import project.log.Log;
import project.log.LogService;
import project.log.MoneyLog;
import project.log.MoneyLogService;
import project.party.PartyService;
import project.party.model.Party;
import project.syspara.Syspara;
import project.syspara.SysparaService;
import project.tip.TipConstants;
import project.tip.TipService;
import project.user.UserDataService;
import project.wallet.Wallet;
import project.wallet.WalletExtend;
import project.wallet.WalletLog;
import project.wallet.WalletLogService;
import project.wallet.WalletService;
import project.wallet.rate.ExchangeRateService;
import security.SecUser;
import security.internal.SecUserService;
import util.DateUtil;
import util.RandomUtil;
 
public class RechargeBlockchainServiceImpl implements RechargeBlockchainService {
 
    protected JdbcTemplate jdbcTemplate;
    protected UserDataService userDataService;
    protected WalletService walletService;
    protected MoneyLogService moneyLogService;
    protected ExchangeRateService exchangeRateService;
    protected WalletLogService walletLogService;
    protected RechargeBonusService rechargeBonusService;
    protected DataService dataService;
    protected LogService logService;
    protected SecUserService secUserService;
    protected PartyService partyService;
    protected SysparaService sysparaService;
    protected ChannelBlockchainService channelBlockchainService;
    protected TipService tipService;
 
    @Override
    public void save(RechargeBlockchain recharge) {
 
        List<RechargeBlockchain> oreders = this.findByPartyIdAndSucceeded(recharge.getPartyId(), 0);
        double recharge_only_one = Double.valueOf(sysparaService.find("recharge_only_one").getValue());
        if (oreders != null && recharge_only_one==1) {
            throw new BusinessException("提交失败,当前有未处理订单");
        }
        
        if (!"ETH".equals(recharge.getSymbol().toUpperCase())) {
            JdbcTemplate jdbcTemplate=ApplicationUtil.getBean(JdbcTemplate.class);
            List<HashMap> list=jdbcTemplate.query("SELECT * FROM T_PARTY_BLOCKCHAIN WHERE ADDRESS =?",RecordObjectMapper.newInstance(HashMap.class),recharge.getChannel_address());
            if(ObjectUtils.isEmpty(list)) {
                ChannelBlockchain channel = channelBlockchainService.findByNameAndCoinAndAdd(recharge.getBlockchain_name(),
                        recharge.getSymbol(), recharge.getChannel_address());
 
                if (channel == null || !recharge.getSymbol().toUpperCase().equals(channel.getCoin())) {
                    throw new BusinessException("充值链错误");
                }
            }
        }
 
        DecimalFormat df = new DecimalFormat("#.##");
//        amount = Double.valueOf(df.format(amount));
        double recharge_limit_min = Double.valueOf(sysparaService.find("recharge_limit_min").getValue());
        double recharge_limit_max = Double.valueOf(sysparaService.find("recharge_limit_max").getValue());
        if ("usdt".equals(recharge.getSymbol())||"usdc".equals(recharge.getSymbol())) {
            if (recharge.getVolume() < recharge_limit_min) {
                throw new BusinessException("充值价值不得小于最小限额");
            }
 
            if (recharge.getVolume() > recharge_limit_max) {
                throw new BusinessException("充值价值不得大于最大限额");
            }
 
        } else {
 
            List<Realtime> realtime_list = this.dataService.realtime(recharge.getSymbol());
            Realtime realtime = null;
            if (realtime_list.size() > 0) {
                realtime = realtime_list.get(0);
            } else {
                throw new BusinessException("系统错误,请稍后重试");
            }
            double transfer_usdt = Arith.mul(realtime.getClose(), recharge.getVolume());// 对应usdt价格
            if (transfer_usdt < recharge_limit_min) {
 
                throw new BusinessException("充值价值不得小于最小限额");
            }
 
            if (transfer_usdt > recharge_limit_max) {
                throw new BusinessException("充值价值不得大于最大限额");
            }
 
        }
 
        recharge.setCreated(new Date());
        if ("".equals(recharge.getOrder_no()) || recharge.getOrder_no() == null) {
            recharge.setOrder_no(DateUtil.getToday("yyMMddHHmmss") + RandomUtil.getRandomNum(8));
        }
 
        recharge.setId(ApplicationUtil.getCurrentTimeUUID());
        this.insertRechargeBlockchain(recharge);
 
        /*
         * 保存资金日志
         */
        WalletLog walletLog = new WalletLog();
        walletLog.setCategory(Constants.MONEYLOG_CATEGORY_RECHARGE);
        walletLog.setPartyId(recharge.getPartyId());
        walletLog.setOrder_no(recharge.getOrder_no());
        walletLog.setStatus(recharge.getSucceeded());
 
        walletLog.setAmount(recharge.getVolume());
        walletLog.setWallettype(recharge.getSymbol());
        walletLog.setCreateTime(new Date());
        walletLogService.save(walletLog);
 
        tipService.saveTip(recharge.getId().toString(), TipConstants.RECHARGE_BLOCKCHAIN);
    }
 
    @Override
    public void save_api(RechargeBlockchain recharge) {
 
        if (!"ETH".equals(recharge.getSymbol().toUpperCase())) {
            ChannelBlockchain channel = channelBlockchainService.findByNameAndCoinAndAdd(recharge.getBlockchain_name(),
                    recharge.getSymbol(), recharge.getChannel_address());
 
            if (channel == null || !recharge.getSymbol().toUpperCase().equals(channel.getCoin())) {
                throw new BusinessException("充值链错误");
            }
        }
 
        double recharge_limit_min = Double.valueOf(sysparaService.find("recharge_limit_min").getValue());
        double recharge_limit_max = Double.valueOf(sysparaService.find("recharge_limit_max").getValue());
        if ("usdt".equals(recharge.getSymbol())) {
            if (recharge.getVolume() < recharge_limit_min) {
                throw new BusinessException("充值价值不得小于最小限额");
            }
 
            if (recharge.getVolume() > recharge_limit_max) {
                throw new BusinessException("充值价值不得大于最大限额");
            }
 
        } else {
 
            List<Realtime> realtime_list = this.dataService.realtime(recharge.getSymbol());
            Realtime realtime = null;
            if (realtime_list.size() > 0) {
                realtime = realtime_list.get(0);
            } else {
                throw new BusinessException("系统错误,请稍后重试");
            }
            double transfer_usdt = Arith.mul(realtime.getClose(), recharge.getVolume());// 对应usdt价格
            if (transfer_usdt < recharge_limit_min) {
                throw new BusinessException("充值价值不得小于最小限额");
            }
 
            if (transfer_usdt > recharge_limit_max) {
                throw new BusinessException("充值价值不得大于最大限额");
            }
 
        }
        recharge.setCreated(new Date());
        if ("".equals(recharge.getOrder_no()) || recharge.getOrder_no() == null) {
            recharge.setOrder_no(DateUtil.getToday("yyMMddHHmmss") + RandomUtil.getRandomNum(8));
        }
 
        /*
         * 保存资金日志
         */
        WalletLog walletLog = new WalletLog();
        walletLog.setCategory(Constants.MONEYLOG_CATEGORY_RECHARGE);
        walletLog.setPartyId(recharge.getPartyId());
        walletLog.setOrder_no(recharge.getOrder_no());
 
        walletLog.setAmount(recharge.getVolume());
        walletLog.setWallettype(recharge.getSymbol());
        walletLog.setCreateTime(new Date());
 
        Date date = new Date();
        recharge.setReviewTime(date);
        recharge.setSucceeded(1);
 
        /**
         * 如果是usdt则加入wallet,否则寻找walletExtend里相同币种
         */
 
        Party party = this.partyService.cachePartyBy(recharge.getPartyId(), false);
 
        Syspara user_recom_bonus_open = sysparaService.find("user_recom_bonus_open");
 
        if ("usdt".equals(recharge.getSymbol())) {
            double amount = recharge.getVolume();
            Wallet wallet = new Wallet();
            wallet = walletService.saveWalletByPartyId(recharge.getPartyId());
 
            double amount_before = wallet.getMoney();
 
            walletService.update(wallet.getPartyId().toString(), amount);
 
            /*
             * 保存资金日志
             */
            MoneyLog moneyLog = new MoneyLog();
            moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_COIN);
            moneyLog.setAmount_before(amount_before);
            moneyLog.setAmount(amount);
            moneyLog.setAmount_after(Arith.add(wallet.getMoney(), amount));
 
            moneyLog.setLog("使用区块链三方接口充值订单[" + recharge.getOrder_no() + "]");
            moneyLog.setPartyId(recharge.getPartyId());
            moneyLog.setWallettype(Constants.WALLET);
            moneyLog.setContent_type(Constants.MONEYLOG_CONTENT_RECHARGE);
            moneyLog.setCreateTime(new Date());
            moneyLogService.save(moneyLog);
 
            walletLog.setStatus(recharge.getSucceeded());
            walletLogService.save(walletLog);
 
            /**
             * 创建订单
             */
            recharge.setId(ApplicationUtil.getCurrentTimeUUID());
            this.insertRechargeBlockchain(recharge);
            /**
             * 给他的代理添加充值记录
             */
            userDataService.saveRechargeHandle(recharge.getPartyId(), recharge.getVolume(), recharge.getSymbol());
 
            /**
             * 若已开启充值奖励 ,则充值到账后给他的代理用户添加奖金
             */
            if ("true".equals(user_recom_bonus_open.getValue())) {
                rechargeBonusService.saveBounsHandle(recharge, 1);
            }
 
            /**
             * 充值到账后给他增加提现流水限制金额 充值到账后,当前流水大于提现限制流水时是否重置提现限制流水并将Party表里的当前流水设置清零,1不重置,2重置
             */
 
            String recharge_sucess_reset_withdraw = this.sysparaService.find("recharge_sucess_reset_withdraw")
                    .getValue();
            if ("1".equals(recharge_sucess_reset_withdraw)) {
                party.setWithdraw_limit_amount(Arith.add(party.getWithdraw_limit_amount(), amount));
                if (party.getWithdraw_limit_now_amount() > party.getWithdraw_limit_amount()) {
                    party.setWithdraw_limit_now_amount(0);
                }
            }
            if ("2".equals(recharge_sucess_reset_withdraw)) {
                double withdraw_limit_turnover_percent = Double
                        .valueOf(sysparaService.find("withdraw_limit_turnover_percent").getValue());
                double party_withdraw = Arith.mul(party.getWithdraw_limit_amount(), withdraw_limit_turnover_percent);
 
                if (party.getWithdraw_limit_now_amount() >= party_withdraw) {
                    party.setWithdraw_limit_amount(amount);
                    party.setWithdraw_limit_now_amount(0);
                } else {
                    party.setWithdraw_limit_amount(Arith.add(party.getWithdraw_limit_amount(), amount));
                }
            }
 
            partyService.update(party);
 
        } else {
 
            List<Realtime> realtime_list = this.dataService.realtime(recharge.getSymbol());
            Realtime realtime = null;
            if (realtime_list.size() > 0) {
                realtime = realtime_list.get(0);
            } else {
                throw new BusinessException("系统错误,请稍后重试");
            }
            double transfer_usdt = realtime.getClose();// 对应usdt价格
 
            WalletExtend walletExtend = new WalletExtend();
            walletExtend = walletService.saveExtendByPara(recharge.getPartyId(), recharge.getSymbol());
 
            double volume = recharge.getVolume();
            double amount_before = walletExtend.getAmount();
 
            walletService.updateExtend(walletExtend.getPartyId().toString(), walletExtend.getWallettype(), volume);
 
            /**
             * 创建订单
             */
            recharge.setId(ApplicationUtil.getCurrentTimeUUID());
            this.insertRechargeBlockchain(recharge);
            /**
             * 币种usdt价格= 币种价格×充值数量
             */
            double usdt_amount = Arith.mul(volume, transfer_usdt);
            /*
             * 保存资金日志
             */
            MoneyLog moneyLog = new MoneyLog();
            moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_COIN);
            moneyLog.setAmount_before(amount_before);
            moneyLog.setAmount(volume);
            moneyLog.setAmount_after(Arith.add(walletExtend.getAmount(), volume));
 
            moneyLog.setLog("使用区块链三方接口充值订单[" + recharge.getOrder_no() + "]");
            moneyLog.setPartyId(recharge.getPartyId());
            moneyLog.setWallettype(recharge.getSymbol());
            moneyLog.setContent_type(Constants.MONEYLOG_CONTENT_RECHARGE);
            moneyLog.setCreateTime(new Date());
            moneyLogService.save(moneyLog);
 
            walletLog.setStatus(recharge.getSucceeded());
            walletLogService.save(walletLog);
            /**
             * 给他的代理添加充值记录
             */
            userDataService.saveRechargeHandle(recharge.getPartyId(), recharge.getVolume(), recharge.getSymbol());
            /**
             * 买币-币冲充值其他非usdt币时使用
             */
//            userDataService.saveBuy(recharge.getPartyId(), recharge.getSymbol(), recharge.getVolume());
 
            /**
             * 充值到账后给他的代理用户添加奖金
             */
            if ("true".equals(user_recom_bonus_open.getValue())) {
                rechargeBonusService.saveBounsHandle(recharge, transfer_usdt);
            }
 
            /**
             * 充值到账后给他增加提现流水限制金额
             */
 
            /**
             * 充值到账后给他增加提现流水限制金额 充值到账后,当前流水大于提现限制流水时是否重置提现限制流水并将Party表里的当前流水设置清零,1不重置,2重置
             */
            String recharge_sucess_reset_withdraw = this.sysparaService.find("recharge_sucess_reset_withdraw")
                    .getValue();
            if ("1".equals(recharge_sucess_reset_withdraw)) {
                party.setWithdraw_limit_amount(Arith.add(party.getWithdraw_limit_amount(), usdt_amount));
                if (party.getWithdraw_limit_now_amount() > party.getWithdraw_limit_amount()) {
                    party.setWithdraw_limit_now_amount(0);
                }
            }
            if ("2".equals(recharge_sucess_reset_withdraw)) {
                double withdraw_limit_turnover_percent = Double
                        .valueOf(sysparaService.find("withdraw_limit_turnover_percent").getValue());
                double party_withdraw = Arith.mul(party.getWithdraw_limit_amount(), withdraw_limit_turnover_percent);
 
                if (party.getWithdraw_limit_now_amount() >= party_withdraw) {
                    party.setWithdraw_limit_amount(usdt_amount);
                    party.setWithdraw_limit_now_amount(0);
                } else {
                    party.setWithdraw_limit_amount(Arith.add(party.getWithdraw_limit_amount(), usdt_amount));
                }
            }
 
            partyService.update(party);
 
        }
 
        Log log = new Log();
        log.setCategory(Constants.LOG_CATEGORY_OPERATION);
        log.setExtra(recharge.getOrder_no());
        log.setUsername(party.getUsername());
        log.setPartyId(recharge.getPartyId());
        log.setCreateTime(new Date());
        log.setLog("使用区块链三方接口到账一笔充值订单。订单号[" + recharge.getOrder_no() + "]。");
 
        logService.saveSync(log);
        tipService.deleteTip(recharge.getId().toString());
 
    }
    
    /**
     * 根据ID获取充值订单
     */
    public RechargeBlockchain get(String id) {
        List<RechargeBlockchain> list = jdbcTemplate.query("SELECT * FROM T_RECHARGE_BLOCKCHAIN_ORDER WHERE UUID=?", RecordObjectMapper.newInstance(RechargeBlockchain.class), id);
        if (null != list && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
    
    @Override
    public RechargeBlockchain findByOrderNo(String order_no) {
        List<RechargeBlockchain> list = jdbcTemplate.query("SELECT * FROM T_RECHARGE_BLOCKCHAIN_ORDER WHERE ORDER_NO=?", 
                RecordObjectMapper.newInstance(RechargeBlockchain.class), order_no);
        if (null != list && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
 
    public List<RechargeBlockchain> findByPartyIdAndToday(Serializable partyId) {
        List<RechargeBlockchain> list = jdbcTemplate.query("SELECT * FROM T_RECHARGE_BLOCKCHAIN_ORDER WHERE PARTY_ID=? AND DateDiff(CREATED,NOW())=0 ", 
                RecordObjectMapper.newInstance(RechargeBlockchain.class), partyId);
        if (list.size() > 0) {
            return list;
        }
        return null;
    }
 
    public List<RechargeBlockchain> findBySucceededAndDay(int succeeded, Integer days) {
        List<RechargeBlockchain> list = jdbcTemplate.query("SELECT * FROM T_RECHARGE_BLOCKCHAIN_ORDER WHERE SUCCEEDED=? AND DateDiff(CREATED,NOW())=-1 ", 
                RecordObjectMapper.newInstance(RechargeBlockchain.class), succeeded);
        if (list.size() > 0) {
            return list;
        }
        return null;
    }
 
    public List<RechargeBlockchain> findByPartyIdAndSucceeded(Serializable partyId, int succeeded) {
        List<RechargeBlockchain> list = jdbcTemplate.query("SELECT * FROM T_RECHARGE_BLOCKCHAIN_ORDER WHERE PARTY_ID=? AND SUCCEEDED=? ", 
                RecordObjectMapper.newInstance(RechargeBlockchain.class), partyId, succeeded);
        if (list.size() > 0) {
            return list;
        }
        return null;
    }
 
    @Override
    public boolean saveSucceeded(String id, String operator, double success_amount) {
        // RechargeBlockchain recharge = this.findByOrderNo(order_no);
        RechargeBlockchain recharge = this.get(id);
        String order_no = recharge.getOrder_no();
        if (recharge.getSucceeded() == 1) {
            return false;
        }
        
        recharge.setReviewTime(new Date());
        recharge.setSucceeded(1);
 
        WalletLog walletLog = walletLogService.find(Constants.MONEYLOG_CATEGORY_RECHARGE, recharge.getOrder_no());
        SecUser secUser = secUserService.findUserByPartyId(recharge.getPartyId());
        if (success_amount != recharge.getVolume()) {
            Log log = new Log();
            log.setCategory(Constants.LOG_CATEGORY_OPERATION);
            log.setExtra(order_no);
            log.setOperator(operator);
            log.setUsername(secUser.getUsername());
            log.setPartyId(recharge.getPartyId());
            log.setCreateTime(new Date());
            log.setLog("管理员修改充值数量,原充值数量[" 
            + recharge.getVolume() + "],修改后充值数量[" + success_amount + "]。订单号[" + order_no+ "]。");
 
            logService.saveSync(log);
            walletLog.setAmount(success_amount);
            recharge.setVolume(success_amount);
        }
 
        /**
         * 如果是usdt则加入wallet,否则寻找walletExtend里相同币种
         */
 
        Party party = this.partyService.cachePartyBy(recharge.getPartyId(), false);
 
        Syspara user_recom_bonus_open = sysparaService.find("user_recom_bonus_open");
 
        if ("usdt".equals(recharge.getSymbol())) {
            double amount = recharge.getVolume();
 
            Wallet wallet = new Wallet();
            wallet = walletService.saveWalletByPartyId(recharge.getPartyId());
            
            double amount_before = wallet.getMoney();
            
            walletService.update(wallet.getPartyId().toString(), amount);
 
            // 保存资金日志
            MoneyLog moneyLog = new MoneyLog();
            moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_COIN);
            moneyLog.setAmount_before(amount_before);
            moneyLog.setAmount(amount);
            moneyLog.setAmount_after(Arith.add(wallet.getMoney(), amount));
            moneyLog.setLog("充值订单[" + recharge.getOrder_no() + "]");
            moneyLog.setPartyId(recharge.getPartyId());
            moneyLog.setWallettype(Constants.WALLET);
            moneyLog.setContent_type(Constants.MONEYLOG_CONTENT_RECHARGE);
            moneyLog.setCreateTime(new Date());
            moneyLogService.save(moneyLog);
 
            walletLog.setStatus(recharge.getSucceeded());
            walletLogService.update(walletLog);
 
            this.updateRechargeBlockchain(recharge);
            /**
             * 给他的代理添加充值记录
             */
            userDataService.saveRechargeHandle(recharge.getPartyId(), recharge.getVolume(), recharge.getSymbol());
 
            /**
             * 若已开启充值奖励 ,则充值到账后给他的代理用户添加奖金
             */
            if ("true".equals(user_recom_bonus_open.getValue())) {
                rechargeBonusService.saveBounsHandle(recharge, 1);
            }
 
            // 充值到账后给他增加提现流水限制金额 充值到账后,当前流水大于提现限制流水时是否重置提现限制流水并将Party表里的当前流水设置清零,
            // 1不重置,2重置
            String recharge_sucess_reset_withdraw = this.sysparaService.find("recharge_sucess_reset_withdraw").getValue();
            if ("1".equals(recharge_sucess_reset_withdraw)) {
                party.setWithdraw_limit_amount(Arith.add(party.getWithdraw_limit_amount(), amount));
                if (party.getWithdraw_limit_now_amount() > party.getWithdraw_limit_amount()) {
                    party.setWithdraw_limit_now_amount(0);
                }
            }
            if ("2".equals(recharge_sucess_reset_withdraw)) {
                double withdraw_limit_turnover_percent = Double
                        .valueOf(sysparaService.find("withdraw_limit_turnover_percent").getValue());
                double party_withdraw = Arith.mul(party.getWithdraw_limit_amount(), withdraw_limit_turnover_percent);
 
                if (party.getWithdraw_limit_now_amount() >= party_withdraw) {
                    party.setWithdraw_limit_amount(amount);
                    party.setWithdraw_limit_now_amount(0);
                } else {
                    party.setWithdraw_limit_amount(Arith.add(party.getWithdraw_limit_amount(), amount));
                }
            }
 
            partyService.update(party);
 
        } else {
 
            List<Realtime> realtime_list = this.dataService.realtime(recharge.getSymbol());
            Realtime realtime = null;
            if (realtime_list.size() > 0) {
                realtime = realtime_list.get(0);
            } else {
                throw new BusinessException("系统错误,请稍后重试");
            }
            // 对应usdt价格
            double transfer_usdt = realtime.getClose();
 
            WalletExtend walletExtend = new WalletExtend();
            walletExtend = walletService.saveExtendByPara(recharge.getPartyId(), recharge.getSymbol());
 
            double volume = recharge.getVolume();
 
            double amount_before = walletExtend.getAmount();
 
            // walletExtend = walletService.saveWalletExtendByParaAndUpdate(String.valueOf(recharge.getPartyId()), recharge.getSymbol(), volume);
            walletService.updateExtend(walletExtend.getPartyId().toString(), walletExtend.getWallettype(), volume);
            this.updateRechargeBlockchain(recharge);
            
            // 币种usdt价格= 币种价格×充值数量
            double usdt_amount = Arith.mul(volume, transfer_usdt);
            
            // 保存资金日志
            MoneyLog moneyLog = new MoneyLog();
            moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_COIN);
            moneyLog.setAmount_before(amount_before);
            moneyLog.setAmount(volume);
            moneyLog.setAmount_after(Arith.add(walletExtend.getAmount(), volume));
 
            moneyLog.setLog("充值订单[" + recharge.getOrder_no() + "]");
            moneyLog.setPartyId(recharge.getPartyId());
            moneyLog.setWallettype(recharge.getSymbol());
            moneyLog.setContent_type(Constants.MONEYLOG_CONTENT_RECHARGE);
            moneyLog.setCreateTime(new Date());
            moneyLogService.save(moneyLog);
 
            walletLog.setStatus(recharge.getSucceeded());
            walletLogService.update(walletLog);
            /**
             * 给他的代理添加充值记录
             */
            userDataService.saveRechargeHandle(recharge.getPartyId(), recharge.getVolume(), recharge.getSymbol());
            /**
             * 买币-币冲充值其他非usdt币时使用
             */
//            userDataService.saveBuy(recharge.getPartyId(), recharge.getSymbol(), recharge.getVolume());
 
            /**
             * 充值到账后给他的代理用户添加奖金
             */
            if ("true".equals(user_recom_bonus_open.getValue())) {
                rechargeBonusService.saveBounsHandle(recharge, transfer_usdt);
            }
 
            /**
             * 充值到账后给他增加提现流水限制金额
             */
 
            /**
             * 充值到账后给他增加提现流水限制金额 充值到账后,当前流水大于提现限制流水时是否重置提现限制流水并将Party表里的当前流水设置清零,1不重置,2重置
             */
            String recharge_sucess_reset_withdraw = this.sysparaService.find("recharge_sucess_reset_withdraw")
                    .getValue();
            if ("1".equals(recharge_sucess_reset_withdraw)) {
                party.setWithdraw_limit_amount(Arith.add(party.getWithdraw_limit_amount(), usdt_amount));
                if (party.getWithdraw_limit_now_amount() > party.getWithdraw_limit_amount()) {
                    party.setWithdraw_limit_now_amount(0);
                }
            }
            if ("2".equals(recharge_sucess_reset_withdraw)) {
                double withdraw_limit_turnover_percent = Double
                        .valueOf(sysparaService.find("withdraw_limit_turnover_percent").getValue());
                double party_withdraw = Arith.mul(party.getWithdraw_limit_amount(), withdraw_limit_turnover_percent);
 
                if (party.getWithdraw_limit_now_amount() >= party_withdraw) {
                    party.setWithdraw_limit_amount(usdt_amount);
                    party.setWithdraw_limit_now_amount(0);
                } else {
                    party.setWithdraw_limit_amount(Arith.add(party.getWithdraw_limit_amount(), usdt_amount));
                }
            }
 
            partyService.update(party);
 
        }
 
        Log log = new Log();
        log.setCategory(Constants.LOG_CATEGORY_OPERATION);
        log.setExtra(order_no);
        log.setOperator(operator);
        log.setUsername(secUser.getUsername());
        log.setPartyId(recharge.getPartyId());
        log.setCreateTime(new Date());
        log.setLog("手动到账一笔充值订单。订单号[" + order_no + "]。");
 
        logService.saveSync(log);
        tipService.deleteTip(recharge.getId().toString());
        return true;
 
    }
 
    public boolean saveReject(RechargeBlockchain recharge) {
        // 通过后不可驳回
        if (recharge.getSucceeded() == 2 || recharge.getSucceeded() == 1) {
            return false;
        }
 
        recharge.setSucceeded(2);
 
        this.updateRechargeBlockchain(recharge);
        tipService.deleteTip(recharge.getId().toString());
 
        WalletLog walletLog = walletLogService.find(Constants.MONEYLOG_CATEGORY_RECHARGE, recharge.getOrder_no());
        walletLog.setStatus(recharge.getSucceeded());
        walletLogService.update(walletLog);
 
        return true;
 
    }
    
    public void insertRechargeBlockchain(RechargeBlockchain rechargeBlockchain) {
        Object[] jdbcParams = ApplicationUtil.getInsertStatement(rechargeBlockchain);
        String insertUserSql = (String)jdbcParams[0];
        Object[] sqlParameters = (Object[])jdbcParams[1];
        jdbcTemplate.update(insertUserSql, sqlParameters);
    }
 
    public void updateRechargeBlockchain(RechargeBlockchain rechargeBlockchain) {
        Object[] jdbcParams = ApplicationUtil.getUpdateStatement(rechargeBlockchain, "WHERE UUID=?", new Object[] {rechargeBlockchain.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 setUserDataService(UserDataService userDataService) {
        this.userDataService = userDataService;
    }
 
    public void setWalletService(WalletService walletService) {
        this.walletService = walletService;
    }
 
    public void setMoneyLogService(MoneyLogService moneyLogService) {
        this.moneyLogService = moneyLogService;
    }
 
    public void setExchangeRateService(ExchangeRateService exchangeRateService) {
        this.exchangeRateService = exchangeRateService;
    }
 
    public void setWalletLogService(WalletLogService walletLogService) {
        this.walletLogService = walletLogService;
    }
 
    public void setRechargeBonusService(RechargeBonusService rechargeBonusService) {
        this.rechargeBonusService = rechargeBonusService;
    }
 
    public void setDataService(DataService dataService) {
        this.dataService = dataService;
    }
 
    public void setLogService(LogService logService) {
        this.logService = logService;
    }
 
    public void setSecUserService(SecUserService secUserService) {
        this.secUserService = secUserService;
    }
 
    public void setPartyService(PartyService partyService) {
        this.partyService = partyService;
    }
 
    public void setSysparaService(SysparaService sysparaService) {
        this.sysparaService = sysparaService;
    }
 
    public void setChannelBlockchainService(ChannelBlockchainService channelBlockchainService) {
        this.channelBlockchainService = channelBlockchainService;
    }
 
    public void setTipService(TipService tipService) {
        this.tipService = tipService;
    }
 
}