Mobileapi.class.php 11.6 KB
<?php
/**
 * 手机客户端API接口
 */
class Controller_MobileApi extends Controller_Abstract
{

	/**
	 * 获取客户端模块
	 * 
	 * @return json
	 */
	public function getMobileModuleListAction()
	{
		$modules = Facade_Mobile::getModule();
		$data = array();
		foreach($modules as $module)
 		{
 		    $headCover = '';
 		    $url = '';
 		    if($module['id'] == 1)
 		    {
 		        $headCover = SITE_IMG.'/yohood/yohood-logo-mobile_v3.png';
 		    }
 		    if(!empty($module['url']))
 		    {
 		    	if(preg_match('@^http://@', $module['url']))
 		    	{
 		    		$url = $module['url'];
 		    	}
 		    	else
 		    	{
 		    	    $url = SITE_MAIN.$module['url'];
 		    	}
 		    }
			$data []  = array('id'=> $module['id'],
			                  'status'=> $module['status'],
			           		  'moduleName' => $module['module_name'],
					          'headCover' => $headCover,
			                  'url' => $url,
			    );
		}
		return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
	}
	
	/**
	 * 获取资讯
	 * 
	 * @return json
	 */
	public function getNewsListAction()
	{
		list($offset, $limit) = $this->getMobileLimit();
		$tag = trim($this->_request->query('tag',''));
		if($tag == '全部资讯')
		{
			$tag = '';
		}
		if($tag == '视频') //手机端视频要小
		{
			$tag = '手机视频';
		}
		$data = array('total' => '0', 'list'=> array());
		$newses = Facade_News::getList($tag, $offset, $limit, array('视频'));
		$data['total'] = Facade_News::getTotal($tag, array('视频'));
		foreach($newses as $news)
		{
			if($news['tag'] == '视频')
			{
				continue;
			}
			if($news['tag'] == '手机视频')
			{
				$news['tag'] = '视频';
			}
			if(!empty($news['client_thumb']))
			{
				$image = $news['client_thumb'];
			}
			else
			{
				$image = $news['thumb'];
			}
			$data['list'][] = array(
							'id' => $news['id'],
							'tag' => $news['tag'], 'title' => sprintf("[%s] %s", $news['tag'], strip_tags($news['title'])),
							'image' => Lib_Images::getImageUrl($image, 'source','fragmentimg'),
					        'isVideo'=> strval($news['tag'] == '视频'?1:0),
					        'createTime' => $news['create_time']
			   );
		}
		return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
	}
	
	/**
	 * 获取资讯标签
	 * 
	 * @return json
	 */
	public function getTagsAction()
	{
		$data = array();
		$types =  Facade_News::$types;
		$newTags = Facade_News::getTags();
		foreach($types as $type)
		{
			foreach($newTags as $tag)
			{
				if($type == $tag['tag'])
				{
					$data[] = $type;
					break;
				}
			}
		}
		$data = array_merge(array('全部资讯'), $data);
		return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
	}
	
	/**
	 * 获取资讯详情
	 * 
	 * @return json
	 */
	public function getNewsDetailAction()
	{
		$id = $this->_request->query('id');
		$news = Facade_News::getOneById($id);
		Facade_News::updateHits($id);
		$data = array();
		$data =  array('content'=> '', 'images' => array(), 'video'=> '',  'content' => '','video_image'=>'','url'=>'','title' => '') ;
	    preg_match_all("@<img([^>]*)\s*src=('|\")([^'\"]+)('|\")@", $news['content'], $imageMatches);
	    preg_match_all("@<embed([^>]*)\s*src=\"http:\/\/res\.yoho\.cn\/res\/yohood\/swf\/YohoodPlayer\.swf\?url=(.+)\" width=@", $news['content'], $videoMatches);
	    if(!empty($news['client_thumb']))
	    {
	    	$image = $news['client_thumb'];
	    }
	    else
	    {
	    	$image = $news['thumb'];
	    }
	    if(!empty($imageMatches[3]))
	    {
	    	$data['images'] = array_unique($imageMatches[3]);//去除数组中重复值
	    }
	    $data['thumb'] = Lib_Images::getImageUrl($image, 'source','fragmentimg');
	    $data['title'] = strip_tags($news['title']);
	    $data['video_image'] = Lib_Images::getImageUrl($image, 'source','fragmentimg');
	    $patterns = array("/\s+/", "/<p[^>]*?>(.*?)<\/p>/is","/<(\/?br.*?)>/si");
	    $replaces = array(" ", "$1\n", "");
	    $news['content'] = preg_replace($patterns, $replaces, $news['content']);
	    $news['content'] = Lib_Utils_StringHelper::stripTags($news['content']);
	    $data['content'] = preg_replace("/([\n]{2,})/","\n", $news['content']);
	    $data['content'] = htmlspecialchars_decode($data['content']);
	    $data['brief'] = Lib_Utils_StringHelper::substr_cn(Lib_Utils_StringHelper::stripTags($news['content']), 95);
	    $data['url'] = SITE_MAIN.'/news/detail/id/'.$id;
	    if(!empty($videoMatches[2]))
	    {
	    	$data['video'] = current($videoMatches[2]);
	    }
	    return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
	}
	
	/**
	 * 获取品牌列表页
	 * 
	 * @return json
	 */
	public function getBrandListAction()
	{
		list($offset, $limit) = $this->getMobileLimit();
		$isLike = $this->_request->query('isLike', 0);
		$state = 1;
		$limit = 500;
		$brands = Facade_Brand::getBrandByState($offset, $limit, $state);
		$data = array('total'=> '0', 'list'=> array(), 
		'boothMapImage1F' => SITE_RES.'/images/yohood/yohood1F.jpg',
		'boothMapImage4F' => SITE_RES.'/images/yohood/yohood4F.jpg',
		);
		$boothList = Facade_Brand::getBoothList();
		$data['total'] = count($boothList);
		$yohobuyBrands = Facade_Brand::getYohobuyBrand();
		$signBrands = Facade_Brand::getSignBrand();
		foreach($boothList as $booth)
		{
		    $index = Lib_Utils_StringHelper::getFirstLetter($booth['brand_name']);
		    if(empty($index))
		    {
		        $index = substr($booth['brand_name'], 0, 1);
		    }
		    $index = strtoupper($index);
		    if(is_numeric($index))
		    {
		        $index = '0-9';
		    }
		    $x = $y = 0;
		    if($booth['floor'] == 1)
		    {
		    	$x = strval(intval($booth['x']) / 3802.0);
		    	$y = strval(intval($booth['y']) / 2019.0);
		    }
		    else if($booth['floor'] == 4)
		    {
		        $x = strval(intval($booth['x']) / 3775.0);
		        $y = strval(intval($booth['y']) / 2104.0);
		    }
		    $yohobuyBrandId = '0';
		    foreach($yohobuyBrands as $yohobuyBrand)
		    {
	    	    if(strtolower($yohobuyBrand['brand_name']) == strtolower($booth['brand_name']))
	    	    {
	    	        $yohobuyBrandId = $yohobuyBrand['brand_id'];
	    	        break;
	    	    }
		    }
		    $url = '';
		    foreach($brands as $brand)
		    {
		        if(strtolower($brand['name']) == strtolower($booth['brand_name']))
		        {
		            $url = SITE_MAIN.'/brand/detail/id/'.$brand['id'];
		            break;
		        }
		    }
		    $data['list'][$index][] = array(
		            'id' => $yohobuyBrandId, 
		            'name' => $booth['brand_name'],
		            'booths' => array('id' => $booth['booth_id'], 'x'=> $x, 'y' => $y ),
		            'boothId'=> $booth['booth_id'],
		            'url' => $url,
		            'floor'=> $booth['floor']
		    );
		}
		ksort($data['list']);
		return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
	}
	
	/**
	 * 获取限量推荐商品
	 * 
	 * @return json
	 */
	public function recomProductListAction()
	{
		list($offset, $limit) = $this->getMobileLimit();
		$data = array('total'=>'0', 'list'=> array());
		$state = 1;
		$data['total'] = Facade_Prod::getProdTotal($state);
		$products = Facade_Prod::getProd($state, $offset, $limit);
		foreach($products as $product)
		{
			$images = explode('|', $product['pic']);
			$data['list'][] = array(
					   'id' => $product['product_id'],
					   'brandId' => $product['brand_id'],
					   'price' => $product['price'], 'url'=> $product['url'],
					   'name'=> $product['name'], 'image'=> $images[0],
					   'skn' =>$product['product_skn'],
			         );
		}
		return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
	}
	
	/**
	 * 获取活动计划
	 * 
	 * @return json
	 */
	public function getActivityPlanListAction()
	{
		$planList = Facade_Activity::getActivityPlan();
		$data = array();
		$serverTime = time();
		foreach($planList as $plan)
		{
			$data[] = array('id' => $plan['id'], 'title' => $plan['title'],
						'content'=> $plan['content'],'place'=> $plan['place'],
					    'startTime' => $plan['start_time'], 'endTime' => $plan['end_time'],
					    'image' =>  Lib_Images::getImageUrl($plan['pic'],'source','fragmentimg'),
						'serverTime' => $serverTime,
					    'url' => SITE_MAIN.'/activity/plan',
			        );
		}
		return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
	}
	
	/**
	 * 获取活动介绍
	 * 
	 * @return json
	 */
	public function getActivityIntroduceAction()
	{
		$data = array(
					 'image'=> SITE_RES.'/images/yohood/activity_banner.jpg',
					 'address'=>'上海世贸商城',
					 'anavLatitude'=>'31.201374',//高德维度
					 'anavLongitude'=>'121.401041', //高德经度
				   	 'list' => array(
							 array('id'=> '1', 'title'=>'活动介绍','url'=> SITE_MAIN.'/activity/introduce/title/'.rawurlencode('活动介绍客户端')),
							 array('id'=> '2', 'title'=>'购物流程','url'=> SITE_MAIN.'/activity/introduce/title/'.rawurlencode('购物流程客户端')),
							// array('id'=> '3', 'title'=>'现场购票流程','url'=> SITE_MAIN.'/activity/introduce/title/'.rawurlencode('现场购票流程客户端')),
							// array('id'=> '4', 'title'=>'线上购票流程','url'=> SITE_MAIN.'/activity/introduce/title/'.rawurlencode('线上购票流程客户端')),
							 array('id'=> '5', 'title'=>'Q&A','url'=> SITE_MAIN.'/activity/qa'),
						)
					);
		return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
	}
	
	/**
	 * 合作伙伴
	 * 
	 * @return json
	 */
	public function getPartnerListAction()
	{
		$partnerList = Facade_Partner::getPartner();
		$data = array();
		foreach($partnerList as $partner)
		{
			$data[] = array(
						'id'=> $partner['id'],
						'title' =>$partner['name'],
						'logo'=> Lib_Images::getImageUrl($partner['pic'], 'source','fragmentimg'),
						'image' => Lib_Images::getImageUrl($partner['pic'], 'source','fragmentimg'),
						'description' => $partner['description'],
					    'createTime' => $partner['create_time']
			);
		}
		return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
	}
	
	/**
	 * 获取booth签到列表
	 * 
	 * @return json
	 */
	public function getBoothSignListAction()
	{
		$data = array_values(Facade_Brand::getSignLayout());		
		return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
	}
	
	/**
	 * 获取壁纸
	 * 
	 * @return json
	 */
	public function getWallpaperListAction()
	{
		$screenWidth = intval($this->_request->query('screenWidth', '640'));
		$screenHeight = intval($this->_request->query('screenHeight', '960'));
		$data = array('cover'=> SITE_IMG.'/yohood/wallpaper/cover.jpg', 'list'=> array(), 'url' => SITE_MAIN.'/default/wallpaper');
		$dir = SITE_IMG.'/yohood/wallpaper';
		if($screenWidth >=1440 && $screenHeight>=1200)
		{
			$dir.='/1440x1200/';
		}
		else if($screenWidth >=640 && $screenHeight>=1136)
		{
			$dir.='/640x1136/';
		}
		else
		{
			$dir.='/640x960/';
		}
		for($i = 1; $i<=11; $i++)
		{
			$data['list'][] = $dir.$i.'.jpg';
		}
		return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
	}
}