Express.php
1.9 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
<?php
namespace addons\shopro\controller;
use addons\shopro\exception\Exception;
use addons\shopro\model\Order;
use addons\shopro\model\User;
use think\Db;
use think\Log;
class Express extends Base
{
protected $noNeedLogin = ['callback'];
protected $noNeedRight = ['*'];
/**
* 物流信息订阅回调接口
*/
public function callback()
{
$requestData = $this->request->post();
$expressLib = new \addons\shopro\library\Express();
// 信息记录日志
\think\Log::write('expresscallback:'. json_encode($requestData));
$data = json_decode(html_entity_decode($requestData['RequestData']), true);
$expressData = $data['Data'];
foreach ($expressData as $key => $express) {
// 查找包裹
$orderExpress = \addons\shopro\model\OrderExpress::with('order')->where('express_code', $express['ShipperCode'])
->where('express_no', $express['LogisticCode'])
->find();
if (!$orderExpress) {
// 包裹不存在,记录日志信息,然后继续下一个
\think\Log::write('orderExpressNotFound:' . json_encode($express));
continue;
}
if (!$express['Success']) {
// 失败了
if ($express['Reason'] == '三天无轨迹' || $express['Reason'] == '七天无轨迹') {
// 需要重新订阅
$expressLib->subscribe([
'express_code' => $express['ShipperCode'],
'express_no' => $express['LogisticCode']
], $orderExpress, $orderExpress->order);
}
continue;
}
$expressLib->checkAndAddTraces($orderExpress, $express);
}
return $expressLib->setPushResult(true);
}
}