RefundBalanceOrderResource.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace App\Http\Resources;
  3. use App\Models\RefundBalanceOrder;
  4. use Carbon\Carbon;
  5. use Illuminate\Http\Resources\Json\JsonResource;
  6. class RefundBalanceOrderResource extends JsonResource
  7. {
  8. /**
  9. * Transform the resource into an array.
  10. *
  11. * @param \Illuminate\Http\Request $request
  12. * @return array
  13. */
  14. public function toArray($request)
  15. {
  16. $model = $this->resource;
  17. $try_again = false;
  18. if($model->err_code == 'SYSTEMERROR' && $model->pay_status == RefundBalanceOrder::PAY_STATUS_NO){
  19. $try_again = true;
  20. }
  21. $data = [
  22. 'id' => $model->id,
  23. 'nickname' => $model->users->nickname ?? '',
  24. 'mobile' => $model->users->mobile ?? '',
  25. 'created_at' => Carbon::parse($model->created_at)->format('Y-m-d H:i:s'),
  26. 'area_id' => $model->area_id,
  27. 'area_name' => $model->area->name ?? '',
  28. 'admin_user_name' => $model->adminUser->name,
  29. 'pay_money' => $model->pay_money,
  30. 'pay_status' => $model->pay_status,
  31. 'no' => $model->no,
  32. 'try_again' => $try_again
  33. ];
  34. return $data;
  35. }
  36. }