<?php
namespace Admin\Controller;


/**
 * 后台首页控制器
 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
 */
class SuperSignController extends ThinkController
{
    public function lists($p = 1) {



        $page = intval($p);
        $page = $page ? $page : 1; //默认显示第一页数据
        $row=10;
        if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}

        $map =[];
        if (I('account')) {
            $map['tab_user.account'] = I('account');
        }

        if (I('order_id')) {
            $map['order_id'] = I('order_id');
        }

        if (I('start')&&I('end')) {
            $map['pay_time'] = ['between',[strtotime(I('start')),strtotime(I('end'))]];
        } else if(I('start')&&!I('end')) {
            $map['pay_time'] = ['egt',strtotime(I('start'))];
        } else if (!I('start')&&I('end')) {
            $map['pay_time'] = ['elt',strtotime(I('end'))];
        }

        if (I('game_name')) {
            $map['game_name'] = ['like',I('game_name').'%'];
        }

        if (I('promote_id')||I('promote_id')=='0') {
            $map['tab_user.promote_id'] = I('promote_id');
        }

        $map['tab_game_supersign.pay_status'] = 1;

        $data = M('game_supersign','tab_')
            ->field("order_id,ticket,pay_time,tab_user.account,tab_game.game_name,tab_user.promote_account,pay_price,pay_way")
            ->join("left join tab_user on tab_game_supersign.user_id = tab_user.id")
            ->join("left join tab_game on tab_game_supersign.game_id = tab_game.id")
            ->page($p, $row)
            ->order("pay_time DESC")
            ->where($map)
            ->select();

        foreach ($data as $key => $Value) {
            $data[$key]['pay_time'] = date('Y-m-d H:i:s',$Value['pay_time']);
            if ($Value['pay_way']==1) {
                $data[$key]['pay_way'] = '支付宝';
            } else if ($Value['pay_way']==2) {
                $data[$key]['pay_way'] = '微信';
            } else if($Value['pay_way']==3){
                $data[$key]['pay_way'] = '双乾支付宝';
            }else if($Value['pay_way']==4){
                $data[$key]['pay_way'] = '双乾微信';
            }else {
                $data[$key]['pay_way'] = '未知';
            }
        }

        $count = M('game_supersign','tab_')
            ->field("order_id,ticket,pay_time,tab_user.account,tab_game.game_name,tab_user.promote_account,pay_price")
            ->join("left join tab_user on tab_game_supersign.user_id = tab_user.id")
            ->join("left join tab_game on tab_game_supersign.game_id = tab_game.id")->where($map)->count();

        $page = set_pagination($count, $row);
        if ($page) {
            $this->assign('_page', $page);
        }
        $this->meta_title = '超级签订单';
        $this->assign('data',$data);
        $this->display();

    }
}