AppointmentRule.php
3.2 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
<?php
namespace app\school\controller\project_appointment;
use app\common\controller\DoubleBase;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use think\exception\ValidateException;
use app\school\model\project_appointment\AppointmentRule as AppointmentRuleModel;
/**
* 基地入驻规则管理
*/
class AppointmentRule extends DoubleBase
{
protected $noNeedRight = ['*'];
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new AppointmentRuleModel();
}
/**
* 添加
*/
public function add()
{
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
if($this->model->where(['school_id' => SCHOOL_ID])->find()) {
$this->error('入驻规则已存在不能重复上传');
}
if(!isset($params['image_url'])) {
$this->error('请上传入驻流程图');
}
if(!isset($params['data_url'])) {
$this->error('请上传入驻资料');
}
$params['data_url'] = json_encode($params['data_url']);
$params['school_id'] = SCHOOL_ID;
Db::startTrans();
try {
$result = $this->model->allowField(true)->save($params);
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
$this->success();
}
$this->error(__('Parameter %s can not be empty', ''));
}
return $this->view->fetch();
}
/**
* 编辑
*/
public function edit($ids = null)
{
if(empty($ids)){
$ids = $this->request->param('id');
}
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
$params['school_id'] = SCHOOL_ID;
if(!isset($params['image_url'])) {
$this->error('请上传入驻流程图');
}
if(!isset($params['data_url'])) {
$this->error('请上传入驻资料');
}
$params['data_url'] = json_encode($params['data_url']);
Db::startTrans();
try {
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
$this->success();
}
$this->error(__('Parameter %s can not be empty', ''));
}
$row['data_url'] = json_decode($row['data_url'],true);
$this->view->assign("row", $row); //选中的数据
$this->assignconfig('id',$ids);
return $this->view->fetch();
}
}