修改处方药品数据获取方式
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user