| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace app\common\service;
- use app\common\model\ServicesOrderModel;
- use app\common\model\YsBankListModel;
- use utils\RedisCache;
- /**
- * 服务商订单 by wes
- * Class ServiceOrderService
- * @package app\common\service
- */
- class ServiceOrderService
- {
- protected static $instance = null;
- protected $model = null;
- public function __construct()
- {
- $this->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;
- }
- }
|