InstallController.class.php
7 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
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 17/6/13
* Time: 18:13
*/
namespace Rpc\Controller\Common;
use Think\Db;
use Think\Log;
class InstallController extends AbstractController
{
/**
* 是否必须登录
*/
protected $_require_login = false;
private $qyDomain = QY_DOMAIN;
private $nowTime = MILLI_TIME;
/**
* 应用默认数据安装接口
* @author tangxingguo
*/
public function Index()
{
Log::record('---Add Answer qyDomain info:' . QY_DOMAIN , Log::INFO);
// 添加问题
$this->_addQuestion();
// 添加回答
$this->_addAnswer();
}
/**
* 执行sql语句
* @author tangxingguo
* @param $sql
*/
private function _exeSql($sql)
{
if (empty($sql)) {
return;
}
$db = &Db::getInstance();
try {
$db->query($sql);
} catch (\Exception $e) {
}
}
/**
* 默认分类数据
* @author tangxingguo
* @return string
*/
private function _addClass()
{
// 兼容多次操作
$db = &Db::getInstance();
$classSql = "select * from `oa_answer_class` WHERE `domain` = '{$this->qyDomain}' and `status` < 3";
$classInfo = $db->query($classSql);
if (!empty($classInfo)) {
return;
}
// 默认分类数据
$defaultClass = [
[
'class_name' => '管理常识',
'description' => '',
'manager_id' => '',
'manager_name' => '',
'order' => -1,
'domain' => $this->qyDomain,
'status' => 1,
'created' => $this->nowTime,
],
[
'class_name' => '职业技能',
'description' => '',
],
[
'class_name' => '办公效率',
'description' => '',
],
[
'class_name' => '市场营销',
'description' => '',
],
[
'class_name' => '职业发展',
'description' => '',
],
];
// sql
$sql = "INSERT INTO `oa_course_class` (`class_name`, `description`, `manager_id`, `manager_name`, `order`, `domain`, `status`, `created`) VALUES ";
foreach ($defaultClass as $k => $v) {
$sql .= "('{$v['class_name']}', '{$v['description']}', '{$v['manager_id']}', '{$v['manager_name']}', '{$v['order']}', '{$this->qyDomain}', 1, '{$this->nowTime}')";
if (end($defaultClass) == $v) {
$sql .= ";";
} else {
$sql .= ",";
}
}
$this->_exeSql($sql);
}
// 添加问题
private function _addQuestion()
{
// 兼容多次操作
$db = &Db::getInstance();
$questionSql = "select * from `oa_answer_question` WHERE `domain` = '{$this->qyDomain}' and `status` < 3";
$questionInfo = $db->query($questionSql);
if (!empty($questionInfo)) {
return;
}
// 提问数据
$defaultData = [
'class_id' => 0,
'uid' => '',
'username' => '员圈小助手',
'checker_type' => 2,
'checker_uid' => '',
'checker_name' => '员圈小助手',
'question_title' => '问答中心有什么作用呢?',
'description' => '请按照使用场景和用途分别进行描述。',
'integral' => 0,
'is_solve' => 2,
'answer_wait_total' => 0,
'answer_pass_total' => 1,
'check_time' => $this->nowTime,
'check_status' => 2,
'domain' => $this->qyDomain,
'status' => 1,
'created' => $this->nowTime,
];
$sql = $this->_formatInsert('oa_answer_question', $defaultData);
$this->_exeSql($sql);
}
// 添加回答
private function _addAnswer()
{
// 兼容多次操作
$db = &Db::getInstance();
$answerSql = "select * from `oa_answer_answer` WHERE `domain` = '{$this->qyDomain}' and `status` < 3";
$answerInfo = $db->query($answerSql);
if (!empty($answerInfo)) {
return;
}
// 提问信息
$db = &Db::getInstance();
$questionSql = "select * from `oa_answer_question` WHERE `username` = '员圈小助手' and `domain` = '{$this->qyDomain}' and `status` < 3";
$questionInfo = $db->query($questionSql);
if (empty($questionInfo)) {
Log::record('---Add Answer fail info:没有找到提问数据', Log::ERR);
return;
}
// 回答数据
$data = [
'question_id' => $questionInfo[0]['question_id'],
'class_id' => 0,
'user_type' => 2,
'uid' => '',
'username' => '员圈小助手',
'checker_type' => 2,
'checker_uid' => '',
'checker_name' => '员圈小助手',
'answer_content' => '问答中心可以帮助企业搭建一个移动化的互动问答社区。<br />(1)其使用场景在于:当员工在工作/学习中遇到问题时,可以自行在问答中心来发起提问,可设置一定的悬赏积分,来激励其他员工进行解答。<br />(2)用途上来说:通过问答中心,企业可以充分发挥员工的积极性,将工作中常见的问题进行沉淀,也可以挖掘优秀的员工,通过这种互动的方式来提供员工学习的积极性。员工可以通过问答的形式获得帮助,有一个渠道来解决自身遇到的问题,可以提高自己的业务水平。',
'is_best' => 2,
'like_total' => 0,
'check_time' => $this->nowTime,
'check_status' => 2,
'domain' => $this->qyDomain,
'status' => 1,
'created' => $this->nowTime,
];
$sql = $this->_formatInsert('oa_answer_answer', $data);
$this->_exeSql($sql);
}
/**
* 根据数组数据格式化为添加sql语句
* @author tangxingguo
* @param string $tableName 表名
* @param array $data 数据
* @return string|void
*/
private function _formatInsert($tableName, $data)
{
if (empty($data) && !is_array($data)) {
return;
}
// 拼接sql
$sql = "INSERT INTO `{$tableName}` ";
$keys = "(";
$values = "(";
foreach ($data as $k => $v) {
if (array_slice($data, -1, 1) == [$k => $v]) {
$symbol = "";
} else {
$symbol = ",";
}
$keys .= "`{$k}`{$symbol} ";
if (is_numeric($v)) {
$values .= "{$v}{$symbol} ";
} else {
$values .= "'{$v}'{$symbol} ";
}
}
$keys .= ") VALUES ";
$values .= ");";
$sql .= $keys . $values;
return $sql;
}
}