100 lines
3.9 KiB
PHP
100 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Models\ProductOrderItem;
|
|
use App\Models\YiiModels\Prescription;
|
|
use App\Models\YiiModels\ProductOrder;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
/**
|
|
* @mixin ProductOrder
|
|
*/
|
|
class ProductOrderDetailResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'store_id' => $this->store_id,
|
|
'su_id' => $this->su_id,
|
|
'user_id' => $this->user_id,
|
|
'up_id' => $this->up_id,
|
|
'order_no' => $this->order_no,
|
|
'sync_order_no' => $this->sync_order_no,
|
|
'p_id' => $this->p_id,
|
|
'order_type' => $this->order_type,
|
|
'type' => $this->type,
|
|
'type_string' => $this->type_string,
|
|
'is_pay' => $this->is_pay,
|
|
'items_price' => $this->items_price,
|
|
'total_pay_price' => $this->total_pay_price,
|
|
'pay_time' => $this->pay_time,
|
|
'address_id' => $this->address_id,
|
|
'address' => $this->address,
|
|
'cancel_status' => $this->cancel_status,
|
|
'cancel_status_string' => $this->cancel_status_string,
|
|
'cancel_time' => $this->cancel_time,
|
|
'cancel_remark' => $this->cancel_remark,
|
|
'refund_status' => $this->refund_status,
|
|
'refund_time' => $this->refund_time,
|
|
'received_time' => $this->received_time,
|
|
'auto_cancel_time' => $this->auto_cancel_time,
|
|
'status' => $this->status,
|
|
'pay_method' => $this->pay_method,
|
|
'trans_expenses' => $this->trans_expenses,
|
|
'free_ship' => $this->free_ship,
|
|
'remark' => $this->remark,
|
|
'express_name' => $this->express_name,
|
|
'express_mobile' => $this->express_mobile,
|
|
'express_region' => $this->express_region,
|
|
'express_address' => $this->express_address,
|
|
'express_no_id' => $this->express_no_id,
|
|
'created_at_format' => $this->created_at_format,
|
|
'items' => $this->items->map(function (ProductOrderItem $item) {
|
|
return [
|
|
'id' => $item->id,
|
|
'product_order_id' => $item->product_order_id,
|
|
'drug_id' => $item->drug_id,
|
|
'drug_image' => $item->drug_image,
|
|
'number' => $item->number,
|
|
'price' => $item->price,
|
|
'drug_name' => $item->drug_name,
|
|
'small_info' => $item->small_info,
|
|
];
|
|
}),
|
|
'prescription' => $this->getPrescription(),
|
|
];
|
|
}
|
|
|
|
private function getPrescription()
|
|
{
|
|
if (!$this->prescription) {
|
|
return [];
|
|
}
|
|
if (in_array($this->prescription->prescription_type, [Prescription::CHINESE_MEDICINES_DECOCTION_PIECE, Prescription::DISPENSING_GRANULES])) {
|
|
return [
|
|
'id' => $this->prescription->id,
|
|
'dosage_price' => $this->items->sum('price'),
|
|
'dosage' => $this->prescription->content['repice'][0]['dosage'],
|
|
'prescription_type' => $this->prescription->prescription_type,
|
|
'prescription_type_string' => $this->prescription->prescription_type_string,
|
|
];
|
|
}
|
|
if (in_array($this->prescription->prescription_type, (array)Prescription::WESTERN_ZHONG_CHENG_MEDICINE)) {
|
|
return [
|
|
'id' => $this->prescription->id,
|
|
'dosage_price' => $this->items->sum('price'),
|
|
'prescription_type' => $this->prescription->prescription_type,
|
|
'prescription_type_string' => $this->prescription->prescription_type_string,
|
|
];
|
|
}
|
|
}
|
|
}
|