| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace App\Http\Controllers\agent;
- use App\Http\Controllers\AgentApiController;
- use App\Services\Agent\AgentMemberService;
- use App\Services\MemberDailyReportService;
- use App\Services\UserService;
- use Illuminate\Http\Request;
- class MemberController extends AgentApiController
- {
- private const HIDDEN_USER_FIELDS = ['admin_note', 'real_name', 'secret_key', 'secret_pass', 'visitor_id', 'agent_user_code'];
- private const WALLET_FIELDS = ['id', 'member_id', 'coin', 'available_balance', 'frozen_balance', 'total_balance', 'yuebao',
- 'yuebao_invest', 'wager_required', 'wager_completed'];
- /** 入股代理(股东)不能查看会员明细(会员列表、会员日报、财务统计、注单统计),改用 GET /agent/reports/period。 */
- private function denyEquity(): void
- {
- if ($this->currentAgent()->isEquity()) throw new \RuntimeException('入股代理不能查看会员明细,请使用周期报表');
- }
- /** 会员列表:字段与总后台 GET /admin/user 一致,只查本代理的会员;不提供充值、提现、冻结、解冻。 */
- public function index(Request $request)
- {
- return $this->execute(function () use ($request) {
- $this->denyEquity();
- $fields = 'available_balance,created_at,last_active_time,frozen_balance,yuebao,total_consume,wager_required,wager_completed,wager_remaining,third_game_total_balance';
- $search = $request->validate([
- 'page' => ['nullable', 'integer', 'min:1'], 'limit' => ['nullable', 'integer', 'min:1', 'max:100'],
- 'member_id' => ['nullable', 'string', 'min:1'], 'account' => ['nullable', 'string', 'min:1'],
- 'like_first_name' => ['nullable', 'string', 'min:1'], 'username' => ['nullable', 'string', 'min:1'],
- 'register_ip' => ['nullable', 'string', 'min:1'], 'level' => ['nullable'], 'is_online' => ['nullable', 'boolean'],
- 'sort_field' => ['nullable', 'string', 'in:' . $fields], 'sort_order' => ['nullable', 'string', 'in:asc,desc'],
- 'start_time' => ['nullable', 'date_format:Y-m-d', 'required_with:end_time'],
- 'end_time' => ['nullable', 'date_format:Y-m-d', 'required_with:start_time'],
- ]);
- $search['agent_id'] = (int) $this->currentAgent()->id;
- $result = UserService::paginate($search, $search['sort_order'] ?? 'desc', $search['sort_field'] ?? 'created_at');
- foreach ($result['data'] as $user) {
- // 去掉总后台专用字段:后台备注、实名、找回密钥、推荐人(可能属于其他代理)。
- // 上级都是当前代理自己,不返回 system_agent / superior
- $user->makeHidden(array_merge(self::HIDDEN_USER_FIELDS, ['superior']))->unsetRelation('agent')->unsetRelation('systemAgent');
- $user->wallet?->setVisible(self::WALLET_FIELDS);
- }
- return $result;
- });
- }
- public function dailyReport(Request $request, MemberDailyReportService $reports)
- {
- return $this->execute(function () use ($request, $reports) {
- $this->denyEquity();
- $data = $request->validate([
- 'page' => ['nullable', 'integer', 'min:1'], 'limit' => ['nullable', 'integer', 'min:1', 'max:100'],
- 'start_date' => ['nullable', 'date_format:Y-m-d'], 'end_date' => ['nullable', 'date_format:Y-m-d', 'after_or_equal:start_date'],
- 'member_id' => ['nullable', 'string', 'max:64'], 'username' => ['nullable', 'string', 'max:128'],
- ]);
- return $reports->paginate($data, $this->currentAgent());
- });
- }
- public function finance(Request $request, AgentMemberService $service)
- {
- return $this->execute(function () use ($request, $service) {
- $this->denyEquity();
- return $service->finance($this->currentAgent(), $this->validateList($request));
- });
- }
- public function bets(Request $request, AgentMemberService $service)
- {
- return $this->execute(function () use ($request, $service) {
- $this->denyEquity();
- $data = $request->validate([
- 'page' => ['nullable', 'integer', 'min:1'], 'limit' => ['nullable', 'integer', 'min:1', 'max:100'],
- 'source' => ['nullable', 'in:pc28,sport,jisu,lhc,third'], 'member_id' => ['nullable', 'string', 'max:64'],
- 'username' => ['nullable', 'string', 'max:128'], 'status' => ['nullable', 'integer'],
- 'start_date' => ['nullable', 'date_format:Y-m-d'], 'end_date' => ['nullable', 'date_format:Y-m-d', 'after_or_equal:start_date'],
- ]);
- return $service->bets($this->currentAgent(), $data);
- });
- }
- private function validateList(Request $request): array
- {
- return $request->validate([
- 'page' => ['nullable', 'integer', 'min:1'], 'limit' => ['nullable', 'integer', 'min:1', 'max:100'],
- 'keyword' => ['nullable', 'string', 'max:128'], 'agent_id' => ['nullable', 'integer'],
- 'status' => ['nullable', 'integer'], 'start_date' => ['nullable', 'date_format:Y-m-d'],
- 'end_date' => ['nullable', 'date_format:Y-m-d', 'after_or_equal:start_date'],
- ]);
- }
- }
|