InstallController.class.php
2.48 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
<?php
/**
* 应用安装时的消息回调
* User: zhuxun37
* Date: 16/8/11
* Time: 下午3:44
*/
namespace Frontend\Controller\Callback;
use Common\Common\Cache;
use Common\Model\SettingModel;
use Common\Service\AttrService;
use Common\Service\InviteSettingService;
use Common\Service\JobService;
use Common\Service\SettingService;
use VcySDK\Job;
use VcySDK\Role;
use VcySDK\Service;
class InstallController extends AbstractController
{
/**
* 应用状态,可用
*/
const PLUGIN_STATE_AVAILABLE = 1;
/**
* 应用状态,不可用
*/
const PLUGIN_STATE_UNAVAILABLE = 2;
/**
* 安装消息回调
* @return bool
*/
public function Index()
{
$this->Install();
exit('SUCCESS');
}
/**
* 安装应用
* @author zhonglei
*/
public function Install()
{
// 默认数据
$defaultData = \Common\Sql\DefaultData::installData();
// 微信端管理权限配置
$settingService = new SettingService();
if (!$settings = $settingService->get_by_conds(array())) {
foreach ($defaultData['setting'] as $_set) {
$settingService->insert($_set);
}
}
// 邀请函设置写入默认数据
$inviteSettingServ = new InviteSettingService();
$inviteSetting = $inviteSettingServ->get_by_conds([]);
if (!$inviteSetting) {
$inviteSettingServ->insert($defaultData['invite_setting']);
}
// 属性表写入默认数据
$attrService = new AttrService();
$attr = $attrService->get_by_conds([]);
if (!$attr) {
foreach ($defaultData['attr'] as $attr) {
$attrService->insert($attr);
}
}
// 角色、岗位 默认数据
$jobSdk = new Job(Service::instance());
foreach ($defaultData['default_job'] as $name) {
try {
$jobSdk->create(['jobName' => $name]);
} catch (\Exception $e) {
\Think\Log::record('初始化岗位出错:::' . var_export($e->getMessage()));
}
}
$roleSdk = new Role(Service::instance());
foreach ($defaultData['default_role'] as $name) {
try {
$roleSdk->create(['roleName' => $name]);
} catch (\Exception $e) {
\Think\Log::record('初始化角色出错:::' . var_export($e->getMessage()));
}
}
return true;
}
}