123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- namespace App\Exports;
- use App\Base\Utils;
- use App\Models\User\User;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Support\Arr;
- use Maatwebsite\Excel\Concerns\FromCollection;
- class AdminUserExport implements FromCollection
- {
- public $params;
- /**
- * @param $params
- */
- public function __construct($params)
- {
- $this->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;
- }
- }
|