ExpressService.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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)
  23. {
  24. if (Cache::has('express_' . $delivery_id)) {
  25. $result = Cache::get('express_' . $delivery_id);
  26. } else {
  27. $result = self::query($delivery_id);
  28. if (is_array($result) &&
  29. isset($result['result']) &&
  30. isset($result['result']['deliverystatus']) &&
  31. $result['result']['deliverystatus'] >= 3)
  32. $cacheTime = 0;
  33. else
  34. $cacheTime = 1800;
  35. $result = $result['result']['list'] ?? [];
  36. Cache::set('express_' . $delivery_id, $result, $cacheTime);
  37. }
  38. return $result;
  39. }
  40. }