AuthorityAddController.class.php
2.26 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
<?php
/**
* 权限范围添加
* AbstractController.class.php
* $author$
*/
namespace Apicp\Controller\Integral;
use Common\Model\AuthorityMainModel;
use Common\Model\PluginModel;
use Common\Service\AuthorityMainService;
use Common\Service\AuthorityService;
use Common\Service\PluginService;
class AuthorityAddController extends AbstractController
{
public function index()
{
try {
$authorityMainServ = new AuthorityMainService();
$haveAuthorityServ = new AuthorityService();
$pluginServ = new PluginService();
$authorityMainServ->start_trans();
$haveAuthorityServ->start_trans();
// 写入主表数据
$pluginData = $pluginServ->get_by_conds(['ap_key' => PluginModel::INTEGRAL_CENTER]);
$amId = $authorityMainServ->insert([
'ap_id' => $pluginData['ap_id'],
'visible_range' => AuthorityMainModel::VISIBLE_RANGE_ALL,
'visible_range_type' => $haveAuthorityServ->getRankFilter()
]);
// 拼装写入数据
$insertData = [];
$ids = [];
foreach (I('post.obj_list') as $item) {
$ids[] = $item['authority_id'];
$insertData[] = [
'am_id' => $amId,
'authority_id' => $item['authority_id'],
'authority_id_type' => $item['authority_id_type'],
];
}
// 是否已经存在
if (!empty($ids)) {
$isExist = $haveAuthorityServ->listAuthorityWithVisibleRangeType($ids, $this->getRankFilter());
if (!empty($isExist)) {
E(L('_ERR_DATA_CAN_NOT_REPEAT', ['name' => '可查看权限范围']));
}
}
if (empty($insertData)) {
E('_ERR_EMPTY_POST');
}
// 写入权限对象数据
$haveAuthorityServ->insert_all($insertData);
$authorityMainServ->commit();
$haveAuthorityServ->commit();
} catch (\Exception $e) {
E($e->getCode() . ':' . $e->getMessage());
$authorityMainServ->rollback();
$haveAuthorityServ->rollback();
}
return true;
}
}