<?php
/**
*物流API
*/
class expressAction extends baseAction
{
	/**
	  * @method 获取物流信息
	  * @http   get  http://192.168.1.115/www/API/home/index.php/express/getTrack?ext_exp_code=yuantong&ext_number=888386718169629838+&ext_from=B2C&token=B2C-8FD3-D52A-7425-TEST
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  ext_id             int          1、提供ext_id
	  * @param  ext_exp_code       string		2、提供物流代码 ext_exp_code、物流单号ext_number
	  * @param  ext_number         string    
	  * @param  ext_from           string    
	  * @param  ext_extnum           string    顺丰的 顺丰快递必须添加收或寄件人手机尾号4位(单号:4位手机号)
	  * @author soul
	  * @copyright 2017/4/13
	  * @return {"status":true,"data":{"ext_id":"33","ext_exp_code":"shentong","exp_name":null,"ext_number":"3333666120059","ext_track":"[{\"time\":1499696133,\"context\":\"\\u5742\\u7530\\u8425\\u4e1a\\u70b9-\\u6768\\u4e2d\\u946b-\\u5df2\\u6536\\u4ef6\"}....]"},"code":0}
	  */
	function getTrack()
	{
		$MainExpress = new MainExpress();
		if(!empty($_GET['ext_id']))
		{
			//已有
			$dataArr = ['ext_id'=>(int) $_GET['ext_id']];
		}
		else
		{
			//新建
			$dataArr = [
				'ext_exp_code'=>trim($_GET['ext_exp_code']),
				'ext_number'=>trim($_GET['ext_number']),
				'ext_from'=>trim($_GET['ext_from']),
				'ext_extnum'=>isset($_GET['ext_extnum'])? trim($_GET['ext_extnum']): '',
			];
		}
		$res = $MainExpress->getTrack($dataArr);
		echo json_encode($res);
	}

	/**
	  * @method 获取物流公司列表
	  * @http   get
	  * @param  token              string [必填] 调用接口凭证 (post|get)
	  * @param  type               string 默认【base】 || all
	  * @author soul
	  * @copyright 2017/4/13
	  * @return base {"status":true,"data":[{"exp_code":"325","exp_name":"\u5706\u901a\u901f\u9012"},{"exp_code":"326","exp_name":"\u97f5\u8fbe\u5feb\u9012"}....]}
	  * @return all {"status":true,"data":[{"exp_code":"325","exp_name":"\u5706\u901a\u901f\u9012","exp_url":"http:\/\/www.yto.net.cn\/","exp_telephone":"95554","exp_initial":null,"exp_seq":"2"}....]}
	  */
	function getExpress()
	{
		$MainExpress = new MainExpress();
		$res = $MainExpress->getExpress();
		$filedArr = !empty($_GET['type']) && $_GET['type'] == 'all'? ['exp_code', 'exp_name', 'exp_url', 'exp_telephone', 'exp_initial', 'exp_seq']:['exp_code', 'exp_name'];
		$arr = [];
		foreach($res['data'] as $v)
		{
			if(empty($v['exp_status'])) continue;
			$temp = [];
			foreach($filedArr as $filed)
			{
				$temp[$filed] = $v[$filed];
			}
			$arr[] = $temp;
		}
		$res['data'] = $arr;
		echo json_encode($res);
	}
}