params = $params; } public function collection() { $data = \App\Models\User\User::query()->with(["group", "company"])->when($this->params['status'], function (Builder $query) { return $query->where("status", $this->params['status']); })->when($this->params['userinfo'], function (Builder $query) { return $query->where(function (Builder $query) { return $query->where("phone", $this->params['userinfo'])->orWhere("email", $this->params['userinfo'])->orWhere("id", $this->params['userinfo']); }); })->orderByDesc("id")->get()->map(function (User $u) { return [ "id" => Utils::idNo4($u->id), "phone" => $u->phone, "email" => $u->email, "company" => optional($u->company)->name, "status" => $u->status == User::STATUS_OK ? "正常" : "禁用", "group_name" => optional($u->group)->name ?? "", "created_at" => $u->created_at->format("Y-m-d"), ]; }); $data->prepend(["用户ID", "用户手机号", "用户邮箱", "企业用户", "用户状态", "当前身份", "注册时间"]); return $data; } }