Files
exchange-2.0/app/Http/Resources/TransactionDetailResource.php
2024-01-25 16:52:06 +08:00

37 lines
1008 B
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class TransactionDetailResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
$item_from_1688 = str_contains($this->product_code, 'offerId');
$offer_id_1688 = null;
if ($item_from_1688) {
$offerId = explode(',', $this->product_code)[0];
$offer_id_1688 = substr($offerId, strpos($offerId, ':') + 1);
}
return [
'id' => $this->id,
'stockCode' => $this->product_code,
'description' => $this->product_name,
'quantity' => $this->quantity,
'unit_price' => (double) $this->price,
'total' => (double) $this->amount,
'item_from_1688' => $item_from_1688,
'offer_id_1688' => $offer_id_1688
];
}
}