model = new MoneyLogModel(); } /** * 静态化入口 * @return static|null */ public static function make() { if (!self::$instance) { self::$instance = new static(); } return self::$instance; } /** * 获取列表 * @param $params 查询参数 * @param int $pageSize * @param string $field * @param string $cache * @return array|mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getList($params, $pageSize = 10, $field = '', $cache = true) { $page = request()->post('page', 1); $cacheKey = "caches:temp:profitLogs:{$page}_{$pageSize}_" . md5(json_encode($params)); $data = RedisCache::get($cacheKey); if ($data && $cache) { return $data; } $typeArr = config('type.profit'); $where = ['status' => 1]; $type = isset($params['type']) ? intval($params['type']) : 0; if ($type) { $where['type'] = $type; } $field = $field ? $field : 'id,uid,money,status,state,type,create_at,remark'; $data = $this->model->where($where) ->field($field) ->withAttr('type', function ($value, $data) use ($typeArr) { return isset($typeArr[$value]) ? $typeArr[$value] : '未知类型'; }) ->order('id desc') ->page($page, $pageSize)->select(); $data = $data ? $data->toArray() : []; if ($data && $cache) { RedisCache::set($cacheKey, $data, rand(3, 5)); } return $data; } }