wallet tron transactions
This commit is contained in:
@ -4,6 +4,7 @@ namespace App\Models\Api\Wallet;
|
||||
|
||||
use App\Bean\Model\Api\Order\CustomerUserPostOrderBean;
|
||||
use App\Bean\Model\Api\Wallet\CustomerWalletBalanceTransactionBean;
|
||||
use App\Cache\Table\Api\TableCustomerSettingCache;
|
||||
use App\Exceptions\ModelException;
|
||||
use App\Models\Api\Base\ApiBaseModel;
|
||||
use App\Models\Api\Order\CustomerUserPostOrderModel;
|
||||
@ -14,7 +15,7 @@ use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CustomerWalletBalanceTransactionModel extends ApiBaseModel
|
||||
{
|
||||
protected $table = 'customer_wallet_balance_transactions';
|
||||
protected $table = 'customer_wallet_balance_transaction';
|
||||
protected $primaryKey = 'id';
|
||||
protected $fillable = [
|
||||
'id',
|
||||
@ -24,6 +25,7 @@ class CustomerWalletBalanceTransactionModel extends ApiBaseModel
|
||||
'uid',
|
||||
'currency_code',
|
||||
'amount',
|
||||
'fee_amount',
|
||||
'before_total_amount',
|
||||
'after_total_amount',
|
||||
'source_params',
|
||||
@ -694,23 +696,34 @@ class CustomerWalletBalanceTransactionModel extends ApiBaseModel
|
||||
$bean->setStatus(self::STATUS_PROCESSING);
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
//获取提现手续费
|
||||
$oTableCustomerSettingCache = new TableCustomerSettingCache();
|
||||
$withdraw_fee = $oTableCustomerSettingCache->getWithdrawFeeAmount();
|
||||
//查询用户余额
|
||||
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByUidCurrencyCode($bean->getUid(), $bean->getCurrencyCode());
|
||||
if (!$resWalletBalanceModel) throw new ModelException('wallet not found');
|
||||
//检查余额是否足够
|
||||
if (Math::bcComp(Math::bcSub($resWalletBalanceModel->available_amount, $withdraw_fee), abs($bean->getAmount())) == -1) throw new ModelException('balance not enough');
|
||||
|
||||
$bean->setFeeAmount($withdraw_fee);
|
||||
$bean->setWalletId($resWalletBalanceModel->id);
|
||||
$bean->setBeforeTotalAmount($resWalletBalanceModel->total_amount);
|
||||
$bean->setAfterTotalAmount($resWalletBalanceModel->total_amount);
|
||||
//新增账变
|
||||
$res = $this->addTransaction($bean);
|
||||
if (!$res) throw new ModelException('addTransaction fail');
|
||||
//先扣除手续费
|
||||
$res = $this->typeTransactionFeeSub($uid, $currency_code, $withdraw_fee, $res->id . ' withdraw fee');
|
||||
if (!$res) throw new ModelException('withdraw fee fail');
|
||||
//变更余额
|
||||
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||
//先冻结,等回调成功再扣减
|
||||
$res = $oCustomerWalletBalanceModel->frozenAmount($bean->getWalletId(), $bean->getAmount());
|
||||
if (!$res) throw new ModelException('withdraw fail');
|
||||
DB::commit();
|
||||
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||
//@@发送到提现通知钱包队列
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
@ -760,6 +773,9 @@ class CustomerWalletBalanceTransactionModel extends ApiBaseModel
|
||||
if (!empty($remark)) $updateItem['remark'] = $remark;
|
||||
$res = $this->updateItem($updateItem);
|
||||
if (!$res) throw new ModelException('updateItem fail');
|
||||
//返还手续费
|
||||
$res = $this->typeTransactionFeeAdd($resModel->uid, $resModel->currency_code, $resModel->fee_amount, $resModel->id . ' withdraw fail return fee');
|
||||
if (!$res) throw new ModelException('withdraw fail return fee fail');
|
||||
}
|
||||
DB::commit();
|
||||
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||
@ -803,13 +819,13 @@ class CustomerWalletBalanceTransactionModel extends ApiBaseModel
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
Logs::ErrLog('typeRecharge error rollBack', $e);
|
||||
Logs::ErrLog(__FUNCTION__.'typeRecharge error rollBack', $e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function addTransaction(CustomerWalletBalanceTransactionBean &$bean)
|
||||
function addTransaction(CustomerWalletBalanceTransactionBean &$bean): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
|
||||
{
|
||||
if (!$bean->getWalletId()) throw new ModelException('wallet_id is required');
|
||||
if (!$bean->getType()) throw new ModelException('type is required');
|
||||
|
||||
Reference in New Issue
Block a user