ShopOrderShippingService.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\common\service;
  3. use app\common\model\ShopOrderShippingModel;
  4. use app\common\model\YsBankListModel;
  5. use utils\RedisCache;
  6. /**
  7. * 订单配送信息 by wes
  8. * Class ShopOrderShippingService
  9. * @package app\common\service
  10. */
  11. class ShopOrderShippingService
  12. {
  13. protected static $instance = null;
  14. protected $model = null;
  15. public function __construct()
  16. {
  17. $this->model = new ShopOrderShippingModel();
  18. }
  19. /**
  20. * 静态化入口
  21. * @return static|null
  22. */
  23. public static function make()
  24. {
  25. if (!self::$instance) {
  26. self::$instance = new static();
  27. }
  28. return self::$instance;
  29. }
  30. /**
  31. * 根据单号获取订单信息(有缓存)
  32. * @param $orderId 订单号
  33. * @param string $field 返沪字段
  34. * @param bool $cache 是否缓存,默认是
  35. * @return array|mixed
  36. */
  37. public function getInfo($orderId, $field='', $cache=true)
  38. {
  39. $cacheKey = "caches:orders:shipping:info_{$orderId}".($field? '_'.md5($field):'');
  40. $data = RedisCache::get($cacheKey);
  41. if($data && $cache){
  42. return $data;
  43. }
  44. $where = ['order_id'=> $orderId];
  45. $field = $field? $field : 'sp_id,order_id,sp_name,sp_mobile,sp_province,sp_city,sp_county,sp_remark,sp_mergename';
  46. $data = $this->model->where($where)->field($field)->findOrEmpty();
  47. $data = $data? $data->toArray() : [];
  48. if($data && $cache){
  49. RedisCache::set($cacheKey, $data, rand(10,20));
  50. }
  51. return $data;
  52. }
  53. }