UserResource.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Http\Resources;
  3. use App\Models\User;
  4. use Illuminate\Http\Resources\Json\JsonResource;
  5. class UserResource extends JsonResource
  6. {
  7. /**
  8. * Transform the resource into an array.
  9. *
  10. * @param \Illuminate\Http\Request $request
  11. * @return array
  12. */
  13. public function toArray($request)
  14. {
  15. $model = $this->resource;
  16. $deposit_type = '';
  17. if ($model->is_deposit == User::DEPOSIT_OK) {
  18. if ($model->is_student) {
  19. $deposit_type = '(' . User::$depositTypeMaps[($model->deposit_type + 1)] . ')';
  20. } else {
  21. $deposit_type = '(' . User::$depositTypeMaps[$model->deposit_type] . ')';
  22. }
  23. }
  24. $data = [
  25. 'deposit_status' => User::$depositMaps[$model->is_deposit ?? User::DEPOSIT_NO] . $deposit_type,
  26. 'card_status' => User::$cardMaps[$model->is_card_certified ?? User::CARD_NO],
  27. 'register_source' => User::$registerSourceMaps[$model->register_source ?? User::REGISTER_SOURCE_WEAPP],
  28. 'account_status' => User::$statusMaps[$model->status ?? User::STATUS_PAUSE],
  29. 'areaname' => $model->areas->name ?? '',
  30. 'phone_detail' => $model->userPhone->detail ?? '',
  31. ];
  32. return array_merge(parent::toArray($request), $data);
  33. }
  34. }