<?php
declare (strict_types = 1);

namespace app\controller;

use app\BaseController;
use app\model\GameStatisModel;
use app\model\GameBetGameModel;
use app\common\CommonUtils;
use app\model\GameModel;
use think\facade\Request;

class RankList extends BaseController
{    
    /**
     * 赢钱榜
     */
    public function WinAmount()
    {
        $userInfo = $this->request->userInfo;
        
        // 获取查询参数
        $page = Request::get('page', 1, 'intval');
        $limit = Request::get('limit', 10, 'intval');
        $filters['date'] = Request::get('date', '', 'trim');
        
        try {
            // 获取赢钱榜数据
            $result = GameBetGameModel::getWinRanking(
                $userInfo['merchant_id'],
                $page, 
                $limit,
                $filters
            );
            
            // 格式化金额数据
            foreach ($result['list'] as &$item) {
                $item['general_merchant'] = '';
                $item['channel'] = '';                
                $item['total_win'] = CommonUtils::convertBalance($item['total_win'], false);
                $item['total_bet'] = CommonUtils::convertBalance($item['total_bet'], false);
                $item['balance'] = CommonUtils::convertBalance($item['balance'], false);
            }
            
            return json_success($result, '获取成功');
        } catch (\Exception $e) {
            return json_error([], '获取赢钱榜失败：' . $e->getMessage());
        }
    }  
    
    /**
     * 输钱榜
     */
    public function LoseAmount() {
        $userInfo = $this->request->userInfo;
        
        // 获取查询参数
        $page = Request::get('page', 1, 'intval');
        $limit = Request::get('limit', 10, 'intval');
        $filters['date'] = Request::get('date', '', 'trim');
        
        try {
            // 获取输钱榜数据
            $result = GameBetGameModel::getLoseRanking(
                $userInfo['merchant_id'],
                $page, 
                $limit,
                $filters
            );
            
            // 格式化金额数据
            foreach ($result['list'] as &$item) {
                $item['general_merchant'] = '';
                $item['channel'] = '';
                $item['total_lose'] = CommonUtils::convertBalance($item['total_lose'], false);
                $item['total_bet'] = CommonUtils::convertBalance($item['total_bet'], false);
                $item['balance'] = CommonUtils::convertBalance($item['balance'], false);
            }
            
            return json_success($result, '获取成功');
        } catch (\Exception $e) {
            return json_error([], '获取输钱榜失败：' . $e->getMessage());
        }
    }

    /**
     * 注单榜
     */
    public function BetAmount() {
        $userInfo = $this->request->userInfo;
        
        // 获取查询参数
        $page = Request::get('page', 1, 'intval');
        $limit = Request::get('limit', 10, 'intval');
        $filters['date'] = Request::get('date', '', 'trim');
        
        try {
            // 获取赢钱榜数据
            $result = GameBetGameModel::getBetAmountRanking(
                $userInfo['merchant_id'],
                $page, 
                $limit,
                $filters
            );
            
            // 格式化金额数据
            foreach ($result['list'] as &$item) {
                $item['general_merchant'] = '';
                $item['channel'] = '';                
                $item['total_win'] = CommonUtils::convertBalance($item['total_win'], false);
                $item['total_bet'] = CommonUtils::convertBalance($item['total_bet'], false);
                $item['balance'] = CommonUtils::convertBalance($item['balance'], false);
            }
            
            return json_success($result, '获取成功');
        } catch (\Exception $e) {
            return json_error([], '获取注单额榜失败：' . $e->getMessage());
        }
    }
    
}