ProjectCompetition.php
9.4 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
namespace app\index\controller;
use app\common\controller\Frontend;
use think\Db;
class ProjectCompetition extends Frontend
{
protected $noNeedLogin = [];
protected $noNeedRight = '*';
protected $layout = 'default';
protected $model = null;
public function _initialize()
{
parent::_initialize(); // TODO: Change the autogenerated stub
$this->assign('index','index');
}
/**
* @return string
* @throws \think\Exception
* @throws \think\exception\DbException
* 申请专利情况
*/
public function CompetitionIndex(){
$param = $this->request->param();
$list = Db::name("project_competition")->where(['regiter_id'=>$param['regiter_id']])->paginate(10,false,['query'=>request()->param()]);
$this->assign("list",$list);
$this->assign("page",$list->render());
$this->assignconfig("regiter_id",$param['regiter_id']);
$this->assign("regiter_id",$param['regiter_id']);
return $this->view->fetch();
}
/**
* @return string
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* 添加专利
*/
public function CompetitionAdd(){
$param = $this->request->param();
if($this->request->isAjax()){
if(empty($param["competition_title"])){
$this->error("请输入专利题名");
}else{
$insert["competition_title"] = $param["competition_title"];//专利题名
}
if(empty($param["regiter_id"])){
$this->error("参数错误");
}else{
$insert["regiter_id"] = $param["regiter_id"];//项目id
$insert["container_id"] = Db::name("project_register")->where(['id'=>$param["regiter_id"]])->value("container_id");//容器id
}
if(empty($param["organizer"])){
$this->error("请填写主办单位");
}else{
$insert["organizer"] = $param["organizer"];//主办单位
}
if(empty($param["reward_date"])){
$this->error("请选择获奖日期");
}else{
$insert["reward_date"] = strtotime($param["reward_date"]);//获奖日期
}
if(empty($param["competition_level"])){
$this->error("请选择竞赛级别");
}else{
$insert["competition_level"] = $param["competition_level"];//竞赛级别
}
if(empty($param["reward_level"])){
$this->error("请选择获奖等级");
}else{
$insert["reward_level"] = $param["reward_level"];//获奖等级
}
if(empty($param["my_file"])){
$this->error("请上传支撑材料");
}else{
$insert["file"] = $param["my_file"];//支撑材料
}
if(empty($param["student_json"])){
$this->error("请至少填写一个申请者");
}else{
$insert["student_json"] = json_encode($param["student_json"],JSON_UNESCAPED_UNICODE);//获奖学生信息集合集合格式
}
$insert["students"] ='';//获奖学生id集合
$insert["memo"] = $param["memo"];//备注
$insert["createtime"] = time();//创建时间
$user = $this->auth;
$insert["user_id"] = $user->id;//备注
$insert["username"] = $user->nickname;//备注
$info = Db::name('project_competition')->where(["competition_title"=>$param["competition_title"],"regiter_id"=>$param["regiter_id"]])->find();
if($info){
$this->error("此竞赛获奖情况已存在,请勿重复添加");
}
$status = Db::name('project_competition')->insert($insert);
if($status){
$this->success("添加成功");
}else{
$this->error("添加失败");
}
}
$this->assign("regiter_id",$param['regiter_id']);
$this->assignconfig("regiter_id",$param['regiter_id']);
return $this->view->fetch();
}
/**
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
* 删除论文
*/
public function CompetitionDelete(){
$param = $this->request->param();
$info = Db::name("project_competition")->where(['competition_id'=>$param['competition_id']])->find();
if(!empty($info)){
$status = Db::name("project_competition")->where(['competition_id'=>$param['competition_id']])->delete();
if($status){
$this->success("操作成功");
}else{
$this->error("操作失败");
}
}else{
$this->error("此信息不存在");
}
}
/**
* @return string
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* 编辑论文
*/
public function CompetitionEdit(){
$param = $this->request->param();
if($this->request->isAjax()){
if(empty($param["competition_title"])){
$this->error("请输入专利题名");
}else{
$insert["competition_title"] = $param["competition_title"];//专利题名
}
if(empty($param["regiter_id"])){
$this->error("参数错误");
}else{
$insert["regiter_id"] = $param["regiter_id"];//项目id
$insert["container_id"] = Db::name("project_register")->where(['id'=>$param["regiter_id"]])->value("container_id");//容器id
}
if(empty($param["organizer"])){
$this->error("请填写主办单位");
}else{
$insert["organizer"] = $param["organizer"];//主办单位
}
if(empty($param["reward_date"])){
$this->error("请选择获奖日期");
}else{
$insert["reward_date"] = strtotime($param["reward_date"]);//获奖日期
}
if(empty($param["competition_level"])){
$this->error("请选择竞赛级别");
}else{
$insert["competition_level"] = $param["competition_level"];//竞赛级别
}
if(empty($param["reward_level"])){
$this->error("请选择获奖等级");
}else{
$insert["reward_level"] = $param["reward_level"];//获奖等级
}
if(empty($param["my_file"])){
$this->error("请上传支撑材料");
}else{
$insert["file"] = $param["my_file"];//支撑材料
}
if(empty($param["student_json"])){
$this->error("请至少填写一个申请者");
}else{
$insert["student_json"] = json_encode($param["student_json"],JSON_UNESCAPED_UNICODE);//获奖学生信息集合集合格式
}
$insert["students"] ='';//获奖学生id集合
$insert["memo"] = $param["memo"];//备注
$insert["createtime"] = time();//创建时间
$info = Db::name('project_competition')->where(["competition_title"=>$param["competition_title"],"regiter_id"=>$param["regiter_id"]])->find();
if($info['competition_id'] != $param['competition_id']){
$this->error("此专利已存在,请勿重复添加");
}
$status = Db::name('project_competition')->where(['competition_id'=>$param['competition_id']])->update($insert);
if($status){
$this->success("操作成功");
}else{
$this->error("操作失败");
}
}
$info = Db::name('project_competition')->where(["competition_id"=>$param["competition_id"]])->find();
$info['filename'] = Db::name('attachment')->where(["url"=>$info["file"]])->value("filename");
$this->assign("filename",$info['filename']);
$this->assign("url",$info['file']);
$this->assignconfig("date",date("Y-m-d",$info['reward_date']));
$this->assignconfig("competition_id",$param['competition_id']);
$this->assignconfig("regiter_id",$param['regiter_id']);
$this->assign("regiter_id",$param['regiter_id']);
return $this->view->fetch();
}
public function getCompetitionData(){
$param = $this->request->param();
$info = Db::name('project_competition')->where(["competition_id"=>$param["competition_id"]])->find();
if(empty($info)){
$this->error("此论文不存在");
}else{
$info['student_json'] = json_decode( $info['student_json'],true);
$info['filename'] = Db::name('attachment')->where(["url"=>$info["file"]])->value("filename");
$this->success('','',$info);
}
}
}