123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- namespace App\Modules\Admin\Services;
- use App\Models\User;
- class UserService
- {
- public function paginate($data)
- {
- $p = User::query()->orderByDesc("id")->paginate($data['page_size']);
- return [
- "total" => $p->total(),
- "page_total" => $p->lastPage(),
- "list" => array_map(function (User $u) {
- return [
- "id" => $u->id,
- "phone" => $u->phone,
- "email" => $u->email,
- "status" => $u->status,
- "created_at" => $u->created_at->format("Y-m-d"),
- "company" => "todo company",
- ];
- }, $p->items()),
- ];
- }
- public function changeStatus($data)
- {
- $u = User::findOrFail($data['id']);
- $u->status = $u->status == User::STATUS_OK ? User::STATUS_STOP : User::STATUS_OK;
- $u->save();
- return true;
- }
- }
|