InstallController.class.php
10.4 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
/**
* Created by PhpStorm.
* User: zhonglei
* Date: 17/6/12
* Time: 19:31
*/
namespace Frontend\Controller\Callback;
use Common\Model\CommonRecommenderModel;
use Common\Service\CommonRecommenderService;
use Common\Service\CommonSettingService;
use VcySDK\Attach;
use VcySDK\Service;
class InstallController extends AbstractController
{
/**
* 应用默认数据安装接口
* @author zhonglei
*/
public function Index()
{
// 插入默认数据
$CommonSettingServ = new CommonSettingService();
$CommonSettingServ->setDefaultData();
// 默认栏目数据
$this->setDefaultRecommender();
// 通知员圈其他应用进行数据初始化
$pluginList = [
// 注意: 下面四个的顺序 和 首页推荐顺序有关
'Activity',
'News',
'Exam',
'Course',
'Questionnaire',
'Sign',
'Workmate',
'Assistant',
'Answer',
'Doc',
'Integral',
'Train',
'Task',
'Teacher',
// 存在安装员圈 但没安装通讯录 再点击邀请人员 通讯录相关时 会报错的问题
// 所以这里也去通知通讯录安装
'Contact',
// 新增直播应用数据初始化
'Live'
];
foreach ($pluginList as $plugin) {
try {
$rpc = \Com\Rpc::phprpc(rpcUrl('/' . $plugin . '/Rpc/Common/Install'));
call_user_func([$rpc, 'index']);
} catch (\Exception $e) {
\Think\Log::record('企业 Domain:' . QY_DOMAIN . '应用初始化失败:' . var_export($e, true));
}
}
exit('SUCCESS');
}
/**
* 默认栏目数据
* @return bool
*/
private function setDefaultRecommender()
{
$recommenderServ = new CommonRecommenderService();
$count = $recommenderServ->count_by_conds(['type' => 2]);
if ($count > 0) {
return true;
}
// 需要上传 图标的栏目
$attach = new Attach(Service::instance());
$needUploadLogo = ['Train', 'Questionnaire', 'Activity', 'Workmate', 'News', 'Sign', 'Task', 'Live'];
foreach (
[
[
'name' => '线下培训',
'url' => 'Train/Frontend/Index/List ',
'app_dir' => 'Train',
'attch_id' => '',
'data' => 'a:1:{s:8:"category";a:1:{i:0;a:5:{s:2:"id";s:1:"1";s:4:"name";s:6:"全部";s:4:"upId";s:1:"0";s:3:"url";s:25:"Train/Frontend/Index/List";s:9:"$$hashKey";s:11:"object:1615";}}}',
],
[
'name' => '员圈任务',
'url' => 'Task/Frontend/Index/TaskIndex/Index',
'app_dir' => 'Task',
'attch_id' => '',
'data' => 'a:1:{s:8:"category";a:1:{i:0;a:5:{s:2:"id";s:1:"0";s:4:"name";s:6:"全部";s:4:"upId";s:1:"0";s:3:"url";s:35:"Task/Frontend/Index/TaskIndex/Index";s:9:"$$hashKey";s:10:"object:458";}}}',
],
[
'name' => '培训调研',
'url' => 'Questionnaire/Frontend/Index/List',
'app_dir' => 'Questionnaire',
'attch_id' => '',
'data' => 'a:1:{s:8:"category";a:1:{i:0;a:5:{s:2:"id";s:1:"1";s:4:"name";s:6:"全部";s:4:"upId";s:1:"0";s:3:"url";s:33:"Questionnaire/Frontend/Index/List";s:9:"$$hashKey";s:11:"object:1844";}}}',
],
[
'name' => '员圈活动',
'url' => 'Activity/Frontend/Index/Index',
'app_dir' => 'Activity',
'attch_id' => '',
'data' => 'a:1:{s:8:"category";a:1:{i:0;a:5:{s:2:"id";s:1:"1";s:4:"name";s:6:"全部";s:4:"upId";s:1:"0";s:3:"url";s:29:"Activity/Frontend/Index/Index";s:9:"$$hashKey";s:11:"object:2073";}}}',
],
[
'name' => '积分排行',
'url' => 'Integral/Frontend/Index/IntegralRank/Index',
'app_dir' => 'Integral',
'attch_id' => 'integral',
'data' => 'a:1:{s:8:"category";a:1:{i:0;a:4:{s:2:"id";i:0;s:4:"name";s:6:"全部";s:4:"upId";i:0;s:3:"url";s:42:"Integral/Frontend/Index/IntegralRank/Index";}}}',
],
[
'name' => '签到',
'url' => 'Task/Frontend/Index/SignIndex',
'app_dir' => 'Sign',
'attch_id' => '',
'data' => 'a:1:{s:8:"category";a:1:{i:0;a:5:{s:2:"id";i:1;s:4:"name";s:6:"全部";s:4:"upId";i:0;s:3:"url";s:26:"Task/Frontend/Index/SIndex";s:9:"$$hashKey";s:11:"object:5052";}}}',
],
[
'name' => '员圈',
'url' => 'Workmate/Frontend/Index/Index ',
'app_dir' => 'Workmate',
'attch_id' => '',
'data' => 'a:1:{s:8:"category";a:1:{i:0;a:4:{s:2:"id";i:0;s:4:"name";s:6:"全部";s:4:"upId";i:0;s:3:"url";s:42:"Integral/Frontend/Index/IntegralRank/Index";}}}',
],
[
'name' => '员圈头条',
'url' => 'News/Frontend/Index/NewsList/Index?class_id=0',
'app_dir' => 'News',
'attch_id' => '',
'data' => 'a:1:{s:8:"category";a:1:{i:0;a:5:{s:2:"id";s:1:"0";s:4:"name";s:6:"全部";s:4:"upId";s:1:"0";s:3:"url";s:45:"News/Frontend/Index/NewsList/Index?class_id=0";s:9:"$$hashKey";s:11:"object:1576";}}}',
],
[
'name' => '员圈直播',
'url' => 'Live/Frontend/Index/RoomList/Index',
'app_dir' => 'Live',
'attch_id' => '',
'data' => 'a:1:{s:8:"category";a:1:{i:0;a:4:{s:2:"id";i:0;s:4:"name";s:6:"全部";s:4:"upId";i:0;s:3:"url";s:34:"Live/Frontend/Index/RoomList/Index";}}}',
],
[
'name' => '资料库',
'url' => 'Doc/Frontend/Index/DocIndex/Index',
'app_dir' => 'Doc',
'attch_id' => 'bank',
'data' => 'a:1:{s:8:"category";a:1:{i:0;a:5:{s:2:"id";s:1:"0";s:4:"name";s:6:"全部";s:4:"upId";s:1:"0";s:3:"url";s:33:"Doc/Frontend/Index/DocIndex/Index";s:9:"$$hashKey";s:10:"object:404";}}}',
],
[
'name' => '问答中心',
'url' => 'Answer/Frontend/Index/QuestionList/Index',
'app_dir' => 'Answer',
'attch_id' => 'answer',
'data' => 'a:1:{s:8:"category";a:1:{i:0;a:5:{s:2:"id";s:1:"0";s:4:"name";s:6:"全部";s:4:"upId";s:1:"0";s:3:"url";s:49:"Course/Frontend/Index/CourseList/Index?class_id=0";s:9:"$$hashKey";s:11:"object:1777";}}}',
],
[
'name' => '考试中心',
'url' => 'Exam/Frontend/Index/List',
'app_dir' => 'Exam',
'attch_id' => 'exam',
'data' => 'a:1:{s:8:"category";a:1:{i:0;a:5:{s:2:"id";s:1:"1";s:4:"name";s:6:"全部";s:4:"upId";s:1:"0";s:3:"url";s:24:"Exam/Frontend/Index/List";s:9:"$$hashKey";s:11:"object:1040";}}}',
],
[
'name' => '课程中心',
'url' => 'Course/Frontend/Index/CourseList/Index?class_id=0',
'app_dir' => 'Course',
'attch_id' => 'course',
'data' => 'a:1:{s:8:"category";a:1:{i:0;a:5:{s:2:"id";s:1:"0";s:4:"name";s:6:"全部";s:4:"upId";s:1:"0";s:3:"url";s:49:"Course/Frontend/Index/CourseList/Index?class_id=0";s:9:"$$hashKey";s:10:"object:742";}}}',
],
] as $item
) {
// 上传默认图片 (如果需要)
$result = [];
if (in_array($item['app_dir'], $needUploadLogo)) {
try {
$picFile = CODE_ROOT . DIRECTORY_SEPARATOR . "www/static/img/public/{$item['app_dir']}.png";
$fileData = [
'file' => [
'name' => QY_DOMAIN . "_{$item['app_dir']}.png",
'type' => mime_content_type($picFile),
'size' => filesize($picFile),
'tmp_name' => $picFile,
],
];
$result = $attach->upload([
'atMediatype' => Attach::TYPE_IMG,
], $fileData);
} catch (\Exception $e) {
\Think\Log::record('setDefaultMedal 方法内错误:::' . $e->getMessage());
continue;
}
}
$insertData = [
'type' => CommonRecommenderModel::TYPE_ICON,
'displayorder' => CommonRecommenderModel::VALUE_DISPLAYORDER_MIN,
'hide' => CommonRecommenderModel::HIDE_NO,
'system' => CommonRecommenderModel::SYSTEM_NO,
'title' => $item['name'],
'attach_id' => empty($item['attch_id']) ? $result['atId'] : $item['attch_id'],
'pic' => empty($item['attch_id']) ? $result['atAttachment'] : $item['attch_id'],
'url' => $item['url'],
'description' => '',
'app_dir' => $item['app_dir'],
// TODO 2017-10-24 20:13:17 zhoutao 这里写死以后要注意到 如果应用标识变了 这里做好做成动态的
'app_identifier' => 'yuanquan',
'data_id' => '',
'data_category_id' => 0,
'data' => $item['data'],
'dateline' => MILLI_TIME,
'adminer_id' => '',
'adminer' => '',
];
// 特殊要求: displayorder 字段更新为主键 ID 值
try {
$id = $recommenderServ->insert($insertData);
$recommenderServ->update($id, ['displayorder' => $id]);
} catch (\Exception $e) {
\Think\Log::record('写入栏目默认数据出错:::' . var_export($e, true));
}
}
return true;
}
}