89 lines
2.3 KiB
PHP
89 lines
2.3 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 $case_product_id 主键id
|
|
* @property int $inquiry_case_id 病例id
|
|
* @property int $product_id 商品id
|
|
* @property int $case_product_num 药品数量
|
|
* @property \Carbon\Carbon $created_at 创建时间
|
|
* @property \Carbon\Carbon $updated_at 修改时间
|
|
* @property-read Product $Product
|
|
*/
|
|
class InquiryCaseProduct extends Model
|
|
{
|
|
use Snowflake;
|
|
|
|
/**
|
|
* The table associated with the model.
|
|
*/
|
|
protected ?string $table = 'inquiry_case_product';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*/
|
|
protected array $fillable = ['case_product_id', 'inquiry_case_id', 'product_id', 'case_product_num', 'created_at', 'updated_at'];
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*/
|
|
protected array $casts = ['case_product_id' => 'integer', 'inquiry_case_id' => 'integer', 'product_id' => 'integer', 'case_product_num' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];
|
|
|
|
protected string $primaryKey = "case_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
|
|
* @param array $fields
|
|
* @return Collection|array
|
|
*/
|
|
public static function getWithProductList(array $params = [], array $fields = ['*']): Collection|array
|
|
{
|
|
return self::with([
|
|
"Product"
|
|
])
|
|
->where($params)
|
|
->get($fields);
|
|
}
|
|
|
|
}
|