| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace app\common\service;
- use app\common\model\ShopOrderShippingModel;
- use app\common\model\YsBankListModel;
- use utils\RedisCache;
- /**
- * 订单配送信息 by wes
- * Class ShopOrderShippingService
- * @package app\common\service
- */
- class ShopOrderShippingService
- {
- protected static $instance = null;
- protected $model = null;
- public function __construct()
- {
- $this->model = new ShopOrderShippingModel();
- }
- /**
- * 静态化入口
- * @return static|null
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = new static();
- }
- return self::$instance;
- }
- /**
- * 根据单号获取订单信息(有缓存)
- * @param $orderId 订单号
- * @param string $field 返沪字段
- * @param bool $cache 是否缓存,默认是
- * @return array|mixed
- */
- public function getInfo($orderId, $field='', $cache=true)
- {
- $cacheKey = "caches:orders:shipping:info_{$orderId}".($field? '_'.md5($field):'');
- $data = RedisCache::get($cacheKey);
- if($data && $cache){
- return $data;
- }
- $where = ['order_id'=> $orderId];
- $field = $field? $field : 'sp_id,order_id,sp_name,sp_mobile,sp_province,sp_city,sp_county,sp_remark,sp_mergename';
- $data = $this->model->where($where)->field($field)->findOrEmpty();
- $data = $data? $data->toArray() : [];
- if($data && $cache){
- RedisCache::set($cacheKey, $data, rand(10,20));
- }
- return $data;
- }
- }
|