model = new ServicesOrderModel(); } /** * 静态化入口 * @return static|null */ public static function make() { if (!self::$instance) { self::$instance = new static(); } return self::$instance; } /** * 根据单号获取订单信息(有缓存) * @param $orderSn 订单号 * @param int $uid 所属用户ID * @param int $status 状态 * @param string $field 返沪字段 * @param bool $cache 是否缓存,默认是 * @return array|mixed */ public function getInfoBySn($orderSn, $uid=0, $status=0, $field='', $cache=false) { $cacheKey = "caches:serviceOrders:info:sn{$orderSn}_{$uid}".($field? '_'.md5($field):''); $data = RedisCache::get($cacheKey); if($data && $cache){ return $data; } $where = ['recharge_sn'=> $orderSn]; if($uid>0){ $where['user_id'] = $uid; } if($status>0){ $where['status'] = $status; } $field = $field? $field : 'order_id,recharge_sn as order_sn,user_id,payment,total_price,status,pay_type'; $data = $this->model->where($where)->field($field)->findOrEmpty(); $data = $data? $data->toArray() : []; if($data && $cache){ RedisCache::set($cacheKey, $data, rand(5,10)); } return $data; } }