<?php

namespace App\Services;

use App\Model\InquiryCaseProduct;

/**
 * 病例
 */
class CaseService extends BaseService
{
    /**
     * 获取病例商品列表
     * @param string|int $inquiry_case_id
     * @return array
     */
    public function getCaseProductlist(string|int $inquiry_case_id): array
    {
        if (empty($inquiry_case_id)){
            return [];
        }

        $params = array();
        $params['inquiry_case_id'] = $inquiry_case_id;
        $inquiry_case_products = InquiryCaseProduct::getWithProductList($params);
        if (empty($inquiry_case_products)){
            return [];
        }

        $result = [];
        foreach ($inquiry_case_products as $inquiry_case_product){
            if (!empty($inquiry_case_product['Product'])){
                $data = array();
                $data['product_id'] = $inquiry_case_product['product_id'];
                $data['case_product_num'] = $inquiry_case_product['case_product_num'];
                $data['product_name'] = $inquiry_case_product['Product']['product_name'];
                $data['product_price'] = $inquiry_case_product['Product']['product_price'];
                $data['product_type'] = $inquiry_case_product['Product']['product_type'];
                $data['product_cover_img'] = addAliyunOssWebsite($inquiry_case_product['Product']['product_cover_img']);
                $data['product_spec'] = $inquiry_case_product['Product']['product_spec'];
                $data['license_number'] = $inquiry_case_product['Product']['license_number'];
                $data['manufacturer'] = $inquiry_case_product['Product']['manufacturer'];
                $data['packaging_unit'] = $inquiry_case_product['Product']['packaging_unit'];

                $result[] = $data;
            }
        }

        return $result;
    }
}