InstallController.class.php
4.87 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
<?php
/**
* 应用安装时的消息回调
* User: zhuxun37
* Date: 16/8/11
* Time: 下午3:44
*/
namespace Frontend\Controller\Callback;
use Common\Service\BaseinfoService;
use Common\Service\ClassifyService;
use Think\Log;
class InstallController extends AbstractController
{
/** @var BaseinfoService */
protected $base_info;
public function __construct()
{
parent::__construct();
// 实例化调研基础信息表
$this->base_info = new BaseinfoService();
}
/**
* 安装消息回调
*
* $this->callBackData 格式如下:
* {
* "epId":"B646C6F67F0000017D3965FCF2FD3A2F",
* "plPluginid":"D194A216C0A8C7BD2C339C03334A40EE",
* "thirdIdentifier":"QY",
* "eplAvailable":1,
* "epEnumber":"local",
* "qysSuiteid":"tj371afbea374f01b2",
* "flag":false,
* "corpid": "wxac606454f473e98f",
* "url":"http://thr.vchangyi.com/local/Contact/Frontend/Callback/Install"
* }
*
* @return bool
*/
public function Index()
{
Log::record(sprintf('---%s %s INSTALL START---', QY_DOMAIN, APP_IDENTIFIER), Log::INFO);
Log::record(var_export($this->callBackData, true), Log::INFO);
Log::record(sprintf('---%s %s INSTALL END ---', QY_DOMAIN, APP_IDENTIFIER), Log::INFO);
$this->Install();
exit('SUCCESS');
}
/**
* 安装应用
* @author liyifei
* @return void
*/
public function Install()
{
$this->setDefaultCate();
exit('SUCCESS');
}
/**
* 卸载应用
* @author zhonglei
* @return void
*/
public function Uninstall()
{
}
protected function setDefaultCate()
{
// 查询是否存在默认分类
$cateServ = new ClassifyService();
$count = $cateServ->count_by_conds(array('is_system' => 1));
if ($count > 0) {
return;
}
// 如果不存在默认分类,则插入默认分类数据
$DefaultCate = \Common\Sql\DefaultData::installData();
$cateServ->insert($DefaultCate);
}
/**
* 应用数据库数据更新升级【v3.0.0】
*
* @author daijun
*
* @return void
*/
public function UpdateDBv3()
{
set_time_limit(0);
ini_set("memory_limit", "1128M");
$sql = array();
// 调研基础信息表
$pes = $this->base_info->query("SHOW FIELDS FROM oa_questionnaire_baseinfo ");
$field = array_column($pes, 'field');
if (!in_array('integral_action_type', $field)) {
// 新增策略类型字段
$sql[] = "ALTER TABLE oa_questionnaire_baseinfo add integral_action_type TINYINT(3) UNSIGNED NOT NULL DEFAULT '1' COMMENT '积分策略(1:启用默认,2:不启用,3:启用自定义策略)' AFTER `remind_crid`";
}
if (!in_array('integral_strategyid', $field)) {
// 新增策略id字段
$sql[] = "ALTER TABLE oa_questionnaire_baseinfo add integral_strategyid varchar(255) NOT NULL DEFAULT '' COMMENT '积分策略ID集合(序列化存储)' AFTER `remind_crid`";
}
$pes_a = $this->base_info->query("SHOW FIELDS FROM oa_questionnaire_answer ");
$field_a = array_column($pes_a, 'field');
if (!in_array('integral_strategyid', $field_a)) {
// 新增积分策略ID
$sql[] = "ALTER TABLE `oa_questionnaire_answer` ADD `businessid` VARCHAR(100) NOT null DEFAULT '' COMMENT '积分策略ID' AFTER `username`;";
}
// 新增用户参与调研次数统计表
$sql[] = "CREATE TABLE IF NOT EXISTS `oa_questionnaire_count` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
`uid` CHAR(32) NOT NULL DEFAULT '' COMMENT '用户ID',
`num` INT(10) NOT NULL DEFAULT '0' COMMENT '参加次数',
`domain` VARCHAR(32) NOT NULL DEFAULT '' COMMENT '企业域名',
`status` TINYINT(3) NOT NULL DEFAULT '1' COMMENT '状态=1.初始化,2.更新,3删除',
`created` BIGINT(13) NOT NULL DEFAULT '0' COMMENT '创建时间',
`updated` BIGINT(13) NOT NULL DEFAULT '0' COMMENT '更新时间',
`deleted` BIGINT(13) NOT NULL DEFAULT '0' COMMENT '删除时间',
PRIMARY KEY (`id`),
KEY `domain_status` (`domain`,`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户参加调研次数统计表';";
if (!empty($sql)) {
// 循环执行sql更新语句
foreach ($sql as $key => $value) {
$this->base_info->execute($value);
}
}
exit('SUCCESS');
}
}