|
@@ -11,6 +11,7 @@
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
|
|
+use App\Models\CapitalLogModel;
|
|
|
use App\Models\CoinLogModel;
|
|
use App\Models\CoinLogModel;
|
|
|
use App\Models\MemberModel;
|
|
use App\Models\MemberModel;
|
|
|
use App\Services\Api\MemberService;
|
|
use App\Services\Api\MemberService;
|
|
@@ -56,6 +57,7 @@ class UsdtWalletService extends BaseService
|
|
|
{
|
|
{
|
|
|
$this->memberModel = new MemberModel();
|
|
$this->memberModel = new MemberModel();
|
|
|
$this->coinModel = new CoinLogModel();
|
|
$this->coinModel = new CoinLogModel();
|
|
|
|
|
+ $this->capitalModel = new CapitalLogModel();
|
|
|
$this->config = ConfigService::make()->getConfigOptionByGroup(4);
|
|
$this->config = ConfigService::make()->getConfigOptionByGroup(4);
|
|
|
$this->apiUrl = isset($this->config['usdt_api_url']) ? $this->config['usdt_api_url'] : '';
|
|
$this->apiUrl = isset($this->config['usdt_api_url']) ? $this->config['usdt_api_url'] : '';
|
|
|
if (empty($this->config) || empty($this->apiUrl)) {
|
|
if (empty($this->config) || empty($this->apiUrl)) {
|
|
@@ -396,12 +398,13 @@ class UsdtWalletService extends BaseService
|
|
|
$txid = isset($v['transaction_id']) ? $v['transaction_id'] : '';
|
|
$txid = isset($v['transaction_id']) ? $v['transaction_id'] : '';
|
|
|
if (!CoinLogService::make()->checkExists('txid', $txid) && $time > time() - 12 * 3600) {
|
|
if (!CoinLogService::make()->checkExists('txid', $txid) && $time > time() - 12 * 3600) {
|
|
|
$balance = $this->memberModel->where(['id' => $userId])->value('usdt_num');
|
|
$balance = $this->memberModel->where(['id' => $userId])->value('usdt_num');
|
|
|
|
|
+ $orderNo = get_order_num('TR');
|
|
|
$log = [
|
|
$log = [
|
|
|
'user_id' => $userId,
|
|
'user_id' => $userId,
|
|
|
'change_type' => 1,
|
|
'change_type' => 1,
|
|
|
'coin_type' => $coinType,
|
|
'coin_type' => $coinType,
|
|
|
'contact_type' => 1,
|
|
'contact_type' => 1,
|
|
|
- 'order_no' => get_order_num('TR'),
|
|
|
|
|
|
|
+ 'order_no' => $orderNo,
|
|
|
'from_address' => isset($v['from']) ? $v['from'] : '',
|
|
'from_address' => isset($v['from']) ? $v['from'] : '',
|
|
|
'to_address' => isset($v['to']) ? $v['to'] : '',
|
|
'to_address' => isset($v['to']) ? $v['to'] : '',
|
|
|
'txid' => $txid,
|
|
'txid' => $txid,
|
|
@@ -416,6 +419,25 @@ class UsdtWalletService extends BaseService
|
|
|
if ($amount >= $coinInMin && $this->memberModel->where(['id' => $userId])->increment('usdt_num', $amount)) {
|
|
if ($amount >= $coinInMin && $this->memberModel->where(['id' => $userId])->increment('usdt_num', $amount)) {
|
|
|
$this->memberModel->where(['id' => $userId])->increment('trc_usdt', $amount);
|
|
$this->memberModel->where(['id' => $userId])->increment('trc_usdt', $amount);
|
|
|
$log['status'] = 1;
|
|
$log['status'] = 1;
|
|
|
|
|
+
|
|
|
|
|
+ $data = [
|
|
|
|
|
+ 'order_no' => $orderNo,
|
|
|
|
|
+ 'user_id' => $userId,
|
|
|
|
|
+ 'type' => 4,
|
|
|
|
|
+ 'pay_type' => 1,
|
|
|
|
|
+ 'trade_type' => 3,
|
|
|
|
|
+ 'change_type' => 1,
|
|
|
|
|
+ 'num' => $amount,
|
|
|
|
|
+ 'total' => 0,
|
|
|
|
|
+ 'balance' => floatval($balance+$amount),
|
|
|
|
|
+ 'create_time' => time(),
|
|
|
|
|
+ 'update_time' => time(),
|
|
|
|
|
+ 'remark' => '存币',
|
|
|
|
|
+ 'status' => 1,
|
|
|
|
|
+ 'mark' => 1,
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ $this->capitalModel->edit($data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$logs[] = $log;
|
|
$logs[] = $log;
|
|
@@ -442,11 +464,11 @@ class UsdtWalletService extends BaseService
|
|
|
|
|
|
|
|
// 存币
|
|
// 存币
|
|
|
if($type == 1){
|
|
if($type == 1){
|
|
|
- $url = sprintf($this->apiUrls['usdt_trx2_transfer_logs'], $address, $limit, 'true', 'false');
|
|
|
|
|
|
|
+ $url = sprintf($this->apiUrls['usdt_trx2_transfer_log'], $address, $limit, 'true', 'false');
|
|
|
}
|
|
}
|
|
|
// 提币
|
|
// 提币
|
|
|
else{
|
|
else{
|
|
|
- $url = sprintf($this->apiUrls['usdt_trx2_transfer_logs'], $address, $limit, 'false', 'true');
|
|
|
|
|
|
|
+ $url = sprintf($this->apiUrls['usdt_trx2_transfer_log'], $address, $limit, 'false', 'true');
|
|
|
}
|
|
}
|
|
|
$headers = ["TRON-PRO-API-KEY" => $this->config['tron_api_key']];
|
|
$headers = ["TRON-PRO-API-KEY" => $this->config['tron_api_key']];
|
|
|
RedisService::set("caches:wallets:transfer_temp_otc_{$type}", ['url' => $this->config['tron_api_url'] . $url], 600);
|
|
RedisService::set("caches:wallets:transfer_temp_otc_{$type}", ['url' => $this->config['tron_api_url'] . $url], 600);
|
|
@@ -459,6 +481,18 @@ class UsdtWalletService extends BaseService
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if($datas){
|
|
|
|
|
+ foreach ($datas as &$item){
|
|
|
|
|
+ $time = ($item['block_timestamp']/1000);
|
|
|
|
|
+ $item['time_text'] = $time? datetime($time, 'm-d H:i') : '';
|
|
|
|
|
+ $item['num'] = floatval($item['value']/1000000);
|
|
|
|
|
+ $item['contact_type'] = 1;
|
|
|
|
|
+ $item['change_type'] = $type;
|
|
|
|
|
+ $item['status'] = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
return $datas;
|
|
return $datas;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -503,6 +537,27 @@ class UsdtWalletService extends BaseService
|
|
|
// 直接更新提币状态
|
|
// 直接更新提币状态
|
|
|
CoinLogModel::where(['txid' => $txid, 'user_id' => $userId])->update(['status' => 1, 'update_time' => time()]);
|
|
CoinLogModel::where(['txid' => $txid, 'user_id' => $userId])->update(['status' => 1, 'update_time' => time()]);
|
|
|
|
|
|
|
|
|
|
+ // 明细处理
|
|
|
|
|
+ $num = floatval($coinInfo['num'] + $coinInfo['free']);
|
|
|
|
|
+ $data = [
|
|
|
|
|
+ 'order_no' => $coinInfo['order_no'],
|
|
|
|
|
+ 'user_id' => $userId,
|
|
|
|
|
+ 'type' => 5,
|
|
|
|
|
+ 'pay_type' => 1,
|
|
|
|
|
+ 'trade_type' => 3,
|
|
|
|
|
+ 'change_type' => 2,
|
|
|
|
|
+ 'num' => $num,
|
|
|
|
|
+ 'total' => 0,
|
|
|
|
|
+ 'balance' => floatval($coinInfo['balance']-$num),
|
|
|
|
|
+ 'create_time' => time(),
|
|
|
|
|
+ 'update_time' => time(),
|
|
|
|
|
+ 'remark' => '提币',
|
|
|
|
|
+ 'status' => 1,
|
|
|
|
|
+ 'mark' => 1,
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ $this->capitalModel->edit($data);
|
|
|
|
|
+
|
|
|
$logs[] = ['log'=> $v,'order'=> $coinInfo];
|
|
$logs[] = ['log'=> $v,'order'=> $coinInfo];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -548,12 +603,13 @@ class UsdtWalletService extends BaseService
|
|
|
$txid = isset($v['transaction_id']) ? $v['transaction_id'] : '';
|
|
$txid = isset($v['transaction_id']) ? $v['transaction_id'] : '';
|
|
|
if (!CoinLogService::make()->checkExists('txid', $txid) && $time > time() - 12 * 3600) {
|
|
if (!CoinLogService::make()->checkExists('txid', $txid) && $time > time() - 12 * 3600) {
|
|
|
$balance = $this->memberModel->where(['id' => $userId])->value('usdt_num');
|
|
$balance = $this->memberModel->where(['id' => $userId])->value('usdt_num');
|
|
|
|
|
+ $orderNo = get_order_num('TW');
|
|
|
$log = [
|
|
$log = [
|
|
|
'user_id' => $userId,
|
|
'user_id' => $userId,
|
|
|
'change_type' => 2,
|
|
'change_type' => 2,
|
|
|
'coin_type' => $coinType,
|
|
'coin_type' => $coinType,
|
|
|
'contact_type' => 1,
|
|
'contact_type' => 1,
|
|
|
- 'order_no' => get_order_num('TW'),
|
|
|
|
|
|
|
+ 'order_no' => $orderNo,
|
|
|
'from_address' => isset($v['from']) ? $v['from'] : '',
|
|
'from_address' => isset($v['from']) ? $v['from'] : '',
|
|
|
'to_address' => isset($v['to']) ? $v['to'] : '',
|
|
'to_address' => isset($v['to']) ? $v['to'] : '',
|
|
|
'txid' => $txid,
|
|
'txid' => $txid,
|
|
@@ -568,6 +624,27 @@ class UsdtWalletService extends BaseService
|
|
|
if ($amount >= $coinOutMin && $this->memberModel->where(['id' => $userId])->decrement('usdt_num', $amount)) {
|
|
if ($amount >= $coinOutMin && $this->memberModel->where(['id' => $userId])->decrement('usdt_num', $amount)) {
|
|
|
$this->memberModel->where(['id' => $userId])->decrement('trc_usdt', $amount);
|
|
$this->memberModel->where(['id' => $userId])->decrement('trc_usdt', $amount);
|
|
|
$log['status'] = 1;
|
|
$log['status'] = 1;
|
|
|
|
|
+
|
|
|
|
|
+ // 明细处理
|
|
|
|
|
+ $data = [
|
|
|
|
|
+ 'order_no' => $orderNo,
|
|
|
|
|
+ 'user_id' => $userId,
|
|
|
|
|
+ 'type' => 5,
|
|
|
|
|
+ 'pay_type' => 1,
|
|
|
|
|
+ 'trade_type' => 3,
|
|
|
|
|
+ 'change_type' => 2,
|
|
|
|
|
+ 'num' => $amount,
|
|
|
|
|
+ 'total' => 0,
|
|
|
|
|
+ 'balance' => floatval($balance - $amount),
|
|
|
|
|
+ 'create_time' => time(),
|
|
|
|
|
+ 'update_time' => time(),
|
|
|
|
|
+ 'remark' => '提币',
|
|
|
|
|
+ 'status' => 1,
|
|
|
|
|
+ 'mark' => 1,
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ $this->capitalModel->edit($data);
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$logs[] = $log;
|
|
$logs[] = $log;
|
|
@@ -626,11 +703,6 @@ class UsdtWalletService extends BaseService
|
|
|
*/
|
|
*/
|
|
|
public function getTrc20Usdt($address)
|
|
public function getTrc20Usdt($address)
|
|
|
{
|
|
{
|
|
|
- $cacheKey = "caches:wallet:balance:{$address}";
|
|
|
|
|
- if (RedisService::get($cacheKey)) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
if (empty($address)) {
|
|
if (empty($address)) {
|
|
|
$this->error = '1018';
|
|
$this->error = '1018';
|
|
|
return false;
|
|
return false;
|
|
@@ -651,7 +723,6 @@ class UsdtWalletService extends BaseService
|
|
|
$address = $tron->getAddress();
|
|
$address = $tron->getAddress();
|
|
|
$address = new \Tron\Address($address['base58'], '', $address['hex']);
|
|
$address = new \Tron\Address($address['base58'], '', $address['hex']);
|
|
|
$result = $trxWallet->balance($address);
|
|
$result = $trxWallet->balance($address);
|
|
|
-
|
|
|
|
|
return $result ? floatval($result) : '0.00';
|
|
return $result ? floatval($result) : '0.00';
|
|
|
|
|
|
|
|
} catch (\Exception $exception) {
|
|
} catch (\Exception $exception) {
|
|
@@ -720,4 +791,42 @@ class UsdtWalletService extends BaseService
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * USDT-ERC20余额
|
|
|
|
|
+ * @param $address
|
|
|
|
|
+ * @return false|float|string
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getErc20Usdt($address)
|
|
|
|
|
+ {
|
|
|
|
|
+ $cacheKey = "caches:wallet:balance:{$address}";
|
|
|
|
|
+ if (RedisService::get($cacheKey)) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($address)) {
|
|
|
|
|
+ $this->error = '1018';
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ return '0.00';
|
|
|
|
|
+
|
|
|
|
|
+ } catch (\Exception $exception) {
|
|
|
|
|
+ $this->error = $exception->getMessage();
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取USDT-ERC2.0交易记录(进出账)
|
|
|
|
|
+ * @param $address 用户钱包地址
|
|
|
|
|
+ * @param int $coinType 币种:1-usdt
|
|
|
|
|
+ * @param int $limit 转账记录数,最新的
|
|
|
|
|
+ * @return array|false
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getErc20TransferLog($address, $type = 1, $limit = 50)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|