<?php


namespace App\Models;


use App\Facade\TableName;
use App\Http\helper\NumConfig;
use Illuminate\Support\Facades\DB;

class Withdrawal
{

    public function assessment($cz_money)
    {
        $assessment = '';
        switch ($cz_money) {
            case 0:
                $assessment = '';
                break;
            case $cz_money >= 10000:
                $assessment = '充10000+';
                break;
            case $cz_money >= 1000 && $cz_money < 10000 :
                $assessment = '充1000+';
                break;
            case $cz_money >= 100 && $cz_money < 1000:
                $assessment = '充100+';
                break;
            case $cz_money > 0 && $cz_money < 100:
                $assessment = '充少';
                break;
        }
        return $assessment;
    }

    // 返回状态文字
    public function stateText($State, $lock = 0)
    {
        switch ($State) {
            case 1:
                $states = __('auto.审核中');
                break;
            case 2:
                $states =  __('auto.通过');
                break;
            case -1:

                $states = $lock == 3 ? __('auto.拒绝') :__('auto.清退');
//                $states = '审核拒绝';
                break;
            case 4:
                $states = __('auto.系统回收');
                break;
            case 5:
                $states = __('auto.处理中');
                break;
            case 6:
                $states = '<span style="color: red;">'.__('auto.第三方订单失败').'</span>';
                break;
            case 7:
                $states = __('auto.三方账单清算中');
                break;
            default:
                $states = __('auto.未知');
                break;
        }
        return $states;
    }

    // 获取用户提现信息
    public function AccountWithDrawInfo($PixNum, $agent)
    {
//        $first = DB::connection('write')->table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
//            ->where('UserID', $UserID)
//            ->select(['BankUserName', 'PhoneNumber', 'EmailAddress', 'PixNum', 'PixType'])
//            ->first();
//        if (!$first) return false;

        // 验证不支持的CNPJ
//        $PixNumLength = strlen($PixNum);
//        if ($PixNumLength == 14 && in_array($agent, [5])) return false;
        return true;
    }

    // 获取哪个三方提现
    public function getAgentChannel($agent)
    {
        switch ($agent) {
            case 1:
                $orderAgent = 5;
                break;
            case 2:
                $orderAgent = 3;
                break;
            case 3:
                $orderAgent = 8;
                break;
            case 4:
                $orderAgent = 7;
                break;
            case 5:
                $orderAgent = 11;
                break;
            case 6:
                $orderAgent = 13;
                break;
            case 7:
                $orderAgent = 15;
                break;
            case 8:
                $orderAgent = DB::table('agent.dbo.admin_configs')->where([
                    'type' => 'cash',
                    'config_key' => 'cash',
                    'config_value' => 8,
                ])->value('id');
                break;
            default:
                $orderAgent = 0;
                break;
        }

        return $orderAgent;
    }

    // 平台所有提现
    public function totalWithdraw()
    {
        return DB::table(TableName::QPRecordDB() . 'RecordUserTotalStatistics')
            ->where('Withdraw', '>', 0)
            ->selectRaw('sum(Withdraw) Withdraw,count(UserID) countUser')
            ->first();
    }

    public function WithDrawRecovery()
    {
        $first = DB::table('QPAccountsDB.dbo.WithDrawRecovery')
            ->selectRaw('sum(WithDraw) WithDraw,sum(ServiceFee) ServiceFee')
            ->first();
        return empty($first) ? 0 : ($first->WithDraw + $first->ServiceFee) / NumConfig::NUM_VALUE;
    }
}
