Rate.php
5.1 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
<?php
namespace app\school\controller\project_approval;
use app\common\controller\DoubleBase;
use app\school\controller\project_common\ProjectData;
use app\school\model\project_common\ProjectRegister;
use app\school\model\project_common\ProjectReview;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use think\exception\ValidateException;
class Rate extends DoubleBase
{
protected $containerId = null;
protected $model = null;
// 评审阶段(0:立项评审;1:中期检查;2:项目结题)
protected $reviewStage = 0;
protected $shopIdAutoCondition = false;
// 项目级别列表
protected $levels = [
'0' => '未评级',
'1' => '院级',
'2' => '校级',
'3' => '省级',
'4' => '国家级'
];
// 引入获取项目数据的traits
use ProjectData;
public function _initialize()
{
parent::_initialize();
$this->containerId = $_COOKIE['container_id'];
$this->model = new ProjectRegister();
}
public function index()
{
if ($this->request->isAjax())
{
$map = [];
$filter = json_decode($this->request->get('filter'), true);
//自定义搜索条件
if(isset($filter['project_type'])) {
$map['a.project_type'] = $filter['project_type'];
}
if(isset($filter['project_level'])) {
$map['a.project_level'] = $filter['project_level'];
}
if(isset($filter['college_id'])) {
$map['u.college'] = $filter['college_id'];
}
if(isset($filter['username'])) {
$map['u.nickname'] = ['like',"%{$filter['username']}%"];
}
$map['a.review_stage'] = ['IN', '1,2'];
if ($this->auth->rule_type == 1){
//所属学院或部门
$map['a.project_college'] = $this->auth->college_id;
}
$result = $this->approvalProjectData($map);
return json($result);
}
$stageWhere = [
'container_id' => $this->containerId,
'review_stage' => 0
];
$reviewStageIds = (new ProjectReview())->where($stageWhere)->column('id');
$this->assignconfig('review_stage_ids', $reviewStageIds);
$this->assignconfig('project_level', $this->levels);
$this->assign('levels', $this->levels);
return $this->view->fetch();
}
/**
* 编辑
*/
public function edit($ids = null)
{
$row = $this->model->where(array('id'=>$ids,'school_id'=>SCHOOL_ID))->find();
if (!$row) {
$this->error(__('No Results were found'));
}
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException(true)->validate($validate);
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
$this->success();
} else {
$this->error(__('No rows were updated'));
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
$this->view->assign("row", $row);
$this->assign('project_levels', $this->levels);
return $this->view->fetch();
}
/**
* 批量评级
*/
public function rate()
{
if ($this->request->isAjax()) {
$ids = explode(',', $this->request->param('ids'));
$projectLevel = $this->request->param('project_level');
$projectLevels = array_map(function ($id) use ($projectLevel) {
return [
'id' => $id,
'project_level' => $projectLevel
];
}, $ids);
Db::startTrans();
try {
$this->model->allowField(true)->saveAll($projectLevels);
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
$this->success();
}
}
}