用户账变 用户钱包
This commit is contained in:
@ -10,6 +10,7 @@ use App\Tools\Times;
|
||||
use App\Tools\Tools;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Symfony\Contracts\Service;
|
||||
|
||||
class WalletPlatformBalanceTransactionModel extends WalletBaseModel
|
||||
{
|
||||
@ -156,17 +157,22 @@ class WalletPlatformBalanceTransactionModel extends WalletBaseModel
|
||||
}
|
||||
|
||||
//成功提现处理
|
||||
function withdrawSuccByUserTransactionId($user_transaction_id, $remark = ''): bool
|
||||
function withdrawSuccByUserTransactionId($user_transaction_id,$entered_amount, $remark = ''): bool
|
||||
{
|
||||
try{
|
||||
Db::beginTransaction();
|
||||
$resModel = $this->findItemByWhere(['from_user_transaction_id' => $user_transaction_id, 'type' => self::TYPE_USER_WITHDRAW]);
|
||||
if (!$resModel) return false;
|
||||
if (!in_array($resModel->status, [self::STATUS_WAITING_QUEUE, self::STATUS_CHAIN_WAITING_CALLBACK])) return false;
|
||||
$resModel->status = self::STATUS_SUCCESS;
|
||||
if(!empty($remark)) $resModel->remark = $remark;
|
||||
$resModel->updated_at = Times::getNowDateTime();
|
||||
$res = $resModel->save();
|
||||
if (!$resModel) throw new ModelException('user transaction not found');
|
||||
if (!in_array($resModel->status, [self::STATUS_WAITING_QUEUE, self::STATUS_CHAIN_WAITING_CALLBACK])) throw new ModelException('status error');
|
||||
$updateItems = [
|
||||
'id' => $resModel->id,
|
||||
'status' => self::STATUS_SUCCESS,
|
||||
'updated_at' => Times::getNowDateTime(),
|
||||
'entered_amount' => $entered_amount,
|
||||
'fee_amount' => Db::raw('received_amount - '.$entered_amount),
|
||||
];
|
||||
if(!empty($remark)) $updateItems['remark'] = $remark;
|
||||
$res = $this->updateItem($updateItems);
|
||||
if(!$res) throw new ModelException('save error');
|
||||
|
||||
//扣除平台冻结余额
|
||||
@ -196,9 +202,13 @@ class WalletPlatformBalanceTransactionModel extends WalletBaseModel
|
||||
if (!$resModel) throw new ModelException('user transaction not found');
|
||||
if (!in_array($resModel->status, [self::STATUS_WAITING_QUEUE, self::STATUS_CHAIN_WAITING_CALLBACK])) throw new ModelException('status error');
|
||||
//更改账变状态
|
||||
$resModel->status = self::STATUS_FAIL;
|
||||
if(!empty($remark)) $resModel->remark = $remark;
|
||||
$res = $resModel->save();
|
||||
$updateItems = [
|
||||
'id' => $resModel->id,
|
||||
'status' => self::STATUS_FAIL,
|
||||
'updated_at' => Times::getNowDateTime(),
|
||||
];
|
||||
if(!empty($remark)) $updateItems['remark'] = $remark;
|
||||
$res = $this->updateItem($updateItems);
|
||||
if (!$res) throw new ModelException('save error');
|
||||
|
||||
//解冻平台余额
|
||||
|
||||
@ -303,13 +303,22 @@ class WalletPlatformUserTransactionModel extends WalletBaseModel
|
||||
if ($resWalletPlatformUserTransactionModel->type != self::TYPE_WITHDRAW) throw new ModelException('type error');
|
||||
if ($resWalletPlatformUserTransactionModel->status != self::STATUS_CHAIN_WAITING) throw new ModelException('status error');
|
||||
//用户账变处理
|
||||
$resWalletPlatformUserTransactionModel->status = $status;
|
||||
$resWalletPlatformUserTransactionModel->save();
|
||||
$updateItems = [
|
||||
'id' => $resWalletPlatformUserTransactionModel->id,
|
||||
'status' => $status,
|
||||
'entered_amount' => $resWalletAddrTransactionModel->entered_amount,
|
||||
'fee_amount' => Db::raw('received_amount - '.$resWalletAddrTransactionModel->entered_amount),
|
||||
];
|
||||
$res = $this->updateItem($updateItems);
|
||||
if(!$res) {
|
||||
Log::error('listenWithdrawCallbackErr', $updateItems);
|
||||
return;
|
||||
}
|
||||
|
||||
//平台余额和账变处理
|
||||
$oWalletPlatformBalanceTransactionModel = new WalletPlatformBalanceTransactionModel();
|
||||
if ($status == self::STATUS_SUCCESS) { //成功
|
||||
$oWalletPlatformBalanceTransactionModel->withdrawSuccByUserTransactionId($id);
|
||||
$oWalletPlatformBalanceTransactionModel->withdrawSuccByUserTransactionId($id,$resWalletAddrTransactionModel->entered_amount);
|
||||
} else { //失败
|
||||
$oWalletPlatformBalanceTransactionModel->withdrawErrByUserTransactionId($id);
|
||||
}
|
||||
|
||||
@ -247,10 +247,15 @@ class WalletAddrModel extends WalletBaseModel
|
||||
}
|
||||
|
||||
if ($type == WalletAddrTransactionModel::TYPE_TRANSFER && $resWalletAddrTransactionModel) { //提现已有账变,修改账变状态即可
|
||||
$res = $oWalletAddrTransactionModel->updateItem([
|
||||
$updateItems = [
|
||||
'id' => $resWalletAddrTransactionModel->id,
|
||||
'status' => $status,
|
||||
]);
|
||||
];
|
||||
if($status == WalletAddrTransactionModel::STATUS_SUCCESS){
|
||||
$updateItems['entered_amount'] = $amount;
|
||||
$updateItems['fee_amount'] = Db::raw('received_amount - '.$amount);
|
||||
}
|
||||
$res = $oWalletAddrTransactionModel->updateItem($updateItems);
|
||||
if (!$res) {
|
||||
Log::error('listenWalletAddrCallbackErr', ['token' => $token, 'addr' => $addr, 'amount' => $amount, 'status' => $status, 'wallet_addr_id' => $resModel->id, 'wallet_transaction_id' => $resWalletAddrTransactionModel->id, 'error' => '修改账变状态失败']);
|
||||
throw new ModelException('修改账变状态失败');
|
||||
|
||||
@ -19,6 +19,12 @@ class WalletCurrencyModel extends WalletBaseModel
|
||||
'created_at',
|
||||
];
|
||||
|
||||
const TYPE_CASH = 1;
|
||||
const TYPE_CRYPTO_COIN = 2;
|
||||
const TYPE = [
|
||||
self::TYPE_CASH => '现金',
|
||||
self::TYPE_CRYPTO_COIN => '加密货币',
|
||||
];
|
||||
const CODE_USDT_TRC20 = 'USDT_TRC20';
|
||||
|
||||
function findByCode($code,$columns = ['*']): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|null
|
||||
|
||||
Reference in New Issue
Block a user