| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Api;
- use App\Models\CoinLogModel;
- use App\Models\MemberModel;
- use App\Models\UserModel;
- use App\Services\BaseService;
- use App\Services\ConfigService;
- use App\Services\RedisService;
- use Earnp\GoogleAuthenticator\GoogleAuthenticator;
- /**
- * 币种明细(提币、存币)-服务类
- * Class CoinLogService
- * @package App\Services\Api
- */
- class CoinLogService extends BaseService
- {
- // 静态对象
- protected static $instance = null;
- /**
- * 构造函数
- * @since 2020/11/10
- * CoinLogService constructor.
- */
- public function __construct()
- {
- $this->model = new CoinLogModel();
- $this->memberModel = new MemberModel();
- }
- /**
- * 静态入口
- * @return static|null
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = (new static());
- }
- return self::$instance;
- }
- /**
- * 获取列表
- * @param $params 参数
- * @param int $pageSize 分页大小:默认 15
- * @return array
- */
- public function getDataList($params, $pageSize = 15)
- {
- $where = ['a.mark' => 1];
- $type = isset($params['type']) ? $params['type'] : 1;
- $status = isset($params['status']) ? $params['status'] : 0;
- $changeType = isset($params['change_type']) ? $params['change_type'] : 1;
- $contactType = isset($params['contact_type']) ? $params['contact_type'] : 1;
- $coinType = isset($params['coin_type']) ? $params['coin_type'] : 1;
- $userId = isset($params['user_id']) ? $params['user_id'] : 0;
- if ($type > 0) {
- $where['a.type'] = $type;
- }
- if ($status > 0) {
- $where['a.status'] = $status;
- }
- if ($contactType > 0) {
- $where['a.contact_type'] = $contactType;
- }
- if ($changeType > 0) {
- $where['a.change_type'] = $changeType;
- }
- if ($coinType > 0) {
- $where['a.coin_type'] = $coinType;
- }
- if ($userId > 0) {
- $where['a.user_id'] = $userId;
- }
- $list = $this->model->from('coin_logs as a')
- ->leftJoin('member as m', 'm.id', '=', 'a.user_id')
- ->where($where)
- ->where(function ($query) use ($params) {
- $keyword = isset($params['keyword']) ? $params['keyword'] : '';
- if ($keyword) {
- $query->where('a.order_no', 'like', "{$keyword}")->orWhere('m.username', 'like', "%{$keyword}%");
- }
- // 日期
- $date = isset($params['date']) ? $params['date'] : [];
- $start = isset($date[0]) ? $date[0] : '';
- $end = isset($date[1]) ? $date[1] : '';
- $end = $start >= $end ? '' : $end;
- if ($start) {
- $query->where('a.create_time', '>=', strtotime($start));
- }
- if ($end) {
- $query->where('a.create_time', '<', strtotime($end));
- }
- })
- ->select(['a.*', 'm.username'])
- ->orderBy('a.create_time', 'desc')
- ->paginate($pageSize > 0 ? $pageSize : 9999999);
- $list = $list ? $list->toArray() : [];
- if ($list) {
- foreach ($list['data'] as &$item) {
- $item['time_text'] = $item['create_time'] ? datetime(strtotime($item['create_time']), 'm-d H:i') : '';
- }
- }
- return [
- 'pageSize' => $pageSize,
- 'total' => isset($list['total']) ? $list['total'] : 0,
- 'list' => isset($list['data']) ? $list['data'] : []
- ];
- }
- /**
- * 验证是否存在
- * @param \App\Services\字段名 $field
- * @param \App\Services\字段值 $value
- * @param string $pk
- * @return mixed
- */
- public function checkExists($field, $value, $pk = 'id', $status = 0)
- {
- $cacheKey = "caches:coinLogs:exists:{$field}_{$value}";
- if ($result = RedisService::get($cacheKey)) {
- return $result;
- }
- $result = parent::checkExists($field, $value, $pk, $status);
- if ($result) {
- RedisService::set($cacheKey, $result, rand(3, 5));
- }
- return $result;
- }
- }
|