更新模块市场功能

This commit is contained in:
2026-01-30 16:19:53 +08:00
parent 5e997747c5
commit 581738da6e
7 changed files with 280 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
/**
* 编辑分类(添加/编辑)
* @param int $id 分类ID,为空时新增,有值时编辑
*/
public function editCategory(int $id = 0)
{
$data = request()->param();
// 过滤只保留数据库表需要的字段
$allowedFields = ['id', 'title', 'status'];
$saveData = [];
foreach ($allowedFields as $field) {
if (isset($data[$field])) {
$saveData[$field] = $data[$field];
}
}
if ($id > 0) {
// 编辑模式
$saveData['update_time'] = date('Y-m-d H:i:s');
SystemModuleCategory::where('id', $id)->update($saveData);
$this->logSuccess('模块市场', '编辑模块分类', ['id' => $id, 'data' => $saveData]);
return json([
'code' => 200,
'msg' => '编辑成功'
]);
} else {
// 新增模式
$saveData['create_time'] = date('Y-m-d H:i:s');
$cateId = SystemModuleCategory::insertGetId($saveData);
$this->logSuccess('模块市场', '添加模块分类', ['data' => $saveData]);
return json([
'code' => 200,
'msg' => '添加成功'
]);
}
}