<?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','aps_contact', 'aps_info'], 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));
		}
		$contact['aps_contact'] = json_decode($res['data']['aps_contact'], true);
		// print_r($contact['aps_contact']);
		LibTpl::Set('contact', $contact);
		$OthBase= new OthBase();
		$limit=2;
		$res=$OthBase->get('cms_article left join cms_category on cat_id=art_cat_id',['*'],sprintf(" and art_shop_id=%d and cat_style='news' order by art_seq asc,art_etime desc limit %d",mvc::$cfg['SHOPID'],$limit));
		if(!empty($res['data']))
		{
			foreach ($res['data'] as $k => $v) 
			{
				$imgArr=json_decode($v['art_imgs']);
				if(!empty($imgArr))
				{
					$imgArr=array_map(function($v){
						return mvc::$cfg['FILE_CENTER']['b2c']['url_get'].'&c=adorn&f='.str_replace('/100', '',$v).mvc::$cfg['FILE_CENTER']['b2c']['get_uri'];
					}, $imgArr);
				}
				$res['data'][$k]['art_imgs']=$imgArr;
				$res['data'][$k]['time']=date('Y-m-d',$v['art_etime']);
			}
		}
		// print_r($res);
		LibTpl::Set('news', $res['data']);
		//body 样式类名【可选】
		//LibTpl::Set('bodyClass', 'bgf');
		LibTpl::Set('footMenu', 'index');
		LibTpl::Set('title', '首页');
		LibTpl::Put();
	}
	function contact()
	{

		$Params = mvc::$URL_PARAMS;
		$OthBase = new OthBase();
		$Params['t']=!empty($Params['t'])?$Params['t']:'info';
		$res=$OthBase->get('cms_article',['*'],sprintf(" and art_id=%d ",4),true);
		LibTpl::Set('about', $res['data']);
		$limit=5;
		$res=$OthBase->get('cms_article left join cms_category on cat_id=art_cat_id',['*'],sprintf(" and art_shop_id=%d and cat_style='news' order by art_seq asc,art_etime desc limit %d",mvc::$cfg['SHOPID'],$limit));
		LibTpl::Set('news', $res['data']);
		LibTpl::Set('Params', $Params);
		LibTpl::Set('footMenu', 'contact');
		LibTpl::Set('title', '客服');
		LibTpl::Put();
	}
	function getNewsLists()
	{
		$Params = mvc::$URL_PARAMS;
		$OthBase = new OthBase();
		$limit=!empty($Params['perPage'])?(int)$Params['perPage']:5;
		$page=!empty($Params['page'])?(int)$Params['page']:1;
		$res=$OthBase->get('cms_article left join cms_category on cat_id=art_cat_id',['*'],sprintf(" and art_shop_id=%d and cat_style='news' order by art_seq asc,art_etime desc limit %d,%d",mvc::$cfg['SHOPID'],($page-1)*$limit,$limit));
		if(!empty($res['data']))
		{
			foreach ($res['data'] as $k => $v) 
			{
				$imgArr=json_decode($v['art_imgs']);
				if(!empty($imgArr))
				{
					$imgArr=array_map(function($v){
						return mvc::$cfg['FILE_CENTER']['b2c']['url_get'].'&c=adorn&f='.str_replace('/100', '',$v).mvc::$cfg['FILE_CENTER']['b2c']['get_uri'];
					}, $imgArr);
				}
				$res['data'][$k]['art_imgs']=$imgArr;
				$res['data'][$k]['time']=date('Y-m-d',$v['art_etime']);
			}
		}
		LibTpl::Set('Params', $Params);
		LibFc::ajaxJsonEncode($res);
	}
	function new()
	{
		$Params = mvc::$URL_PARAMS;
		$OthBase = new OthBase();
		$res=$OthBase->get('cms_category',['*'],sprintf(' and cat_shop_id=%d order by cat_seq asc',mvc::$cfg['SHOPID']));
		// $Params['t']=$res['data'][0]['cat_style'];
		LibTpl::Set('cateArr', $res['data']);
		if(LibFc::Int($Params['aId']))
		{
			$res=$OthBase->get('cms_article',['*'],sprintf(" and art_id=%d",$Params['aId']),true);
			LibTpl::Set('data', $res['data']);
		}
		LibTpl::Set('footMenu', 'contact');
		LibTpl::Set('title', '客服');
		LibTpl::Put();
	}
	
}