InstallController.class.php
3.44 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
<?php
/**
* 套件应用安装初始化数据
* 同事圈
* @author zhoutao
* @date 2017-09-27 10:05:30
*/
namespace Rpc\Controller\Common;
use Common\Service\AttachmentService;
use Common\Service\CircleService;
use Common\Service\SettingService;
use VcySDK\Attach;
use VcySDK\Exception;
use VcySDK\Service;
class InstallController extends AbstractController
{
public function Index()
{
$settingServ = new SettingService();
$count = $settingServ->count();
if (!$count) {
// 默认配置信息
$defaultData = \Common\Sql\DefaultData::installData();
$settingServ->insert_all($defaultData['workmate_config_default']);
// 安装默认数据
$this->default_circle();
}
return true;
}
/**
* 安装默认数据
*
* @return bool
*/
private function default_circle()
{
$circle_serv = new CircleService();
$attach_serv = new AttachmentService();
// 是否已经有默认数据
$default_data = $circle_serv->get_by_conds([]);
if (!$default_data) {
$at_ids = [];
// 上传默认图片
$attach = new Attach(Service::instance());
try {
$picFiles = [
CODE_ROOT . DIRECTORY_SEPARATOR . "www/static/img/workmate/default_1.png",
CODE_ROOT . DIRECTORY_SEPARATOR . "www/static/img/workmate/default_2.png",
CODE_ROOT . DIRECTORY_SEPARATOR . "www/static/img/workmate/default_3.png",
];
foreach ($picFiles as $key => $pic) {
$fileData = [
'file' => [
'name' => QY_DOMAIN . '_default_'. $key .'.png',
'type' => mime_content_type($pic),
'size' => filesize($pic),
'tmp_name' => $pic,
],
];
$result = $attach->upload([
'atMediatype' => Attach::TYPE_IMG,
], $fileData);
$at_ids[] = $result['atId'];
}
} catch (Exception $e) {
\Think\Log::record('setDefaultMedal 方法内错误:::' . $e->getMessage());
} catch (\Exception $e) {
\Think\Log::record('setDefaultMedal 方法内错误:::' . $e->getMessage());
}
if (!empty($at_ids)) {
// 写入默认数据
$cid = $circle_serv->insert([
'username' => '员圈小助手',
'content' => '欢迎来到「员圈」社区,这是企业内部的朋友圈,企业专属的内部论坛,支持发表话题、评论、点赞;在这里可以畅所欲言,碰撞思维,交流工作心得,组织公司活动等。',
'is_attach' => 1,
'audit_state' => 1,
'audit_type' => 1,
'audit_time' => MILLI_TIME,
]);
// 写入附件数据
$attach_data = [];
foreach ($at_ids as $at_id) {
$attach_data[] = [
'cid' => $cid,
'atid' => $at_id,
];
}
$attach_serv->insert_all($attach_data);
}
}
return true;
}
}