<?php
class indexAction
{
	function cache()
	{
		$Params = mvc::$URL_PARAMS;
		if(!empty($Params['css']))
		{
			switch($Params['css'])
			{
				case 'common':
					header("Content-type: text/css");
					$file = file_get_contents(mvc::$cfg['SYS_ROOT'].'static/css/common.css');
					$file = str_replace('url(../', 'url('.mvc::$cfg['SYS_URL'].'static/', $file);
					if(!empty(mvc::$cfg['shopInfo']['ssu_conf']['color']))
						$file = str_replace('#e7181e', mvc::$cfg['shopInfo']['ssu_conf']['color'], $file);
					echo $file;
					exit;
				break;
			}
		}
	}


	function index()
	{
		$OthWxJs = new OthWxJs();
		$res = $OthWxJs->getSign();
        //是否开启会员模块
        $moduleArr = mvc::$cfg['shopInfo']['ssu_modules'];
        $LibPjlApi = new LibPjlApi();
		$getArr = [
			'shopid' => mvc::$cfg['SHOPID'],
		];
        $banner = !empty(mvc::$cfg['shopInfo']['ssu_banner'])? explode(',',mvc::$cfg['shopInfo']['ssu_banner']):[];
        $result = $LibPjlApi->get('super/getSuperTags', $getArr, [], true);
        LibTpl::Set('tagsArr',$result['data']);
        LibTpl::Set('moduleArr',$moduleArr);
		LibTpl::Set('signPackage', $res['data']);
        LibTpl::Set('banner',$banner);
		LibTpl::Set('footMenu', 'index');
		LibTpl::Set('title', '首页');
		LibTpl::Put();
	}


	
	/**设置微信的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);
	}

    /**
     * @method 图片验证码
     * @author Yangxing
     * @copyright 2019/10/22
     */
    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);
    }

    /**
     * 图片上传
     */
    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);
    }

    /**
     * @method 保存纠错信息
     * @author Yangxing
     * @copyright 2019/10/22
     */
    function addJiuCuo()
    {
        if($_SESSION['imgcode'] != strtoupper($_POST['imgcode']))
            LibFc::ajaxJsonEncode(['status'=>false, 'data'=>'图片验证码不正确', 'code'=>'code_error']);
        if(!empty($_POST['jc_txt']) && (!empty($_POST['jc_pro_id']) || !empty($_POST['keyword'])))
        {
            $addArr = [
                'shopid'=> mvc::$cfg['SHOPID'],
                'jc_txt'=> $_POST['jc_txt'],
                'jc_uid'=> (int) $_SESSION['_userid'],
                'jc_url' => $_POST['url'],
                'jc_atime'=>time(),
                'jc_imgs' => $_POST['imgUrl'],
            ];
            if(isset($_POST['jc_pro_id']))
            {
                $addArr ['jc_pro_id'] = (int) $_POST['jc_pro_id'];
                $addArr['jc_type'] = 'item';
            } else if(isset($_POST['keyword'])){
                $addArr['jc_vin'] = $_POST['keyword'];
                $addArr['jc_type'] = 'vin';
            }else{
                $addArr['jc_type'] = 'index';
            }
            unset($_SESSION['imgcode']);
            $LibYpApi = new LibPjlApi();
            $result = $LibYpApi->get('super/addSuperJiucuo', [],$addArr);
            LibFc::ajaxJsonEncode($result);
        }
        LibFc::ajaxJsonEncode(['status'=>false,'data'=>'纠错内容不能为空']);
    }
    /**
     * @method 获取当前目录权限
     * @author zhengweihua 
     * @copyright 2022-06-18
     */
    function getPermissionData()
    {
        $Params = mvc::$URL_PARAMS;
		$LibPjlApi = new LibPjlApi();
		$getArr =[
			'shopid'=>mvc::$cfg['SHOPID'],
		];
		$result = $LibPjlApi->get('super/getMemberRule', $getArr, [], true);
		$modArr = array_column($result['data'],'smr_code');
        LibFc::ReturnJson(true,$modArr);
    }
}
