Browse Source
feat(replica): 新增全网爆文复刻功能模块
feat(replica): 新增全网爆文复刻功能模块
- 新增爆文复刻模型ExpiosiveReplica - 新增控制器ExpiosiveReplicaController实现CURD操作 - 新增数据访问层ExpiosiveReplicaDao - 新增服务层ExpiosiveRepmaster
6 changed files with 236 additions and 0 deletions
-
46app/controller/ExpiosiveReplicaController.php
-
15app/dao/ExpiosiveReplicaDao.php
-
33app/model/ExpiosiveReplica.php
-
15app/route/route.php
-
106app/service/ExpiosiveReplicaService.php
-
21app/validate/ExpiosiveReplicaValidate.php
@ -0,0 +1,46 @@ |
|||||
|
<?php |
||||
|
namespace app\controller; |
||||
|
|
||||
|
use app\service\ExpiosiveReplicaService; |
||||
|
use app\validate\ExpiosiveReplicaValidate; |
||||
|
use support\Response; |
||||
|
|
||||
|
class ExpiosiveReplicaController |
||||
|
{ |
||||
|
public function save(ExpiosiveReplicaService $service): Response |
||||
|
{ |
||||
|
$params = requestOnly([ |
||||
|
'url' => '', |
||||
|
'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()); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\dao; |
||||
|
|
||||
|
use app\model\ExpiosiveReplica; |
||||
|
use plugin\piadmin\app\base\UserBaseDao; |
||||
|
|
||||
|
class ExpiosiveReplicaDao extends UserBaseDao |
||||
|
{ |
||||
|
protected function setModel(): string |
||||
|
{ |
||||
|
return ExpiosiveReplica::class; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\model; |
||||
|
|
||||
|
use plugin\piadmin\app\base\BaseModel; |
||||
|
|
||||
|
/** |
||||
|
* AI创作指令模型 |
||||
|
*/ |
||||
|
class ExpiosiveReplica extends BaseModel |
||||
|
{ |
||||
|
/** |
||||
|
* The table associated with the model. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $table = 'geo_explosive_replica'; |
||||
|
|
||||
|
/** |
||||
|
* The primary key associated with the table. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $primaryKey = 'id'; |
||||
|
|
||||
|
/** |
||||
|
* Indicates if the model should be timestamped. |
||||
|
* |
||||
|
* @var bool |
||||
|
*/ |
||||
|
public $timestamps = true; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,106 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\service; |
||||
|
|
||||
|
use app\dao\ExpiosiveReplicaDao; |
||||
|
use plugin\piadmin\app\base\BaseService; |
||||
|
use plugin\piadmin\app\exception\ApiException; |
||||
|
use plugin\piadmin\app\utils\RequestUtils; |
||||
|
use support\think\Db; |
||||
|
|
||||
|
class ExpiosiveReplicaService extends BaseService |
||||
|
{ |
||||
|
|
||||
|
protected $dao; |
||||
|
|
||||
|
public function __construct(ExpiosiveReplicaDao $dao) |
||||
|
{ |
||||
|
$this->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; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\validate; |
||||
|
|
||||
|
use plugin\piadmin\app\base\BaseValidate; |
||||
|
|
||||
|
class ExpiosiveReplicaValidate extends BaseValidate |
||||
|
{ |
||||
|
protected $group = [ |
||||
|
'save' => [ |
||||
|
'url' => 'require', |
||||
|
'portrait_category_id' => 'require|number', |
||||
|
'ai_command_id' => 'require|number' |
||||
|
], |
||||
|
]; |
||||
|
protected $message = [ |
||||
|
'url.require' => '文章链接不能为空', |
||||
|
'portrait_category_id.require' => '文章配图不能为空', |
||||
|
'ai_command_id.require' => '爆文改写指令不能为空', |
||||
|
]; |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue