<?php
// +----------------------------------------------------------------------
// | WANCMS游戏平台管理系统
// +----------------------------------------------------------------------
// | Copyright (c) 2015 http://www.wancms.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 顽皮蛋 <shf_l@163.com> <http://www.wancms.com>
// +----------------------------------------------------------------------
// | 修改时间: 2015/05/26
// +----------------------------------------------------------------------
namespace Phonegame\Controller;
use Common\Controller\PhonegameController;
/**
 * 会员防沉迷控制器
 * @author 顽皮蛋 <shf_l@163.com>
 */
class FcmController extends PhonegameController {
	protected $users_model;
	function _initialize(){
		parent::_initialize();
		$this->users_model=D("Common/Users");
	}
	/**
     * 会员防沉迷
     * @author 顽皮蛋 <shf_l@163.com>
     */
	public function index() {
		$userid=sp_get_current_userid();
		$user=$this->users_model->where(array("id"=>$userid))->find();
		$hotgame = M("m_game")->where("isdisplay=1")->order('downloadnum desc')->limit('2')->getField('id,pic1,gametype,gamename,android_url_image,android_url,downloadnum');
        $this->assign("hotgame",$hotgame);
		$this->assign($user);
    	$this->display($this->template.'/template1'.'/User'.'/fcm');
    }
    /**
     * 会员防沉迷修改
     * @author 顽皮蛋 <shf_l@163.com>
     */
   public function edit_post() {
    	if(IS_POST){
    		$userid=sp_get_current_userid();
    		$u=$this->users_model->where(array("id"=>$userid))->find();
    		if($u['realname'])$this->error("您已经绑定，请不要重复绑定");
    		$_POST['id']=$userid;
    		$_POST['is_fcm']= 0;
    		if ($this->users_model->create()) {
				if ($this->users_model->save()!==false) {
					$user=$this->users_model->find($userid);
					sp_update_current_user($user);
					$this->success("保存成功！",U("/user/fcm"));
				} else {
					$this->error("保存失败！");
				}
			} else {
				$this->error($this->users_model->getError());
			}
    	}
    }
}

