IndexController.class.php
2.29 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
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 18/6/21
* Time: 17:08
*/
namespace Frontend\Controller\UpdateDB;
use Think\Db;
class IndexController extends AbstractController
{
/**
* 数据库升级脚本
* 1、新增人员属性:英文名、上级,为旧数据写入默认数据;
* @author liyifei
* @return string
*/
public function Index()
{
$db = &Db::getInstance();
// 所有企业
$all_domain = $db->query("SELECT DISTINCT `domain` FROM `oa_contact_attr` WHERE `status` < 3");
$all_domain = array_column($all_domain, 'domain');
// 删除已写入的默认数据
try {
$db->query("DELETE FROM `oa_contact_attr` WHERE `field_name` IN ('memEnglishName', 'memIsleader') AND `status` < 3");
} catch (\Exception $e) {
// exit("数据库升级失败:" . $e->getMessage());
}
// 为所有企业写入默认数据
$content = '';
$times = MILLI_TIME;
$sql = "INSERT INTO `oa_contact_attr` (`field_name`, `attr_name`, `postion`, `type`, `option`, `order`, `is_system`, `is_open`, `is_open_edit`, `is_required`, `is_required_edit`, `is_open_cp`, `is_open_cp_edit`, `is_required_cp`, `is_required_cp_edit`, `is_show`, `is_show_edit`, `is_allow_user_modify`, `is_allow_user_modify_edit`, `domain`, `created`) VALUES ";
$option = serialize(
[
[
'name' => '是',
'value' => 1
],
[
'name' => '否',
'value' => 0
]
]
);
foreach ($all_domain as $domain) {
$content .= "('memEnglishName', '英文名', 1, 1, '', 10, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, '{$domain}', {$times}), ('memIsleader', '上级', 1, 7, '{$option}', 10, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, '{$domain}', {$times}),";
}
// 执行sql,写入"培训阶段"数据
if (!empty($content)) {
$sql .= substr($content, 0, -1) . ';';
try {
$db->query($sql);
} catch (\Exception $e) {
// exit("数据库升级失败:" . $e->getMessage());
}
}
exit('SUCCESS');
}
}