修改处方药品数据获取方式

This commit is contained in:
wucongxing 2023-03-01 14:21:13 +08:00
parent 80b63cd73d
commit ad7e6551f1
3 changed files with 109 additions and 14 deletions

View File

@ -0,0 +1,90 @@
<?php
declare(strict_types=1);
namespace App\Model;
use Hyperf\Database\Model\Collection;
use Hyperf\Database\Model\Relations\HasOne;
use Hyperf\Snowflake\Concern\Snowflake;
/**
* @property int $prescription_product_id 主键id
* @property int $order_prescription_id 订单-处方id
* @property int $product_id 商品id
* @property int $prescription_product_num 商品数量
* @property \Carbon\Carbon $created_at 创建时间
* @property \Carbon\Carbon $updated_at 修改时间
*/
class OrderPrescriptionProduct extends Model
{
use Snowflake;
/**
* The table associated with the model.
*/
protected ?string $table = 'order_prescription_product';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = ['prescription_product_id', 'order_prescription_id', 'product_id', 'prescription_product_num', 'created_at', 'updated_at'];
protected string $primaryKey = "prescription_product_id";
/**
* 关联商品表
*/
public function Product(): HasOne
{
return $this->hasOne(Product::class, 'product_id', 'product_id');
}
/**
* 获取信息-单条
* @param array $params
* @param array $fields
* @return object|null
*/
public static function getOne(array $params, array $fields = ['*']): object|null
{
return self::where($params)->first($fields);
}
/**
* 获取数据-
* @param array $params
* @param array $fields
* @return Collection|array
*/
public static function getList(array $params = [], array $fields = ['*']): Collection|array
{
return self::where($params)->get($fields);
}
/**
* 获取是否存在
* @param array $params
* @return bool
*/
public static function getExists(array $params): bool
{
return self::where($params)->exists();
}
/**
* 获取数据-关联商品表
* @param array $params
* @param array $fields
* @return Collection|array
*/
public static function getWithProductList(array $params = [], array $fields = ['*']): Collection|array
{
return self::with([
"Product"
])
->where($params)
->get($fields);
}
}

View File

@ -3,6 +3,7 @@
namespace App\Services;
use App\Model\OrderPrescription;
use App\Model\OrderPrescriptionProduct;
use App\Model\OrderProductItem;
use Hyperf\Contract\LengthAwarePaginatorInterface;
@ -59,7 +60,7 @@ class OrderPrescriptionService extends BaseService
}
/**
* 获取处方订单中开方商品数据
* 获取处方中开方药品
* @param string|int $order_inquiry_id
* @param string|int $order_prescription_id
* @return array
@ -69,23 +70,25 @@ class OrderPrescriptionService extends BaseService
$params = array();
$params['order_inquiry_id'] = $order_inquiry_id;
$params['order_prescription_id'] = $order_prescription_id;
$order_product_items = OrderProductItem::getWithProductList($params);
if(empty($order_product_items)){
$order_prescription_products = OrderPrescriptionProduct::getWithProductList($params);
if(empty($order_prescription_products)){
return [];
}
$result = [];
foreach ($order_product_items as $order_product_item){
foreach ($order_prescription_products as $order_prescription_product){
$data = array();
$data['product_item_id'] = $order_product_item['product_item_id'];
$data['product_id'] = $order_product_item['product_id'];
$data['amount'] = $order_product_item['amount'];
$data['product_cover_img'] = addAliyunOssWebsite($order_product_item['product_cover_img']);
$data['single_unit'] = $order_product_item['Product']['single_unit'];
$data['single_use'] = $order_product_item['Product']['single_use'];
$data['packaging_unit'] = $order_product_item['Product']['packaging_unit'];
$data['frequency_use'] = $order_product_item['Product']['frequency_use'];
$data['prescription_product_id'] = $order_prescription_product['prescription_product_id'];
$data['product_id'] = $order_prescription_product['product_id'];
$data['prescription_product_num'] = $order_prescription_product['prescription_product_num'];
$data['product_name'] = $order_prescription_product['Product']['product_name'];
$data['product_cover_img'] = addAliyunOssWebsite($order_prescription_product['Product']['product_cover_img']);
$data['product_spec'] = $order_prescription_product['Product']['product_spec'];
$data['single_unit'] = $order_prescription_product['Product']['single_unit'];
$data['single_use'] = $order_prescription_product['Product']['single_use'];
$data['packaging_unit'] = $order_prescription_product['Product']['packaging_unit'];
$data['frequency_use'] = $order_prescription_product['Product']['frequency_use'];
$result[] = $data;
}

View File

@ -848,12 +848,14 @@ class UserDoctorService extends BaseService
// 订单-商品订单列表
$OrderPrescriptionService = new OrderPrescriptionService();
$order_product_items = $OrderPrescriptionService->getproductList($order_inquiry_id,$order_prescription_id);
$order_prescription_product = $OrderPrescriptionService->getproductList($order_inquiry_id,$order_prescription_id);
// 获取处方关联疾病表
}
$result = array();
$result['inquiry_case_product'] = $inquiry_case_product;// 用药意向
$result['order_product_items'] = $order_product_items ?? [];// 开方药品
$result['order_prescription_product'] = $order_prescription_product ?? [];// 开方药品
$result['case'] = $order_inquiry_case;// 病例数据
$result['prescription']['doctor_advice'] = $order_prescription['doctor_advice'] ?? "";// 医嘱