1.优化管理员提现记录审核为一个操作
2.修复创建玩家报错“参数%s不能为空” 3.修复玩家登录报错
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user