feat: add article and production modules

This commit is contained in:
2026-08-31 13:16:46 +08:00
parent ac3da246b2
commit 5c586a1a95
334 changed files with 34419 additions and 1 deletions
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace plugin\article\app\model;
use app\model\system\Admin;
use core\base\BaseModel as CoreBaseModel;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
abstract class BaseModel extends CoreBaseModel
{
use SoftDeletes;
protected $appends = ['created_date', 'updated_date', 'created_name', 'updated_name'];
public function createds(): HasOne
{
return $this->hasOne(Admin::class, 'id', 'created_by')->select('id', 'real_name as created_name');
}
public function updateds(): HasOne
{
return $this->hasOne(Admin::class, 'id', 'updated_by')->select('id', 'real_name as updated_name');
}
public function getCreatedNameAttribute(): string
{
return $this->createds?->created_name ?? '';
}
public function getUpdatedNameAttribute(): string
{
return $this->updateds?->updated_name ?? '';
}
}
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace plugin\article\app\model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Category extends BaseModel
{
protected $table = 'article_category';
protected $fillable = [
'id',
'name',
'slug',
'parent_id',
'sort',
'enabled',
'description',
'created_by',
'updated_by',
'created_at',
'updated_at',
'deleted_at',
];
protected $casts = [
'parent_id' => 'integer',
'sort' => 'integer',
'enabled' => 'integer',
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
public function contents(): HasMany
{
return $this->hasMany(Content::class, 'category_id', 'id');
}
}
@@ -0,0 +1,93 @@
<?php
declare(strict_types=1);
namespace plugin\article\app\model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Content extends BaseModel
{
protected $table = 'article_content';
protected $fillable = [
'id',
'title',
'content_type',
'slug',
'category_id',
'channel',
'visibility',
'author',
'source',
'cover',
'seo_keywords',
'seo_title',
'seo_description',
'summary',
'content',
'status',
'is_top',
'is_recommend',
'allow_comment',
'sort',
'view_count',
'like_count',
'comment_count',
'favorite_count',
'published_at',
'offline_at',
'created_by',
'updated_by',
'created_at',
'updated_at',
'deleted_at',
];
protected $casts = [
'category_id' => 'integer',
'visibility' => 'integer',
'status' => 'integer',
'is_top' => 'integer',
'is_recommend' => 'integer',
'allow_comment' => 'integer',
'sort' => 'integer',
'view_count' => 'integer',
'like_count' => 'integer',
'comment_count' => 'integer',
'favorite_count' => 'integer',
'published_at' => 'integer',
'offline_at' => 'integer',
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
protected $appends = ['tag_names', 'tag_ids', 'category_name', 'created_date', 'updated_date', 'created_name', 'updated_name'];
public function category(): BelongsTo
{
return $this->belongsTo(Category::class, 'category_id', 'id');
}
public function tags(): BelongsToMany
{
return $this->belongsToMany(Tag::class, 'article_content_tag', 'content_id', 'tag_id');
}
public function getCategoryNameAttribute(): string
{
return $this->category?->name ?? '';
}
public function getTagNamesAttribute(): string
{
return $this->tags->pluck('name')->implode('、');
}
public function getTagIdsAttribute(): array
{
return $this->tags->pluck('id')->map(static fn($id) => is_numeric($id) ? (int)$id : $id)->values()->all();
}
}
+41
View File
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace plugin\article\app\model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Tag extends BaseModel
{
protected $table = 'article_tag';
protected $fillable = [
'id',
'name',
'slug',
'sort',
'heat',
'enabled',
'description',
'created_by',
'updated_by',
'created_at',
'updated_at',
'deleted_at',
];
protected $casts = [
'sort' => 'integer',
'heat' => 'integer',
'enabled' => 'integer',
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
public function contents(): BelongsToMany
{
return $this->belongsToMany(Content::class, 'article_content_tag', 'tag_id', 'content_id');
}
}