更新显示架构

This commit is contained in:
2026-03-09 09:40:36 +08:00
parent 99fc99f8ad
commit 4cbc52c51b
14 changed files with 1162 additions and 1 deletions
@@ -0,0 +1,180 @@
<?php
declare(strict_types=1);
namespace app\admin\controller\Cms\Demand;
use app\index\BaseController;
use Symfony\Component\VarDumper\VarDumper;
use think\exception\ValidateException;
use think\facade\Request;
use think\facade\Session;
use think\response\Json;
use think\db\exception\DbException;
use app\model\Cms\Demand;
use app\model\Cms\DemandCategory;
class DemandController extends BaseController
{
/**
* 获取需求列表
* @return Json
*/
public function getDemandList(): Json
{
// 查询分类
$demandList = Demand::where('delete_time', null)
->order('id', 'desc')
->select();
if (!$demandList) {
return json([
'code' => 200,
'msg' => 'success',
'list' => [],
]);
}
return json([
'code' => 200,
'msg' => 'success',
'list' => $demandList,
]);
}
/**
* 增加需求
* @return Json
*/
public function addDemand(): Json
{
try {
$data = Request::only(['title', 'desc', 'applicant', 'status']);
// 验证数据
if (empty($data['title']) || empty($data['desc'])) {
return json([
'code' => 400,
'msg' => '标题和描述不能为空',
]);
}
// 创建需求
$demand = Demand::create([
'title' => $data['title'],
'desc' => $data['desc'],
'applicant' => $data['applicant'] ?? '',
'status' => $data['status'] ?? 'pending',
]);
return json([
'code' => 200,
'msg' => '添加成功',
'data' => $demand,
]);
} catch (\Exception $e) {
return json([
'code' => 500,
'msg' => '添加失败:' . $e->getMessage(),
]);
}
}
/**
* 编辑需求
* @return Json
*/
public function editDemand(): Json
{
try {
$id = Request::param('id');
$data = Request::only(['title', 'desc', 'applicant', 'status']);
// 验证数据
if (empty($id)) {
return json([
'code' => 400,
'msg' => '需求ID不能为空',
]);
}
if (empty($data['title']) || empty($data['desc'])) {
return json([
'code' => 400,
'msg' => '标题和描述不能为空',
]);
}
// 查找需求
$demand = Demand::find($id);
if (!$demand) {
return json([
'code' => 404,
'msg' => '需求不存在',
]);
}
// 更新需求
$demand->save([
'title' => $data['title'],
'desc' => $data['desc'],
'applicant' => $data['applicant'] ?? '',
'status' => $data['status'] ?? 'pending',
]);
return json([
'code' => 200,
'msg' => '编辑成功',
'data' => $demand,
]);
} catch (\Exception $e) {
return json([
'code' => 500,
'msg' => '编辑失败:' . $e->getMessage(),
]);
}
}
/**
* 删除需求
* @return Json
*/
public function deleteDemand(): Json
{
try {
$id = Request::param('id');
// 验证数据
if (empty($id)) {
return json([
'code' => 400,
'msg' => '需求ID不能为空',
]);
}
// 查找需求
$demand = Demand::find($id);
if (!$demand) {
return json([
'code' => 404,
'msg' => '需求不存在',
]);
}
// 软删除
$demand->delete();
return json([
'code' => 200,
'msg' => '删除成功',
]);
} catch (\Exception $e) {
return json([
'code' => 500,
'msg' => '删除失败:' . $e->getMessage(),
]);
}
}
}
+120
View File
@@ -0,0 +1,120 @@
<?php
declare(strict_types=1);
namespace app\admin\controller;
use app\admin\BaseController;
use app\service\ThemeService;
use think\facade\Request;
/**
* 模板管理控制器
*/
class ThemeController extends BaseController
{
private ThemeService $themeService;
public function __construct()
{
$this->themeService = new ThemeService();
}
/**
* 获取模板列表(后台管理)
* @return \think\response\Json
*/
public function index()
{
$themes = $this->themeService->getThemeList();
$currentTheme = $this->themeService->getCurrentTheme();
return json([
'code' => 200,
'msg' => 'success',
'data' => [
'list' => $themes,
'currentTheme' => $currentTheme
]
]);
}
/**
* 切换模板
* @return \think\response\Json
*/
public function switch()
{
$themeKey = Request::post('theme_key', '');
if (empty($themeKey)) {
return json([
'code' => 400,
'msg' => '模板标识不能为空'
]);
}
$result = $this->themeService->switchTheme($themeKey);
if ($result) {
return json([
'code' => 200,
'msg' => '切换成功'
]);
}
return json([
'code' => 400,
'msg' => '切换失败,模板不存在'
]);
}
/**
* 获取模板字段数据
* @return \think\response\Json
*/
public function getData()
{
$themeKey = Request::get('theme_key', '');
$themeData = $this->themeService->getThemeData($themeKey ?: null);
return json([
'code' => 200,
'msg' => 'success',
'data' => $themeData
]);
}
/**
* 保存模板字段数据
* @return \think\response\Json
*/
public function saveData()
{
$themeKey = Request::post('theme_key', '');
$fieldKey = Request::post('field_key', '');
$fieldValue = Request::post('field_value', '');
if (empty($themeKey) || empty($fieldKey)) {
return json([
'code' => 400,
'msg' => '参数不完整'
]);
}
$result = $this->themeService->saveThemeField($themeKey, $fieldKey, $fieldValue);
if ($result) {
return json([
'code' => 200,
'msg' => '保存成功'
]);
}
return json([
'code' => 400,
'msg' => '保存失败'
]);
}
}
+8
View File
@@ -0,0 +1,8 @@
<?php
use think\facade\Route;
// 需求路由
Route::get('demandList', 'app\\admin\\controller\\Cms\\Demand\\DemandController@getDemandList');
Route::post('addDemand', 'app\\admin\\controller\\Cms\\Demand\\DemandController@addDemand');
Route::post('editDemand/:id', 'app\\admin\\controller\\Cms\\Demand\\DemandController@editDemand');
Route::post('deleteDemand/:id', 'app\\admin\\controller\\Cms\\Demand\\DemandController@deleteDemand');
+8
View File
@@ -0,0 +1,8 @@
<?php
use think\facade\Route;
// 模板管理路由
Route::get('theme', 'app\admin\controller\ThemeController@index');
Route::post('theme/switch', 'app\admin\controller\ThemeController@switch');
Route::get('theme/data', 'app\admin\controller\ThemeController@getData');
Route::post('theme/data', 'app\admin\controller\ThemeController@saveData');