DelOldController.class.php
4.86 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
<?php
/**
* 删除指定应用老数据
* Created by PhpStorm.
* User: heyuelong
* Date: 2018年5月9日10:22:36
*/
namespace Apicp\Controller\Attachment;
use Common\Common\AttachOperation;
use Think\Log;
use VcySDK\Exception;
class DelOldController extends AbstractController
{
protected $_require_login = false;
public function Index()
{
// 初始化附件操作类
$attach = AttachOperation::instance();
$app = I('get.app');
// 初始化普通附件IDS
$at_ids = [];
// 初始化视频附件IDS
$video_ids = [];
$destination = C('LOG_PATH') . date('y_m_d') . '.text';
// 本方法根据应用区分不同的方案
switch ($app) {
case 'course':
list($at_ids, $video_ids) = $attach->get_course_at_ids();
Log::write('课程中心__附件IDS:' . print_r($at_ids, true) . '_视频IDS:' . print_r($video_ids, true), 'ERR', '', $destination);
break;
case 'exam':
$at_ids = $attach->get_exam_at_ids();
Log::write('考试中心__附件IDS:' . print_r($at_ids, true), 'ERR', '', $destination);
break;
case 'answer':
$at_ids = $attach->get_answer_at_ids();
Log::write('问答中心__附件IDS:' . print_r($at_ids, true), 'ERR', '', $destination);
break;
case 'doc':
$at_ids = $attach->get_doc_at_ids();
Log::write('资料库__附件IDS:' . print_r($at_ids, true), 'ERR', '', $destination);
break;
case 'live':
$at_ids = $attach->get_live_at_ids();
Log::write('直播__附件IDS:' . print_r($at_ids, true), 'ERR', '', $destination);
break;
case 'news':
list($at_ids, $video_ids) = $attach->get_news_at_ids();
Log::write('新闻公告__附件IDS:' . print_r($at_ids, true) . '_视频IDS:' . print_r($video_ids, true), 'ERR', '', $destination);
break;
case 'workmate':
$at_ids = $attach->get_workmate_at_ids();
Log::write('同事圈__附件IDS:' . print_r($at_ids, true), 'ERR', '', $destination);
break;
case 'activity':
$at_ids = $attach->get_activity_at_ids();
Log::write('活动中心__附件IDS:' . print_r($at_ids, true), 'ERR', '', $destination);
break;
case 'questionnaire':
$at_ids = $attach->get_questionnaire_at_ids();
Log::write('调研中心__附件IDS:' . print_r($at_ids, true), 'ERR', '', $destination);
break;
case 'train':
$at_ids = $attach->get_train_at_ids();
Log::write('线下培训__附件IDS:' . print_r($at_ids, true), 'ERR', '', $destination);
break;
case 'task':
$at_ids = $attach->get_task_at_ids();
Log::write('任务中心__附件IDS:' . print_r($at_ids, true), 'ERR', '', $destination);
break;
case 'integral':
$at_ids = $attach->get_integral_at_ids();
Log::write('积分中心__附件IDS:' . print_r($at_ids, true), 'ERR', '', $destination);
break;
case 'common':
$at_ids = $attach->get_common_at_ids();
Log::write('公共__附件IDS:' . print_r($at_ids, true), 'ERR', '', $destination);
break;
case 'sale':
$at_ids = $attach->get_sale_at_ids();
Log::write('业绩比拼__附件IDS:' . print_r($at_ids, true), 'ERR', '', $destination);
break;
case 'teacher':
$at_ids = $attach->get_teacher_at_ids();
Log::write('企业讲师__附件IDS:' . print_r($at_ids, true), 'ERR', '', $destination);
break;
case 'lottery':
$at_ids = $attach->get_lottery_at_ids();
Log::write('积分抽奖__附件IDS:' . print_r($at_ids, true), 'ERR', '', $destination);
break;
default:
return true;
}
$message = '';
// 如果存在普通附件
if (!empty($at_ids)) {
try {
$attach->deleteFile($at_ids);
} catch (Exception $e) {
$message .= ' 附件IDS: ' . $e->getMessage();
}
}
// 如果存在视频
if (!empty($video_ids)) {
try {
$attach->deleteVideo($video_ids);
} catch (Exception $e) {
$message .= ' 视频IDS:' . $e->getMessage();
}
$this->_result = ['msg' => $message];
return true;
}
}
}