ExpressService.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\services;
  12. use think\facade\Cache;
  13. class ExpressService
  14. {
  15. const API = 'https://wuliu.market.alicloudapi.com/kdi';
  16. public static function query($no, $type = '')
  17. {
  18. $appCode = systemConfig('express_app_code');
  19. if (!$appCode) return false;
  20. $res = HttpService::getRequest(self::API, compact('no', 'type'), ['Authorization:APPCODE ' . $appCode]);
  21. return json_decode($res, true) ?: null;
  22. }
  23. public static function express($delivery_id)
  24. {
  25. if (Cache::has('express_' . $delivery_id)) {
  26. $result = Cache::get('express_' . $delivery_id);
  27. } else {
  28. $result = self::query($delivery_id);
  29. if (is_array($result) &&
  30. isset($result['result']) &&
  31. isset($result['result']['deliverystatus']) &&
  32. $result['result']['deliverystatus'] >= 3)
  33. $cacheTime = 0;
  34. else
  35. $cacheTime = 1800;
  36. $result = $result['result']['list'] ?? [];
  37. Cache::set('express_' . $delivery_id, $result, $cacheTime);
  38. }
  39. return $result;
  40. }
  41. }