CoinLogService.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Common;
  12. use App\Models\CoinLogModel;
  13. use App\Services\BaseService;
  14. use App\Services\RedisService;
  15. /**
  16. * 币种明细(提币、存币)-服务类
  17. * Class CoinLogService
  18. * @package App\Services\Common
  19. */
  20. class CoinLogService extends BaseService
  21. {
  22. // 静态对象
  23. protected static $instance = null;
  24. /**
  25. * 构造函数
  26. * @since 2020/11/10
  27. * CoinLogService constructor.
  28. */
  29. public function __construct()
  30. {
  31. $this->model = new CoinLogModel();
  32. }
  33. /**
  34. * 静态入口
  35. * @return static|null
  36. */
  37. public static function make()
  38. {
  39. if (!self::$instance) {
  40. self::$instance = (new static());
  41. }
  42. return self::$instance;
  43. }
  44. /**
  45. * 获取列表
  46. * @param $params 参数
  47. * @param int $pageSize 分页大小:默认 15
  48. * @return array
  49. */
  50. public function getDataList($params, $pageSize = 15)
  51. {
  52. $where = ['a.mark' => 1];
  53. $type = isset($params['type'])? $params['type'] : 1;
  54. $changeType = isset($params['change_type'])? $params['change_type'] : 1;
  55. $contactType = isset($params['contact_type'])? $params['contact_type'] : 1;
  56. $coinType = isset($params['coin_type'])? $params['coin_type'] : 1;
  57. $userId = isset($params['user_id'])? $params['user_id'] : 0;
  58. if($type>0){
  59. $where['a.type'] = $type;
  60. }
  61. if($contactType>0){
  62. $where['a.contact_type'] = $contactType;
  63. }
  64. if($changeType>0){
  65. $where['a.change_type'] = $changeType;
  66. }
  67. if($coinType>0){
  68. $where['a.coin_type'] = $coinType;
  69. }
  70. if($userId>0){
  71. $where['a.user_id'] = $userId;
  72. }
  73. $list = $this->model->from('coin_logs as a')
  74. ->leftJoin('member as m', 'm.id', '=', 'a.user_id')
  75. ->where($where)
  76. ->where(function ($query) use($params){
  77. $keyword = isset($params['keyword'])? $params['keyword'] : '';
  78. if($keyword){
  79. $query->where('a.order_no','like',"{$keyword}")->orWhere('m.username','like',"%{$keyword}%");
  80. }
  81. })
  82. ->select(['a.*', 'm.username'])
  83. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  84. $list = $list? $list->toArray() :[];
  85. if($list){
  86. foreach($list['data'] as &$item){
  87. $item['time_text'] = $item['create_time']? datetime(strtotime($item['create_time']), 'm-d H:i'):'';
  88. }
  89. }
  90. return [
  91. 'pageSize'=> $pageSize,
  92. 'total'=>isset($list['total'])? $list['total'] : 0,
  93. 'list'=> isset($list['data'])? $list['data'] : []
  94. ];
  95. }
  96. /**
  97. * 验证是否存在
  98. * @param \App\Services\字段名 $field
  99. * @param \App\Services\字段值 $value
  100. * @param string $pk
  101. * @return mixed
  102. */
  103. public function checkExists($field, $value, $pk = 'id', $status=0)
  104. {
  105. $cacheKey = "caches:coinLogs:exists:{$field}_{$value}";
  106. if($result = RedisService::get($cacheKey)){
  107. return $result;
  108. }
  109. $result = parent::checkExists($field, $value, $pk, $status);
  110. if($result){
  111. RedisService::set($cacheKey, $result, rand(3,5));
  112. }
  113. return $result;
  114. }
  115. }