<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Response\ResponseJson;
use App\Models\ESTP\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ESTPUserController extends Controller
{
    use ResponseJson;



    /**
     * 获取创业家列表
     *
     * @param Request $request
     * @return JsonResponse
     */
    public function index(Request $request)
    {
        $keyword = $request->input('keyword');
        $role = $request->input('role');
        $perPage = $request->input('page_size', 15);

        // 获取创业家列表
        $query = User::query();

        // 根据角色筛选
        if ($role) {
            $query->with($role)->where('role', $role);
        }

        // 模糊搜索姓名/手机号/企业名称
        if ($keyword) {
            $query->where(function ($query) use ($keyword) {
                $query->where('mobile', $keyword)
                    ->orWhere('name', 'LIKE', '%' . $keyword . '%')
                    ->orWhere('company_name', 'LIKE', '%' . $keyword . '%');
            });

        }

        $list = $query->orderByDesc('id')->paginate($perPage);



        return $this->success('ok',$list);
    }



}
