0, "message" => "缺少参数")); exit(); } if (!in_array($type, array(1, 2, 3))) { echo json_encode(array("success" => 0, "message" => "参数错误[1]")); exit(); } $groupInfo = Exam::model()->getGroupInfo($examId); if (empty($groupInfo)) exit(json_encode(array("success" => 0, "message" => "考试信息错误"))); $typeRel = array('1' => 'wb_group_id', '2' => 'isp_group_id', '3' => 'wbisp_group_id'); $groupId = $groupInfo[$typeRel[$type]]; if (!empty($groupId)) { $apiUrl = isset(Yii::app()->params["improve_url"][$groupId]) ? Yii::app()->params["improve_url"][$groupId] : null; } else { $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; } if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $params = array( "schoolId" => $this->schoolId, "examId" => $examId, "classId" => $classId, "type" => $type, "studentIds" => array(), ); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $classId)); $Sem = new SSemester(); $code = $Sem->conn->createQuery()->from('semester')->where("semester_id = '" . $classinfo['semester_id'] . "'") ->limit(1) ->query() ->read(); $print_time = ClassExamPrinter::model()->findAll('exam_id=:exam_id and class_id=:classid and type=0', array(':exam_id' => $examId, ':classid' => $classId)); $intarr = array( "schoolId" => $this->schoolId, "clazzId" => $classId, "semester" => $code['refer_code'], "grade" => $classinfo['grade'], "students" => array(), "examTime" => $print_time[0]->add_time, "classify" => $type, ); //判断学科 $examInfo = Exam::model()->findByPk($examId); $intarr['subject'] = $examInfo['subject_id']; if (in_array($intarr['subject'], $this->mathSubjectId)) { $intarr['subject'] = 3; } if ($type == 1) { $productName = $examInfo->name . '"错题本"'; $pdfPathColumn = 'wrongbook_pdf_path'; $isGenerateColumn = 'is_wrongbook_pdf'; $isDownloadColumn = 'is_wrongbook_download'; $downloadTimeCoulmn = 'download_wrongbook_time'; } elseif ($type == 2) { $productName = $examInfo->name . '"个性化学习方案"'; $pdfPathColumn = 'isp_pdf_path'; $isGenerateColumn = 'is_isp_pdf'; $isDownloadColumn = 'is_two_isp_download'; $downloadTimeCoulmn = 'download_two_isp_time'; } else { $productName = $examInfo->name . '"个性化学习宝"'; $pdfPathColumn = 'wbisp_pdf_path'; $isGenerateColumn = 'is_wbisp_pdf'; $isDownloadColumn = 'is_three_isp_download'; $downloadTimeCoulmn = 'download_three_isp_time'; } $productDownload = new ProductDownload($type); //*****获取生成的学生***// $generateStu = $productDownload->getGenerateStu('student_paper_relation', 'exam_id', $pdfPathColumn, $isGenerateColumn, $examId, $studentsIds, $absentFilter); if(!$generateStu){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } $params['studentIds'] = $generateStu['studentIds']; $pathArr = $generateStu['pathArr']; if ($printType == 'third_isp') { $params["subjectId"] = 8; $params["type"] = 3; } if (Yii::app()->params["limit_open"]) { $params["studentIds"] = $productDownload->getCanDownloadStu($generateStu['studentIds'], $intarr, $this->schoolId); } ProductProcessTime::model()->updateDownloadTime($params["studentIds"],$type,$examId); //**************** Step-2 判断是否已经存在下载任务 ********************// if ($classDownload) { $packTask = $this->getExistTask($examId, $classId, $type, count($params['studentIds'])); if (isset($packTask->pack_status) && $packTask->pack_status == 0) { echo json_encode(array("success" => 3, "message" => "")); exit; } if (isset($packTask->pack_url) && $packTask->pack_url) { if($this->updateIspDownloadStatus($params["studentIds"],$classId,$examId,$isDownloadColumn,$downloadTimeCoulmn) !== false){ ProductProcessTime::model()->updateDownloadTime($params["studentIds"],$type,$examId); } echo json_encode(array("success" => 1, "downloadPath" => $packTask->pack_url)); exit; } } //**************** Step-3 根据接口获取文件大小来判断走原有接口打包流程还是走脚本任务 ************// $sizeRs = Curl::post($apiUrl . "/rest/download_file_size/index", array('path_arr' => $pathArr)); if (!($sizeRs = json_decode($sizeRs))) { echo json_encode(array("success" => 0, "downloadPath" => '请求接口失败')); exit; } if (isset($sizeRs->size)) { //************ Step-3-1 大于限定值 发送任务到后台打包 ******// if (Yii::app()->params["pack_product_file_limit"] < $sizeRs->size) { $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = $type; $packProductModel->product_name = $productName; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $classId; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $examId; $packProductModel->student_count = count($params["studentIds"]); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateIspDownloadStatus($params["studentIds"],$classId,$examId,$isDownloadColumn,$downloadTimeCoulmn); echo json_encode(array("success" => 3, "message" => "")); exit; } else { //************ Step-3-2 小于限定值 原有接口流程 ******// $rs = Curl::post($apiUrl . "/rest/download_pdf/index", $params); if (!($rs = json_decode($rs))) { $rs = array("success" => 0, "message" => "请求接口失败",); } if ($printType != 'third_wb') { if ($rs->success != 0) { $rs->success = 2; } } if (isset($rs->downloadPath)) { if($this->updateIspDownloadStatus($params["studentIds"],$classId,$examId,$isDownloadColumn,$downloadTimeCoulmn) !== false){ ProductProcessTime::model()->updateDownloadTime($params["studentIds"],$type,$examId); } } if ($groupId && isset($rs->downloadPath)) { if (YII_ENV == 'pro' || YII_ENV == 'production') { $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/', 'http://zstatic' . $groupId, $rs->downloadPath); } } echo json_encode($rs); exit; } } else { echo json_encode(array("success" => 0, "message" => $sizeRs->message)); exit; } } /** * 更新个性化学习宝下载状态 * @param array $studentIds * @param $classId * @param $examId * @param $isDownloadColumn * @param $downloadTimeCoulmn * @return mixed */ private function updateIspDownloadStatus($studentIds=array(), $classId, $examId, $isDownloadColumn, $downloadTimeCoulmn) { $criteria = new CDbCriteria(); if ($studentIds) { $criteria->addInCondition('student_id', $studentIds); } else { $criteria->addCondition('(is_complete = :is_complete and is_feedback = :is_complete) or is_del = :is_complete '); $criteria->params[':is_complete'] = 1; $criteria->params[':is_feedback'] = 1; $criteria->params[':is_del'] = 1; } $criteria->addCondition('class_id=:class_id'); $criteria->params[':class_id'] = $classId; $criteria->addCondition('exam_id=:exam_id'); $criteria->addCondition("{$isDownloadColumn}=:is_download"); $criteria->params[':exam_id'] = $examId; $criteria->params[':is_download'] = 0; return SStudentPaperRelation::model()->updateAll(array($isDownloadColumn => 1, $downloadTimeCoulmn => time()), $criteria); } //添加错题本/两步/三步提分下载任务 public function actionAddIspTask() { $examId = Req::get("examId"); $classId = Req::get("classId"); $type = Req::get("type"); $studentsIds = Req::get("studentsIds"); $printType = Req::get("printType"); $absentFilter = Req::get("absent_filter"); if (!$examId || !$classId || !$type) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } if (!in_array($type, array(1, 2, 3))) { echo json_encode(array("success" => 0, "message" => "参数错误[1]")); exit(); } $groupInfo = Exam::model()->getGroupInfo($examId); if (empty($groupInfo)) exit(json_encode(array("success" => 0, "message" => "考试信息错误"))); $typeRel = array('1' => 'wb_group_id', '2' => 'isp_group_id', '3' => 'wbisp_group_id'); $groupId = $groupInfo[$typeRel[$type]]; if (!empty($groupId)) { $apiUrl = isset(Yii::app()->params["improve_url"][$groupId]) ? Yii::app()->params["improve_url"][$groupId] : null; } else { $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; } if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $params = array( "schoolId" => $this->schoolId, "examId" => $examId, "classId" => $classId, "type" => $type, "studentIds" => array(), ); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $classId)); $Sem = new SSemester(); $code = $Sem->conn->createQuery()->from('semester')->where("semester_id = '" . $classinfo['semester_id'] . "'") ->limit(1) ->query() ->read(); $print_time = ClassExamPrinter::model()->findAll('exam_id=:exam_id and class_id=:classid and type=0', array(':exam_id' => $examId, ':classid' => $classId)); $intarr = array( "schoolId" => $this->schoolId, "clazzId" => $classId, "semester" => $code['refer_code'], "grade" => $classinfo['grade'], "students" => array(), "examTime" => $print_time[0]->add_time, "classify" => $type, ); //判断学科 $examInfo = Exam::model()->findByPk($examId); $intarr['subject'] = $examInfo['subject_id']; if (in_array($intarr['subject'], $this->mathSubjectId)) { $intarr['subject'] = 3; } if ($type == 1) { $productName = $examInfo->name . '"错题本"'; $pdfPathColumn = 'wrongbook_pdf_path'; $isGenerateColumn = 'is_wrongbook_pdf'; $isDownloadColumn = 'is_wrongbook_download'; $downloadTimeCoulmn = 'download_wrongbook_time'; } elseif ($type == 2) { $productName = $examInfo->name . '"个性化学习方案"'; $pdfPathColumn = 'isp_pdf_path'; $isGenerateColumn = 'is_isp_pdf'; $isDownloadColumn = 'is_two_isp_download'; $downloadTimeCoulmn = 'download_two_isp_time'; } else { $productName = $examInfo->name . '"个性化学习宝"'; $pdfPathColumn = 'wbisp_pdf_path'; $isGenerateColumn = 'is_wbisp_pdf'; $isDownloadColumn = 'is_three_isp_download'; $downloadTimeCoulmn = 'download_three_isp_time'; } $productDoanload = new ProductDownload($type); //*****获取生成的学生***// $generateStu = $productDoanload->getGenerateStu('student_paper_relation', 'exam_id', $pdfPathColumn, $isGenerateColumn, $examId, $studentsIds, $absentFilter); if(!$generateStu){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } $params['studentIds'] = $generateStu['studentIds']; if ($printType == 'third_isp') { $params["subjectId"] = 8; $params["type"] = 3; } if (Yii::app()->params["limit_open"]) { $params["studentIds"] = $productDoanload->getCanDownloadStu($generateStu['studentIds'], $intarr, $this->schoolId); } $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = $type; $packProductModel->product_name = $productName; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $classId; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $examId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); if($this->updateIspDownloadStatus($params["studentIds"],$classId,$examId,$isDownloadColumn,$downloadTimeCoulmn) !== false){ ProductProcessTime::model()->updateDownloadTime($params["studentIds"],$type,$examId); } echo json_encode(array("success" => 3, "message" => "")); exit; } //阶段复习个性化学习宝下载 public function actionDownload_student_product() { $classId = Req::get("classId"); $type = Req::get("type"); $studentsIds = Req::get("studentsIds"); $classDownload = $studentsIds ? false : true; if (!$classId || !$type) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } if (!in_array($type, array(1, 2, 3))) { echo json_encode(array("success" => 0, "message" => "参数错误[1]")); exit(); } $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $classId)); $student_class_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status', array(':class_id' => $classId, ':status' => 0)); if ($student_class_data) { if (!$studentsIds) { $studentsIds = array(); foreach ($student_class_data as $v) { $studentsIds[] = $v->student_id; } } }else{ echo json_encode(array("success" => 0, "message" => "班级暂无学生")); exit; } if(in_array($this->subjectId,$this->mathSubjectId)){ $subjectId=3; }else{ $subjectId=$this->subjectId; } $params = array( "schoolId" => $this->schoolId, "classId" => $classId, "type" => $type, 'subjectId'=>$subjectId ); if ($studentsIds) { if (!is_array($studentsIds)) { $studentsIds = explode(',', $studentsIds); } $stuids = array(); if (Yii::app()->params["limit_open"]) { $semester = new SSemester(); $nowsem = $semester->getCurrentSemester(); $intarr = array( "schoolId" => $this->schoolId, "clazzId" => $classId, "semester" => $nowsem['refer_code'], "grade" => $classinfo['grade'], "examTime" => time(), "classify" => 1, "subject" => $subjectId, "students" => $studentsIds ); $this->getStuOrder($intarr, $stuids); } else { $stuids = $studentsIds; } if (!$stuids) { echo json_encode(array("success" => 0, "message" => "所选的学生没有下载权限")); exit; } $params['studentIds'] = $stuids; $_students = array(); if ($params["studentIds"]) { $_students = $params["studentIds"]; } $_student_product_data=SStudentProductModel::model()->getStudentCreate($_students,$subjectId,$type,$this->semesterId); if (!$_student_product_data) { echo json_encode(array("success" => 0, "message" => "所选的学生尚未生成PDF")); exit; } } $planId=SStudentProductModel::model()->getPlanId($classId,$subjectId,$type); $params['planId']=$planId; //**************** Step-2 判断是否已经存在下载任务 ********************// if ($classDownload) { $packTask = $this->getExistTask($this->semesterId . '_' . $type, $classId, ProductDownload::PRODUCT_TYPE_STAGE_REVIEW, count($studentsIds)); if (isset($packTask->pack_status) && $packTask->pack_status == 0) { echo json_encode(array("success" => 3, "message" => "")); exit; } if (isset($packTask->pack_url) && $packTask->pack_url) { $this->updateSpDownloadStatus($params['studentIds'],$type,$planId); echo json_encode(array("success" => 1, "downloadPath" => $packTask->pack_url)); exit; } } //**************** Step-3 根据接口获取文件大小来判断走原有接口打包流程还是走脚本任务 ************// $pathArr = array(); if (isset($_student_product_data)) { foreach ($_student_product_data as $item) { $pathArr[] = $item['pdf_path']; } } $sizeRs = Curl::post($apiUrl . "/rest/download_file_size/index", array('path_arr' => $pathArr)); if (!($sizeRs = json_decode($sizeRs))) { echo json_encode(array("success" => 0, "message" => "请求接口失败")); exit; } if (isset($sizeRs->size)) { //************ Step-3-1 大于限定值 发送任务到后台打包 ******// if (Yii::app()->params["pack_product_file_limit"] < $sizeRs->size) { $semesterName = isset($nowsem->semester_name) ? $nowsem->semester_name : ''; if ($type == 1) { $productName = $semesterName . '"期中阶段复习个性化学习宝"'; } elseif ($type == 2) { $productName = $semesterName . '"期末阶段复习个性化学习宝"'; } else { $productName = $semesterName . '"总复习个性化学习宝"'; } $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_STAGE_REVIEW; $packProductModel->product_name = $productName; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $classId; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $this->semesterId . '_' . $type; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_sp/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateSpDownloadStatus($params['studentIds'],$type,$planId); echo json_encode(array("success" => 3, "message" => "")); exit; } else { //************ Step-3-2 小于限定值 走原有api流程 ******// $rs = Curl::post($apiUrl . "/rest/download_sp/index", $params); if (!($rs = json_decode($rs))) { echo json_encode(array("success" => 0, "message" => "请求接口失败")); exit; } if ($rs->success != 0) { $rs->success = 2; $rs->limitinfo = '全班允许下载'; } if ($params["studentIds"] && ($rs->success == 1 || $rs->success == 2)) { $this->updateSpDownloadStatus($params['studentIds'],$type,$planId); } echo json_encode($rs); exit; } } else { echo json_encode(array("success" => 0, "message" => $sizeRs->message)); exit; } } /** * 更新阶段复习个性化学习宝下载状态 * @param $studentIds * @param $type */ private function updateSpDownloadStatus($studentIds, $type,$planId) { $criteria = new CDbCriteria(); $criteria->addInCondition('student_id', $studentIds); $criteria->addCondition('type=:type'); $criteria->addCondition('plan_id=:pid'); $criteria->params[':type'] = $type; $criteria->params[':pid'] = $planId; SStudentProductModel::model()->updateAll(array('is_download' => 1, 'download_time' => time()), $criteria); } //添加阶段复习个性化学习宝下载任务 public function actionAddSpTask() { $classId = Req::get("classId"); $type = Req::get("type"); $studentsIds = Req::get("studentsIds"); if (!$classId || !$type) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } if (!in_array($type, array(1, 2, 3))) { echo json_encode(array("success" => 0, "message" => "参数错误[1]")); exit(); } $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $params = array( "schoolId" => $this->schoolId, "classId" => $classId, "type" => $type, ); $student_class_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status', array(':class_id' => $classId, ':status' => 0)); if ($student_class_data) { if (!$studentsIds) { $studentsIds = array(); foreach ($student_class_data as $v) { $studentsIds[] = $v->student_id; } } } else { echo json_encode(array("success" => 0, "message" => "班级暂无学生")); exit; } $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $classId)); if ($studentsIds) { if (!is_array($studentsIds)) { $studentsIds = explode(',', $studentsIds); } $stuids = array(); if (Yii::app()->params["limit_open"]) { $semester = new SSemester(); $nowsem = $semester->getCurrentSemester(); $intarr = array( "schoolId" => $this->schoolId, "clazzId" => $classId, "semester" => $nowsem['refer_code'], "grade" => $classinfo['grade'], "examTime" => time(), "classify" => 1, "subject" => 3, "students" => $studentsIds ); $this->getStuOrder($intarr, $stuids); } else { $stuids = $studentsIds; } if (!$stuids) { echo json_encode(array("success" => 0, "message" => "所选的学生没有下载权限")); exit; } $params['studentIds'] = $stuids; $criteria = new CDbCriteria(); $_students = array(); if ($params["studentIds"]) { $_students = $params["studentIds"]; } $criteria->addInCondition('student_id',$_students); $criteria->addCondition('semester_id=:semester_id'); $criteria->addCondition('type=:type'); $criteria->addCondition('is_pdf_created=:is_pdf_created'); $criteria->params[':semester_id'] = $this->semesterId; $criteria->params[':type'] = $type; $criteria->params[':is_pdf_created'] = 1; $_student_product_data = SStudentProductModel::model()->findAll($criteria); if (!$_student_product_data) { echo json_encode(array("success" => 0, "message" => "所选的学生尚未生成PDF")); exit; } } $semesterName = isset($nowsem->semester_name) ? $nowsem->semester_name : ''; if ($type == 1) { $productName = $semesterName . '"期中阶段复习个性化学习宝"'; } elseif ($type == 2) { $productName = $semesterName . '"期末阶段复习个性化学习宝"'; } else { $productName = $semesterName . '"总复习个性化学习宝"'; } $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_STAGE_REVIEW; $packProductModel->product_name = $productName; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $classId; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $this->semesterId . '_' . $type; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_sp/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateSpDownloadStatus($params['studentIds'],$type); echo json_encode(array("success" => 3, "message" => "")); exit; } /** * 下载二轮复习个性化提分手册 */ public function actionGetMathReviewFile() { $mrId = (string)Req::get("mrId"); $studentsIds = Req::get("studentsIds"); $classDownload = $studentsIds ? false : true; $params = array(); if (!$mrId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } //*****获取生成的学生***// $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_SECOND_RUN); $generateStu = $productDownload->getGenerateStu('math_review_student', 'mr_id', 'review_pdf_path', 'is_review_pdf', $mrId, $studentsIds); if(!$generateStu){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } $params['studentIds'] = $generateStu['studentIds']; $pathArr = $generateStu['pathArr']; $params['mrId'] = $mrId; $sql = "select class_id,grade,create_time,semester_id,school_group_id,`name` from math_review_setting where mr_id = '{$mrId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $Sem = new SSemester(); $code = $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '" . $msg['semester_id'] . "'") ->limit(1) ->query() ->read(); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); $intarr = array( "schoolId" => $this->schoolId, "clazzId" => $msg['class_id'], "semester" => $code['refer_code'], "grade" => $msg['grade'], "students" => $studentsIds, "examTime" => $msg['create_time'], "classify" => 5, "subject" => 3 ); if (isset($msg['school_group_id']) && $msg['school_group_id']) { $apiUrl = isset(Yii::app()->params["improve_url"][$msg['school_group_id']]) ? Yii::app()->params["improve_url"][$msg['school_group_id']] : null; } else { $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; } if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } //************ Step-1 判断是否有订单 *************// if (Yii::app()->params["limit_open"]) { if (Yii::app()->params["limit_open"]) { $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId); } } $params['schoolId'] = $this->schoolId; $params['type'] = 1; //**************** Step-2 判断是否已经存在下载任务 ********************// if ($classDownload) { $packTask = $this->getExistTask($mrId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_SECOND_RUN, count($params["studentIds"])); if (isset($packTask->pack_status) && $packTask->pack_status == 0) { echo json_encode(array("success" => 3, "message" => "")); exit; } if (isset($packTask->pack_url) && $packTask->pack_url) { $this->updateSecondRunDownloadStatus($params['studentIds'],$mrId); echo json_encode(array("success" => 1, "downloadPath" => $packTask->pack_url)); exit; } } //**************** Step-3 根据接口获取文件大小来判断走原有接口打包流程还是走脚本任务 ************// $sizeRs = Curl::post($apiUrl . "/rest/download_file_size/index", array('path_arr' => $pathArr)); if (!($sizeRs = json_decode($sizeRs))) { echo json_encode(array("success" => 0, "message" => "请求接口失败")); exit; } if (isset($sizeRs->size)) { //************ Step-3-1 大于限定值 发送任务到后台打包 ******// if (Yii::app()->params["pack_product_file_limit"] < $sizeRs->size) { $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_SECOND_RUN; $packProductModel->product_name = $msg['name'].'二轮复习提分手册'; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $mrId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_math_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateSecondRunDownloadStatus($params['studentIds'],$mrId); echo json_encode(array("success" => 3, "message" => "")); exit; } else { $rs = Curl::post($apiUrl . "/rest/download_math_pdf/index", $params); if (!($rs = json_decode($rs))) { echo json_encode(array("success" => 0, "message" => '请求接口失败')); exit; } else { //更新下载时间 if ($rs->success == 1 || $rs->success == 2) { $this->updateSecondRunDownloadStatus($params['studentIds'],$mrId); } } if (isset($msg['school_group_id']) && $msg['school_group_id'] && isset($rs->downloadPath)) { if (YII_ENV == 'pro' || YII_ENV == 'production') { $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/', 'http://zstatic' . $msg['school_group_id'], $rs->downloadPath); } } echo json_encode($rs); exit; } } else { echo json_encode(array("success" => 0, "message" => $sizeRs->message)); exit; } } /** * 更新二轮下载状态 * @param $studentsIds * @param $mrId */ private function updateSecondRunDownloadStatus($studentsIds, $mrId) { $time = time(); $sql = "update math_review_student set is_review_download = 1,review_download_time={$time} where mr_id = '{$mrId}' and student_id in (" . implode(',', $studentsIds) . ")"; $this->sConn->createCommand($sql)->execute(); } /** * 添加二轮提分手册下载任务 */ public function actionAddSecondRunTask() { $mrId = (string)Req::get("mrId"); $studentsIds = Req::get("studentsIds"); $params = array(); if (!$mrId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } //*****获取生成的学生***// $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_SECOND_RUN); $generateStu = $productDownload->getGenerateStu('math_review_student', 'mr_id', 'review_pdf_path', 'is_review_pdf', $mrId, $studentsIds); if(!$generateStu){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } $params['studentIds'] = $generateStu['studentIds']; $sql = "select class_id,grade,create_time,semester_id,school_group_id,`name` from math_review_setting where mr_id = '{$mrId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $Sem = new SSemester(); $code = $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '" . $msg['semester_id'] . "'") ->limit(1) ->query() ->read(); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); $intarr = array( "schoolId" => $this->schoolId, "clazzId" => $msg['class_id'], "semester" => $code['refer_code'], "grade" => $msg['grade'], "examTime" => $msg['create_time'], "classify" => 5, "subject" => 3 ); if (isset($msg['school_group_id']) && $msg['school_group_id']) { $apiUrl = isset(Yii::app()->params["improve_url"][$msg['school_group_id']]) ? Yii::app()->params["improve_url"][$msg['school_group_id']] : null; } else { $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; } if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } //************ Step-1 判断是否有订单 *************// if (Yii::app()->params["limit_open"]) { if (Yii::app()->params["limit_open"]) { $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId); } } $params['mrId'] = $mrId; $params['schoolId'] = $this->schoolId; $params['type'] = 1; $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_SECOND_RUN; $packProductModel->product_name = $msg['name'].'二轮复习提分手册'; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $mrId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_math_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateSecondRunDownloadStatus($params['studentIds'],$mrId); echo json_encode(array("success" => 3, "message" => "")); exit; } /** * 下载好题本 */ public function actionGetHtbFile() { $htbId = (string)Req::get("htbId"); $studentsIds = Req::get("studentsIds"); $classDownload = $studentsIds ? false : true; $params = array(); if (!$htbId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } //*****获取生成的学生***// $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_HTB); $generateStu = $productDownload->getGenerateStu('math_htb_student', 'htb_id', 'htb_pdf_path', 'is_htb_pdf', $htbId, $studentsIds); if(!$generateStu){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } $params['studentIds'] = $generateStu['studentIds']; $pathArr = $generateStu['pathArr']; $sql = "select class_id,grade,create_time,semester_id,school_group_id,name from math_htb_setting where htb_id = '{$htbId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $Sem = new SSemester(); $code = $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '" . $msg['semester_id'] . "'") ->limit(1) ->query() ->read(); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); $intarr = array( "schoolId" => $this->schoolId, "clazzId" => $msg['class_id'], "semester" => $code['refer_code'], "grade" => $msg['grade'], "examTime" => $msg['create_time'], "classify" => 9, "subject" => 3 ); if (isset($msg['school_group_id']) && $msg['school_group_id']) { $apiUrl = isset(Yii::app()->params["improve_url"][$msg['school_group_id']]) ? Yii::app()->params["improve_url"][$msg['school_group_id']] : null; } else { $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; } if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } //************ Step-1 判断是否有订单 *************// if (Yii::app()->params["limit_open"]) { if (Yii::app()->params["limit_open"]) { $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId); } } $params['schoolId'] = $this->schoolId; $params['type'] = 5; $params['htbId'] = $htbId; //**************** Step-2 判断是否已经存在下载任务 ********************// if ($classDownload) { $packTask = $this->getExistTask($htbId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_HTB, count($params["studentIds"])); if (isset($packTask->pack_status) && $packTask->pack_status == 0) { echo json_encode(array("success" => 3, "message" => "")); exit; } if (isset($packTask->pack_url) && $packTask->pack_url) { $this->updateHtbDownloadStatus($params['studentIds'],$htbId); echo json_encode(array("success" => 1, "downloadPath" => $packTask->pack_url)); exit; } } //**************** Step-3 根据接口获取文件大小来判断走原有接口打包流程还是走脚本任务 ************// $sizeRs = Curl::post($apiUrl . "/rest/download_file_size/index", array('path_arr' => $pathArr)); if (!($sizeRs = json_decode($sizeRs))) { echo json_encode(array("success" => 0, "message" => "请求接口失败")); exit; } if (isset($sizeRs->size)) { //************ Step-3-1 大于限定值 发送任务到后台打包 ******// if (Yii::app()->params["pack_product_file_limit"] < $sizeRs->size) { $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_HTB; $packProductModel->product_name = $msg['name'].'好题本'; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $htbId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateHtbDownloadStatus($params['studentIds'],$htbId); echo json_encode(array("success" => 3, "message" => "")); exit; } else { $rs = Curl::post($apiUrl . "/rest/download_week_pdf/index", $params); if (!($rs = json_decode($rs))) { echo json_encode(array("success" => 0, "message" => '请求接口失败')); exit; } else { //更新下载时间 if ($rs->success == 1 || $rs->success == 2) { $this->updateHtbDownloadStatus($params['studentIds'],$htbId); } } if (isset($msg['school_group_id']) && $msg['school_group_id'] && isset($rs->downloadPath)) { if (YII_ENV == 'pro' || YII_ENV == 'production') { $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/', 'http://zstatic' . $msg['school_group_id'], $rs->downloadPath); } } echo json_encode($rs); exit; } } else { echo json_encode(array("success" => 0, "message" => $sizeRs->message)); exit; } } /** * 更新好题本下载状态 * @param $studentsIds * @param $htbId */ private function updateHtbDownloadStatus($studentsIds, $htbId) { $time = time(); $sql = "update math_htb_student set is_htb_download = 1,htb_download_time={$time} where htb_id = '{$htbId}' and student_id in (" . implode(',', $studentsIds) . ")"; $this->sConn->createCommand($sql)->execute(); } /** * 添加好题本下载任务 */ public function actionAddHtbTask() { $htbId = (string)Req::get("htbId"); $studentsIds = Req::get("studentsIds"); $params = array(); if (!$htbId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } //*****获取生成的学生***// $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_HTB); $generateStu = $productDownload->getGenerateStu('math_htb_student', 'htb_id', 'htb_pdf_path', 'is_htb_pdf', $htbId, $studentsIds); if(!$generateStu){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } $params['studentIds'] = $generateStu['studentIds']; $sql = "select class_id,grade,create_time,semester_id,school_group_id from math_htb_setting where htb_id = '{$htbId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $Sem = new SSemester(); $code = $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '" . $msg['semester_id'] . "'") ->limit(1) ->query() ->read(); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); $intarr = array( "schoolId" => $this->schoolId, "clazzId" => $msg['class_id'], "semester" => $code['refer_code'], "grade" => $msg['grade'], "examTime" => $msg['create_time'], "classify" => 9, "subject" => 3 ); if (isset($msg['school_group_id']) && $msg['school_group_id']) { $apiUrl = isset(Yii::app()->params["improve_url"][$msg['school_group_id']]) ? Yii::app()->params["improve_url"][$msg['school_group_id']] : null; } else { $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; } if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_HTB); //************ Step-1 判断是否有订单 *************// if (Yii::app()->params["limit_open"]) { if (Yii::app()->params["limit_open"]) { $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId); } } $params['schoolId'] = $this->schoolId; $params['type'] = 5; $params['htbId'] = $htbId; $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_HTB; $packProductModel->product_name = $msg['name']."好题本"; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $htbId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateHtbDownloadStatus($params['studentIds'],$htbId); echo json_encode(array("success" => 3, "message" => "")); exit; } /** * 下载假期报告 */ public function actionGetHolidayReportFile() { $reportId = (string)Req::get("reportId"); $studentsIds = Req::get("studentsIds"); $classDownload = $studentsIds ? false : true; $params = array(); if (!$reportId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } //获取组ID $sql = "select school_group_id,semester_id from holiday_report_setting where report_id = '{$reportId}'"; $report_settint_data = $this->sConn->createCommand($sql)->queryRow(); if (!$report_settint_data) { echo json_encode(array("success" => 0, "message" => "设置信息错误")); exit(); } else { $school_group_id = $report_settint_data['school_group_id']; } if (isset($school_group_id) && $school_group_id) { $apiUrl = isset(Yii::app()->params["improve_url"][$school_group_id]) ? Yii::app()->params["improve_url"][$school_group_id] : null; } else { $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; } //*****获取生成的学生***// $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_HOLIDAY_REPORT); $generateStu = $productDownload->getGenerateStu('holiday_report_student', 'report_id', 'report_pdf_path', 'is_report_pdf', $reportId, $studentsIds); if(!$generateStu){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } $params['studentIds'] = $generateStu['studentIds']; $pathArr = $generateStu['pathArr']; if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $sql = "select class_id,grade,create_time,semester_id from holiday_report_setting where report_id = '{$reportId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $Sem = new SSemester(); $code = $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '" . $msg['semester_id'] . "'") ->limit(1) ->query() ->read(); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); $intarr = array( "subject" => 3, "grade" => $msg['grade'], "examTime" => $msg['create_time'], ); //************ Step-1 判断是否有订单 *************// $params["studentIds"] = $params['studentIds']; // if (Yii::app()->params["limit_open"]) { // $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId); // } $params['schoolId'] = $this->schoolId; $params['type'] = 4; $params['reportId'] = $reportId; //**************** Step-2 判断是否已经存在下载任务 ********************// if ($classDownload) { $packTask = $this->getExistTask($reportId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_HOLIDAY_REPORT, count($params["studentIds"])); if (isset($packTask->pack_status) && $packTask->pack_status == 0) { echo json_encode(array("success" => 3, "message" => "")); exit; } if (isset($packTask->pack_url) && $packTask->pack_url) { $this->updateHrpDownloadStatus($params['studentIds'],$reportId); echo json_encode(array("success" => 1, "downloadPath" => $packTask->pack_url)); exit; } } //**************** Step-3 根据接口获取文件大小来判断走原有接口打包流程还是走脚本任务 ************// $sizeRs = Curl::post($apiUrl . "/rest/download_file_size/index", array('path_arr' => $pathArr)); if (!($sizeRs = json_decode($sizeRs))) { echo json_encode(array("success" => 0, "message" => "请求接口失败")); exit; } $smeName = isset($code['name'] ) ? $code['name'] : ''; if (isset($sizeRs->size)) { //************ Step-3-1 大于限定值 发送任务到后台打包 ******// if (Yii::app()->params["pack_product_file_limit"] < $sizeRs->size) { $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_HOLIDAY_REPORT; $packProductModel->product_name = $classinfo['class_name'].$smeName . '假期总结报告'; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $reportId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateHrpDownloadStatus($params['studentIds'],$reportId); echo json_encode(array("success" => 3, "message" => "")); exit; } else { $rs = Curl::post($apiUrl . "/rest/download_week_pdf/index", $params); if (!($rs = json_decode($rs))) { $rs = array( "success" => 0, "message" => "请求接口失败", ); } else { //更新下载时间 $this->updateHrpDownloadStatus($params['studentIds'],$reportId); } if (isset($school_group_id) && $school_group_id && isset($rs->downloadPath)) { if (YII_ENV == 'pro' || YII_ENV == 'production') { $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/', 'http://zstatic' . $school_group_id, $rs->downloadPath); } } echo json_encode($rs); exit; } } else { echo json_encode(array("success" => 0, "message" => $sizeRs->message)); exit; } } /** * 更新假期报告下载状态 * @param $studentsIds * @param $reportId */ private function updateHrpDownloadStatus($studentsIds, $reportId){ $time = time(); $sql = "update holiday_report_student set is_report_download = 1,report_download_time={$time} where report_id = '{$reportId}' and student_id in (" . implode(',', $studentsIds) . ") and report_download_time = 0"; $this->sConn->createCommand($sql)->execute(); } /** * 添加假期报告下载任务 */ public function actionAddHolidayReportTask() { $reportId = (string)Req::get("reportId"); $studentsIds = Req::get("studentsIds"); $params = array(); if (!$reportId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } //获取组ID $sql = "select school_group_id,semester_id from holiday_report_setting where report_id = '{$reportId}'"; $report_settint_data = $this->sConn->createCommand($sql)->queryRow(); if (!$report_settint_data) { echo json_encode(array("success" => 0, "message" => "设置信息错误")); exit(); } else { $school_group_id = $report_settint_data['school_group_id']; } if (isset($school_group_id) && $school_group_id) { $apiUrl = isset(Yii::app()->params["improve_url"][$school_group_id]) ? Yii::app()->params["improve_url"][$school_group_id] : null; } else { $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; } //*****获取生成的学生***// $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_HOLIDAY_REPORT); $generateStu = $productDownload->getGenerateStu('holiday_report_student', 'report_id', 'report_pdf_path', 'is_report_pdf', $reportId, $studentsIds); if(!$generateStu){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } $params['studentIds'] = $generateStu['studentIds']; if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $sql = "select class_id,grade,create_time,semester_id from holiday_report_setting where report_id = '{$reportId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $Sem = new SSemester(); $code = $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '" . $msg['semester_id'] . "'") ->limit(1) ->query() ->read(); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); $intarr = array( "subject" => 3, "grade" => $msg['grade'], "examTime" => $msg['create_time'], ); //************ Step-1 判断是否有订单 *************// if (Yii::app()->params["limit_open"]) { $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId); } $params['schoolId'] = $this->schoolId; $params['type'] = 4; $params['reportId'] = $reportId; $smeName = isset($code['name'] ) ? $code['name'] : ''; $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_HOLIDAY_REPORT; $packProductModel->product_name = $classinfo['class_name'].$smeName . '假期总结报告'; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $reportId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateHrpDownloadStatus($params['studentIds'],$reportId); echo json_encode(array("success" => 3, "message" => "")); exit; } /** * 下载晨读词汇 */ public function actionGetEnglishFile() { $weekId = (string)Req::get("weekId"); $studentsIds = Req::get("studentsIds"); $classDownload = $studentsIds ? false : true; $params = array(); if (!$weekId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } //*****获取生成的学生***// $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_EN_MRV); $generateStu = $productDownload->getGenerateStu('english_week_student', 'week_id', 'week_pdf_path', 'is_week_pdf', $weekId, $studentsIds); if(!$generateStu){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } $params['studentIds'] = $generateStu['studentIds']; $pathArr = $generateStu['pathArr']; $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $sql = "select class_id,grade,create_time,semester_id,`name` from english_week where week_id = '{$weekId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $Sem = new SSemester(); $code = $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '" . $msg['semester_id'] . "'") ->limit(1) ->query() ->read(); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); $intarr = array( "schoolId" => $this->schoolId, "clazzId" => $msg['class_id'], "semester" => $code['refer_code'], "grade" => $msg['grade'], "examTime" => $msg['create_time'], "classify" => 3, "subject" => 8 ); //************ Step-1 判断是否有订单 *************// if (Yii::app()->params["limit_open"]) { if (Yii::app()->params["limit_open"]) { $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId); } } $params['schoolId'] = $this->schoolId; $params['type'] = 1; $params['weekId'] = $weekId; //**************** Step-2 判断是否已经存在下载任务 ********************// if($classDownload) { $packTask = $this->getExistTask($weekId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_EN_MRV, count($params["studentIds"])); if (isset($packTask->pack_status) && $packTask->pack_status == 0) { echo json_encode(array("success" => 3, "message" => "")); exit; } if (isset($packTask->pack_url) && $packTask->pack_url) { $this->updateEnMrvDownloadStatus($params['studentIds'],$weekId); echo json_encode(array("success" => 1, "downloadPath" => $packTask->pack_url)); exit; } } //**************** Step-3 根据接口获取文件大小来判断走原有接口打包流程还是走脚本任务 ************// $sizeRs = Curl::post($apiUrl . "/rest/download_file_size/index", array('path_arr' => $pathArr)); if (!($sizeRs = json_decode($sizeRs))) { echo json_encode(array("success" => 0, "message" => "请求接口失败")); exit; } if (isset($sizeRs->size)) { //************ Step-3-1 大于限定值 发送任务到后台打包 ******// if (Yii::app()->params["pack_product_file_limit"] < $sizeRs->size) { $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_EN_MRV; $packProductModel->product_name = $msg['name'] . '晨读词汇'; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $weekId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateEnMrvDownloadStatus($params['studentIds'],$weekId); echo json_encode(array("success" => 3, "message" => "")); exit; } else { $rs = Curl::post($apiUrl . "/rest/download_week_pdf/index", $params); if (!($rs = json_decode($rs))) { $rs = array( "success" => 0, "message" => "请求接口失败", ); } else { //更新下载时间 if ($rs->success == 1 || $rs->success == 2) { $this->updateEnMrvDownloadStatus($params['studentIds'],$weekId); } } echo json_encode($rs); exit; } } else { echo json_encode(array("success" => 0, "message" => $sizeRs->message)); exit; } } /** * 更新晨读词汇下载状态 * @param $studentsIds * @param $weekId */ private function updateEnMrvDownloadStatus($studentsIds, $weekId) { $time = time(); $sql = "update english_week_student set is_week_download = 1,week_download_time={$time} where week_id = '{$weekId}' and student_id in (" . implode(',', $studentsIds) . ")"; $this->sConn->createCommand($sql)->execute(); } /** * 添加晨读词汇下载任务 */ public function actionAddEnMrvTask() { $weekId = (string)Req::get("weekId"); $studentsIds = Req::get("studentsIds"); $params = array(); if (!$weekId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } //*****获取生成的学生***// $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_EN_MRV); $generateStu = $productDownload->getGenerateStu('english_week_student', 'week_id', 'week_pdf_path', 'is_week_pdf', $weekId, $studentsIds); if(!$generateStu){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } $params['studentIds'] = $generateStu['studentIds']; $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $sql = "select class_id,grade,create_time,semester_id,`name` from english_week where week_id = '{$weekId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $Sem = new SSemester(); $code = $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '" . $msg['semester_id'] . "'") ->limit(1) ->query() ->read(); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); $intarr = array( "schoolId" => $this->schoolId, "clazzId" => $msg['class_id'], "semester" => $code['refer_code'], "grade" => $msg['grade'], "examTime" => $msg['create_time'], "classify" => 3, "subject" => 8 ); //************ Step-1 判断是否有订单 *************// if (Yii::app()->params["limit_open"]) { if (Yii::app()->params["limit_open"]) { $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId); } } $params['schoolId'] = $this->schoolId; $params['type'] = 1; $params['weekId'] = $weekId; $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_EN_MRV; $packProductModel->product_name = $msg['name'] . '晨读词汇'; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $weekId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateEnMrvDownloadStatus($params['studentIds'],$weekId); echo json_encode(array("success" => 3, "message" => "")); exit; } /** * 下载外刊美文个性化学习宝 */ public function actionGetEnglishReadingFile() { $weekId = (string)Req::get("weekId"); $studentsIds = Req::get("studentsIds"); $classDownload = $studentsIds ? false : true; $params = array(); if (!$weekId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } $sql = "select class_id,er.grade,er.create_time,er.semester_id,name,ers.category,ers.product_type from english_reading er join english_reading_setting ers on ers.reading_id=er.reading_id where week_id = '{$weekId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $Sem = new SSemester(); $code = $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '" . $msg['semester_id'] . "'") ->limit(1) ->query() ->read(); $classify=6; if($msg['category']==2){ if($msg['product_type']==1){ $classify=57; $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_EN_READING_JICHU); }elseif($msg['product_type']==2){ $classify=61; $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_EN_READING_WAIKAN); }elseif($msg['product_type']==3){ $classify=58; $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_EN_READING_REDIAN); } }else{ $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_EN_READING); } //*****获取生成的学生***// $generateStu = $productDownload->getGenerateStu('english_reading_student', 'week_id', 'week_pdf_path', 'is_week_pdf', $weekId, $studentsIds); if(!$generateStu){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } $params['studentIds'] = $generateStu['studentIds']; $pathArr = $generateStu['pathArr']; $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); $intarr = array( "schoolId" => $this->schoolId, "clazzId" => $msg['class_id'], "semester" => $code['refer_code'], "grade" => $msg['grade'], "students" => $studentsIds, "examTime" => $msg['create_time'], "classify" => $classify, "subject" => 8 ); //************ Step-1 判断是否有订单 *************// if (Yii::app()->params["limit_open"]) { if (Yii::app()->params["limit_open"]) { $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId); } } $params['schoolId'] = $this->schoolId; $params['type'] = 3; $params['weekId'] = $weekId; //**************** Step-2 判断是否已经存在下载任务 ********************// if($classDownload) { $packTask = $this->getExistTask($weekId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_EN_READING, count($params["studentIds"])); if (isset($packTask->pack_status) && $packTask->pack_status == 0) { echo json_encode(array("success" => 3, "message" => "")); exit; } if (isset($packTask->pack_url) && $packTask->pack_url) { $this->updateEnreadingDownloadStatus($params['studentIds'],$weekId); echo json_encode(array("success" => 1, "downloadPath" => $packTask->pack_url)); exit; } } //**************** Step-3 根据接口获取文件大小来判断走原有接口打包流程还是走脚本任务 ************// $sizeRs = Curl::post($apiUrl . "/rest/download_file_size/index", array('path_arr' => $pathArr)); if (!($sizeRs = json_decode($sizeRs))) { echo json_encode(array("success" => 0, "message" => "请求接口失败")); exit; } if (isset($sizeRs->size)) { //************ Step-3-1 大于限定值 发送任务到后台打包 ******// if (Yii::app()->params["pack_product_file_limit"] < $sizeRs->size) { $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_EN_READING; $packProductModel->product_name = $msg['name'] . '外刊宝'; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $weekId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateEnreadingDownloadStatus($params['studentIds'],$weekId); echo json_encode(array("success" => 3, "message" => "")); exit; } else { $rs = Curl::post($apiUrl . "/rest/download_week_pdf/index", $params); if (!($rs = json_decode($rs))) { $rs = array( "success" => 0, "message" => "请求接口失败", ); } else { //更新下载时间 if ($rs->success == 1 || $rs->success == 2) { $this->updateEnreadingDownloadStatus($params['studentIds'],$weekId); } } echo json_encode($rs); exit; } } else { echo json_encode(array("success" => 0, "message" => $sizeRs->message)); exit; } } /** * 更新外刊下载状态 * @param $studentsIds * @param $weekId */ private function updateEnreadingDownloadStatus($studentsIds, $weekId) { $time = time(); $sql = "update english_reading_student set is_week_download = 1,week_download_time={$time} where week_id = '{$weekId}' and student_id in (" . implode(',', $studentsIds) . ") and week_download_time = 0"; $this->sConn->createCommand($sql)->execute(); } /** * 添加外刊美文个性化学习宝下载任务 */ public function actionAddEnReadingTask() { $weekId = (string)Req::get("weekId"); $studentsIds = Req::get("studentsIds"); if (!$weekId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } //*****获取生成的学生***// $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_EN_READING); $generateStu = $productDownload->getGenerateStu('english_reading_student', 'week_id', 'week_pdf_path', 'is_week_pdf', $weekId, $studentsIds); if(!$generateStu){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } $params['studentIds'] = $generateStu['studentIds']; $sql = "select class_id,grade,create_time,semester_id,name from english_reading where week_id = '{$weekId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $Sem = new SSemester(); $code = $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '" . $msg['semester_id'] . "'") ->limit(1) ->query() ->read(); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); $intarr = array( "schoolId" => $this->schoolId, "clazzId" => $msg['class_id'], "semester" => $code['refer_code'], "grade" => $msg['grade'], "students" => $studentsIds, "examTime" => $msg['create_time'], "classify" => 6, "subject" => 8 ); //************ Step-1 判断是否有订单 *************// //$params = array(); $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } if (Yii::app()->params["limit_open"]) { if (Yii::app()->params["limit_open"]) { $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId); } } //*******产品接口参数******// $params['weekId'] = $weekId; $params['schoolId'] = $this->schoolId; $params['type'] = 3; $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_EN_READING; $packProductModel->product_name = $msg['name'] . '外刊宝'; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $weekId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateEnreadingDownloadStatus($params['studentIds'],$weekId); echo json_encode(array("success" => 3, "message" => "")); exit; } /** * 获取已存在的下载任务 * @param $unique_id * @param $class_id * @param $type * @param $studentCount * @return bool|mixed */ private function getExistTask($unique_id, $class_id, $type, $studentCount) { $schoolId = $this->schoolId; $subjectId = $this->subjectId; $effectTime = time() - 86400; $sql = <<2 and create_time>{$effectTime} order by create_time desc limit 1; SQL; $rs = BusinessPackProductTask::model()->findBySql($sql); return $rs; } /** * 获取学生是否有订单 * @param $intarr * @param $stuids */ protected function getStuOrder($intarr, &$stuids) { $basic = imsBasicAuth($this->schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]); foreach (array(1, 2, 3) as $type) { $intarr['classify'] = $type; $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr), $basic)); if (!$rs) { Yii::app()->jump->error("接口错误"); } if ($rs->errCode != "00") { Yii::app()->jump->error($rs->errMsg); } $stuids = array_unique(array_merge($stuids, $rs->data)); } } //批量下载假期报告 public function actionBatchHoliday(){ $json_params = file_get_contents('php://input'); $params_arr = json_decode($json_params, true); $notFound = 0; foreach ($params_arr as $param) { $reportId = isset($param['reportId']) ? $param['reportId'] : null; if (!$reportId) { echo json_encode(array("status" => 0, "message" => "缺少参数"));exit(); } $params = array(); //获取组ID $sql = "select school_group_id,semester_id from holiday_report_setting where report_id = '{$reportId}'"; $report_settint_data = $this->sConn->createCommand($sql)->queryRow(); if (!$report_settint_data) { echo json_encode(array("success" => 0, "message" => "设置信息错误")); exit(); } else { $school_group_id = $report_settint_data['school_group_id']; } if (isset($school_group_id) && $school_group_id) { $apiUrl = isset(Yii::app()->params["improve_url"][$school_group_id]) ? Yii::app()->params["improve_url"][$school_group_id] : null; } else { $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; } //*****获取生成的学生***// $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_HOLIDAY_REPORT); $generateStu = $productDownload->getGenerateStu('holiday_report_student', 'report_id', 'report_pdf_path', 'is_report_pdf', $reportId, array()); if(!$generateStu){ $notFound++; continue; } $params['studentIds'] = $generateStu['studentIds']; if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $sql = "select class_id,grade,create_time,semester_id from holiday_report_setting where report_id = '{$reportId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $Sem = new SSemester(); $code = $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '" . $msg['semester_id'] . "'") ->limit(1) ->query() ->read(); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); $params['schoolId'] = $this->schoolId; $params['type'] = 4; $params['reportId'] = $reportId; //**************** Step-2 判断是否已经存在下载任务 ********************// $packTask = $this->getExistTask($reportId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_HOLIDAY_REPORT, count($params["studentIds"])); if ($packTask) { continue; } $smeName = isset($code['name'] ) ? $code['name'] : ''; //************ 批量直接发送任务到后台打包 ******// $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_HOLIDAY_REPORT; $packProductModel->product_name = $classinfo['class_name'].$smeName . '假期总结报告'; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $reportId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateHrpDownloadStatus($params['studentIds'],$reportId); } if($notFound == count($params_arr)){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } echo json_encode(array("success" => 1, "message" => "success")); } //批量下载错题本 提分方案 个性化学习宝 public function actionBatchIsp() { $json_params = file_get_contents('php://input'); $params_arr = json_decode($json_params, true); $notFound = 0; foreach ($params_arr as $param) { $examId = isset($param['examId']) ? $param['examId'] : null; $classId = isset($param['classId']) ? $param['classId'] : null; $type = isset($param['type']) ? $param['type'] : null; $printType = isset($param['printType']) ? $param['printType'] : null; $absentFilter = isset($param['absent_filter']) ? $param['absent_filter'] : false; if (!$examId || !$classId || !$type) { echo json_encode(array("success" => 0, "message" => "缺少参数"));exit(); } if (!in_array($type, array(1, 2, 3))) { echo json_encode(array("success" => 0, "message" => "参数错误[1]"));exit(); } $groupInfo = Exam::model()->getGroupInfo($examId); if (empty($groupInfo)) exit(json_encode(array("success" => 0, "message" => "考试信息错误"))); $typeRel = array('1' => 'wb_group_id', '2' => 'isp_group_id', '3' => 'wbisp_group_id'); $groupId = $groupInfo[$typeRel[$type]]; if (!empty($groupId)) { $apiUrl = isset(Yii::app()->params["improve_url"][$groupId]) ? Yii::app()->params["improve_url"][$groupId] : null; } else { $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; } if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $params = array( "schoolId" => $this->schoolId, "examId" => $examId, "classId" => $classId, "type" => $type, "studentIds" => array(), ); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $classId)); //判断学科 $examInfo = Exam::model()->findByPk($examId); if ($type == 1) { $productName = $examInfo->name . '"错题本"'; $pdfPathColumn = 'wrongbook_pdf_path'; $isGenerateColumn = 'is_wrongbook_pdf'; $isDownloadColumn = 'is_wrongbook_download'; $downloadTimeCoulmn = 'download_wrongbook_time'; } elseif ($type == 2) { $productName = $examInfo->name . '"个性化学习方案"'; $pdfPathColumn = 'isp_pdf_path'; $isGenerateColumn = 'is_isp_pdf'; $isDownloadColumn = 'is_two_isp_download'; $downloadTimeCoulmn = 'download_two_isp_time'; } else { $productName = $examInfo->name . '"个性化学习宝"'; $pdfPathColumn = 'wbisp_pdf_path'; $isGenerateColumn = 'is_wbisp_pdf'; $isDownloadColumn = 'is_three_isp_download'; $downloadTimeCoulmn = 'download_two_isp_time'; } $productDownload = new ProductDownload($type); //*****获取生成的学生***// $generateStu = $productDownload->getGenerateStu('student_paper_relation', 'exam_id', $pdfPathColumn, $isGenerateColumn, $examId, array(), $absentFilter); if(!$generateStu){ $notFound++; continue; } $params['studentIds'] = $generateStu['studentIds']; if ($printType == 'third_isp') { $params["subjectId"] = 8; $params["type"] = 3; } ProductProcessTime::model()->updateDownloadTime($params["studentIds"],$type,$examId); //**************** Step-2 判断是否已经存在下载任务 ********************// $packTask = $this->getExistTask($examId, $classId, $type, count($params['studentIds'])); if ($packTask) { continue; } //************Step-3 批量直接发送任务到后台打包 ******// $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = $type; $packProductModel->product_name = $productName; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $classId; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $examId; $packProductModel->student_count = count($params["studentIds"]); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateIspDownloadStatus($params["studentIds"],$classId,$examId,$isDownloadColumn,$downloadTimeCoulmn); } if($notFound == count($params_arr)){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } echo json_encode(array("success" => 1, "message" => "success")); } //批量下载阶段复习个性化学习宝 public function actionBatchSp() { $json_params = file_get_contents('php://input'); $params_arr = json_decode($json_params, true); $notFound = 0; foreach ($params_arr as $param) { $classId = isset($param['classId'])?$param['classId']:null; $type = isset($param['type'])?$param['type']:null; if (!$classId || !$type) { echo json_encode(array("success" => 0, "message" => "缺少参数"));exit(); } if (!in_array($type, array(1, 2, 3))) { echo json_encode(array("success" => 0, "message" => "参数错误[1]"));exit(); } $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $params = array( "schoolId" => $this->schoolId, "classId" => $classId, "type" => $type, ); $studentsIds = array(); $student_class_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status', array(':class_id' => $classId, ':status' => 0)); if ($student_class_data) { foreach ($student_class_data as $v) { $studentsIds[] = $v->student_id; } } else { echo json_encode(array("success" => 0, "message" => "班级暂无学生")); exit; } $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $classId)); $params['studentIds'] = $studentsIds; if(in_array($this->subjectId,$this->mathSubjectId)){ $subjectId=3; }else{ $subjectId=$this->subjectId; } $_student_product_data=SStudentProductModel::model()->getStudentCreate($studentsIds,$subjectId,$type,$this->semesterId); if (!$_student_product_data) { //echo json_encode(array("success" => 0, "message" => $classinfo['class_name']."学生尚未生成PDF")); $notFound++; continue; } $planId=SStudentProductModel::model()->getPlanId($classId,$subjectId,$type); $params['planId']=$planId; //************ 判断是否已经存在下载任务 **********// $packTask = $this->getExistTask($this->semesterId . '_' . $type, $classId, ProductDownload::PRODUCT_TYPE_STAGE_REVIEW, count($_student_product_data)); if ($packTask) { continue; } $semester = new SSemester(); $nowsem = $semester->getCurrentSemester(); $semesterName = isset($nowsem->semester_name) ? $nowsem->semester_name : ''; if ($type == 1) { $productName = $semesterName . '"期中阶段复习个性化学习宝"'; } elseif ($type == 2) { $productName = $semesterName . '"期末阶段复习个性化学习宝"'; } else { $productName = $semesterName . '"总复习个性化学习宝"'; } $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_STAGE_REVIEW; $packProductModel->product_name = $productName; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $classId; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $this->semesterId . '_' . $type; $packProductModel->student_count = count($_student_product_data); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_sp/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateSpDownloadStatus($params['studentIds'], $type,$planId); } if($notFound == count($params_arr)){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } echo json_encode(array("success" => 1, "message" => "success")); } //批量下载二轮复习提分手册 public function actionBatchMathReview(){ $json_params = file_get_contents('php://input'); $params_arr = json_decode($json_params, true); $notFound = 0; foreach ($params_arr as $param) { $mrId = isset($param['mrId'])?$param['mrId']:null; $params = array(); if (!$mrId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } //*****获取生成的学生***// $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_SECOND_RUN); $generateStu = $productDownload->getGenerateStu('math_review_student', 'mr_id', 'review_pdf_path', 'is_review_pdf', $mrId, array()); if(!$generateStu){ $notFound++; continue; } $params['studentIds'] = $generateStu['studentIds']; $sql = "select class_id,grade,create_time,semester_id,school_group_id,`name` from math_review_setting where mr_id = '{$mrId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); if (isset($msg['school_group_id']) && $msg['school_group_id']) { $apiUrl = isset(Yii::app()->params["improve_url"][$msg['school_group_id']]) ? Yii::app()->params["improve_url"][$msg['school_group_id']] : null; } else { $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; } if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $packTask = $this->getExistTask($mrId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_SECOND_RUN, count($params["studentIds"])); if ($packTask) { continue; } $params['mrId'] = $mrId; $params['schoolId'] = $this->schoolId; $params['type'] = 1; $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_SECOND_RUN; $packProductModel->product_name = $msg['name'] . '二轮复习学习手册'; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $mrId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_math_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateSecondRunDownloadStatus($params['studentIds'], $mrId); } if($notFound == count($params_arr)){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } echo json_encode(array("success" => 1, "message" => "success")); } //批量下载好题本 public function actionBatchHtb() { $json_params = file_get_contents('php://input'); $params_arr = json_decode($json_params, true); $notFound = 0; foreach ($params_arr as $param) { $htbId = isset($param['htbId']) ? $param['htbId'] : null; $params = array(); if (!$htbId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } //*****获取生成的学生***// $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_HTB); $generateStu = $productDownload->getGenerateStu('math_htb_student', 'htb_id', 'htb_pdf_path', 'is_htb_pdf', $htbId, array()); if(!$generateStu){ $notFound++; continue; } $params['studentIds'] = $generateStu['studentIds']; $sql = "select class_id,grade,create_time,semester_id,school_group_id from math_htb_setting where htb_id = '{$htbId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); if (isset($msg['school_group_id']) && $msg['school_group_id']) { $apiUrl = isset(Yii::app()->params["improve_url"][$msg['school_group_id']]) ? Yii::app()->params["improve_url"][$msg['school_group_id']] : null; } else { $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; } if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $packTask = $this->getExistTask($htbId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_HTB, count($params["studentIds"])); if ($packTask) { continue; } $params['schoolId'] = $this->schoolId; $params['type'] = 5; $params['htbId'] = $htbId; $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_HTB; $packProductModel->product_name = $msg['name']."好题本"; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $htbId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateHtbDownloadStatus($params['studentIds'],$htbId); } if($notFound == count($params_arr)){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } echo json_encode(array("success" => 1, "message" => "success")); } //批量晨读词汇 public function actionBatchEnMrv() { $json_params = file_get_contents('php://input'); $params_arr = json_decode($json_params, true); $notFound = 0; foreach ($params_arr as $param) { $weekId = isset($param['weekId']) ? $param['weekId'] : null; $params = array(); if (!$weekId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } //*****获取生成的学生***// $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_EN_MRV); $generateStu = $productDownload->getGenerateStu('english_week_student', 'week_id', 'week_pdf_path', 'is_week_pdf', $weekId, array()); if(!$generateStu){ $notFound++; continue; } $params['studentIds'] = $generateStu['studentIds']; $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $sql = "select class_id,grade,create_time,semester_id,`name` from english_week where week_id = '{$weekId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); //************ 判断是任务是否存在 *************// $packTask = $this->getExistTask($weekId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_EN_MRV, count($params["studentIds"])); if ($packTask) { continue; } $params['schoolId'] = $this->schoolId; $params['type'] = 1; $params['weekId'] = $weekId; $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_EN_MRV; $packProductModel->product_name = $msg['name'] . '晨读词汇'; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $weekId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateEnMrvDownloadStatus($params['studentIds'], $weekId); } if($notFound == count($params_arr)){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } echo json_encode(array("success" => 1, "message" => "success")); } /** * 批量外刊美文个性化学习宝 */ public function actionBatchEnReading() { $json_params = file_get_contents('php://input'); $params_arr = json_decode($json_params, true); $notFound = 0; foreach ($params_arr as $param) { $weekId = isset($param['weekId']) ? (string)$param['weekId'] : null; $params = array(); if (!$weekId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } //*****获取生成的学生***// $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_EN_READING); $generateStu = $productDownload->getGenerateStu('english_reading_student', 'week_id', 'week_pdf_path', 'is_week_pdf', $weekId, array()); if(!$generateStu){ $notFound++; continue; } $params['studentIds'] = $generateStu['studentIds']; $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $sql = "select class_id,grade,create_time,semester_id,name from english_reading where week_id = '{$weekId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); $params['schoolId'] = $this->schoolId; $params['type'] = 3; $params['weekId'] = $weekId; //**************** Step-2 判断是否已经存在下载任务 ********************// $packTask = $this->getExistTask($weekId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_EN_READING, count($params["studentIds"])); if($packTask){ continue; } $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_EN_READING; $packProductModel->product_name = $msg['name'] . '外刊宝'; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $weekId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateEnreadingDownloadStatus($params['studentIds'], $weekId); } if($notFound == count($params_arr)){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } echo json_encode(array("success" => 1, "message" => "success")); } /** * 下载词汇宝 */ public function actionGetMagicWordFile() { $mwId = (string)Req::get("mw_id"); $studentsIds = Req::get("studentsIds"); $classDownload = $studentsIds ? false : true; $params = array(); if (!$mwId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } $sql = "select class_id,grade,create_time,semester_id,name from english_magic_word where mw_id = '{$mwId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); //*****获取生成的学生***// $productDownload = new ProductDownload($msg['grade']==3?ProductDownload::PRODUCT_TYPE_EN_MAGIC_WORD:ProductDownload::PRODUCT_TYPE_EN_INTEREST_WORD); $generateStu = $productDownload->getGenerateStu('english_magic_word_student', 'mw_id', 'week_pdf_path', 'is_week_pdf', $mwId, $studentsIds); if(!$generateStu){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } $params['studentIds'] = $generateStu['studentIds']; $pathArr = $generateStu['pathArr']; $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $Sem = new SSemester(); $code = $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '" . $msg['semester_id'] . "'") ->limit(1) ->query() ->read(); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); $intarr = array( "schoolId" => $this->schoolId, "clazzId" => $msg['class_id'], "semester" => $code['refer_code'], "grade" => $msg['grade'], "students" => $studentsIds, "examTime" => $msg['create_time'], "classify" => 11, "subject" => 8 ); //************ Step-1 判断是否有订单 *************// if (Yii::app()->params["limit_open"]) { if (Yii::app()->params["limit_open"]) { $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId); } } $params['schoolId'] = $this->schoolId; $params['type'] = 6; $params['mwId'] = $mwId; //**************** Step-2 判断是否已经存在下载任务 ********************// if($classDownload) { $packTask = $this->getExistTask($mwId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_EN_MAGIC_WORD, count($params["studentIds"])); if (isset($packTask->pack_status) && $packTask->pack_status == 0) { echo json_encode(array("success" => 3, "message" => "")); exit; } if (isset($packTask->pack_url) && $packTask->pack_url) { $this->updateMagicWordDownloadStatus($params['studentIds'],$mwId); echo json_encode(array("success" => 1, "downloadPath" => $packTask->pack_url)); exit; } } //**************** Step-3 根据接口获取文件大小来判断走原有接口打包流程还是走脚本任务 ************// $sizeRs = Curl::post($apiUrl . "/rest/download_file_size/index", array('path_arr' => $pathArr)); if (!($sizeRs = json_decode($sizeRs))) { echo json_encode(array("success" => 0, "message" => "请求接口失败")); exit; } if (isset($sizeRs->size)) { //************ Step-3-1 大于限定值 发送任务到后台打包 ******// if (Yii::app()->params["pack_product_file_limit"] < $sizeRs->size) { $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_EN_READING; $packProductModel->product_name = $msg['name'] . '词汇宝'; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $mwId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateMagicWordDownloadStatus($params['studentIds'],$mwId); echo json_encode(array("success" => 3, "message" => "")); exit; } else { $rs = Curl::post($apiUrl . "/rest/download_week_pdf/index", $params); if (!($rs = json_decode($rs))) { $rs = array( "success" => 0, "message" => "请求接口失败", ); } else { //更新下载时间 if ($rs->success == 1 || $rs->success == 2) { $this->updateMagicWordDownloadStatus($params['studentIds'],$mwId); } } echo json_encode($rs); exit; } } else { echo json_encode(array("success" => 0, "message" => $sizeRs->message)); exit; } } /** * 更新词汇宝下载状态 * @param $studentsIds * @param $weekId */ private function updateMagicWordDownloadStatus($studentsIds, $weekId) { $time = time(); $sql = "update english_magic_word_student set is_week_download = 1,week_download_time={$time} where mw_id = '{$weekId}' and student_id in (" . implode(',', $studentsIds) . ") and week_download_time = 0"; $this->sConn->createCommand($sql)->execute(); } /** * 更新词汇宝批改后检测卡下载状态 * @param $studentsIds * @param $weekId */ private function updateMagicWordAfterDownloadStatus($studentsIds, $weekId) { $time = time(); $sql = "update english_magic_word_student set is_card_download = 1,card_download_time={$time} where mw_id = '{$weekId}' and student_id in (" . implode(',', $studentsIds) . ") and card_download_time = 0"; $this->sConn->createCommand($sql)->execute(); } /** * 添加词汇宝下载任务 */ public function actionAddMagicWordTask() { $weekId = (string)Req::get("mw_id"); $studentsIds = Req::get("studentsIds"); if (!$weekId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } $sql = "select class_id,grade,create_time,semester_id,name from english_magic_word where mw_id = '{$weekId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); //*****获取生成的学生***// $productDownload = new ProductDownload($msg['grade']==3?ProductDownload::PRODUCT_TYPE_EN_MAGIC_WORD:ProductDownload::PRODUCT_TYPE_EN_INTEREST_WORD); $generateStu = $productDownload->getGenerateStu('english_magic_word_student', 'mw_id', 'week_pdf_path', 'is_week_pdf', $weekId, $studentsIds); if(!$generateStu){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } $params['studentIds'] = $generateStu['studentIds']; $Sem = new SSemester(); $code = $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '" . $msg['semester_id'] . "'") ->limit(1) ->query() ->read(); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); $intarr = array( "schoolId" => $this->schoolId, "clazzId" => $msg['class_id'], "semester" => $code['refer_code'], "grade" => $msg['grade'], "students" => $studentsIds, "examTime" => $msg['create_time'], "classify" => 11, "subject" => 8 ); //************ Step-1 判断是否有订单 *************// $params = array(); $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } if (Yii::app()->params["limit_open"]) { if (Yii::app()->params["limit_open"]) { $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId); } } //*******产品接口参数******// $params['mwId'] = $weekId; $params['schoolId'] = $this->schoolId; $params['type'] = 6; $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_EN_MAGIC_WORD; $packProductModel->product_name = $msg['name'] . '词汇宝'; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $weekId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateMagicWordDownloadStatus($params['studentIds'],$weekId); echo json_encode(array("success" => 3, "message" => "")); exit; } /** * 批量词汇宝下载 */ public function actionBatchMagicWord() { $json_params = file_get_contents('php://input'); $params_arr = json_decode($json_params, true); $notFound = 0; foreach ($params_arr as $param) { $weekId = isset($param['mw_id']) ? (string)$param['mw_id'] : null; $params = array(); if (!$weekId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } //*****获取生成的学生***// $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_EN_MAGIC_WORD); $generateStu = $productDownload->getGenerateStu('english_magic_word_student', 'mw_id', 'week_pdf_path', 'is_week_pdf', $weekId, array()); if(!$generateStu){ $notFound++; continue; } $params['studentIds'] = $generateStu['studentIds']; $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $sql = "select class_id,grade,create_time,semester_id,name from english_magic_word where mw_id = '{$weekId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); $params['schoolId'] = $this->schoolId; $params['type'] = 6; $params['mwId'] = $weekId; //**************** Step-2 判断是否已经存在下载任务 ********************// $packTask = $this->getExistTask($weekId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_EN_MAGIC_WORD, count($params["studentIds"])); if($packTask){ continue; } $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_EN_MAGIC_WORD; $packProductModel->product_name = $msg['name'] . '词汇宝'; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $weekId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateMagicWordDownloadStatus($params['studentIds'], $weekId); } if($notFound == count($params_arr)){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } echo json_encode(array("success" => 1, "message" => "success")); } /** * 下载词汇宝检测卡 */ public function actionGetMagicWordCard() { $mwId = (string)Req::get("mw_id"); $params = array(); if (!$mwId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } $sql = "select student_id from english_magic_word_student where mw_id = '{$mwId}' and is_card_pdf = 1"; $stuArr = $this->getDbConnection()->createCommand($sql)->queryAll(); if ($stuArr) { foreach ($stuArr as $k => $v) { $params['studentIds'][] = $v['student_id']; } }else{ echo json_encode(array("success" => 0, "message" => "未找到生成的检测卡")); exit(); } $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $params['schoolId'] = $this->schoolId; $params['type'] = 6; $params['mwId'] = $mwId; $params['isMwCard'] = 1; $rs = Curl::post($apiUrl . "/rest/download_week_pdf/index", $params); if (!($rs = json_decode($rs))) { $rs = array( "success" => 0, "message" => "请求接口失败", ); } else { //更新下载时间 if ($rs->success == 1 || $rs->success == 2) { $this->updateMagicWordAfterDownloadStatus($params['studentIds'],$mwId); } } echo json_encode($rs); exit; } /** * 下载写作宝 */ public function actionGetWritingFile() { $ewId = (string)Req::get("ew_id"); $studentsIds = Req::get("studentsIds"); $classDownload = $studentsIds ? false : true; $params = array(); if (!$ewId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } $sql = "select class_id,grade,create_time,semester_id,name from english_writing where ew_id = '{$ewId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); //*****获取生成的学生***// $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_WRITING); $generateStu = $productDownload->getGenerateStu('english_writing_student', 'ew_id', 'week_pdf_path', 'is_week_pdf', $ewId, $studentsIds); if(!$generateStu){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } $params['studentIds'] = $generateStu['studentIds']; $pathArr = $generateStu['pathArr']; $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $Sem = new SSemester(); $code = $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '" . $msg['semester_id'] . "'") ->limit(1) ->query() ->read(); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); $intarr = array( "schoolId" => $this->schoolId, "clazzId" => $msg['class_id'], "semester" => $code['refer_code'], "grade" => $msg['grade'], "students" => $studentsIds, "examTime" => $msg['create_time'], "classify" => 32, "subject" => 8 ); //************ Step-1 判断是否有订单 *************// if (Yii::app()->params["limit_open"]) { if (Yii::app()->params["limit_open"]) { $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId); } } $params['schoolId'] = $this->schoolId; $params['type'] = 7; $params['ewId'] = $ewId; //**************** Step-2 判断是否已经存在下载任务 ********************// if($classDownload) { $packTask = $this->getExistTask($ewId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_WRITING, count($params["studentIds"])); if (isset($packTask->pack_status) && $packTask->pack_status == 0) { echo json_encode(array("success" => 3, "message" => "")); exit; } if (isset($packTask->pack_url) && $packTask->pack_url) { $this->updateWritingDownloadStatus($params['studentIds'],$ewId); echo json_encode(array("success" => 1, "downloadPath" => $packTask->pack_url)); exit; } } //**************** Step-3 根据接口获取文件大小来判断走原有接口打包流程还是走脚本任务 ************// $sizeRs = Curl::post($apiUrl . "/rest/download_file_size/index", array('path_arr' => $pathArr)); if (!($sizeRs = json_decode($sizeRs))) { echo json_encode(array("success" => 0, "message" => "请求接口失败")); exit; } if (isset($sizeRs->size)) { //************ Step-3-1 大于限定值 发送任务到后台打包 ******// if (Yii::app()->params["pack_product_file_limit"] < $sizeRs->size) { $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_WRITING; $packProductModel->product_name = $msg['name'] . '写作宝'; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $ewId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateWritingDownloadStatus($params['studentIds'],$ewId); echo json_encode(array("success" => 3, "message" => "")); exit; } else { $rs = Curl::post($apiUrl . "/rest/download_week_pdf/index", $params); if (!($rs = json_decode($rs))) { $rs = array( "success" => 0, "message" => "请求接口失败", ); } else { //更新下载时间 if ($rs->success == 1 || $rs->success == 2) { $this->updateWritingDownloadStatus($params['studentIds'],$ewId); } } echo json_encode($rs); exit; } } else { echo json_encode(array("success" => 0, "message" => $sizeRs->message)); exit; } } /** * 更新写作宝下载状态 * @param $studentsIds * @param $weekId */ private function updateWritingDownloadStatus($studentsIds, $weekId) { $time = time(); $sql = "update english_writing_student set is_week_download = 1,week_download_time={$time} where ew_id = '{$weekId}' and student_id in (" . implode(',', $studentsIds) . ") and week_download_time = 0"; $this->sConn->createCommand($sql)->execute(); } /** * 添加写作宝下载任务 */ public function actionAddWritingTask() { $weekId = (string)Req::get("ew_id"); $studentsIds = Req::get("studentsIds"); if (!$weekId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } $sql = "select class_id,grade,create_time,semester_id,name from english_writing where ew_id = '{$weekId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); //*****获取生成的学生***// $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_WRITING); $generateStu = $productDownload->getGenerateStu('english_writing_student', 'ew_id', 'week_pdf_path', 'is_week_pdf', $weekId, $studentsIds); if(!$generateStu){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } $params['studentIds'] = $generateStu['studentIds']; $Sem = new SSemester(); $code = $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '" . $msg['semester_id'] . "'") ->limit(1) ->query() ->read(); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); $intarr = array( "schoolId" => $this->schoolId, "clazzId" => $msg['class_id'], "semester" => $code['refer_code'], "grade" => $msg['grade'], "students" => $studentsIds, "examTime" => $msg['create_time'], "classify" => 32, "subject" => 8 ); //************ Step-1 判断是否有订单 *************// $params = array(); $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } if (Yii::app()->params["limit_open"]) { if (Yii::app()->params["limit_open"]) { $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId); } } //*******产品接口参数******// $params['ewId'] = $weekId; $params['schoolId'] = $this->schoolId; $params['type'] = 7; $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_WRITING; $packProductModel->product_name = $msg['name'] . '写作宝'; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $weekId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateWritingDownloadStatus($params['studentIds'],$weekId); echo json_encode(array("success" => 3, "message" => "")); exit; } /** * 批量写作宝下载 */ public function actionBatchWriting() { $json_params = file_get_contents('php://input'); $params_arr = json_decode($json_params, true); $notFound = 0; foreach ($params_arr as $param) { $weekId = isset($param['ew_id']) ? (string)$param['ew_id'] : null; $params = array(); if (!$weekId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } //*****获取生成的学生***// $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_WRITING); $generateStu = $productDownload->getGenerateStu('english_writing_student', 'ew_id', 'week_pdf_path', 'is_week_pdf', $weekId, array()); if(!$generateStu){ $notFound++; continue; } $params['studentIds'] = $generateStu['studentIds']; $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $sql = "select class_id,grade,create_time,semester_id,name from english_writing where ew_id = '{$weekId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); $params['schoolId'] = $this->schoolId; $params['type'] = 7; $params['ewId'] = $weekId; //**************** Step-2 判断是否已经存在下载任务 ********************// $packTask = $this->getExistTask($weekId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_WRITING, count($params["studentIds"])); if($packTask){ continue; } $packProductModel = new BusinessPackProductTask(); $packProductModel->school_id = $this->schoolId; $packProductModel->auth_username = $this->authUsername; $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_WRITING; $packProductModel->product_name = $msg['name'] . '写作宝'; $packProductModel->subject_id = $this->subjectId; $packProductModel->class_id = $msg['class_id']; $packProductModel->class_name = $classinfo['class_name']; $packProductModel->unique_key = $weekId; $packProductModel->student_count = count($params['studentIds']); $packProductModel->pack_json = json_encode($params); $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index"; $packProductModel->create_time = time(); $packProductModel->save(); $this->updateWritingDownloadStatus($params['studentIds'], $weekId); } if($notFound == count($params_arr)){ echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit(); } echo json_encode(array("success" => 1, "message" => "success")); } /** * 下载写作宝检测卡 */ public function actionGetWritingCard() { $ewId = (string)Req::get("ew_id"); $params = array(); if (!$ewId) { echo json_encode(array("success" => 0, "message" => "缺少参数")); exit(); } $sql = "select student_id from english_writing_student where ew_id = '{$ewId}' and is_card_pdf = 1"; $stuArr = $this->getDbConnection()->createCommand($sql)->queryAll(); if ($stuArr) { foreach ($stuArr as $k => $v) { $params['studentIds'][] = $v['student_id']; } }else{ echo json_encode(array("success" => 0, "message" => "未找到生成的检测卡")); exit(); } $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("success" => 0, "message" => "接口配置信息错误")); exit(); } $params['schoolId'] = $this->schoolId; $params['type'] = 7; $params['ewId'] = $ewId; $params['isMwCard'] = 1; $rs = Curl::post($apiUrl . "/rest/download_week_pdf/index", $params); if (!($rs = json_decode($rs))) { $rs = array( "success" => 0, "message" => "请求接口失败", ); } else { //更新下载时间 if ($rs->success == 1 || $rs->success == 2) { $time = time(); $sql = "update english_writing_student set is_card_download = 1,card_download_time={$time} where ew_id = '{$ewId}' and student_id in (" . implode(',', $params['studentIds']) . ")"; $this->sConn->createCommand($sql)->execute(); } } echo json_encode($rs); exit; } }