InviteNewUserGiveGiftLogResource.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Http\Resources;
  3. use App\Models\CardRiding;
  4. use App\Models\Coupon;
  5. use App\Models\InviteNewUsersGiveGiftLog;
  6. use Illuminate\Http\Resources\Json\JsonResource;
  7. class InviteNewUserGiveGiftLogResource extends JsonResource
  8. {
  9. /**
  10. * Transform the resource into an array.
  11. *
  12. * @param \Illuminate\Http\Request $request
  13. * @return array
  14. */
  15. public function toArray($request)
  16. {
  17. $model = $this->resource;
  18. switch ($model->gift_type){
  19. case InviteNewUsersGiveGiftLog::GIFT_TYPE_CARD:
  20. $card = CardRiding::find($model->gift_id);
  21. $gift_name = $card->name;
  22. break;
  23. case InviteNewUsersGiveGiftLog::GIFT_TYPE_COUPON:
  24. $coupon = Coupon::find($model->gift_id);
  25. $gift_name = $coupon->title;
  26. break;
  27. case InviteNewUsersGiveGiftLog::GIFT_TYPE_BALANCE:
  28. $gift_name = '赠送余额';
  29. break;
  30. default:
  31. $gift_name = '';
  32. }
  33. $data = [
  34. 'active_name' => $model->inviteNewUsersConfig->name,
  35. 'user_name' => $model->users->nickname . '('.$model->users->truename.')' ,
  36. 'user_mobile' => $model->users->mobile,
  37. 'gift_name' => $gift_name,
  38. 'gift_type_name' => InviteNewUsersGiveGiftLog::$giftTypeMaps[$model->gift_type]
  39. ];
  40. return array_merge(parent::toArray($request),$data);
  41. }
  42. }