UserActionLogic.php
2.6 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
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\user\logic;
use think\Db;
class UserActionLogic
{
/**
* 导入应用用户行为
* @param $app
* @return array
* @throws \ReflectionException
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public static function importUserActions($app)
{
$userActionConfigFile = cmf_get_app_config_file($app, 'user_action');
if (file_exists($userActionConfigFile)) {
$userActionsInFile = include $userActionConfigFile;
foreach ($userActionsInFile as $userActionKey => $userAction) {
$userAction['cycle_type'] = empty($userAction['cycle_type']) ? 0 : $userAction['cycle_type'];
if (!in_array($userAction['cycle_type'], [0, 1, 2, 3])) {
$userAction['cycle_type'] = 0;
}
if (!empty($userAction['url']) && is_array($userAction['url']) && !empty($userAction['url']['action'])) {
$userAction['url'] = json_encode($userAction['url']);
} else {
$userAction['url'] = '';
}
$findUserAction = Db::name('user_action')->where('action', $userActionKey)->count();
$userAction['app'] = $app;
if ($findUserAction > 0) {
Db::name('user_action')->where('action', $userActionKey)
->strict(false)->field(true)
->update([
'name' => $userAction['name'],
'url' => $userAction['url']
]);
} else {
$userAction['action'] = $userActionKey;
Db::name('user_action')->strict(false)
->field(true)
->insert($userAction);
}
}
}
}
}