Browse Source
feat(admin): 新增网媒配置管理功能
feat(admin): 新增网媒配置管理功能
- 添加网媒配置控制器、服务类和数据访问对象 - 实现配置项的增删改查接口 - 配置路由组并应用权限中间件 - 支持系统配置项保护机制 - 优化媒体数据同步逻辑,支持分页处理 - 增加自媒体数据结构与操作支持 - 调整数据库模型继承关系以提高代码复用性 - 扩展API服务能力,适配多种媒体类型同步需求master
9 changed files with 365 additions and 48 deletions
-
60app/controller/admin/OnlineMediasConfigController.php
-
15app/dao/admin/OnlineMediasConfigDao.php
-
4app/dao/admin/OnlineMediasDao.php
-
15app/dao/admin/SelfMediasDao.php
-
33app/model/admin/OnlineMediasConfig.php
-
33app/model/admin/SelfMedias.php
-
20app/route/admin.php
-
127app/service/admin/ApiService.php
-
106app/service/admin/OnlineMediasConfigService.php
@ -0,0 +1,60 @@ |
|||||
|
<?php |
||||
|
namespace app\controller\admin; |
||||
|
|
||||
|
|
||||
|
use app\service\admin\OnlineMediasConfigService; |
||||
|
use plugin\piadmin\app\utils\ArrayUtils; |
||||
|
use support\Response; |
||||
|
|
||||
|
class OnlineMediasConfigController |
||||
|
{ |
||||
|
public function save(OnlineMediasConfigService $service): Response |
||||
|
{ |
||||
|
$params = requestOnly([ |
||||
|
'module_id' => 1, |
||||
|
'code' => '', |
||||
|
'name' => '', |
||||
|
'value' => '', |
||||
|
'pid' => '', |
||||
|
'status' => 1 |
||||
|
]); |
||||
|
|
||||
|
// validate(SystemDeptValidate::class)->check($params, 'save');
|
||||
|
|
||||
|
return success($service->saveData($params)); |
||||
|
} |
||||
|
|
||||
|
public function update(OnlineMediasConfigService $service): Response |
||||
|
{ |
||||
|
$params = requestOnly([ |
||||
|
'id' => '', |
||||
|
'module_id' => 1, |
||||
|
'code' => '', |
||||
|
'name' => 1000, |
||||
|
'value' => '', |
||||
|
'pid' => '', |
||||
|
'status' => 1 |
||||
|
]); |
||||
|
|
||||
|
// validate(SystemDeptValidate::class)->check($params, 'update');
|
||||
|
|
||||
|
return success($service->updateData(ArrayUtils::filterNotEmpty($params))); |
||||
|
} |
||||
|
|
||||
|
public function index(OnlineMediasConfigService $service): Response |
||||
|
{ |
||||
|
return success($service->listData()); |
||||
|
} |
||||
|
|
||||
|
public function read(OnlineMediasConfigService $service): Response |
||||
|
{ |
||||
|
$id = input('id'); |
||||
|
return success($service->readData($id)); |
||||
|
} |
||||
|
|
||||
|
public function delete(OnlineMediasConfigService $service): Response |
||||
|
{ |
||||
|
$ids = input('ids'); |
||||
|
return success($service->deleteData($ids)); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\dao\admin; |
||||
|
|
||||
|
use app\model\admin\OnlineMediasConfig; |
||||
|
use plugin\piadmin\app\base\BaseDao; |
||||
|
|
||||
|
class OnlineMediasConfigDao extends BaseDao |
||||
|
{ |
||||
|
protected function setModel(): string |
||||
|
{ |
||||
|
return OnlineMediasConfig::class; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\dao\admin; |
||||
|
|
||||
|
use app\model\admin\SelfMedias; |
||||
|
use plugin\piadmin\app\base\BaseDao; |
||||
|
|
||||
|
class SelfMediasDao extends BaseDao |
||||
|
{ |
||||
|
protected function setModel(): string |
||||
|
{ |
||||
|
return SelfMedias::class; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\model\admin; |
||||
|
|
||||
|
use plugin\piadmin\app\base\BaseModel; |
||||
|
|
||||
|
/** |
||||
|
* AI创作指令模型 |
||||
|
*/ |
||||
|
class OnlineMediasConfig extends BaseModel |
||||
|
{ |
||||
|
/** |
||||
|
* The table associated with the model. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $table = 'geo_online_medias_config'; |
||||
|
|
||||
|
/** |
||||
|
* 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,33 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\model\admin; |
||||
|
|
||||
|
use plugin\piadmin\app\base\BaseModel; |
||||
|
|
||||
|
/** |
||||
|
* AI创作指令模型 |
||||
|
*/ |
||||
|
class SelfMedias extends BaseModel |
||||
|
{ |
||||
|
/** |
||||
|
* The table associated with the model. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $table = 'geo_self_medias'; |
||||
|
|
||||
|
/** |
||||
|
* 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\admin; |
||||
|
|
||||
|
use app\dao\admin\OnlineMediasConfigDao; |
||||
|
use plugin\piadmin\app\base\BaseService; |
||||
|
use plugin\piadmin\app\exception\ApiException; |
||||
|
use plugin\piadmin\app\utils\TreeUtils; |
||||
|
use think\facade\Db; |
||||
|
|
||||
|
class OnlineMediasConfigService extends BaseService |
||||
|
{ |
||||
|
public function __construct() |
||||
|
{ |
||||
|
$this->dao = app()->make(OnlineMediasConfigDao::class); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 保存数据 |
||||
|
* @param array $params |
||||
|
* @return \plugin\piadmin\app\base\BaseModel |
||||
|
* @throws \think\db\exception\DataNotFoundException |
||||
|
* @throws \think\db\exception\DbException |
||||
|
* @throws \think\db\exception\ModelNotFoundException |
||||
|
*/ |
||||
|
public function saveData(array $params) |
||||
|
{ |
||||
|
return $this->dao->save($params); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 更新数据 |
||||
|
* @param array $params |
||||
|
* @throws \think\db\exception\DataNotFoundException |
||||
|
* @throws \think\db\exception\DbException |
||||
|
* @throws \think\db\exception\ModelNotFoundException |
||||
|
*/ |
||||
|
public function updateData(array $params) |
||||
|
{ |
||||
|
$config = $this->dao->get(['id' => $params['id']]); |
||||
|
if (empty($config)) { |
||||
|
throw new ApiException('配置项不存在'); |
||||
|
} |
||||
|
if ($config['is_system'] == 1) { |
||||
|
throw new ApiException('系统配置项不允许修改'); |
||||
|
} |
||||
|
// 落库
|
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
$this->dao->update(['id' => $config['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 |
||||
|
{ |
||||
|
$query = [ |
||||
|
'delete_time' => 0 |
||||
|
]; |
||||
|
$list = $this->dao->selectList($query)->toArray(); |
||||
|
return TreeUtils::toTree($list); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 详情数据 |
||||
|
* @param mixed $id |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function readData(mixed $id): array |
||||
|
{ |
||||
|
$config = $this->dao->get(['id' => $id]); |
||||
|
if (empty($config)) { |
||||
|
return []; |
||||
|
} |
||||
|
if ($config['is_system'] == 1) { |
||||
|
throw new ApiException('系统配置项不允许查看'); |
||||
|
} |
||||
|
return $config->toArray(); |
||||
|
} |
||||
|
|
||||
|
public function deleteData($ids) |
||||
|
{ |
||||
|
// 落库
|
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
foreach ($ids as $id) { |
||||
|
$this->dao->update(['id' => $id, 'is_system' => 2], ['delete_time' => time()]); |
||||
|
} |
||||
|
Db::commit(); |
||||
|
} catch (\Exception $exception) { |
||||
|
Db::rollback(); |
||||
|
throw new ApiException($exception->getMessage()); |
||||
|
} |
||||
|
return ['id' => $ids]; |
||||
|
} |
||||
|
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue