12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace App\Http\Resources;
- use App\Models\CardRiding;
- use App\Models\Coupon;
- use App\Models\InviteNewUsersGiveGiftLog;
- use Illuminate\Http\Resources\Json\JsonResource;
- class InviteNewUserGiveGiftLogResource extends JsonResource
- {
- /**
- * Transform the resource into an array.
- *
- * @param \Illuminate\Http\Request $request
- * @return array
- */
- public function toArray($request)
- {
- $model = $this->resource;
- switch ($model->gift_type){
- case InviteNewUsersGiveGiftLog::GIFT_TYPE_CARD:
- $card = CardRiding::find($model->gift_id);
- $gift_name = $card->name;
- break;
- case InviteNewUsersGiveGiftLog::GIFT_TYPE_COUPON:
- $coupon = Coupon::find($model->gift_id);
- $gift_name = $coupon->title;
- break;
- case InviteNewUsersGiveGiftLog::GIFT_TYPE_BALANCE:
- $gift_name = '赠送余额';
- break;
- default:
- $gift_name = '';
- }
- $data = [
- 'active_name' => $model->inviteNewUsersConfig->name,
- 'user_name' => $model->users->nickname . '('.$model->users->truename.')' ,
- 'user_mobile' => $model->users->mobile,
- 'gift_name' => $gift_name,
- 'gift_type_name' => InviteNewUsersGiveGiftLog::$giftTypeMaps[$model->gift_type]
- ];
- return array_merge(parent::toArray($request),$data);
- }
- }
|