|
|
@@ -96,7 +96,6 @@ class UsdtWalletService extends BaseService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* trx 转账
|
|
|
* @param $to 进账账户
|
|
|
@@ -357,7 +356,6 @@ class UsdtWalletService extends BaseService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 监听USDT-TRC2.0转账记录并进账
|
|
|
* @param $userId 用户ID
|
|
|
@@ -752,7 +750,6 @@ class UsdtWalletService extends BaseService
|
|
|
return ['wif' => $wif, 'hexAddress' => $this->getHexAddress($address), 'address' => $address];
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 获取HASH钱包地址
|
|
|
* @param $address 钱包地址
|
|
|
@@ -825,4 +822,156 @@ class UsdtWalletService extends BaseService
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * usdt-trc2.0 归集
|
|
|
+ * @throws \Tron\Exceptions\TransactionException
|
|
|
+ * @throws \Tron\Exceptions\TronErrorException
|
|
|
+ */
|
|
|
+ public function usdtErcTrigger($force = false)
|
|
|
+ {
|
|
|
+
|
|
|
+ return false;
|
|
|
+
|
|
|
+ if (empty($this->config['tron_api_url'])) {
|
|
|
+ $this->error = '2206';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $headers = ["TRON-PRO-API-KEY" => $this->config['tron_api_key']];
|
|
|
+ $api = new Api(new Client(['base_uri' => $this->config['tron_api_url'], 'headers' => $headers]));
|
|
|
+ $trcWallet = new TRC20($api, ['contract_address' => $this->config['tron_contract_address'], 'decimals' => 6]);
|
|
|
+ $trxWallet = new TRX($api, ['contract_address' => $this->config['tron_contract_address'], 'decimals' => 6]);
|
|
|
+
|
|
|
+ // 获取钱包参数
|
|
|
+ try {
|
|
|
+
|
|
|
+ // 用收账钱包归集
|
|
|
+ $otcAddress = ConfigService::make()->getConfigByCode('trc_address');
|
|
|
+ $otcAddressPrivate = ConfigService::make()->getConfigByCode('trc_private_key');
|
|
|
+ // 出账手续费钱包
|
|
|
+ $otcOutAddress = ConfigService::make()->getConfigByCode('trc_out_address');
|
|
|
+ $otcOutAddressPrivate = ConfigService::make()->getConfigByCode('trc_out_private_key');
|
|
|
+ $triggerMin = ConfigService::make()->getConfigByCode('trade_trigger_min');
|
|
|
+ $triggerTime = ConfigService::make()->getConfigByCode('trade_trigger_time');
|
|
|
+ $triggerFree = ConfigService::make()->getConfigByCode('trade_trigger_free');
|
|
|
+ $triggerFree = $triggerFree > 0 ? $triggerFree : 8;
|
|
|
+ $triggerMin = $triggerMin > 0 ? $triggerMin : 0.1;
|
|
|
+ $triggerTime = $triggerTime > 0 ? $triggerTime * 86400 : 86400;
|
|
|
+ if (empty($otcAddress) || empty($otcAddressPrivate)) {
|
|
|
+ $this->error = '2203';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 出账钱包
|
|
|
+ if (empty($otcOutAddress) || empty($otcOutAddressPrivate)) {
|
|
|
+ $this->error = '2203';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $page = RedisService::get("caches:wallet:transferPage");
|
|
|
+ $page = $page ? $page : 1;
|
|
|
+
|
|
|
+ // 归集时间段为凌晨0点-5点
|
|
|
+ if ((date('H:i') >= '05:00') && !$force) {
|
|
|
+ $this->error = '不在归集时间段';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (RedisService::get("caches:wallet:triggerLock:{$page}")) {
|
|
|
+ $this->error = '不要频繁操作,30秒后重试';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 上锁
|
|
|
+ RedisService::set("caches:wallet:triggerLock:{$page}", 1, rand(10, 30));
|
|
|
+ $addrList = MemberService::make()->getTriggerAddressList($triggerMin, $page, 200);
|
|
|
+ if (empty($addrList)) {
|
|
|
+ RedisService::set("caches:wallet:transferPage", 1, 600);
|
|
|
+ $this->error = '1019';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 平台钱包地址
|
|
|
+ $count = 0;
|
|
|
+ $failedCount = 0;
|
|
|
+ $tron = new Tron();
|
|
|
+ $tron->setAddress($otcAddress);
|
|
|
+ $otcAddress = $tron->getAddress();
|
|
|
+ $otcAddressData = new \Tron\Address($otcAddress['base58'], $otcAddressPrivate, $otcAddress['hex']);
|
|
|
+
|
|
|
+ // 平台出账钱包地址
|
|
|
+ $tron->setAddress($otcOutAddress);
|
|
|
+ $otcOutAddress = $tron->getAddress();
|
|
|
+ $otcOutAddressData = new \Tron\Address($otcOutAddress['base58'], $otcOutAddressPrivate, $otcOutAddress['hex']);
|
|
|
+ $cacheKey = "caches:wallet:trigger:";
|
|
|
+ foreach ($addrList as $v) {
|
|
|
+ try {
|
|
|
+ // 获取子钱包TRC-USDT余额
|
|
|
+ $userId = isset($v['id']) ? $v['id'] : 0;
|
|
|
+ $address = isset($v['trc_address']) ? $v['trc_address'] : '';
|
|
|
+ $hexAddress = isset($v['trc_hexaddress']) ? $v['trc_hexaddress'] : '';
|
|
|
+ $addressPrivate = isset($v['trc_wif']) ? $v['trc_wif'] : '';
|
|
|
+ $triggerAddress = new \Tron\Address($address, $addressPrivate, $hexAddress);
|
|
|
+ // 可归集的USDT余额
|
|
|
+ $triggerUsdt = $trcWallet->balance($triggerAddress);
|
|
|
+
|
|
|
+ // USDT 余额低于归集金额,则不归集
|
|
|
+ if ($triggerUsdt < $triggerMin) {
|
|
|
+ $failedCount++;
|
|
|
+ $error = ['data' => $v, 'usdt' => $triggerUsdt, 'triggerMin' => $triggerMin, 'error' => '用户余额不足归集', 'date' => date('Y-m-d H:i:s')];
|
|
|
+ RedisService::set($cacheKey . "U_{$userId}:error", $error, 7200);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取子钱包TRX余额
|
|
|
+ $triggerTrx = $trxWallet->balance($triggerAddress);
|
|
|
+
|
|
|
+ // 获取平台出账钱包TRX余额
|
|
|
+ $otcOutTrxTotal = $trxWallet->balance($otcOutAddressData);
|
|
|
+
|
|
|
+ // 如果子钱包和平台钱包TRX余额不足手续费,则不归集
|
|
|
+ if ($triggerTrx < $triggerFree && $otcOutTrxTotal < $triggerFree) {
|
|
|
+ $failedCount++;
|
|
|
+ $error = ['data' => $v, 'usdt' => $triggerUsdt, 'triggerMin' => $triggerMin, 'triggerTrx' => $triggerTrx, 'otcTrx' => $otcOutTrxTotal, 'error' => '平台钱包手续费不足', 'date' => date('Y-m-d H:i:s')];
|
|
|
+ RedisService::set($cacheKey . "U_{$userId}:error", $error, 7200);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果子钱包TRX不足手续费8个,平台TRX充足则自动充值后下次调用时归集
|
|
|
+ if ($triggerTrx < $triggerFree) {
|
|
|
+ $failedCount++;
|
|
|
+ $result = $this->trxTransfer($address, $triggerFree);
|
|
|
+ $error = ['data' => $v, 'usdt' => $triggerUsdt, 'triggerMin' => $triggerMin, 'triggerTrx' => $triggerTrx, 'transfer' => $result, 'error' => '归集钱包手续费不足,先充值', 'date' => date('Y-m-d H:i:s')];
|
|
|
+ RedisService::set($cacheKey . "U_{$userId}:catch", $error, 7200);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 满足归集条件处理
|
|
|
+ $result = $trcWallet->transfer($triggerAddress, $otcAddressData, $triggerUsdt);
|
|
|
+ RedisService::set($cacheKey . "U_{$userId}:result", ['data' => $v, 'result' => $result, 'msg' => '归集已提交', 'date' => date('Y-m-d H:i:s')], 7200);
|
|
|
+ $count++;
|
|
|
+
|
|
|
+ } catch (\Exception $exception) {
|
|
|
+ $failedCount++;
|
|
|
+ RedisService::set($cacheKey . "U_{$userId}:exception", ['data' => $v, 'msg' => $exception->getMessage(), 'date' => date('Y-m-d H:i:s')], 7200);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 超出分页数,下次处理下一页
|
|
|
+ if (count($addrList) >= 200) {
|
|
|
+ RedisService::set("caches:wallet:transferPage", $page + 1, 600);
|
|
|
+ }
|
|
|
+ if ($count > 0) {
|
|
|
+ return ['success' => $count, 'fail' => $failedCount];
|
|
|
+ } else {
|
|
|
+ $this->error = 1021;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } catch (\Exception $exception) {
|
|
|
+ $this->error = $exception->getMessage();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|