Browse Source

feat(article): 新增文章分类功能

- 创建文章分类模型及数据表
- 实现分类关联创建任务逻辑
- 添加分类名称存储字段
- 自动同步分类至创建任务参数
- 完善分类ID回填机制
master
zhangf@suq.cn 1 week ago
parent
commit
b215e57c06
  1. 15
      app/dao/ArticleCategoryDao.php
  2. 33
      app/model/ArticleCategory.php
  3. 8
      app/service/CreationTaskService.php

15
app/dao/ArticleCategoryDao.php

@ -0,0 +1,15 @@
<?php
namespace app\dao;
use app\model\ArticleCategory;
use plugin\piadmin\app\base\BaseDao;
class ArticleCategoryDao extends BaseDao
{
protected function setModel(): string
{
return ArticleCategory::class;
}
}

33
app/model/ArticleCategory.php

@ -0,0 +1,33 @@
<?php
namespace app\model;
use plugin\piadmin\app\base\BaseModel;
/**
* AI创作指令模型
*/
class ArticleCategory extends BaseModel
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'geo_article_category';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
}

8
app/service/CreationTaskService.php

@ -2,6 +2,7 @@
namespace app\service;
use app\dao\ArticleCategoryDao;
use app\dao\CreationTaskDao;
use app\dao\DistillationWordDao;
use plugin\piadmin\app\base\BaseService;
@ -13,11 +14,13 @@ class CreationTaskService extends BaseService
protected $dao;
protected $distillationDao;
protected $articleCategoryDao;
public function __construct(CreationTaskDao $dao)
{
$this->dao = $dao;
$this->distillationDao = app()->make(DistillationWordDao::class);
$this->articleCategoryDao = app()->make(ArticleCategoryDao::class);
}
/**
@ -30,7 +33,10 @@ class CreationTaskService extends BaseService
Db::startTrans();
try {
//同步创建文章分类,若存在则不创建
$category = $this->articleCategoryDao->save([
'name' => $params['name']
]);
$params['article_category_id'] = $category['id'];
if (isNotBlank($params['knowledge_ids'])) {
$params['knowledge_ids'] = implode(',', $params['knowledge_ids']);
}

Loading…
Cancel
Save