UserService.php 960 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Modules\Admin\Services;
  3. use App\Models\User;
  4. class UserService
  5. {
  6. public function paginate($data)
  7. {
  8. $p = User::query()->orderByDesc("id")->paginate($data['page_size']);
  9. return [
  10. "total" => $p->total(),
  11. "page_total" => $p->lastPage(),
  12. "list" => array_map(function (User $u) {
  13. return [
  14. "id" => $u->id,
  15. "phone" => $u->phone,
  16. "email" => $u->email,
  17. "status" => $u->status,
  18. "created_at" => $u->created_at->format("Y-m-d"),
  19. "company" => "todo company",
  20. ];
  21. }, $p->items()),
  22. ];
  23. }
  24. public function changeStatus($data)
  25. {
  26. $u = User::findOrFail($data['id']);
  27. $u->status = $u->status == User::STATUS_OK ? User::STATUS_STOP : User::STATUS_OK;
  28. $u->save();
  29. return true;
  30. }
  31. }