Files
hospital-applets-api/app/Model/OrderPrescriptionProduct.php
T
haomingming 012984f636
Build Docker / build (push) Has been cancelled
监管平台更新接口 V2
2026-05-12 14:49:47 +08:00

144 lines
4.0 KiB
PHP

<?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 $use_status 使用状态(1:已使用 0:未使用)
* @property int $prescription_product_num 商品数量
* @property string $product_name 商品名称
* @property string $product_spec 商品规格
* @property string $license_number 批准文号
* @property string $manufacturer 生产厂家
* @property string $single_unit 单次剂量(例:1次1包)
* @property string $single_use 单次用法(例:口服)
* @property string $packaging_unit 基本包装单位(例:盒/瓶)
* @property string $frequency_use 使用频率(例:1天3次)
* @property int $available_days 可用天数(3)
* @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', 'use_status', 'prescription_product_num', 'product_name', 'product_price', 'product_spec', 'license_number', 'manufacturer', 'single_unit', 'single_use', 'packaging_unit', 'frequency_use', 'available_days', '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 $data
* @return \Hyperf\Database\Model\Model|OrderPrescriptionProduct
*/
public static function addOrderPrescriptionProduct(array $data): \Hyperf\Database\Model\Model|OrderPrescriptionProduct
{
return self::create($data);
}
public static function edit(array $params = [], array $data = []): int
{
return self::where($params)->update($data);
}
/**
* 删除
* @param array $params
* @return int|mixed
*/
public static function deleteOrderPrescriptionProduct(array $params): mixed
{
return self::where($params)->delete();
}
/**
* 获取数据
* 限制数量
* @param array $params
* @param array $fields
* @return Collection|array
*/
public static function getLimit(array $params = [], array $fields = ['*']): Collection|array
{
return self::where($params)
->limit(10)
->get($fields);
}
/**
* 获取数据-关联商品表
* 限制数量
* @param array $params
* @param array $fields
* @return Collection|array
*/
public static function getWithProductLimit(array $params = [], array $fields = ['*']): Collection|array
{
return self::with([
"Product"
])
->where($params)
->limit(10)
->get($fields);
}
}