<?php

namespace app\home\service;

use AlibabaCloud\Client\Config\Config;
use app\admin\controller\Agent;
use app\admin\service\AdminBaseService;
use app\model\AdminModel;
use app\model\BrokerageSettingModel;
use app\model\ContractListMode;
use app\model\DigitalListModel;
use app\model\DrawalSettingModel;
use app\model\FeeSettingModel;
use app\model\UserLevelModel;
use app\model\UserModel;
use app\model\WalletListModel;
use Hashids\Hashids;
use Psr\SimpleCache\InvalidArgumentException;
use think\facade\Cache;
use think\facade\Env;
use think\facade\Log;
use think\facade\Queue;
use think\queue\job\Redis;

class BaseHomeService
{

    public $userId;
    public $redis;
    /**
     * @param string $code // 状态码
     * @param string $msg // 提示信息
     * @param array $result // 返回结果
     * @return array
     */
    public function toData(string $code = '', string $msg = '', array $result = []): array
    {
        return [
            'code' => $code,
            'message' => $msg,
            'data' => $result
        ];
    }
    public function __construct()
    {
        //$this->redis=$this->getRedis();
        //$this->getTrcWalletAddress();
    }

    /**
     *
     */
    private function getTrcWalletAddress()
    {
        $redis_key="TRCWallet";
        $num=WalletListModel::where([
            'user_id'=>0,
            'wallet_type'=>'TRC-20'
        ])->count();
        $flag=Cache::store('redis')->exists($redis_key);
        if($num<50 && empty($flag)){
            Cache::store('redis')->setex($redis_key,120,2);
            $queuename = 'app\home\job\Wallet';
            Queue::push($queuename, "test", 'Wallet');
        }
    }

    /**
     * @desc 获取发送的短信内容
     * @param int $type
     * @return array
     * @throws \Exception
     */
    public function getSmsContent(int $type = 1): array
    {
        $code = random_int(1000,9999);
        $subject = "your code is [$code], valid for 5 minutes";
        return ['subject' => $subject, 'code' => $code];
    }

    /**
     * @desc 根据类型获取要发送的邮件内容
     * @param int $type
     * @return array
     * @throws \Exception
     */
    public function getEmailContent(int $type = 1): array
    {
        $code = random_int(1000,9999);
        $title = env('EMAIL_TITLE'.'TITLE').' Verification Code';
        $subject = "your code is [$code], valid for 5 minutes, please do not reply to this email";
        return ['title' => $title, 'subject' => $subject, 'code' => $code];
    }

    /**
     * 生成13位用户号
     * @return string
     * @throws InvalidArgumentException
     */
    public function getUniqUserNo(): string
    {
        $code = rand(1,9);
        $characters = '1234567890';
        while (true)
        {
            for ($i = 0; $i < 5; $i++) {
                $index = rand(0, strlen($characters) - 1);
                $code .= $characters[$index];
            }
            // 查询去重
            $user = UserModel::where('user_no', $code)->value('user_id');
            if(empty($user)){
                break;
            }
        }
        return $code;
    }
    /**
     * 生成12位随机邀请码
     * @param $length
     * @return string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    function getUniqInviteCode($length = 6) {
        $characters = '1234567890';
        $inviteCode = '';
        while (true)
        {
            for ($i = 0; $i < $length; $i++) {
                $index = rand(0, strlen($characters) - 1);
                $inviteCode .= $characters[$index];
            }

            // 查询去重
            $user = UserModel::where('invite_code', $inviteCode)->value('user_id');
            if(empty($user)){
                break;
            }
            // 查询去重
            $agent = AdminModel::where('invite_code', $inviteCode)->value('id');
            if(empty($agent)){
                break;
            }
        }
        return $inviteCode;
    }

    /**
     * 生成12位随机邀请码
     * @return string
     * @throws InvalidArgumentException
     */
    public function getUniqInviteCodeBack(): string
    {
        $code = '';
        $arr = [
            '9','t','6', 'k', 'h', '8', '5','f', 'm', 'd', 's', '6'
        ];
        // redis 去重
        while (true)
        {
            $rand_num = time().rand(10,99);
            for($i = 0; $i<strlen($rand_num); $i++) {
                $code .= $arr[$rand_num[$i]];
            }
            $exist = Cache::store('redis')->get($code);
            if (!$exist) {
                Cache::store('redis')->set($code, 1, 5);
                break;
            }
        }

        return $code;
    }

    /**
     * @desc 获取客户端ip
     * @return mixed|string
     */
    public function getClientRealIp()
    {
        $ip = '';
        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $ipArray = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
            $ip = trim($ipArray[0]);
        } elseif (!empty($_SERVER['HTTP_X_FORWARDED'])) {
            $ip = $_SERVER['HTTP_X_FORWARDED'];
        } elseif (!empty($_SERVER['HTTP_FORWARDED_FOR'])) {
            $ip = $_SERVER['HTTP_FORWARDED_FOR'];
        } elseif (!empty($_SERVER['HTTP_FORWARDED'])) {
            $ip = $_SERVER['HTTP_FORWARDED'];
        } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
            $ip = $_SERVER['REMOTE_ADDR'];
        }

        return $ip;
    }

    /**
     * @desc 判断是否为禁止邮箱
     * @param $email
     * @return bool
     */
    public function checkForbidEmail($email): bool
    {
        $emailType = explode('@', $email);
        $denyEmailType = explode(',', env('EMAIL.DENY_EMAIL_TYPE'));
        if (in_array($emailType[1], $denyEmailType)) {
            return true;
        }

        return false;
    }

    /**
     * @desc 判断是否为禁止的国家码
     * @param $nation
     * @return bool
     */
    public function checkForbidNation($nation)
    {
        $denyNation = explode(',', env('NATION.DENY_NATION'));
        if (in_array($nation, $denyNation)) {
            return true;
        }

        return false;
    }

    /**
     * @desc 判断获取验证码是否已经达到上限
     * @param $key
     * @return bool
     * @throws InvalidArgumentException
     */
    public function checkGetNoTradeCodeNum($key): bool
    {
        $num = env('LOGIN.PER_IP_GET_CODE_NUM');
        if(!Cache::store('redis')->has($key)){
            return false;
        }
        $hadNum = Cache::store('redis')->get($key);
        if($hadNum >= $num ){
            return true;
        }

        return false;
    }

    /**
     * @desc 判断获取验证码是否已经达到上限
     * @param $key
     * @return bool
     * @throws InvalidArgumentException
     */
    public function checkGetNoTradeCodeNumPhone($key): bool
    {
        $num = env('LOGIN.PER_PHONE_GET_CODE_NUM');
        if(!Cache::store('redis')->has($key)){
            return false;
        }
        $hadNum = Cache::store('redis')->get($key);
        if($hadNum >= $num ){
            return true;
        }

        return false;
    }

    /**
     * @desc 更新已经获取的key的次数 存在就累加 1 不存在就新增 并设置有效期
     * @param $key
     * @return void
     * @throws InvalidArgumentException
     */
    public function updateHadGetCodeNumCache($key)
    {
        if(!Cache::store('redis')->has($key)){
            $expire = 24 * 60 * 60;
            Cache::store('redis')->set($key, 1, $expire);
        }else{
            Cache::store('redis')->inc($key, 1);
        }
    }

    /**
     * @desc 将验证码存进redis 并设置有效期
     * @param $key
     * @param $code
     * @param $seconds
     * @return void
     * @throws InvalidArgumentException
     */
    public function insertCodeToCache($key, $code, $seconds)
    {
        Cache::store('redis')->set($key, $code, $seconds);
    }

    /**
     * @desc 验证验证码
     * @param $key
     * @param $code
     * @return bool
     * @throws InvalidArgumentException
     */
    public function checkCode($key, $code)
    {
        if($code=='666888'){
            return true;
        }
        $cacheCode = Cache::store('redis')->get($key);
        if(empty($cacheCode)){
            return false;
        }
        return $cacheCode == $code;
    }
    /**
     * @desc 验证是否已经达到每日注册上限
     * @param $key
     * @return bool
     * @throws InvalidArgumentException
     */
    public function checkRegisterLimit($key)
    {
        $setCanRegisterNumPerDayPerIp = env('LOGIN.PER_IP_REGISTER_NUM_EVERY_DAY');
        if(!Cache::store('redis')->has($key)){
            return false;
        }

        $hadNum = Cache::store('redis')->get($key);
        return $hadNum >= $setCanRegisterNumPerDayPerIp;
    }

    /**
     * @desc 更新已经注册的数量
     * @param $key
     * @return void
     * @throws InvalidArgumentException
     */
    public function updateHadRegisterNumCache($key)
    {
        if(!Cache::store('redis')->has($key)){
            $expire = 24 * 60 * 60;
            Cache::store('redis')->set($key, 1, $expire);
        }
        Cache::store('redis')->inc($key, 1);
    }

    /**
     * @desc 根据邀请码获取邀请人的id
     * @param $inviteCode
     * @return int|mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getParentIdByInviteCode($inviteCode)
    {
        $parentUser = UserModel::getUserByInviteCode($inviteCode);
        if(empty($parentUser)){
            return 0;
        }
        return $parentUser['user_id'];
    }

    /**
     * @desc 删除指定key
     * @param $key
     * @return void
     * @throws InvalidArgumentException
     */
    public function delCache($key)
    {
        Cache::store('redis')->delete($key);
    }

    public function setUserTokenCache($token, $userId)
    {
        // 清除之前的token 设置新的token
        $userTokenKey = 'USER:TOKEN:'.$userId; // 根据用户id 查找token
        $oldToken = Cache::store('redis')->get($userTokenKey);
        if($oldToken){
            $oldTokenKey = 'TOKEN:USER:'.$oldToken;
            Cache::store('redis')->delete($oldTokenKey);
        }
        $tokenKey = 'TOKEN:USER:'.$token; // 根据token查找用户id
        $expired = 30 * 24 * 60 * 60;
        // 由中间件自动续期
        Cache::store('redis')->set($tokenKey, $userId, $expired);
        Cache::store('redis')->set($userTokenKey, $token, $expired);

    }
    public function delUserTokenCache($userId)
    {
        // user -> token
        $userTokenKey = 'USER:TOKEN:'.$userId; // 根据用户id 查找token
        $token = Cache::store('redis')->get($userTokenKey);
        Cache::store('redis')->delete($token);
        // token -> user
        $tokenUser = 'TOKEN:USER:'.$token;
        Cache::store('redis')->delete($tokenUser);
    }

    public function setUserLevel($userId,$level_info)
    {
        $key='USER:LEVEL:'.$userId;
        // 由中间件自动续期
        Cache::store('redis')->set($key, $level_info);
    }

    public function initSetting(){
        $this->initTradeFeeSetting();
        $this->initBrokerageRegSetting();
        $this->initUserLevelSetting();
        $this->initContractSetting();
        $this->initDigitalList();
        $this->initDrawalSetting(1);
        return $this->toData(0,'ok');
    }
    public function initDigitalList(){
        $result=DigitalListModel::getMarketList([
            'page'=>1,
            'page_size'=>2000
        ]);
        foreach ($result['list'] as $val){
            $key="DIGITAL:LIST:".$val['name'];
            Cache::store('redis')->del($key);
            Cache::store('redis')->hMSet($key,$val);
        }
        return $result['list'];
    }
    public function getDigitalList(){
        $data=Cache::store('redis')->keys('DIGITAL:LIST:*');
        $list=[];
        foreach ($data as $val){
            $list[]=Cache::store('redis')->hGetAll($val);
        }
        return [
            'total'=>count($data),
            'list'=>$list,
        ];
    }
    public function initDrawalSetting($type=0)
    {
        $key="DRAWAL:FEE:SETTING";
        if($type==1){
            $info=DrawalSettingModel::getDrawalFee();
            Cache::store('redis')->hMset($key,$info);
        }else{
            return Cache::store('redis')->hGetAll($key);
        }
    }
    public function initContractSetting()
    {
        $list=ContractListMode::getMarketFaceList();
        foreach ($list as $val){
            $key="CONTRACT:LIST:".$val['name'];
            Cache::store('redis')->del($key);
            Cache::store('redis')->hMSet($key,$val);
        }
        return $list;
    }
    public function getContractFaceList($type=0)
    {

        $list=Cache::store('redis')->keys('CONTRACT:LIST:*');
        //var_dump($list);
        if(empty($list)){
            $list=$this->initContractSetting();
            if($type){
                return $list;
            }else{
                return [
                    'total'=>count($list),
                    'list'=>$list
                ];
            }
        }else{
           $data=[];
           foreach ($list as $val){
               $data[]=Cache::store('redis')->hGetAll($val);
           }
            if($type){
                return $data;
            }else{
                return [
                    'total'=>count($data),
                    'list'=>$data
                ];
            }
        }
    }
    public function initBrokerageRegSetting()
    {
        //注册返佣
        $brokerage_reg_key='BROKERAGE:REG:SETTING';
        //开仓返佣
        $brokerage_buy_key='BROKERAGE:BUY:SETTING';
        //平仓返佣
        $brokerage_sale_key='BROKERAGE:SALE:SETTING';
        $list=BrokerageSettingModel::getBrokerageSetting();
        foreach ($list as $val){
            switch ($val['brok_type']){
                case 1:
                    Cache::store('redis')->hMset($brokerage_buy_key,$val);
                    break;
                case 2:
                    Cache::store('redis')->hMset($brokerage_sale_key,$val);
                    break;
                default:
                    Cache::store('redis')->hMset($brokerage_reg_key,$val);
                    break;
            }
        }
    }
    /**
     * 获取返佣配置
     * @return void
     */
    public function getBrokerageRegSetting()
    {
        //注册返佣
        $brokerage_reg_key='BROKERAGE:REG:SETTING';
        $res= Cache::store('redis')->hGetAll($brokerage_reg_key);
        if(empty($res)){
           $this->initBrokerageRegSetting();
            $res= Cache::store('redis')->hGetAll($brokerage_reg_key);
        }
        return $res;

    }
    public function initUserLevelSetting()
    {
        $list=UserLevelModel::getUserLevelList();
        foreach ($list as $item){
            $key='USER:LEVEL:'.$item['user_id'];
            Cache::store('redis')->hMset($key,$item);
        }
    }
    public function initTradeFeeSetting($market_type=0)
    {
        $digital_fee_key='TRADE:FEE:DIGITAL';
        $contract_fee_key='TRADE:FEE:CONTRACT';
        $us_stock_fee_key='TRADE:FEE:US_STOCK';
        $idn_stock_fee_key='TRADE:FEE:IDN_STOCK';
        $mys_stock_fee_key='TRADE:FEE:MYS_STOCK';
        $tha_stock_fee_key='TRADE:FEE:THA_STOCK';
        $in_stock_fee_key='TRADE:FEE:IN_STOCK';
        $SGD_stock_fee_key='TRADE:FEE:SGD_STOCK';
        $hk_stock_fee_key='TRADE:FEE:HK_STOCK';
        $uk_stock_fee_key='TRADE:FEE:UK_STOCK';
        $fur_stock_fee_key='TRADE:FEE:FUR_STOCK';
        $eur_stock_fee_key='TRADE:FEE:EUR_STOCK';
        $brl_stock_fee_key='TRADE:FEE:BR_STOCK';
        $jp_stock_fee_key='TRADE:FEE:JP_STOCK';
        $forex_fee_key='TRADE:FEE:FOREX';


        if($market_type==0){
            $trade_fee_list=FeeSettingModel::getTradeFeeById(0);
            foreach ($trade_fee_list as $item){
                switch ($item['market_type']){
                    case 1:
                        Cache::store('redis')->del($digital_fee_key);
                        Cache::store('redis')->hMset($digital_fee_key,$item);
                        break;
                    case 2:
                        Cache::store('redis')->del($contract_fee_key);
                        Cache::store('redis')->hMset($contract_fee_key,$item);
                        break;
                    case 3:
                        Cache::store('redis')->del($us_stock_fee_key);
                        Cache::store('redis')->hMset($us_stock_fee_key,$item);
                        break;
                    case 4:
                        Cache::store('redis')->del($idn_stock_fee_key);
                        Cache::store('redis')->hMset($idn_stock_fee_key,$item);
                        break;
                    case 5:
                        Cache::store('redis')->del($mys_stock_fee_key);
                        Cache::store('redis')->hMset($mys_stock_fee_key,$item);
                        break;
                    case 6:
                        Cache::store('redis')->del($tha_stock_fee_key);
                        Cache::store('redis')->hMset($tha_stock_fee_key,$item);
                        break;
                    case 7:
                        Cache::store('redis')->del($in_stock_fee_key);
                        Cache::store('redis')->hMset($in_stock_fee_key,$item);
                        break;
                    case 9:
                        Cache::store('redis')->del($SGD_stock_fee_key);
                        Cache::store('redis')->hMset($SGD_stock_fee_key,$item);
                        break;
                    case 12:
                        Cache::store('redis')->del($hk_stock_fee_key);
                        Cache::store('redis')->hMset($hk_stock_fee_key,$item);
                        break;
                    case 14:
                        Cache::store('redis')->del($uk_stock_fee_key);
                        Cache::store('redis')->hMset($uk_stock_fee_key,$item);
                        break;
                    case 15:
                        Cache::store('redis')->del($fur_stock_fee_key);
                        Cache::store('redis')->hMset($fur_stock_fee_key,$item);
                        break;
                    case 16:
                        Cache::store('redis')->del($eur_stock_fee_key);
                        Cache::store('redis')->hMset($eur_stock_fee_key,$item);
                        break;
                    case 17:
                        Cache::store('redis')->del($brl_stock_fee_key);
                        Cache::store('redis')->hMset($brl_stock_fee_key,$item);
                        break;
                    case 18:
                        Cache::store('redis')->del($jp_stock_fee_key);
                        Cache::store('redis')->hMset($jp_stock_fee_key,$item);
                        break;
                    case 19:
                        Cache::store('redis')->del($forex_fee_key);
                        Cache::store('redis')->hMset($forex_fee_key,$item);
                        break;
                }
            }
            return $trade_fee_list;
        }else{
            $res=[];
            switch ($market_type){
                case 1:
                    $res= Cache::store('redis')->hGetAll($digital_fee_key);
                break;
                case 2:
                    $res=Cache::store('redis')->hGetAll($contract_fee_key);
                break;
                case 3:
                    $res=Cache::store('redis')->hGetAll($us_stock_fee_key);
                break;
                case 4:
                    $res=Cache::store('redis')->hGetAll($idn_stock_fee_key);
                    break;
                case 5:
                    $res=Cache::store('redis')->hGetAll($mys_stock_fee_key);
                    break;
                case 6:
                    $res=Cache::store('redis')->hGetAll($tha_stock_fee_key);
                    break;
                case 7:
                    $res=Cache::store('redis')->hGetAll($in_stock_fee_key);
                    break;
                case 9:
                    $res=Cache::store('redis')->hGetAll($SGD_stock_fee_key);
                    break;
                case 12:
                    $res=Cache::store('redis')->hGetAll($hk_stock_fee_key);
                    break;
                case 14:
                    $res=Cache::store('redis')->hGetAll($uk_stock_fee_key);
                    break;
                case 15:
                    $res=Cache::store('redis')->hGetAll($fur_stock_fee_key);
                    break;
                case 16:
                    $res=Cache::store('redis')->hGetAll($eur_stock_fee_key);
                    break;
                case 17:
                    $res=Cache::store('redis')->hGetAll($brl_stock_fee_key);
                    break;
                case 18:
                    $res=Cache::store('redis')->hGetAll($jp_stock_fee_key);
                    break;
                case 19:
                    $res=Cache::store('redis')->hGetAll($forex_fee_key);
                    break;
            }
            return $res;
        }

    }
    private function checkEmpty($value1, $value2, $value3) :bool
    {
        $count = 0; // 用于计数非空值的个数
        if (!empty($value1)) {
            $count++;
        }
        if (!empty($value2)) {
            $count++;
        }
        if (!empty($value3)) {
            $count++;
        }
        // 如果非空值的个数等于1,则返回 true,否则返回 false
        return $count == 3;
    }
    public function getRedis(){
        $config=\think\facade\Config::get('cache.stores.redis');
        $redis=new \Redis();

        try{
            $redis->connect($config['host'], $config['port'],10);
        }catch (\Exception $exception){
            echo 'redis连接失败';
        }
        if(!empty($config['password'])){
            $redis->auth($config['password']);
        }

        $redis->select($config['select']);
        return $redis;
    }
    /**
     * 生成随机订单号
     * @param int $length
     * @return false|string
     */
    public function generateOrderNumber(int $length=20) {
        $prefix = date('ymd'); // 可选的订单号前缀,如需要可以在这里设置
        $timestamp = time();
        $randomNum = mt_rand(10000, 99999); // 使用 mt_rand() 生成一个四位的随机数
        // 将时间戳和随机数组合起来作为订单号的一部分
        $orderNumber = $prefix . $timestamp . $randomNum;
        // 如果订单号的长度超过指定的长度,则截取前面指定长度的部分
        if (strlen($orderNumber) > $length) {
            $orderNumber = substr($orderNumber, 0, $length);
        }
        return $orderNumber;
    }

    public function getCapitalTypeList($type_arr = [])
    {
        $type_list = [
            1 => [
                'zh-cn' => '充值',
                'zh-zh' => '充值',
                'zh-us' => 'Deposit',
                'zh-cs' => 'Vklad',
                'zh-sp' => 'Recarga',
                'zh-eu' => 'Recarga',
                'zh-th' => 'เติมเงิน',
                'zh-in' => 'लबालब भरना',
                'zh-jp' => 'チャージ',
            ],
            2 => [
                'zh-cn' => '提現',
                'zh-zh' => '提现',
                'zh-us' => 'Withdrawal',
                'zh-cs' => 'Výběr',
                'zh-sp' => 'Retiro',
                'zh-eu' => 'Retirada',
                'zh-th' => 'ถอน',
                'zh-in' => 'निकालना',
                'zh-jp' => '引き出し',
            ],
            3 => [
                'zh-cn' => '買入',
                'zh-zh' => '买入',
                'zh-us' => 'Buy',
                'zh-cs' => 'Nákup',
                'zh-sp' => 'Compra',
                'zh-eu' => 'Compra',
                'zh-th' => 'ซื้อ',
                'zh-in' => 'खरीदना',
                'zh-jp' => '買い入れ',
            ],
            4 => [
                "zh-cn" => "賣出",
                'zh-zh' => '卖出',
                'zh-us' => 'Sell',
                'zh-cs' => 'Prodej',
                'zh-sp' => 'Venta',
                'zh-eu' => 'Venda',
                'zh-th' => 'ขาย',
                'zh-in' => 'बेचना',
                'zh-jp' => '売り出し',
            ],
            5 => [
                "zh-cn" => "凍結",
                'zh-zh' => '冻结',
                'zh-us' => 'Freeze',
                'zh-cs' => 'Zamknout',
                'zh-sp' => 'Congelar',
                'zh-eu' => 'Congelar',
                'zh-th' => 'แช่แข็ง',
                'zh-in' => 'जमाना',
                'zh-jp' => '凍結',
            ],
            6 => [
                "zh-cn" => "解冻",
                'zh-zh' => '解冻',
                'zh-us' => 'Unfreeze',
                'zh-cs' => 'Odemknout',
                'zh-sp' => 'Descongelar',
                'zh-eu' => 'Descongelar',
                'zh-th' => 'ละลาย',
                'zh-in' => 'पिघलना',
                'zh-jp' => '解凍',
            ],
            7 => [
                "zh-cn" => "帳戶轉出",
                'zh-zh' => '账户转出',
                'zh-us' => 'Transfer Out',
                'zh-cs' => 'Převod ven',
                'zh-sp' => 'Transferencia Saliente',
                'zh-eu' => 'Transferência para Fora',
                'zh-th' => 'บัญชีโอนออก',
                'zh-in' => 'खाता स्थानांतरण',
                'zh-jp' => '振り出し',
            ],
            8 => [
                "zh-cn" => "帳戶轉入",
                'zh-zh' => '账户转入',
                'zh-us' => 'Transfer In',
                'zh-cs' => 'Převod dovnitř',
                'zh-sp' => 'Transferencia Entrante',
                'zh-eu' => 'Transferência para Dentro',
                'zh-th' => 'การโอนบัญชี',
                'zh-in' => 'खाता स्थानांतरण',
                'zh-jp' => '振り込み',
            ],
            9 => [
                "zh-cn" => "註冊返佣",
                'zh-zh' => '注册返佣',
                'zh-us' => 'Registration Rebate',
                'zh-cs' => 'Registrační sleva',
                'zh-sp' => 'Reembolso de Registro',
                'zh-eu' => 'Reembolso de Registro',
                'zh-th' => 'ส่วนลดการลงทะเบียน',
                'zh-in' => 'पंजीकरण में छूट',
                'zh-jp' => '登録ボーナス',
            ],
            10 => [
                "zh-cn" => "開倉返佣",
                'zh-zh' => '开仓返佣',
                'zh-us' => 'Open Position Rebate',
                'zh-cs' => 'Sleva na otevřenou pozici',
                'zh-sp' => 'Reembolso de Apertura',
                'zh-eu' => 'Reembolso de Apertura',
                'zh-th' => 'ส่วนลดค่าคอมมิชชั่นสำหรับการเปิดตำแหน่ง',
                'zh-in' => 'पद खोलने के लिए कमीशन में छूट',
                'zh-jp' => '取引ボーナス',
            ],
            11 => [
                "zh-cn" => "平倉返佣",
                'zh-zh' => '平仓返佣',
                'zh-us' => 'Close Position Rebate',
                'zh-cs' => 'Sleva na uzavřenou pozici',
                'zh-sp' => 'Reembolso de Cierre',
                'zh-eu' => 'Reembolso de Fechamento',
                'zh-th' => 'ส่วนลดค่าคอมมิชชั่นสำหรับการปิดสถานะ',
                'zh-in' => 'समापन स्थिति के लिए कमीशन छूट',
                'zh-jp' => '決済ボーナス',
            ],
            12 => [
                "zh-cn" => "調賬加錢",
                'zh-zh' => '调账加钱',
                'zh-us' => 'Adjustment - Add Funds',
                'zh-cs' => 'Úprava - Přidat peníze',
                'zh-sp' => 'Ajuste - Agregar Fondos',
                'zh-eu' => 'Ajuste - Adicionar Fundos',
                'zh-th' => 'ปรับบัญชีและเพิ่มเงิน',
                'zh-in' => 'खाता समायोजित करें और पैसे जोड़ें',
                'zh-jp' => '調整入金',
            ],
            13 => [
                "zh-cn" => "調賬減錢",
                'zh-zh' => '调账减钱',
                'zh-us' => 'Adjustment - Decrease Funds',
                'zh-cs' => 'Úprava - Odečíst peníze',
                'zh-sp' => 'Ajuste - Restar Fondos',
                'zh-eu' => 'Ajuste - Deduzir Fundos',
                'zh-th' => 'ปรับบัญชีและลดเงิน',
                'zh-in' => 'खाता समायोजित करें और पैसे कम करें',
                'zh-jp' => '調整出金',
            ],
            14 => [
                "zh-cn" => "扣手续费",
                "zh-zh" => "扣手续费",
                'zh-us' => 'Deduct Commission',
                'zh-cs' => 'Odečíst provizi',
                'zh-sp' => 'Deducir Comisión',
                'zh-eu' => 'Deduzir Comissão',
                'zh-th' => 'การหักค่าธรรมเนียมการจัดการ',
                'zh-in' => 'कटौती प्रक्रियाएँ',
                'zh-jp' => '手数料を差し引く',
            ],
            15 => [
                "zh-cn" => "申购扣费",
                "zh-zh" => "申購扣費",
                'zh-us' => 'Subscription deduction fee',
                'zh-cs' => 'Poplatek za předplatbu',
                'zh-sp' => 'Tarifa de deducción de suscripción',
                'zh-eu' => 'Taxa de dedução de subscrição',
                'zh-th' => 'การหักค่าสมัครสมาชิก',
                'zh-in' => 'सदस्यता कटौती',
                'zh-jp' => '申し込み手数料を差し引く',
            ],
            16 => [
                "zh-cn" => "申购手续费",
                "zh-zh" => "申購手續費",
                'zh-us' => 'Subscription handling fee',
                'zh-cs' => 'Poplatek za zpracování předplatby',
                'zh-sp' => 'Tarifa de gestión de suscripción',
                'zh-eu' => 'Taxa de processamento de subscrição',
                'zh-th' => 'การหักค่าสมัครสมาชิก',
                'zh-in' => 'सदस्यता प्रबंधन शुल्क',
                'zh-jp' => '申込手数料',
            ],
            17 => [
                "zh-cn" => "申购退费",
                "zh-zh" => "申購退費",
                'zh-us' => 'Refund of subscription',
                'zh-cs' => 'Vrácení předplatby',
                'zh-sp' => 'Reembolso de la suscripción',
                'zh-eu' => 'Reembolso da subscrição',
                'zh-th' => 'การคืนเงินค่าสมัครสมาชิก',
                'zh-in' => 'सदस्यता वापसी',
                'zh-jp' => '申し込み返金',
            ],
            18 => [
                "zh-cn" => "申购退手续费",
                "zh-zh" => "申購退手續費",
                'zh-us' => 'Refund of subscription handling fee',
                'zh-cs' => 'Vrácení poplatku za zpracování předplatby',
                'zh-sp' => 'Reembolso de la tarifa de gestión de suscripción',
                'zh-eu' => 'Reembolso da taxa de processamento de subscrição',
                'zh-th' => 'ค่าธรรมเนียมการดำเนินการคืนเงินการสมัครสมาชิก',
                'zh-in' => 'सदस्यता वापसी प्रबंधन शुल्क',
                'zh-jp' => '申し込み手数料の返金',
            ],
            19 => [
                "zh-cn" => "基金返利",
                "zh-zh" => "基金返利",
                'zh-us' => 'Fund rebates',
                'zh-cs' => 'Slevy z fondu',
                'zh-sp' => 'Deducción de fondos',
                'zh-eu' => 'Descontos de fundos',
                'zh-th' => 'เงินคืน',
                'zh-in' => 'फोन्ड फिनु बेट',
                'zh-jp' => 'ファンドリベート',
            ],
        ];

        if (empty($type_arr)) {
            return $type_list;
        } else {
            $result = [];
            foreach ($type_arr as $v) {
                $result[$v] = $type_list[$v];
            }
            return $result;
        }
    }


}