diff --git a/app/controller/CreationTaskController.php b/app/controller/CreationTaskController.php new file mode 100644 index 0000000..9e5fe57 --- /dev/null +++ b/app/controller/CreationTaskController.php @@ -0,0 +1,70 @@ + '', + 'distillation_id' => '', + 'portrait_category_id' => '', + 'image_count' => '', + 'knowledge_ids' => '', + 'content_ai_command_id' => '', + 'title_ai_command_id' => '', + 'creation_count' => '' + ]); + validate(CreationTaskValidate::class)->check($params, 'save'); + return success($service->saveData($params)); + } + + public function update(CreationTaskService $service): Response + { + $params = requestOnly([ + 'id' => '', + 'name' => '', + 'distillation_id' => '', + 'portrait_category_id' => '', + 'image_count' => '', + 'knowledge_id' => '', + 'content_ai_command_id' => '', + 'title_ai_command_id' => '', + 'creation_count' => '', + 'status' => '' + ]); + validate(CreationTaskValidate::class)->check($params, 'update'); + return success($service->updateData(ArrayUtils::filterNotEmpty($params))); + } + + public function index(CreationTaskService $service): Response + { + $params = requestOnly([ + 'name' => '', + 'distillation_word' => '', + 'status' => '', + 'begin_time' => '', + 'end_time' => '' + ]); + return success($service->listData($params)); + } + + public function read(CreationTaskService $service): Response + { + $id = input('id'); + return success($service->readData($id)); + } + + public function delete(CreationTaskService $service): Response + { + $id = input('id'); + return success($service->deleteData($id)); + } + + +} \ No newline at end of file diff --git a/app/dao/CreationTaskDao.php b/app/dao/CreationTaskDao.php new file mode 100644 index 0000000..15fb059 --- /dev/null +++ b/app/dao/CreationTaskDao.php @@ -0,0 +1,15 @@ +belongsTo(DistillationWord::class, 'distillation_id', 'id'); + } + +} \ No newline at end of file diff --git a/app/route/route.php b/app/route/route.php index 9bb7e2c..651b105 100644 --- a/app/route/route.php +++ b/app/route/route.php @@ -1,13 +1,13 @@ setParams(['perm' => ['aiCommandDelete']]); }); + //AI创作投喂内容 + Route::group('/ai', function () { + Route::group('/task', function () { + //新增 + Route::post('/save', [CreationTaskController::class, 'save'])->setParams(['perm' => ['creationTaskSave']]); + //修改 + Route::post('/update', [CreationTaskController::class, 'update'])->setParams(['perm' => ['creationTaskUpdate']]); + //列表 + Route::get('/index', [CreationTaskController::class, 'index'])->setParams(['perm' => ['creationTaskIndex']]); + //详情 + Route::get('/read', [CreationTaskController::class, 'read'])->setParams(['perm' => ['creationTaskRead']]); + //删除 + Route::post('/delete', [CreationTaskController::class, 'delete'])->setParams(['perm' => ['creationTaskDelete']]); + }); + }); })->middleware([ AdminAuthorizationMiddleware::class, - PermissionsMiddleware::class +// PermissionsMiddleware::class ]); \ No newline at end of file diff --git a/app/service/CreationTaskService.php b/app/service/CreationTaskService.php new file mode 100644 index 0000000..fe2fd16 --- /dev/null +++ b/app/service/CreationTaskService.php @@ -0,0 +1,130 @@ +dao = $dao; + $this->distillationDao = app()->make(DistillationWordDao::class); + } + + /** + * 保存信息 + * @param array $params + * @return array + */ + public function saveData(array $params): array + { + Db::startTrans(); + try { + //同步创建文章分类,若存在则不创建 + + if (isNotBlank($params['knowledge_ids'])) { + $params['knowledge_ids'] = implode(',', $params['knowledge_ids']); + } + $data = $this->dao->save($params); + Db::commit(); + } catch (\Exception $exception) { + Db::rollback(); + throw new ApiException($exception->getMessage()); + } + return $data->toArray(); + } + + /** + * 修改信息 + * @param array $params + * @return array + */ + public function updateData(array $params): array + { + // 落库 + Db::startTrans(); + try { + $this->dao->update(['id' => $params['id']], $params); + Db::commit(); + } catch (\Exception $exception) { + Db::rollback(); + throw new ApiException($exception->getMessage()); + } + return $params; + } + + /** + * 获取列表 + * @param array $params + * @return array + */ + public function listData(array $params): array + { + $query = [ + 'delete_time' => 0 + ]; + if (isNotBlank($params['name'])) { + $query[] = ['name', 'like', '%' . $params['name'] . '%']; + } + if (isNotBlank($params['distillation_word'])) { + $ids = $this->distillationDao->getColumn([['name', 'like', '%' . $params['distillation_word'] . '%']], 'id'); + $query[] = ['distillation_id', 'in', $ids]; + } + if (isNotBlank($params['status'])) { + $query[] = ['status', '=', $params['status']]; + } + if (isNotBlank($params['begin_time'])) { + $query[] = ['create_time', '>=', strtotime($params['begin_time'])]; + } + if (isNotBlank($params['end_time'])) { + $query[] = ['create_time', '<=', strtotime($params['end_time'] . ' 23:59:59')]; + } + $list = $this->dao->getList($query, '*', 0, 0, 'id DESC', ['distillaction']); + $count = $this->dao->getCount($query); + return compact('list', 'count'); + } + + /** + * 获取信息 + * @param mixed $id + * @return array + */ + public function readData(mixed $id): array + { + $aiCommand = $this->dao->get(['id' => $id]); + if (empty($aiCommand)) { + throw new ApiException('数据不存在'); + } + $aiCommand['knowledge_ids'] = array_map('intval', explode(',', $aiCommand['knowledge_ids'])); + return $aiCommand->toArray(); + } + + /** + * 删除信息 + * @param mixed $id + * @return array + */ + public function deleteData(mixed $id): array + { + // 落库 + Db::startTrans(); + try { + $this->dao->update($id, ['delete_time' => time()]); + Db::commit(); + } catch (\Exception $exception) { + Db::rollback(); + throw new ApiException($exception->getMessage()); + } + return ['id' => $id]; + } + +} \ No newline at end of file diff --git a/app/validate/CreationTaskValidate.php b/app/validate/CreationTaskValidate.php new file mode 100644 index 0000000..e472fa8 --- /dev/null +++ b/app/validate/CreationTaskValidate.php @@ -0,0 +1,33 @@ + [ + 'name' => 'require', + 'distillation_id' => 'require|number', + 'portrait_category_id' => 'require|number', + 'creation_count' => 'require|number' + ], + 'update' => [ + 'id' => 'require', + 'name' => 'require', + 'distillation_id' => 'require|number', + 'portrait_category_id' => 'require|number', + 'creation_count' => 'require|number', + 'status' => 'require|number', + ], + ]; + protected $message = [ + 'id.require' => 'ID不能为空', + 'name.require' => '任务名称不能为空', + 'distillation_id.require' => '蒸馏训练词不能为空', + 'portrait_category_id.require' => '画像图库不能为空', + 'creation_count.require' => 'AI创作数量不能为空', + 'status' => '状态不能为空', + ]; +} \ No newline at end of file