validate([ 'page' => ['nullable', 'integer', 'min:1'], 'limit' => ['nullable', 'integer', 'min:1'], 'type' => ['nullable', 'integer'], 'member_id' => ['nullable', 'string', 'min:1'], 'related_id' => ['nullable', 'string', 'min:1'], 'change_type' => ['nullable', 'string', 'in:' . implode(',', request()->input('is_fancai') == 1 ? MemberBonusLogService::types() : BalanceLogService::$RW)], 'start_time' => ['nullable', 'date', 'date_format:Y-m-d', 'required_with:end_time'], 'end_time' => ['nullable', 'date', 'date_format:Y-m-d', 'required_with:start_time'], 'account' => ['nullable', 'string', 'max:64'], 'first_name' => ['nullable'], 'is_fancai' => ['nullable', 'integer','in:0,1'], // 用户类型/注册来源:-1 tg用户,0 后台客服账号,1 真实用户,2 虚拟用户 'from' => ['nullable'], ]); $page = request()->input('page', 1); $limit = request()->input('limit', 10); // 旧版彩金页面固定传 type=2;彩金现在涵盖可用余额及历史冻结奖励。 if (!empty($params['is_fancai'])) { $changeType = $params['change_type'] ?? null; unset($params['type'], $params['change_type']); } $query = BalanceLog::join('users', 'users.member_id', '=', 'balance_logs.member_id') ->where(BalanceLogService::getWhere($params)); if (!empty($params['is_fancai'])) { $bonusLogs = new MemberBonusLogService(); $data['change_types'] = MemberBonusLogService::types(); $query = $query->whereIn('balance_logs.change_type', MemberBonusLogService::LEDGER_TYPES) ->whereIn('balance_logs.type', [1, 2])->where('balance_logs.amount', '>', 0); $bonusLogs->filter($query, $changeType); } else { $data['change_types'] = BalanceLogService::$RW; } // 统计与列表共用筛选条件;clone 避免 count/sum 影响后续分页查询 $data['total'] = (clone $query)->count(); $data['total_amount'] = bcadd((clone $query)->sum('balance_logs.amount'), 0, 2); $data['data'] = $query->select("balance_logs.*", "users.first_name", "users.account", "users.admin_note as user_admin_note", "users.from as user_from") ->orderByDesc('balance_logs.id') ->forPage($page, $limit) ->with(['member']) ->get() ->toArray(); if (isset($bonusLogs)) $data['data'] = $bonusLogs->decorate($data['data']); } catch (ValidationException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first()); } catch (Exception $e) { return $this->error($e->getCode(),$e->getMessage()); } return $this->success($data); } }