﻿<?php
/**
 * 后台，用户管理控制器
 * @author liuxiaoqing <liuxiaoqing@zhishisoft.com>
 * @version TS3.0
 */
// 加载后台控制器
tsload(APPS_PATH . '/admin/Lib/Action/AdministratorAction.class.php');

class PayAction extends AdministratorAction
{

    public $pageTitle = array();

    /**
     * 初始化，初始化页面表头信息，用于双语
     */
    public function _initialize()
    {
        $this->pageTitle['index'] = L('PUBLIC_USER_MANAGEMENT');
        $this->pageTitle['pending'] = L('PUBLIC_PENDING_LIST');
        $this->pageTitle['profile'] = L('PUBLIC_PROFILE_SETTING');
        $this->pageTitle['profileCategory'] = L('PUBLIC_PROFILE_SETTING');
        $this->pageTitle['dellist'] = L('PUBLIC_DISABLE_LIST');
        $this->pageTitle['online'] = '在线用户列表';
        $this->pageTitle['addUser'] = L('PUBLIC_ADD_USER_INFO');
        $this->pageTitle['editUser'] = L('PUBLIC_EDIT_USER');
        $this->pageTitle['addProfileField'] = L('PUBLIC_ADD_FIELD');
        $this->pageTitle['editProfileField'] = L('PUBLIC_EDIT_FIELD');
        $this->pageTitle['addProfileCategory'] = L('PUBLIC_ADD_FIELD_CLASSIFICATION');
        $this->pageTitle['editProfileCategory'] = L('PUBLIC_EDITCATEOGRY');
        $this->pageTitle['verify'] = '待认证用户';
        $this->pageTitle['verifyGroup'] = '待认证企业';
        $this->pageTitle['verified'] = '已认证用户';
        $this->pageTitle['verifiedGroup'] = '已认证企业';
        $this->pageTitle['addVerify'] = '添加认证';
        $this->pageTitle['category'] = '推荐标签';
        $this->pageTitle['verifyCategory'] = '认证分类';
        $this->pageTitle['verifyConfig'] = '认证配置';
        $this->pageTitle['official'] = '官方用户配置';
        $this->pageTitle['officialCategory'] = '官方用户分类';
        $this->pageTitle['officialList'] = '官方用户列表';
        $this->pageTitle['officialAddUser'] = '添加官方用户';
        $this->pageTitle['findPeopleConfig'] = '全局配置';

        parent::_initialize();
    }

    /**
     * 游戏管理 - 道具管理
     */
    public function shop()
    {

        // 初始化用户列表管理菜单
        $this->_initShopListAdminMenu();

        if ($_POST['type']) {
            $type = intval($_POST['type']);
        } else {
            $type = intval($_REQUEST['type']);
        }
        $type1 = intval($_REQUEST['type']);
        $state = intval($_POST['state']);
        $_REQUEST['tabHash'] = 'shop_' . $type1;
        $user = t($_POST['user']);
        $server = intval($_POST['server']);
        $character_name = t($_POST['character_name']);
        $ctime = ($_POST['ctime']);
        if ($state == 0) {
            $map['state'] = 1;
        }
        if ($state == 2) {
            $map['state'] = 0;
        }
        if ($type > 0) {
            $map['type'] = $type;
        }
        if ($server > 0) {
            $map['server'] = $server;
        }
        if (!empty($user)) {
            $map['user'] = array("like", "%" . $user . "%");
        }
        if (!empty($character_name)) {
            $map['character_name'] = array("like", "%" . $character_name . "%");
        }
        if (!empty($ctime)) {
            if (!empty ($ctime[0]) && !empty ($ctime[1])) {
                // 时间区间条件
                $map ['time'] = array(
                    'BETWEEN',
                    array(
                        strtotime($ctime[0]),
                        strtotime($ctime[1])
                    )
                );
            } else if (!empty ($ctime[0])) {
                // 时间大于条件
                $map ['time'] = array(
                    'GT',
                    strtotime($ctime[0])
                );
            } elseif (!empty ($ctime[1])) {
                // 时间小于条件
                $map ['time'] = array(
                    'LT',
                    strtotime($ctime[1])
                );
            }
        }
        $order = "id";
        if ($_POST['order'] == "money") {
            $order = "money";
        }

        // 数据的格式化与listKey保持一致
        $listData = $this->_getShopList('20', $map, $order);

        // 列表批量操作按钮
        $this->pageButton[] = array('title' => L('PUBLIC_SEARCH_USER'), 'onclick' => "admin.fold('search_form')");
        $this->pageButton[] = array('title' => "消费总金额: " . $listData['total'] . " 元", 'onclick' => "");
        $this->displayList($listData);
    }

    /**
     * 游戏管理 - 充值管理
     */
    public function pay()
    {
        $_REQUEST['tabHash'] = 'pay';
        // 初始化用户列表管理菜单
        $this->_initPayListAdminMenu();

        $type = ($_POST['pay_type']);
        $user = t($_POST['user']);
        $mony = t($_POST['mony']);
        $order = t($_POST['order']);

        $ctime = ($_POST['ctime']);

        if (!empty($type)) {
            $map['pay_type'] = $type;
        }
        if ($mony > 0) {
            $map['mony'] = $mony;
        }

        if (!empty($user)) {
            $map['user'] = array("like", "%" . $user . "%");
        }
        if (!empty($order)) {
            $map['order'] = $order;
        }

        // 数据的格式化与listKey保持一致
        $listData = $this->_getPayList('20', $map, 'index');

        if (!empty($ctime)) {
            if (!empty ($ctime[0]) && !empty ($ctime[1])) {
                // 时间区间条件
                $map ['paytime'] = array(
                    'BETWEEN',
                    array(
                        strtotime($ctime[0]),
                        strtotime($ctime[1])
                    )
                );
            } else if (!empty ($ctime[0])) {
                // 时间大于条件
                $map ['paytime'] = array(
                    'GT',
                    strtotime($ctime[0])
                );
            } elseif (!empty ($ctime[1])) {
                // 时间小于条件
                $map ['paytime'] = array(
                    'LT',
                    strtotime($ctime[1])
                );
            }
			// 数据的格式化与listKey保持一致
			$listData = $this->_getPayList2('20', $map, 'index');
        }

        // 列表批量操作按钮
        $this->pageButton[] = array('title' => L('PUBLIC_SEARCH_USER'), 'onclick' => "admin.fold('search_form')");
        $this->pageButton[] = array('title' => "消费总金额 :" . $listData['total'] . " 元", 'onclick' => "");
        // 转移用户部门，如果需要请将下面的注释打开
        // $this->pageButton[] = array('title'=>L('PUBLIC_TRANSFER_DEPARTMENT'),'onclick'=>"admin.changeUserDepartment()");
        $this->displayList($listData);
    }

    /**
     * 人工确认完成订单
     */
    public function dopaylog()
    {
        $return = array(
            'status' => 1,
            'data' => "操作完成"
        );
        $order = $_POST['order'];
        if (empty($order)) {
            $return['data'] = "参数异常";
        }else{
            $pmodel = M("pay");
            $model = M("pay_temp");

            $map['order'] = $order;

            $pdata = $pmodel->where($map)->find();
            if(!empty($pdata)){
                $return['data'] = "订单已正常结束，不做处理";
            }else{
                $data = $model->where($map)->find();
                $time = time();
                $add_pay["user"] = $data['user'];
                $add_pay["mony"] = $data['mony'];
                $add_pay["p_mony"] = $data['p_mony'];
                $add_pay["order"] = $order;
                $add_pay["pay_type"] = 'hand';
                $add_pay["ip"] = $_SERVER['REMOTE_ADDR'];
                $add_pay["payid"] = '1010';
                $add_pay["state"] = 1;
                $add_pay["time"] = $data['time'];
                $add_pay["paytime"] = $time;
                $add_pay["ext"] = $data['ext'];
                if($pmodel->add($add_pay)){
                    $umodel = M("user");
                    //增加P币
                    $result = $umodel->setInc('pbi',"login='".$data['user']."'",$data['mony']);
                    if($result){
                        $return['data'] = "操作成功，充值P币数量:".$data['mony'];
                    }else{
                        $return['data'] = "充值P币失败";
                    }
                }else{
                    $return['data'] = "生成订单失败";
                }
            }
        }
        echo json_encode($return);
    }

    /**
     * 充值日志
     */

    public function paylog()
    {
        $_REQUEST['tabHash'] = 'paylog';
        // 初始化用户列表管理菜单
        $this->_initPayListAdminMenu();
        $this->pageKeyList = array('user', 'mony', 'order', 'state', 'time', 'DOACTION');
        $this->searchKey = array('order');
//        $type = ($_POST['pay_type']);
//        $user = t($_POST['user']);
//        $mony = t($_POST['mony']);
        $order = t($_POST['order']);

//        $ctime = ($_POST['ctime']);

//        if (!empty($type)) {
//            $map['pay_type'] = $type;
//        }
//        if ($mony > 0) {
//            $map['mony'] = $mony;
//        }
//
//        if (!empty($user)) {
//            $map['user'] = array("like", "%" . $user . "%");
//        }
        if (!empty($order)) {
            $map['order'] = $order;
        }

//        if (!empty($ctime)) {
//            if (!empty ($ctime[0]) && !empty ($ctime[1])) {
//                // 时间区间条件
//                $map ['paytime'] = array(
//                    'BETWEEN',
//                    array(
//                        strtotime($ctime[0]),
//                        strtotime($ctime[1])
//                    )
//                );
//            } else if (!empty ($ctime[0])) {
//                // 时间大于条件
//                $map ['paytime'] = array(
//                    'GT',
//                    strtotime($ctime[0])
//                );
//            } elseif (!empty ($ctime[1])) {
//                // 时间小于条件
//                $map ['paytime'] = array(
//                    'LT',
//                    strtotime($ctime[1])
//                );
//            }
//        }
        if (empty($map)) {
            $map['id'] = array('LT', 0);
        }
        // 数据的格式化与listKey保持一致
        $listData = $this->_getPayLogList('20', $map, 'index');

        // 列表批量操作按钮
        $this->pageButton[] = array('title' => L('PUBLIC_SEARCH_USER'), 'onclick' => "admin.fold('search_form')");
        // 转移用户部门，如果需要请将下面的注释打开
        // $this->pageButton[] = array('title'=>L('PUBLIC_TRANSFER_DEPARTMENT'),'onclick'=>"admin.changeUserDepartment()");

        $this->displayList($listData);
    }

    /**
     * 初始化用户列表管理菜单
     * @param string $type 列表类型，index、pending、dellist
     */
    private function _initShopListAdminMenu()
    {
        $this->pageTab[] = array('title' => "全部", 'tabHash' => 'shop_0', 'url' => U('admin/User/index'));
        $this->pageTab[] = array('title' => "购买元宝", 'tabHash' => 'shop_1', 'url' => U('admin/Pay/shop', array("type" => "1")));
        $this->pageTab[] = array('title' => "遁甲天书", 'tabHash' => 'shop_2', 'url' => U('admin/Pay/shop', array("type" => "2")));
        $this->pageTab[] = array('title' => "太平要术", 'tabHash' => 'shop_3', 'url' => U('admin/Pay/shop', array("type" => "3")));
        $this->pageTab[] = array('title' => "左氏春秋", 'tabHash' => 'shop_4', 'url' => U('admin/Pay/shop', array("type" => "4")));


        // 搜索选项的key值
        $this->searchKey = array('user', 'server', 'character_name', 'type', 'state', 'order', array('ctime', 'ctime1'));
        // 针对搜索的特殊选项
        $this->opt['server'] = array('0' => "全部", '103' => "桃园", '108' => "江陵", '110' => "新野", '111' => "建业", '112'=>"豫州");
        $this->opt['state'] = array('0' => "成功", '1' => "全部", '2' => "失败");
        $this->opt['type'] = array('0' => "全部", '1' => "购买元宝", '2' => "遁甲天书", '3' => "太平要术", '4' => "左氏春秋");
        $this->opt['order'] = array('id' => "按日期", 'money' => "按消费金额");

        // 列表key值 DOACTION表示操作
        $this->pageKeyList = array('user', 'server', 'money', 'character_name', 'character_level', 'character_country', 'character_role', 'type', 'state', 'ext', 'time', 'DOACTION');

    }

    /**
     * 初始化用户列表管理菜单
     * @param string $type 列表类型，index、pending、dellist
     */
    private function _initAwardListAdminMenu()
    {
        $this->pageTab[] = array('title' => "全部", 'tabHash' => 'shop_0', 'url' => U('admin/Pay/award', array("state" => "-1")));
        $this->pageTab[] = array('title' => "未处理", 'tabHash' => 'shop_1', 'url' => U('admin/Pay/award', array("state" => "0")));
        $this->pageTab[] = array('title' => "已处理", 'tabHash' => 'shop_2', 'url' => U('admin/Pay/award', array("state" => "1")));


        // 搜索选项的key值
        $this->searchKey = array('user', 'user_', 'server', 'game_name', 'goods_name', 'state', array('ctime', 'ctime1'));
        // 针对搜索的特殊选项
        $this->opt['server'] = array('0' => "全部", '103' => "桃园", '108' => "江陵", '110' => "新野", '111' => "建业", '112'=>"豫州");
        $this->opt['state'] = array('-1' => "全部", '0' => "未处理", '1' => "已处理");


        // 列表key值 DOACTION表示操作
        $this->pageKeyList = array('user', 'server', 'game_name', 'goods_name', 'time', 'end_time', 'state', 'DOACTION');

    }

    /**
     * 解析用户购买道具列表数据
     * @param integer $limit 结果集数目，默认为20
     * @param array $map 查询条件
     * @param string $type 格式化数据类型，index、pending、dellist
     * @return array 解析后的用户列表数据
     */
    private function _getShopList($limit = 20, $map = array(), $order = 'id', $type = 'index')
    {
        // 设置列表主键
        $this->_listpk = 'id';

        $role = C("role");
        $role_1 = C("role_1");
        $country = C("country");

        //$server_ary = C("server_name");
        $server_ary = C("server_name_all");
        $type_ary = array("", "购买元宝", "遁甲天书", "太平要术", "左氏春秋");

        // 取用户列表
        $model = M("cashmoney");
        $listData = $model->where($map)->order("$order desc")->findPage($limit);

        $total = $model->where($map)->sum("money");
        foreach ($listData['data'] as $k => $v) {
            $listData['data'][$k]['time'] = date('Y-m-d H:i:s', $v['time']);
            $listData['data'][$k]['type'] = $type_ary[$v['type']];
            $listData['data'][$k]['server'] = $server_ary[$v['server']];
            $listData['data'][$k]['character_country'] = $country[$v['character_country_num']];

            $state = $listData['data'][$k]['state'];
            if ($state == 0) {
                $listData['data'][$k]['state'] = "失败";
            } else {
                $listData['data'][$k]['state'] = "成功";
            }

            if ($v['character_class'] == 0) {
                $listData['data'][$k]['character_role'] = $role[$v['character_add_class']];
            } else if ($x[2] == 1) {
                $listData['data'][$k]['character_role'] = $role_1[$v['character_add_class']];
            }
        }
        $listData['total'] = $total;
        return $listData;
    }


    /**
     * 初始化用户列表管理菜单
     * @param string $type 列表类型，index、pending、dellist
     */
    private function _initPayListAdminMenu()
    {
        // 搜索选项的key值
        $this->searchKey = array('user', 'mony', 'order', 'pay_type', array('ctime', 'ctime1'));
        $this->opt['pay_type'] = array('alipay' => "支付宝充值", 'hand'=>"人工确认单");//'admin' => "系统代充",'0' => "全部", 
        // 列表key值 DOACTION表示操作
        $this->pageKeyList = array('user', 'mony', 'order', 'pay_type', 'paytime', 'DOACTION');

    }
	
    /**
     * 解析用户充值列表数据
     * @param integer $limit 结果集数目，默认为20
     * @param array $map 查询条件
     * @param string $type 格式化数据类型，index、pending、dellist
     * @return array 解析后的用户列表数据
     */
    private function _getPayList($limit = 20, $map = array())
    {
        // 设置列表主键
        $this->_listpk = 'id';


        // 取用户列表
        $model = M("pay");
		$listData = $model->where($map)->where("pay_type='alipay' or pay_type='hand'")->order("id desc")->findPage($limit);//
        $payary = array('alipay' => "支付宝充值", 'hand'=>"人工确认单");//'admin' => "系统代充",'0' => "全部", 
        $total = $model->where($map)->where("pay_type='alipay' or pay_type='hand'")->sum("mony");//
        foreach ($listData['data'] as $k => $v) {
            $listData['data'][$k]['paytime'] = date('Y-m-d H:i:s', $v['paytime']);
            $listData['data'][$k]['pay_type'] = $payary[$v['pay_type']];

        }
        $listData['total'] = floor($total);
        return $listData;
    }
	
	/**
     * 解析用户充值列表数据
     * @param integer $limit 结果集数目，默认为20
     * @param array $map 查询条件
     * @param string $type 格式化数据类型，index、pending、dellist
     * @return array 解析后的用户列表数据
     */
    private function _getPayList2($limit = 20, $map = array())
    {
        // 设置列表主键
        $this->_listpk = 'id';


        // 取用户列表
        $model = M("pay");
		$listData = $model->where($map)->order("id desc")->findPage($limit);//
        $payary = array('alipay' => "支付宝充值", 'hand'=>"人工确认单");//'admin' => "系统代充",'0' => "全部", 
        $total = $model->where($map)->where("pay_type='alipay' or pay_type='hand'")->sum("mony");//
        foreach ($listData['data'] as $k => $v) {
            $listData['data'][$k]['paytime'] = date('Y-m-d H:i:s', $v['paytime']);
            $listData['data'][$k]['pay_type'] = $payary[$v['pay_type']];

        }
        $listData['total'] = floor($total);
        return $listData;
    }

    /**
     * 解析用户充值日志列表数据
     * @param integer $limit 结果集数目，默认为20
     * @param array $map 查询条件
     * @param string $type 格式化数据类型，index、pending、dellist
     * @return array 解析后的用户列表数据
     */
    private function _getPayLogList($limit = 20, $map = array())
    {
        // 设置列表主键
        $this->_listpk = 'id';

        $tmp = 0;
        // 订单日志
        $model = M("pay_temp");

//        完成订单
        $pmodel = M("pay");
        $plistData = $pmodel->where($map)->order("id desc")->findPage();
        if (empty($plistData['data'])) {
            $tmp = 1;
            $plistData = $model->where($map)->order("id desc")->findPage($limit);
        }

        $payary = array('alipay' => "支付宝充值", 'hand'=>"人工确认单");//'admin' => "系统代充",'0' => "全部", 

        foreach ($plistData['data'] as $k => $v) {
            if ($tmp == 1) {
                $plistData['data'][$k]['state'] = "未完成";
                $plistData['data'][$k]['time'] = date('Y-m-d H:i:s', $v['time']);
                $plistData['data'][$k]['DOACTION'] = '<a href="javascript:void(0)" onclick="admin.paylogok(\'' . $plistData['data'][$k]['order'] . '\')">确认到账</a>';
            } else {
                $plistData['data'][$k]['state'] = $payary[$plistData['data'][$k]['pay_type']];
                $plistData['data'][$k]['time'] = date('Y-m-d H:i:s', $v['paytime']);
                $plistData['data'][$k]['DOACTION'] = "";
            }
        }
        return $plistData;
    }

    /**
     * 游戏管理 -系统管理员充值管理
     */
    public function admin()
    {
        $_REQUEST['tabHash'] = 'admin';
        // 初始化用户列表管理菜单
        // 搜索选项的key值
        $this->searchKey = array('user_name', 'mony', 'info', 'fid_name', array('ctime', 'ctime1'));
        // 列表key值 DOACTION表示操作
        $this->pageKeyList = array('user_name', 'mony', 'fid_name', 'info', 'time', 'DOACTION');

        $fid_name = t($_POST['fid_name']);
        $user_name = t($_POST['user_name']);
        $mony = t($_POST['mony']);
        $info = t($_POST['info']);
        $ctime = ($_POST['ctime']);

        if ($fid_name > 0) {
            $map['fid_name'] = array("like", "%" . $fid_name . "%");
        }
        if ($mony > 0) {
            $map['mony'] = $mony;
        }

        if (!empty($user_name)) {
            $map['user_name'] = array("like", "%" . $user_name . "%");
        }
        if (!empty($info)) {
            $map['order'] = array("like", "%" . $info . "%");
        }

        if (!empty($ctime)) {
            if (!empty ($ctime[0]) && !empty ($ctime[1])) {
                // 时间区间条件
                $map ['time'] = array(
                    'BETWEEN',
                    array(
                        strtotime($ctime[0]),
                        strtotime($ctime[1])
                    )
                );
            } else if (!empty ($ctime[0])) {
                // 时间大于条件
                $map ['time'] = array(
                    'GT',
                    strtotime($ctime[0])
                );
            } elseif (!empty ($ctime[1])) {
                // 时间小于条件
                $map ['time'] = array(
                    'LT',
                    strtotime($ctime[1])
                );
            }
        }

        // 数据的格式化与listKey保持一致
        $listData = $this->_getAdminList('20', $map, 'index');

        // 列表批量操作按钮
        $this->pageButton[] = array('title' => L('PUBLIC_SEARCH_USER'), 'onclick' => "admin.fold('search_form')");
        $this->pageButton[] = array('title' => "充值总金额 :" . $listData['total'] . " 元", 'onclick' => "");
        // 转移用户部门，如果需要请将下面的注释打开
        // $this->pageButton[] = array('title'=>L('PUBLIC_TRANSFER_DEPARTMENT'),'onclick'=>"admin.changeUserDepartment()");
        $this->displayList($listData);
    }

    /**
     * 解析系统管理员充值列表数据
     * @param integer $limit 结果集数目，默认为20
     * @param array $map 查询条件
     * @param string $type 格式化数据类型，index、pending、dellist
     * @return array 解析后的用户列表数据
     */
    private function _getAdminList($limit = 20, $map = array())
    {
        // 设置列表主键
        $this->_listpk = 'id';


        // 取用户列表
        $model = M("pay_give");
        $listData = $model->where($map)->order("id desc")->findPage($limit);

        $total = $model->where($map)->sum("mony");
        foreach ($listData['data'] as $k => $v) {
            $listData['data'][$k]['time'] = date('Y-m-d H:i:s', $v['time']);

        }
        $listData['total'] = floor($total);
        return $listData;
    }

    function paylist()
    {
        // 初始化用户列表管理菜单
        $this->_initPayList();

        $type = intval($_POST['type']);
        $state = 1;
        $user = t($_POST['user']);
        $server = intval($_POST['server']);
        $ctime = ($_POST['ctime']);
        $map['state'] = 1;

        if ($type > 0) {
            $map['type'] = $type;
        }
        if ($server > 0) {
            $map['server'] = $server;
        }

        if (!empty($user)) {
            $map['user'] = array("like", "%" . $user . "%");
        }

        if (!empty($ctime)) {
            if (!empty ($ctime[0]) && !empty ($ctime[1])) {
                // 时间区间条件
                $map ['time'] = array(
                    'BETWEEN',
                    array(
                        strtotime($ctime[0]),
                        strtotime($ctime[1])
                    )
                );
            } else if (!empty ($ctime[0])) {
                // 时间大于条件
                $map ['time'] = array(
                    'GT',
                    strtotime($ctime[0])
                );
            } elseif (!empty ($ctime[1])) {
                // 时间小于条件
                $map ['time'] = array(
                    'LT',
                    strtotime($ctime[1])
                );
            }
        }

        // 数据的格式化与listKey保持一致
        $listData = $this->_getShopSumList('20', $map);

        // 列表批量操作按钮
        $this->pageButton[] = array('title' => L('PUBLIC_SEARCH_USER'), 'onclick' => "admin.fold('search_form')");

        $this->displayList($listData);
    }

    /**
     * 初始化用户列表管理菜单
     * @param string $type 列表类型，index、pending、dellist
     */
    private function _initPayList()
    {

        // 搜索选项的key值
        $this->searchKey = array('user', 'server', 'type', array('ctime', 'ctime1'));
        // 针对搜索的特殊选项
        $this->opt['server'] = array('0' => "全部", '103' => "桃园", '108' => "江陵", '110' => "新野", '111' => "建业", '112'=>"豫州");
        $this->opt['type'] = array('0' => "全部", '1' => "购买元宝", '2' => "遁甲天书", '3' => "太平要术", '4' => "左氏春秋");

        // 列表key值 DOACTION表示操作
        $this->pageKeyList = array('user', 'count_mony', 'count', 'server', 'character_level', 'character_name', 'character_country', 'character_role', 'type', 'time', 'login_time');

    }

    /**
     * 解析用户购买道具统计数据
     * @param integer $limit 结果集数目，默认为20
     * @param array $map 查询条件
     * @param string $type 格式化数据类型，index、pending、dellist
     * @return array 解析后的用户列表数据
     */
    private function _getShopSumList($limit = 20, $map = array())
    {
        // 设置列表主键
        $this->_listpk = 'id';
        $limit = 10000;
        $role = C("role");
        $role_1 = C("role_1");
        $country = C("country");

        //$server_ary = C("server_name");
        $server_ary = C("server_name_all");
        $type_ary = array("", "购买元宝", "遁甲天书", "太平要术", "左氏春秋");

        // 取用户列表
        $model = M("cashmoney");
        $listData = $model->where($map)
            ->field("*,sum(`money`) as count_mony,sum(`pay_money`) as count")
            ->group("user")->order("count_mony desc")->findPage($limit);
        /*$listData = $model->where ( $map )
        ->field("*,(`money`) as count_mony,(`pay_money`) as count")
        ->order ( "count_mony desc" )->findPage ( $limit );*/
        $total = $model->where($map)->sum("money");
        foreach ($listData['data'] as $k => $v) {
            $listData['data'][$k]['time'] = date('Y-m-d H:i:s', $v['time']);
            $listData['data'][$k]['type'] = $type_ary[$v['type']];
            $listData['data'][$k]['server'] = $server_ary[$v['server']];
            $listData['data'][$k]['character_country'] = $country[$v['character_country_num']];
            if ($v['login_time'] > 0) {
                $listData['data'][$k]['login_time'] = date('Y-m-d H:i:s', $v['login_time']);
            } else {
                $listData['data'][$k]['login_time'] = "0";
            }
            $state = $listData['data'][$k]['state'];
            if ($state == 0) {
                $listData['data'][$k]['state'] = "失败";
            } else {
                $listData['data'][$k]['state'] = "成功";
            }

            if ($v['character_class'] == 0) {
                $listData['data'][$k]['character_role'] = $role[$v['character_add_class']];
            } else if ($x[2] == 1) {
                $listData['data'][$k]['character_role'] = $role_1[$v['character_add_class']];
            }
        }
        $listData['total'] = $total;
        return $listData;
    }

    /**
     * 游戏管理 - 抽奖管理
     */
    public function award()
    {

        // 初始化用户列表管理菜单
        $this->_initAwardListAdminMenu();

        $state = intval($_REQUEST['state']);

        $user = t($_POST['user']);
        $user_ = t($_POST['user_']);
        $guser = t($_REQUEST['user']);
        $server = intval($_POST['server']);
        $game_name = t($_POST['game_name']);
        $goods_name = t($_POST['goods_name']);
        $ctime = ($_POST['ctime']);

        $where = "";
        if ($state == -1) {
            //$map['state'] = $state;
        } else {
            $map['state'] = $state;
            $where .= "state=" . $state . "&";
        }
        if ($server > 0) {
            $map['server'] = $server;
            $where .= "server=" . $server . "&";
        }
        if (!empty($user)) {
            $map['user'] = $user;
            $where .= "user=" . $user . "&";
        } else if (!empty($guser)) {
            $map['user'] = $guser;
            $where .= "user=" . $guser . "&";
        }

        if (!empty($user_)) {
            $map['user'] = array("like", "%" . $user_ . "%");
            $where .= "user=" . $user_ . "&";
        }

        if (!empty($game_name)) {
            $map['game_name'] = array("like", "%" . $game_name . "%");
            $where .= "game_name=" . $game_name . "&";
        }
        if (!empty($goods_name)) {
            $map['goods_name'] = array("like", "%" . $goods_name . "%");
            $where .= "goods_name=" . $goods_name . "&";
        }
        if (!empty($ctime)) {
            if (!empty ($ctime[0]) && !empty ($ctime[1])) {
                // 时间区间条件
                $map ['time'] = array(
                    'BETWEEN',
                    array(
                        strtotime($ctime[0]),
                        strtotime($ctime[1])
                    )
                );
            } else if (!empty ($ctime[0])) {
                // 时间大于条件
                $map ['time'] = array(
                    'GT',
                    strtotime($ctime[0])
                );
            } elseif (!empty ($ctime[1])) {
                // 时间小于条件
                $map ['time'] = array(
                    'LT',
                    strtotime($ctime[1])
                );
            }
        }

        // 数据的格式化与listKey保持一致
        $listData = $this->_getAwardList('20', $map, $where);

        // 列表批量操作按钮
        $this->pageButton[] = array('title' => L('PUBLIC_SEARCH_USER'), 'onclick' => "admin.fold('search_form')");
        $this->pageButton[] = array('title' => "批量派奖", 'onclick' => "admin.awardChuli()");
        $this->displayList($listData);
    }

    /**
     * 解析用户购买道具列表数据
     * @param integer $limit 结果集数目，默认为20
     * @param array $map 查询条件
     * @param string $type 格式化数据类型，index、pending、dellist
     * @return array 解析后的用户列表数据
     */
    private function _getAwardList($limit = 20, $map = array(), $where, $order = 'id')
    {
        // 设置列表主键
        $this->_listpk = 'id';


        //$server_ary = C("server_name");
        $server_ary = C("server_name_all");

        // 取用户列表
        $model = M("award");
        $listData = $model->where($map)->order("state asc")->findPage($limit);
        $listData['html'] = str_replace("act=award&", "act=award&" . $where, $listData['html']);
        foreach ($listData['data'] as $k => $v) {
            $listData['data'][$k]['time'] = date('Y-m-d H:i:s', $v['time']);
            $listData['data'][$k]['end_time'] = date('Y-m-d H:i:s', $v['end_time']);
            $listData['data'][$k]['server'] = $server_ary[$v['server']];

            $state = $listData['data'][$k]['state'];
            if ($state == 0) {
                $listData['data'][$k]['state'] = "未处理";
                $listData['data'][$k]['DOACTION'] = '<a href="javascript:void(0)" onclick="admin.releaseAward(' . $v['id'] . ')" style="color:#F00;">' . "派奖" . '</a>';
            } else {
                $listData['data'][$k]['state'] = "已处理";
                $listData['data'][$k]['DOACTION'] = '<a href="javascript:void(0)" style="color:#00F;">' . "已派奖" . '</a>';
            }


        }

        return $listData;
    }

    /**
     *发奖处理
     **/
    public function releaseAward()
    {
        $sid = explode(",", $_POST['id']);
        $model = M("award");
        foreach ($sid as $k => $v) {
            $id = intval($v);
            if ($id == "" || $id == 0) continue;
            if ($id > 0) {
                $x = $model->where("id =" . $id)->save(array("state" => 1, "end_time" => time()));
            }
        }

        exit("1");
        if ($id > 0) {
            $model = M("award");
            if ($model->where("id=" . $id)->save(array("state" => 1, "end_time" => time()))) {
                exit("1");
            }
        }
        exit("0");
    }

    public function integral()
    {
        $model = M("config_integral");
        $val = $model->where("id=1")->find();

        $this->assign("val", $val['val']);
        $this->display();
    }

    public function dointegral()
    {
        $val = intval($_POST['val']);
        $model = M("config_integral");
        if ($model->where("id=1")->save(array("val" => $val))) {
            exit("ok");
        } else {
            exit("fail");
        }
    }
}