100 lines
3.7 KiB
PHP
100 lines
3.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\library\finance\WithdrawFlow;
|
|
use app\common\model\UserWalletRecord;
|
|
use Webman\Http\Request;
|
|
use support\Response;
|
|
|
|
class Wallet extends MobileBase
|
|
{
|
|
public function balanceSummary(Request $request): Response
|
|
{
|
|
$response = $this->initializeMobile($request);
|
|
if ($response !== null) {
|
|
return $response;
|
|
}
|
|
$user = $this->auth->getUser();
|
|
$coinBalance = WithdrawFlow::amountString($user->coin ?? '0');
|
|
$flow = WithdrawFlow::status(intval($user->id), [
|
|
'total_deposit_coin' => $user->total_deposit_coin ?? '0',
|
|
'total_withdraw_coin' => $user->total_withdraw_coin ?? '0',
|
|
'bet_flow_coin' => $user->bet_flow_coin ?? '0',
|
|
]);
|
|
$maxWithdrawable = WithdrawFlow::maxWithdrawable($coinBalance, $flow);
|
|
return $this->mobileSuccess([
|
|
'coin_balance' => $coinBalance,
|
|
'frozen_balance' => '0.0000',
|
|
'withdrawable_balance' => $coinBalance,
|
|
'max_withdrawable' => $maxWithdrawable,
|
|
'total_deposit_coin' => WithdrawFlow::amountString($user->total_deposit_coin ?? '0'),
|
|
'total_withdraw_coin' => WithdrawFlow::amountString($user->total_withdraw_coin ?? '0'),
|
|
'bet_flow_coin' => $flow['bet_flow_coin'],
|
|
'withdraw_flow' => [
|
|
'ratio' => $flow['ratio'],
|
|
'net_deposit' => $flow['net_deposit'],
|
|
'required_bet_flow' => $flow['required_bet_flow'],
|
|
'remaining_bet_flow' => $flow['remaining_bet_flow'],
|
|
'eligible' => $flow['eligible'],
|
|
'max_withdraw_by_flow' => $flow['flow_unlimited'] ? null : $flow['max_withdraw_by_flow'],
|
|
'flow_unlimited' => $flow['flow_unlimited'],
|
|
],
|
|
]);
|
|
}
|
|
|
|
public function recordList(Request $request): Response
|
|
{
|
|
$response = $this->initializeMobile($request);
|
|
if ($response !== null) {
|
|
return $response;
|
|
}
|
|
$type = trim((string) $request->input('type', 'all'));
|
|
$page = $this->intValue($request->input('page', 1), 1);
|
|
$pageSize = $this->intValue($request->input('page_size', 20), 20);
|
|
|
|
$query = UserWalletRecord::where('user_id', $this->auth->id)->order('id', 'desc');
|
|
if ($type !== '' && $type !== 'all') {
|
|
$query->where('biz_type', $type);
|
|
}
|
|
$paginate = $query->paginate([
|
|
'page' => $page,
|
|
'list_rows' => $pageSize,
|
|
]);
|
|
$list = [];
|
|
foreach ($paginate->items() as $row) {
|
|
$list[] = [
|
|
'record_id' => $row->id,
|
|
'biz_type' => $row->biz_type,
|
|
'direction' => $row->direction,
|
|
'amount' => $row->amount,
|
|
'balance_before' => $row->balance_before,
|
|
'balance_after' => $row->balance_after,
|
|
'ref_type' => $row->ref_type,
|
|
'ref_id' => $row->ref_id,
|
|
'create_time' => $row->create_time,
|
|
];
|
|
}
|
|
return $this->mobileSuccess([
|
|
'list' => $list,
|
|
'pagination' => [
|
|
'page' => $paginate->currentPage(),
|
|
'page_size' => $paginate->listRows(),
|
|
'total' => $paginate->total(),
|
|
],
|
|
]);
|
|
}
|
|
|
|
private function intValue($value, int $default): int
|
|
{
|
|
$result = filter_var($value, FILTER_VALIDATE_INT);
|
|
if ($result === false) {
|
|
return $default;
|
|
}
|
|
return $result;
|
|
}
|
|
}
|
|
|