68 lines
1.6 KiB
PHP
68 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Model;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
use Hyperf\Database\Model\Collection;
|
|
use Hyperf\Database\Model\Relations\HasOne;
|
|
use Hyperf\Snowflake\Concern\Snowflake;
|
|
|
|
/**
|
|
* @property int $class_id 主键id
|
|
* @property int $article_id 文章-科普id
|
|
* @property int $basic_class_id 基础数据-科普-分类id
|
|
* @property Carbon $created_at 创建时间
|
|
* @property Carbon $updated_at 修改时间
|
|
*/
|
|
class ArticleScienceClass extends Model
|
|
{
|
|
use Snowflake;
|
|
|
|
/**
|
|
* The table associated with the model.
|
|
*/
|
|
protected ?string $table = 'article_science_class';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*/
|
|
protected array $fillable = ['class_id', 'article_id', 'basic_class_id', 'created_at', 'updated_at'];
|
|
|
|
protected string $primaryKey = "class_id";
|
|
|
|
/**
|
|
* 关联基础分类
|
|
*/
|
|
public function BasicArticleClass(): HasOne
|
|
{
|
|
return $this->hasOne(BasicArticleClass::class, 'basic_class_id', 'basic_class_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);
|
|
}
|
|
|
|
}
|