diff --git a/.env b/.env
index 86e5f26..7b47b8b 100644
--- a/.env
+++ b/.env
@@ -1,14 +1,14 @@
-APP_DEBUG = false
+APP_DEBUG = true
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
[DATABASE]
TYPE = mysql
-HOSTNAME = 127.0.0.1
+HOSTNAME = 192.168.31.201
DATABASE = ruankao
-USERNAME = ruankao
-PASSWORD = 123456
+USERNAME = root
+PASSWORD = 920103
HOSTPORT = 3306
CHARSET = utf8
DEBUG = true
diff --git a/.gitignore b/.gitignore
index 625fcdf..bc13e57 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@
runtime
*.log
config/database.php
+.env
\ No newline at end of file
diff --git a/app/admin/controller/TkController.php b/app/admin/controller/TkController.php
index 3b6b056..6b3b956 100644
--- a/app/admin/controller/TkController.php
+++ b/app/admin/controller/TkController.php
@@ -92,21 +92,6 @@ class TkController extends BaseController
}
}
-
- //递归构建树形结构
- private function buildTree($item, $list)
- {
- $item['children'] = [];
- foreach ($list as $child) {
- if ($child['parent_id'] == $item['id']) {
- // 添加层级关系标识
- $child['isLeaf'] = ($child['level'] == max(array_column($list, 'level')));
- $item['children'][] = $this->buildTree($child, $list);
- }
- }
- return $item;
- }
-
//题目分类增加
public function categoryadd()
{
@@ -162,7 +147,7 @@ class TkController extends BaseController
// 分类筛选
if (!empty($params['category'])) {
- $cateInfo = TkSubjects::where('name', $params['category'])
+ $cateInfo = TkQuestions::where('name', $params['category'])
->where('delete_time', null)
->where('status', 1)
->field('id')
@@ -190,7 +175,7 @@ class TkController extends BaseController
->select()
->each(function ($item) {
// 获取分类信息
- $cateInfo = TkSubjects::where('id', (int) $item['cate'])
+ $cateInfo = TkQuestions::where('id', (int) $item['cate'])
->field('name, icon')
->find();
if ($cateInfo) {
@@ -210,44 +195,69 @@ class TkController extends BaseController
'data' => $lists
]);
} else {
- $allCategories = TkSubjects::where('delete_time', null)
- ->where('status', 1)
- ->field('id, name, cid, icon')
- ->order('sort asc, id asc')
- ->select()
- ->toArray();
+ // $allCategories = TkQuestions::where('delete_time', null)
+ // ->where('status', 1)
+ // ->field('id, name, cid, icon')
+ // ->order('sort asc, id asc')
+ // ->select()
+ // ->toArray();
- $categories = $this->buildParentChild($allCategories);
+ // $categories = $this->buildParentChild($allCategories);
- View::assign([
- 'categories' => $categories
- ]);
+ // View::assign([
+ // 'categories' => $categories
+ // ]);
return View::fetch();
}
}
- // 构建父子结构
- private function buildParentChild($lists)
+ //题目添加
+ public function topicadd()
{
- $tree = [];
- foreach ($lists as $item) {
- if ($item['cid'] == 0) {
- // 顶级分类
- $tree[] = $item;
- } else {
- // 子分类
- foreach ($tree as &$parent) {
- if ($parent['id'] == $item['cid']) {
- if (!isset($parent['children'])) {
- $parent['children'] = [];
- }
- $parent['children'][] = $item;
- break;
- }
- }
+ if ($this->request->isPost()) {
+ $params = $this->request->post();
+
+ // 数据验证
+ $validate = new \think\Validate([
+ 'question_type' => 'require|number|between:1,6',
+ 'subject_id' => 'require|number',
+ 'knowledge_point_id' => 'number',
+ 'difficulty' => 'number|between:1,5',
+ 'content' => 'require',
+ 'analysis' => 'require',
+ 'answer' => 'require'
+ ]);
+
+ if (!$validate->check($params)) {
+ return json(['code' => 1, 'msg' => $validate->getError()]);
}
+
+ // 处理数据
+ $data = [
+ 'question_type' => (int)$params['question_type'],
+ 'subject_id' => (int)$params['subject_id'],
+ 'knowledge_point_id' => isset($params['knowledge_point_id']) ? (int)$params['knowledge_point_id'] : null,
+ 'difficulty' => isset($params['difficulty']) ? (int)$params['difficulty'] : 3,
+ 'content' => $params['content'],
+ 'analysis' => $params['analysis'],
+ 'answer' => $params['answer'],
+ 'created_by' => $this->getUserId(), // 假设有获取当前用户ID的方法
+ 'created_time' => date('Y-m-d H:i:s'),
+ 'updated_by' => $this->getUserId(),
+ 'updated_time' => date('Y-m-d H:i:s')
+ ];
+
+ // 保存数据
+ $result = \think\facade\Db::name('questions')->insert($data);
+
+ if ($result) {
+ return json(['code' => 0, 'msg' => '添加成功']);
+ } else {
+ return json(['code' => 1, 'msg' => '添加失败']);
+ }
+ } else {
+ return View::fetch();
}
- return $tree;
}
}
\ No newline at end of file
diff --git a/app/admin/view/public/header.php b/app/admin/view/public/header.php
index 814978e..c22c9d1 100644
--- a/app/admin/view/public/header.php
+++ b/app/admin/view/public/header.php
@@ -6,8 +6,9 @@
-
-
+
+
+
+
\ No newline at end of file
+
+