Logistics.php
5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/**
* 物流相关
* @author tongdesheng
*
*/
class YHMApi_App_V1_Logistics extends YHMApi_App_V1_Base {
/**
* 获取货流公司列表
*/
public static function getCompanyList(array $params, $fileds = '*') {
$data = YHMOrders_Models_Logistics_Client::getList();
$companyList = array();
foreach ($data as $k => $v) {
$list = array(
'id' => $v['id'],
'company_name' => $v['company_name'],
'initials' => $v['initials'],
'pinyin' => $v['pinyin'],
'logistics_logo' => YHMUpload_Images::template($v['logo'], 'yhfair')
);
$companyList[] = $list;
}
return self::result(200, '快递公司列表', $companyList);
}
/**
* 查看物流信息
* @param array $params
* @param string $fields
*/
public static function getLogisticsDetail(array $params, $fields = "*") {
$uid = $params['uid'];
$order_code = $params['order_code']; //订单号
if (empty($order_code)) {
return self::result(400, '订单号不能为空');
}
//根据订单号查出物流信息
$order_delivery = YHMOrders_Models_Delivery_Client::getOneByOrderCode($order_code);
if (empty($order_delivery)) {
return self::result(400, '没有查到物流信息');
}
//物流公司信息
$company = YHMOrders_Models_Logistics_Client::getOneById($order_delivery['deliver_company_id']);
$company_code = $company['company_code']; //公司代码
$list= YHMOrders_Models_Logistics_Client::getOrderLogistics($order_code);
if ($list)
{
// print_r($list['detail_list']);
$retData= json_decode($list['detail_list'], true);
return self::result(200, '获取成功', $retData);
}
// $req_config = array(
// 'adapter' => 'Zend_Http_Client_Adapter_Curl',
// 'timeout' => 5000
// );
$retData = array();
//先查库, 如果库里有信息就不调用接口
try {
$mc = YHMUtils_Mc::getMc();
$retData = $mc->get('logistics_' . $order_code);
// if (!isset($retData['message']))
{
// $client = new Zend_Http_Client(YHMConfig_Express::$_url, $req_config);
// $data = array(
// 'appid' => YHMConfig_Express::$_appid,
// 'com' => $company_code,
// 'nu' => $order_delivery['delivery_code']
// );
// $client->setParameterGet($data);
// $requestResults = $client->request('GET');
// $result = $requestResults->getBody();
// $express = json_decode($result, true);
// $retData = array(
// 'logistics_company' => $company['company_name'],
// 'logistics_code' => $order_delivery['delivery_code'],
// 'logistics_logo' => YHMUpload_Images::template($company['logo'], 'yhfair'),
// 'detail_list' => array()
// );
// if (!empty($express['data']['info']['context'])) {
// foreach ($express['data']['info']['context'] as $oneData) {
// $retData['detail_list'][] = array(
// 'status_time' => empty($oneData['time']) ? '' : $oneData['time'],
// 'status_info' => $oneData['desc']
// );
// }
// }
$retData = array(
'logistics_company' => $company['company_name'],
'logistics_code' => $order_delivery['delivery_code'],
'logistics_logo' => YHMUpload_Images::template($company['logo'], 'yhfair'),
'detail_list' => array()
);
$url="http://www.kuaidi100.com/query?type=$company_code&postid=".$order_delivery['delivery_code']."&id=1&valicode=&temp=0.2546041894394805";
$list=file_get_contents($url);
// print_r(json_decode($list,true));
$express=json_decode($list,true);
if (!empty($express['data'])) {
foreach ($express['data'] as $oneData) {
$retData['detail_list'][] = array(
'status_time' => empty($oneData['time']) ? '' : strtotime($oneData['time']),
'status_info' => $oneData['context']
);
}
// print_r($list);
$retData['message']=$express['message'];
// print_r($express);
if ($express['state']==3)
{
$mc->set('logistics_' . $order_code,$retData);
// echo $order_code;
YHMOrders_Models_Logistics_Client::setOrderLogistics($order_code, json_encode($retData));
}
$mc->set('logistics_' . $order_code,$retData,84600);
}
}
} catch (Exception $ex) {
$retData['message'] = $ex->getMessage();
$retData['status_time'] = 0;
$retData['status_info'] = 0;
}
return self::result(200, '获取成功', $retData);
}
}