SaveController.class.php
1.61 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
<?php
/**
* Created by PhpStorm.
* User: zhonglei
* Date: 2018/3/26
* Time: 11:41
*/
namespace Apicp\Controller\Dict;
use Com\PackageValidate;
use Common\Service\DictService;
class SaveController extends AbstractController
{
/**
* Save
* @author zhonglei
* @desc 保存字典
* @param int dict_id:true 字典ID
* @param String key:true 字典Key(teacher_title=讲师头衔;teacher_task_type=讲师授课任务类型)
* @param String value:true 字典值
* @return Array
* array(
* 'dict_id' => 1 // 字典ID
* )
*/
public function Index_post()
{
$rules = [
'dict_id' => 'require|integer',
'key' => 'require|max:64',
'value' => 'require|max:64',
];
// 验证数据
$validate = new PackageValidate($rules, [], array_keys($rules));
$post_data = $validate->postData;
$dictServ = new DictService();
$dict_id = $post_data['dict_id'];
unset($post_data['dict_id']);
$conds = $post_data;
// 编辑
if ($dict_id > 0) {
if (empty($dictServ->get($dict_id))) {
E('_ERR_DICT_NOT_FOUND');
}
$conds['dict_id != ?'] = $dict_id;
}
// 判断重复数据
if (!empty($dictServ->get_by_conds($conds))) {
E('_ERR_DICT_EXIST');
}
// 保存
if ($dict_id == 0) {
$dict_id = $dictServ->insert($post_data);
} else {
$dictServ->update($dict_id, $post_data);
}
$this->_result['dict_id'] = $dict_id;
}
}