AdminUserResource.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Http\Resources;
  3. use App\Models\AdminUser;
  4. use App\Models\AdminUserArea;
  5. use App\Traits\ResourceRolePermissionHelpers;
  6. use Illuminate\Support\Facades\Storage;
  7. class AdminUserResource extends JsonResource
  8. {
  9. use ResourceRolePermissionHelpers;
  10. /**
  11. * Transform the resource into an array.
  12. *
  13. * @param \Illuminate\Http\Request $request
  14. *
  15. * @return array
  16. */
  17. public function toArray($request)
  18. {
  19. /** @var AdminUser $model */
  20. $model = $this->resource;
  21. $test = AdminUserArea::query()->where('area_id', 99999)->where('admin_id', $model->id)->first();
  22. return [
  23. 'id' => $model->id,
  24. 'account' => $model->account,
  25. 'name' => $model->name,
  26. 'phone' => $model->phone,
  27. 'job_number' => $model->job_number,
  28. 'pid' => $model->pid,
  29. 'area_remark' => $model->area_remark,
  30. 'status' => (bool)$model->status,
  31. 'is_login_app' => (bool)$model->is_login_app,
  32. 'avatar' => $model->avatar,
  33. 'roles' => $this->getRoles(),
  34. 'areas' => $this->getAreas(),
  35. 'quanbu' => empty($test) ? false : true,
  36. 'permissions' => $this->getPermissions(),
  37. 'created_at' => (string)$model->created_at,
  38. 'updated_at' => (string)$model->updated_at,
  39. 'merchant_id' => $model->merchant_id,
  40. ];
  41. }
  42. }