<?php

namespace Biz\Money;
use function GuzzleHttp\Psr7\str;

/**
 * game query
 */
//ini_set('display_errors', 1);
//
//error_reporting(E_ALL);
class MoneyQuery
{

    /**
     * 获取彩金详细
     */
    function CToDetail($data){

        $arr1 = [0=>'待审核',1=>'已通过',2=>'驳回'];
        $arr2 = ['sign'=>'签到彩金','first_save'=>'首冲彩金','upgrade'=>'晋级彩金'];
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : '';
        $uid = isset($data['uid']) ? $data['uid'] : '';
        $money_type = isset($data['money_type']) ? $data['money_type'] : ''; //资金类型

        $data_codes = lm("lottery_money_log", "Commons")->where('account_identity', $id_one)->where('id', $uid)->first();

        $data_codes['vip_name'] = lm("dc_user_grade", "Commons")->where('grade', $data_codes['grade'])->first()['name'];
        $data_codes['list']  = lm("lottery_money_log", "Commons")->where('lottery_money_type', $money_type)->where('account_identity', $id_one)->select('lottery_money_type','create_time','status','id')->orderBy('create_time','desc')->get()->toArray();
        $data=$data_codes->toArray();
        $data['status_name']=$arr1[$data_codes['status']];
        $data['money_type_name']=$arr2[$data_codes['lottery_money_type']];
        foreach ($data['list'] as $key =>$value){
            $data['list'][$key]['lottery_money_type']=$arr2[$value['lottery_money_type']];
            $data['list'][$key]['status_name']=$arr1[$value['status']];
            $data['list'][$key]['status']=$value['status'];

        }

        return $data;
    }

    /**
     * cToUpgrade
     * @param $data
     * @return array
     * 由 ikeke 修改于2018-12-10 修改内容：数据输出时的结构对于 APP 端不友好解析不出来
     */
    function cToUpgrade($data){

        $obj_money_log=lm("lottery_money_log", "commons");
        $arr1 = [0=>'待审核',1=>'已通过',2=>'驳回'];

        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $create_time = isset($data['create_time']) ? $data['create_time'] : '';
        $page = isset($data['page']) ? $data['page'] : '1';
        $where = '';

        $time = date("Y-m-d 00:00:00",strtotime($create_time));
        $timeday= date("Y-m-d 23:59:59",strtotime($create_time));

        $yesterday1= date("Y-m-d 00:00:00",strtotime("-1 day",strtotime($create_time)));
        $yesterday2= date("Y-m-d 23:59:59",strtotime("-1 day",strtotime($create_time)));

        $tomorrow1= date("Y-m-d 00:00:00",strtotime("1 day",strtotime($create_time)));
        $tomorrow2= date("Y-m-d 23:59:59",strtotime("1 day",strtotime($create_time)));
        if (preg_match('/^(\d{4}-\d{2}-\d{2})?$/',$create_time)){
            $where .="create_time >= '{$time}' and create_time <= '{$timeday}'";
        }else{
            return -5005;
        }

        $where .=" AND account_identity='{$id_one}'";


        $list = 10;

        $first = ($page - 1) * $list;

        $row =$obj_money_log->orderBy('create_time', 'desc')->whereRaw($where)->offset($first)->select('lottery_money_name','money','status','create_time','id','lottery_money_type')->limit($list)->get();

        if (!$row) {
            return -5004;
        }
        $rows['lists'] = $row->toArray();

        foreach($rows['lists'] as $key =>$value){

            $rows['lists'][$key]['status_name']=$arr1[$value['status']];

        }
        //前一天 和 后一天
        $yesterday ="account_identity='{$id_one}' AND create_time >'{$yesterday1}' AND create_time <= '{$yesterday2}'";
        $tomorrow="account_identity='{$id_one}' AND create_time >= '{$tomorrow1}' AND create_time <= '{$tomorrow2}'";

        //统计
        $where_s = "lottery_money_type ='sign' AND account_identity='{$id_one}' AND {$where}";
        $where_f = "lottery_money_type ='first_save' AND account_identity='{$id_one}' AND {$where}";
        $where_u = "lottery_money_type ='upgrade' AND account_identity='{$id_one}' AND {$where}";

        //前一天 和 后一天
        $rows['yesterdayCount']=$obj_money_log->whereRaw($yesterday)->sum('money');
        $rows['tomorrow']=$obj_money_log->whereRaw($tomorrow)->sum('money');


        $rows['countS']=$obj_money_log->whereRaw($where)->sum('money');

        $rows['signCount']=$obj_money_log->whereRaw($where_s)->sum('money');
        $rows['firstCount']=$obj_money_log->whereRaw($where_f)->sum('money');
        $rows['upgradeCount']=$obj_money_log->whereRaw($where_u)->sum('money');

        if ($rows['lists']){
            $rows['is_k']=1;
        }else{
            $rows['is_k']=0;
        }

      return $rows;

    }

    /*
            * 账号明细记录
    */
    function Winning($data)
    {
        $time = date("Y-m-d 00:00:00",time());
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $status = isset($data['status']) ? $data['status'] : ''; //资金状态
        $money_type = isset($data['trade_type']) ? $data['trade_type'] : ''; //资金类型
        $page = isset($data['page']) ? $data['page'] : '1'; //资金类型
        $money_time = isset($data['money_time']) ? $data['money_time'] : ''; //添加时间
        $field = isset($data['field']) ? $data['field'] : 'money_time'; //排序字段
        $orderby = isset($data['orderby']) ? $data['orderby'] : 'desc'; //排序
        if (empty($id_one)) {
            return -4010;
        }
        $arrmt = explode('|', $money_type);
        if(isset($arrmt[1])){
            $money_type = $arrmt[1];
        }
        $arr = [ //向数据库追加数组  然后循环出来
            'trade_type' => $money_type,
            'status' => $status,
            'account_identity' => $id_one,
        ];
        $where = 'status = 1';
        $timeday= date("Y-m-d 23:59:59");
        $week=date("Y-m-d 23:59:59",strtotime("last week"));
        $month=date("Y-m-d 23:59:59",strtotime("last month"));
        $twomonth=date("Y-m-d 23:59:59",strtotime("-0 year -2 month -0 day"));
        $sixmonth=date("Y-m-d 23:59:59",strtotime("-0 year -6 month -0 day"));

        if(is_array($money_time) && count($money_time)==2){
            $time = date('Y-m-d 00:00:00',strtotime($money_time[0]));
            $timeday = date('Y-m-d 23:59:59',strtotime($money_time[1]));
            $where .=" AND money_time >='{$time}' AND money_time <= '{$timeday}'";
        }else if(is_array($money_time) && count($money_time)==1 && !empty($money_time[0])){
            $time = date('Y-m-d 00:00:00',strtotime($money_time[0]));
            $timeday = date('Y-m-d 23:59:59',strtotime($money_time[0]));
            $where .=" AND money_time >='{$time}' AND money_time <= '{$timeday}'";
        }else if (!empty($money_time)){
            switch ($money_time){
                case 1:
                    $where .=" AND money_time >='{$time}' AND money_time < '{$timeday}'";
                    break;
                case 2:
                    $where .=" AND money_time >= '{$week}' and money_time < '{$time}'";
                    break;
                case 3:
                    $where .=" AND money_time >='{$month}' and money_time < '{$time}'";
                    break;
                case 4:
                    $where .=" AND money_time >='{$twomonth}' and money_time < '{$time}'";
                    break;
                case 5:
                    $where .=" AND money_time >='{$sixmonth}' and money_time < '{$time}'";
                    break;
                default:
                    break;
            }
        }
        foreach ($arr as $key => $value) {
            //循环数组
            if($key=='trade_type' && !empty($value)){
                $where .= " AND {$key} in ({$value}) "; //获取值
            }else if ($value != '' && $key != 'a.id' && $key != 'b.id') { //判断条件
                $where .= " AND {$key}='{$value}'"; //获取值
            }
        }
        $where = str_replace('19-1,19-2', '19', $where);
        $where = str_replace('19-1', '19', $where);
        $where = str_replace('19-2', '19', $where);

        $list = 20;
        //获取总页数

        //return $where;

        $count_list = lm("money_details", "commons")->whereRaw($where)->count();
        $count_page = ceil($count_list / $list);
        $first = ($page - 1) * $list;
        $rows = lm("money_details", "commons")
            ->orderBy('money_time', 'desc')->whereRaw($where)->offset($first)->limit($list)->orderby($field,$orderby)->get();
        if (!$rows) {
            return -5004;
        }
        $rows = $rows->toArray();

        $money_type = $this->GetMonetType();
        $Winning = $this->GetStatus();

        foreach ($Winning as $key => $v) {
            foreach ($rows as $k => $val) {
                if ($val['status'] == $key) {
                    $val['is_status']=$val['status'];
                    $val['status'] = lang()->get($v);
                    $rowr[] = $val;
                }
            }
        }
        foreach ($rowr as $k => $v) {
            if(in_array($v['trade_type'], array(1,2,3))){
                $buyinfo = lm('Money_buy','Commons')->select('game_name')->where('order_id',$v['trade_id'])->first();
                if(!$buyinfo || count($buyinfo->toArray())<1){
                    $buyinfo = lm('SixMoney_buy','Commons')->select('game_name')->where('order_id',$v['trade_id'])->first();
                    if($buyinfo && isset($buyinfo->game_name))$v['gname'] = $buyinfo->game_name;
                }else{
                    $v['gname'] = $buyinfo->game_name;
                }
            }

            foreach ($money_type as $key => $val) {
                if ($v['trade_type'] == $key) {
                    $v['trade_type_id'] = $v['trade_type'];
                    if($v['trade_type']==19){
                        if($v['money_type']==1){
                            $v['trade_type'] = '额度转入';
                        }else{
                            $v['trade_type'] = '额度转出';
                        }
                    }else{
                        $v['trade_type'] = lang()->get($val['name']);
                    }

                    if($v['money_type']==1){
                        $v['money'] = '+'. $v['money'];
                    }else{
                         $v['money'] = '-'. $v['money'];
                    }
                    $ro[] = $v;
                }

            }
        }
        return $ro;

    }

    /*统计账户分类总额*/
    public function AccountSum($data){
        $time = date("Y-m-d 00:00:00",time());
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $money_type = isset($data['trade_type']) ? $data['trade_type'] : ''; //资金类型
        $page = isset($data['page']) ? $data['page'] : '1'; //资金类型
        $money_time = isset($data['money_time']) ? $data['money_time'] : ''; //添加时间
        if (empty($id_one)) {
            return -4010;
        }
        $arrmt = explode('|', $money_type);
        if(isset($arrmt[1])){
            $money_type = $arrmt[1];
        }
        $arr = [ //向数据库追加数组  然后循环出来
            'trade_type' => $money_type,
            'account_identity' => $id_one,
        ];
        $where = 'status = 1';
        $timeday= date("Y-m-d 23:59:59");
        $week=date("Y-m-d 23:59:59",strtotime("last week"));
        $month=date("Y-m-d 23:59:59",strtotime("last month"));
        $twomonth=date("Y-m-d 23:59:59",strtotime("-0 year -2 month -0 day"));
        $sixmonth=date("Y-m-d 23:59:59",strtotime("-0 year -6 month -0 day"));

        if(is_array($money_time) && count($money_time)==2){
            $time = date('Y-m-d 00:00:00',strtotime($money_time[0]));
            $timeday = date('Y-m-d 23:59:59',strtotime($money_time[1]));
            $where .=" AND money_time >='{$time}' AND money_time <= '{$timeday}'";
        }else if (!empty($money_time) && !empty($money_time[0]) && !is_numeric($money_time[0])){
            $time = date('Y-m-d 00:00:00',strtotime($money_time[0]));
            $timeday = date('Y-m-d 23:59:59',strtotime($money_time[0]));
            $where .=" AND money_time >='{$time}' AND money_time <= '{$timeday}'";
        }else if (!empty($money_time)){
            switch ($money_time){
                case 1:
                    $where .=" AND money_time >='{$time}' AND money_time < '{$timeday}'";
                    break;
                case 2:
                    $where .=" AND money_time >= '{$week}' and money_time < '{$time}'";
                    break;
                case 3:
                    $where .=" AND money_time >='{$month}' and money_time < '{$time}'";
                    break;
                case 4:
                    $where .=" AND money_time >='{$twomonth}' and money_time < '{$time}'";
                    break;
                case 5:
                    $where .=" AND money_time >='{$sixmonth}' and money_time < '{$time}'";
                    break;
                default:
                    break;
            }
        }

        foreach ($arr as $key => $value) {
            //循环数组
            if($key=='trade_type' && !empty($value)){
                $where .= " AND {$key} in ({$value}) "; //获取值
            }else if ($value != '' && $key != 'a.id' && $key != 'b.id') { //判断条件
                $where .= " AND {$key}='{$value}'"; //获取值
            }
        }

        $list = 10;
        $first = ($page - 1) * $list;
        //获取总页数
        $sql = "SELECT sum(money),trade_type,money_type FROM money_details where " . $where . " group by trade_type,money_type";
        $res = S ('DB')->select ($sql);
        $res = json_encode($res);
        $res = json_decode($res,1);

        $ttype = $this->Tradetype();
        $sum = array();
        for($i=1;$i<23;$i++){
            if($i==19){
                $sum['19-1']=0;
                $sum['19-2']=0;
            }else{
                $sum[$i]=0;
            }
        }

        foreach ($res as $k => $v) {
            if($v['trade_type']==22){
                if($v['money_type']==1){
                    $sum[$v['trade_type']] += $v['sum'];
                }else{
                    $sum[$v['trade_type']] -= $v['sum'];
                }
            }else if($v['trade_type']==19){
                $tk = $v['trade_type'] . '-' . $v['money_type'];
                $sum[$tk] = $v['sum'] + $sum[$tk];
            }else{
                $sum[$v['trade_type']] = $v['sum'] + $sum[$v['trade_type']];
            }
        }

        return $sum;
    }

    //交易类型
    private function Tradetype(){
        return array(
            '1' => '投注',
            '2' => '追号',
            '3' => '撤单',
            '4' => '中奖',
            '5' => '提现',
            '6' => '在线充值',
            '7' => '返水',
            '8' => '回水',
            '9' => '管理员扣款',
            '10' => '佣金提成',
            '11' => '后台充值',
            '12' => '活动',
            '13' => '充值赠送',
            '14' => '汇款',
            '15' => '冻结提现',
            '16' => '红包打赏',
            '19' => '额度转账',
            '19-1' => '额度转入',
            '19-2' => '额度转出',
            '22' => '代理代充',
        );
    }

    /***
     * 六合投注列表
     * @param $data
     * @return mixed
     */
    public function SixBettingRecord($data)
    {

        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $status = isset($data['status']) ? $data['status'] : ''; //资金状态
        $order_id = isset($data['order_id']) ? $data['order_id'] : ''; //资金类型
        $game_status = isset($data['game_status']) ? $data['game_status'] : ''; //资金类型
        $page = isset($data['page']) ? $data['page'] : '1'; //资金类型
        //return $page;
        $play_num = "";
        if (empty($id_one)) {
            return -4010;
        }

        $arr = [ //向数据库追加数组  然后循环出来
            'status' => $status,
            'account_identity' => $id_one,
            'order_id' => $order_id,
            'game_status' => $game_status,
        ];

        $where = '1 = 1';
        foreach ($arr as $key => $value) {
            //循环数组
            if ($value != '' && $key != 'a.id' && $key != 'b.id') { //判断条件
                $where .= " AND {$key}='{$value}'"; //获取值
            }
        }

        $list = 10;
        //获取总页数
        $count_list = lm("sixMoney_buy", "commons")->whereRaw($where)->count();
        $count_page = ceil($count_list / $list);
        $first = ($page - 1) * $list;

        $code_data = lm("sixMoney_buy", "commons")
            ->whereRaw($where)->orderBy('money_time', 'desc')
            ->offset($first)->limit($list)->get();
        if (!$code_data) {
            return -5004;
        }
        $code_data = $code_data->toArray();

        foreach ($code_data as $k=>$v){
            $data_codes = lm($v['game_name'], "Commons")->select('status')->where('info_no', $v['game_no'])->first();
            if ($data_codes){
                $data_codes=$data_codes->toArray();
                $code_data[$k]['gamed_status']=$data_codes['status'];
            }
        }

        $Winning = $this->GetMoneyStatus();
        $Status = $this->GetWinStatus();
        foreach ($code_data as $k => $val) {
            $val['game_type'] = lang()->get($val['game_name']);
            foreach ($Winning as $key => $v) {
                //return $val['status'];
                if ($val['status'] == $key) {
                    $val['status'] = lang()->get($v);
                    $row[] = $val;
                }
            }
        }

        foreach ($Status as $key => $v) {
            foreach ($row as $k => $val) {
                if ($val['game_status'] == $key) {
                    $val['game_status'] = lang()->get($v);
                    $index = $val['id'];
                    $rowy[$index] = $val;
                    //$aa[]=$val;
                }

            }
        }

        rsort($rowy);

        return $rowy;

    }


    /*
    * 投注记录
    */
    public function BettingRecord($data)
    {

        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $status = isset($data['status']) ? $data['status'] : ''; //资金状态
        $order_id = isset($data['order_id']) ? $data['order_id'] : ''; //资金类型
        $game_status = isset($data['game_status']) ? $data['game_status'] : ''; //资金类型
        $game_name = isset($data['game_name']) ? $data['game_name'] : ''; //资金类型
        $page = isset($data['page']) ? $data['page'] : '1'; //资金类型
        //return $page;
        $play_num = "";
        if (empty($id_one)) {
            return -4010;
        }

        $arr = [ //向数据库追加数组  然后循环出来
            'status' => $status,
            'account_identity' => $id_one,
            'order_id' => $order_id,
            'game_status' => $game_status,
            'game_name' => $game_name,
        ];
        $account = lm("game_type", "commons");
        $game = $account->where("status", "=", "1")->get()->toArray();

        //return $game;
        $where = '1 = 1';

        foreach ($arr as $key => $value) {
            //循环数组
            if ($value != '' && $key != 'a.id' && $key != 'b.id') { //判断条件
                $where .= " AND {$key}='{$value}'"; //获取值
            }
        }

        //return $where;
        //$code_data = lm("money_buy", "commons")->whereRaw($where)->get();

        $list = 10;
        //获取总页数
        $count_list = lm("money_buy", "commons")->whereRaw($where)->count();
        $count_page = ceil($count_list / $list);
        $first = ($page - 1) * $list;
        //$code_datas = $accountd->orderBy('money_time', 'desc')->whereRaw($where)->offset($first)->limit($list)->get();

        $code_data = lm("money_buy", "commons")
            ->whereRaw($where)->orderBy('money_time', 'desc')
            ->offset($first)->limit($list)->get();
        if (!$code_data) {
            return -5004;
        }
        $code_data = $code_data->toArray();

        $Winning = $this->GetMoneyStatus();
        $Status = $this->GetWinStatus();
        foreach ($code_data as $k => $val) {
            $val['game_type'] = lang()->get($val['game_name']);
            foreach ($Winning as $key => $v) {
                //return $val['status'];
                if ($val['status'] == $key) {
                    $val['status'] = lang()->get($v);
                    $row[] = $val;
                }
            }
        }

        foreach ($Status as $key => $v) {
            foreach ($row as $k => $val) {
                if ($val['game_status'] == $key) {
                    $val['game_status'] = lang()->get($v);
                    $index = $val['id'];
                    $rowy[$index] = $val;
                    //$aa[]=$val;
                }

            }
        }

        rsort($rowy);

        return $rowy;

    }


    /*
    * 长龙近期投注记录
  */
    public function LongBetRecords($data)
    {
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $status = isset($data['status']) ? $data['status'] : ''; //资金状态
        $game_status = isset($data['game_status']) ? $data['game_status'] : ''; //资金类型
        $game_name = isset($data['game_name']) ? $data['game_name'] : ''; //资金类型
        $page = isset($data['page']) ? $data['page'] : '1'; //资金类型
        //return $page;
        $play_num = "";
        if (empty($id_one)) {
            return -4010;
        }

        $arr = [ //向数据库追加数组  然后循环出来
            'status' => $status,
            'account_identity' => $id_one,
            'game_status' => $game_status,
            'game_name' => $game_name,
        ];
        //$gamelist = lm("game_type", "commons")->select('name','table_name')->where("status", "=", "1")->get()->toArray();
        //print_r($gamelist);exit;
        $where = '1 = 1';

        foreach ($arr as $key => $value) {
            //循环数组
            if ($value != '' && $key != 'a.id' && $key != 'b.id') { //判断条件
                $where .= " AND {$key}='{$value}'"; //获取值
            }
        }

        $list = 10;
        //获取总页数
        $count_list = lm("money_buy", "commons")->whereRaw($where)->count();
        $count_page = ceil($count_list / $list);
        $first = ($page - 1) * $list;

        $code_data = lm("money_buy", "commons")->select('game_name','game_no','money','prize_money','game_status','order_id','money_time','status')
            ->whereRaw($where)->orderBy('money_time', 'desc')
            ->offset($first)->limit($list)->get();
        if (!$code_data) {
            return -5004;
        }
        $code_data = $code_data->toArray();
        //print_r($code_data);

        $Status = array("1" => "win", "2" => "notwin", "0" => "audit", "3" => "killorder");
        foreach ($code_data as $k => $val) {
            $code_data[$k]['game_type'] = lang()->get($val['game_name']);
            $code_data[$k]['game_status'] = $val['status']==4?'已撤单':lang()->get($Status[$val['game_status']]);
        }
        //rsort($code_data);

        return $code_data;

    }

    //即时开奖游戏记录
    public function CurBetRecord($data){
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $game_name = isset($data['game_name']) ? $data['game_name'] : ''; //资金状态

        if (empty($game_name)) {
            return "";
        }
        $play_num = "";
        if (empty($id_one)) {
            return -4010;
        }

        $code_data = lm($game_name, "commons")->orderBy('create_time', 'desc')->where('account_identity',$id_one)->get();

        if (empty($code_data)) {
            return "";
        } else {
            $code_data = $code_data->toArray();
        }

        return $code_data;
    }

    /*
    * 投注未开奖
    */
    public function NotBetRecord($data)
    {
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $game_name = isset($data['game_name']) ? $data['game_name'] : ''; //资金状态

        if (empty($game_name)) {
            return "";
        }
        $no = isset($data['no']) ? $data['no'] : ''; //资金类型
        $delstatus = isset($data['delstatus']) ? $data['delstatus'] : '1';
        $status = isset($data['status']) ? $data['status'] : '0';
        $play_num = "";
        if (empty($id_one)) {
            return -4010;
        }
        $game = new \Biz\Game\GameQuery;
        $no = $game->getNo($game_name);
        $arr = [ //向数据库追加数组  然后循环出来
            'no' => $no,
            'status' => $status,
            'account_identity' => $id_one,
            'delstatus' => $delstatus,
        ];
        $where = '1 = 1';

        foreach ($arr as $key => $value) {
            //循环数组
            if ($value != '' && $key != 'a.id' && $key != 'b.id') { //判断条件
                $where .= " AND {$key}='{$value}'"; //获取值
            }
        }

        $name = $game_name . "_buy";
        $code_data = lm($name, "commons")->orderBy('open_time', 'desc')->whereRaw($where)->get();

        if (empty($code_data)) {
            return "";
        } else {
            $code_data = lm($name, "commons")->orderBy('open_time', 'desc')->whereRaw($where)->get()->toArray();
        }

        //return $game_name;
        //var_dump($code_data);
        foreach ($code_data as $o => $v) {
            $tab_name = "bjpk10Parse";
            $nums = C()->get($tab_name);

            $data_paramt = json_decode($v['codes'], 1);

            //var_dump($data_paramt);
            //echo 1;
            if (array_key_exists("head_three", $data_paramt)) {
                $paramt = $this->CodeData($data_paramt,3,$game_name);
            } elseif (array_key_exists("head_two", $data_paramt)) {
                $paramt = $this->CodeData($data_paramt,2,$game_name);

                //return $data_paramt;
            } elseif (array_key_exists("specialthree", $data_paramt)) {
                $paramt = $this->CodesDatas($data_paramt,3,$game_name);
            } elseif (array_key_exists("fivestar", $data_paramt)) {
                $paramt = $this->CodesDatas($data_paramt,5,$game_name);
            } elseif (array_key_exists("fourstar", $data_paramt)) {
                $paramt = $this->CodesDatas($data_paramt,4,$game_name);

                //return $data_paramt;
            } elseif (array_key_exists("behindthreestar", $data_paramt)) {
                $paramt = $this->CodesDatas($data_paramt,3,$game_name);

                //return $data_paramt;
            } elseif (array_key_exists("frontthreestar", $data_paramt)) {
                $paramt = $this->CodesDatas($data_paramt,3,$game_name);

                //return $data_paramt;
            } elseif (array_key_exists("fronttwostar", $data_paramt)) {
                $paramt = $this->CodesDatas($data_paramt,2,$game_name);
                //return $data_paramt;
            } else {
                $datat = [
                    'codes' => $v['codes'],
                ];
                $paramt = $nums->change($datat,$game_name);
            }

            /*echo '<pre>';
            print_r($data_paramt);
            print_r($paramt);*/
            foreach ($paramt as $v) {
                //var_dump($v);
                $CodeDate = lang()->get($v['codeDate']);
                $play_num .= $v['codes'] . "（￥" . $v['money'] . "） ";
            }
            $code_data[$o]['num'] = count($paramt);
            $code_data[$o]['codeDate'] = $CodeDate;
            $code_data[$o]['coded'] = $play_num;
            $play_num = "";
        }
        return $code_data;
    }

    /*
    * 中奖记录
    */
    function Profit($data)
    {
        //$id_one = $_SESSION['uinfo']['account_identity'];
        //return 1111;
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        if (empty($id_one)) {
            return -4010;
        }

        $arr = [ //向数据库追加数组  然后循环出来
            'account_identity' => $id_one,
        ];
        $where = '1 = 1';

        foreach ($arr as $key => $value) {
            //循环数组
            if ($value != '' && $key != 'a.id' && $key != 'b.id') { //判断条件
                $where .= " AND {$key}='{$value}'"; //获取值
            }
        }
        $rows = lm("money_prize", "commons")->orderBy('money_time', 'desc')->whereRaw($where)->get();
        //return $rows;
        if (count($rows) != 0) {
            $rows = lm("money_prize", "commons")->orderBy('money_time', 'desc')->whereRaw($where)->get()->toArray();
            $account = lm("game_type", "commons");
            $game = $account->where("status", "=", "1")->get()->toArray();
            foreach ($rows as $k => $val) {
                foreach ($game as $v) {
                    if ($v['name'] == $val['game_name']) {
                        $tal_name = $v['table_name'] . "_buy";
                        $dat = lm($tal_name, "commons")->where("order_id", $val['buy_identity'])->first();

                        if (count($dat) != 0) {
                            $dat = lm($tal_name, "commons")->where("order_id", $val['buy_identity'])->first()->toArray();

                            $rows[$k]['no'] = $dat['no'];
                            $rows[$k]['bet_money'] = "-" . $dat['money'];
                        } else {
                            $rows[$k]['no'] = 0;
                            $rows[$k]['bet_money'] = 0;
                        }

                    }
                }

            }

        } else {
            return "";
        }

        $Winning = $this->GetStatus();

        foreach ($Winning as $key => $v) {
            foreach ($rows as $k => $val) {
                if ($val['status'] == $key) {
                    $val['status'] = lang()->get($v);
                    $val['trade_type'] = lang()->get("Winning");
                    $val['money'] = "+" . $val['money'];
                    $rowr[] = $val;
                }
            }
        }

        $len = count($rowr);
        for ($i = 0; $i < $len; $i++) {
            for ($j = $len; $j < $len - $i; $j--) {
                if ($rowr[$i]['money_time'] > $rowr[$j]['money_time']) {
                    $temp = $rowr[$i];
                    $rowr[$j] = $rowr[$i];
                    $rowr[$i] = $temp;
                }
            }
        }
        return $rowr;

    }

    //资金流水订单详情
    function MorderDetail($order_id){
        $info = lm('money_details','Commons')->where('trade_id',$order_id)->first();
        if($info && count($info->toArray())>0){
            $info = $info->toArray();
            $ttype = $this->Tradetype();
            $info['tradename'] = $ttype[$info['trade_type']];
            $info['money_time'] = date('Y-m-d H:i:s',strtotime($info['money_time']));
            $td = explode('订单号', $info['trade_desc']);
            if($info['trade_type']==22){
                if($info['money_type'] == 2)$info['trade_desc'] = str_replace('代理'.$info['account_name'].'为下级', '您为', $td[0]);
                if($info['money_type'] == 1)$info['trade_desc'] = str_replace('下级会员'.$info['account_name'], '您', $td[0]);
            }else if($info['trade_type']==12){
                if($info['money_type']==1){
                    $info['trade_desc'] = '系统为您添加活动金额：' . $info['money'] . '元。';
                }else{
                    $info['trade_desc'] = '系统为您扣除活动金额：' . $info['money'] . '元。';
                }
            }else if($info['trade_type']==13){
                $info['trade_desc'] = '系统为您充值赠送：' . $info['money'] . '元。';
            }else if($info['trade_type']==14){
                $info['trade_desc'] = '您汇款充值：' . $info['money'] . '元。';
            }else if($info['trade_type']==11){
                $info['trade_desc'] = '系统为您添加金额' . $info['money'] . '元；';
            }else if($info['trade_type']==9){
                $info['trade_desc'] = '系统为您扣除金额' . $info['money'] . '元；';
            }else{
                $td[0] = str_replace($info['account_name'], '您', $td[0]);
                $td[0] = str_replace('反水', '返水', $td[0]);
                $info['trade_desc'] = $td[0];
            }
            
            
            return $info;
        }
        return -4047;
    }

    /*
    * 提现记录
    */

    function Recharge($data)
    {

        //$id_one = $_SESSION['uinfo']['account_identity'];
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        //return $id_one;
        $status = isset($data['status']) ? $data['status'] : ''; //资金状态
        $order_id = isset($data['order_id']) ? $data['order_id'] : ''; //资金状态
        $page = isset($data['page']) ? $data['page'] : '1'; //资金类型
        if (empty($id_one)) {
            return -4010;
        }

        $arr = [ //向数据库追加数组  然后循环出来
            'status' => $status,
            'account_identity' => $id_one,
            'order_id' => $order_id,
        ];
        $where = '1 = 1';

        foreach ($arr as $key => $value) {
            //循环数组
            if ($value != '' && $key != 'a.id' && $key != 'b.id') { //判断条件
                $where .= " AND {$key}='{$value}'"; //获取值
            }
        }

        $list = 30;
        //获取总页数
        $count_list = lm("money_recharge", "commons")->whereRaw($where)->count();
        $count_page = ceil($count_list / $list);
        $first = ($page - 1) * $list;
        //$code_datas = $accountd->orderBy('money_time', 'desc')->whereRaw($where)->offset($first)->limit($list)->get();

        $rows = lm("money_recharge", "commons")
            ->whereRaw($where)->orderBy('apply_time', 'desc')
            ->offset($first)->limit($list)->get();
        if (!$rows) {
            return -5004;
        }
        $rows = $rows->toArray();

        $Winning = $this->GetStatus();

        foreach ($Winning as $key => $v) {
            foreach ($rows as $k => $val) {
                if ($val['status'] == $key) {
                    $val['statud'] = lang()->get($v);
                    $val['trade_type'] = lang()->get("Recharge");
                    $val['money'] = "+" . $val['money'];
                    $index = strtotime($val['apply_time']);
                    $rowr[$index] = $val;
                }
            }
        }
        rsort($rowr);
        return $rowr;

    }

    /*
    * 充值记录
    */

    function Withdrawals($data)
    {
        //$id_one = $_SESSION['uinfo']['account_identity'];
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $status = isset($data['status']) ? $data['status'] : ''; //资金状态
        $order_id = isset($data['order_id']) ? $data['order_id'] : ''; //资金状态
        $page = isset($data['page']) ? $data['page'] : '1'; //资金类型
        //return 1;
        if (empty($id_one)) {
            return -4010;
        }

        $arr = [ //向数据库追加数组  然后循环出来
            'status' => $status,
            'account_identity' => $id_one,
            'order_id' => $order_id,
        ];
        $where = '1 = 1';

        foreach ($arr as $key => $value) {
            //循环数组
            if ($value != '' && $key != 'a.id' && $key != 'b.id') { //判断条件
                $where .= " AND {$key}='{$value}'"; //获取值
            }
        }

        $list = 30;
        //获取总页数
        $count_list = lm("money_take", "commons")->whereRaw($where)->count();
        $count_page = ceil($count_list / $list);
        $first = ($page - 1) * $list;
        //$code_datas = $accountd->orderBy('money_time', 'desc')->whereRaw($where)->offset($first)->limit($list)->get();

        $rows = lm("money_take", "commons")
            ->whereRaw($where)->orderBy('apply_time', 'desc')
            ->offset($first)->limit($list)->get();
        if (!$rows) {
            return -5004;
        }
        $rows = $rows->toArray();

        //return $rows;

        $Winning = $this->GetStatus();

        foreach ($Winning as $key => $v) {
            foreach ($rows as $k => $val) {
                if ($val['status'] == $key) {
                    $val['status'] = lang()->get($v);
                    $val['trade_type'] = lang()->get("Withdrawals");
                    $val['money'] = "-" . $val['money'];
                    $index = strtotime($val['apply_time']);
                    $rowr[$index] = $val;
                }
            }
        }
        rsort($rowr);
        return $rowr;

    }

    //充值记录新
    public function saveMoneyRecord($data){
        //todo 建议按年计算数据
        $time = date("Y-m-d 00:00:00",time());
        //$id_one = $_SESSION['uinfo']['account_identity'];
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        //return $id_one;
        $status = isset($data['status']) ? $data['status'] : ''; //资金状态
        $order_id = isset($data['order_id']) ? $data['order_id'] : ''; //资金状态
        $page = isset($data['page']) ? $data['page'] : '1'; //资金类型
        $money_time = isset($data['money_time']) ? $data['money_time'] : ''; //添加时间
        $time = isset($data['time']) ? $data['time'] : ''; //添加时间
        if (empty($id_one)) {
            return -4010;
        }
        if (!empty($time)) {//qtx 2018-12-20
            $newtime = explode('~',$time);
            if(count($newtime) ==2){
                $new_time1 = $newtime[0];
                $new_time2 = $newtime[1];
            }else{
                $new_time1 = $newtime[0];
                $new_time2 = $newtime[0];
            }
        }
        $arr = [ //向数据库追加数组  然后循环出来
            'status' => $status,
            'account_identity' => $id_one,
            'order_id' => $order_id
        ];
        $where = '1 = 1';
        if(!empty($new_time1) && !empty($new_time2)){
            //$where .= " AND complete_time >= '".$new_time1." 00:00:00' AND complete_time <='".$new_time2." 23:59:59'"; //添加时间
            $where .= " AND apply_time >= '".$new_time1." 00:00:00' AND apply_time <='".$new_time2." 23:59:59' AND recharge_type in('汇款','汇款赠送','活动充值','后台充值','后台充值赠送','在线充值','在线充值赠送')"; //添加时间
        }
        //dump($where);
        $timeday= date("Y-m-d 23:59:59");
        $week=date("Y-m-d 23:59:59",strtotime("last week"));
        $month=date("Y-m-d 23:59:59",strtotime("last month"));
        $twomonth=date("Y-m-d 23:59:59",strtotime("-0 year -2 month -0 day"));
        $sixmonth=date("Y-m-d 23:59:59",strtotime("-0 year -6 month -0 day"));
        if (!empty($money_time)){
            switch ($money_time){
                case 1:
                    $where .=" AND apply_time >='{$time}' AND apply_time < '{$timeday}'";
                    break;
                case 2:
                    $where .=" AND apply_time >= '{$week}' and apply_time < '{$time}'";
                    break;
                case 3:
                    $where .=" AND apply_time >='{$month}' and apply_time < '{$time}'";
                    break;
                case 4:
                    $where .=" AND apply_time >='{$twomonth}' and apply_time < '{$time}'";
                    break;
                case 5:
                    $where .=" AND apply_time >='{$sixmonth}' and apply_time < '{$time}'";
                    break;
                default:
                    break;
            }
        }

        foreach ($arr as $key => $value) {
            //循环数组
            if ($value != '' && $key != 'a.id' && $key != 'b.id') { //判断条件
                $where .= " AND {$key}='{$value}'"; //获取值
            }

        }
        $rows = lm("money_recharge", "commons")
            ->whereRaw($where)
            ->orderBy('apply_time', 'desc')
            ->get();
        if (!$rows) {
            return -5004;
        }
        $rows = $rows->toArray();
        $month  =  $total   =  0;
        $year  =  0;
        $ym = 0;
        //2019-1-1 anton liu 修改
        $months = [];
        $statusType = $this->GetStatus();
        foreach ($rows as $k => $v){
            $ym = date('Ym',strtotime($v['apply_time']));
            $month = date('m',strtotime($v['apply_time']));
            $year = date('Y',strtotime($v['apply_time']));
            if($v['status'] == 1){
                $months[$ym]['total'] +=$v['money'];
            }
            $months[$ym]['month']   = $month;
            $months[$ym]['year']   = $year;
            $months[$ym]['ym']   = $year . '年' . intval($month);
            $months[$ym]['sort']   = intval($ym);
            $v['is_status'] = $v['status'];
            $v['status']    =  lang()-> get($statusType[$v['status']]);
            $v['trade_type']    =  lang()-> get("Withdrawals");
            $v['pass_time']    =  $v["apply_time"];
            $months[$ym]['info'][]   =$v;
        }
        array_multisort(array_column($months,'sort'), SORT_DESC,$months);
        return $months;
    }

    //取款记录新
    public function takeMoneyRecord($data){

        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $status = isset($data['status']) ? $data['status'] : ''; //资金状态
        $order_id = isset($data['order_id']) ? $data['order_id'] : ''; //资金状态
        $time = isset($data['time']) ? $data['time'] : ''; //添加时间
        if (empty($id_one)) {
            return -4010;
        }

        $arr = [ //向数据库追加数组  然后循环出来
            'status' => $status,
            'account_identity' => $id_one,
            'order_id' => $order_id,

        ];
        if (!empty($time)) {//qtx 2018-12-20
            $newtime = explode('~',$time);
            if(count($newtime) ==2){
                $new_time1 = $newtime[0];
                $new_time2 = $newtime[1];
            }else{
                $new_time1 = $newtime[0];
                $new_time2 = $newtime[0];
            }
        }
        $where = '1 = 1';
        if(!empty($new_time1) && !empty($new_time2)){
            $where .= " AND apply_time >= '".$new_time1." 00:00:00' AND apply_time <'".$new_time2." 23:59:59'"; //添加时间
        }
        //$where = "apply_time > '".date('Y')."-01-01 00:00:00'";
        foreach ($arr as $key => $value) {
            //循环数组
            if ($value != '' && $key != 'a.id' && $key != 'b.id') { //判断条件
                $where .= " AND {$key}='{$value}'"; //获取值
            }
        }

        //todo 建议按年计算数据

        $rows = lm("money_take", "commons")->whereRaw($where)->orderBy('id', 'desc')->get();
        if (!$rows) {
            return -5004;
        }
        $rows = $rows->toArray();

        $month  =  $total   =   $status =0;

        $statusType = $this->GetStatus();

        //分月
        $res =[];

        foreach($rows as $r){
            //$m = $r['apply_time']?date('Y年n',strtotime($r['apply_time'])):date('Y年n',strtotime($r['apply_time']));
            $m = $r['apply_time']?date('n',strtotime($r['apply_time'])):date('n',strtotime($r['apply_time']));
            $res["$m "][]=$r;
        }
        $_data=[];
        foreach ($res as $d=>$x){
            $_data[$d]['month']=date('Y',strtotime($x[0]['apply_time'])).'年'.$d.'月';
            foreach ($x as $r){
                $_data[$d]['total'] +=$r['status']==1?$r['money']:0;
                $r['is_status'] =  $r['status'] ;
                $r['status']    =  lang()-> get($statusType[$r['status']]);
                $r['trade_type']    =  lang()-> get("Withdrawals");
                $_data[$d]['info'][]=$r;
            }
        }
//
//        foreach ($rows as $v){
//            if($month==date('m',strtotime($v['pass_time']))&&$status==1){
//                $total  +=$v['money'];
//            }else{
//                $total =$v['money'];
//                $month =$v['pass_time']?date('m',strtotime($v['pass_time'])):date('m',strtotime($v['apply_time']));
//                $status =   $v['status'];
//            }
//
//            $retarray[$month]['total']   = $total;
//            $retarray[$month]['month']   = $month;
//            $v['is_status'] =  $v['status'] ;
//            $v['status']    =  lang()-> get($statusType[$v['status']]);
//            $v['trade_type']    =  lang()-> get("Withdrawals");
//            $v['pass_time']    =  $v["pass_time"];
//            $retarray[$month]['info'][]   =$v;
//        }
//
//       rsort($retarray);
        if(count($_data)>0){
            return $_data;
        }else{
            //Render('',-5004);
            return -5004;
        }


    }
    /*
    * 回水记录
    */
    function Backwater($data)
    {
        //$id_one = $_SESSION['uinfo']['account_identity'];
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $status = isset($data['status']) ? $data['status'] : ''; //资金状态
        if (empty($id_one)) {
            return -4010;
        }

        $arr = [ //向数据库追加数组  然后循环出来
            'status' => $status,
            'account_identity' => $id_one,
        ];
        $where = '1 = 1';

        foreach ($arr as $key => $value) {
            //循环数组
            if ($value != '' && $key != 'a.id' && $key != 'b.id') { //判断条件
                $where .= " AND {$key}='{$value}'"; //获取值
            }
        }
        $rows = lm("money_return", "commons")->whereRaw($where)->get();

        if (count($rows) != 0) {
            $rows = lm("money_return", "commons")->whereRaw($where)->get()->toArray();
        } else {
            return "";
        }

        $Winning = $this->GetStatus();

        foreach ($Winning as $key => $v) {
            foreach ($rows as $k => $val) {
                if ($val['status'] == $key) {
                    $val['status'] = lang()->get($v);
                    $val['trade_type'] = lang()->get("backwater");
                    $val['money'] = "+" . $val['money'];
                    $rowr[] = $val;
                }
            }
        }
        return $rowr;

    }

    /*
     * 投注详情显示
    */
    function Details($data)
    {
        $play_num = "";
        $order_id = isset($data['order_id']) ? $data['order_id'] : '';
        $game_name = isset($data['game_name']) ? $data['game_name'] : '';
        if (empty($order_id)) {
            return -2001;
        }
        if($game_name=='zbdetail'){
            $dinfo = lm('Money_buy','Commons')->where('order_id',$order_id)->first();
            if(!$dinfo || count($dinfo->toArray())<1){
                $dinfo = lm('SixMoney_buy','Commons')->where('order_id',$order_id)->first();
            }
            if(!$dinfo || count($dinfo->toArray())<1)return -2138;
            $game_name = $dinfo->game_name;
        }
        $account = lm("game_type", "commons");
        $game = $account->where("status", "=", "1")->get()->toArray();
        foreach ($game as $v) {
            if ($v['table_name'] == $game_name) {
                //注单信息
                $account = lm($v['table_name'] . "_buy", "commons");
                $identity_no = $account->where("order_id", $order_id)->first();//投注表当前订单信息
                if (count($identity_no) != 0) {
                    $identity_no = $identity_no->toArray();
                } else {
                    return "";
                }

                //当期游戏信息
                $value_no = lm($v['table_name'], "commons")->where("identity", $identity_no['game_identity'])->first();

                if($value_no){
                    $value_no=$value_no->toArray();
                }
                $value_no['name'] = $v['table_name'];
                $value_no['betstatus'] = $identity_no['status'];
                if ($identity_no['status'] != '0') {
                    if($v['table_name'] == 'sixlottery' || $v['table_name'] == 'sfsixlottery'){
                        $dat = lm('sixMoney_buy', "commons")->where('order_id', $identity_no['order_id'])->first();
                    }else{
                        $dat = lm('money_buy', "commons")->where('order_id', $identity_no['order_id'])->first();
                    }

                    if (count($dat) != 0) {
                        $dat = $dat->toArray();
                        $value_no['win_money'] = $dat['prize_money'];
                    } else {
                        $value_no['win_money'] = 0;
                    }
                }

                $data_codes = lm('Sixlottery', "Commons")->select('status')->where('info_no', $identity_no['no'])->first();
                if ($data_codes){
                    $data_codes=$data_codes->toArray();
                    $value_no['gamed_status']=$data_codes['status'];
                }
                $sfsixdata_codes = lm('Sfsixlottery', "Commons")->select('status')->where('info_no', $identity_no['no'])->first();
                if ($sfsixdata_codes){
                    $sfsixdata_codes=$sfsixdata_codes->toArray();
                    $value_no['gamed_status']=$sfsixdata_codes['status'];
                }
                //print_r($dat);

                $Winning = $this->GetWinStatus();

                foreach ($Winning as $k => $t) {
                    if ($identity_no['delstatus'] == 1) {
                        if ($identity_no['status'] == $k) {
                            //return $t;
                            $value_no['whetherwin'] = lang()->get($t);
                        }
                    } else {
                        $value_no['whetherwin'] = lang()->get($Winning[3]);
                    }
                }

                $back = lm('money_back', "Commons")->where('buy_identity', $order_id)->first();
                if (!empty($back)) {

                    $back = lm('money_back', "Commons")->where('buy_identity', $order_id)->first()->toArray();
                    $value_no['back_money'] = $back['money'];

                }

                $value_no['icon'] = $v['icon'];
                $value_no['link'] = $v['link'];
                $value_no['game_type'] = $v['name'];
                $value_no['order_id'] = $identity_no['order_id'];
                $value_no['money'] = $identity_no['money'];
                $value_no['open_time'] = $identity_no['open_time'];

                $tab_name = "bjpk10Parse";
                $nums = C()->get($tab_name);
                //print_r($dat);
               // print_r($value_no);
                $prizecodes = (isset($dat['prize']))?json_decode($dat['prize'],1):'';//开奖号码

                $data_paramt = json_decode($identity_no['codes'], 1);//投注号码

                //计算可重复号码组合注数
                $regrouptype = $this->reGrouptype();
                $grouparr = array();
                foreach ($data_paramt as $key => $value) {
                    if(in_array($key, $regrouptype)){
                        foreach ($value as $sk => $sv) {
                            $seatarr = explode('_',$sk);
                            $val2=$sv;
                            if(isset($val2['settings'])){
                                unset($val2['settings']);
                            }
                            if(isset($grouparr[$seatarr[0]])){
                                $grouparr[$seatarr[0]] += count(val2);
                            }else{
                                $grouparr[$seatarr[0]] = count(val2);
                            }
                        }
                    }
                    foreach ($value as $ke => $val) {
                        foreach ($val as $k => $v) {
                            if($k ==='settings'){
                                $value_no['multiple'] = $v['multiple'];
                            }

                        }
                    }
                }

                $pgarr = array();
                if(!empty($prizecodes)){
                    foreach ($prizecodes as $key => $value) {
                        if(in_array($key, $regrouptype)){
                            foreach ($value as $sk => $sv) {
                                $seatarr = explode('_',$sk);
                                $val2 = $sv;
                                if (isset($val2['settings'])) {
                                    unset($val2['settings']);
                                }
                                if(isset($pgarr[$seatarr[0]])){
                                    $pgarr[$seatarr[0]] += count(val2);
                                }else{
                                    $pgarr[$seatarr[0]] = count(val2);
                                }
                            }
                        }
                    }
                }

                $paramt = $this->CodesDetails($data_paramt,$game_name,$identity_no);

                //玩法分类注单金额
                $ptmoney = array();

                $prize_amt = $this->PrizeDetails($prizecodes,$game_name);

                $parr = array();
                if(is_array($prize_amt) && count($prize_amt)>0){
                    foreach ($prize_amt as $k => $v) {
                        $parr[$v['codeDate']][] = $v['codes'];
                    }
                }

                if (is_array($paramt)){
                    foreach ($paramt as $k=>$v){
                        $ptmoney[$v['codeDate']] = (isset($ptmoney[$v['codeDate']]))?($ptmoney[$v['codeDate']]+$v['money']):$v['money'];
                        if(in_array($v['codes'], $parr[$v['codeDate']])){
                            $paramt[$k]['isp'] = '中奖';
                        }else if($dat['game_status']==0){
                            $paramt[$k]['isp'] = '待开奖';
                        }else{
                            $paramt[$k]['isp'] = '未中奖';
                        }
                        if ($v['codeDate'] == 'series_twoborn' || $v['codeDate'] == 'series_fiveborn' || $v['codeDate'] == 'series_fourborn' || $v['codeDate'] == 'series_threeborn') {
                            $paramt[$k]['codes']=rtrim($v['codes'], ',');
                        }
                    }
	
					$error_game_arr       = ['ssc','pk10'];
                    $right_lang	=	['mix'=>'大小单双'];
                    $listdata   =   [];
                    foreach ($paramt as $i=>$v) {
                        $listdata[$i]=$v;
                        $chcodes = $this->ChangeLan($game_name,$v['codes']);
                        $chcodes = empty($chcodes)?$v['codes']:$chcodes;
                        $play_num .= $chcodes . "（￥" . $v['money'] . "）" . '    ' . $v['isp'] . '<br/>';
                        $CodeDate = $v['codeDate'];
	
						$CodeDates	=	lang($game_name)->get($v['codeDate']);
						//语言包修正---blues
                        foreach ($error_game_arr as $e){
                        	if(strpos($game_name,$e)!==false){
								$CodeDates = $right_lang[$v['codeDate']]??$CodeDates;
							}
						}
                        
                        $value_no['ptypename'] = $CodeDates;
                        if (empty($value_no['CodeDates'])) {
                            $n = explode('-',$chcodes);
                            if(empty($n[0])){
                                $value_no['CodeDates'] =$chcodes;
                            }else{
                                $value_no['CodeDates'] = $n[0];
                            }

                        }
                    }
                }else{
                    $CodeDate='';
                    $CodeDates='';
                }

                if (array_key_exists("general_pass", $data_paramt) || array_key_exists("join_born", $data_paramt)) {
                    $value_no['num'] = 1;
                }else{
                    if(empty($grouparr)){
                        $value_no['num'] = count($paramt);
                    }else{
                        $value_no['num'] = 1;
                        foreach($grouparr as $k=>$v){
                            $value_no['num'] *= $v;
                        }
                    }

                }
                if(count($data_paramt) > 1){
                    $value_no['ptypename'] = '混合';
                    $value_no['CodeDates'] = '混合';
                }
                $value_no['details'] = $play_num;
                $value_no['showlist'] = $listdata;
                $value_no['opencodes'] = $data_paramt;
                $value_no['CodeDate'] = $CodeDate;
                //$value_no['CodeDates'] = $CodeDates;
            }
        }
        $value_no['ptmoney'] = $ptmoney;
        unset($value_no['prizes']);
        return $value_no;
    }

    private function ChangeLan($gamename,$codes){
        $codes = is_array($codes)?$codes:explode(',', $codes);
        $res = array();
        foreach ($codes as $value) {
            $res[] = is_numeric($value)?$value:lang($gamename)->get($value);
        }
        return implode(',', $res);
    }

    //可重复号码玩法组合
    private function reGrouptype(){
        return array(
            'fronttwostar',
            'fourstar',
            'frontthreestar',
            'behindthreestar',
            'fivestar'
        );
    }

    /*
     * PC投注记录
    */
    public function PcBettingRecord($data,$c=-1)
    {
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $time1 = isset($data['time1']) ? $data['time1'] : ''; //资金状态
        $time2 = isset($data['time2']) ? $data['time2'] : ''; //资金类型
        $no = isset($data['no']) ? $data['no'] : ''; //资金类型
        //return $no;
        $game_type = isset($data['game']) ? $data['game'] : ''; //资金类型
        $status = isset($data['status']) ? $data['status'] : '';
        $money_time = isset($data['money_time']) ? $data['money_time'] : '';
        $id = isset($data['id']) ? $data['id'] : '';
        $order_id = isset($data['order_id']) ? $data['order_id'] : '';
        $page = isset($data['page']) ? $data['page'] : 2;
        $arrd = [ //向数据库追加数组  然后循环出来
            'a.open_time' => $time1,
            'b.open_time' => $time2,
            'game_no' => $no,
            'id' => $id,
            'order_id' => $order_id,
            'account_identity' => $id_one,
            'status' => $status,
            'game_name' => $game_type,
            'money_time' => $money_time,
        ];

        if (empty($id_one)) {
            return -4010;
        }
        // $account = lm("game_type", "commons");
        // $game = $account->where("status", "1")->get()->toArray();
        //return $game;
        $play_num = "";
        $where = '1 = 1';

        $accountd = lm('money_buy', "commons");
        foreach ($arrd as $key => $value) {
            //循环数组
            if ($value != '' && $key != 'a.open_time' && $key != 'b.open_time') { //判断条件
                $where .= " AND {$key}='{$value}'"; //获取值
            }
            if ($value != '' && $key == 'a.open_time') {
                $where .= " AND money_time>='{$time1}'";
            }
            if ($value != '' && $key == 'b.open_time') {
                $where .= " AND money_time<='{$time2}'";
            }
        }
        //return $where;
        $list = 10;
        //统计总额
        $total = $accountd->whereRaw($where)->sum('money');
        if($c==1){
            $countMoney = empty($total)?0:$total;
            return $countMoney;
        }
        //获取总页数
        $count_list = $accountd->whereRaw($where)->count();
        $count_page = ceil($count_list / $list);
        $first = ($page - 1) * $list;
        $code_datas = $accountd->orderBy('money_time', 'desc')->whereRaw($where)->offset($first)->limit($list)->get();//注单信息
        if (!empty($code_datas)) {
            $code_data = $code_datas->toArray();
        } else {
            return "";
        }
        //return $code_data;
        foreach ($code_data as $k => $v) {
            $data_codes = lm($v['game_name'], "Commons")->select('status','codes', 'extra')->where('info_no', $v['game_no'])->first();
            $v['game_type'] = lang()->get($v['game_name']);
            if (!empty($data_codes)) {
                //开奖派奖号码
                if ($v['game_name'] == "xy28" || $v['game_name'] == "jnd28"|| $v['game_name'] == "gpxy28" || $v['game_name'] == "gpjnd28" || $v['game_name'] == "xjp28" || $v['game_name'] == "hs28" || $v['game_name'] == "tw28" || $v['game_name'] == "dj28"|| $v['game_name'] == "one28") {
                    $v['wing_codes'] = $data_codes->extra;
                } else {
                    $v['wing_codes'] = $data_codes->codes;//
                }
                $v['gamed_status'] = $data_codes->status;
            }
            $datu[] = $v;
        }

        if (empty($datu)) {
            return "";
        }

        foreach ($datu as $key => $val) {
            if ($val['game_name'] == "xy28" || $val['game_name'] == "jnd28" || $val['game_name'] == 'hs28' || $val['game_name'] == "gpxy28" || $val['game_name'] == "gpjnd28" || $val['game_name'] == "tw28" || $val['game_name'] == "dj28" || $val['game_name'] == "xjp28"|| $val['game_name'] == "one28") {
                $params = json_decode($val['wing_codes'], 1);
                $datu[$key]['wing_codes'] = $params['code'];

            }
        }

        foreach ($datu as $val){
            $rowt[]=$this->dataChange($val,$game_type);
        }
        $dat = [
            'total'=> $total,
            'data' => $rowt,
            'count_page' => $count_page,
            'page' => $page,
            //'where' => $datu,

        ];
        return $dat;
        // return 1;

    }


    /*
     * PC六合投注记录
    */
    public function PcSixlotteryRecord($data)
    {
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $time1 = isset($data['time1']) ? $data['time1'] : ''; //资金状态
        $time2 = isset($data['time2']) ? $data['time2'] : ''; //资金类型
        $no = isset($data['no']) ? $data['no'] : ''; //资金类型
        //return $no;
        $game_type = isset($data['game']) ? $data['game'] : ''; //资金类型
        $status = isset($data['status']) ? $data['status'] : '';
        $money_time = isset($data['money_time']) ? $data['money_time'] : '';
        $id = isset($data['id']) ? $data['id'] : '';
        $order_id = isset($data['order_id']) ? $data['order_id'] : '';
        $page = isset($data['page']) ? $data['page'] : 2;
        $arrd = [ //向数据库追加数组  然后循环出来
            'a.open_time' => $time1,
            'b.open_time' => $time2,
            'game_no' => $no,
            'id' => $id,
            'order_id' => $order_id,
            'account_identity' => $id_one,
            'status' => $status,
            'game_name' => $game_type,
            'money_time' => $money_time,
        ];

        if (empty($id_one)) {
            return -4010;
        }
        // $account = lm("game_type", "commons");
        // $game = $account->where("status", "1")->get()->toArray();
        //return $game;
        $play_num = "";
        $where = '1 = 1';

        $accountd = lm('SixMoney_buy', "commons");
        foreach ($arrd as $key => $value) {
            //循环数组
            if ($value != '' && $key != 'a.open_time' && $key != 'b.open_time') { //判断条件
                $where .= " AND {$key}='{$value}'"; //获取值
            }
            if ($value != '' && $key == 'a.open_time') {
                $where .= " AND money_time>='{$time1}'";
            }
            if ($value != '' && $key == 'b.open_time') {
                $where .= " AND money_time<='{$time2}'";
            }
        }
        //return $where;
        $list = 10;
        //获取总页数
        $count_list = $accountd->whereRaw($where)->count();
        $count_page = ceil($count_list / $list);
        $first = ($page - 1) * $list;
        $code_datas = $accountd->orderBy('money_time', 'desc')->whereRaw($where)->offset($first)->limit($list)->get();//注单信息
        if (!empty($code_datas)) {
            $code_data = $code_datas->toArray();
        } else {
            return "";
        }

        //return $code_data;
        foreach ($code_data as $k => $v) {
            $data_codes = lm($v['game_name'], "Commons")->select('status','codes', 'extra')->where('info_no', $v['game_no'])->first();
            $v['game_type'] = lang()->get($v['game_name']);
            if (!empty($data_codes)) {
                //开奖派奖号码

                $v['wing_codes'] = $data_codes->codes;//
                $v['gamed_status'] = $data_codes->status;
            }
            $datu[] = $v;
        }


        if (empty($datu)) {
            return "";
        }

        foreach ($datu as $val){
            $rowt[]=$this->dataChange($val,$game_type);
        }

        $dat = [
            'data' => $rowt,
            'count_page' => $count_page,
            'page' => $page,
            //'where' => $datu,

        ];

        return $dat;
        // return 1;

    }

    /*
    * pc投注详情
    */
    public function PcBettingDetails($data)
    {
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $time1 = isset($data['time1']) ? $data['time1'] : ''; //资金状态
        $time2 = isset($data['time2']) ? $data['time2'] : ''; //资金类型
        $no = isset($data['no']) ? $data['no'] : ''; //资金类型
        //return $no;
        $game_type = isset($data['game']) ? $data['game'] : ''; //资金类型
        $status = isset($data['status']) ? $data['status'] : '';
        $money_time = isset($data['money_time']) ? $data['money_time'] : '';
        $id = isset($data['id']) ? $data['id'] : '';
        $order_id = isset($data['order_id']) ? $data['order_id'] : '';
        $page = isset($data['page']) ? $data['page'] : 2;
        $arrd = [ //向数据库追加数组  然后循环出来
            'a.open_time' => $time1,
            'b.open_time' => $time2,
            'game_no' => $no,
            'id' => $id,
            'order_id' => $order_id,
            'account_identity' => $id_one,
            'status' => $status,
            'game_name' => $game_type,
            'money_time' => $money_time,
        ];

        if (empty($id_one)) {
            return -4010;
        }
        // $account = lm("game_type", "commons");
        // $game = $account->where("status", "1")->get()->toArray();
        //return $game;
        $play_num = "";
        $where = '1 = 1';

        $accountd = lm('money_buy', "commons");
        foreach ($arrd as $key => $value) {
            //循环数组
            if ($value != '' && $key != 'a.open_time' && $key != 'b.open_time') { //判断条件
                $where .= " AND {$key}='{$value}'"; //获取值
            }
            if ($value != '' && $key == 'a.open_time') {
                $where .= " AND money_time>='{$time1}'";
            }
            if ($value != '' && $key == 'b.open_time') {
                $where .= " AND money_time<='{$time2}'";
            }
        }
        //return $where;
        $list = 10;
        //获取总页数
        $count_list = $accountd->whereRaw($where)->count();
        $count_page = ceil($count_list / $list);
        $first = ($page - 1) * $list;
        $code_datas = $accountd->orderBy('money_time', 'desc')->whereRaw($where)->offset($first)->limit($list)->get();//注单信息
        if (!empty($code_datas)) {
            $code_data = $code_datas->toArray();
        } else {
            return "";
        }
        //return $code_data;
        foreach ($code_data as $k => $v) {
            $data_codes = lm($v['game_name'], "Commons")->select('status','codes', 'extra')->where('info_no', $v['game_no'])->first();
            $v['game_type'] = lang()->get($v['game_name']);
            if (!empty($data_codes)) {
                //开奖派奖号码
                if ($v['game_name'] == "xy28" || $v['game_name'] == "jnd28" || $v['game_name'] == "gpxy28" || $v['game_name'] == "gpjnd28" || $v['game_name'] == "tw28" || $v['game_name'] == "xjp28" || $v['game_name'] == "dj28" || $v['game_name'] == "hs28") {
                    $v['wing_codes'] = $data_codes->extra;
                } else {
                    $v['wing_codes'] = $data_codes->codes;//
                }
                $v['gamed_status'] = $data_codes->status;//
            }
            $datu = $v;
        }

        if ($datu['game_name'] == "xy28" || $datu['game_name'] == "jnd28" || $datu['game_name'] == 'hs28' || $datu['game_name'] == "gpxy28" || $datu['game_name'] == "gpjnd28" || $datu['game_name'] == "xjp28" || $datu['game_name'] == "tw28" || $datu['game_name'] == "dj28" ) {
            $params = json_decode($datu['wing_codes'], 1);
            $datu['wing_codes'] = $params['code'];

        }
        if (empty($datu)) {
            return "";
        }

        return $datu;
    }


    /*
    * pc六合投注详情PcSixlotteryRecord
    */
    public function PcSixlotteryDetails($data)
    {
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $time1 = isset($data['time1']) ? $data['time1'] : ''; //资金状态
        $time2 = isset($data['time2']) ? $data['time2'] : ''; //资金类型
        $no = isset($data['no']) ? $data['no'] : ''; //资金类型
        //return $no;
        $game_type = isset($data['game']) ? $data['game'] : ''; //资金类型
        $status = isset($data['status']) ? $data['status'] : '';
        $money_time = isset($data['money_time']) ? $data['money_time'] : '';
        $id = isset($data['id']) ? $data['id'] : '';
        $order_id = isset($data['order_id']) ? $data['order_id'] : '';
        $page = isset($data['page']) ? $data['page'] : 2;
        $arrd = [ //向数据库追加数组  然后循环出来
            'a.open_time' => $time1,
            'b.open_time' => $time2,
            'game_no' => $no,
            'id' => $id,
            'order_id' => $order_id,
            'account_identity' => $id_one,
            'status' => $status,
            'game_name' => $game_type,
            'money_time' => $money_time,
        ];

        if (empty($id_one)) {
            return -4010;
        }
        // $account = lm("game_type", "commons");
        // $game = $account->where("status", "1")->get()->toArray();
        //return $game;
        $play_num = "";
        $where = '1 = 1';

        $accountd = lm('SixMoney_buy', "commons");
        foreach ($arrd as $key => $value) {
            //循环数组
            if ($value != '' && $key != 'a.open_time' && $key != 'b.open_time') { //判断条件
                $where .= " AND {$key}='{$value}'"; //获取值
            }
            if ($value != '' && $key == 'a.open_time') {
                $where .= " AND money_time>='{$time1}'";
            }
            if ($value != '' && $key == 'b.open_time') {
                $where .= " AND money_time<='{$time2}'";
            }
        }
        //return $where;
        $list = 10;
        //获取总页数
        $count_list = $accountd->whereRaw($where)->count();
        $count_page = ceil($count_list / $list);
        $first = ($page - 1) * $list;
        $code_datas = $accountd->orderBy('money_time', 'desc')->whereRaw($where)->offset($first)->limit($list)->get();//注单信息
        if (!empty($code_datas)) {
            $code_data = $code_datas->toArray();
        } else {
            return "";
        }
        //return $code_data;
        foreach ($code_data as $k => $v) {
            $data_codes = lm($v['game_name'], "Commons")->select('status','codes', 'extra')->where('info_no', $v['game_no'])->first();
            $v['game_type'] = lang()->get($v['game_name']);
            if (!empty($data_codes)) {

                    $v['wing_codes'] = $data_codes->codes;//
                    $v['gamed_status'] = $data_codes->status;//

            }
            $datu = $v;
        }

        if (empty($datu)) {
            return "";
        }

        return $datu;
    }

    public function dataChange($data,$game='sixlottery') {

        $args = array();
        $buy_code = json_decode($data['codes'], 1); //该注购买号码
        //$color_code = json_decode($data['prizes'], 1); //该注购买号码
        $prize_code = json_decode($data['prize'], 1); //改注中奖号码
        $prize_num = $data['wing_codes']; //改注中奖号码

        $asb=array(
            //正码1-6
            'general_size',
            'general_parity',
            'general_sumsize',
            'general_sumparity',
            'general_endsize',
        );

        $asd =array(
            // 特码A_大小、单双、半特（混合）
            'special_size_a',
            'special_parity_a',
            'special_half_a',
            'special_sumsize_a',
            'special_sumparity_a',
            'special_endsize_a',

            // 特码b_大小、单双、半特（混合）
            'special_size_b',
            'special_parity_b',
            'special_half_b',
            'special_sumsize_b',
            'special_sumparity_b',
            'special_endsize_b',

            //合肖
            'join_born',

            //半波
            'special_halfwave',

            //半半波
            'special_mixwave',

            //两面
            'special_twofaceparity',
            'specialsum_twofaceparity',
            'special_twofacesize',
            'specialsum_twofacesize'
        );

        $unmdata=array(
            'special_halfwave',
            'special_mixwave',
            'poscode',
            'fronttwostar',
            'fivestar',
            'fourstar',
            'behindthreestar',
            'fronttwostar',
            'zhixuan',
            'frontthreestar',
            'bulls',
            'size',
            'mix',
            'possize',
            'dragon',
            'join_born',
            'general_parity',
            'general_pass',
            'general_twofacesize',
            'general_size',
            'generalsum_twofaceparity',
            'twosided',


        );
        $paramt = $this->PccodeDetails($buy_code);

        $odds=$this->getSettings($data['game_name']);

        if (is_array($paramt) && count($paramt) > 0) {
            $i = 0;
            $a = "";
            $s = 1;
            $daa = 0;
            foreach ($paramt as $k => $v) {

                if (is_array($v) && count($v) > 0) {

                    foreach ($v as $k1 => $v1) {
                        $datas = explode(',', $k1);
                        $datrr = explode('_', $k1);
                        if (in_array($k, $unmdata)) {
                            $a = lang($data['game_name'])->get($k . '-' . $k1);
                        } elseif (!empty($datrr) && count($datas) == 1) {
                            foreach ($datrr as $value) {
                                if ($value > 0 || strlen($value) == 1) {
                                    $a .= lang($data['game_name'])->get($k) . '-' . $value . "_";
                                } else {
                                    $a .= lang($data['game_name'])->get($k . '-' . $value) . "_";
                                }
                            }
                        } elseif (!empty($datas)) {
                            foreach ($datas as $value) {
                                if ($value > 0 || strlen($value) == 1) {
                                    $a .= lang($data['game_name'])->get($k) . '-' . $value . "_";
                                } else {
                                    $a .= lang($data['game_name'])->get($k . '-' . $value) . "_";
                                }
                            }
                        } else {
                            $a = $k1;
                        }

                        $a = rtrim($a, '_');
                        $args[$i] = array(
                            'gameType' => lang($data['game_name'])->get($k),
                            'codes' => lang($data['game_name'])->get($k) . '-' . $a,
                            'money' => $v1[0],
                            'maybe' => $v1[0] * $v1['settings']['multiple'],
                            'play' => $k,
                            'p_codes' => $a,
                            'p_code' => $k1,
                            'back' => empty($v1['settings']['back']) ? 0 : $v1['settings']['back'],
                        );

                        if (isset($v1['settings']['multiple']['max'])) {
                            $args[$i]['odds'] = $v1['settings']['multiple']['max'];
                        } else {
                            $args[$i]['odds'] = $v1['settings']['multiple'];
                        } if ($data['gamed_status'] == 3) {
                            $args[$i]['prize_status'] = '开奖中';
                            $args[$i]['get_money'] = 0;
                        }else if ($data['status'] == 4) {
                            $args[$i]['prize_status'] = '撤单';
                            $args[$i]['get_money'] = 0;
                        } else if ($data['game_status'] == 0) {
                            $args[$i]['prize_status'] = '待开奖';
                            $args[$i]['get_money'] = 0;
                        } elseif (in_array($k, $asd)) {
                            $datas1 = explode(',', $prize_num);
                            if (in_array(49, $datas1)) {
                                $args[$i]['prize_status'] = '和';
                                $args[$i]['get_money'] = $v1[0];
                                $args[$i]['odds'] = 1;
                            } else {
                                $args[$i]['prize_status'] = '未中奖';
                                $args[$i]['get_money'] = -$v1[0];
                            }
                        } elseif (stripos($data['game_name'], '11x5') !== false) {

                            if ($k == 'total') {
                                $datas1 = explode(',', $prize_num);

                                foreach ($datas1 as $r) {
                                    $daa += $r;
                                }
                                if ($k1 == 'big' || $k1 == 'small') {
                                    if ($daa == 30) {
                                        $args[$i]['prize_status'] = '和';
                                        $args[$i]['get_money'] = $v1[0];
                                        $args[$i]['odds'] = 1;
                                    }else{
                                        $args[$i]['prize_status'] = '未中奖';
                                        $args[$i]['get_money'] = -$v1[0];
                                    }
                                } else {
                                    $args[$i]['prize_status'] = '未中奖';
                                    $args[$i]['get_money'] = -$v1[0];
                                }
                                $daa = 0;
                            }elseif ($k == 'dragon') {
                                $datas1 = explode(',', $prize_num);

                                if ($k1 == 'big' || $k1 == 'small') {
                                    if ($datas1[0] == $datas1[4]) {
                                        $args[$i]['prize_status'] = '和';
                                        $args[$i]['get_money'] = $v1[0];
                                        $args[$i]['odds'] = 1;
                                    }
                                } else {
                                    $args[$i]['prize_status'] = '未中奖';
                                    $args[$i]['get_money'] = -$v1[0];
                                }
                            }else{
                                $args[$i]['prize_status'] = '未中奖';
                                $args[$i]['get_money'] = -$v1[0];
                            }
                        } elseif (in_array($k, $asb)) {
                            $datas1 = explode(',', $prize_num);
                            foreach ($datas1 as $k1 => $v1) {
                                foreach ($datrr as $k2 => $v2) {
                                    if ((string)$k1 + 1 == $v2 && $v1 == "49") {
                                        $args[$i]['prize_status'] = '和';
                                        $args[$i]['get_money'] = $v1[0];
                                        $args[$i]['odds'] = 1;
                                    }
                                }
                            }
                        } else {
                            $args[$i]['prize_status'] = '未中奖';
                            $args[$i]['get_money'] = -$v1[0];
                        }
                        $i++;
                        $a = "";
                    }

                }

            }
        }

        //中奖判断
        $datauu=explode(',',$prize_num);
        $dataw=explode(',',$prize_num);
        if (is_array($prize_code) && count($prize_code) && $data['gamed_status'] == 2) {
            foreach ($prize_code as $kk => $vv) {
                $name = $k;
            }

            foreach ($dataw as $k=>$vv){
                if ($vv > 9){
                    $aa[$k]=$vv % 10;
                }else{
                    $aa[$k]=$vv;
                }
            }


            $bb[$name]=array_unique($aa);
            $cc=array_unique($aa);
            $datass[$name] = $datauu;
            array_pop($datauu);
            $datd[$name] =$datauu;

            //中奖号码
            $paramt = $this->PcWincodeDetails($prize_code,$datass,$datd,$cc,$bb,$buy_code);

            $arry = array(

                'selfselect_eightlose',//八不中
                'selfselect_elevenlose',
                'selfselect_twelvelose',
                'selfselect_tenlose',
                'selfselect_sixlose',
                'selfselect_ninelose',
                'selfselect_sevenlose',
                'selfselect_fivelose',//五不中
            );

            $arrys = array(
                'series_twospecial',//二中特
                'series_threetwo'
            );

            $asse = array(
                '5'=>'series_fiveend',
                '4'=>'series_fourend',
                '3'=>'series_threeend',
                '2'=>'series_twoend',
            );


            $xy28= array(
                'specialthree'
            );


            foreach ($paramt as $p_k => $p_v) {
                //购买号码
                foreach ($args as $num => $v) {
                    if ($v['play'] == $p_k) {
                        if (is_array($p_v) && count($p_v) > 0) {

                            if ($data['game_name'] == 'sixlottery' || $data['game_name'] == 'sfsixlottery'){
                                $args=$this->Win($args,$p_k,$p_v,$v,$arry,$num,$arrys,$odds,$dataw,$asd,$prize_num,$asse,$bb,$asb);
                            }
                            elseif(stripos($data['game_name'], '11x5') !== false){

                                if( ($v['play'] == 'total' || $v['play'] == 'dragon') && ($v['p_code'] == 'big' || $v['p_code'] == 'small')) {
                                    if ($v['prize_status'] != '和') {

                                        foreach ($p_v as $p_k1 => $p_v2) {
                                            if ($v['p_code'] == $p_v2) {
                                                $args[$num]['prize_status'] = '中奖';
                                                $args[$num]['get_money'] = $v['money'] * $v['odds'] - $v['money'];
                                                break;
                                            } else {
                                                $args[$num]['prize_status'] = '未中奖';
                                                $args[$num]['get_money'] = -$v['money'];
                                            }
                                        }
                                    }

                                }else{
                                    foreach ($p_v as $p_k1 => $p_v2) {
                                        if ($v['p_code'] == $p_v2) {
                                            $args[$num]['prize_status'] = '中奖';
                                            $args[$num]['get_money'] = $v['money'] * $v['odds'] - $v['money'];
                                            break;
                                        } else {
                                            $args[$num]['prize_status'] = '未中奖';
                                            $args[$num]['get_money'] = -$v['money'];
                                        }
                                    }
                                }
                            }elseif(in_array($p_k, $xy28)) {

                                foreach ($p_v as $p_k1 => $p_v2) {
                                    intval($p_v2);
                                    settype($p_v2, "string");
                                    if (stripos($v['p_code'],$p_v2) !== false) {
                                        $args[$num]['prize_status'] = '中奖';
                                        $args[$num]['get_money'] = $v['money'] * $v['odds'] - $v['money'];
                                        break;
                                    } else {
                                        $args[$num]['prize_status'] = '未中奖';
                                        $args[$num]['get_money'] = -$v['money'];
                                    }
                                }
                            }else {

                                foreach ($p_v as $p_k1 => $p_v2) {
                                    if ($v['p_code'] == $p_v2) {
                                        $args[$num]['prize_status'] = '中奖';
                                        $args[$num]['get_money'] = $v['money'] * $v['odds'] - $v['money'];
                                        break;
                                    } else {
                                        $args[$num]['prize_status'] = '未中奖';
                                        $args[$num]['get_money'] = -$v['money'];
                                    }
                                }
                            }


                        }
                    }
                }
            }
        }

        if(is_array($args) && count($args) > 0){


            foreach ($args as $k=>$v){
                if (isset($v['prize_status'])){
                    $argss[$k]['codes'] = $v['p_codes']."-".$v['prize_status'];
                }else{
                    $argss[$k]['codes'] = $v['p_codes']."-未中奖";
                }

                $argss[$k]['codeDate'] = $v['gameType'];
                $argss[$k]['money'] = $v['money'];
            }

            if (count($args) >= 2){
                $codeds =$argss[0]['codes'].$argss[1]['codes'];
            }else{
                $codeds =$argss[0]['codes'];
            }
          $game_type=$args[0]['gameType'];
        }else{
            $game_type="";
            $codeds='';
            $argss='';
        }


        if ($data['status'] == 4){
            $game_status='撤单';
        }elseif ($data['game_status'] == 0){
            $game_status='待开奖';
        }elseif ($data['game_status'] == 1){
            $game_status='中奖';
        }elseif ($data['game_status'] == 2){
            $game_status='未中奖';
        }
        if ($data['wing_codes'] == '-1'){
            $data['wing_codes']="";
        }
        $da_args['order_id']=$data['order_id'];
        $da_args['wing_codes'] = $data['wing_codes'];
        $da_args['get_money'] = $data['get_money']-$data['money'];
        $da_args['game_no'] = $data['game_no'];
        $da_args['get_money'] = $data['get_money'];
        $da_args['game_type'] = $data['game_type'];
        $da_args['money'] = $data['money'];
        $da_args['codes'] = $data['codes'];
        $da_args['game_name'] = $data['game_name'];
        $da_args['codeDate'] = $game_type;
        $da_args['codet'] = $argss;
        $da_args['coded'] = $codeds;
        $da_args['money_time'] = $data['money_time'];
        $da_args['id'] = $data['id'];
        $da_args['game_status'] = $game_status;
        $da_args['gamed_status'] = $data['gamed_status'];

        return $da_args;
    }


    /*
    * pc账户明细
    */
    function PcWinning($data)
    {
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $id = isset($data['id']) ? $data['id'] : '';
        $page = isset($data['page']) ? $data['page'] : 1;
        $num1 = isset($data['num1']) ? $data['num1'] : '';
        $num2 = isset($data['num2']) ? $data['num2'] : '';
        $new_time = isset($data['time']) ? $data['time'] : '';
        $trade_type = isset($data['trade_type']) ? $data['trade_type'] : ''; //资金状态
        if (empty($id_one)) {
            return -4010;
        }

        if ($num2 > $num1) {
            $bb = $num1;
            $num1 = $num2;
            $num2 = $bb;
        }

        if (!empty($new_time)) {
            $new_time1 = $new_time;
            $new_time2 = date("Y-m-d", strtotime("+1 day", strtotime($new_time)));
             $arr = [ //向数据库追加数组  然后循环出来
            'a.id' => $num1,
            'b.id' => $num2,
            'id' => $id,
            'trade_type' => $trade_type,
            'a.money_time' => $new_time1,
            'b.money_time' => $new_time2,
            "account_identity" => $id_one,
        ];
        }else{
             $arr = [ //向数据库追加数组  然后循环出来
            'a.id' => $num1,
            'b.id' => $num2,
            'id' => $id,
            'trade_type' => $trade_type,
            "account_identity" => $id_one,
        ];
        }

        //var_dump($new_time1,$new_time2);

        //return ;


        $where = '1 = 1';

        foreach ($arr as $key => $value) {
            //循环数组
            if ($value != '' && $key != 'a.id' && $key != 'b.id' && $key != 'a.money_time' && $key != 'b.money_time') { //判断条件
                $where .= " AND {$key}='{$value}'"; //获取值
            }
            if ($value != '' && $key == 'a.id') {
                //$time1 = date('Y-m-d 00:00:00', strtotime($time1));
                $where .= " AND id<='{$num1}'";
            }
            if ($value != '' && $key == 'b.id') {
                //$time2 = date('Y-m-d H:i:s', (strtotime($time2) + 24 * 60 * 60 - 1));
                $where .= " AND id>='{$num2}'";
            }
            if ($value != '' && $key == 'a.money_time') {
                //$time1 = date('Y-m-d 00:00:00', strtotime($time1));
                $where .= " AND money_time>='{$new_time1}'";
            }
            if ($value != '' && $key == 'b.money_time') {
                //$time2 = date('Y-m-d H:i:s', (strtotime($time2) + 24 * 60 * 60 - 1));
                $where .= " AND money_time<'{$new_time2}'";
            }
        }

        //return $where;
        $rows = lm("money_details", "commons")->whereRaw($where)->get();

        // return $rows;
        if (count($rows) != 0) {

            $list = 10;
            //获取总页数
            $count_list = lm("money_details", "commons")->whereRaw($where)->count();
            $count_page = ceil($count_list / $list);
            $first = ($page - 1) * $list;
            $rows = lm("money_details", "commons")->orderBy('money_time', 'desc')->whereRaw($where)->offset($first)->limit($list)->get()->toArray();

            // return $rows;
            //$rows=lm("money_details","commons")->whereRaw($where)->get()->toArray();
        } else {
            return "";
        }

        foreach ($rows as $k => $v) {
            if ($v['money_type'] == "1" && $v['status'] == '1') {
                $rows[$k]['old_money'] = sprintf("%.1f", $v['money_cash'] - $v['money']);
            } elseif ($v['money_type'] == "2" && $v['status'] == '1') {
                $rows[$k]['old_money'] = sprintf("%.1f", $v['money_cash'] + $v['money']);
            } else {
                $rows[$k]['old_money'] = $v['money_cash'];
            }
        }
        // $status=$this->GetStatus();
        $money_type = $this->GetMonetType();
        $Winning = $this->GetStatut();
        foreach ($rows as $k => $val) {
            foreach ($money_type as $key => $v) {

                if ($val['trade_type'] == $key) {
                    $val['trade_type'] = lang()->get($v['name']);
                    $val['money'] = $val['money'];
                    $row[] = $val;
                }
            }
        }

        //return $row;
        foreach ($Winning as $key => $v) {
            foreach ($row as $k => $val) {
                if ($val['status'] == $key) {
                    $val['status'] = lang()->get($v);
                    $rowt[] = $val;
                }
            }
        }

        $len = count($rowt);
        for ($i = 0; $i < $len; $i++) {
            for ($j = $len; $j < $len - $i; $j--) {
                if ($rowt[$i]['money_time'] > $rowt[$j]['money_time']) {
                    $temp = $rowt[$i];
                    $rowt[$j] = $rowt[$i];
                    $rowt[$i] = $temp;
                }
            }
        }

        $dat = [
            'data' => $rowt,
            'count_page' => $count_page,
            'page' => $page,

        ];
        return $dat;

    }

    /*
    * 账号盈亏
    */
    public function Personals($data)
    {

        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $now_times = isset($data['now_times']) ? $data['now_times'] : ''; //用户唯一id
        // return $now_times;
        if ($now_times == "当天") {
            // return 1;
            $now_time_old = date("Y-m-d", strtotime("+1 day"));
            $now_time = date('Y-m-d', time());

            for ($i = 1; $i <= 10; $i++) {
                if ($i == '5' || $i == '6') {

                } else {
                    $datas[] = lm("money_details", "commons")->where("account_identity", $id_one)
                        ->where("trade_type", "$i")
                        ->where("money_time", ">", $now_time)
                        ->where("money_time", "<", $now_time_old)
                        ->get()->toArray();
                }
            }

        } elseif ($now_times == "一周") {
            $now_time_old = date("Y-m-d", strtotime("-7 day"));
            $week_time = date("Y-m-d", strtotime("+1 day"));

            for ($i = 1; $i <= 10; $i++) {
                if ($i == '5' || $i == '6') {

                } else {
                    $datas[] = lm("money_details", "commons")->where("account_identity", $id_one)
                        ->where("trade_type", "$i")
                        ->where("money_time", "<", $week_time)
                        ->where("money_time", ">", $now_time_old)
                        ->get()->toArray();
                }
            }

        } else {

            for ($i = 1; $i <= 10; $i++) {
                if ($i == '5' || $i == '6') {

                } else {
                    $datas[] = lm("money_details", "commons")->where("account_identity", $id_one)
                        ->where("trade_type", "$i")
                        ->get()->toArray();
                }
            }
        }

        foreach ($datas as $key => $val) {
            if (empty($val)) {
                continue;
            }
            $arr[] = $val;
        }

        // return $arr;

        if (empty($arr)) {
            @$arrs['eart'] = 0;
            @$arrs['koukuan'] = 0;
            @$arrs['defection'] = 0;
            @$arrs['balance'] = 0;
            @$arrs['open_times'] = 0;
            @$arrs['money_time'] = 0;
        } else {
            foreach ($arr as $v) {
                foreach ($v as $val) {
                    $arrs[] = $val;
                }
            }

            foreach ($arrs as $k => $v) {
                $arrs[$k]['money_time'] = date("m", strtotime($v['money_time']));
            }
        }

        // return $arrs;

        $date = [
            '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12',

        ];
        $datq = array();
        $eart = 0;
        $expenditure = "";
        foreach ($date as $k => $val) {
            foreach ($arrs as $v) {
                if ($val == $v['money_time']) {

                    if ($v['trade_type'] == "1" || $v['trade_type'] == "2" || $v['trade_type'] == "9") {

                        @$expenditure += $v['money'];
                    }
                    if ($v['trade_type'] == "3" || $v['trade_type'] == "4" || $v['trade_type'] == "7" || $v['trade_type'] == "8" || $v['trade_type'] == "10") {

                        @$eart += $v['money'];
                    }
                    $balance = $eart - $expenditure;
                    //return $balance;
                }
            }

            @$datq[$k]['eart'] = $eart;
            @$datq[$k]['balance'] = $balance;
            @$datq[$k]['expenditure'] = $expenditure;
            @$datq[$k]['time'] = $val;

            //return $datq;
            $eart = 0;
            $balance = 0;
            $expenditure = 0;
        }

        return $datq;
        //echo json_encode($datq);
    }

    //盈亏
    public function Personal($data)
    {

        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $now_times = isset($data['now_times']) ? $data['now_times'] : ''; //用户唯一id
        // return $now_times;
        if ($now_times == "当天") {
            // return 1;
            $now_time_old = date("Y-m-d", strtotime("+1 day"));
            $now_time = date('Y-m-d', time());


                    $datas = lm("money_buy", "commons")
                        ->where("account_identity", $id_one)
                        ->where("status",'!=', "4")
                        ->orWhere("status", "2")
                        ->where("money_time", ">", $now_time)
                        ->where("money_time", "<", $now_time_old)
                        ->get();
                    if ($datas){
                        $datas=$datas->toArray();
                    }


        } elseif ($now_times == "一周") {
            $now_time_old = date("Y-m-d", strtotime("-7 day"));
            $week_time = date("Y-m-d", strtotime("+1 day"));


                    $datas = lm("money_buy", "commons")->where("account_identity", $id_one)
                        ->where("status",'!=', "4")
                        ->where("money_time", "<", $week_time)
                        ->where("money_time", ">", $now_time_old)
                        ->get();
            if ($datas){
                $datas=$datas->toArray();
            }


        } else {
                    $datas = lm("money_buy", "commons")
                        ->where("account_identity", $id_one)
                        ->where("status",'!=', "4")
                        ->get();
            if ($datas){
                $datas=$datas->toArray();
            }
        }



        foreach ($datas as $key => $val) {
            if (empty($val)) {
                continue;
            }
            $arr[] = $val;
        }



        $date = [
            '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12',

        ];
        $datq = array();
        $eart = 0;
        $balance = 0;
        $expenditure = "";
        foreach ($date as $k => $val) {
            foreach ($arr as $v) {
                if ($val == date("m", strtotime($v['money_time']))) {



                        @$eart += $v['prize_money'];

                        @$expenditure += $v['money'];


                    @$balance += $v['get_money'];
                }
            }

            @$datq[$k]['eart'] = $eart;
            @$datq[$k]['balance'] = $balance;
            @$datq[$k]['expenditure'] = $expenditure;
            @$datq[$k]['time'] = $val;

            //return $datq;
            $eart = 0;
            $balance = 0;
            $expenditure = 0;
        }

        $sixnum=$this->sixPersonal($id_one,$now_times);

        foreach ($sixnum as $v){
            foreach ($datq as $k=>$val){
                if ($v['time'] == $val['time']){
                    $datq[$k]['eart']=$v['eart']+$val['eart'];
                    $datq[$k]['balance']=$v['balance']+$val['balance'];
                    $datq[$k]['expenditure']=$v['expenditure']+$val['expenditure'];
                }
            }
        }
        return $datq;
        //echo json_encode($datq);
    }


    public function sixPersonal($id_one,$now_times)
    {

        if ($now_times == "当天") {
            $now_time_old = date("Y-m-d", strtotime("+1 day"));
            $now_time = date('Y-m-d', time());


            $datas = lm("sixMoney_buy", "commons")->where("account_identity", $id_one)
                ->where("status",'!=', "4")
                ->where("money_time", ">", $now_time)
                ->where("money_time", "<", $now_time_old)
                ->get();
            if ($datas){
                $datas=$datas->toArray();
            }


        } elseif ($now_times == "一周") {
            $now_time_old = date("Y-m-d", strtotime("-7 day"));
            $week_time = date("Y-m-d", strtotime("+1 day"));


            $datas = lm("sixMoney_buy", "commons")->where("account_identity", $id_one)
                ->where("status",'!=', "4")
                ->where("money_time", "<", $week_time)
                ->where("money_time", ">", $now_time_old)
                ->get();
            if ($datas){
                $datas=$datas->toArray();
            }


        } else {
            $datas = lm("sixMoney_buy", "commons")->where("account_identity", $id_one)
                ->where("status",'!=', "4")
                ->get();
            if ($datas){
                $datas=$datas->toArray();
            }
        }



        foreach ($datas as $key => $val) {
            if (empty($val)) {
                continue;
            }
            $arr[] = $val;
        }


        $date = [
            '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12',

        ];
        $datq = array();
        $eart = 0;
        $balance = 0;
        $expenditure = "";
        foreach ($date as $k => $val) {
            foreach ($arr as $v) {

                if ($val == date("m", strtotime($v['money_time']))) {

                        @$eart += $v['prize_money'];

                        @$expenditure += $v['money'];


                    @$balance += $v['get_money'];
                    //return $balance;
                }
            }

            @$datq[$k]['eart'] = $eart;
            @$datq[$k]['balance'] = $balance;
            @$datq[$k]['expenditure'] = $expenditure;
            @$datq[$k]['time'] = $val;

            //return $datq;
            $eart = 0;
            $balance = 0;
            $expenditure = 0;
        }

        return $datq;
        //echo json_encode($datq);
    }

    /*
     * 充值记录
    */

    function PCRecharge($data,$c=-1)
    {
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $id = isset($data['id']) ? $data['id'] : '';
        $page = isset($data['page']) ? $data['page'] : 1;
        $num1 = isset($data['num1']) ? $data['num1'] : '';
        $num2 = isset($data['num2']) ? $data['num2'] : '';
        $new_time = isset($data['time']) ? $data['time'] : '';
        if (empty($id_one)) {
            return -4010;
        }

        if ($num2 > $num1) {
            $bb = $num1;
            $num1 = $num2;
            $num2 = $bb;
        }

        if (!empty($new_time)) {//qtx 2018-12-11
            $newtime = explode('~',$new_time);
            if(count($newtime) ==2){
                $new_time1 = $newtime[0].' 00:00:00';
                $new_time2 = $newtime[1].' 23:59:59';
            }else{
                $new_time1 = $new_time;
                $new_time2 = date("Y-m-d", strtotime("+1 day", strtotime($new_time)));
            }

            $arr = [ //向数据库追加数组  然后循环出来
            'a.id' => $num1,
            'b.id' => $num2,
            'id' => $id,
            'a.apply_time' => $new_time1,
            'b.apply_time' => $new_time2,
            "account_identity" => $id_one,
        ];

        }else{
            $arr = [ //向数据库追加数组  然后循环出来
            'a.id' => $num1,
            'b.id' => $num2,
            'id' => $id,
            "account_identity" => $id_one,
        ];
        }



        $where = '1 = 1';

        foreach ($arr as $key => $value) {
            //循环数组
            if ($value != '' && $key != 'a.id' && $key != 'b.id' && $key != 'a.apply_time' && $key != 'b.apply_time') { //判断条件
                $where .= " AND {$key}='{$value}'"; //获取值
            }
            if ($value != '' && $key == 'a.id') {
                //$time1 = date('Y-m-d 00:00:00', strtotime($time1));
                $where .= " AND id<='{$num1}'";
            }
            if ($value != '' && $key == 'b.id') {
                //$time2 = date('Y-m-d H:i:s', (strtotime($time2) + 24 * 60 * 60 - 1));
                $where .= " AND id>='{$num2}'";
            }
            if ($value != '' && $key == 'a.apply_time') {
                //$time1 = date('Y-m-d 00:00:00', strtotime($time1));
                $where .= " AND apply_time>='{$new_time1}'";
            }
            if ($value != '' && $key == 'b.apply_time') {
                //$time2 = date('Y-m-d H:i:s', (strtotime($time2) + 24 * 60 * 60 - 1));
                $where .= " AND apply_time<'{$new_time2}'";
            }
        }


        $rows = lm("money_recharge", "commons")->whereRaw($where)->get();
        if($c==1){
            $where .=" AND status=1";
            $countMoney = $count_list = lm("money_recharge", "commons")->whereRaw($where)->sum('money');
            $countMoney = empty($countMoney)?0:$countMoney;
            return $countMoney;
        }

        if (count($rows) != 0) {

            $list = 10;
            //获取总页数
            $count_list = lm("money_recharge", "commons")->whereRaw($where)->count();
            $count_page = ceil($count_list / $list);
            $first = ($page - 1) * $list;
            $rows = lm("money_recharge", "commons")->orderBy('apply_time', 'desc')->whereRaw($where)->offset($first)->limit($list)->get()->toArray();

            //$rows=lm("money_recharge","commons")->whereRaw($where)->get()->toArray();
            //return $rows;
        } else {
            return "";
        }

        $Winning = $this->GetStatus();
        foreach ($Winning as $key => $v) {
            foreach ($rows as $k => $val) {

                if ($val['status'] == $key) {
                    if ($val['status'] == '1') {
                        $val['old_money'] = ($val['money_cash'] - $val['money']);
                    } else {
                        $val['old_money'] = $val['money_cash'];
                    }
                    $val['statud'] = lang()->get($v);
                    $val['trade_type'] = lang()->get("Recharge");
                    $val['money'] = $val['money'];
                    $index = strtotime($val['apply_time']);

                    $rowr[$index] = $val;
                    //return $rowr;
                }
            }
        }

        rsort($rowr);
        $dat = [
            'data' => $rowr,
            'count_page' => $count_page,
            'page' => $page,

        ];
        return $dat;
    }

    /*
    * 提现记录
    */

    function PCWithdrawals($data,$c=-1)
    {
        //$id_one = $_SESSION['uinfo']['account_identity'];
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $id = isset($data['id']) ? $data['id'] : '';
        $page = isset($data['page']) ? $data['page'] : 1;
        $num1 = isset($data['num1']) ? $data['num1'] : '';
        $num2 = isset($data['num2']) ? $data['num2'] : '';
        $new_time = isset($data['time']) ? $data['time'] : '';
        if (empty($id_one)) {
            return -4010;
        }

        if ($num2 > $num1) {
            $bb = $num1;
            $num1 = $num2;
            $num2 = $bb;
        }

        if (!empty($new_time)) {//qtx 2018-12-11
            $newtime = explode('~',$new_time);
            if(count($newtime) ==2){
                $new_time1 = $newtime[0].' 00:00:00';
                $new_time2 = $newtime[1].' 23:59:59';
            }else{
                $new_time1 = $new_time;
                $new_time2 = date("Y-m-d", strtotime("+1 day", strtotime($new_time)));
            }
            $arr = [ //向数据库追加数组  然后循环出来
            'a.id' => $num1,
            'b.id' => $num2,
            'id' => $id,
            'a.apply_time' => $new_time1,
            'b.apply_time' => $new_time2,
            "account_identity" => $id_one,
        ];
        }else{
            $arr = [ //向数据库追加数组  然后循环出来
            'a.id' => $num1,
            'b.id' => $num2,
            'id' => $id,
            "account_identity" => $id_one,
        ];
        }



        $where = '1 = 1';

        foreach ($arr as $key => $value) {
            //循环数组
            if ($value != '' && $key != 'a.id' && $key != 'b.id' && $key != 'a.apply_time' && $key != 'b.apply_time') { //判断条件
                $where .= " AND {$key}='{$value}'"; //获取值
            }
            if ($value != '' && $key == 'a.id') {
                //$time1 = date('Y-m-d 00:00:00', strtotime($time1));
                $where .= " AND id<='{$num1}'";
            }
            if ($value != '' && $key == 'b.id') {
                //$time2 = date('Y-m-d H:i:s', (strtotime($time2) + 24 * 60 * 60 - 1));
                $where .= " AND id>='{$num2}'";
            }
            if ($value != '' && $key == 'a.apply_time') {
                //$time1 = date('Y-m-d 00:00:00', strtotime($time1));
                $where .= " AND apply_time>='{$new_time1}'";
            }
            if ($value != '' && $key == 'b.apply_time') {
                //$time2 = date('Y-m-d H:i:s', (strtotime($time2) + 24 * 60 * 60 - 1));
                $where .= " AND apply_time<'{$new_time2}'";
            }
        }

        $rows = lm("money_take", "commons")->whereRaw($where)->get();
        if($c==1){
            $where .=" AND status=1";
            $countMoney = lm("money_take", "commons")->whereRaw($where)->sum('money');
            $countMoney = empty($countMoney)?0:$countMoney;
            return $countMoney;
        }

        if (count($rows) != 0) {
            $list = 10;
            //获取总页数
            $count_list = lm("money_take", "commons")->whereRaw($where)->count();
            //return $count_list;
            $count_page = ceil($count_list / $list);
            $first = ($page - 1) * $list;
            $rows = lm("money_take", "commons")->orderBy('apply_time', 'desc')->whereRaw($where)->offset($first)->limit($list)->get()->toArray();
        } else {
            return "";
        }

        $Winning = $this->GetStatus();

        foreach ($Winning as $key => $v) {
            foreach ($rows as $k => $val) {
                if ($val['status'] == $key) {
                    if ($val['status'] == '1') {
                        $val['old_money'] = ($val['money_cash'] + $val['money']);
                    } else {
                        $val['old_money'] = $val['money_cash'];
                    }
                    $val['status'] = lang()->get($v);

                    $val['trade_type'] = lang()->get("Withdrawals");
                    $val['money'] = $val['money'];

                    $index = strtotime($val['apply_time']);
                    $rowr[$index] = $val;
                }
            }
        }
        rsort($rowr);
        $dat = [
            'data' => $rowr,
            'count_page' => $count_page,
            'page' => $page,

        ];
        return $dat;
    }

    /*
    * 投注详情
    */
    function Betting($data)
    {
        $id = isset($data['id']) ? $data['id'] : '11315';
        $game_name = isset($data['game_name']) ? $data['game_name'] : 'cqssc';
        if ($game_name == 'jnd28' || $game_name == 'xy28') {
            $tab_name = "SpecialCodeDataAccess";
        } else {
            $tab_name = "PoscodeDataAccess";
        }
        $cls = "\\Biz\\Game\\DataAccess\\" . ucfirst($game_name) . "\\" . $tab_name;
        $settings = new $cls();
        $number = $settings->getAttr();

        $code_datas = lm('money_buy', "commons")->where('id', $id)->get();

        if (!empty($code_datas)) {
            $code_data = $code_datas->toArray();
        } else {
            return "";
        }

        foreach ($code_data as $o => $v) {

            $tab_name = "bjpk10Parse";
            $nums = C()->get($tab_name);

            $data_paramt = json_decode($v['codes'], 1);

            if (array_key_exists("head_three", $data_paramt)) {
                $paramt = $this->CodeData($data_paramt);
            } elseif (array_key_exists("head_two", $data_paramt)) {
                $paramt = $this->CodeData($data_paramt);

            } elseif (array_key_exists("fivestar", $data_paramt)) {
                $paramt = $this->CQCodeData($data_paramt);

            } elseif (array_key_exists("fourstar", $data_paramt)) {
                $paramt = $this->CQCodeData($data_paramt);

            } elseif (array_key_exists("behindthreestar", $data_paramt)) {
                $paramt = $this->CQCodeData($data_paramt);

            } elseif (array_key_exists("frontthreestar", $data_paramt)) {
                $paramt = $this->CQCodeData($data_paramt);

            } elseif (array_key_exists("fronttwostar", $data_paramt)) {
                $paramt = $this->CQCodeData($data_paramt);
            } else {
                $datat = [
                    'codes' => $v['codes'],
                ];
                $paramt = $nums->change($datat);
            }

            foreach ($paramt as $va) {
                $CodeDate[] = $va['codes'];

            }

            if ($v['game_status'] == 1) {
                $args = array();
                $paramd = json_decode($v['prize'], 1);
                $paramds = '';
                if (empty($paramd)) {
                    $prize_code[] = "";
                }
                if (array_key_exists("head_three", $data_paramt)) {
                    foreach ($paramd as $v) {
                        foreach ($v as $ku => $val) {
                            $str = explode("_", $val);
                            $paramds .= $str[1] . ',';
                            $ast = substr($paramds, 0, strlen($paramds) - 1);
                        }
                        $args[]['codes'] = $ast;
                    }
                    foreach ($paramt as $kp => $vp) {

                    }
                } elseif (array_key_exists("head_two", $data_paramt)) {
                    foreach ($paramd as $v) {

                        foreach ($v as $ku => $val) {
                            $str = explode("_", $val);
                            $paramds .= $str[1] . ',';
                            $ast = substr($paramds, 0, strlen($paramds) - 1);

                        }
                        $args[]['codes'] = $ast;
                    }
                } elseif (array_key_exists("fivestar", $data_paramt)) {
                    foreach ($paramd as $v) {

                        foreach ($v as $ku => $val) {
                            $str = explode("_", $val);
                            $paramds .= $str[1] . ',';
                            $ast = substr($paramds, 0, strlen($paramds) - 1);

                        }
                        $args[]['codes'] = $ast;
                    }
                } elseif (array_key_exists("fourstar", $data_paramt)) {
                    foreach ($paramd as $v) {

                        foreach ($v as $ku => $val) {
                            $str = explode("_", $val);
                            $paramds .= $str[1] . ',';
                            $ast = substr($paramds, 0, strlen($paramds) - 1);

                        }
                        $args[]['codes'] = $ast;
                        return $args;
                    }

                } elseif (array_key_exists("behindthreestar", $data_paramt)) {
                    foreach ($paramd as $v) {

                        foreach ($v as $ku => $val) {
                            $str = explode("_", $val);
                            $paramds .= $str[1] . ',';
                            $ast = substr($paramds, 0, strlen($paramds) - 1);

                        }
                        $args[]['codes'] = $ast;
                    }

                } elseif (array_key_exists("frontthreestar", $data_paramt)) {
                    foreach ($paramd as $v) {

                        foreach ($v as $ku => $val) {
                            $str = explode("_", $val);
                            $paramds .= $str[1] . ',';
                            $ast = substr($paramds, 0, strlen($paramds) - 1);

                        }
                        $args[]['codes'] = $ast;
                    }
                } elseif (array_key_exists("fronttwostar", $data_paramt)) {

                    foreach ($paramd as $v) {

                        foreach ($v as $ku => $val) {
                            $str = explode("_", $val);
                            $paramds .= $str[1] . ',';
                            $ast = substr($paramds, 0, strlen($paramds) - 1);

                        }
                        $args[]['codes'] = $ast;
                    }

                }
            }
        }

        foreach ($paramt as $kp => $vp) {

            foreach ($args as $ka => $va) {

                if ($va['codes'] == $vp['codes']) {

                    $prize_code[] = $vp['codes'];
                    break;
                }
            }
        }

        $arr = [
            'title' => $game_name,
            'number' => $number,
            'buy_code' => $CodeDate,
            'prize_code' => $prize_code,
        ];
        dump($data_paramt);
        exit;
    }

    //快乐赛宝投注记录
    function DiceBettingDetails($data){
        $account_identity = isset($data['account_identity']) ? $data['account_identity'] : '';
        $data=lm('Dice','commons')->orderBy('create_time', 'desc')->where('master_identity',$account_identity)->orWhere('guster_identity',$account_identity)->limit(10)->get();

        foreach ($data as $k=>$v){
            if ($v['master_identity'] == $account_identity){
                $data[$k]['name_id']=1;
            }else{
                $data[$k]['name_id']=2;
            }
            if ($v['winner_identity'] == $account_identity){
                $data[$k]['name_win']=1;
            }else{
                $data[$k]['name_win']=2;
            }
        }
        return $data;
    }


    //赔率
    function getSettings($game='sixlottery') {
        $game = empty($game)?'sixlottery':$game;
        //权限检测
        $arrys = array(
            'series_twospecial',//二中特
            'series_threetwo-0',
            'series_fiveend-0',
            'series_fourend-0',
            'series_threeend-0',
            'series_twoend-0',

            'series_twoborn-rate',
            'series_twoborn-cattle',
            'series_twoborn-tiger',
            'series_twoborn-rabbit',
            'series_twoborn-dragon',
            'series_twoborn-snake',
            'series_twoborn-horse',
            'series_twoborn-sheep',
            'series_twoborn-monkey',
            'series_twoborn-chick',
            'series_twoborn-dog',
            'series_twoborn-pig',

            'general_born'

        );
        $data = lm('Game_odds','Commons')->getOdds($game);
        if($data<0){
            return responseToJson($data);
        }
        $data = json_decode($data['odds'], 1);
        return $data;
        $array = array();
        $i = 0;
        foreach ($arrys as $v){
            $bs[$v]=$data[$v];
        }
        return $bs;
    }


    /*
     * PC塞子游戏投注记录
    */
    public function PcDiceBettingRecord($data)
    {
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $time1 = isset($data['time1']) ? $data['time1'] : ''; //时间
        $time2 = isset($data['time2']) ? $data['time2'] : ''; //时间
        $game_type = isset($data['game'])&& !empty($data['game']) ? trim($data['game']) : 'diceone'; //游戏类型
        $id = isset($data['id']) ? $data['id'] : '';
        $page = isset($data['page']) ? $data['page'] : 2;

        if ($game_type == 'diceone'){
            $arrd = [ //向数据库追加数组  然后循环出来
                'a.create_time' => $time1,
                'b.create_time' => $time2,
                'id' => $id,
                'account_identity' => $id_one,
            ];
        }else{
            $arrd = [ //向数据库追加数组  然后循环出来
                'a.create_time' => $time1,
                'b.create_time' => $time2,
                'id' => $id,
                'master_identity'=>$id_one,
                'guster_identity'=>$id_one,
            ];
        }


        if (empty($id_one)) {
            return -4010;
        }
        $where = '1 = 1';

        $accountd = lm($game_type, "commons");
        foreach ($arrd as $key => $value) {
            //循环数组
            if ($value != '' && $key != 'a.create_time' && $key != 'b.create_time' && $key != 'master_identity' && $key != 'guster_identity') { //判断条件
                $where .= " AND {$key}='{$value}'"; //获取值
            }
            if ($value != '' && $key == 'a.create_time') {
                $where .= " AND create_time>='{$time1}'";
            }
            if ($value != '' && $key == 'b.create_time') {
                $where .= " AND create_time<='{$time2}'";
            }
            if ($value != '' && $key == 'master_identity') {
                $where .= " AND master_identity='{$id_one}'";
            }
            if ($value != '' && $key == 'guster_identity') {
                $where .= " or guster_identity='{$id_one}'";
            }
        }
        //return $where;
        $list = 10;
        //获取总页数
        $count_list = $accountd->whereRaw($where)->count();
        $count_page = ceil($count_list / $list);
        $first = ($page - 1) * $list;
        $code_datas = $accountd->orderBy('create_time', 'desc')->whereRaw($where)->offset($first)->limit($list)->get();//注单信息
        if (!empty($code_datas)) {
            $code_data = $code_datas->toArray();
        } else {
            return "";
        }


        foreach ($code_data as $k => $val) {
            if ($game_type == 'diceone'){
                if ($val['winstatus'] == '1') {
                    $code_data[$k]['winstatus'] = '中奖';
                }else{
                    $code_data[$k]['winstatus'] = '未中奖';
                }

                $code_data[$k]['game_name'] = '单人快乐骰宝';
            }else{
                if ($val['winner_identity'] == $id_one){
                    $code_data[$k]['winstatus'] = '中奖';
                }else{
                    $code_data[$k]['winstatus'] = '未中奖';
                }

                if ($val['winner_identity'] == $val['master_identity']){
                    $code_data[$k]['codes'] = $val['master_num'];
                    $code_data[$k]['money'] = $val['master_money'];
                }else{
                    $code_data[$k]['codes'] = $val['guster_num'];
                    $code_data[$k]['money'] = $val['guster_money'];
                }
                $code_data[$k]['game_name'] = '双人快乐骰宝';
            }
            $code_data[$k]['coded'] = '查看详情';
            $code_data[$k]['game'] = $game_type;
        }



        $dat = [
            'data' => $code_data,
            'count_page' => $count_page,
            'page' => $page,
        ];
        return $dat;

    }

    //塞子投注详情
    public function DicedataChange($data) {
        $id = isset($data['id']) ? $data['id'] : '';
        $game=isset($data['game']) ? $data['game'] : '';
        $game_name=isset($data['game_name']) ? $data['game_name'] : '';

        $accountd = lm($game, "commons")->where('id',$id)->first();
        if (!empty($accountd)) {
            $accountd = $accountd->toArray();
        } else {
            return "";
        }

        $args = array();
        $buy_code = json_decode($accountd['buycodes'], 1); //该注购买号码
        $prize_code = json_decode($accountd['prizes'], 1); //改注中奖号码

        $paramt = $buy_code;


        if (is_array($paramt) && count($paramt) > 0) {
            $i = 0;
            $a="";
            $s=1;
            foreach ($paramt as $k => $v) {

                if (is_array($v) && count($v) > 0) {

                    foreach ($v as $k1 => $v1) {

                        $args[$i] = array(
                            'gameType' => lang($game)->get($k),
                            'codes' => lang($game)->get($k). '-' . lang($game)->get($k1),
                            'money' => $v1[0],
                            'maybe' => $v1[0] * $v1['settings']['multiple'],
                            'play' => $k,
                            'p_codes' => $a,
                            'p_code' => $k1,
                            'back' => empty($v1['settings']['back']) ? 0 : $v1['settings']['back'],
                        );

                        if (isset($v1['settings']['multiple']['max'])) {
                            $args[$i]['odds'] = $v1['settings']['multiple']['max'];
                        } else {
                            $args[$i]['odds'] = $v1['settings']['multiple'];
                        }
                        if ($data['betstatus'] == 2) {
                            $args[$i]['prize_status'] = '撤单';
                            $args[$i]['get_money']=0;
                        }else {
                            $args[$i]['prize_status'] = '未中奖';
                            $args[$i]['get_money'] = -$v1[0];
                        }
                        $i++;
                        $a="";
                    }

                }

            }

        }

        //中奖判断

        if (is_array($prize_code) && count($prize_code)) {

            //中奖号码
            $paramt = $prize_code['data'];

            foreach ($paramt as $p_k => $p_v) {
                //购买号码
                foreach ($args as $num => $v) {

                    if ($v['play'] == $p_k) {
                        if (is_array($p_v) && count($p_v) > 0) {
                            foreach ($p_v as $p_k1 => $p_v2) {
                                if ($v['p_code'] == $p_k1) {
                                    $args[$num]['prize_status'] = '中奖';
                                    $args[$num]['get_money'] = $v['money'] * $v['odds'] - $v['money'];
                                    break;
                                } else {
                                    $args[$num]['prize_status'] = '未中奖';
                                    $args[$num]['get_money'] = -$v['money'];

                                }
                            }
                        }
                    }
                }
            }
        }

        foreach ($args as $k=>$v){
            $argss[$k]['codes'] = $v['codes']."-".$v['prize_status'];
            $argss[$k]['codeDate'] = $v['gameType'];
            $argss[$k]['money'] = $v['money'];
        }

        if (count($args) >= 2){
            $codeds =$argss[0]['codes'].$argss[1]['codes'];
        }else{
            $codeds =$argss[0]['codes'];
        }

        $da_args['wing_codes'] = $accountd['codes'];
        $da_args['game_no'] = $accountd['id'];
        $da_args['get_money'] = $accountd['winmoney']-$accountd['money'];;
        $da_args['game_type'] = $game_name;;
        $da_args['money'] = $accountd['money'];
        $da_args['codes'] = $accountd['codes'];
        $da_args['codeDate'] = $args[0]['gameType'];
        $da_args['codet'] = $argss;
        $da_args['coded'] = $codeds;
        $da_args['id'] = $accountd['id'];

        return $da_args;
    }

    //双人塞子投注详情
    public function DiceSdataChange($data) {
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $id = isset($data['id']) ? $data['id'] : '';
        $game=isset($data['game']) ? $data['game'] : '';
        $game_name=isset($data['game_name']) ? $data['game_name'] : '';

        $accountd = lm($game, "commons")->where('id',$id)->first();
        if (!empty($accountd)) {
            $accountd = $accountd->toArray();
        } else {
            return "";
        }



        foreach ($accountd as $k=>$v){

            if ($v['winner_identity'] == $id_one){
                $accountd[$k]['winner_type'] ='中奖';
            }else{
                $accountd[$k]['winner_type'] ='未中奖';
            }
            if ($v['winner_identity'] == $v['master_identity']){
                $accountd[$k]['codes'] = $v['master_num'];
                $accountd[$k]['money'] = $v['master_money'];
            }else{
                $accountd[$k]['codes'] = $v['guster_num'];
                $accountd[$k]['money'] = $v['guster_money'];
            }
        }

        foreach ($accountd as $k=>$v){
            $argss[$k]['codeDate'] = '双人';
            $argss[$k]['codes'] = $v['codes']."-".$v['winner_type'];
            $argss[$k]['money'] = $v['money'];
        }
        $da_args['wing_codes'] = $accountd['codes'];
        $da_args['game_no'] = $accountd['id'];
        $da_args['get_money'] = $accountd['win_money']-$accountd['money'];;
        $da_args['game_type'] = $game_name;;
        $da_args['money'] = $accountd['money'];
        $da_args['codet'] = $argss;
        $da_args['id'] = $accountd['id'];


        return $da_args;
    }
    /**
     * 对象数组转为普通数组
     *
     * AJAX提交到后台的JSON字串经decode解码后为一个对象数组，
     * 为此必须转为普通数组后才能进行后续处理，
     * 此函数支持多维数组处理。
     *
     * @param array
     * @return array
     */
    function ObjarrayToArray($obj)
    {
        $ret = array();
        foreach ($obj as $key => $value) {
            if (gettype($value) == "array" || gettype($value) == "object") {
                $ret[$key] = $this->ObjarrayToArray($value);
            } else {
                $ret[$key] = $value;
            }
        }
        return $ret;
    }

    public function getColorCodes()
    {
        return array(
            'coler' => array(
                "code_type" => "coler",
                "code_types" => "coler",
            ),
            'code' => array(
                "code_type" => "code",
                "code_types" => "code",
            ),
            'size_parity' => array(
                "code_type" => "blend",
                "code_types" => "size_parity",
            ),
            'parity' => array(
                "code_type" => "blend",
                "code_types" => "parity",
            ),
            'size' => array(
                "code_type" => "blend",
                "code_types" => "size",
            ),
            'e_size' => array(
                "code_type" => "blend",
                "code_types" => "e_size",
            ),
            'iden' => array(
                "code_type" => "blend",
                "code_types" => "iden",
            ),
        );
    }

    public function getMixCodes()
    {
        return array(
            'coler' => array(
                '0' => 'green',
                '1' => 'red',
                '2' => 'blue',
            ),
            'size_parity' => array(
                '0' => 'Smalldouble',
                '1' => 'Bigdouble',
                '2' => 'Smallsingle',
                '3' => 'Bigsingle',
            ),
            'parity' => array(
                '1' => 'double',
                '2' => 'single',
            ),
            'size' => array(
                '0' => 'Small',
                '1' => 'Big',

            ),
            'e_size' => array(
                '0' => 'Notnum',
                '1' => 'VeryBig',
                '2' => 'VerySmall',
            ),
            'iden' => array(
                '0' => 'NotWin',
                '1' => 'Win',
            ),
        );
    }

    function GetWinStatus()
    {
        return array("1" => "win", "2" => "notwin", "0" => "audit", "3" => "killorder");
    }

    function GetStatus()
    {
        return array("1" => "success", "2" => "fail", "0" => "audits");
    }

    function GetStatut()
    {
        return array("1" => "success", "0" => "fail");
    }

    function GetBuyStatus()
    {
        return array("1" => "Betting", "2" => "Chase", "3" => "ChageOrder");
    }

    function GetMonetType()
    {
        return array(
            "1" => array("name" => "Betting", "opt" => "-", "old" => "+"),
            "2" => array("name" => "ChaseNumber", "opt" => "-", "old" => "+"),
            "3" => array("name" => "killorder", "opt" => "+", "old" => "-"),
            "4" => array("name" => "Winning", "opt" => "+", "old" => "-"),
            "5" => array("name" => "Withdrawals", "opt" => "-", "old" => "+"),
            "6" => array("name" => "Recharge", "opt" => "+", "old" => "-"),
            "7" => array("name" => "Defection", "opt" => "+", "old" => "-"),
            "8" => array("name" => "backwater", "opt" => "+", "old" => "-"),
            "9" => array("name" => "DeductMoney", "opt" => "-", "old" => "-"),
            "10" => array("name" => "Commission", "opt" => "+", "old" => "-"),
            "11" => array("name" => "HandRecharge", "opt" => "+", "old" => "-"),
            "12" => array("name" => "Active", "opt" => "+", "old" => "-"),
            "13" => array("name" => "Give", "opt" => "+", "old" => "-"),
            "14" => array("name" => "Remit", "opt" => "+", "old" => "-"),
            "15" => array("name" => "NoWithdrawals", "opt" => "+", "old" => "-"),
            "16" => array("name" => "redget", "opt" => "+", "old" => "-"),
            "19" => array("name" => "changemoney", "opt" => "+", "old" => "-"),
            "22" => array("name" => "agentrecharge", "opt" => "+", "old" => "-"),
        );
    }

    function GetMoneyStatus()
    {
        return array("1" => "Betting", "2" => "ChaseNumber", '4' => 'ChageOrder', '5' => 'notWithdrawals');
    }

    /**
     * 计算组数
     * @param  [type] $data [description]
     * @return [type]       [description]
     */
    function countNum($data, $money, $type,$multiple='',$game_name)
    {
        $hasNums = array_pop($data); //从数组中弹出最后一个数组
        while (is_array($data) && count($data) > 0) {
            $item = array_pop($data); //从数组中弹出最后一个
            $nums = $hasNums;
            $hasNums = [];
            if (is_array($item) && count($item) > 0) {
                foreach ($item as $k => $v) {
                    if (array_key_exists($k, $item)) {
                        $el = $item[$k]; //转存
                        foreach ($nums as $k2 => $v2) {
                            if (array_key_exists($k2, $nums)) {
                                $el2 = $nums[$k2];
                                if (gettype($el2) == 'string') {
                                    $tmp = explode(',', $el2);
                                    if ($this->checkExists($tmp, $el)) {
                                        continue;
                                    }
                                } else {
                                    if ($el2 == $el) {
                                        continue;
                                    }
                                }
                                $str = $el . ',' . $el2;
                                array_push($hasNums, $str);
                            }
                        }
                    }
                }
            }
        }
        if (count($hasNums) > 1) {
            foreach ($hasNums as $k => $v) {
                if (array_key_exists($k, $hasNums)) {
                    $element = $hasNums[$k];
                }
            }
        }
        $hasNum = array();

        foreach ($hasNums as $a => $b) {
            $hasNum[$a]['codes'] = $b;
            $hasNum[$a]['money'] = $money;
            $hasNum[$a]['show_type'] = lang($game_name)->get($type);
            $hasNum[$a]['show_nos'] = $b;
            $hasNum[$a]['multiple'] = $multiple;
            $hasNum[$a]['codeDate'] = $type;
        }
        return $hasNum;
    }

    function CQcountNum($data, $money, $type)
    {
        $hasNums = array_pop($data); //从数组中弹出最后一个数组

        // dump($data);
        while (is_array($data) && count($data) > 0) {
            $item = array_pop($data); //从数组中弹出最后一个
            $nums = $hasNums;
            $hasNums = [];
            if (is_array($item) && count($item) > 0) {
                foreach ($item as $k => $v) {
                    if (array_key_exists($k, $item)) {
                        $el = $item[$k]; //转存
                        //dump($item);
                        foreach ($nums as $k2 => $v2) {
                            if (array_key_exists($k2, $nums)) {
                                $el2 = $nums[$k2];

                                //dump(gettype($el2));
                                if (gettype($el2) == 'string') {
                                    $tmp = explode(',', $el2);
                                    if ($this->checkExists($tmp, $el)) {
                                        continue;
                                    }
                                } else {
                                    if ($el2 == $el) {
                                        continue;
                                    }
                                }
                                $str = $el . ',' . $el2;
                                array_push($hasNums, $str);
                            }
                        }
                    }
                }
            }
        }
        if (count($hasNums) > 1) {
            foreach ($hasNums as $k => $v) {
                if (array_key_exists($k, $hasNums)) {
                    $element = $hasNums[$k];
                }
            }
        }

        //dump($hasNums);
        foreach ($hasNums as $a => $b) {
            $as = explode(",", $b);
            sort($as);
            $arrs[] = $as;

        }
        foreach ($arrs as $v) {
            $cc[] = implode(',', $v);
        }
        $asb = array_unique($cc);
        foreach ($asb as $v) {
            $adc[] = $v;
        }

        $hasNum = array();
        foreach ($adc as $a => $b) {
            $hasNum[$a]['codes'] = $b;
            $hasNum[$a]['money'] = $money;
            $hasNum[$a]['codeDate'] = $type;
        }
        return $hasNum;
    }

    function checkExists($data, $value)
    {
        foreach ($data as $k => $v) {
            //判断键位是否存在
            if (array_key_exists($k, $data)) {
                $element = $data[$k];
                if ($element == $value) {
                    return true;
                }
            }
        }
        return false;
    }

    function CodeData($data,$game_name)
    {
        $codes = array();
        foreach ($data as $k => $v) {
            $type = $k;
            if (is_array($v) && count($v) > 0) {
                foreach ($v as $k1 => $v1) {
                    $temp = explode('_', $k1);
                    $money = $v[$k1][0];
                    $multiple   =   $v[$k1]['settings']['multiple'];
                    if (!array_key_exists($temp[0] - 1, $codes)) {
                        $codes[$temp[0] - 1] = array();
                        array_push($codes[$temp[0] - 1], intval($temp[1]));
                    } else {
                        array_push($codes[$temp[0] - 1], intval($temp[1]));
                    }
                }
            }
        }
        $tempArr = $this->countNum($codes, $money, $type,$multiple,$game_name);
        return $tempArr;

    }

    function CQCodeData($data, $num)
    {
        $codes = array();
        foreach ($data as $k => $v) {
            $type = $k;
            if (is_array($v) && count($v) > 0) {
                foreach ($v as $k1 => $v1) {
                    $temp = explode('_', $k1);
                    //var_dump($temp);
                    $money = $v[$k1][0];
                    if (!array_key_exists($temp[0] - 1, $codes)) {
                        $codes[] = $temp[1];
                        //array_push($codes[$temp[0] - 1], intval($temp[1]));
                    }
                }
            }
        }
        for ($i = 0; $i < $num; $i++) {
            $bbb[] = array_slice($codes, $i * 1, $num);
        }

        $tempArr = $this->CQcountNum($bbb, $money, $type);
        return $tempArr;

    }
    //号码组合解析排列 is_prtize匹配多少个算中奖，colse表示不中

    /**
     * @param $data
     * @param $num
     * @param string $is_prize 匹配多少个算中奖
     * @param string $is_str 表示是字符串的号码
     * @return mixed
     */
    function CodesData($data, $num, $is_prize = '', $is_str = '', $game = '')
    {
        $codes = array();
        foreach ($data as $k => $v) {
            $type = $k;
            if (is_array($v) && count($v) > 0) {
                foreach ($v as $k1 => $v1) {
                    $money = $v[$k1][0];
                    $multiple   =   $v[$k1]['settings']['multiple'];
                    if ($k == 'series_twospecial'){
                        $codes[]= str_replace('g_','',$k1);
                    }else{
                        $codes[] = $k1;
                    }
                }
            }
        }

        if(count($codes) >= $num){
            $a = $this->Isniu($codes, $num);
        }else{
            $nums = count($codes);
            $a = $this->Isniu($codes, $nums);
        }


        //语言包内容组合
        $sixarr = array('sfsixlottery','sixlottery');
        if (is_array($a)){
            foreach ($a as $k => $v) {
                $codelists[$k]['codes'] = $v;
                $codelists[$k]['money'] = $money;
                $codelists[$k]['multiple'] = $multiple;
                $codelists[$k]['show_nos'] = in_array($game, $sixarr)?$this->ChangeLan($game,$v):$v;
                $codelists[$k]['show_type'] =lang($game)->get($type);
                $codelists[$k]['codeDate'] = $type;
                if (!empty($is_prize)) {
                    $codelists[$k]['is_prize'] = $is_prize;
                }
                if (!empty($is_str)) {
                    $codelists[$k]['is_str'] = $is_str;
                }
                if (!empty($game)) {
                    $codelists[$k]['game'] = $game;
                }
            }
        }else{
              $codelists='';
        }

        return $codelists;

    }

    function CodesDataA($data, $num, $is_prize = '', $is_str = '', $game = '')
    {
        $codes = array();
        foreach ($data as $k => $v) {
            $type = $k;
            if (is_array($v) && count($v) > 0) {
                foreach ($v as $k1 => $v1) {
                    $money = $v[$k1][0];
                    if ($k == 'series_twospecial'){
                        $codes[]= str_replace('g_','',$k1);
                    }
//                    elseif($k == 'join_born'){
//                        $codes[]= str_replace('_N','',$k1);
//                    }
                    else{
                        $codes[] = $k1;
                    }
                }
            }
        }

        $datas=array();
        $datad=array();
        sort($codes);
        if(count($codes) >= $num){
            $a = $this->Isniu($codes, $num);
        }else{
            $nums = count($codes);
            $a = $this->Isniu($codes, $nums);
        }


        foreach ($data as $val){
            foreach ($val as $value){
                if (is_array($a)){
                    foreach ($a as $k=>$v){
                        $datas[$v]=$value;

                    }
                }

            }
        }
        $datad[$type]=$datas;

        return $datad;

    }
    function CodesDatasA($data, $num, $is_prize = '', $is_str = '', $game = '')
    {
        $codes = array();
        foreach ($data as $k => $v) {
            $type = $k;
            if (is_array($v) && count($v) > 0) {
                foreach ($v as $k1 => $v1) {
                    $money = $v[$k1][0];
                    $codes[] = $v1;
                }
            }
        }
        $datas=array();
        $datad=array();
        sort($codes);
        if(count($codes) >= $num){
            $a = $this->Isniu($codes, $num);
        }else{
            $nums = count($codes);
            $a = $this->Isniu($codes, $nums);
        }

        foreach ($a as $k=>$v){
            $datas[$k]=$v;

        }

        $datad[$type]=$datas;
        return $datad;

    }
    function getCombinationToString($arr, $m)
    {
        $result = array();
        if ($m == 1) {
            return $arr;
        }
        if ($m == count($arr)) {
            $result[] = implode(',', $arr);
            return $result;
        }

        $temp_firstelement = $arr[0];
        unset($arr[0]);
        $arr = array_values($arr);
        $temp_list1 = $this->getCombinationToString($arr, ($m - 1));
        foreach ($temp_list1 as $s) {
            $s = $temp_firstelement . ',' . $s;
            $result[] = $s;
        }
        unset($temp_list1);
        $temp_list2 = $this->getCombinationToString($arr, $m);
        foreach ($temp_list2 as $s) {
            $result[] = $s;
        }
        unset($temp_list2);
        return $result;
    }

    function Isniu($codes, $num)
    {
        $r= $this->getCombinationToString($codes, $num);
        $code_names=array();
        return $r;
    }


    function CodesDatas($data, $num, $game_name)
    {
        $codes = array();
        foreach ($data as $k => $v) {
            $type = $k;
            if (is_array($v) && count($v) > 0) {
                foreach ($v as $k1 => $v1) {
                    $money = $v[$k1][0];
                    $multiple   =   $v[$k1]['settings']['multiple'];
                    $codes[] = $k1;
                }
            }
        }
        foreach ($codes as $v) {
            $coded[] = lang($game_name)->get($v);
        }

        if(count(explode('_', $codes[0]))>1){
            $a = $this->PositionGroup($codes,$num);
        }else{
            $a = $this->Isniu($codes, $num);
        }
        $sixarr = array('sfsixlottery','sixlottery');
        foreach ($a as $k => $v) {
            $codelists[$k]['codes'] = $v;
            $codelists[$k]['money'] = $money;
            $codelists[$k]['multiple'] = $multiple;
            $codelists[$k]['show_nos'] = in_array($game_name, $sixarr)?$this->ChangeLan($game_name,$v):$v;
            $codelists[$k]['show_type'] = in_array($game_name, $sixarr)? lang($game_name)->get($type):lang($game_name)->get($type);
            $codelists[$k]['codeDate'] = $type;
        }
        return $codelists;

    }

    //按位置分组，不同位置号码可相同
    private function PositionGroup($codes,$num){
        $arr = array();
        $tarr = array();
        $tc = '';
        $i = 0;
        $j = 0;
        foreach ($codes as $k => $v) {
            $i = 0;
            $cs = explode('_', $v);
            if(!empty($tc) && $tc!=$cs[0]){
                $j = 0;
                $tarr = $arr;
                $arr = array();
            }
            if(empty($tarr)){
                $arr[][$cs[0]] = $v;
            }else{
                $arr = array_merge($arr,$tarr);
                $n = count($arr);
                $i = $j;
                for($i=$j;$i<$n;$i++){
                    if(isset($arr[$i][$cs[0]]))break;
                    $arr[$i][$cs[0]] = $v;
                    $j++;
                }
            }
            $tc = $cs[0];
        }
        foreach ($arr as $key => $value) {
            $arr[$key] = implode(',', $value);
        }
        return $arr;
    }

    function currentTotalMoney($data, $money, $joins)
    {
        $codes = array();
        $tempMoney = 0;
        foreach ($data as $k => $v) {
            $class = explode('-', $v['name']);
            $class[0] = str_replace('_', '', $class[0]);
            $obj = $joins[$class[0]];
            if (!$obj) {
                // toLog('-3223-' . "{$class[0]}");
                return -3223;
            }
            if ($obj->getCalcRule() == 'spesc') {
                $tempMoney = $tempMoney + $v['price'];
                $one_price = $v['price'];
                $temp = explode('_', $class[1]);
                // $codes[$temp[0]] = array();
                // array_push($codes[$temp[0]], $temp[1]);
                if (!array_key_exists($temp[0] - 1, $codes)) {
                    $codes[$temp[0] - 1] = array();
                }
                array_push($codes[$temp[0] - 1], intval($temp[1]));
            }
        }

        $countarr = $this->countNum($data, $obj->num);
        $money_codes = $one_price * $countarr;
        $truemoeny = ($money - $tempMoney) > 0 ? $money - $tempMoney : 0;
        $num = $truemoeny + $money_codes;
        // dump($num);
        return $num;
    }

    function countNums($codes, $num)
    {
        $a = count($codes);//总号码数
        if ($a < $num) {
            return -2127;
        }
        $total = 1;
        for ($i = $a; $i >= 1; $i--) {
            if ($i > $a - $num) {
                $total *= $i;
            }
        }
        for ($i = $num; $i >= 1; $i--) {
            $total /= $i;
        }
        //dump($a);
        return $total;
    }

    function prizeChange($params,$gamename){
        if (is_array($params) && count($params) > 0) {
            foreach ($params as $k => $v) {
                if (is_array($v) && count($v) > 0) {
                    foreach ($v as $k1 => $v1) {
                        $args[] = array('codes' => lang($gamename)->get($k . '-' . $v1), 'codeDate' => $k);
                    }
                }else{
                    $args[] = array('codes' => lang($gamename)->get($k . '-' . $v), 'codeDate' => $k);
                }
            }
        }
        return $args;
    }

    function PrizeData($data)
    {
        $codes = array();
        foreach ($data as $k => $v) {
            $type = $k;
            if (is_array($v) && count($v) > 0) {
                foreach ($v as $k1 => $v1) {
                    $temp = explode('_', $v1);
                    if (!array_key_exists($temp[0] - 1, $codes)) {
                        $codes[$temp[0] - 1] = array();
                        array_push($codes[$temp[0] - 1], intval($temp[1]));
                    } else {
                        array_push($codes[$temp[0] - 1], intval($temp[1]));
                    }
                }
            }
        }
        $tempArr = $this->countNum($codes, 0, $type);
        return $tempArr;

    }

    function PrizesDatas($data, $num, $game_name)
    {
        $codes = array();
        foreach ($data as $k => $v) {
            $type = $k;
            if (is_array($v) && count($v) > 0) {
                foreach ($v as $k1 => $v1) {
                    $codes[] = $v1;
                }
            }
        }
        foreach ($codes as $v) {
            $coded[] = lang($game_name)->get($v);
        }
        $a = $this->Isniu($codes, $num);
        foreach ($a as $k => $v) {
            $codelists[$k]['codes'] = $v;
            $codelists[$k]['codeDate'] = $type;
        }
        return $codelists;
    }

    /**
     * @param $data
     * @param $num
     * @param string $is_prize 匹配多少个算中奖
     * @param string $is_str 表示是字符串的号码
     * @return mixed
     */
    function PrizesData($data, $num, $is_prize = '', $is_str = '', $game = '')
    {
        $codes = array();
        foreach ($data as $k => $v) {
            $type = $k;
            if (is_array($v) && count($v) > 0) {
                foreach ($v as $k1 => $v1) {
                    if ($k == 'series_twospecial'){
                        $codes[]= str_replace('g_','',$v1);
                    }else{
                        $codes[] = $v1;
                    }
                }
            }
        }

        if(count($codes) >= $num){
            $a = $this->Isniu($codes, $num);
        }else{
            $nums = count($codes);
            $a = $this->Isniu($codes, $nums);
        }

        //语言包内容组合
        if (is_array($a)){
            foreach ($a as $k => $v) {
                $codelists[$k]['codes'] = $v;
                $codelists[$k]['codeDate'] = $type;
                if (!empty($is_prize)) {
                    $codelists[$k]['is_prize'] = $is_prize;
                }
                if (!empty($is_str)) {
                    $codelists[$k]['is_str'] = $is_str;
                }
                if (!empty($game)) {
                    $codelists[$k]['game'] = $game;
                }
            }
        }else{
              $codelists='';
        }
        return $codelists;
    }



    function PrizeDetails($data_paramt,$game_name){
        if (array_key_exists("sum_born", $data_paramt)) {
            $paramt = $this->prizeChange($data_paramt, $game_name);
            foreach ($data_paramt as $k =>$v){
                foreach ($v as $kk => $vv){
                    if ($vv == 2){
                        foreach ($paramt as $k=>$v){
                            $paramt[$k]['codes']='总肖-234';
                        }
                    }else{
                        $paramt=$this->prizeChange($datat, $game_name);
                    }
                }
            }
        }elseif (array_key_exists("head_three", $data_paramt)) {
            $paramt = $this->PrizeData($data_paramt);
        } elseif (array_key_exists("head_two", $data_paramt)) {
            $paramt = $this->PrizeData($data_paramt);
        } elseif (array_key_exists("specialthree", $data_paramt)) {
            //特码包3
            $stdp['specialthree'] = $data_paramt['specialthree'];
            $paramt = $this->PrizesData($stdp, 3, 1);
            $paramt1 = $this->prizeChange($data_paramt, $game_name);
            foreach ($paramt1 as $stk => $stv) {
                if($stv['codeDate']!='specialthree'){
                    $paramt[] = $stv;
                }
            }
        }elseif (array_key_exists("series_twospecial", $data_paramt)) {
            //二中特
            $paramt = $this->PrizesData($data_paramt, 2, 2, 1);
        } elseif (array_key_exists("series_four", $data_paramt)) {
            //4全中
            $paramt = $this->PrizesData($data_paramt, 4, 4);
        } elseif (array_key_exists("series_three", $data_paramt)) {
            //三全中
            $paramt = $this->PrizesData($data_paramt, 3, 3);
        }elseif (array_key_exists("twodiffnum", $data_paramt)) {
            //二不同号
            $paramt = $this->PrizesData($data_paramt, 2, 2);
        }elseif (array_key_exists("thdiffnum", $data_paramt)) {
            //三不同号
            $paramt = $this->PrizesData($data_paramt, 3, 3);
        } elseif (array_key_exists("series_specialmix", $data_paramt)) {
            $paramt = $this->PrizesData($data_paramt, 2);
        } elseif (array_key_exists("series_two", $data_paramt)) {
            //二全中
            $paramt = $this->PrizesData($data_paramt, 2, 2);
        } elseif (array_key_exists("series_threetwo", $data_paramt)) {
            //三种二
            $paramt = $this->PrizesData($data_paramt, 3, 2);
        } elseif (array_key_exists("series_fiveborn", $data_paramt)) {
            $paramt = $this->PrizesDatas($data_paramt, 5, $game_name);
        } elseif (array_key_exists("series_fourborn", $data_paramt)) {
            $paramt = $this->PrizesDatas($data_paramt, 4, $game_name);
        } elseif (array_key_exists("series_threeborn", $data_paramt)) {
            $paramt = $this->PrizesDatas($data_paramt, 3, $game_name);
        } elseif (array_key_exists("series_twoborn", $data_paramt)) {
            $paramt = $this->PrizesDatas($data_paramt, 2, $game_name);
        } elseif (array_key_exists("series_fiveend", $data_paramt)) {
            //
            $paramt = $this->PrizesData($data_paramt, 5);
        } elseif (array_key_exists("series_fourend", $data_paramt)) {
            //4尾碰
            $paramt = $this->PrizesData($data_paramt, 4);
        } elseif (array_key_exists("series_threeend", $data_paramt)) {
            //三尾碰
            $paramt = $this->PrizesData($data_paramt, 3);
        } elseif (array_key_exists("series_twoend", $data_paramt)) {
            $paramt = $this->PrizesData($data_paramt, 2);
        } elseif (array_key_exists("selfselect_fivelose", $data_paramt)) {
            //五不中
            $paramt = $this->PrizesData($data_paramt, 5, 5);
        } elseif (array_key_exists("selfselect_sevenlose", $data_paramt)) {
            //七不中
            $paramt = $this->PrizesData($data_paramt, 7, 7);
        } elseif (array_key_exists("selfselect_ninelose", $data_paramt)) {
            //九不中
            $paramt = $this->PrizesData($data_paramt, 9, 9);
        } elseif (array_key_exists("selfselect_sixlose", $data_paramt)) {
            //六不中
            $paramt = $this->PrizesData($data_paramt, 6, 6);
        } elseif (array_key_exists("selfselect_tenlose", $data_paramt)) {
            //十不中
            $paramt = $this->PrizesData($data_paramt, 10, 10);
        } elseif (array_key_exists("selfselect_twelvelose", $data_paramt)) {
            //十二不中
            $paramt = $this->PrizesData($data_paramt, 12, 12);
        } elseif (array_key_exists("selfselect_elevenlose", $data_paramt)) {
            //十一不中
            $paramt = $this->PrizesData($data_paramt, 11, 11);
        } elseif (array_key_exists("selfselect_eightlose", $data_paramt)) {
            $paramt = $this->PrizesData($data_paramt, 8, 8);
        }else {
            $paramt = $this->prizeChange($data_paramt, $game_name);
        }
        return $paramt;
    }


    function CodesDetails($data_paramt,$game_name,$identity_no){

        $tab_name = "bjpk10Parse";
        $nums = C()->get($tab_name);
        if (array_key_exists("sum_born", $data_paramt)) {
            $datat = [
                'codes' => $identity_no['codes'],
            ];
            $paramt = $nums->change($datat, $game_name);
            foreach ($data_paramt as $k =>$v){
                foreach ($v as $kk => $vv){
                    if ($kk == 2){
                        foreach ($paramt as $k=>$v){
                            $paramt[$k]['codes']='总肖-234';
                        }
                    }else{
                        $paramt=$nums->change($datat, $game_name);
                    }
                }
            }

        }elseif (array_key_exists("head_three", $data_paramt)) {
            $paramt = $this->CodeData($data_paramt,$game_name);
        } elseif (array_key_exists("head_two", $data_paramt)) {
            $paramt = $this->CodeData($data_paramt,$game_name);
        } elseif (array_key_exists("specialthree", $data_paramt)) {
            //特码包3
            $stdp['specialthree'] = $data_paramt['specialthree'];
            $paramt = $this->CodesData($stdp, 3, 1,'',$game_name);
            $datat = [
                'codes' => $identity_no['codes'],
            ];
            $paramt1 = $nums->change($datat, $game_name);
            foreach ($paramt1 as $stk => $stv) {
                if($stv['codeDate']!='specialthree'){
                    $paramt[] = $stv;
                }
            }
        }elseif (array_key_exists("series_twospecial", $data_paramt)) {
            //二中特
            $paramt = $this->CodesData($data_paramt, 2, 2, 1,$game_name);
        } elseif (array_key_exists("series_four", $data_paramt)) {
            //4全中
            $paramt = $this->CodesData($data_paramt, 4, 4,'',$game_name);
        } elseif (array_key_exists("series_three", $data_paramt)) {
            //三全中
            $paramt = $this->CodesData($data_paramt, 3, 3,'',$game_name);
        }elseif (array_key_exists("twodiffnum", $data_paramt)) {
            //二不同号
            $paramt = $this->CodesData($data_paramt, 2, 2,'',$game_name);
        }elseif (array_key_exists("thdiffnum", $data_paramt)) {
            //三不同号
            $paramt = $this->CodesData($data_paramt, 3, 3,'',$game_name);
        } elseif (array_key_exists("series_specialmix", $data_paramt)) {
            $paramt = $this->CodesData($data_paramt, 2,'','',$game_name);
        } elseif (array_key_exists("series_two", $data_paramt)) {
            //二全中
            $paramt = $this->CodesData($data_paramt, 2, 2,'',$game_name);
        } elseif (array_key_exists("series_threetwo", $data_paramt)) {
            //三种二
            $paramt = $this->CodesData($data_paramt, 3, 2,'',$game_name);
        } elseif (array_key_exists("series_fiveborn", $data_paramt)) {
            $paramt = $this->CodesDatas($data_paramt, 5, $game_name);
        } elseif (array_key_exists("series_fourborn", $data_paramt)) {
            $paramt = $this->CodesDatas($data_paramt, 4, $game_name);
        } elseif (array_key_exists("series_threeborn", $data_paramt)) {
            $paramt = $this->CodesDatas($data_paramt, 3, $game_name);
        } elseif (array_key_exists("series_twoborn", $data_paramt)) {
            $paramt = $this->CodesDatas($data_paramt, 2, $game_name);
        } elseif (array_key_exists("series_fiveend", $data_paramt)) {
            //
            $paramt = $this->CodesData($data_paramt, 5,'','',$game_name);
        } elseif (array_key_exists("series_fourend", $data_paramt)) {
            //4尾碰
            $paramt = $this->CodesData($data_paramt, 4,'','',$game_name);
        } elseif (array_key_exists("series_threeend", $data_paramt)) {
            //三尾碰
            $paramt = $this->CodesData($data_paramt, 3,'','',$game_name);
        } elseif (array_key_exists("series_twoend", $data_paramt)) {
            $paramt = $this->CodesData($data_paramt, 2,'','',$game_name);
        } elseif (array_key_exists("selfselect_fivelose", $data_paramt)) {
            //五不中
            $paramt = $this->CodesData($data_paramt, 5, 5,'',$game_name);
        } elseif (array_key_exists("selfselect_sevenlose", $data_paramt)) {
            //七不中
            $paramt = $this->CodesData($data_paramt, 7, 7,'',$game_name);
        } elseif (array_key_exists("selfselect_ninelose", $data_paramt)) {
            //九不中
            $paramt = $this->CodesData($data_paramt, 9, 9,'',$game_name);
        } elseif (array_key_exists("selfselect_sixlose", $data_paramt)) {
            //六不中
            $paramt = $this->CodesData($data_paramt, 6, 6,'',$game_name);
        } elseif (array_key_exists("selfselect_tenlose", $data_paramt)) {
            //十不中
            $paramt = $this->CodesData($data_paramt, 10, 10,'',$game_name);
        } elseif (array_key_exists("selfselect_twelvelose", $data_paramt)) {
            //十二不中
            $paramt = $this->CodesData($data_paramt, 12, 12,'',$game_name);
        } elseif (array_key_exists("selfselect_elevenlose", $data_paramt)) {
            //十一不中
            $paramt = $this->CodesData($data_paramt, 11, 11,'',$game_name);
        } elseif (array_key_exists("selfselect_eightlose", $data_paramt)) {
            $paramt = $this->CodesData($data_paramt, 8, 8,'',$game_name);
        }else {

            $datat = [
                'codes' => $identity_no['codes'],
            ];

            $paramt = $nums->change($datat, $game_name);
        }
        return $paramt;
    }

    function PccodeDetails($buy_code){

        if (array_key_exists("sum_born", $buy_code)) {

            foreach ($buy_code as $k =>$v){
                $type = $k;
                foreach ($v as $kk => $vv){
                    if ($kk == 2){
                        $param['234']=$vv;
                    }else{
                        $param[$kk]=$vv;
                    }
                }

            }
            $paramt[$type] = $param;
        }   elseif (array_key_exists("specialthree", $buy_code)) {
            $st_bcode['specialthree'] = $buy_code['specialthree'];
            $paramt = $this->CodesDataA($st_bcode, 3, 1);
            $buy_code['specialthree'] = $paramt['specialthree'];
            $paramt = $buy_code;
        }elseif (array_key_exists("series_twospecial", $buy_code)) {
            //二中特
            $paramt = $this->CodesDataA($buy_code, 2, 2, 1);
        } elseif (array_key_exists("series_four", $buy_code)) {
            //四全中
            $paramt = $this->CodesDataA($buy_code, 4, 4);
        } elseif (array_key_exists("series_three", $buy_code)) {
            //三全中
            $paramt = $this->CodesDataA($buy_code, 3, 3);
        } elseif (array_key_exists("thdiffnum", $buy_code)) {
            //三不同号
            $paramt = $this->CodesDataA($buy_code, 3, 3);
        } elseif (array_key_exists("twodiffnum", $buy_code)) {
            //二不同号
            $paramt = $this->CodesDataA($buy_code, 2, 2);
        } elseif (array_key_exists("series_specialmix", $buy_code)) {
            //特串
            $paramt = $this->CodesDataA($buy_code, 2, 2);
        } elseif (array_key_exists("series_two", $buy_code)) {
            //二全中
            $paramt = $this->CodesDataA($buy_code, 2, 2);
        } elseif (array_key_exists("series_threetwo", $buy_code)) {
            //三种二
            $paramt = $this->CodesDataA($buy_code, 3, 2);
        } elseif (array_key_exists("series_fiveborn", $buy_code)) {
            $paramt = $this->CodesDataA($buy_code, 5, 5, '');
        } elseif (array_key_exists("series_fourborn", $buy_code)) {
            $paramt = $this->CodesDataA($buy_code, 4, 4, '');
        } elseif (array_key_exists("series_threeborn", $buy_code)) {
            $paramt = $this->CodesDataA($buy_code, 3, 3, '');
        } elseif (array_key_exists("series_twoborn", $buy_code)) {
            $paramt = $this->CodesDataA($buy_code, 2, 2, '');
        } elseif (array_key_exists("series_fiveend", $buy_code)) {
            //五尾碰
            $paramt = $this->CodesDataA($buy_code, 5, 5);
        } elseif (array_key_exists("series_fourend", $buy_code)) {
            $paramt = $this->CodesDataA($buy_code, 4, 4);
        } elseif (array_key_exists("series_threeend", $buy_code)) {
            $paramt = $this->CodesDataA($buy_code, 3, 3);
        } elseif (array_key_exists("series_twoend", $buy_code)) {
            //二尾碰
            $paramt = $this->CodesDataA($buy_code, 2, 2);
        } elseif (array_key_exists("selfselect_fivelose", $buy_code)) {
            //五不中
            $paramt = $this->CodesDataA($buy_code, 5, 5);
        } elseif (array_key_exists("selfselect_sevenlose", $buy_code)) {
            //七不中
            $paramt = $this->CodesDataA($buy_code, 7, 7);
        } elseif (array_key_exists("selfselect_ninelose", $buy_code)) {
            //九不中
            $paramt = $this->CodesDataA($buy_code, 9, 9);
        } elseif (array_key_exists("selfselect_sixlose", $buy_code)) {
            //六不中
            $paramt = $this->CodesDataA($buy_code, 6, 6);
        } elseif (array_key_exists("selfselect_tenlose", $buy_code)) {
            //十不中
            $paramt = $this->CodesDataA($buy_code, 10, 10);
        } elseif (array_key_exists("selfselect_twelvelose", $buy_code)) {
            //十二不中
            $paramt = $this->CodesDataA($buy_code, 12, 12);
        } elseif (array_key_exists("selfselect_elevenlose", $buy_code)) {
            //十一不中
            $paramt = $this->CodesDataA($buy_code, 11, 11);
        } elseif (array_key_exists("selfselect_eightlose", $buy_code)) {
            //八不中
            $paramt = $this->CodesDataA($buy_code, 8, 8);
        }elseif (array_key_exists("join_born", $buy_code)) {
            //八不中
            $paramt = $this->CodesDataA($buy_code, 1, 1);
        }else{
            $paramt= $buy_code;
        }
        return $paramt;
    }

    function PcWincodeDetails($prize_code,$datass,$datd,$cc,$bb,$buy_code){
        if (array_key_exists("head_three", $prize_code)) {
            $paramt = $this->CodeData($prize_code);
        } elseif (array_key_exists("head_two", $prize_code)) {
            $paramt = $this->CodeData($prize_code);
        }elseif (array_key_exists("series_twospecial", $prize_code)) {
            //二中特
            $paramt = $this->CodesDatasA($datass, 2, 2, 1);
        } elseif (array_key_exists("series_four", $prize_code)) {
            //四全中
            $paramt = $this->CodesDatasA($datd, 4, 4);
        } elseif (array_key_exists("series_three", $prize_code)) {
            //三全中
            $paramt = $this->CodesDatasA($datd, 3, 3);
        }elseif (array_key_exists("thdiffnum", $prize_code)) {
            //三不同号
            $paramt = $this->CodesDatasA($prize_code, 3, 3);
        }elseif (array_key_exists("twodiffnum", $prize_code)) {
            //二不同号
            $paramt = $this->CodesDatasA($prize_code, 2, 2);
        } elseif (array_key_exists("series_specialmix", $prize_code)) {
            //特串
            $paramt = $this->CodesDatasA($datass, 2, 2);
        } elseif (array_key_exists("series_two", $prize_code)) {
            //二全中
            $paramt = $this->CodesDatasA($datd, 2, 2);
        } elseif (array_key_exists("series_threetwo", $prize_code)) {
            //三种二
            $paramt = $this->CodesDatasA($datass, 3, 2);
        } elseif (array_key_exists("series_fiveborn", $prize_code)) {
            $paramt = $this->CodesDatasA($prize_code, 5, 5, '');
        } elseif (array_key_exists("series_fourborn", $prize_code)) {
            $paramt = $this->CodesDatasA($prize_code, 4, 4, '');
        } elseif (array_key_exists("series_threeborn", $prize_code)) {
            $paramt = $this->CodesDatasA($prize_code, 3, 3, '');
        } elseif (array_key_exists("series_twoborn", $prize_code)) {
            $paramt = $this->CodesDatasA($prize_code, 2, 2, '');
        } elseif (array_key_exists("series_fiveend", $prize_code)) {
            //五尾碰
            if (count($cc) >= 5){
                $paramt = $this->CodesDatasA($bb, 5, 5);
            }else{
                $paramt = $this->CodesDatasA($datass, 5, 5);
            }
        } elseif (array_key_exists("series_fourend", $prize_code)) {
            if (count($cc) >= 4){
                $paramt = $this->CodesDatasA($bb, 4, 4);
            }else{
                $paramt = $this->CodesDatasA($datass, 4, 4);
            }
        } elseif (array_key_exists("series_threeend", $prize_code)) {
            if (count($cc) >= 3){
                $paramt = $this->CodesDatasA($bb, 3, 3);
            }else{
                $paramt = $this->CodesDatasA($datass, 3, 3);
            }
        } elseif (array_key_exists("series_twoend", $prize_code)) {
            //二尾碰
            if (count($cc) >= 2){
                $paramt = $this->CodesDatasA($bb, 2, 2);
            }else{
                $paramt = $this->CodesDatasA($datass, 2, 2);
            }
        } elseif (array_key_exists("selfselect_fivelose", $buy_code)) {
            //五不中
            $paramt = $datass;
        } elseif (array_key_exists("selfselect_sevenlose", $buy_code)) {
            //七不中
            $paramt = $datass;
        } elseif (array_key_exists("selfselect_ninelose", $buy_code)) {
            //九不中
            $paramt = $datass;
        } elseif (array_key_exists("selfselect_sixlose", $buy_code)) {
            //六不中
            $paramt = $datass;
        } elseif (array_key_exists("selfselect_tenlose", $buy_code)) {
            //十不中
            $paramt = $datass;
        } elseif (array_key_exists("selfselect_twelvelose", $buy_code)) {
            //十二不中
            $paramt = $datass;
        } elseif (array_key_exists("selfselect_elevenlose", $buy_code)) {
            //十一不中
            $paramt = $datass;
        } elseif (array_key_exists("selfselect_eightlose", $buy_code)) {
            //八不中
            $paramt = $datass;
        }else{
            $paramt= $prize_code;
        }
        return $paramt;
    }
    function Win($args,$p_k,$p_v,$v,$arry,$num,$arrys,$odds,$dataw,$asd,$prize_num,$asse,$bb,$asb){

        if (in_array($p_k, $arry)) {
            $not_num = 2;
            foreach ($p_v as $p_k1 => $p_v2) {
                $datas = explode(',', $v['p_code']);
                foreach ($datas as $vss){
                    if ($vss == $p_v2){
                        $not_num =1;
                        break;
                    }
                }
            }
            if ($not_num == 2){
                $args[$num]['prize_status'] = '中奖';
                $args[$num]['get_money'] = $v['money'] * $v['odds']- $v['money'];;

            } else {
                $args[$num]['prize_status'] = '未中奖';
                $args[$num]['get_money'] = -$v['money'];
            }

        } elseif (in_array($p_k, $arrys)) {
            foreach ($p_v as $p_k1 => $p_v2) {
                $datass = explode(',', $p_v2);
                $datas2 = explode(',', $v['p_code']);
//                                    var_dump($datas1,$datas2);
                foreach ($datass as $va) {

                    $datas1[] = intval($va);

                }
                if (count($datas1) == 2 ) {
                    if ($v['p_code'] == $p_v2){
//                                            echo 1;
                        $args[$num]['prize_status'] = '中奖';
                        $args[$num]['get_money'] = $v['money'] * $odds[$p_k]['settings']['multiple']['max'] - $v['money'];
                        $args[$num]['odds'] = $odds[$p_k]['settings']['multiple']['max'];
                    }

                    if($v['p_code'] == $p_v2 && stripos($v['p_code'], $dataw[6]) !== false) {
                        $args[$num]['prize_status'] = '中奖';
                        $args[$num]['odds'] = $odds[$p_k]['settings']['multiple']['min'];
                        $args[$num]['get_money'] = $v['money'] * $odds[$p_k]['settings']['multiple']['min'] - $v['money'];
//                                            break;
                    }
                }

                if (count($datas1) == 3 ) {
                    if ($v['p_code'] == $p_v2){
//                                            echo 1;
                        $args[$num]['prize_status'] = '中奖';
                        $args[$num]['get_money'] = $v['money'] * $odds[$p_k]['settings']['multiple']['min'] - $v['money'];
                        $args[$num]['odds'] = $odds[$p_k]['settings']['multiple']['min'];
                        break;
                    }

                    $intersection = array_intersect($datas1, $datas2);

                    if(count($intersection) == 2 && $v['p_code'] != $p_v2) {
//                                            var_dump($intersection);
                        $args[$num]['prize_status'] = '中奖';
                        $args[$num]['odds'] = $odds[$p_k]['settings']['multiple']['max'];
                        $args[$num]['get_money'] = $v['money'] * $odds[$p_k]['settings']['multiple']['max'] - $v['money'];
//                                            break;
                    }

                }
                unset($datas1);
            }
        }elseif (in_array($p_k, $asd)) {
            $datas1 = explode(',', $prize_num);
            if (in_array(49, $datas1)) {
                $args[$num]['prize_status'] = '和';
                $args[$num]['odds'] = 1;
                $args[$num]['get_money'] = $v['money'];
            } else {
                foreach ($p_v as $p_k1 => $p_v2) {
                    if ($v['p_code'] == $p_v2) {
                        $args[$num]['prize_status'] = '中奖';
                        $args[$num]['get_money'] = $v['money'] * $v['odds'] - $v['money'];
                        break;
                    } else {
                        $args[$num]['prize_status'] = '未中奖';
                        $args[$num]['get_money'] = -$v['money'];
                    }
                }
            }
        }

        elseif(in_array($p_k,$asse)){

            foreach ($asse as   $kk=> $vv){
                if (count($bb) < $kk){
                    $args[$num]['prize_status'] = '未中奖';
                    $args[$num]['get_money'] = -$v['money'];
                }
            }
            foreach ($p_v as $p_k1 => $p_v2) {
                if ($v['p_code'] == $p_v2) {
                    $args[$num]['prize_status'] = '中奖';
                    $args[$num]['get_money'] = $v['money'] * $v['odds'] - $v['money'];
                    break;
                } else {
                    $args[$num]['prize_status'] = '未中奖';
                    $args[$num]['get_money'] = -$v['money'];
                }
            }

        }elseif ($p_k == 'series_specialmix') {
            foreach ($p_v as $p_k1 => $p_v2) {
                if ($v['p_code'] == $p_v2 && stripos($v['p_code'], $dataw[6]) !== false) {
                    $args[$num]['prize_status'] = '中奖';
                    $args[$num]['get_money'] = $v['money'] * $v['odds'] - $v['money'];
                    break;
                } else {

                    $args[$num]['prize_status'] = '未中奖';
                    $args[$num]['get_money'] = -$v['money'];

                }

            }
        }elseif ($p_k == 'specialthree') {
            foreach ($p_v as $p_k1 => $p_v2) {
                $stcodes = explode(',', $v['p_code']);
                if(in_array($p_v2, $stcodes)){
                    $args[$num]['prize_status'] = ($p_v2==13 || $p_v2==14)?'和':'中奖';
                    $v['odds'] = ($p_v2==13 || $p_v2==14)?1:$v['odds'];
                    $args[$num]['get_money'] = $v['money'] * $v['odds'] - $v['money'];
                    break;
                } else {
                    $args[$num]['prize_status'] = '未中奖';
                    $args[$num]['get_money'] = -$v['money'];
                }
            }
        }elseif ($p_k == 'seven_colorwave') {

            foreach ($p_v as $p_k1 => $p_v2) {

                if ($v['p_code'] == $p_v2 && $v['p_code'] == 'draw') {
                    $args[$num]['prize_status'] = '中奖';
                    $args[$num]['get_money'] = ($v['money'] * $v['odds'] + $v['back']) - $v['money'];
                    break;
                } else {
                    $args[$num]['prize_status'] = '和';
                    $args[$num]['get_money'] = 0;
                }

                if ($v['p_code'] == $p_v2 ) {
                    $args[$num]['prize_status'] = '中奖';
                    $args[$num]['get_money'] = ($v['money'] * $v['odds'] + $v['back']) - $v['money'];
                    break;
                } else {
                    $args[$num]['prize_status'] = '未中奖';
                }
            }
        }
        elseif(in_array($p_k,$asb)){

            if (isset($v['prize_status'])){
                if ($v['prize_status'] == "和"){
                    $args[$num]['prize_status'] = '和';
                    $args[$num]['odds'] = 1;
                    $args[$num]['get_money'] = $v['money'];
                }else{
                    foreach ($p_v as $p_k1 => $p_v2) {
                        if ($v['p_code'] == $p_v2) {
                            $args[$num]['prize_status'] = '中奖';
                            $args[$num]['get_money'] = $v['money'] * $v['odds'] - $v['money'];
                            break;
                        } else {
                            $args[$num]['prize_status'] = '未中奖';
                            $args[$num]['get_money'] = -$v['money'];
                        }
                    }
                }
            }else{
                foreach ($p_v as $p_k1 => $p_v2) {
                    if ($v['p_code'] == $p_v2) {
                        $args[$num]['prize_status'] = '中奖';
                        $args[$num]['get_money'] = $v['money'] * $v['odds'] - $v['money'];
                        break;
                    } else {
                        $args[$num]['prize_status'] = '未中奖';
                        $args[$num]['get_money'] = -$v['money'];
                    }
                }
            }

        }else {
            foreach ($p_v as $p_k1 => $p_v2) {
                if ($v['p_code'] == $p_v2) {
                    $args[$num]['prize_status'] = '中奖';
                    $args[$num]['get_money'] = $v['money'] * $v['odds'] - $v['money'];
                    break;
                } else {
                    $args[$num]['prize_status'] = '未中奖';
                    $args[$num]['get_money'] = -$v['money'];
                }
            }
        }

        return $args;
    }

    /*
     *提现限额
     */
    function recordWithdraw($type=1,$account_identity,$money=0,$donate_money,$percent=1,$remark=''){
        //用户id
        if(empty($account_identity)){
            return -50020;
        }
        //本金
        if($money < 0){
            return -50021;
        }
        //彩金
        if($donate_money < 0){
            return -50022;
        }
        //倍数
        if(empty($percent)){
            return -50023;
        }
        $widthdraw = lm('WithDrawRule',"commons")->where('account_identity',$account_identity)->first();
        $account = lm('Account_detailed',"commons")->where('account_identity',$account_identity)->first();
        if(!empty($account)){
            $account = $account->toArray();
        }else{
            return -50024;
        }

        $data['updated_at'] = date('Y-m-d H:i:s');
        $total = $money+$donate_money;
        if(!empty($widthdraw)){
            $widthdraw = $widthdraw->toArray();
            $data['needBettingMoney'] = $total*$percent+$widthdraw['needBettingMoney'];
            if(empty($widthdraw['donate_start'])){
                $data['donate_start'] = date('Y-m-d H:i:s');
            }
            $res=lm('WithDrawRule', 'commons')->where('account_identity', $account_identity)->update($data);

        }else{
            $data['bettingMoney'] = 0;
            $data['needBettingMoney'] = $total*$percent;
            $data['account_identity'] = $account_identity;
            $data['created_at'] = date('Y-m-d H:i:s');
            $data['start_time'] = time();
            $data['donate_start'] = date('Y-m-d H:i:s');
            $res=lm ('WithDrawRule', 'commons')->insert($data);
        }

        return $res;
    }

    //有效投注统计
    function EffectiveBetting($data,$c=-1)
    {
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $page = isset($data['page']) ? $data['page'] : 1;
        //$start = isset($data['start']) ? $data['start'] : '';
        //$end = isset($data['end']) ? $data['end'] : '';
        $time = isset($data['time']) ? $data['time'] : '';
        $start = '';
        $end = '';
        if(!empty($time)){//qtx 2018-12-11
            $newtime = explode('~',$time);
            if(count($newtime) ==2){
                $start = $newtime[0].' 00:00:00';
                $end = $newtime[1].' 23:59:59';
            }else{
                $start = $time;
                $end = date("Y-m-d", strtotime("+1 day", strtotime($time)));
            }
        }
        if (empty($id_one)) {
            return -4010;
        }
        $where = "account_identity = '". $id_one ."' AND status < 4 AND game_status > 0";
        $wheretwo = "account_identity = '". $id_one."'";
        //时间段
        if(!empty($start) && !empty($end))
        {
            $where .= " AND money_time >= '".$start."' AND money_time <= '".$end."'";
            $wheretwo .= " AND money_time >= '".$start."' AND money_time <= '".$end."'";
        }
        //时间段，只有开始
        if(!empty($start) && empty($end))
        {
            $where .= " AND money_time >= '".$start."'";
            $wheretwo .= " AND money_time >= '".$start."'";
        }
        //时间段，只有结束
        if(empty($start) && !empty($end))
        {
            $where .= " AND money_time <= '".$end."'";
            $wheretwo .= " AND money_time <= '".$end."'";
        }
        //print_r($where); exit;
        $filed = ['order_id','game_name','game_no','money','prize_money','game_status','money_time'];
        //dump($where);
        $rows = lm("money_buy", "commons")->whereRaw($where)->get($filed);
        if($c==1){//qtx 2018-12-19

            $countMoney = lm("money_buy", "commons")->whereRaw($where)->sum('money');
            $winMoney = lm("money_buy", "commons")->whereRaw($where)->sum('prize_money');
            $profitMoney = lm("money_buy", "commons")->whereRaw($where)->sum('get_money');
            $sumbet = lm("money_buy", "commons")->whereRaw($wheretwo)->sum('money');//总投注
            $wherethree[] = array('status','<',4);
            $wherethree[] = array('game_status','=',0);
            $noawardbet = lm("money_buy", "commons")->whereRaw($wheretwo)->where($wherethree)->sum('money');//未开奖投注
            $cancelbet = lm("money_buy", "commons")->whereRaw($wheretwo)->where('status','=',4)->sum('money');//撤单投注
            $sumbet = empty($sumbet)?0:$sumbet;
            $noawardbet = empty($noawardbet)?0:$noawardbet;
            $cancelbet = empty($cancelbet)?0:$cancelbet;
            $countMoney = empty($countMoney)?0:$countMoney;
            $winMoney = empty($winMoney)?0:$winMoney;
            $profitMoney = empty($profitMoney)?0:$profitMoney;
            $arrto['countMoney'] = $countMoney;
            $arrto['winMoney'] = $winMoney;
            $arrto['profitMoney'] = $profitMoney;
            $arrto['sumbet'] = $sumbet;
            $arrto['noawardbet'] = $noawardbet;
            $arrto['cancelbet'] = $cancelbet;
            return $arrto;
        }
        if (count($rows) != 0) {

            $list = 20;
            //获取总页数
            $count_list = lm("money_buy", "commons")->whereRaw($where)->count();
            $count_page = ceil($count_list / $list);
            $first = ($page - 1) * $list;
            $rows = lm("money_buy", "commons")
                ->orderBy('money_time', 'desc')
                ->whereRaw($where)
                ->offset($first)
                ->limit($list)
                ->get($filed)
                ->toArray();
            //计算当前页总和
            $sum = lm("money_buy", "commons")
                ->orderBy('money_time', 'desc')
                ->whereRaw($where)
                ->offset($first)
                ->limit($list)
                ->get(['money']);
            $current_total = $sum->sum('money');
            //总投注额
            $total_sum = lm("money_buy", "commons")
                ->orderBy('money_time', 'desc')
                ->whereRaw($where)->sum('money');
        }else{
            return ['type'=>1,'code' => -10009];
        }
        $game = lm('game_type','commons')->get(['name','table_name']);
        $lang = [];
        foreach ($game as $k=>$v)
        {
            $lang[$v['table_name']] = $v['name'];
        }
        $dat = [
            'type'=>1,
            'data' => $rows,
            'current_total' => $current_total,
            'total_sum' =>$total_sum,
            'count_page' => $count_page,
            'page' => $page,
            'lang' =>$lang,
        ];
        return $dat;

    }
    //六合投注统计
    function EffectivesixBetting($data,$c=-1)//qtx 2018-12-19
    {
        $id_one = isset($data['account_identity']) ? $data['account_identity'] : ''; //用户唯一id
        $page = isset($data['page']) ? $data['page'] : 1;
        //$start = isset($data['start']) ? $data['start'] : '';
        //$end = isset($data['end']) ? $data['end'] : '';
        $time = isset($data['time']) ? $data['time'] : '';
        $start = '';
        $end = '';
        if(!empty($time)){//qtx 2018-12-11
            $newtime = explode('~',$time);
            if(count($newtime) ==2){
                $start = $newtime[0].' 00:00:00';
                $end = $newtime[1].' 23:59:59';

            }else{
                $start = $time;
                $end = date("Y-m-d", strtotime("+1 day", strtotime($time)));
            }
        }
        if (empty($id_one)) {
            return -4010;
        }
        $where = "account_identity = '". $id_one ."' AND status < 4 AND game_status > 0";
        $wheretwo = "account_identity = '". $id_one."'";
        //时间段
        if(!empty($start) && !empty($end))
        {
            $where .= " AND money_time >= '".$start."' AND money_time <= '".$end."'";
            $wheretwo .= " AND money_time >= '".$start."' AND money_time <= '".$end."'";
        }
        //时间段，只有开始
        if(!empty($start) && empty($end))
        {
            $where .= " AND money_time >= '".$start."'";
            $wheretwo .= " AND money_time >= '".$start."'";
        }
        //时间段，只有结束
        if(empty($start) && !empty($end))
        {
            $where .= " AND money_time <= '".$end."'";
            $wheretwo .= " AND money_time <= '".$end."'";
        }

        //print_r($where);
        $filed = ['order_id','game_name','game_no','money','prize_money','game_status','money_time'];

        $rows = lm("SixMoney_buy", "commons")->whereRaw($where)->get($filed);

        if($c==1){//qtx 2018-12-19

            $countMoney = lm("SixMoney_buy", "commons")->whereRaw($where)->sum('money');
            $winMoney = lm("SixMoney_buy", "commons")->whereRaw($where)->sum('prize_money');
            $profitMoney = lm("SixMoney_buy", "commons")->whereRaw($where)->sum('get_money');
            $sumbet = lm("SixMoney_buy", "commons")->whereRaw($wheretwo)->sum('money');//总投注

            $wherethree[] = array('status','<',4);
            $wherethree[] = array('game_status','=',0);
            $noawardbet = lm("SixMoney_buy", "commons")->whereRaw($wheretwo)->where($wherethree)->sum('money');//未开奖投注
            $cancelbet = lm("SixMoney_buy", "commons")->whereRaw($wheretwo)->where('status','=',4)->sum('money');//撤单投注
            $sumbet = empty($sumbet)?0:$sumbet;
            $noawardbet = empty($noawardbet)?0:$noawardbet;
            $cancelbet = empty($cancelbet)?0:$cancelbet;
            $countMoney = empty($countMoney)?0:$countMoney;
            $winMoney = empty($winMoney)?0:$winMoney;
            $profitMoney = empty($profitMoney)?0:$profitMoney;
            $arrto['sixcountMoney'] = $countMoney;
            $arrto['sixwinMoney'] = $winMoney;
            $arrto['sixprofitMoney'] = $profitMoney;
            $arrto['sixsumbet'] = $sumbet;
            $arrto['sixnoawardbet'] = $noawardbet;
            $arrto['sixcancelbet'] = $cancelbet;
            //dump($arrto);
            return $arrto;
        }
        if (count($rows) != 0) {

            $list = 20;
            //获取总页数
            $count_list = lm("SixMoney_buy", "commons")->whereRaw($where)->count();
            $count_page = ceil($count_list / $list);
            $first = ($page - 1) * $list;
            $rows = lm("SixMoney_buy", "commons")
                ->orderBy('money_time', 'desc')
                ->whereRaw($where)
                ->offset($first)
                ->limit($list)
                ->get($filed)
                ->toArray();
            //计算当前页总和
            $sum = lm("SixMoney_buy", "commons")
                ->orderBy('money_time', 'desc')
                ->whereRaw($where)
                ->offset($first)
                ->limit($list)
                ->get(['money']);
            $current_total = $sum->sum('money');
            //总投注额
            $total_sum = lm("SixMoney_buy", "commons")
                ->orderBy('money_time', 'desc')
                ->whereRaw($where)->sum('money');
        }else{
            return ['type'=>1,'code' => -10009];
        }
        $game = lm('game_type','commons')->get(['name','table_name']);
        $lang = [];
        foreach ($game as $k=>$v)
        {
            $lang[$v['table_name']] = $v['name'];
        }
        $dat = [
            'type'=>1,
            'data' => $rows,
            'current_total' => $current_total,
            'total_sum' =>$total_sum,
            'count_page' => $count_page,
            'page' => $page,
            'lang' =>$lang,
        ];
        return $dat;

    }

    /*
     *手机端记录
     */
    /*
     *手机端记录
     */
    public function NewBettinglist($data)
    {

        $id_one = $data['account_identity'] ? $data['account_identity'] : ''; //用户唯一id
        $status = $data['status'] ? $data['status'] : ''; //资金状态
        $order_id = $data['order_id'] ? $data['order_id'] : ''; //资金类型
        if($data['game_status'] != ''){
            $game_status = $data['game_status'];
        }

        $game_name = $data['game_name'] ? $data['game_name'] : ''; //资金类型
        $page = $data['page'] ? $data['page'] : '1'; //资金类型
        $money_time = $data['time'] ? $data['time'] : date('Y-m-d'); //时间
        $reorder = $data['reorder'] ? $data['reorder'] : 'money_time';
        $updown = $data['updown'] ? $data['updown'] : 'desc';
        if (!empty($money_time)) {//qtx 2018-12-11
            $newtime = explode('~',$money_time);
            if(count($newtime) ==2){
                $start_time = $newtime[0];
                $end_time = $newtime[1];
                $beforetime = date("Y-m-d",strtotime("$start_time -1 day"));
                $nexttime = date("Y-m-d",strtotime("$end_time +1 day"));
            }else{
                $beforetime = date("Y-m-d",strtotime("$money_time -1 day"));
                $nexttime = date("Y-m-d",strtotime("$money_time +1 day"));
            }
        }

        //$beforetime = date("Y-m-d",strtotime("$money_time -1 day"));
        //$nexttime = date("Y-m-d",strtotime("$money_time +1 day"));
        //return $page;
        $play_num = "";
        if (empty($id_one)) {
            return -4010;
        }

        $arr = [ //向数据库追加数组  然后循环出来
            'status' => $status,
            'account_identity' => $id_one,
            'order_id' => $order_id,
            'game_status' => $game_status,
            'game_name' => $game_name,
            'money_time' => $money_time
        ];

        $account = lm("game_type", "commons");
        $game = $account->where("status", "=", "1")->get()->toArray();

        //return $game;
       $where = '1 = 1';
        $wheretwo = '2=2';
        $wherethree = '3=3';

        foreach ($arr as $key => $value) {
            //循环数组

            if($value != '' && $key =='money_time'){
                if(count($newtime) ==2){
                    $where .= " AND money_time>='".$start_time." 00:00:00' AND money_time<='".$end_time." 23:59:59'";
                }else{
                    $where .= " AND {$key}>='{$value} 00:00:00' AND {$key}<='{$value} 23:59:59'";
                }

            }else{
                if ($value != '' && $key != 'a.id' && $key != 'b.id') { //判断条件
                    $where .= " AND {$key}='{$value}'"; //获取值
                }
            }
        }
        $arr['money_time'] = $beforetime;
        /* foreach ($arr as $key => $value) {
            if($value != '' && $key =='money_time'){
                $wheretwo .= " AND {$key}>='{$value} 00:00:00' AND {$key}<='{$value} 23:59:59'";
            }else{
                if ($value != '' && $key != 'a.id' && $key != 'b.id') { //判断条件
                    $wheretwo .= " AND {$key}='{$value}'"; //获取值
                }
            }
        }
        $arr['money_time'] = $nexttime;
        foreach ($arr as $key => $value) {
            if($value != '' && $key =='money_time'){
                $wherethree .= " AND {$key}>='{$value} 00:00:00' AND {$key}<='{$value} 23:59:59'";
            }else{
                if ($value != '' && $key != 'a.id' && $key != 'b.id') { //判断条件
                    $wherethree .= " AND {$key}='{$value}'"; //获取值
                }
            }
        }*/
        //$code_data = lm("money_buy", "commons")->whereRaw($where)->get();
        $resultdata =array();
        $list = 15;
        //获取总页数
        $count_list = lm("money_buy", "commons")->whereRaw($where)->count();
        $count_page = ceil($count_list / $list);
        $first = ($page - 1) * $list;
        //$code_datas = $accountd->orderBy('money_time', 'desc')->whereRaw($where)->offset($first)->limit($list)->get();
/*        $before_data = lm("money_buy", "commons")
            ->whereRaw($wheretwo)->orderBy($reorder,$updown)
            ->offset($first)->limit($list)->get();
        $next_data = lm("money_buy", "commons")
            ->whereRaw($wherethree)->orderBy($reorder,$updown)
            ->offset($first)->limit($list)->get();

*/



        //2018-12-31 anton liu 添加六合彩追号记录 start
        $game_data = lm("money_buy", "commons")
            ->whereRaw($where)->orderBy($reorder,$updown)
            ->offset($first)->limit($list)->orderby('id','desc')->get();
        if (!$game_data) {
            return -5004;
        }
        $game_data = $game_data->toArray();
        //$before_data    =   '';
        //$next_data    =   '';
        $sixgame_data   =[];

        //新增获取六合彩追号记录 //2019-01-09 16:42 blues
        if($status==2){
            $sixgame_data = lm("SixMoney_buy", "commons")
                ->whereRaw($where)->orderBy($reorder,$updown)
                ->offset($first)->limit($list)->orderby('id','desc')->get();
            if (!$sixgame_data) {
                return -5004;
            }
            $sixgame_data = $sixgame_data->toArray();
        }

        $code_data = array_merge($game_data,$sixgame_data);

        //end
        $beforenum = 0;
        $nextnum = 0;
        $tonum = 0;
        $rowy = array();
        if(empty($before_data)){
            $resultdata['beforeday'] = $beforenum;
        }else{

            $before_data = $before_data->toArray();
            foreach ($before_data as $key => $value) {
                $beforenum = $beforenum + floatval($value['get_money']);
            }
            $resultdata['beforeday'] = $beforenum;
        }
        if(empty($next_data)){
            $resultdata['nextday'] = $nextnum;
        }else{
            $next_data = $next_data->toArray();
            foreach ($next_data as $key => $value) {
                $nextnum = $nextnum + floatval($value['get_money']);
            }
            $resultdata['nextday'] = $nextnum;
        }

        $Winning = $this->GetMoneyStatus();
        $Status = $this->GetWinStatus();
        foreach ($code_data as $k => $val) {
            $val['game_type'] = lang()->get($val['game_name']);
            $data_paramt =json_decode($val['codes'],true);
            $regrouptype = $this->reGrouptype();
            $grouparr = array();
            foreach ($data_paramt as $key => $value) {
                if(in_array($key, $regrouptype)){
                    foreach ($value as $sk => $sv) {
                        $seatarr = explode('_',$sk);
                        $val2=$sv;
                        if(isset($val2['settings'])){
                            unset($val2['settings']);
                        }

                        if(isset($grouparr[$seatarr[0]])){
                            $grouparr[$seatarr[0]] += count($val2);
                        }else{
                            $grouparr[$seatarr[0]] = count($val2);
                        }
                    }
                }
            }
            $accounttwo = lm($val['game_name'] . "_buy", "commons");
            $identity_no = $accounttwo->where("order_id", $val['order_id'])->first();
            if (count($identity_no) != 0) {
                $identity_no = $identity_no->toArray();
            } else {
                return "";
            }
            $paramt = $this->CodesDetails($data_paramt,$val['game_name'],$identity_no);
            if (array_key_exists("general_pass", $data_paramt) || array_key_exists("join_born", $data_paramt)) {
                $val['num'] = 1;
            }else{
                if(empty($grouparr)){
                    $val['num'] = count($paramt);
                }else{
                    $val['num'] = 1;
                    foreach($grouparr as $k=>$v){
                        $val['num'] *= $v;
                    }
                }
            }
/*            if($val['game_status'] > 0){
                $tonum = $tonum+ floatval($val['get_money']);


            }*/
            $tonum  =   0;
            $val['timename'] = $this->time_tranx(strtotime($val['money_time']));
            if($status == 4){
                $wherecan['account_identity'] = $val['account_identity'];
                $wherecan['out_order_id'] = $val['order_id'];
                $cancel = lm("money_details", "commons")->where($wherecan)->first();
                if(!empty($cancel)){
                    $cancel = $cancel->toArray();
                    $val['canceltime'] = $cancel['money_time'];
                    $val['canceltimename'] = $this->time_tranx(strtotime($cancel['money_time']));
                }
            }
            foreach ($Winning as $key => $v) {
                //return $val['status'];
                if ($val['status'] == $key) {
                    $val['status'] = lang()->get($v);
                    $row[] = $val;
                }
            }
            //$val['game_number'] = count($codes['specialCode']);
        }
        $resultdata['today'] = $tonum;
        foreach ($Status as $key => $v) {
            foreach ($row as $k => $val) {
                if ($val['game_status'] == $key) {
                    $val['game_status'] = lang()->get($v);
                    $index = $val['id'];
                    $rowy[$index] = $val;
                    //$aa[]=$val;
                }

            }
        }
        rsort($rowy);
        if($resultdata['today'] >= 0){
            $resultdata['todayact'] = 1;
        }else{
            $resultdata['todayact'] = 0;
        }
        if($resultdata['beforeday'] >= 0){
            $resultdata['beforedayact'] = 1;
        }else{
            $resultdata['beforedayact'] = 0;
        }
        if($resultdata['nextday'] >= 0){
            $resultdata['nextdayact'] = 1;
        }else{
            $resultdata['nextdayact'] = 0;
        }
        $resultdata['tolist'] = $rowy;
        $resultdata['count_page'] = $count_page;
        $resultdata['act_page'] = intval($page);

        return $resultdata;

    }
    /***
     * 六合投注列表
     * @param $data
     * @return mixed
     */
    public function newSixBettingRecord($data)
    {

        $id_one = $data['account_identity'] ? $data['account_identity'] : ''; //用户唯一id
        $status = $data['status'] ? $data['status'] : ''; //资金状态
        $order_id = $data['order_id'] ? $data['order_id'] : ''; //资金类型
        $game_status = isset($data['game_status']) ? $data['game_status'] : ''; //资金类型
        $game_name = $data['game_name'] ? $data['game_name'] : ''; //资金类型
        $page = $data['page'] ? $data['page'] : '1'; //资金类型
        $money_time = $data['time'] ? $data['time'] : date('Y-m-d'); //时间
        $reorder = $data['reorder'] ? $data['reorder'] : 'money_time';
        $updown = $data['updown'] ? $data['updown'] : 'desc';
        if (!empty($money_time)) {//qtx 2018-12-11
            $newtime = explode('~',$money_time);
            if(count($newtime) ==2){
                $start_time = $newtime[0];
                $end_time = $newtime[1];
                $beforetime = date("Y-m-d",strtotime("$start_time -1 day"));
                $nexttime = date("Y-m-d",strtotime("$end_time +1 day"));
            }else{
                $beforetime = date("Y-m-d",strtotime("$money_time -1 day"));
                $nexttime = date("Y-m-d",strtotime("$money_time +1 day"));

            }
        }
        //return $page;
        $play_num = "";
        if (empty($id_one)) {
            return -4010;
        }

        $arr = [ //向数据库追加数组  然后循环出来
            'status' => $status,
            'account_identity' => $id_one,
            'order_id' => $order_id,
            'game_status' => $game_status,
            'money_time' => $money_time
        ];

        $where = '1 = 1';
        $wheretwo = '2=2';
        $wherethree = '3=3';
        foreach ($arr as $key => $value) {
            //循环数组
            if($value != '' && $key =='money_time'){
                if(count($newtime) ==2){
                    $where .= " AND money_time>='".$start_time." 00:00:00' AND money_time<='".$end_time." 23:59:59'";
                }else{
                    $where .= " AND {$key}>='{$value} 00:00:00' AND {$key}<='{$value} 23:59:59'";
                }
            }else{
                if (($value != '' || $value===0) && $key != 'a.id' && $key != 'b.id') { //判断条件
                    $where .= " AND {$key}='{$value}'"; //获取值
                }
            }
        }
        $arr['money_time'] = $beforetime;
        foreach ($arr as $key => $value) {
            if($value != '' && $key =='money_time'){
                $wheretwo .= " AND {$key}>='{$value} 00:00:00' AND {$key}<='{$value} 23:59:59'";
            }else{
                if (($value != '' || $value===0) && $key != 'a.id' && $key != 'b.id') { //判断条件
                    $wheretwo .= " AND {$key}='{$value}'"; //获取值
                }
            }
        }
        $arr['money_time'] = $nexttime;
        foreach ($arr as $key => $value) {
            if($value != '' && $key =='money_time'){
                $wherethree .= " AND {$key}>='{$value} 00:00:00' AND {$key}<='{$value} 23:59:59'";
            }else{
                if (($value != '' || $value===0) && $key != 'a.id' && $key != 'b.id') { //判断条件
                    $wherethree .= " AND {$key}='{$value}'"; //获取值
                }
            }
        }

        $list = 15;
        //获取总页数
        $count_list = lm("sixMoney_buy", "commons")->whereRaw($where)->count();
        $count_page = ceil($count_list / $list);
        $first = ($page - 1) * $list;
        $before_data = lm("sixMoney_buy", "commons")
            ->whereRaw($wheretwo)->orderBy($reorder,$updown)
            ->offset($first)->limit($list)->get();
        $next_data = lm("sixMoney_buy", "commons")
            ->whereRaw($wherethree)->orderBy($reorder,$updown)
            ->offset($first)->limit($list)->get();

        $code_data = lm("sixMoney_buy", "commons")
            ->whereRaw($where)->orderBy($reorder,$updown)
            ->offset($first)->limit($list)->get();
        if (!$code_data) {
            return -5004;
        }
        $beforenum = 0.00;
        $nextnum = 0.00;
        $tonum = 0.00;
        $rowy = array();
        if(empty($before_data)){
            $resultdata['beforeday'] = $beforenum;
        }else{
            $before_data = $before_data->toArray();
            foreach ($before_data as $key => $value) {
                $beforenum = $beforenum + sprintf("%.2f",$value['get_money']);
            }
            $resultdata['beforeday'] = $beforenum;
        }
        if(empty($next_data)){
            $resultdata['nextday'] = $nextnum;
        }else{
            $next_data = $next_data->toArray();
            foreach ($next_data as $key => $value) {
                $nextnum = $nextnum + sprintf("%.2f",$value['get_money']);
            }
            $resultdata['nextday'] = $nextnum;
        }

        $code_data = $code_data->toArray();

        foreach ($code_data as $k=>$v){
            $data_codes = lm($v['game_name'], "Commons")->select('status')->where('info_no', $v['game_no'])->first();
            if ($data_codes){
                $data_codes=$data_codes->toArray();
                $code_data[$k]['gamed_status']=$data_codes['status'];
            }
            //$tonum = $tonum+ intval($v['get_money']);

        }
        //$resultdata['today'] = $tonum;
        $Winning = $this->GetMoneyStatus();
        $Status = $this->GetWinStatus();
        foreach ($code_data as $k => $val) {
            $val['game_type'] = lang()->get($val['game_name']);
            $data_paramt =json_decode($val['codes'],true);
            $regrouptype = $this->reGrouptype();
            $grouparr = array();
            foreach ($data_paramt as $key => $value) {
                if(in_array($key, $regrouptype)){
                    foreach ($value as $sk => $sv) {
                        $seatarr = explode('_',$sk);
                        $val2=$sv;
                        if(isset($val2['settings'])){
                            unset($val2['settings']);
                        }

                        if(isset($grouparr[$seatarr[0]])){
                            $grouparr[$seatarr[0]] += count($val2);
                        }else{
                            $grouparr[$seatarr[0]] = count($val2);
                        }
                    }
                }
            }
            $accounttwo = lm($val['game_name'] . "_buy", "commons");
            $identity_no = $accounttwo->where("order_id", $val['order_id'])->first();
            if (count($identity_no) != 0) {
                $identity_no = $identity_no->toArray();
            } else {
                return "";
            }
            $paramt = $this->CodesDetails($data_paramt,$val['game_name'],$identity_no);
            if (array_key_exists("general_pass", $data_paramt) || array_key_exists("join_born", $data_paramt)) {
                $val['num'] = 1;
            }else{
                if(empty($grouparr)){
                    $val['num'] = count($paramt);
                }else{
                    $val['num'] = 1;
                    foreach($grouparr as $k=>$v){
                        $val['num'] *= $v;
                    }
                }
            }
            $tonum = $tonum + intval($val['get_money']);
            $val['timename'] = $this->time_tranx(strtotime($val['money_time']));
            if($status == 4){
                $wherecan['account_identity'] = $val['account_identity'];
                $wherecan['out_order_id'] = $val['order_id'];
                $cancel = lm("money_details", "commons")->where($wherecan)->first();
                if(!empty($cancel)){
                    $cancel = $cancel->toArray();
                    $val['canceltime'] = $cancel['money_time'];
                    $val['canceltimename'] = $this->time_tranx(strtotime($cancel['money_time']));
                }
            }
            foreach ($Winning as $key => $v) {
                //return $val['status'];
                if ($val['status'] == $key) {
                    $val['status'] = lang()->get($v);
                    $row[] = $val;
                }
            }
        }
        $resultdata['today'] = $tonum;
        foreach ($Status as $key => $v) {
            foreach ($row as $k => $val) {
                if ($val['game_status'] == $key) {
                    $val['game_status'] = lang()->get($v);
                    $index = $val['id'];
                    $rowy[$index] = $val;
                    //$aa[]=$val;
                }

            }
        }
        rsort($rowy);
        if($resultdata['today'] >= 0){
            $resultdata['todayact'] = 1;
        }else{
            $resultdata['todayact'] = 0;
        }
        if($resultdata['beforeday'] >= 0){
            $resultdata['beforedayact'] = 1;
        }else{
            $resultdata['beforedayact'] = 0;
        }
        if($resultdata['nextday'] >= 0){
            $resultdata['nextdayact'] = 1;
        }else{
            $resultdata['nextdayact'] = 0;
        }
        $resultdata['tolist'] = $rowy;
        $resultdata['count_page'] = $count_page;
        $resultdata['act_page'] = intval($page);
        return $resultdata;

    }

    //时间函数
    function time_tranx($the_time){
       $dur = time() - $the_time;
       if($dur < 0){
            return $the_time;
       }elseif($dur < 60){
            return $dur.'秒前';
       }elseif($dur < 3600){
            return floor($dur/60).'分钟前';
       }elseif($dur < 86400){
            return floor($dur/3600).'小时前';
       }elseif($dur < 259200){
            return floor($dur/86400).'天前';
       }else{
            return '超过3天前';
       }

    }

    /*
     * 回水金额
     */
    public function backWaterMoney($data){
        $id_one = $data['account_identity'] ? $data['account_identity'] : ''; //用户唯一id
        $status = isset($data['status']) ? $data['status'] : '1'; //资金状态
        $new_time = isset($data['time']) ? $data['time'] : '';
        if (empty($id_one)) {
            return -4010;
        }
        if(!empty($new_time)){//qtx 2018-12-11
            $newtime = explode('~',$new_time);
            if(count($newtime) ==2){
                $new_time1 = $newtime[0];
                $new_time2 = $newtime[1];
            }else{
                $new_time1 = $new_time;
                $new_time2 = $new_time;
            }
            $where[] = array('processing_time','>=',$new_time1.' 00:00:00');
            $where[] = array('processing_time','<=',$new_time2.' 23:59:59');
        }

        $where[] = array('account_identity','=',$id_one);
        $where[] = array('status','=',$status);
        $code_data = lm("money_return", "commons")->where($where)->sum('money');
        if (!$code_data) {
            return -5004;
        }

        return $code_data;

    }

    /*
     * 返水金额
     */
    public function returnMoney($data){
        $id_one = $data['account_identity'] ? $data['account_identity'] : ''; //用户唯一id
        $status = isset($data['status']) ? $data['status'] : '3'; //资金状态
        $new_time = isset($data['time']) ? $data['time'] : '';
        if (empty($id_one)) {
            return -4010;
        }
        if(!empty($new_time)){//qtx 2018-12-11
            $newtime = explode('~',$new_time);
            if(count($newtime) ==2){
                $new_time1 = $newtime[0]    ;
                $new_time2 = $newtime[1];
            }else{
                $new_time1 = $new_time;
                $new_time2 = $new_time;
            }
            $where[] = array('processing_time','>=',$new_time1.' 00:00:00');
            $where[] = array('processing_time','<=',$new_time2.' 23:59:59');
        }

        $where[] = array('account_identity','=',$id_one);
        $where[] = array('status','=',$status);

        $code_data = lm("money_back", "commons")->where($where)->sum('money');
        if (!$code_data) {
            return -5004;
        }
        return $code_data;
    }

    /*
     * 投注汇总结果
     */
    public function bettingsum($data){
        $id_one = $data['account_identity'] ? $data['account_identity'] : ''; //用户唯一id
        if (empty($id_one)) {
            return -4010;
        }
        $time = $data['time'] ? $data['time'] : date('Y-m-d'); //时间

        $where[] = array('account_identity','=',$id_one);
        $where[] = array('status','<',4);
        $where[] = array('game_status','>',0);
        if (!empty($time)) {//qtx 2018-12-11
            $newtime = explode('~',$time);
            if(count($newtime) ==2){
                $start_time = $newtime[0];
                $end_time = $newtime[1];
                $beforetime = date("Y-m-d",strtotime("$start_time -1 day"));
                $nexttime = date("Y-m-d",strtotime("$end_time +1 day"));
                $where[] = array('money_time','>=',$start_time.' 00:00:00');
                $where[] = array('money_time','<=',$end_time.' 23:59:59');
            }else{
                $beforetime = date("Y-m-d",strtotime("$time -1 day"));
                $nexttime = date("Y-m-d",strtotime("$time +1 day"));
                $where[] = array('money_time','>=',$time.' 00:00:00');
                $where[] = array('money_time','<=',$time.' 23:59:59');
            }

        }
        

        $arr = array();
        $arrdata = array();
        $tablename = lm("game_type", "commons")->select('name','table_name','close_status')->where("status", "=", "1")->where("table_name","<>",'-1')->get()->toArray();
        foreach ($tablename as $key => $value) {
            $arr[$value['table_name']]=$value;
            $arr[$value['table_name']]['money'] = 0;
            $arr[$value['table_name']]['prize_money'] = 0;
            $arr[$value['table_name']]['get_money'] = 0;
        }
        $codedata = lm("money_buy", "commons")->where($where)->get();
        $six_codedata = lm("SixMoney_buy", "commons")->where($where)->get();

//        $where[3] = array('money_time','>=',$beforetime.' 00:00:00');
//        $where[4] = array('money_time','<=',$beforetime.' 23:59:59');
//        $before_data = lm("money_buy", "commons")->where($where)->get();
//
//        $where[3] = array('money_time','>=',$nexttime.' 00:00:00');
//        $where[4] = array('money_time','<=',$nexttime.' 23:59:59');
//        $next_data = lm("money_buy", "commons")->where($where)->get();

        $codedata = $codedata->toArray();
		$six_codedata =count($six_codedata)>0? $six_codedata->toArray():[];
//        $before_data = $before_data->toArray();
//        $next_data = $next_data->toArray();
        $before_data    ='';
        $next_data      ='';
        if(empty($codedata)){
            $arrdata['today'] = 0;
            $arrdata['todayact'] = 0;
            $arrdata['tolist'] ='';
        }
        if(empty($before_data)){
            $arrdata['beforeday'] = 0;
            $arrdata['beforedayact'] = 0;
        }
        if(empty($next_data)){
            $arrdata['nextday'] = 0;
            $arrdata['nextdayact'] = 0;
        }

        foreach ($before_data as $key => $value) {
            $arrdata['beforeday'] += $value['get_money'];
        }
        foreach ($next_data as $key => $value) {
            $arrdata['nextday'] += $value['get_money'];
        }
        
		$codedata	=	array_merge($six_codedata,$codedata);
        foreach ($codedata as $key => $value) {
            $arr[$value['game_name']]['money'] += $value['money'];
            $arr[$value['game_name']]['prize_money'] += $value['prize_money'];
            $arr[$value['game_name']]['get_money'] += $value['get_money'];
            $arrdata['today'] += $value['get_money'];

        }

        if($arrdata['today'] >= 0){
            $arrdata['todayact'] = 1;
        }else{
            $arrdata['todayact'] = 0;
        }
        if($arrdata['beforeday'] >= 0){
            $arrdata['beforedayact'] = 1;
        }else{
            $arrdata['beforedayact'] = 0;
        }
        if($arrdata['nextday'] >= 0){
            $arrdata['nextdayact'] = 1;
        }else{
            $arrdata['nextdayact'] = 0;
        }
        $arrdata['tolist'] = array_values($arr);

        return $arrdata;

    }
}
