OnlineTrainController.php
3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/**
* Created by PhpStorm.
* auther: sgj
* Date: 2020/10/10
* Time: 11:37
*/
namespace app\admin\controller;
use api\common\model\ClassModel;
use cmf\controller\AdminBaseController;
class OnlineTrainController extends AdminBaseController
{
public function index(){
$param = $this->request->param();
$map=[];
$data=db('class')->where($map)->order('weight desc')->paginate(10);
$data->appends($param);
$list=$data->items();
foreach ($list as $k=>$v){
}
$this->assign([
'data'=>$list,
'page'=>$data->render(),
]);
return $this->fetch();
}
/**
* 编辑页面
* @return mixed
*/
public function edit(){
if ($this->request->isPost()){
$data=input();
$id=$data['id'];
unset($data['id']);
$result=db('class')->where('id',$id)->update($data);
if ($result==1){
$this->success('修改成功');
}else{
$this->error('修改失败');
}
}else{
$id=input('id');
$info=db('class')->where('id',$id)->find();
$this->assign('data',$info);
return $this->fetch();
}
}
/**
* 添加信息
* @return mixed
*/
public function add(){
if ($this->request->isPost()){
$data=input();
$result=db('class')->insert($data);
if (!empty($result)){
$this->success('操作成功');
}else{
$this->error('操作失败');
}
}else{
return $this->fetch();
}
}
/**
* 问题列表
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function questionlist(){
$id=input('id');
$list=db('class_question')->where('class_id',$id)->select()->toArray();
foreach ($list as $k=>$v) {
$list[$k]['info']=json_decode($v['options'],true);
}
$this->assign('list',$list);
return $this->fetch();
}
/**
* 删除对应问题
*/
public function delete(){
$id=input('id');
$result=db('class_question')->where('id',$id)->delete();
if ($result){
$this->success('操作成功');
}else{
$this->error('操作失败');
}
}
/**
* 问题详情
*/
public function questioninfo(){
$id=input('id');
$data=db('class_question')->where('id',$id)->find();
$data['options']=json_decode($data['options'],true);
$this->assign('data',$data);
return $this->fetch();
}
public function questionadd(){
$data['options'][]='';
$data['options'][]='';
$data['options'][]='';
$data['options'][]='';
$this->assign('data',$data);
return $this->fetch();
}
/**
* 添加问题
*/
public function addquestionpost(){
$data=input();
$data['options']=json_encode($data['options']);
$result=db('class_question')->insert($data);
if ($result){
$this->success('操作成功');
}else{
$this->error('操作失败');
}
}
/**
* 编辑问题
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function editQuestion(){
$data=input();
$id=$data['id'];
$update['title']=$data['title'];
$update['options']=json_encode($data['options']);
$update['answer']=$data['answer'];
$info=db('class_question')->where('id',$id)->update($update);
if(!empty($info)){
$this->success('操作成功');
}else{
$this->error('操作失败');
}
}
}