Files
cycle_api/app/Models/Api/Wallet/CustomerWalletBalanceModel.php
2024-03-10 00:44:58 +08:00

131 lines
3.9 KiB
PHP

<?php
namespace App\Models\Api\Wallet;
use App\Models\Api\Base\ApiBaseModel;
use Illuminate\Support\Facades\DB;
class CustomerWalletBalanceModel extends ApiBaseModel
{
protected $table = 'customer_wallet_balance';
protected $primaryKey = 'id';
protected $fillable = [
'id',
'uid',
'currency_code',
'total_amount',
'frozen_amount',
'available_amount',
'security_amount',
'recharge_wallet_addr',
'created_at',
'updated_at',
];
function frozenAmount($id,$amount): bool|int
{
$amount = abs($amount);
$updateItem = [
'id' => $id,
'frozen_amount' => DB::raw('frozen_amount + '. $amount),
'available_amount' => DB::raw('available_amount - '. $amount),
];
return $this->updateItem($updateItem);
}
function unFrozenAmount($id,$amount): bool|int
{
$amount = abs($amount);
$updateItem = [
'id' => $id,
'frozen_amount' => DB::raw('frozen_amount - '. $amount),
'available_amount' => DB::raw('available_amount + '. $amount),
];
return $this->updateItem($updateItem);
}
function subFrozenAmount($id, $amount): bool|int
{
$amount = abs($amount);
$updateItem = [
'id' => $id,
'total_amount' => DB::raw('total_amount - '. $amount),
'frozen_amount' => DB::raw('frozen_amount - '. $amount),
];
return $this->updateItem($updateItem);
}
function addFrozenAmount($id, $amount): bool|int
{
$amount = abs($amount);
$updateItem = [
'id' => $id,
'total_amount' => DB::raw('total_amount + '. $amount),
'frozen_amount' => DB::raw('frozen_amount + '. $amount),
];
return $this->updateItem($updateItem);
}
function subAvailableAmount($id, $amount): bool|int
{
$amount = abs($amount);
$updateItem = [
'id' => $id,
'total_amount' => DB::raw('total_amount - '. $amount),
'available_amount' => DB::raw('available_amount - '. $amount),
];
return $this->updateItem($updateItem);
}
function addAvailableAmount($id, $amount): bool|int
{
$amount = abs($amount);
$updateItem = [
'id' => $id,
'total_amount' => DB::raw('total_amount + '. $amount),
'available_amount' => DB::raw('available_amount + '. $amount),
];
return $this->updateItem($updateItem);
}
function balanceToSecurity($id, $amount): bool|int
{
$amount = abs($amount);
$updateItem = [
'id' => $id,
'total_amount' => DB::raw('total_amount - '. $amount),
'available_amount' => DB::raw('available_amount - '. $amount),
'security_amount' => DB::raw('security_amount + '. $amount),
];
return $this->updateItem($updateItem);
}
function securityToBalance($id, $amount): bool|int
{
$amount = abs($amount);
$updateItem = [
'id' => $id,
'total_amount' => DB::raw('total_amount + '. $amount),
'available_amount' => DB::raw('available_amount + '. $amount),
'security_amount' => DB::raw('security_amount - '. $amount),
];
return $this->updateItem($updateItem);
}
function subSecurityAmount($id, $amount): bool|int
{
$amount = abs($amount);
$updateItem = [
'id' => $id,
'security_amount' => DB::raw('security_amount - '. $amount),
];
return $this->updateItem($updateItem);
}
function findByUidCurrencyCode($uid, $currency_code): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Builder|array|null
{
return $this->findItemByWhere(['uid' => $uid, 'currency_code' => $currency_code]);
}
}