admin
2019-03-12 0a21bd61c3c7f33606ea8f571e619e5b1a49c404
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
package com.yeshi.fanli.service.impl.user;
 
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayFundTransToaccountTransferRequest;
import com.alipay.api.response.AlipayFundTransToaccountTransferResponse;
import com.google.gson.Gson;
import com.yeshi.fanli.dao.mybatis.AccountMessageMapper;
import com.yeshi.fanli.dao.mybatis.AlipayAccountValidNormalHistoryMapper;
import com.yeshi.fanli.dao.mybatis.ExtractAuditRecordMapper;
import com.yeshi.fanli.dao.mybatis.ExtractMapper;
import com.yeshi.fanli.dao.mybatis.ExtractRecordMapper;
import com.yeshi.fanli.dao.mybatis.HongBaoV2Mapper;
import com.yeshi.fanli.dao.mybatis.MoneyRecordMapper;
import com.yeshi.fanli.dao.mybatis.PayInfoMapper;
import com.yeshi.fanli.dao.mybatis.SystemMapper;
import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
import com.yeshi.fanli.dao.mybatis.hongbao.HongBaoMapper;
import com.yeshi.fanli.dao.mybatis.money.UserMoneyDetailMapper;
import com.yeshi.fanli.dao.user.AccountMessageDao;
import com.yeshi.fanli.dao.user.ExtractDao;
import com.yeshi.fanli.dao.user.ExtractRecordDao;
import com.yeshi.fanli.dao.user.MoneyRecordDao;
import com.yeshi.fanli.entity.bus.user.AlipayTransferResultInfo;
import com.yeshi.fanli.entity.bus.user.Extract;
import com.yeshi.fanli.entity.bus.user.ExtractAuditRecord;
import com.yeshi.fanli.entity.bus.user.ExtractRecord;
import com.yeshi.fanli.entity.bus.user.HongBao;
import com.yeshi.fanli.entity.bus.user.MoneyRecord;
import com.yeshi.fanli.entity.bus.user.PayInfo;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.common.AdminUser;
import com.yeshi.fanli.entity.money.UserMoneyDetail;
import com.yeshi.fanli.exception.ExtractException;
import com.yeshi.fanli.exception.NotExistObjectException;
import com.yeshi.fanli.exception.ObjectStateException;
import com.yeshi.fanli.exception.money.UserMoneyDetailException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.config.SystemConfigService;
import com.yeshi.fanli.service.inter.msg.UserMoneyMsgNotificationService;
import com.yeshi.fanli.service.inter.push.PushService;
import com.yeshi.fanli.service.inter.user.AccountMessageService;
import com.yeshi.fanli.service.inter.user.ExtractRecordService;
import com.yeshi.fanli.service.inter.user.ExtractService;
import com.yeshi.fanli.service.inter.user.MoneyRecordService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.UserNotificationService;
import com.yeshi.fanli.util.CMQManager;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.GsonUtil;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
 
import net.sf.json.JSONObject;
 
@Service
public class ExtractServiceImpl implements ExtractService {
 
    @Resource
    private ExtractDao extractDao;
 
    @Resource
    private UserInfoService userInfoService;
 
    @Resource
    private MoneyRecordService moneyRecordService;
 
    @Resource
    private ConfigService configService;
 
    @Resource
    private ExtractRecordService extractRecordService;
 
    @Resource
    private SystemConfigService systemConfigService;
 
 
    @Resource
    private AccountMessageService accountMessageService;
 
    @Resource
    private ExtractMapper extractMapper;
 
    @Resource
    private ExtractAuditRecordMapper extractAuditRecordMapper;
 
    @Resource
    private UserInfoMapper userInfoMapper;
 
    @Resource
    private ExtractRecordDao extractRecordDao;
 
    @Resource
    private MoneyRecordDao moneyRecordDao;
 
    @Resource
    private AccountMessageDao accountMessageDao;
 
    @Resource
    private PayInfoMapper payInfoMapper;
 
    @Resource
    private MoneyRecordMapper moneyRecordMapper;
 
    @Resource
    private AccountMessageMapper accountMessageMapper;
 
    @Resource
    private ExtractRecordMapper extractRecordMapper;
 
    @Resource
    private SystemMapper systemMapper;
 
    @Resource
    private HongBaoMapper hongBaoMapper;
 
    @Resource
    private HongBaoV2Mapper hongBaoV2Mapper;
 
    @Resource
    private PushService pushService;
 
    @Resource
    private UserNotificationService userNotificationService;
 
    @Resource
    private UserMoneyDetailMapper userMoneyDetailMapper;
 
    @Resource
    private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
 
    @Resource
    private AlipayAccountValidNormalHistoryMapper alipayAccountValidNormalHistoryMapper;
 
    public List<Extract> getExtractInfoByUid(long uid) {
        return extractDao.list("from Extract e where e.userInfo.id=? and e.state != 2", new Serializable[] { uid });
    }
 
    @Transactional
    public Integer addExtract(Extract extract) {
        Integer integer = extract(extract);
        return integer;
    }
 
    public List<Extract> getExtractList(int index) {
        int start = index * Constant.PAGE_SIZE;
        return extractDao.list("from Extract e order by e.id desc", start, Constant.PAGE_SIZE, new Serializable[] {});
    }
 
    public int getCount() {
        Long lcount = extractDao.getCount("select count(e.id) from Extract e");
        return lcount.intValue();
    }
 
    @Transactional
    public Integer passExtract(final long id, AdminUser admin) {
        Extract find = extractMapper.selectByPrimaryKeyForUpdate(id);
        if (find == null)
            return Constant.NOT_EXIST_OBJACT;
 
        if (find.getState() != Extract.STATE_NOT_PROCESS) {
            return Constant.OBJECT_STATE_EXCEPTION;
        }
 
        // 更改提现状态为处理中
        Extract updateExtract = new Extract();
        updateExtract.setId(id);
        updateExtract.setState(Extract.STATE_PROCESSING);
        extractMapper.updateByPrimaryKeySelective(updateExtract);
        transfer(find, admin); // 提现通过,支付宝转账
 
        return null;
    }
 
    @Transactional
    public synchronized void rejectExtract(long id, String reason, long extractTime, AdminUser admin)
            throws ObjectStateException, NotExistObjectException {
        Extract find = extractMapper.selectByPrimaryKey(id);
 
        if (find == null) {
            throw new NotExistObjectException("不存在该对象");
        }
 
        if (find.getState() != Constant.EXTRACT_DEFUALT) {
            throw new ObjectStateException("该状态不等于不为初始状态");
        }
 
        UserInfo user = find.getUserInfo();
 
        userInfoMapper.addHongBaoByUid(user.getId(), find.getMoney());
 
        // 删除提现记录
        moneyRecordMapper.deleteMoneyRecordByExtractId(id);
 
        // 更新原来的状态
        Extract updateExtract = new Extract();
        updateExtract.setId(id);
        updateExtract.setState(Constant.EXTRACT_REJECT);
        updateExtract.setReason(reason);
        extractMapper.updateByPrimaryKeySelective(updateExtract);
 
        long auditTime = java.lang.System.currentTimeMillis();
        // 更新审核记录
        ExtractAuditRecord auditRecord = new ExtractAuditRecord();
        List<ExtractAuditRecord> records = extractAuditRecordMapper.getbyExtractId(id);
        if (records != null && records.size() > 0) {
            auditRecord = records.get(0);
        }
 
        // 角色默认:客服
        auditRecord.setAuditRole("客服");
        // 审核人
        auditRecord.setAdminUser(admin);
        // 提现之后金额 不变
        auditRecord.setAfterMoney(auditRecord.getBeforeMoney());
        // 审核时间
        auditRecord.setAuditTime(auditTime);
 
        // 历史提现金额
        Long uid = user.getId();
        double countSuccessMoneys = extractMapper.countSuccessMoneysByUid(uid);
        auditRecord.setCountMoney(new BigDecimal(countSuccessMoneys));
 
        // 历史提现次数
        long countSuccess = extractMapper.countSuccessByUid(uid);
        auditRecord.setCountNum(countSuccess);
 
        // 更新提现记录审核表
        extractAuditRecordMapper.updateByPrimaryKeySelective(auditRecord);
        // 新版资金详情
        try {
            UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createExtractReject(find);
            userMoneyDetailMapper.insert(userMoneyDetail);
        } catch (UserMoneyDetailException e2) {
            try {
                LogHelper.errorDetailInfo(e2);
            } catch (Exception e3) {
                e3.printStackTrace();
            }
        }
 
        try {
            userNotificationService.extractWrong(user.getId(), find,
                    TimeUtil.getGernalTime(find.getExtractTime(), "yyyy-MM-dd HH:mm"));
        } catch (Exception e) {
            e.printStackTrace();
        }
 
        // 新版通知
        userMoneyMsgNotificationService.extractFail(find, reason);
    }
 
    /**
     * 提现申请
     * 
     * @param extract
     * @return
     */
    @Transactional
    private Integer extract(Extract extract) {
        final String autoExtract = configService.get("extract_way"); // 是否自动转账
        final String maxCount = configService.get("extract_count_day");
        final String maxMoney = configService.get("extract_money_day");
 
        UserInfo user = userInfoMapper.selectByPrimaryKeyForUpdate(extract.getUserInfo().getId());
        // 余额不足
        if (user.getMyHongBao().compareTo(extract.getMoney()) < 0) {
            return 3;
        }
 
        Integer type = setExtractRecord(extract, maxCount, maxMoney);
        if (type != 0) {
            return type;
        }
        extractMapper.insertSelective(extract);
 
        ExtractAuditRecord auditRecord = new ExtractAuditRecord();
        auditRecord.setBeforeMoney(user.getMyHongBao());
        auditRecord.setExtract(extract);
        extractAuditRecordMapper.insertSelective(auditRecord);
 
        // 减去账户资金
        userInfoMapper.subHongBaoByUid(extract.getUserInfo().getId(), extract.getMoney());
 
        MoneyRecord moneyRecord = new MoneyRecord(user, null, extract.getMoney(), "提现", "", extract.getExtractTime(),
                2);
        moneyRecord.setExtract(extract);
        moneyRecordMapper.insertSelective(moneyRecord);
 
        // 新版资金详情
        try {
            UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createExtract(extract);
            userMoneyDetailMapper.insert(userMoneyDetail);
        } catch (UserMoneyDetailException e2) {
            try {
                LogHelper.errorDetailInfo(e2);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
 
        userNotificationService.extractApply(extract.getUserInfo().getId());
        // 添加新版通知
        userMoneyMsgNotificationService.extractApplay(extract);
 
        if ("是".equals(autoExtract)) {
            LogHelper.userInfo("uid=" + user.getId() + ",提交转账申请!");
        } else {// 暂时不自动提现
            transfer(extract, null);
        }
        return null;
    }
 
    /**
     * 转账
     * 
     * @param extract
     * @param session
     */
    @Transactional
    private void transfer(Extract extract, AdminUser adminUser) {
        Integer type = extract.getType();
        if (Constant.ZHIFUBAO == type) {
            extractByZhiFuBao(extract, adminUser);
        } else {
            LogHelper.userInfo("提现类型错误:" + type);
        }
    }
 
    /**
     * 增加提现记录
     * 
     * @param extract
     * @param maxCount
     *            最多提现次数
     * @param maxMoney
     *            最大提现金额
     * @param session
     * @return 如果为0,则增加成功。为1,则超过每日最多提现次数。为2,则超过每日最多提现金额
     */
    @Transactional
    public Integer setExtractRecord(Extract extract, String maxCount, String maxMoney) {
        long uid = extract.getUserInfo().getId();
        BigDecimal money = extract.getMoney();
 
        List<ExtractRecord> extractRecordList = extractRecordMapper.selectByUidAndToday(uid);
 
        if (extractRecordList.size() == 0) {
            ExtractRecord er = new ExtractRecord();
            er.setCount(1);
            er.setMoney(money);
            er.setUserInfo(new UserInfo(uid));
            er.setCreateTime(java.lang.System.currentTimeMillis());
            extractRecordMapper.insertSelective(er);
        } else {
            ExtractRecord er = extractRecordList.get(0);
            int count = er.getCount();
            int maxCountInt = Integer.parseInt(maxCount);
            if (count >= maxCountInt) {
                return 1;
            }
            BigDecimal oldMoney = er.getMoney();
            BigDecimal sumMoney = MoneyBigDecimalUtil.add(money, oldMoney);
            BigDecimal maxMoneyDou = new BigDecimal(maxMoney);
            if (maxMoneyDou.compareTo(sumMoney) == -1) {
                return 2;
            }
 
            ExtractRecord updateER = new ExtractRecord();
            updateER.setId(er.getId());
            updateER.setCount(count + 1);
            updateER.setMoney(sumMoney);
            er.setCreateTime(java.lang.System.currentTimeMillis());
            extractRecordMapper.updateByPrimaryKeySelective(updateER);
        }
        return 0;
    }
 
    /**
     * 提现到支付宝
     * 
     * @param extract
     * @param session
     */
    @Transactional
    private void extractByZhiFuBao(Extract extract, AdminUser adminUser) {
        String privateKey = Constant.alipayConfig.getPrivateKey();
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",
                Constant.alipayConfig.getAppId(), privateKey, "json", "gbk", null, "RSA2");
        AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest();
        String uuid = UUID.randomUUID().toString().replace("-", "");
        String appName = systemConfigService.get("appName", extract.getSystem());
        JSONObject json = new JSONObject();
        json.put("out_biz_no", uuid);
        json.put("payee_type", "ALIPAY_LOGONID");
        json.put("payee_account", extract.getAccount());
        json.put("amount", extract.getMoney());
        json.put("payer_show_name", appName + "提现");
        json.put("payee_real_name", extract.getName());
        json.put("remark", "来自" + appName + "的提现");
        request.setBizContent(json.toString());
        AlipayFundTransToaccountTransferResponse response = null;
        try {
            response = alipayClient.execute(request);
        } catch (AlipayApiException e) {
            e.printStackTrace();
            LogHelper.userErrorInfo("支付宝提现异常:" + response + ",提现信息" + GsonUtil.toJson(extract));
        }
 
        try {
            CMQManager.getInstance().addExtractResultMsg(extract, response, adminUser);
        } catch (Exception e) {
            LogHelper.userErrorInfo("支付宝提现CMQ异常:" + new Gson().toJson(response) + ",提现信息" + GsonUtil.toJson(extract));
        }
    }
 
    /**
     * 提现失败
     * 
     * @param extract
     * @param msg
     * @param session
     */
    @Transactional
    private void extractFail(Extract extract, String msg) {
        UserInfo user = extract.getUserInfo();
        // MoneyRecord moneyRecord = new MoneyRecord(user, null, extract
        // .getMoney(), "提现", "提现失败", new Date().getTime(), 3);
        if ("付款方余额不足".equals(msg)) {
            Extract updateExtract = new Extract();
            updateExtract.setId(extract.getId());
            updateExtract.setState(Constant.EXTRACT_DEFUALT);
            updateExtract.setReason(msg);
            extractMapper.updateByPrimaryKeySelective(updateExtract);
        } else {
            // 老版本功能
            // List<MoneyRecord> list = moneyRecordDao.list("from MoneyRecord mr
            // where mr.extract.id =" + extract.getId());
            // if (list.size() > 0) {
            // MoneyRecord moneyRecord = list.get(0);
            // moneyRecordMapper.deleteByPrimaryKey(moneyRecord.getId());
            // }
 
            Extract updateExtract = new Extract();
            updateExtract.setId(extract.getId());
            updateExtract.setState(Constant.EXTRACT_REJECT);
            updateExtract.setReason(msg);
            extractMapper.updateByPrimaryKeySelective(updateExtract);
 
            userInfoMapper.addHongBaoByUid(user.getId(), extract.getMoney());
 
            // 新版资金详情
            try {
                UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createExtractReject(extract);
                userMoneyDetailMapper.insert(userMoneyDetail);
            } catch (UserMoneyDetailException e2) {
                try {
                    LogHelper.errorDetailInfo(e2);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
 
            try {
 
                userNotificationService.extractTransferFail(user.getId(),
                        TimeUtil.getGernalTime(extract.getExtractTime(), "yyyy-MM-dd HH:mm"));
 
                LogHelper.userInfo("支付宝转账失败:[提现IP:" + extract.getIp() + ",所转账号:" + extract.getAccount() + ",真实姓名:"
                        + extract.getName() + ",所转金额:" + extract.getMoney() + ",失败原因" + extract.getReason() + "]");
 
            } catch (Exception e) {
                e.printStackTrace();
            }
 
            // 新版提现
            userMoneyMsgNotificationService.extractFail(extract, null);
        }
    }
 
    /**
     * 提现成功
     * 
     * @param extract
     * @param session
     */
    @Transactional
    private void extractSuccess(Extract extract) {
        // 老版本功能
        // List<MoneyRecord> list = moneyRecordDao.list("from MoneyRecord mr
        // where mr.extract.id = " + extract.getId());
        // MoneyRecord moneyRecord = list.get(0);
        // moneyRecord.setType(3);
        // MoneyRecord updateMoneyRecord = new MoneyRecord();
        // updateMoneyRecord.setId(moneyRecord.getId());
        // updateMoneyRecord.setType(3);
        // moneyRecordMapper.updateByPrimaryKeySelective(updateMoneyRecord);
        Extract updateExtract = new Extract();
        updateExtract.setId(extract.getId());
        updateExtract.setState(Constant.EXTRACT_PASS);
        updateExtract.setReceiveTime(new Date());
        updateExtract.setReason("提现成功");
        extractMapper.updateByPrimaryKeySelective(updateExtract);
 
        try {
            userNotificationService.extractSuccess(extract.getUserInfo().getId(), extract,
                    TimeUtil.getGernalTime(extract.getExtractTime(), "yyyy-MM-dd HH:mm"));
 
            LogHelper.userInfo("支付宝转账成功:[提现IP:" + extract.getIp() + ",所转账号:" + extract.getAccount() + ",真实姓名:"
                    + extract.getName() + ",所转金额:" + extract.getMoney() + "]");
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 新版通知
        userMoneyMsgNotificationService.extractSuccess(extract);
    }
 
    /**
     * 根据提现记录id获取用户uid
     */
    @Override
    public Extract getExtractById(long id) {
        return extractDao.find(Extract.class, id);
    }
 
    @Override
    public void checkExtract(String uid) throws ExtractException {
        Long count = hongBaoV2Mapper.countByUidAndState(Long.parseLong(uid), HongBao.STATE_YILINGQU);
        if (count == null || count == 0)
            throw new ExtractException(1, "没有已到账的红包");
        List<Integer> list = extractMapper.checkExtract(uid);
        if (list != null && list.size() > 0 && list.get(0) == 0)
            throw new ExtractException(2, "结算资金异常");
    }
 
    @Override
    public Extract selectByPrimaryKey(Long id) {
        return extractMapper.selectByPrimaryKey(id);
    }
 
    @Override
    public Extract getMyTaskInfo(Long adminId) {
        return extractMapper.getMyTaskInfo(adminId);
    }
 
    @Override
    public Extract getNewTaskInfo() {
        return extractMapper.getNewTaskInfo();
    }
 
    @Override
    public List<Map<String, Object>> getFinishRecord(int pageIndex, int pageSize, String key, String startTime,
            String endTime) {
        return extractMapper.getFinishRecord((pageIndex - 1) * pageSize, pageSize, key, startTime, endTime);
    }
 
    @Override
    public int updateByPrimaryKeySelective(Extract record) {
        return extractMapper.updateByPrimaryKeySelective(record);
    }
 
    @Transactional
    @Override
    public void processExtractResult(AlipayTransferResultInfo info) {
        if (info == null)
            return;
        AlipayFundTransToaccountTransferResponse response = info.getAlipayFundTransToaccountTransferResponse();
        Extract extract = info.getExtract();
        AdminUser admin = info.getAdminUser();
        if (response == null)
            return;
        if (extract == null)
            return;
 
        extract = extractMapper.selectByPrimaryKey(info.getExtract().getId());
 
        LogHelper.test("提现结果:code-" + response.getCode() + " 信息:" + response.getMsg());
        long uid = extract.getUserInfo().getId();
        if (response.isSuccess()) {
            String code = response.getCode();
            if ("10000".equals(code)) {
                extractSuccess(extract);
            } else {
                extractFail(extract, response.getSubMsg());
            }
        } else {
            extractFail(extract, response.getSubMsg());
        }
        PayInfo payInfo = new PayInfo();
        payInfo.setBizno(response.getOutBizNo());
        payInfo.setCreatetime(new Date());
        payInfo.setExtract(extract);
        if ("10000".equals(response.getCode())) {
            payInfo.setState(1);
        } else {
            payInfo.setState(2);
        }
        payInfo.setOrderId(response.getOrderId());
        payInfo.setOrdertime(response.getPayDate());
        payInfo.setInfo(response.getSubMsg());
        payInfoMapper.insertSelective(payInfo);
 
        // 更新审核记录
        ExtractAuditRecord auditRecord = null;
        List<ExtractAuditRecord> records = extractAuditRecordMapper.getbyExtractId(extract.getId());
        if (records != null && records.size() > 0) {
            auditRecord = records.get(0);
        }
 
        if (auditRecord != null) {
 
            // 提现付款记录
            List<PayInfo> paylist = payInfoMapper.getListbyExtractId(extract.getId());
 
            if (paylist != null && paylist.size() > 0) {
                // 提现成功 : 提现之前总金额:提现时金额减去提现金额
                BigDecimal exceedMoney = MoneyBigDecimalUtil.sub(auditRecord.getBeforeMoney(), extract.getMoney());
                // 提现之后金额
                auditRecord.setAfterMoney(exceedMoney);
            } else {
                // 提现失败:付款方余额不足、账户信息错误 提现之后金额 不变
                auditRecord.setAfterMoney(auditRecord.getBeforeMoney());
            }
 
            // 历史提现金额
            double countSuccessMoneys = extractMapper.countSuccessMoneysByUid(uid);
            auditRecord.setCountMoney(new BigDecimal(countSuccessMoneys));
 
            // 历史提现次数
            long countSuccess = extractMapper.countSuccessByUid(uid);
            auditRecord.setCountNum(countSuccess);
 
            // 角色默认:客服
            auditRecord.setAuditRole("客服");
            // 审核人
            auditRecord.setAdminUser(admin);
            // 审核时间
            auditRecord.setAuditTime(java.lang.System.currentTimeMillis());
 
            // 更新提现记录审核表
            extractAuditRecordMapper.updateByPrimaryKeySelective(auditRecord);
 
        }
 
    }
 
    @Transactional
    @Override
    public void testExtractSuccess(Long id) {
        Extract extract = extractMapper.selectByPrimaryKey(id);
        extractSuccess(extract);
        Long uid = extract.getUserInfo().getId();
 
        // 更新审核记录
        ExtractAuditRecord auditRecord = null;
        List<ExtractAuditRecord> records = extractAuditRecordMapper.getbyExtractId(extract.getId());
        if (records != null && records.size() > 0) {
            auditRecord = records.get(0);
        }
 
        if (auditRecord != null) {
            // 提现付款记录
            List<PayInfo> paylist = payInfoMapper.getListbyExtractId(extract.getId());
            if (paylist != null && paylist.size() > 0) {
                // 提现成功 : 提现之前总金额:提现时金额减去提现金额
                BigDecimal exceedMoney = MoneyBigDecimalUtil.sub(auditRecord.getBeforeMoney(), extract.getMoney());
                // 提现之后金额
                auditRecord.setAfterMoney(exceedMoney);
            } else {
                // 提现失败:付款方余额不足、账户信息错误 提现之后金额 不变
                auditRecord.setAfterMoney(auditRecord.getBeforeMoney());
            }
 
            // 历史提现金额
            double countSuccessMoneys = extractMapper.countSuccessMoneysByUid(uid);
            auditRecord.setCountMoney(new BigDecimal(countSuccessMoneys));
 
            // 历史提现次数
            long countSuccess = extractMapper.countSuccessByUid(uid);
            auditRecord.setCountNum(countSuccess);
 
            // 角色默认:客服
            auditRecord.setAuditRole("客服");
            // 审核人
            auditRecord.setAdminUser(new AdminUser(3L));
            // 审核时间
            auditRecord.setAuditTime(java.lang.System.currentTimeMillis());
 
            // 更新提现记录审核表
            extractAuditRecordMapper.updateByPrimaryKeySelective(auditRecord);
        }
 
    }
 
    @Override
    public double countTodayMoney(Long uid) {
        return extractMapper.countTodayMoney(uid);
    }
}