diff --git a/app/controller/ExpiosiveReplicaController.php b/app/controller/ExpiosiveReplicaController.php new file mode 100644 index 0000000..130ad9a --- /dev/null +++ b/app/controller/ExpiosiveReplicaController.php @@ -0,0 +1,46 @@ + '', + 'portrait_category_id' => '', + 'ai_command_id' => '' + ]); + validate(ExpiosiveReplicaValidate::class)->check($params, 'save'); + return success($service->saveData($params)); + } + + public function index(ExpiosiveReplicaService $service): Response + { + $params = requestOnly([ + 'begin_time' => '', + 'end_time' => '' + ]); + return success($service->listData($params)); + } + + public function read(ExpiosiveReplicaService $service): Response + { + $id = input('id'); + return success($service->readData($id)); + } + + public function delete(ExpiosiveReplicaService $service): Response + { + $ids = input('ids'); + return success($service->deleteData($ids)); + } + + public function pureIndex(ExpiosiveReplicaService $service) + { + return success($service->selectData()); + } +} \ No newline at end of file diff --git a/app/dao/ExpiosiveReplicaDao.php b/app/dao/ExpiosiveReplicaDao.php new file mode 100644 index 0000000..3febbfd --- /dev/null +++ b/app/dao/ExpiosiveReplicaDao.php @@ -0,0 +1,15 @@ +setParams(['perm' => ['replicaSave']]); + //列表 + Route::get('/index', [ExpiosiveReplicaController::class, 'index'])->setParams(['perm' => ['replicaIndex']]); + //详情 + Route::get('/read', [ExpiosiveReplicaController::class, 'read'])->setParams(['perm' => ['replicaRead']]); + //删除 + Route::post('/delete', [ExpiosiveReplicaController::class, 'delete'])->setParams(['perm' => ['replicaDelete']]); + //下拉数据 + Route::get('/pure/index', [ExpiosiveReplicaController::class, 'pureIndex'])->setParams(['perm' => 'replicaPureIndex']); + }); + //全局代理IP Route::group('/proxy', function () { //新增 diff --git a/app/service/ExpiosiveReplicaService.php b/app/service/ExpiosiveReplicaService.php new file mode 100644 index 0000000..adcbe02 --- /dev/null +++ b/app/service/ExpiosiveReplicaService.php @@ -0,0 +1,106 @@ +dao = $dao; + } + + /** + * 保存信息 + * @param array $params + * @return array + */ + public function saveData(array $params): array + { + Db::startTrans(); + try { + $params['name'] = '全网爆文复刻[' . date('Y-m-d H:i') . ']'; + $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 listData(array $params): array + { + [$page, $limit] = RequestUtils::getPageParameter(); + [$sortRule, $sortField] = RequestUtils::getSortParameter(); + $query = [ + 'delete_time' => 0 + ]; + 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, '*', $page, $limit, "$sortField $sortRule"); + $count = $this->dao->getCount($query); + return compact('list', 'count'); + } + + /** + * 获取信息 + * @param mixed $id + * @return array + */ + public function readData(mixed $id): array + { + $replica = $this->dao->get(['id' => $id]); + if (empty($replica)) { + throw new ApiException('数据不存在'); + } + return $replica->toArray(); + } + + /** + * 删除信息 + * @param mixed $id + * @return array + */ + public function deleteData(array $ids): array + { + // 落库 + Db::startTrans(); + try { + $this->dao->update([['id', 'in', $ids]], ['delete_time' => time()]); + Db::commit(); + } catch (\Exception $exception) { + Db::rollback(); + throw new ApiException($exception->getMessage()); + } + return ['id' => $ids]; + } + + public function selectData() + { + $query = [ + 'delete_time' => 0 + ]; + $list = $this->dao->getList($query); + return $list; + } +} \ No newline at end of file diff --git a/app/validate/ExpiosiveReplicaValidate.php b/app/validate/ExpiosiveReplicaValidate.php new file mode 100644 index 0000000..e4a1f32 --- /dev/null +++ b/app/validate/ExpiosiveReplicaValidate.php @@ -0,0 +1,21 @@ + [ + 'url' => 'require', + 'portrait_category_id' => 'require|number', + 'ai_command_id' => 'require|number' + ], + ]; + protected $message = [ + 'url.require' => '文章链接不能为空', + 'portrait_category_id.require' => '文章配图不能为空', + 'ai_command_id.require' => '爆文改写指令不能为空', + ]; +} \ No newline at end of file