ServiceOrderService.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\common\service;
  3. use app\common\model\ServicesOrderModel;
  4. use app\common\model\YsBankListModel;
  5. use utils\RedisCache;
  6. /**
  7. * 服务商订单 by wes
  8. * Class ServiceOrderService
  9. * @package app\common\service
  10. */
  11. class ServiceOrderService
  12. {
  13. protected static $instance = null;
  14. protected $model = null;
  15. public function __construct()
  16. {
  17. $this->model = new ServicesOrderModel();
  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 $orderSn 订单号
  33. * @param int $uid 所属用户ID
  34. * @param int $status 状态
  35. * @param string $field 返沪字段
  36. * @param bool $cache 是否缓存,默认是
  37. * @return array|mixed
  38. */
  39. public function getInfoBySn($orderSn, $uid=0, $status=0, $field='', $cache=false)
  40. {
  41. $cacheKey = "caches:serviceOrders:info:sn{$orderSn}_{$uid}".($field? '_'.md5($field):'');
  42. $data = RedisCache::get($cacheKey);
  43. if($data && $cache){
  44. return $data;
  45. }
  46. $where = ['recharge_sn'=> $orderSn];
  47. if($uid>0){
  48. $where['user_id'] = $uid;
  49. }
  50. if($status>0){
  51. $where['status'] = $status;
  52. }
  53. $field = $field? $field : 'order_id,recharge_sn as order_sn,user_id,payment,total_price,status,pay_type';
  54. $data = $this->model->where($where)->field($field)->findOrEmpty();
  55. $data = $data? $data->toArray() : [];
  56. if($data && $cache){
  57. RedisCache::set($cacheKey, $data, rand(5,10));
  58. }
  59. return $data;
  60. }
  61. }