fix(user-center): 优化提现记录弹窗分页
This commit is contained in:
@@ -258,19 +258,23 @@ final class CommissionLedger {
|
||||
'permission_callback' => [$this, 'check_user_rest'],
|
||||
'args' => $list_args,
|
||||
]);
|
||||
$withdrawal_args = $list_args;
|
||||
$withdrawal_args['per_page']['default'] = 10;
|
||||
$withdrawal_args['per_page']['maximum'] = 10;
|
||||
register_rest_route('aksrt/v1', '/earnings/withdrawals', [
|
||||
[
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => fn(\WP_REST_Request $request) => rest_ensure_response($this->withdrawals(get_current_user_id(), $request->get_params())),
|
||||
'permission_callback' => [$this, 'check_user_rest'],
|
||||
'args' => $list_args,
|
||||
'args' => $withdrawal_args,
|
||||
],
|
||||
|
||||
[
|
||||
'methods' => \WP_REST_Server::CREATABLE,
|
||||
'callback' => [$this, 'create_withdrawal'],
|
||||
'permission_callback' => [$this, 'check_user_write_rest'],
|
||||
'args' => [
|
||||
'amount' => ['type' => 'string', 'required' => true, 'pattern' => '^(0|[1-9]\\d*)(?:\\.\\d{1,2})?$'],
|
||||
'amount' => ['type' => 'string', 'required' => true, 'pattern' => '^(0|[1-9]\d*)(?:\.\d{1,2})?$'],
|
||||
'method' => ['type' => 'string', 'required' => true, 'sanitize_callback' => 'sanitize_key'],
|
||||
'account' => ['type' => 'string', 'required' => true, 'minLength' => 1, 'maxLength' => 500, 'sanitize_callback' => 'sanitize_text_field'],
|
||||
],
|
||||
@@ -384,7 +388,30 @@ final class CommissionLedger {
|
||||
}
|
||||
public function admin_overview(): array { global $wpdb; $table=$this->table('commission_ledger'); $row=$wpdb->get_row("SELECT COUNT(*) total, SUM(status='pending') pending, SUM(status='settled') settled, COALESCE(SUM(original_amount+adjustment_total),0) amount FROM {$table}",ARRAY_A) ?: []; return ['total'=>(int)($row['total']??0),'pending'=>(int)($row['pending']??0),'settled'=>(int)($row['settled']??0),'amount'=>$this->balance_decimal((string)($row['amount']??'0'))]; }
|
||||
public function admin_ledger(array $args): array { global $wpdb; $table=$this->table('commission_ledger'); $limit=max(1,min(100,(int)($args['per_page']??20))); $page=max(1,(int)($args['page']??1)); $offset=($page-1)*$limit; $status=sanitize_key((string)($args['status']??'')); $where='1=1'; $params=[]; if(in_array($status,['pending','settled','cancelled'],true)){ $where.=' AND status=%s'; $params[]=$status; } $total=(int)($wpdb->get_var($params?$wpdb->prepare("SELECT COUNT(*) FROM {$table} WHERE {$where}",$params):"SELECT COUNT(*) FROM {$table}")); $rows=$wpdb->get_results($wpdb->prepare("SELECT * FROM {$table} WHERE {$where} ORDER BY id DESC LIMIT %d OFFSET %d",array_merge($params,[$limit,$offset])),ARRAY_A); return ['items'=>$rows?:[],'total'=>$total,'page'=>$page,'per_page'=>$limit,'max_pages'=>max(1,(int)ceil($total/$limit))]; }
|
||||
public function withdrawals(int $user_id, array $args): array { return \AKSRT\Payment\Withdrawal::get_instance()->get_user_withdrawals($user_id, ['status'=>sanitize_key((string)($args['status']??'')),'limit'=>max(1,min(100,(int)($args['per_page']??20))),'offset'=>max(0,((int)($args['page']??1)-1)*max(1,(int)($args['per_page']??20)))]); }
|
||||
public function withdrawals(int $user_id, array $args): array {
|
||||
$service = \AKSRT\Payment\Withdrawal::get_instance();
|
||||
$page = max(1, (int) ($args['page'] ?? 1));
|
||||
$per_page = 10;
|
||||
$status = sanitize_key((string) ($args['status'] ?? ''));
|
||||
$filters = ['user_id' => $user_id];
|
||||
if ($status !== '') {
|
||||
$filters['status'] = $status;
|
||||
}
|
||||
$total = $service->get_count($filters);
|
||||
$max_pages = max(1, (int) ceil($total / $per_page));
|
||||
$page = min($page, $max_pages);
|
||||
return [
|
||||
'items' => $service->get_user_withdrawals($user_id, [
|
||||
'status' => $status,
|
||||
'limit' => $per_page,
|
||||
'offset' => ($page - 1) * $per_page,
|
||||
]),
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'per_page' => $per_page,
|
||||
'max_pages' => $max_pages,
|
||||
];
|
||||
}
|
||||
public function create_withdrawal(\WP_REST_Request $request): \WP_REST_Response|\WP_Error {
|
||||
$user_id=get_current_user_id(); $method=sanitize_key((string)$request->get_param('method')); $account=sanitize_text_field((string)$request->get_param('account')); $settings=\AKSRT\Settings\Settings::get_withdrawal_settings(); $affiliate=\AKSRT\Settings\Settings::get_affiliate_settings();
|
||||
$raw_amount=$request->get_param('amount');
|
||||
|
||||
Reference in New Issue
Block a user