AuthorityEditController.class.php
1.97 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
<?php
/**
* 权限范围编辑
* AbstractController.class.php
* $author$
*/
namespace Apicp\Controller\Integral;
use Com\PackageValidate;
use Common\Model\AuthorityMainModel;
use Common\Service\AuthorityMainService;
class AuthorityEditController extends AbstractController
{
public function index()
{
$validate = new PackageValidate(
[
'am_id' => 'require',
'visibleRange' => 'require',
'visibleRangeType' => 'in:' . implode(',', AuthorityMainModel::VISIBLE_RANGE_TYPE)
],
[
'am_id.require' => L('_ERR_PARAMS_CAN_NOT_EMPTY', ['name' => '可见范围主表ID']),
'visibleRange.require' => L('_ERR_PARAMS_CAN_NOT_EMPTY', ['name' => '可见范围']),
'visibleRangeType.in' => L('_ERR_PARAMS_NOT_IN_SCOPE', ['name' => '可见范围类型'])
],
[
'am_id',
'visibleRange',
'visibleRangeType'
]
);
$postData = $validate->postData;
// 判断主表数据是否存在
$authorityMainServ = new AuthorityMainService();
$mainData = $authorityMainServ->get($postData['am_id']);
if (empty($mainData)) {
E(L('_ERR_DATA_IS_NOT_EXIST', ['name' => '主表']));
}
try {
$mainServ = new AuthorityMainService();
$mainServ->start_trans();
// 更新数据
settype($postData['visibleRange'], 'array');
$mainServ->update(
$postData['am_id'],
[
'visible_range' => implode(',', $postData['visibleRange']),
'visible_range_type' => $postData['visibleRangeType']
]
);
$mainServ->commit();
} catch (\Exception $e) {
E($e->getCode() . ':' . $e->getMessage());
$mainServ->rollback();
}
return true;
}
}