Express.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace addons\shopro\controller;
  3. use addons\shopro\exception\Exception;
  4. use addons\shopro\model\Order;
  5. use addons\shopro\model\User;
  6. use think\Db;
  7. use think\Log;
  8. class Express extends Base
  9. {
  10. protected $noNeedLogin = ['callback'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 物流信息订阅回调接口
  14. */
  15. public function callback()
  16. {
  17. $requestData = $this->request->post();
  18. $expressLib = new \addons\shopro\library\Express();
  19. // 信息记录日志
  20. // \think\Log::write('expresscallback:'. json_encode($requestData));
  21. $data = json_decode(html_entity_decode($requestData['RequestData']), true);
  22. $expressData = $data['Data'];
  23. foreach ($expressData as $key => $express) {
  24. // 查找包裹
  25. $orderExpress = \addons\shopro\model\OrderExpress::with('order')->where('express_code', $express['ShipperCode'])
  26. ->where('express_no', $express['LogisticCode'])
  27. ->find();
  28. if (!$orderExpress) {
  29. // 包裹不存在,记录日志信息,然后继续下一个
  30. \think\Log::write('orderExpressNotFound:' . json_encode($express));
  31. continue;
  32. }
  33. if (!$express['Success']) {
  34. // 失败了
  35. if (isset($express['Reason']) && ($express['Reason'] == '三天无轨迹' || $express['Reason'] == '七天无轨迹')) {
  36. // 需要重新订阅
  37. $expressLib->subscribe([
  38. 'express_code' => $express['ShipperCode'],
  39. 'express_no' => $express['LogisticCode']
  40. ], $orderExpress, $orderExpress->order);
  41. }
  42. \think\Log::write('orderExpressReason:' . json_encode($express));
  43. continue;
  44. }
  45. $expressLib->checkAndAddTraces($orderExpress, $express);
  46. }
  47. return $expressLib->setPushResult(true);
  48. }
  49. }