ExpressService.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020/6/17
  7. *
  8. *
  9. */
  10. namespace crmeb\services;
  11. use think\facade\Cache;
  12. class ExpressService
  13. {
  14. const API = 'https://wuliu.market.alicloudapi.com/kdi';
  15. public static function query($no, $type = '')
  16. {
  17. $appCode = systemConfig('express_app_code');
  18. if (!$appCode) return false;
  19. $res = HttpService::getRequest(self::API, compact('no'), ['Authorization:APPCODE ' . $appCode]);
  20. return json_decode($res, true) ?: null;
  21. }
  22. public static function express($delivery_id, $delivery_type = 1)
  23. {
  24. // 虚拟发货不返回物流信息
  25. if ($delivery_type == 3) {
  26. return [];
  27. }
  28. if (Cache::has('express_' . $delivery_id)) {
  29. $result = Cache::get('express_' . $delivery_id);
  30. } else {
  31. $result = self::query($delivery_id);
  32. if (is_array($result) &&
  33. isset($result['result']) &&
  34. isset($result['result']['deliverystatus']) &&
  35. $result['result']['deliverystatus'] >= 3)
  36. $cacheTime = 0;
  37. else
  38. $cacheTime = 1800;
  39. $result = $result['result']['list'] ?? [];
  40. Cache::set('express_' . $delivery_id, $result, $cacheTime);
  41. }
  42. return $result;
  43. }
  44. }