From 25c3288859d660507dd78be62dadecfa3c543180 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Wed, 11 Nov 2020 10:57:11 +0800
Subject: [PATCH] trc20 modify

---
 src/main/java/com/xcong/excoin/quartz/job/TRC20OrderJob.java |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/quartz/job/TRC20OrderJob.java b/src/main/java/com/xcong/excoin/quartz/job/TRC20OrderJob.java
index ab29562..934373e 100644
--- a/src/main/java/com/xcong/excoin/quartz/job/TRC20OrderJob.java
+++ b/src/main/java/com/xcong/excoin/quartz/job/TRC20OrderJob.java
@@ -1,11 +1,18 @@
 package com.xcong.excoin.quartz.job;
 
 import cn.hutool.core.collection.CollUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.xcong.excoin.modules.coin.dao.MemberAccountMoneyChangeDao;
+import com.xcong.excoin.modules.coin.entity.MemberAccountMoneyChange;
 import com.xcong.excoin.modules.member.dao.MemberCoinWithdrawDao;
+import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao;
 import com.xcong.excoin.modules.member.entity.MemberCoinWithdrawEntity;
+import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
 import com.xcong.excoin.utils.TRC20ApiUtils;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.util.HashMap;
@@ -18,19 +25,53 @@
  **/
 @Slf4j
 @Component
+@ConditionalOnProperty(prefix = "app", name = "block-job", havingValue = "true")
 public class TRC20OrderJob {
 
     @Resource
     private MemberCoinWithdrawDao memberCoinWithdrawDao;
+    @Resource
+    private MemberWalletCoinDao memberWalletCoinDao;
+    @Resource
+    private MemberAccountMoneyChangeDao memberAccountMoneyChangeDao;
 
+
+    @Transactional(rollbackFor = Exception.class)
     public void trc20WithdrawOrder() {
+        log.info("trc20订单查询");
         Map<String, Object> param = new HashMap<>();
         param.put("label", "TRC20");
         param.put("status", 1);
         List<MemberCoinWithdrawEntity> withdrawEntities = memberCoinWithdrawDao.selectByMap(param);
         if (CollUtil.isNotEmpty(withdrawEntities)) {
             for (MemberCoinWithdrawEntity withdrawEntity : withdrawEntities) {
+                MemberWalletCoinEntity wallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(withdrawEntity.getMemberId(), withdrawEntity.getSymbol());
                 String applyOrderInfo = TRC20ApiUtils.getApplyOrderInfo(withdrawEntity.getTag());
+                Integer transStatus = JSONObject.parseObject(applyOrderInfo).getInteger("transStatus");
+
+                Map<String, Object> columnMaps = new HashMap<>();
+                columnMaps.put("withdraw_id", withdrawEntity.getId());
+                MemberAccountMoneyChange accountMoneyChanges = memberAccountMoneyChangeDao.selectByMap(columnMaps).get(0);
+                // 状态:2待审核3提币中(审核成功)4提币成功5审核失败
+                if (transStatus == 4) {
+                    memberWalletCoinDao.updateWalletBalance(wallet.getId(), null, null, withdrawEntity.getAmount().negate());
+
+                    accountMoneyChanges.setStatus(MemberAccountMoneyChange.STATUS_SUCCESS_INTEGER);
+                    accountMoneyChanges.setAmount(withdrawEntity.getAmount().negate());
+                    memberAccountMoneyChangeDao.updateById(accountMoneyChanges);
+
+                    withdrawEntity.setStatus(MemberCoinWithdrawEntity.IS_STATUS_Y);
+                    memberCoinWithdrawDao.updateById(withdrawEntity);
+                } else if (transStatus == 5) {
+                    memberWalletCoinDao.updateWalletBalance(wallet.getId(), withdrawEntity.getAmount(), null, withdrawEntity.getAmount().negate());
+
+                    accountMoneyChanges.setStatus(MemberAccountMoneyChange.STATUS_FAIL_INTEGER);
+                    accountMoneyChanges.setAmount(withdrawEntity.getAmount());
+                    memberAccountMoneyChangeDao.updateById(accountMoneyChanges);
+
+                    withdrawEntity.setStatus(MemberCoinWithdrawEntity.IS_STATUS_N);
+                    memberCoinWithdrawDao.updateById(withdrawEntity);
+                }
             }
         }
     }

--
Gitblit v1.9.1