diff --git a/app/controller/AiCommandController.php b/app/controller/AiCommandController.php new file mode 100644 index 0000000..fb200a8 --- /dev/null +++ b/app/controller/AiCommandController.php @@ -0,0 +1,58 @@ + '', + 'type' => '', + 'content' => '' + ]); + validate(AiCommandValidate::class)->check($params, 'save'); + return success($service->saveData($params)); + } + + public function update(AiCommandService $service): Response + { + $params = requestOnly([ + 'id' => '', + 'name' => '', + 'type' => '', + 'content' => '' + ]); + validate(AiCommandValidate::class)->check($params, 'update'); + return success($service->updateData(ArrayUtils::filterNotEmpty($params))); + } + + public function index(AiCommandService $service): Response + { + $params = requestOnly([ + 'name' => '', + 'type' => '', + 'begin_time' => '', + 'end_time' => '' + ]); + return success($service->listData($params)); + } + + public function read(AiCommandService $service): Response + { + $id = input('id'); + return success($service->readData($id)); + } + + public function delete(AiCommandService $service): Response + { + $id = input('id'); + return success($service->deleteData($id)); + } + + +} \ No newline at end of file diff --git a/app/dao/AiCommandDao.php b/app/dao/AiCommandDao.php new file mode 100644 index 0000000..ff978d8 --- /dev/null +++ b/app/dao/AiCommandDao.php @@ -0,0 +1,15 @@ +setParams(['perm' => ['enterpriseLibraryDelete']]); }); + + //AI创作指令 + Route::group('/aiCommand', function () { + //新增 + Route::post('/save', [AiCommandController::class, 'save'])->setParams(['perm' => ['aiCommandSave']]); + //修改 + Route::post('/update', [AiCommandController::class, 'update'])->setParams(['perm' => ['aiCommandUpdate']]); + //列表 + Route::get('/index', [AiCommandController::class, 'index'])->setParams(['perm' => ['aiCommandIndex']]); + //详情 + Route::get('/read', [AiCommandController::class, 'read'])->setParams(['perm' => ['aiCommandRead']]); + //删除 + Route::post('/delete', [AiCommandController::class, 'delete'])->setParams(['perm' => ['aiCommandDelete']]); + }); + })->middleware([ AdminAuthorizationMiddleware::class, PermissionsMiddleware::class diff --git a/app/service/AiCommandService.php b/app/service/AiCommandService.php new file mode 100644 index 0000000..5fc682a --- /dev/null +++ b/app/service/AiCommandService.php @@ -0,0 +1,117 @@ +dao = $dao; + } + + /** + * 保存信息 + * @param array $params + * @return array + */ + public function saveData(array $params): array + { + Db::startTrans(); + try { + $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['type'])) { + $query[] = ['type', '=', $params['type']]; + } + 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, 'id,name,type,create_time'); + $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('数据不存在'); + } + 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/service/DistillationWordService.php b/app/service/DistillationWordService.php index 405ac68..dc5ae44 100644 --- a/app/service/DistillationWordService.php +++ b/app/service/DistillationWordService.php @@ -178,7 +178,7 @@ class DistillationWordService extends BaseService $query = [ 'delete_time' => 0 ]; - $list = $this->dao->getList($query); + $list = $this->dao->getList($query, '*', 0, 0, 'id DESC', [], ['questions']); return $list; } } \ No newline at end of file diff --git a/app/service/EnterprisePortraitCategoryService.php b/app/service/EnterprisePortraitCategoryService.php index b1208ca..2fd9dba 100644 --- a/app/service/EnterprisePortraitCategoryService.php +++ b/app/service/EnterprisePortraitCategoryService.php @@ -122,7 +122,7 @@ class EnterprisePortraitCategoryService extends BaseService $query = [ 'delete_time' => 0 ]; - $list = $this->dao->getList($query); + $list = $this->dao->getList($query, '*', 0, 0, 'id DESC', [], ['files']); return $list; } } \ No newline at end of file diff --git a/app/validate/AiCommandValidate.php b/app/validate/AiCommandValidate.php new file mode 100644 index 0000000..0c65899 --- /dev/null +++ b/app/validate/AiCommandValidate.php @@ -0,0 +1,28 @@ + [ + 'name' => 'require', + 'type' => 'require', + 'content' => 'require', + ], + 'update' => [ + 'id' => 'require', + 'name' => 'require', + 'type' => 'require', + 'content' => 'require', + ], + ]; + protected $message = [ + 'id.require' => '指令ID不能为空', + 'name.require' => '指令名称不能为空', + 'type.require' => '写作类型不能为空', + 'content.require' => '指令内容不能为空' + ]; +} \ No newline at end of file