CoinLogService.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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\Api;
  12. use App\Models\CoinLogModel;
  13. use App\Models\MemberModel;
  14. use App\Models\UserModel;
  15. use App\Services\BaseService;
  16. use App\Services\ConfigService;
  17. use App\Services\RedisService;
  18. use Earnp\GoogleAuthenticator\GoogleAuthenticator;
  19. /**
  20. * 币种明细(提币、存币)-服务类
  21. * Class CoinLogService
  22. * @package App\Services\Api
  23. */
  24. class CoinLogService extends BaseService
  25. {
  26. // 静态对象
  27. protected static $instance = null;
  28. /**
  29. * 构造函数
  30. * @since 2020/11/10
  31. * CoinLogService constructor.
  32. */
  33. public function __construct()
  34. {
  35. $this->model = new CoinLogModel();
  36. $this->memberModel = new MemberModel();
  37. }
  38. /**
  39. * 静态入口
  40. * @return static|null
  41. */
  42. public static function make()
  43. {
  44. if (!self::$instance) {
  45. self::$instance = (new static());
  46. }
  47. return self::$instance;
  48. }
  49. /**
  50. * 获取列表
  51. * @param $params 参数
  52. * @param int $pageSize 分页大小:默认 15
  53. * @return array
  54. */
  55. public function getDataList($params, $pageSize = 15)
  56. {
  57. $where = ['a.mark' => 1];
  58. $type = isset($params['type']) ? $params['type'] : 1;
  59. $status = isset($params['status']) ? $params['status'] : 0;
  60. $changeType = isset($params['change_type']) ? $params['change_type'] : 1;
  61. $contactType = isset($params['contact_type']) ? $params['contact_type'] : 1;
  62. $coinType = isset($params['coin_type']) ? $params['coin_type'] : 1;
  63. $userId = isset($params['user_id']) ? $params['user_id'] : 0;
  64. if ($type > 0) {
  65. $where['a.type'] = $type;
  66. }
  67. if ($status > 0) {
  68. $where['a.status'] = $status;
  69. }
  70. if ($contactType > 0) {
  71. $where['a.contact_type'] = $contactType;
  72. }
  73. if ($changeType > 0) {
  74. $where['a.change_type'] = $changeType;
  75. }
  76. if ($coinType > 0) {
  77. $where['a.coin_type'] = $coinType;
  78. }
  79. if ($userId > 0) {
  80. $where['a.user_id'] = $userId;
  81. }
  82. $list = $this->model->from('coin_logs as a')
  83. ->leftJoin('member as m', 'm.id', '=', 'a.user_id')
  84. ->where($where)
  85. ->where(function ($query) use ($params) {
  86. $keyword = isset($params['keyword']) ? $params['keyword'] : '';
  87. if ($keyword) {
  88. $query->where('a.order_no', 'like', "{$keyword}")->orWhere('m.username', 'like', "%{$keyword}%");
  89. }
  90. // 日期
  91. $date = isset($params['date']) ? $params['date'] : [];
  92. $start = isset($date[0]) ? $date[0] : '';
  93. $end = isset($date[1]) ? $date[1] : '';
  94. $end = $start >= $end ? '' : $end;
  95. if ($start) {
  96. $query->where('a.create_time', '>=', strtotime($start));
  97. }
  98. if ($end) {
  99. $query->where('a.create_time', '<', strtotime($end));
  100. }
  101. })
  102. ->select(['a.*', 'm.username'])
  103. ->orderBy('a.create_time', 'desc')
  104. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  105. $list = $list ? $list->toArray() : [];
  106. if ($list) {
  107. foreach ($list['data'] as &$item) {
  108. $item['time_text'] = $item['create_time'] ? datetime(strtotime($item['create_time']), 'm-d H:i') : '';
  109. }
  110. }
  111. return [
  112. 'pageSize' => $pageSize,
  113. 'total' => isset($list['total']) ? $list['total'] : 0,
  114. 'list' => isset($list['data']) ? $list['data'] : []
  115. ];
  116. }
  117. /**
  118. * 验证是否存在
  119. * @param \App\Services\字段名 $field
  120. * @param \App\Services\字段值 $value
  121. * @param string $pk
  122. * @return mixed
  123. */
  124. public function checkExists($field, $value, $pk = 'id', $status = 0)
  125. {
  126. $cacheKey = "caches:coinLogs:exists:{$field}_{$value}";
  127. if ($result = RedisService::get($cacheKey)) {
  128. return $result;
  129. }
  130. $result = parent::checkExists($field, $value, $pk, $status);
  131. if ($result) {
  132. RedisService::set($cacheKey, $result, rand(3, 5));
  133. }
  134. return $result;
  135. }
  136. }