<?php
class indexAction extends baseAction
{
	function index()
	{
		$OthWxJs = new OthWxJs();
		$res = $OthWxJs->getSign();
		LibTpl::Set('signPackage', $res['data']);
		$B2cBase = new B2cBase();
		$res = $B2cBase->get('sh_shop_app', ['aps_banner'], sprintf(" and aps_shop_id=%d", mvc::$cfg['SHOPID']), true);
		if(!empty($res['data']['aps_banner']))
		{
			$banner=json_decode($res['data']['aps_banner'],true);
			LibTpl::Set('banner', $banner);
			// print_r(current($banner));
		}
		//body 样式类名【可选】
		//LibTpl::Set('bodyClass', 'bgf');
		LibTpl::Set('footMenu', 'index');
		LibTpl::Set('title', '首页');
		LibTpl::Put();
	}

	function contact()
	{
		$Params = mvc::$URL_PARAMS;
		$B2cBase = new B2cBase();
		$res = $B2cBase->get('sh_shop_app', ['aps_contact', 'aps_info'], sprintf(" and aps_shop_id=%d", mvc::$cfg['SHOPID']), true);
		$arr = $res['data'];
		$arr['aps_contact'] = json_decode($arr['aps_contact'], true);
		LibTpl::Set('arr', $arr);
		LibTpl::Set('Params', $Params);
		LibTpl::Set('footMenu', 'contact');
		LibTpl::Set('title', '客服');
		LibTpl::Put();
	}


	/**
	  * @method 图片验证码
	  * @author soul
	  * @copyright 2017/5/9
	  */
	function imgcode()
	{
		$Params = mvc::$URL_PARAMS;
		$OthCheckcode = new OthCheckcode();
		$CofArr = ['onlyNum'=>true];
		if(!empty($Params['type']))
		{
			switch($Params['type'])
			{
				case 'txt':
				case 'reg':
				case 'login': $CofArr = ['onlyNum'=>true, 'height'=>30, 'width'=>90]; break;
				case 'business': $CofArr = ['onlyNum'=>true, 'session_key'=>'BusinessImageCode','level'=>4,'height'=>30, 'width'=>80]; break;
			}
		}
		$OthCheckcode->getImgcode($CofArr);
	}
	
	/**
	  * @method 匹配验证码
	  * @author soul
	  * @copyright 2017/5/9
	  */
	function checkImgcode()
	{
		$Return = ['status'=>false, 'data'=>'验证码不正确', 'code'=>'code_error'];
		if($_SESSION['imgcode'] == strtoupper($_POST['val']))
		{
			$Return = ['status'=>true, 'data'=>'', 'code'=>''];
		}
		LibFc::ajaxJsonEncode($Return);
	}
	function test(){
		LibTpl::Put('user/registerOk.php');
	}

	
	/**设置微信的oppenid到session，并进行跳转**/
	function setWxOpenid()
	{
		$Params = mvc::$URL_PARAMS;
		if(!empty($Params['udata']))
		{
			$WXUserArr = json_decode(base64_decode($Params['udata']), true);
			if(!empty($WXUserArr['openid']))
			{
				$_SESSION['wx_oppenid'] = $WXUserArr['openid'];
			}
		}
		$backUrl = !empty($Params['backUrl'])? base64_decode($Params['backUrl']): mvc::$cfg['SELF_URI'];
		Header("Location: ".$backUrl);
	}
	function download()
	{
		LibTpl::Set('title', '跑街令下载');
		LibTpl::Put();
	}

	public function uploadImage()
    {

        $site = 'b2c';
        $OthFileCenter = new OthFileCenter();
        $dataArr = [
            'cate'=> 'advise',
            'file'=>[
                'name'=> 'temp.jpg',
                'data'=>base64_decode(substr(strstr($_POST['imgUrl'], ','), 1))
            ]
        ];
        $fileRes = $OthFileCenter->upload($dataArr, $site);
        LibFc::ajaxJsonEncode($fileRes);
    }

	public function permission()
	{	
		$Params = mvc::$URL_PARAMS;
		$message = $Params['message']?:'非常抱歉，您无权限访问此页面！';
		$needLogin = empty($_SESSION['_userid'])?true:false;
		$backUrl = $Params['backUrl']?urlencode($Params['backUrl']):urlencode(LibFc::nowUrl());
		LibTpl::Set('message',$message);
		LibTpl::Set('needLogin',$needLogin);
		LibTpl::Set('backUrl',$backUrl);
		LibTpl::Put();
	}
}