PurchaseHistoryCollection.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Http\Resources\V2;
  3. use Carbon\Carbon;
  4. use Illuminate\Http\Resources\Json\ResourceCollection;
  5. class PurchaseHistoryCollection extends ResourceCollection
  6. {
  7. public function toArray($request)
  8. {
  9. return [
  10. 'data' => $this->collection->map(function ($data) {
  11. $pickup_point = null;
  12. if ($data->shipping_type == 'pickup_point' && $data->pickup_point_id) {
  13. $pickup_point = $data->pickup_point;
  14. }
  15. return [
  16. 'id' => $data->id,
  17. 'code' => $data->code,
  18. 'user_id' => (int) $data->user_id,
  19. 'shipping_address' => json_decode($data->shipping_address),
  20. 'payment_type' => ucwords(str_replace('_', ' ', $data->payment_type)),
  21. 'pickup_point' => $pickup_point,
  22. 'shipping_type' => $data->shipping_type,
  23. 'shipping_type_string' => $data->shipping_type != null ? ucwords(str_replace('_', ' ', $data->shipping_type)) : "",
  24. 'payment_status' => $data->payment_status,
  25. 'payment_status_string' => ucwords(str_replace('_', ' ', $data->payment_status)),
  26. 'delivery_status' => $data->delivery_status,
  27. 'delivery_status_string' => $data->delivery_status == 'pending'? "Order Placed" : ucwords(str_replace('_', ' ', $data->delivery_status)),
  28. 'grand_total' => format_price($data->grand_total),
  29. 'coupon_discount' => format_price($data->coupon_discount),
  30. 'shipping_cost' => format_price($data->orderDetails->sum('shipping_cost')),
  31. 'subtotal' => format_price($data->orderDetails->sum('price')),
  32. 'tax' => format_price($data->orderDetails->sum('tax')),
  33. 'date' => Carbon::createFromTimestamp($data->date)->format('d-m-Y'),
  34. 'cancel_request' => $data->cancel_request == 1,
  35. 'manually_payable' => $data->manual_payment && $data->manual_payment_data == null,
  36. 'links' => [
  37. 'details' => ''
  38. ]
  39. ];
  40. })
  41. ];
  42. }
  43. public function with($request)
  44. {
  45. return [
  46. 'success' => true,
  47. 'status' => 200
  48. ];
  49. }
  50. }