DailytaskConfig.class.php
2.55 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
<?php
/**
* Created by PhpStorm.
* User: zhonglei
* Date: 2017/7/27
* Time: 11:21
*/
namespace Common\Common;
use Com\Cache as ComCache;
use Common\Service\DailytaskService;
class DailytaskConfig extends ComCache
{
/**
* 日常任务所有应用
*/
private $_apps = [Constant::APP_SIGN, Constant::APP_WORKMATE, Constant::APP_ANSWER];
/**
* 实例化
* @return DailytaskConfig
*/
public static function &instance()
{
static $instance;
if (empty($instance)) {
$instance = new self();
}
return $instance;
}
/**
* 获取应用设置
* @param string $app 应用
* @return array
*/
private function _getConfig($app)
{
if (empty($app) || !in_array($app, $this->_apps)) {
return [];
}
$taskServ = new DailytaskService();
$config = $taskServ->get_by_conds(['app' => $app]);
if (empty($config)) {
return [
'dailytask_id' => 0,
'app' => $app,
'rules' => [],
'is_open' => Constant::DAILYTASK_IS_OPEN_FALSE,
'update_time' => 0,
];
}
$config['rules'] = empty($config['rules']) ? [] : unserialize($config['rules']);
return $config;
}
/**
* 获取签到设置
* @return array
*/
public function signConfig()
{
return $this->_getConfig(Constant::APP_SIGN);
}
/**
* 获取同事圈设置
* @return array
*/
public function workmateConfig()
{
return $this->_getConfig(Constant::APP_WORKMATE);
}
/**
* 获取问答设置
* @return array
*/
public function answerConfig()
{
return $this->_getConfig(Constant::APP_ANSWER);
}
/**
* 获取缓存数据
* @param string $app 应用
* @return array
*/
public function getCacheData($app)
{
if (empty($app) || !in_array($app, $this->_apps)) {
return [];
}
return $this->get("Common.{$app}Config");
}
/**
* 清除缓存数据
* @param string $app 应用(默认清除所有应用缓存数据)
* @return bool
*/
public function clearCacheData($app = '')
{
if (empty($app) || !in_array($app, $this->_apps)) {
foreach ($this->_apps as $v) {
$this->get("Common.{$v}Config", null);
}
return true;
}
return $this->get("Common.{$app}Config", null);
}
}