123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace App\Http\Resources;
- use App\Models\User;
- use Illuminate\Http\Resources\Json\JsonResource;
- class UserResource extends JsonResource
- {
- /**
- * Transform the resource into an array.
- *
- * @param \Illuminate\Http\Request $request
- * @return array
- */
- public function toArray($request)
- {
- $model = $this->resource;
- $deposit_type = '';
- if ($model->is_deposit == User::DEPOSIT_OK) {
- if ($model->is_student) {
- $deposit_type = '(' . User::$depositTypeMaps[($model->deposit_type + 1)] . ')';
- } else {
- $deposit_type = '(' . User::$depositTypeMaps[$model->deposit_type] . ')';
- }
- }
- $data = [
- 'deposit_status' => User::$depositMaps[$model->is_deposit ?? User::DEPOSIT_NO] . $deposit_type,
- 'card_status' => User::$cardMaps[$model->is_card_certified ?? User::CARD_NO],
- 'register_source' => User::$registerSourceMaps[$model->register_source ?? User::REGISTER_SOURCE_WEAPP],
- 'account_status' => User::$statusMaps[$model->status ?? User::STATUS_PAUSE],
- 'areaname' => $model->areas->name ?? '',
- 'phone_detail' => $model->userPhone->detail ?? '',
- ];
- return array_merge(parent::toArray($request), $data);
- }
- }
|