<?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; } } }