<?php
/**
 *------Create thems Controller------
 *------SCWPHP  Version 1.0.0------
 *------Dev Model Jions------
 *------Create Time 2017-06-19 18:04:54------
 */

namespace App\Api\Controller;
//ini_set('display_errors', 1);
//
//error_reporting(E_ALL);
class UserDetails extends BaseController {

    /**
     * 用户明细列表
     * @return [type] [description]
     */
    public function MoneyList() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data = array();
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $res = $moneyClass->Winning($data);
        //echo $res;
        Render($res, '1', 'success');
    }

    /**
     * 资金流水订单详情
     * @return [type] [description]
     */
    public function MoneyDetail() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data = array();
        $order_id = isset($_REQUEST['order_id']) ? $_REQUEST['order_id'] : '';
        if (empty($order_id)) Render('', '-4046');
        $res = $moneyClass->MorderDetail($order_id);
        //echo $res;
        if ($res < 0) Render('', $res);
        Render($res, '1', 'success');
    }

    /**
     * 充值列表
     * @return [type] [description]
     */
    public function MoneyRecharge() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $data['status'] = isset($_POST['status']) ? $_POST['status'] : '';
        $data['order_id'] = isset($_POST['order_id']) ? $_POST['order_id'] : '';
        $data['page'] = isset($_POST['page']) ? $_POST['page'] : '';
        $res = $moneyClass->Recharge($data);
        //echo $res;
        Render($res, '1', 'success');
    }

    /**
     * 提现列表
     * @return [type] [description]
     */
    public function MoneyTake() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $data['status'] = isset($_POST['status']) ? $_POST['status'] : '';
        $data['order_id'] = isset($_POST['order_id']) ? $_POST['order_id'] : '';
        $data['page'] = isset($_POST['page']) ? $_POST['page'] : '';
        $res = $moneyClass->Withdrawals($data);
        //echo $res;
        Render($res, '1', 'success');
    }


    //彩金升级记录

    public function cToUpgrade() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $data['create_time'] = isset($_POST['create_time']) ? $_POST['create_time'] : '';
        $data['page'] = isset($_POST['page']) ? $_POST['page'] : '';
        $res = $moneyClass->cToUpgrade($data);

        //echo $res;
        Render($res, '1', 'success');
    }

    //新增查询彩金记录
    public function getLotteryLog() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        if (empty($data['account_identity'])) {
            Render('', -4010, '缺少用户唯一标识');
        }
        $data['time'] = isset($_POST['time']) ? $_POST['time'] : '';
        if (empty($data['time'])) {
            Render('', -4010, '缺少时间参数');
        }
        $data['page'] = isset($_POST['page']) ? $_POST['page'] : 1;
        $log = $moneyClass->getLotteryLog($data);
        if ($log < 0) {
            Render('', $log, '获取数据失败');
        }
        Render($log, 1, '获取数据成功');
    }


    //彩金详细
    public function cToDetail() {

        $moneyClass = new \Biz\Money\MoneyQuery;
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $data['uid'] = isset($_POST['uid']) ? $_POST['uid'] : '';
        $data['money_type'] = isset($_POST['money_type']) ? $_POST['money_type'] : '';
        $res = $moneyClass->CToDetail($data);
        //echo $res;
        Render($res, '1', 'success');
    }

    //充值明细新
    public function saveMoneyRecord() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $data['status'] = isset($_POST['status']) ? $_POST['status'] : '';
        $data['order_id'] = isset($_POST['order_id']) ? $_POST['order_id'] : '';
        $data['page'] = isset($_POST['page']) ? $_POST['page'] : '';
        $data['time'] = isset($_POST['time']) ? $_POST['time'] : '';
        $res = $moneyClass->saveMoneyRecord($data);
        //echo $res;
        Render($res, '1', 'success');
    }

    //提款明细新
    public function takeMoneyRecord() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $data['status'] = isset($_POST['status']) ? $_POST['status'] : '';
        $data['order_id'] = isset($_POST['order_id']) ? $_POST['order_id'] : '';
        $data['page'] = isset($_POST['page']) ? $_POST['page'] : '';
        $data['time'] = isset($_POST['time']) ? $_POST['time'] : '';
        $res = $moneyClass->takeMoneyRecord($data);
//        dump($res);
        if (intval($res) < 0) {
            Render('',$res);
        }
        Render($res, '1', 'success');
    }


    /**
     * 充值列表
     * @return [type] [description]
     */
    public function PCMoneyRecharge() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $data['id'] = isset($_POST['id']) ? $_POST['id'] : "";
        $data['num1'] = isset($_POST['num1']) ? $_POST['num1'] : "";
        $data['num2'] = isset($_POST['num2']) ? $_POST['num2'] : "";
        $data['time'] = isset($_POST['time']) ? $_POST['time'] : "";
        $data['page'] = isset($_POST['page']) ? $_POST['page'] : "1";
        $res = $moneyClass->PCRecharge($data);
        //echo $res;
        Render($res, '1', 'success');
    }

    /**
     * 提现列表
     * @return [type] [description]
     */
    public function PCMoneyTake() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $data['id'] = isset($_POST['id']) ? $_POST['id'] : "";
        $data['num1'] = isset($_POST['num1']) ? $_POST['num1'] : "";
        $data['num2'] = isset($_POST['num2']) ? $_POST['num2'] : "";
        $data['time'] = isset($_POST['time']) ? $_POST['time'] : "";
        $data['page'] = isset($_POST['page']) ? $_POST['page'] : "1";
        $res = $moneyClass->PCWithdrawals($data);
        //echo $res;
        Render($res, '1', 'success');
    }

    /**
     * PC用户明细列表
     * @return [type] [description]
     */
    public function PCMoneyList() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data = array();
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $data['id'] = isset($_POST['id']) ? $_POST['id'] : "";
        $data['num1'] = isset($_POST['num1']) ? $_POST['num1'] : "";
        $data['num2'] = isset($_POST['num2']) ? $_POST['num2'] : "";
        $data['time'] = isset($_POST['time']) ? $_POST['time'] : "";
        $data['page'] = isset($_POST['page']) ? $_POST['page'] : "1";
        $data['trade_type'] = isset($_POST['trade_type']) ? $_POST['trade_type'] : "";
        $res = $moneyClass->PcWinning($data);
        //echo $res;
        Render($res, '1', 'success');
    }


    public function OGMoney() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data = array();
        $kyreturnMoney = 0;
        $ogreturnMoney = 0;
        $backMoney = 0;
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $a = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $data['time'] = isset($_POST['time']) ? $_POST['time'] : date('Y-m-d');
        if(empty($data['time'])){
            $data['time'] = date('Y-m-d');
        }
        $kywhere[] = array('GameEndTime','>=',$data['time'].' 00:00:00');
        $kywhere[] = array('GameEndTime','<=',$data['time'].' 23:59:59');
        $ogwheres[] = array('AddTime','>=',strtotime($data['time'].' 00:00:00'));
        $ogwheres[] = array('AddTime','<=',strtotime($data['time'].' 23:59:59'));
        $where[] = array('pass_time','>=',strtotime($data['time'].' 00:00:00'));
        $where[] = array('pass_time','<=',strtotime($data['time'].' 23:59:59'));
        $agwhere[] = array('recalcuTime','>=',strtotime($data['time'].' 00:00:00'));
        $agwhere[] = array('recalcuTime','<=',strtotime($data['time'].' 23:59:59'));
		$hjwhere[] = array('bet_time','>=',$data['time'].' 00:00:00');
		$hjwhere[] = array('bet_time','<=',$data['time'].' 23:59:59');
		
        $kybetting_money = lm("Kygame_betting_ogrbv", "commons")->where('account_identity',$data['account_identity'])->where($kywhere)->sum('CellScore');
        $ogbetting_money = lm("Oggame_betting_ogrbv", "commons")->where('account_identity',$data['account_identity'])->where($ogwheres)->sum('BettingAmount');
        //$agbetting_money = lm("Aggame_betting_ogrbv", "commons")->where('account_identity',$data['account_identity'])->where($agwhere)->sum('validBetAmount');
        $lcqpbetting_money = lm("Lcqpgame_betting_ogrbv", "commons")->where('account_identity',$data['account_identity'])->where($kywhere)->sum('CellScore');
        $lybetting_money = lm("Lygame_betting_ogrbv", "commons")->where('account_identity',$data['account_identity'])->where($kywhere)->sum('CellScore');
		$hjbetting_money = lm("Hjgame_betting_ogrbv", "commons")->where('account_identity',$data['account_identity'])->where($hjwhere)->sum('bet_amount');


        $kywin_money = lm("Kygame_betting_ogrbv", "commons")->where('account_identity',$data['account_identity'])->where('Profit','>',0)->where($kywhere)->sum('Profit');
        $ogwin_money = lm("Oggame_betting_ogrbv", "commons")->where('account_identity',$data['account_identity'])->where('WinLoseAmount','>',0)->where($ogwheres)->sum('WinLoseAmount');
        //$agwin_money = lm("Aggame_betting_ogrbv", "commons")->where('account_identity',$data['account_identity'])->where('netAmount','>',0)->where($agwhere)->sum('netAmount');
        $lcqpwin_money = lm("Lcqpgame_betting_ogrbv", "commons")->where('account_identity',$data['account_identity'])->where('Profit','>',0)->where($kywhere)->sum('Profit');
        $lywin_money = lm("Lygame_betting_ogrbv", "commons")->where('account_identity',$data['account_identity'])->where('Profit','>',0)->where($kywhere)->sum('Profit');
		$hjwin_money = lm("Hjgame_betting_ogrbv", "commons")->where('account_identity',$data['account_identity'])->where('state',1)->where($hjwhere)->sum('profit');

        $ogreturnMoney = lm("Og_backwater", "commons")->where('account_identity',$data['account_identity'])->where('game_type','Oggame')->where($where)->sum('money');    //返水金额
        $kyreturnMoney = lm("Og_backwater", "commons")->where('account_identity',$data['account_identity'])->where('game_type','Kygame')->where($where)->sum('money');    //返水金额
        $lcqpreturnMoney = lm("Og_backwater", "commons")->where('account_identity',$data['account_identity'])->where('game_type','Lcqpgame')->where($where)->sum('money');
        $lyreturnMoney = lm("Og_backwater", "commons")->where('account_identity',$data['account_identity'])->where('game_type','Lygame')->where($where)->sum('money');    //返水金额
        //$agreturnMoney = lm("Og_backwater", "commons")->where('account_identity',$data['account_identity'])->where('game_type','Kygame')->where($where)->sum('money');    //返水金额
		$hjreturnMoney = lm("Og_backwater", "commons")->where('account_identity',$data['account_identity'])->where('game_type','Hjgame')->where($where)->sum('money');
	
		$ogwin = $ogwin_money-$ogbetting_money;//赢亏
        $kywin = $kywin_money-$kybetting_money;//赢亏
        //$agwin = $agwin_money-$agbetting_money;//赢亏
        $lcqpwin = $lcqpwin_money-$lcqpbetting_money;//赢亏
        $lywin = $lywin_money-$lybetting_money;//赢亏
        $hjwin = $hjwin_money-$hjbetting_money;//赢亏
        if ($ogreturnMoney < 0) {
            $ogreturnMoney = 0;
        }
        if ($kyreturnMoney < 0) {
            $kyreturnMoney = 0;
        }
        if ($ogwin_money < 0) {
            $ogwin_money = 0;
        }
        if ($kywin_money < 0) {
            $kywin_money = 0;
        }
        if ($kybetting_money < 0) {
            $kybetting_money = 0;
        }
        if ($ogbetting_money < 0) {
            $ogbetting_money = 0;
        }
        // if ($agbetting_money < 0) {
        //     $agbetting_money = 0;
        // }

        $lcqpbetting_money = ($lcqpbetting_money<0)? 0 : $lcqpbetting_money;
        $lybetting_money = ($lybetting_money<0)? 0 : $lybetting_money;
        // $data = lm('account_detailed', "Commons")->where('account_identity', $a)->first()->toArray();

        $dat = array(
            'kywin_money' => sprintf("%.2f", $kywin_money),
            'ogwin_money' => sprintf("%.2f", $ogwin_money),
            //'agwin_money' => sprintf("%.2f", $agwin_money),
            'lcqpwin_money' => sprintf("%.2f", $lcqpwin_money),
            'lywin_money' => sprintf("%.2f", $lywin_money),
            'hjwin_money' => sprintf("%.2f", $hjwin_money),
            
            'kybetting_money' => sprintf("%.2f", $kybetting_money),
            'ogbetting_money' => sprintf("%.2f", $ogbetting_money),
            //'agbetting_money' => sprintf("%.2f", $agbetting_money),
            'lcqpbetting_money' => sprintf("%.2f", $lcqpbetting_money),
            'lybetting_money' => sprintf("%.2f", $lybetting_money),
            'hjbetting_money' => sprintf("%.2f", $hjbetting_money),
            
  
            'kyreturnMoney' => sprintf("%.2f", $kyreturnMoney),
            'ogreturnMoney' => sprintf("%.2f", $ogreturnMoney),
            'lcqpreturnMoney' => sprintf("%.2f", $lcqpreturnMoney),
            'lyreturnMoney' => sprintf("%.2f", $lyreturnMoney),
            //'agreturnMoney' => sprintf("%.2f", $agreturnMoney),
			'hjreturnMoney' => sprintf("%.2f", $hjreturnMoney),
            
            'kywin' => sprintf("%.2f", $kywin),
            'ogwin' => sprintf("%.2f", $ogwin),
            //'agwin' => sprintf("%.2f", $agwin),
            'lcqpwin' => sprintf("%.2f", $lcqpwin),
            'lywin' => sprintf("%.2f", $lywin),
            'hjwin' => sprintf("%.2f", $hjwin),
        );
        Render($dat, '1', 'success');
    }

    /**
     * PC用户明细列表
     * @return [type] [description]
     */
    public function PCNewMoney() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data = array();
        $withdrawalsMoney = 0;
        $rechargeMoney = 0;
        $betMoney = 0;
        $winMoney = 0;
        $profitMoney = 0;
        $returnMoney = 0;
        $backMoney = 0;
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $a = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $data['id'] = isset($_POST['id']) ? $_POST['id'] : "";
        $data['num1'] = isset($_POST['num1']) ? $_POST['num1'] : "";
        $data['num2'] = isset($_POST['num2']) ? $_POST['num2'] : "";
        $data['time'] = isset($_POST['time']) ? $_POST['time'] : date('Y-m-d');//qtx 2018-12-25
        if(empty($data['time'])){//qtx 2018-12-25
        	$data['time'] = date('Y-m-d');
        }

        $withdrawalsMoney = $moneyClass->PCRecharge($data, 1);    //充值金额

        $rechargeMoney = $moneyClass->PCWithdrawals($data, 1);    //提现金额
        $backMoney = $moneyClass->backWaterMoney($data, 1);    //回水金额
        $returnMoney = $moneyClass->returnMoney($data, 3);    //返水金额
        if ($backMoney < 0) {
            $backMoney = 0;
        }
        if ($returnMoney < 0) {
            $returnMoney = 0;
        }
        $data = array();
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $data['start'] = isset($_POST['start']) ? $_POST['start'] : "";
        $data['end'] = isset($_POST['end']) ? $_POST['end'] : "";
        $data['time'] = isset($_POST['time']) ? $_POST['time'] : date('Y-m-d');//qtx 2018-12-25
        if(empty($data['time'])){//qtx 2018-12-25
        	$data['time'] = date('Y-m-d');
        }
        //dump($data);
        $resMoney = $moneyClass->EffectiveBetting($data, 1);
        $sixresMoney = $moneyClass->EffectivesixBetting($data, 1);
        $data = lm('account_detailed', "Commons")->where('account_identity', $a)->first()->toArray();

        $dat = array(//qtx 2018-12-19
            'withdrawalsMoney' => $withdrawalsMoney,
            'rechargeMoney' => $rechargeMoney,
            'cash' => $data['cash'],
            'betMoney' => sprintf("%.2f", $resMoney['countMoney']),
            'winMoney' => sprintf("%.2f", $resMoney['winMoney']),
            'profitMoney' => sprintf("%.2f", $resMoney['profitMoney']),
            'sumbet' => sprintf("%.2f", $resMoney['sumbet']),
            'noawardbet' => sprintf("%.2f", $resMoney['noawardbet']),
            'cancelbet' => sprintf("%.2f", $resMoney['cancelbet']),
            'backMoney' => sprintf("%.2f", $backMoney),
            'returnMoney' => sprintf("%.2f", $returnMoney),
            'sixbetMoney' => sprintf("%.2f", $sixresMoney['sixcountMoney']),
            'sixwinMoney' => sprintf("%.2f", $sixresMoney['sixwinMoney']),
            'sixprofitMoney' => sprintf("%.2f", $sixresMoney['sixprofitMoney']),
            'sixsumbet' => sprintf("%.2f", $sixresMoney['sixsumbet']),
            'sixnoawardbet' => sprintf("%.2f", $sixresMoney['sixnoawardbet']),
            'sixcancelbet' => sprintf("%.2f", $sixresMoney['sixcancelbet']),
        );
        Render($dat, '1', 'success');
    }

    /**
     * PC投注记录和追号记录
     * @return [type] [description]
     */
    public function PcBettingRecord() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data = array();
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $data['game'] = isset($_POST['game']) ? $_POST['game'] : "";
        $data['money_time'] = isset($_POST['money_time']) ? $_POST['money_time'] : "";
        $data['time1'] = isset($_POST['time1']) ? $_POST['time1'] : "";
        $data['time2'] = isset($_POST['time2']) ? $_POST['time2'] : "";
        $data['no'] = isset($_POST['no']) ? $_POST['no'] : "";
        $data['page'] = isset($_POST['page']) ? $_POST['page'] : "1";
        $data['status'] = isset($_POST['status']) ? $_POST['status'] : "";
        $data['id'] = isset($_POST['id']) ? $_POST['id'] : "";
        $data['order_id'] = isset($_POST['order_id']) ? $_POST['order_id'] : "";
        $res = $moneyClass->PcBettingRecord($data);
        //echo $res;
        Render($res, '1', 'success');
    }

    /**
     * PC投注记录和追号记录
     * @return [type] [description]
     */
    public function PcSixlotteryRecord() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data = array();
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $data['game'] = isset($_POST['game']) ? $_POST['game'] : "";
        $data['money_time'] = isset($_POST['money_time']) ? $_POST['money_time'] : "";
        $data['time1'] = isset($_POST['time1']) ? $_POST['time1'] : "";
        $data['time2'] = isset($_POST['time2']) ? $_POST['time2'] : "";
        $data['no'] = isset($_POST['no']) ? $_POST['no'] : "";
        $data['page'] = isset($_POST['page']) ? $_POST['page'] : "1";
        $data['status'] = isset($_POST['status']) ? $_POST['status'] : "";
        $data['id'] = isset($_POST['id']) ? $_POST['id'] : "";
        $data['order_id'] = isset($_POST['order_id']) ? $_POST['order_id'] : "";
        $res = $moneyClass->PcSixlotteryRecord($data);
        //echo $res;
        Render($res, '1', 'success');
    }

    /**
     * PC塞子游戏投注记录
     * @return [type] [description]
     */
    public function PcDiceBettingRecord() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data = array();
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $data['game'] = isset($_POST['game']) ? $_POST['game'] : "";
        $data['money_time'] = isset($_POST['money_time']) ? $_POST['money_time'] : "";
        $data['time1'] = isset($_POST['time1']) ? $_POST['time1'] : "";
        $data['time2'] = isset($_POST['time2']) ? $_POST['time2'] : "";
        $data['no'] = isset($_POST['no']) ? $_POST['no'] : "";
        $data['page'] = isset($_POST['page']) ? $_POST['page'] : "1";
        $data['status'] = isset($_POST['status']) ? $_POST['status'] : "";
        $data['id'] = isset($_POST['id']) ? $_POST['id'] : "";
        $data['order_id'] = isset($_POST['order_id']) ? $_POST['order_id'] : "";
        $res = $moneyClass->PcDiceBettingRecord($data);
        //echo $res;
        Render($res, '1', 'success');
    }

    /**
     * PC投注记录和追号记录
     * @return [type] [description]
     */
    public function PcBettingDetails() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data = array();
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $data['game'] = isset($_POST['game']) ? $_POST['game'] : "";
        $data['money_time'] = isset($_POST['money_time']) ? $_POST['money_time'] : "";
        $data['time1'] = isset($_POST['time1']) ? $_POST['time1'] : "";
        $data['time2'] = isset($_POST['time2']) ? $_POST['time2'] : "";
        $data['no'] = isset($_POST['no']) ? $_POST['no'] : "";
        $data['page'] = isset($_POST['page']) ? $_POST['page'] : "1";
        $data['status'] = isset($_POST['status']) ? $_POST['status'] : "";
        $data['id'] = isset($_POST['id']) ? $_POST['id'] : "";
        $data['order_id'] = isset($_POST['order_id']) ? $_POST['order_id'] : "";
        $res = $moneyClass->PcBettingDetails($data);
        $dat = $moneyClass->dataChange($res);
        //echo $res;
        Render($dat, '1', 'success');
    }

    /**
     * PC投注记录和追号记录
     * @return [type] [description]
     */
    public function PcSixlotteryDetails() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data = array();
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $data['game'] = isset($_POST['game']) ? $_POST['game'] : "";
        $data['money_time'] = isset($_POST['money_time']) ? $_POST['money_time'] : "";
        $data['time1'] = isset($_POST['time1']) ? $_POST['time1'] : "";
        $data['time2'] = isset($_POST['time2']) ? $_POST['time2'] : "";
        $data['no'] = isset($_POST['no']) ? $_POST['no'] : "";
        $data['page'] = isset($_POST['page']) ? $_POST['page'] : "1";
        $data['status'] = isset($_POST['status']) ? $_POST['status'] : "";
        $data['id'] = isset($_POST['id']) ? $_POST['id'] : "";
        $data['order_id'] = isset($_POST['order_id']) ? $_POST['order_id'] : "";
        $res = $moneyClass->PcSixlotteryDetails($data);
        $dat = $moneyClass->dataChange($res);
        //echo $res;
        Render($dat, '1', 'success');
    }

    /**
     * PC塞子投注详情
     * @return [type] [description]
     */
    public function PcDiceBettingDetails() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data = array();
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $data['game'] = isset($_POST['game']) ? $_POST['game'] : "";
        $data['game_name'] = isset($_POST['game_name']) ? $_POST['game_name'] : "";
        $data['id'] = isset($_POST['id']) ? $_POST['id'] : "";
        if ($data['game'] == 'dice') {
            $res = $moneyClass->DiceSdataChange($data);
        } else {
            $res = $moneyClass->DicedataChange($data);
        }


        Render($res, '1', 'success');
    }

    /*交易类型对应键值*/
    public function GetTradeType() {
        $child = array(
            '1' => '投注',
            '2' => '追号',
            '3' => '撤单',
            '4' => '中奖',
            '5' => '提现',
            '6' => '在线充值',
            '7' => '返水',
            '8' => '回水',
            '9' => '管理员扣款',
            '10' => '佣金提成',
            '11' => '后台充值',
            '12' => '活动',
            '13' => '充值赠送',
            '14' => '汇款',
            '15' => '提现冻结',
            '16' => '红包打赏',
            '19-1' => '额度转入',
            '19-2' => '额度转出',
        );
        $arr = array(
            '1' => array(
                'name' => '全部',
                'child' => $child,
            ),
            '2' => array(
                'name' => '充值',
                'child' => array(
                    '11' => $child['11'],
                    '6' => $child['6'],
                    '14' => $child['14'],
                ),
            ),
            '3' => array(
                'name' => '投注',
                'child' => array(
                    '1' => $child['1'],
                    '2' => $child['2'],
                    '3' => $child['3'],
                ),
            ),
            '4' => array(
                'name' => '中奖',
                'child' => array(
                    '4' => $child['4'],
                ),
            ),
            '5' => array(
                'name' => '提现',
                'child' => array(
                    '5' => $child['5'],
                    '9' => $child['9'],
                ),
            ),
            '6' => array(
                'name' => '额度转账',
                'child' => array(
                    '19-1' => $child['19-1'],
                    '19-2' => $child['19-2'],
                ),
            ),
            '7' => array(
                'name' => '活动优惠',
                'child' => array(
                    '7' => $child['7'],
                    '8' => $child['8'],
                    '10' => $child['10'],
                    '13' => $child['13'],
                    '12' => $child['12'],
                    '16' => $child['16'],
                ),
            ),
        );
        Render($arr, '1', lang()->get('success'));
    }

    /**
     * 查询不同资金类型列表
     */
    public function Querry() {
        $status = isset($_POST['status']) ? $_POST['status'] : '';
        $trade_type = isset($_REQUEST['trade_type']) ? $_REQUEST['trade_type'] : '';
        $account_identity = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $page = isset($_POST['page']) ? $_POST['page'] : '1';
        $money_time = isset($_REQUEST['money_time']) ? $_REQUEST['money_time'] : '';
        $field = isset($_POST['field']) ? $_POST['field'] : 'otime';
        $orderby = isset($_REQUEST['orderby']) ? $_REQUEST['orderby'] : '2';

        $moneyClass = new \Biz\Money\MoneyQuery;
        if(empty($money_time)){//qtx 2018-12-25
         	$prevmonth = date("Y-m-d", strtotime("-1 month"));
        	$money_time = $prevmonth.'~'.date('Y-m-d');
        }
        $mtime = explode('~', $money_time);
        $data = array(
            'account_identity' => $account_identity,
            'status' => $status,
            'trade_type' => $trade_type,
            'page' => $page,
            'field' => ($field == 'otime') ? 'money_time' : 'money',
            'orderby' => ($orderby == 1) ? 'asc' : 'desc',
            'money_time' => substr($money_time, '0', '19'),
        );
        if (count($mtime > 1)) {
            $data['money_time'] = $mtime;
        }
        $res = $moneyClass->Winning($data);
        //var_dump( $res);
        if (is_array($res)) {
            Render($res, '1', lang()->get('success'));
        } else {
            Render('', '-400', lang()->get('fail'));
        }
    }

    /*统计账户明细汇总*/
    public function AccountSum() {
        $trade_type = isset($_REQUEST['trade_type']) ? $_REQUEST['trade_type'] : '';
        $account_identity = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $page = isset($_POST['page']) ? $_POST['page'] : '1';
        $field = isset($_POST['field']) ? $_POST['field'] : 'otime';
        $orderby = isset($_POST['orderby']) ? $_POST['orderby'] : '2';
        $money_time = isset($_REQUEST['money_time']) ? $_REQUEST['money_time'] : '';

        $moneyClass = new \Biz\Money\MoneyQuery;
        $mtime = explode('~', $money_time);
        $data = array(
            'account_identity' => $account_identity,
            'trade_type' => $trade_type,
            'page' => $page,
            'money_time' => substr($money_time, '0', '19'),
        );
        if (count($mtime > 1)) {
            $data['money_time'] = $mtime;
        }
        $res = $moneyClass->AccountSum($data);
        //var_dump( $res);
        if (is_array($res)) {
            Render($res, '1', lang()->get('success'));
        } else {
            Render('', '-400', lang()->get('fail'));
        }
    }

    /**
     * 资金详情
     * @return [type] [description]
     */
    public function details() {
        $data['identity'] = isset($_GET['identity']) ? $_GET['identity'] : '';
        $moneyClass = new \Biz\Money\MoneyQuery;
        $res = $moneyClass->Lists($data);
        Render($res, '1', lang()->get('success'));
    }

    /**
     * 走势图
     * @return [type] [description]
     */
    public function TrendChart() {
        $nums = new \Biz\Game\GameQuery();
        $name = isset($_GET['name']) ? $_GET['name'] : '';
        $num1 = isset($_POST['num1']) ? $_POST['num1'] : '';
        $num2 = isset($_POST['num2']) ? $_POST['num2'] : '';
        $time = isset($_POST['time']) ? $_POST['time'] : '';
        $page = isset($_POST['page']) ? $_POST['page'] : '1'; //资金类型
        $limit = isset($_POST['limit']) ? $_POST['limit'] : '20';
        $datat = [
            'name' => $name,
            'num1' => $num1,
            'num2' => $num2,
            'time' => $time,
            'page' => $page,
            'limit' => $limit,

        ];
        $data = $nums->TrendChart($datat);
        $data['page']=$page;
        //dump(21);
        Render($data, '1', lang()->get('success'));
    }

    /**
     * 投注状态查询
     * @return [type] [description]
     */
    public function BetChart() {
        $nums = new \Biz\Money\MoneyQuery;
        $account_identity = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $game_name = isset($_GET['game_name']) ? $_GET['game_name'] : '';
        $no = isset($_POST['no']) ? $_POST['no'] : '';
        $status = isset($_POST['status']) ? $_POST['status'] : '0';
        $datat = [
            'account_identity' => $account_identity,
            'game_name' => $game_name,
            'no' => $no,
            'status' => $status,

        ];
        if (in_array($game_name, $this->curPrizeGame())) {
            $data = $nums->CurBetRecord($datat);
        } else {
            $data = $nums->NotBetRecord($datat);
        }

        //dump($data);
        Render($data, '1', lang()->get('success'));
    }

    //即时开奖游戏
    private function curPrizeGame() {
        return array(
            'diceone',
        );
    }

    /**
     * 个人盈亏
     * @return [type] [description]
     */
    public function Personal() {

        $now_times = isset($_POST['now_time']) ? $_POST['now_time'] : '';
        //var_dump($now_times);
        $account_identity = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $data = array(
            'account_identity' => $account_identity,
            'now_times' => $now_times,
        );
        $moneyClass = new \Biz\Money\MoneyQuery;
        $res = $moneyClass->Personal($data);
        Render($res, '1', lang()->get('success'));
    }

    public function test() {
        $money_type = isset($_POST['money_type']) ? $_POST['money_type'] : '';
        $status = isset($_POST['status']) ? $_POST['status'] : '1';
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data = [
            'account_identity' => 'ec4ad43d-6105-e90c-5f3e-38141676c3b6',
            //'money_type'=>$money_type,
            //'status'=>$status
        ];
        $res = $moneyClass->Winning($data);
        // dump($res);
        if (is_array($res)) {
            Render($res, '1', lang()->get('success'));
        } else {
            Render('', '-400', lang()->get('fail'));
        }
    }

    //快乐赛宝
    public function DiceDetails() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $moneyd = new \App\Api\Controller\Specgame;
        $data = array();
        $ta = $moneyd->GetOtherUser();
        $data['account_identity'] = isset($ta['other_user']['account_identity']) ? $ta['other_user']['account_identity'] : $_SESSION['uinfo']['account_identity'];
        $dat = $moneyClass->DiceBettingDetails($data);
        Render($dat, '1', 'success');

    }

    public function DiceOneDetails() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data = array();
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : $_SESSION['uinfo']['account_identity'];
        $dat = $moneyClass->DiceBettingDetails($data);
        Render($dat, '1', 'success');

    }

    //PC用户有效投注统计
    public function BettingRecord() {
        $moneyClass = new \Biz\Money\MoneyQuery;
        $data['account_identity'] = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
        $data['start'] = isset($_POST['start']) ? $_POST['start'] : "";
        $data['end'] = isset($_POST['end']) ? $_POST['end'] : "";
        $data['page'] = isset($_POST['page']) ? $_POST['page'] : "1";
        $res = $moneyClass->EffectiveBetting($data);
        //echo $res;
        Render($res, '1', 'success');
    }

    public function getFav() {
        $uuid = $_SESSION['uinfo']['identity'];
        $obj = lm('UserSetting', 'api')->where('account_identity', $uuid)->first(['fav_info']);
        $in = $obj ? json_decode($obj->fav_info) : [];
        $favs = lm('Game_type', 'commons')->whereIn('table_name', $in)->get(['name', 'table_name', 'icon']);
        Render($favs, 1);
    }

    public function setFav() {
        $uuid = $_SESSION['uinfo']['identity'];
        $type = intval($_POST['type'] ?? 1);
        $game_name = trim($_POST['game_name']);
        $obj = lm('UserSetting', 'api')->where('account_identity', $uuid)->first(['fav_info']);
        $data = $obj && $obj->fav_info != 'null' ? json_decode($obj->fav_info, 1) : [];
        if (intval($type) === 0) {
            if ($key = array_search($game_name, $data)) {
                array_splice($data, $key, 1);
            }
        } elseif ($type === 1) {
            if (!array_search($game_name, $data)) {
                array_push($data, $game_name);
            }
        }
        $ret = lm('UserSetting', 'api')->where('account_identity', $uuid)->update(['fav_info' => json_encode($data)]);
        if ($ret === 1) {
            $this->getFav();
        }
        Render('', -888, '操作失败');

    }
}
