|
|
@@ -13,6 +13,7 @@ use App\Services\CollectService;
|
|
|
use App\Services\UserService;
|
|
|
use App\Services\BalanceLogService;
|
|
|
use App\Helpers\TronHelper;
|
|
|
+use App\Models\Config;
|
|
|
|
|
|
/**
|
|
|
* 用户充值记录
|
|
|
@@ -156,6 +157,9 @@ class RechargeService extends BaseService
|
|
|
{
|
|
|
$info = self::findOne(['txid' => $txid]); // 获取充值的信息
|
|
|
|
|
|
+ // 汇率
|
|
|
+ $rate = Config::where('field', 'exchange_rate_rmb')->first()->val ?? 1;
|
|
|
+
|
|
|
// 待处理进行充值
|
|
|
if ($info['status'] == self::model()::STATUS_STAY) {
|
|
|
$result = TronHelper::getTransactionConfirmations($txid);
|
|
|
@@ -164,23 +168,30 @@ class RechargeService extends BaseService
|
|
|
$data = [];
|
|
|
$data['block_height'] = $result['block_number'];
|
|
|
$data['confirmations'] = $result['latest_block'] - $result['block_number'];
|
|
|
+ $data['exchange_rate'] = $rate;
|
|
|
|
|
|
if ($data['confirmations'] >= TronHelper::CONFIRMED_NUMBER) {
|
|
|
$data['status'] = self::model()::STATUS_SUCCESS;
|
|
|
$where = self::getWhere(['txid' => $txid, 'status' => self::model()::STATUS_STAY]);
|
|
|
$recharge = self::model()::where($where)->update($data);
|
|
|
|
|
|
+ $amount = floatval($info->amount);
|
|
|
+ $rate_amount = bcmul($amount, $rate, 10); // 汇率转换后分数
|
|
|
+
|
|
|
// 更新成功,变动可用余额
|
|
|
if ($recharge) {
|
|
|
- $balanceData = WalletService::updateBalance($info->member_id, $info->amount);
|
|
|
- BalanceLogService::addLog($info->member_id, $info->amount, $balanceData['before_balance'], $balanceData['after_balance'], '充值', $info->id, '');
|
|
|
+ $balanceData = WalletService::updateBalance($info->member_id, $rate_amount);
|
|
|
+ BalanceLogService::addLog($info->member_id, $rate_amount, $balanceData['before_balance'], $balanceData['after_balance'], '充值', $info->id, '');
|
|
|
|
|
|
CollectService::createCollect($info->to_address, $info->coin, $info->net);
|
|
|
|
|
|
$amount = floatval($info->amount);
|
|
|
- $text = " ➕ 充币到帐 +{$amount} USDT\n";
|
|
|
- $text .= "链上哈希:{$txid}\n";
|
|
|
- $text .= "当前余额:{$balanceData['after_balance']}\n";
|
|
|
+ $text = "充值结果通知\n";
|
|
|
+ $text .= "充值数量:{$amount} USDT\n";
|
|
|
+ $text .= "充值地址:{$info->to_address}\n";
|
|
|
+ $text .= "汇率:1 USDT = {$rate} RMB\n";
|
|
|
+ $text .= "折合金额:" . number_format($rate_amount, 2) . " RMB\n";
|
|
|
+ $text .= "状态:成功\n";
|
|
|
TopUpService::notifyTransferSuccess($info->member_id, $text);
|
|
|
}
|
|
|
}
|