90 lines
3.1 KiB
PHP
90 lines
3.1 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace App\Model;
|
||
|
||
|
||
|
||
use Hyperf\Database\Model\Relations\HasOne;
|
||
use Hyperf\Snowflake\Concern\Snowflake;
|
||
|
||
/**
|
||
* @property int $product_id 主键id
|
||
* @property int $product_platform_id 处方平台商品id
|
||
* @property string $product_name 商品名称
|
||
* @property string $common_name 商品通用名
|
||
* @property string $product_price 商品价格
|
||
* @property string $mnemonic_code 商品助记码(首字母简拼)
|
||
* @property int $product_type 药品类型(0:未知 1:中成药 2:西药)
|
||
* @property string $product_platform_code 处方平台商品编码
|
||
* @property string $product_pharmacy_code 第三方药店商品编码
|
||
* @property string $product_cover_img 商品封面图
|
||
* @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 string $available_days 可用天数(3)
|
||
* @property string $product_remarks 商品备注
|
||
* @property \Carbon\Carbon $created_at 创建时间
|
||
* @property \Carbon\Carbon $updated_at 修改时间
|
||
*/
|
||
class Product extends Model
|
||
{
|
||
use Snowflake;
|
||
|
||
/**
|
||
* The table associated with the model.
|
||
*/
|
||
protected ?string $table = 'product';
|
||
|
||
/**
|
||
* The attributes that are mass assignable.
|
||
*/
|
||
protected array $fillable = ['product_id', 'product_platform_id', 'product_name', 'common_name', 'product_price', 'mnemonic_code', 'product_type', 'product_platform_code', 'product_pharmacy_code', 'product_cover_img', 'product_spec', 'license_number', 'manufacturer', 'single_unit', 'single_use', 'packaging_unit', 'frequency_use', 'available_days', 'product_remarks', 'created_at', 'updated_at'];
|
||
|
||
/**
|
||
* The attributes that should be cast to native types.
|
||
*/
|
||
protected array $casts = ['product_id' => 'integer', 'product_platform_id' => 'integer', 'product_type' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];
|
||
|
||
protected string $primaryKey = "product_id";
|
||
|
||
/**
|
||
* 关联库存表
|
||
*/
|
||
public function ProductPlatformAmount(): HasOne
|
||
{
|
||
return $this->hasOne(ProductPlatformAmount::class, 'product_platform_id','product_platform_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 object|null
|
||
*/
|
||
public static function getWithAmountOne(array $params, array $fields = ['*']): object|null
|
||
{
|
||
return self::with([
|
||
'ProductPlatformAmount'
|
||
])
|
||
->where($params)
|
||
->first($fields);
|
||
}
|
||
}
|