1.优化管理员提现记录审核为一个操作

2.修复创建玩家报错“参数%s不能为空”
3.修复玩家登录报错
This commit is contained in:
2026-05-30 18:27:26 +08:00
parent 9a3f3b747f
commit 75e91fee13
11 changed files with 438 additions and 98 deletions

View File

@@ -14,7 +14,7 @@ use Webman\Http\Request as WebmanRequest;
*/
class AdminWithdrawOrder extends Backend
{
protected array $noNeedPermission = ['stats', 'approve', 'reject'];
protected array $noNeedPermission = ['stats'];
protected ?object $model = null;
@@ -61,7 +61,13 @@ class AdminWithdrawOrder extends Backend
$list = $res->items();
foreach ($list as $idx => $item) {
$list[$idx]['can_review'] = $this->canReviewOrder(is_array($item) ? $item : []) ? 1 : 0;
$row = is_array($item) ? $item : $item->toArray();
$canReview = $this->canReviewOrder($row) ? 1 : 0;
if (is_array($item)) {
$list[$idx]['can_review'] = $canReview;
} else {
$item->setAttr('can_review', $canReview);
}
}
return $this->success('', [
@@ -79,7 +85,7 @@ class AdminWithdrawOrder extends Backend
return $this->error(__('Parameter error'));
}
if ($this->request && $this->request->method() === 'POST') {
return $this->error(__('Please use approve/reject buttons to review'));
return $this->error(__('Please use the review action to process this order'));
}
$row = $this->loadWithRelations(intval(strval($id)));
if (!$row) {
@@ -91,7 +97,10 @@ class AdminWithdrawOrder extends Backend
return $this->success('', ['row' => $row]);
}
public function approve(WebmanRequest $request): Response
/**
* 审核(通过 / 拒绝)
*/
public function review(WebmanRequest $request): Response
{
$response = $this->initializeBackend($request);
if ($response !== null) {
@@ -101,46 +110,12 @@ class AdminWithdrawOrder extends Backend
return $this->error(__('Parameter error'));
}
$id = intval(strval($request->post('id', 0)));
if ($id <= 0) {
return $this->error(__('Parameter error'));
}
$order = Db::name('admin_withdraw_order')->where('id', $id)->find();
if (!is_array($order)) {
return $this->error(__('Record not found'));
}
if (!$this->canReviewOrder($order)) {
return $this->error(__('You have no permission'));
}
if (intval($order['status'] ?? 0) !== 0) {
return $this->error(__('This withdraw order has already been reviewed'));
}
$remark = trim((string) $request->post('remark', ''));
Db::startTrans();
try {
AdminWalletService::approveWithdraw($order, intval($this->auth->id), $remark);
Db::commit();
} catch (Throwable $e) {
Db::rollback();
return $this->error($e->getMessage());
}
return $this->success(__('Approved'));
}
public function reject(WebmanRequest $request): Response
{
$response = $this->initializeBackend($request);
if ($response !== null) {
return $response;
}
if ($request->method() !== 'POST') {
return $this->error(__('Parameter error'));
}
$id = intval(strval($request->post('id', 0)));
if ($id <= 0) {
$action = strtolower(trim((string) $request->post('action', '')));
if ($id <= 0 || !in_array($action, ['approve', 'reject'], true)) {
return $this->error(__('Parameter error'));
}
$remark = trim((string) $request->post('remark', ''));
if ($remark === '') {
if ($action === 'reject' && $remark === '') {
return $this->error(__('Please provide reject reason'));
}
$order = Db::name('admin_withdraw_order')->where('id', $id)->find();
@@ -155,13 +130,18 @@ class AdminWithdrawOrder extends Backend
}
Db::startTrans();
try {
AdminWalletService::rejectWithdraw($order, intval($this->auth->id), $remark);
if ($action === 'approve') {
AdminWalletService::approveWithdraw($order, intval($this->auth->id), $remark);
} else {
AdminWalletService::rejectWithdraw($order, intval($this->auth->id), $remark);
}
Db::commit();
} catch (Throwable $e) {
Db::rollback();
return $this->error($e->getMessage());
}
return $this->success(__('Rejected'));
return $this->success($action === 'approve' ? __('Approved') : __('Rejected'));
}
public function stats(WebmanRequest $request): Response
@@ -226,11 +206,11 @@ class AdminWithdrawOrder extends Backend
private function canReviewOrder(array $order): bool
{
if (!$this->auth) {
if (!$this->auth || intval($order['status'] ?? 0) !== 0) {
return false;
}
if ($this->auth->isSuperAdmin() || $this->hasGlobalReadScope()) {
return true;
if (!$this->hasAdminWithdrawReviewPermission()) {
return false;
}
$adminId = intval($order['admin_id'] ?? 0);
if ($adminId <= 0) {
@@ -243,5 +223,19 @@ class AdminWithdrawOrder extends Backend
return in_array($adminId, $scopedAdminIds, true);
}
private function hasAdminWithdrawReviewPermission(): bool
{
if (!$this->auth) {
return false;
}
foreach ($this->buildPermissionRoutePaths('order/adminWithdrawOrder', 'review') as $routePath) {
if ($this->auth->check($routePath)) {
return true;
}
}
return false;
}
}

View File

@@ -108,7 +108,8 @@ class Auth extends MobileBase
$ok = $this->auth->login($username, $password, true);
if (!$ok) {
return $this->mobileError(1101, 'Incorrect account or password');
$detail = (string) $this->auth->getError();
return $this->mobileError(1101, $detail !== '' ? $detail : 'Incorrect account or password');
}
$this->bindMobileDeviceSession($request);

View File

@@ -177,12 +177,15 @@ class Auth extends \ba\Auth
} elseif (preg_match('/^[a-zA-Z][a-zA-Z0-9_]{2,15}$/', $username)) {
$accountType = 'username';
}
if (!$accountType) {
$this->setError('Account not exist');
return false;
if ($accountType) {
$this->model = User::where($accountType, $username)->find();
} else {
// 兼容历史纯数字账号、带 + 前缀手机号等非标准格式
$this->model = User::where('username', $username)->whereOr('phone', $username)->find();
if (!$this->model && str_starts_with($username, '+')) {
$this->model = User::where('phone', substr($username, 1))->find();
}
}
$this->model = User::where($accountType, $username)->find();
if (!$this->model) {
$this->setError('Account not exist');
return false;
@@ -204,7 +207,7 @@ class Auth extends \ba\Auth
if ($this->model->login_failure > 0 && $lastLoginTs > 0 && time() - $lastLoginTs >= 86400) {
$this->model->login_failure = 0;
$this->model->save();
$this->model = User::where($accountType, $username)->find();
$this->model = User::find($this->model->id);
}
if ($this->model->login_failure >= $userLoginRetry) {
$this->setError('Please try again after 1 day');

View File

@@ -39,13 +39,38 @@ if (!function_exists('env')) {
if (!function_exists('__')) {
/**
* 语言翻译BuildAdmin 兼容)
* ThinkPHP 风格占位符(%s / %d 等 + 数字下标 vars在翻译后走 sprintf
* Symfony 风格占位符(%name% 或 '%s' => value 等字符串键)走 trans/strtr。
*/
function __(string $name, array $vars = [], string $lang = ''): mixed
{
if (is_numeric($name) || !$name) {
return $name;
}
return function_exists('trans') ? trans($name, $vars, null, $lang ?: null) : $name;
if (!function_exists('trans')) {
return $name;
}
$positional = [];
$named = [];
foreach ($vars as $k => $v) {
if (is_int($k)) {
$positional[$k] = $v;
} else {
$named[$k] = $v;
}
}
if ($positional !== [] && $named === []) {
$translated = trans($name, [], null, $lang ?: null);
if ($translated === '' || $translated === $name) {
$translated = $name;
}
return vsprintf($translated, array_values($positional));
}
return trans($name, $vars, null, $lang ?: null);
}
}