getPrintCenter(); //生成任务列表参数 foreach ($params_arr as $param) { $examId = isset($param["examId"])? $param["examId"] : ''; $classId = isset($param["classId"]) ? $param["classId"]:''; $type = isset($param["type"])?$param["type"]:''; $printType = isset($param["printType"])? $param["printType"]:''; $is_isp_student_ids = array(); $is_wbisp_student_ids = array(); $is_wrongbook_student_ids = array(); $generate_count = 0; $download_count = 0; $task_name = ''; $kt_students = array(); $download_students = array(); $generate_students = array(); $pathArr = array(); if (!$examId || !$classId || !$type) { echo json_encode(array("status" => 0, "message" => "缺少参数")); exit(); } if (!in_array($type, array(1, 2, 3))) { echo json_encode(array("status" => 0, "message" => "参数错误[1]")); exit(); } $groupInfo = Exam::model()->getGroupInfo($examId); if (empty($groupInfo)) exit(json_encode(array("status" => 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("status" => 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 ($examInfo['subject_id'] == 8 && $type == 2) { $intarr['classify'] = 3; } $wrongbook_download_students = array(); $two_isp_download_students = array(); $three_isp_download_students = array(); $stu = SStudentPaperRelation::model()->findAll("class_id=:class_id and exam_id=:eid", array(":class_id" => $classId, ":eid" => $examId)); foreach ($stu as $key => $val) { $intarr['students'][] = $val->student_id; if ($val->is_isp_pdf == 1) { $is_isp_student_ids[$val->student_id] = $val->student_id; $pathArr['isp'][] = $val->isp_pdf_path; } if ($val->is_wbisp_pdf == 1) { $is_wbisp_student_ids[$val->student_id] = $val->student_id; $pathArr['wbisp'][] = $val->wbisp_pdf_path; } if ($val->is_wrongbook_pdf == 1) { $is_wrongbook_student_ids[$val->student_id] = $val->student_id; $pathArr['wb'][] = $val->wrongbook_pdf_path; } if($val->is_wrongbook_download == 1){ $wrongbook_download_students[$val->student_id] = $val->student_id; } if($val->is_two_isp_download == 1){ $two_isp_download_students[$val->student_id] = $val->student_id; } if($val->is_three_isp_download == 1){ $three_isp_download_students[$val->student_id] = $val->student_id; } } $dredge_count = 0; if ($printType == 'third_isp') { $params["subjectId"] = $examInfo['subject_id']; } if (Yii::app()->params["limit_open"]) { $basic = imsBasicAuth($this->schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]); $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") { echo json_encode(array("status" => 0, "message" => $rs->errMsg)); exit(); } if (!empty($rs->data)) { $params["studentIds"] = $rs->data; //开通数量 $dredge_count = count($rs->data); $kt_students = $rs->data; } else { echo json_encode(array("status" => 0, "message" => "请先购买商品")); exit(); } } else { $params["studentIds"] = $intarr['students']; } if ($type == 1) { $paths = isset($pathArr['wb']) ? $pathArr['wb'] : array(); //生成错题本学生数量 $generate_count = count($is_wrongbook_student_ids); //已下载数量 $download_count = count($wrongbook_download_students); $task_name = $examInfo->name.'"错题本"'; $download_students = $wrongbook_download_students; $generate_students = $is_wrongbook_student_ids; } if ($type == 2) { $paths = isset($pathArr['isp']) ? $pathArr['isp'] : array(); //生成个性化学习宝学生数量 $generate_count = count($is_isp_student_ids); //已下载数量 $download_count = count($two_isp_download_students); $task_name = $examInfo->name.'"个性化学习方案"'; $download_students = $two_isp_download_students; $generate_students = $is_isp_student_ids; } if ($type == 3) { $paths = isset($pathArr['wbisp']) ? $pathArr['wbisp'] : array(); //生成3步个性化学习宝学生数量 $generate_count = count($is_wbisp_student_ids); //已下载数量 $download_count = count($three_isp_download_students); $task_name = $examInfo->name.'"个性化学习宝"'; $download_students = $three_isp_download_students; $generate_students = $is_wbisp_student_ids; } //FIXME 220519 校验文件是否存在 if(!empty($paths)) self::checkFile($apiUrl, $paths, $classinfo['class_name']); //开通且生成 $enable_students = array_intersect($kt_students,$generate_students); //FIXME 任务数据 待补齐 $task_info[] = array( 'complete_time'=>isset($print_time[0]->add_time) ? date('Y-m-d H:i:s',$print_time[0]->add_time) : '', 'generate_count' => $generate_count, 'dredge_count' => $dredge_count, 'download_count'=>$download_count, 'enable_download_count'=> count($enable_students), 'centerId' => $centerId, 'clazzId' => $classId, 'clazzName'=> $classinfo['class_name'], 'examId' => $examId, 'examName' => $examInfo['name'], 'grade' => $classinfo['grade'], 'printPages'=> 0, //FIXME 待计算 'printPeopleNum' => 0, //FIXME 待计算 'printSheets'=> 0, //FIXME 待计算 'sendTime' => '', 'taskName' => $task_name, 'subjectId'=> in_array($examInfo['subject_id'],array(3,6,51)) ? 3 : $examInfo['subject_id'], 'goodsTypeId'=> $type, 'productId'=> $type, 'url' => '', 'enable_students' => $enable_students, 'download_students' => $download_students, 'pack_json' => json_encode($params), 'pack_api_url'=> $apiUrl . "/rest/download_pdf/index", 'auth_username'=> $this->authUsername, 'group_id' => $groupId ); } echo json_encode(array('status'=>1,'message'=>'ok', 'data'=>$task_info),true); exit; } //发送云印任务 public function actionSendCloudTask() { $json_data = Req::post('json_data'); $is_filter = Req::post('is_filter'); $printType = Req::post('printType'); //FIXME 参数待补齐 if($printType == 'wtb'){ $type = 1; }elseif ($printType == 'isp' || $printType == 'studytrend'){ $type = $printType == "isp" ? 2 : 3; }elseif ($printType == 'third_wb' || $printType == 'studytrend'){ $type = 1; }elseif ($printType == 'third_isp' || $printType == 'studytrend'){ $type = $printType == "isp" ? 2 : 3; }else{ echo json_encode(array('status'=>0,'message'=>'参数错误'));exit; } $json_data = html_entity_decode($json_data); $json_arr = json_decode($json_data, true); $total_student_ids = array(); if(!isset($json_arr['data']) || empty($json_arr['data'])){ echo json_encode(array('status'=>0,'message'=>'网络异常,请重试'));exit; } $time = time(); $transaction = Yii::app()->businessDb->beginTransaction(); try { foreach ($json_arr['data'] as $key => &$item) { //是否过滤已下载的学生 $student_ids = $is_filter ? array_diff($item['enable_students'], $item['download_students']) : $item['enable_students']; //无可下载的学生则不发送任务 if (empty($student_ids)) { throw new Exception($item['taskName'].'学生信息获取失败'); } $total_student_ids = array_merge($student_ids, $total_student_ids); // 总打印页数 总张数 学生打印张数 学生打印页数 $criteria = new CDbCriteria(); $criteria->addInCondition('student_id', $student_ids); $criteria->addCondition('exam_id=:exam_id'); $criteria->addCondition('class_id=:class_id'); $criteria->params[':exam_id'] = $item['examId']; $criteria->params[':class_id'] = $item['clazzId']; $res = SStudentPaperRelation::model()->findAll($criteria); $printPages = 0; $printSheets = 0; $student_info = array(); foreach ($res as $key => $val) { $student_info[$key]['studentId'] = $val->student_id; if ($type == 1) { $student_info[$key]['printPages'] = isset($val->wb_page_num) ? $val->wb_page_num : 0; $student_info[$key]['printSheets'] = (isset($val->wb_sheet_num) && $val->wb_sheet_num ) ? $val->wb_sheet_num : ceil($student_info[$key]['printPages'] / 2) ; $printPages += $student_info[$key]['printPages']; $printSheets += $student_info[$key]['printSheets']; } elseif ($type == 2) { $student_info[$key]['printPages'] = isset($val->isp_page_num) ? $val->isp_page_num : 0; $student_info[$key]['printSheets'] = (isset($val->isp_sheet_num) && $val->isp_sheet_num ) ? $val->isp_sheet_num : ceil($student_info[$key]['printPages'] / 2); $printPages += $student_info[$key]['printPages']; $printSheets += $student_info[$key]['printSheets']; } elseif ($type == 3) { $student_info[$key]['printPages'] = isset($val->wbisp_page_num) ? $val->wbisp_page_num : 0; $student_info[$key]['printSheets'] = (isset($val->wbisp_sheet_num) && $val->wbisp_sheet_num ) ? $val->wbisp_sheet_num : ceil($student_info[$key]['printPages'] / 2); $printPages += $student_info[$key]['printPages']; $printSheets += $student_info[$key]['printSheets']; } } $item['printPeopleNum'] = count($student_info); $item['printPages'] = $printPages; $item['printSheets'] = $printSheets; $item['sendTime'] = date('Y-m-d H:i:s', time()); $item['taskDetailReqDTOList'] = $student_info; $pack_json = json_decode($item['pack_json'],true); $pack_json['studentIds'] = $student_ids; $item['pack_json'] = json_encode($pack_json,true); unset($item['complete_time']); unset($item['generate_count']); unset($item['dredge_count']); unset($item['download_count']); unset($item['enable_download_count']); unset($item['enable_students']); unset($item['download_students']); } $studentNames = SStudentInfo::model()->getStudentNames($total_student_ids); //求学生名字 $taskModelList = array(); foreach ($json_arr['data'] as &$item) { foreach ($item['taskDetailReqDTOList'] as &$value) { $value['studentName'] = isset($studentNames[$value['studentId']]) ? $studentNames[$value['studentId']] : ''; } $cloudPrintModel = new BusinessCloudPrintTask(); $cloudPrintModel->redis_key_perfix = Yii::app()->getId(); $cloudPrintModel->redis_key = 'cloud_print_task_' . $item['clazzId'] . '_' . $item['examId'] . '_' . $printType; $cloudPrintModel->pack_json = $item['pack_json']; $cloudPrintModel->pack_api_url = $item['pack_api_url']; $cloudPrintModel->auth_username = $this->authUsername; $cloudPrintModel->group_id = $item['group_id']; $cloudPrintModel->create_time = $time; $cloudPrintModel->update_time = $time; if(!$cloudPrintModel->save()){ throw new Exception('数据库异常操作'); }else{ $item['coachTaskId'] = $cloudPrintModel->primaryKey; $taskModelList[] = $cloudPrintModel; //更新产品服务流程 时间 ProductProcessTime::model()->updateDownloadTime($student_ids,$type,$item['examId']); } } //请求新增云印任务接口 if(isset($taskModelList)) { $params = array("printTaskReqDTOList" => $json_arr['data']); $this->sendIms($params, $taskModelList); } $transaction->commit(); }catch (Exception $e){ $transaction->rollback(); echo json_encode(array('status' => 0, 'message' => $e->getMessage()));exit; } echo json_encode(array('status' => 1, 'message' => 'ok')); exit; } //生成复习个性化学习宝任务列表 public function actionGenerateFxTfbTask() { set_time_limit(0); $json_params = file_get_contents('php://input'); $params_arr = json_decode($json_params, true); $task_info = array(); //获取云印点 $centerId = $this->getPrintCenter(); //生成任务列表参数 foreach ($params_arr as $param) { $classId = isset($param["classId"]) ? $param["classId"] : ''; $type = isset($param["type"]) ? $param["type"] : ''; $studentsIds = isset($param["studentsIds"]) ? $param["studentsIds"] : null; $taskName = isset($param["taskName"]) ? $param["taskName"] : '未知云印任务'; $download_students_ids = array(); $generate_students_ids = array(); $pathArr = array(); if (!$classId || !$type) { echo json_encode(array("status" => 0, "message" => "缺少参数")); exit(); } if (!in_array($type, array(1, 2, 3))) { echo json_encode(array("status" => 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("status" => 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("status" => 0, "message" => "班级暂无学生")); exit; } if(in_array($this->subjectId,$this->mathSubjectId)){ $subjectId=3; }else{ $subjectId=$this->subjectId; } $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'], "students" => array(), "examTime" => time(), "classify" => 1, "subject" => $subjectId, ); $this->getStuOrder($studentsIds, $intarr, $stuids); } else { $stuids = $studentsIds; } if (!$stuids) { echo json_encode(array("status" => 0, "message" => "所选的学生没有下载权限")); exit; } $params['studentIds'] = $stuids; $_student_product_data=SStudentProductModel::model()->getStudentCreate($studentsIds,$subjectId,$type,$this->semesterId); if (!$_student_product_data) { echo json_encode(array("status" => 0, "message" => "所选的学生尚未生成PDF")); exit; } foreach ($_student_product_data as $key=>$val){ $generate_students_ids[$key] = $val['student_id']; if($val['pdf_path']){ $pathArr[] = $val['pdf_path']; } } $download_students=SStudentProductModel::model()->getStudentCreateDown($studentsIds,$subjectId,$type,$this->semesterId); foreach ($download_students as $key=>$val){ $download_students_ids[$key] = $val['student_id']; } } //FIXME 20220519 文件地址校验 if($pathArr) self::checkFile($apiUrl, $pathArr, $classinfo['class_name']); $generate_count = isset($_student_product_data) ? count($_student_product_data) : 0; $dredge_count = isset($stuids) ? count($stuids) : 0; $download_count = isset($download_students) ? count($download_students) : 0; $enable_students = array_intersect($stuids,$generate_students_ids); //FIXME 任务数据 待补齐 $task_info[] = array( 'complete_time'=>isset($_student_product_data[0]['pdf_time']) ? date('Y-m-d ', $_student_product_data[0]['pdf_time']) : '', 'generate_count' => $generate_count, 'dredge_count' => $dredge_count, 'download_count'=> $download_count, 'enable_download_count'=> count($enable_students), 'centerId' => $centerId, 'clazzId' => $classId, 'clazzName'=> isset($classinfo['class_name'])?$classinfo['class_name']:'', 'examId' => 0, 'examName' => '', 'grade' => isset($classinfo['grade']) ? $classinfo['grade'] : '', 'printPages'=> 0, //FIXME 待计算 'printPeopleNum' => 0, //FIXME 待计算 'printSheets'=> 0, //FIXME 待计算 'sendTime' => '', 'taskName' => $taskName, 'subjectId'=> $this->subjectId, 'goodsTypeId'=> 3, 'productId'=> 10003, 'url' => '', 'enable_students' => $enable_students, 'download_students' => $download_students_ids, 'semester_id' => isset($nowsem['semester_id']) ? $nowsem['semester_id'] : 0, 'type' => $type, 'pack_json' => json_encode($params), 'pack_api_url'=> $apiUrl . "/rest/download_sp/index", 'auth_username'=> $this->authUsername, ); } echo json_encode(array('status'=>1,'message'=>'ok', 'data'=>$task_info),true); exit; } //发送复习个性化学习宝云印任务 public function actionSendFxTfbTask() { $json_data = Req::post('json_data'); $is_filter = Req::post('is_filter'); $json_arr = json_decode((html_entity_decode($json_data)), true); $total_student_ids = array(); if(!isset($json_arr['data']) || empty($json_arr['data'])){ echo json_encode(array('status'=>0,'message'=>'网络异常,请重试'));exit; } $time = time(); $transaction = Yii::app()->businessDb->beginTransaction(); try { foreach ($json_arr['data'] as $key => &$item) { //是否过滤已下载的学生 $student_ids = $is_filter ? array_diff($item['enable_students'], $item['download_students']) : $item['enable_students']; //无可下载的学生则不发送任务 if (empty($student_ids)) { continue; } $total_student_ids = array_merge($student_ids, $total_student_ids); // 总打印页数 总张数 学生打印张数 学生打印页数 if(in_array($this->subjectId,$this->mathSubjectId)){ $subjectId=3; }else{ $subjectId=$this->subjectId; } $res=SStudentProductModel::model()->getStudentCreate($student_ids,$subjectId,$item['type'],$this->semesterId,0); $printPages = 0; $printSheets = 0; $student_info = array(); if (empty($res) || !is_array($res)) { echo json_encode(array('status' => 0, 'message' => '网络异常,请稍后重试')); exit; } foreach ($res as $key => $val) { $student_info[$key]['studentId'] = $val['student_id']; $student_info[$key]['printPages'] = isset($val['pdf_page_size']) ? $val['pdf_page_size'] : 0; $student_info[$key]['printSheets'] = ceil($student_info[$key]['printPages'] / 2); $printPages += $student_info[$key]['printPages']; $printSheets += $student_info[$key]['printSheets']; } $item['printPages'] = $printPages; $item['printSheets'] = $printSheets; $item['printPeopleNum'] = count($student_info); $item['sendTime'] = date('Y-m-d H:i:s', time()); $item['taskDetailReqDTOList'] = $student_info; $pack_json = json_decode($item['pack_json'],true); $pack_json['studentIds'] = $student_ids; $item['pack_json'] = json_encode($pack_json,true); unset($item['complete_time']); unset($item['generate_count']); unset($item['dredge_count']); unset($item['download_count']); unset($item['enable_download_count']); unset($item['enable_students']); unset($item['download_students']); } $studentNames = SStudentInfo::model()->getStudentNames($total_student_ids); //求学生名字 $taskModelList = array(); foreach ($json_arr['data'] as &$item) { foreach ($item['taskDetailReqDTOList'] as &$value) { $value['studentName'] = isset($studentNames[$value['studentId']]) ? $studentNames[$value['studentId']] : ''; } $cloudPrintModel = new BusinessCloudPrintTask(); $cloudPrintModel->redis_key_perfix = Yii::app()->getId(); $cloudPrintModel->redis_key = "cloud_print_task_fx_tfb_".$item['clazzId'].'_'.$item['semester_id'].'_'.$item['type']; $cloudPrintModel->pack_json = $item['pack_json']; $cloudPrintModel->pack_api_url = $item['pack_api_url']; $cloudPrintModel->auth_username = $this->authUsername; $cloudPrintModel->create_time = $time; $cloudPrintModel->update_time = $time; if (!$cloudPrintModel->save()) { throw new Exception('数据库异常操作'); } else { $item['coachTaskId'] = $cloudPrintModel->primaryKey; $taskModelList[] = $cloudPrintModel; } } //请求新增云印任务接口 if(isset($taskModelList)) { $params = array("printTaskReqDTOList" => $json_arr['data']); $this->sendIms($params, $taskModelList); } $transaction->commit(); }catch (Exception $e){ $transaction->rollback(); echo json_encode(array('status' => 0, 'message' => $e->getMessage()));exit; } echo json_encode(array('status' => 1, 'message' => 'ok')); exit; } /** * 获取学生是否有订单 * @param $studentsIds * @param $intarr * @param $stuids */ protected function getStuOrder($studentsIds,$intarr,&$stuids){ foreach(array(1,2,3) as $type){ $intarr['classify'] = $type; $intarr['students'] = array_diff($studentsIds,$stuids); if(!$intarr['students']){ break; }else{ $intarr['students'] = array_values($intarr['students']); } $basic = imsBasicAuth($this->schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]); $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 (!empty($rs->data)) { $stuids = array_merge($stuids,$rs->data); } } } //获取云印点 protected function getPrintCenter(){ //获取云印点 $http1 = http('cloud-print/task/coach/center','GET', $this->authUsername, array()); $response1 = formatResponse($http1); if(isset($response1['data']['centerId']) && is_numeric($response1['data']['centerId'])) { $centerId = $response1['data']['centerId']; }else{ echo json_encode(array('status' => 0, 'message' => '云印点未开通'));exit; } return $centerId; } //初始化英语晨读词汇 云印任务 public function actionGenerateMrvPrint() { set_time_limit(0); $json_params = file_get_contents('php://input'); $params_arr = json_decode($json_params, true); $task_info = array(); //获取云印点 $centerId = $this->getPrintCenter(); foreach ($params_arr as $param) { $weekId = isset($param['weekId']) ? $param['weekId'] : null; $params = array(); if (!$weekId) { echo json_encode(array("status" => 0, "message" => "缺少参数")); exit(); } $studentsIds = array(); $download_students_ids = array(); //已下载的学生id $pathArr = array(); //查找已生成学生 $sql = "select student_id,is_week_download,week_pdf_time,week_pdf_path from english_week_student where week_id = '{$weekId}' and is_week_pdf = 1 and student_id>0"; $stuArr = $this->sConn->createCommand($sql)->queryAll(); if ($stuArr) { foreach ($stuArr as $k => $v) { $pathArr[] = $v['week_pdf_path']; $studentsIds[] = $v['student_id']; if($v['is_week_download']) { $download_students_ids[] = $v['student_id']; } } } $generate_count = count($studentsIds); if (!$studentsIds || empty($studentsIds)) { echo json_encode(array("status" => 0, "message" => "无生成的学生")); exit(); } $generate_students_ids = $studentsIds; //已生成的学生id $params['weekId'] = $weekId; $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("status" => 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(); $intarr = array( "schoolId" => $this->schoolId, "clazzId" => $msg['class_id'], "semester" => $code['refer_code'], "grade" => $msg['grade'], "students" => $studentsIds, "examTime" => $msg['create_time'], "classify" => array(3,12), "subject" => 8 ); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); //FIXME 20220519文件校验 if($pathArr) self::checkFile($apiUrl, $pathArr, $classinfo['class_name']); $dredge_count = 0; //查询开通学生 $this->checkOrder($intarr,$studentsIds,$params,$dredge_count); $params['schoolId'] = $this->schoolId; $params['type'] = 1; $enable_students = array_intersect($params["studentIds"],$generate_students_ids); //FIXME 任务数据 待补齐 $task_info[] = array( 'complete_time'=>isset($stuArr[0]['week_pdf_time']) ? date('Y-m-d H:i:s',$stuArr[0]['week_pdf_time']) : '', 'generate_count' => $generate_count, 'dredge_count' => $dredge_count, 'download_count'=>count($download_students_ids), 'enable_download_count'=> count($enable_students), 'centerId' => $centerId, 'clazzId' => $msg['class_id'], 'clazzName'=> $classinfo['class_name'], 'examId' => 0, 'examName' => '', 'goodsName'=> '英语晨读词汇', 'grade' => $classinfo['grade'], 'printPages'=> 0, //FIXME 待计算 'printPeopleNum' => 0, //FIXME 待计算 'printSheets'=> 0, //FIXME 待计算 'sendTime' => '', 'taskName' => $msg['name'], 'subjectId'=> 8, 'goodsTypeId'=> 12, 'productId'=> 10001, 'url' => '', 'enable_students' => $enable_students, 'download_students' => $download_students_ids, 'pack_json' => json_encode($params), 'pack_api_url'=> $apiUrl . "/rest/download_week_pdf/index", 'auth_username'=> $this->authUsername, 'week_id' => $weekId ); } echo json_encode(array('status'=>1,'message'=>'ok', 'data'=>$task_info),true); exit; } //发送英语晨读词汇云印任务 public function actionSendMrvPrintTask() { $json_data = Req::post('json_data'); $is_filter = Req::post('is_filter'); $json_data = html_entity_decode($json_data); $json_arr = json_decode($json_data, true); $total_student_ids = array(); if(!isset($json_arr['data']) || empty($json_arr['data'])){ echo json_encode(array('status'=>0,'message'=>'网络异常,请重试'));exit; } $time = time(); $transaction = Yii::app()->businessDb->beginTransaction(); try { foreach ($json_arr['data'] as $key => &$item) { //是否过滤已下载的学生 $student_ids = $is_filter ? array_diff($item['enable_students'], $item['download_students']) : $item['enable_students']; //无可下载的学生则不发送任务 if (empty($student_ids)) { continue; } $str_ids = implode(',',$student_ids); $total_student_ids = array_merge($student_ids, $total_student_ids); // 总打印页数 总张数 学生打印张数 学生打印页数 $sql = "select student_id,is_week_download,week_pdf_time,week_page_num,week_sheet_num from english_week_student where student_id in ({$str_ids}) and week_id = '{$item['week_id']}' and is_week_pdf = 1"; $res = $this->sConn->createCommand($sql)->queryAll(); $printPages = 0; $printSheets = 0; $student_info = array(); if (empty($res) || !is_array($res)) { echo json_encode(array('status' => 0, 'message' => '网络异常,请稍后重试')); exit; } foreach ($res as $key => $val) { $student_info[$key]['studentId'] = $val['student_id']; $student_info[$key]['printPages'] = isset($val['week_page_num']) ? $val['week_page_num'] : 0; $student_info[$key]['printSheets'] = isset($val['week_sheet_num']) ? $val['week_sheet_num'] : 0; $printPages += $student_info[$key]['printPages']; $printSheets += $student_info[$key]['printSheets']; } $item['printPages'] = $printPages; $item['printSheets'] = $printSheets; $item['printPeopleNum'] = count($student_info); $item['sendTime'] = date('Y-m-d H:i:s', time()); $item['taskDetailReqDTOList'] = $student_info; $pack_json = json_decode($item['pack_json'],true); $pack_json['studentIds'] = $student_ids; $item['pack_json'] = json_encode($pack_json,true); unset($item['complete_time']); unset($item['generate_count']); unset($item['dredge_count']); unset($item['download_count']); unset($item['enable_download_count']); unset($item['enable_students']); unset($item['download_students']); //FIXME 1227 更新下载时间 $time = time(); if($student_ids){ $sql = "update english_week_student set is_week_download = 1,week_download_time={$time} where week_id = '{$item['week_id']}' and student_id in (".implode(',',$student_ids).")"; $this->sConn->createCommand($sql)->execute(); } } $studentNames = SStudentInfo::model()->getStudentNames($total_student_ids); //求学生名字 $taskModelList = array(); foreach ($json_arr['data'] as &$item) { foreach ($item['taskDetailReqDTOList'] as &$value) { $value['studentName'] = isset($studentNames[$value['studentId']]) ? $studentNames[$value['studentId']] : ''; } $cloudPrintModel = new BusinessCloudPrintTask(); $cloudPrintModel->redis_key_perfix = Yii::app()->getId(); $cloudPrintModel->redis_key = "cloud_print_task_mrv".$item['week_id']; $cloudPrintModel->pack_json = $item['pack_json']; $cloudPrintModel->pack_api_url = $item['pack_api_url']; $cloudPrintModel->auth_username = $this->authUsername; $cloudPrintModel->create_time = $time; $cloudPrintModel->update_time = $time; if (!$cloudPrintModel->save()) { throw new Exception('数据库异常操作'); } else { $item['coachTaskId'] = $cloudPrintModel->primaryKey; $taskModelList[] = $cloudPrintModel; } } //请求新增云印任务接口 if(isset($taskModelList)) { $params = array("printTaskReqDTOList" => $json_arr['data']); $this->sendIms($params, $taskModelList); } $transaction->commit(); }catch (Exception $e){ $transaction->rollback(); echo json_encode(array('status' => 0, 'message' => $e->getMessage()));exit; } echo json_encode(array('status' => 1, 'message' => 'ok')); exit; } //初始化二轮复习提分手册 云印任务 public function actionGenerateMathReview() { set_time_limit(0); $json_params = file_get_contents('php://input'); $params_arr = json_decode($json_params, true); $task_info = array(); //获取云印点 $centerId = $this->getPrintCenter(); foreach ($params_arr as $param) { $mr_id = isset($param['mr_id']) ? $param['mr_id'] : null; //TODO 参数待修改 $params = array(); if (!$mr_id) { echo json_encode(array("status" => 0, "message" => "缺少参数")); exit(); } $studentsIds = array(); $download_students_ids = array(); //已下载的学生id $pathArr = array(); //查找已生成学生 $sql = "select student_id,is_review_download,review_pdf_time,review_pdf_path from math_review_student where mr_id = '{$mr_id}' and is_review_pdf = 1"; //TODO 参数待修改 $stuArr = $this->sConn->createCommand($sql)->queryAll(); if ($stuArr) { foreach ($stuArr as $k => $v) { $pathArr[] = $v['review_pdf_path']; $studentsIds[] = $v['student_id']; if($v['is_review_download']) { $download_students_ids[] = $v['student_id']; } } } $generate_count = count($studentsIds); if (!$studentsIds || empty($studentsIds)) { echo json_encode(array("status" => 0, "message" => "无生成的学生")); exit(); } $generate_students_ids = $studentsIds; //已生成的学生id //查找已下载学生 $params['mrId'] = $mr_id; $sql = "select class_id,grade,create_time,semester_id,name,school_group_id from math_review_setting where mr_id = '{$mr_id}'"; $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(); $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(); } $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); //FIXME 20220519文件校验 if($pathArr) self::checkFile($apiUrl, $pathArr, $classinfo['class_name']); $dredge_count = 0; //查询开通学生 $this->checkOrder($intarr,$studentsIds,$params,$dredge_count); $params['schoolId'] = $this->schoolId; $params['type'] = 1; $enable_students = array_intersect($params["studentIds"],$generate_students_ids); //FIXME 任务数据 待补齐 $task_info[] = array( 'complete_time'=>isset($stuArr[0]['review_pdf_time']) ? date('Y-m-d H:i:s',$stuArr[0]['review_pdf_time']) : '', 'generate_count' => $generate_count, 'dredge_count' => $dredge_count, 'download_count'=>count($download_students_ids), 'enable_download_count'=> count($enable_students), 'centerId' => $centerId, 'clazzId' => $msg['class_id'], 'clazzName'=> $classinfo['class_name'], 'examId' => 0, 'examName' => '', 'goodsName'=> '二轮复习提分手册', 'grade' => $classinfo['grade'], 'printPages'=> 0, //FIXME 待计算 'printPeopleNum' => 0, //FIXME 待计算 'printSheets'=> 0, //FIXME 待计算 'sendTime' => '', 'taskName' => $msg['name'], 'subjectId'=> 3, 'goodsTypeId'=> 5, 'productId'=> 5, 'url' => '', 'enable_students' => $enable_students, 'download_students' => $download_students_ids, 'pack_json' => json_encode($params), 'pack_api_url'=> $apiUrl . "/rest/download_math_pdf/index", 'auth_username'=> $this->authUsername, 'mr_id' => $mr_id ); } echo json_encode(array('status'=>1,'message'=>'ok', 'data'=>$task_info),true); exit; } //发送二轮复习提分手册云印任务 public function actionSendReviewTask() { $json_data = Req::post('json_data'); $is_filter = Req::post('is_filter'); $json_data = html_entity_decode($json_data); $json_arr = json_decode($json_data, true); $total_student_ids = array(); if(!isset($json_arr['data']) || empty($json_arr['data'])){ echo json_encode(array('status'=>0,'message'=>'网络异常,请重试'));exit; } $time = time(); $transaction = Yii::app()->businessDb->beginTransaction(); try { foreach ($json_arr['data'] as $key => &$item) { //是否过滤已下载的学生 $student_ids = $is_filter ? array_diff($item['enable_students'], $item['download_students']) : $item['enable_students']; //无可下载的学生则不发送任务 if (empty($student_ids)) { continue; } $str_ids = implode(',',$student_ids); $total_student_ids = array_merge($student_ids, $total_student_ids); // 总打印页数 总张数 学生打印张数 学生打印页数 $sql = "select student_id,is_review_download,review_pdf_time,review_page_num,review_sheet_num from math_review_student where student_id in ({$str_ids}) and mr_id = '{$item['mr_id']}' and is_review_pdf = 1"; $res = $this->sConn->createCommand($sql)->queryAll(); $printPages = 0; $printSheets = 0; $student_info = array(); if (empty($res) || !is_array($res)) { echo json_encode(array('status' => 0, 'message' => '网络异常,请稍后重试')); exit; } foreach ($res as $key => $val) { $student_info[$key]['studentId'] = $val['student_id']; $student_info[$key]['printPages'] = isset($val['review_page_num']) ? $val['review_page_num'] : 0; $student_info[$key]['printSheets'] = (isset($val['review_sheet_num']) && $val['review_sheet_num']) ? $val['review_sheet_num'] : ceil($student_info[$key]['printPages'] / 2); $printPages += $student_info[$key]['printPages']; $printSheets += $student_info[$key]['printSheets']; } $item['printPages'] = $printPages; $item['printSheets'] = $printSheets; $item['printPeopleNum'] = count($student_info); $item['sendTime'] = date('Y-m-d H:i:s', time()); $item['taskDetailReqDTOList'] = $student_info; $pack_json = json_decode($item['pack_json'],true); $pack_json['studentIds'] = $student_ids; $item['pack_json'] = json_encode($pack_json,true); unset($item['complete_time']); unset($item['generate_count']); unset($item['dredge_count']); unset($item['download_count']); unset($item['enable_download_count']); unset($item['enable_students']); unset($item['download_students']); } $studentNames = SStudentInfo::model()->getStudentNames($total_student_ids); //求学生名字 $taskModelList = array(); foreach ($json_arr['data'] as &$item) { foreach ($item['taskDetailReqDTOList'] as &$value) { $value['studentName'] = isset($studentNames[$value['studentId']]) ? $studentNames[$value['studentId']] : ''; } $cloudPrintModel = new BusinessCloudPrintTask(); $cloudPrintModel->redis_key_perfix = Yii::app()->getId(); $cloudPrintModel->redis_key = "cloud_print_task_math_review_".$item['mr_id'];//TODO key修改 $cloudPrintModel->pack_json = $item['pack_json']; $cloudPrintModel->pack_api_url = $item['pack_api_url']; $cloudPrintModel->auth_username = $this->authUsername; $cloudPrintModel->create_time = $time; $cloudPrintModel->update_time = $time; if (!$cloudPrintModel->save()) { throw new Exception('数据库异常操作'); } else { $item['coachTaskId'] = $cloudPrintModel->primaryKey; $taskModelList[] = $cloudPrintModel; } } //请求新增云印任务接口 if(isset($taskModelList)) { $params = array("printTaskReqDTOList" => $json_arr['data']); $this->sendIms($params, $taskModelList); } $transaction->commit(); }catch (Exception $e){ $transaction->rollback(); echo json_encode(array('status' => 0, 'message' => $e->getMessage()));exit; } echo json_encode(array('status' => 1, 'message' => 'ok')); exit; } //初始化英语外刊云印任务 public function actionGenerateEnglishReading() { set_time_limit(0); $json_params = file_get_contents('php://input'); $params_arr = json_decode($json_params, true); $task_info = array(); //获取云印点 $centerId = $this->getPrintCenter(); foreach ($params_arr as $param) { $weekId = isset($param['weekId']) ? $param['weekId'] : null; $params = array(); if (!$weekId) { echo json_encode(array("status" => 0, "message" => "缺少参数")); exit(); } $studentsIds = array(); $download_students_ids = array(); //已下载的学生id $pathArr = array(); //查找已生成学生 $sql = "select student_id,is_week_download,week_pdf_time,week_pdf_path from english_reading_student where week_id = '{$weekId}' and is_week_pdf = 1"; $stuArr = $this->sConn->createCommand($sql)->queryAll(); if ($stuArr) { foreach ($stuArr as $k => $v) { $pathArr[] = $v['week_pdf_path']; $studentsIds[] = $v['student_id']; if($v['is_week_download']) { $download_students_ids[] = $v['student_id']; } } } $generate_count = count($studentsIds); if (!$studentsIds || empty($studentsIds)) { echo json_encode(array("status" => 0, "message" => "无生成的学生")); exit(); } $generate_students_ids = $studentsIds; //已生成的学生id //查找已下载学生 $params['weekId'] = $weekId; $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("status" => 0, "message" => "接口配置信息错误")); exit(); } $sql = "select class_id,er.grade,er.create_time,er.semester_id,er.name,ers.category,ers.product_type from english_reading er left join english_reading_setting ers on er.reading_id= ers.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; }elseif($msg['product_type']==2){ $classify=61; }elseif($msg['product_type']==3){ $classify=58; } } $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 ); $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); $dredge_count = 0; //FIXME 20220519文件校验 if($pathArr) self::checkFile($apiUrl, $pathArr, $classinfo['class_name']); //查询开通学生 $this->checkOrder($intarr,$studentsIds,$params,$dredge_count); $params['schoolId'] = $this->schoolId; $params['type'] = 3; $enable_students = array_intersect($params["studentIds"],$generate_students_ids); //FIXME 任务数据 待补齐 $task_info[] = array( 'complete_time'=>isset($stuArr[0]['week_pdf_time']) ? date('Y-m-d H:i:s',$stuArr[0]['week_pdf_time']) : '', 'generate_count' => $generate_count, 'dredge_count' => $dredge_count, 'download_count'=>count($download_students_ids), 'enable_download_count'=> count($enable_students), 'centerId' => $centerId, 'clazzId' => $msg['class_id'], 'clazzName'=> $classinfo['class_name'], 'examId' => 0, 'examName' => '', 'goodsName'=> '外刊分级每周练', 'grade' => $classinfo['grade'], 'printPages'=> 0, //FIXME 待计算 'printPeopleNum' => 0, //FIXME 待计算 'printSheets'=> 0, //FIXME 待计算 'sendTime' => '', 'taskName' => $msg['name'], 'subjectId'=> 8, 'goodsTypeId'=> $classify, 'productId'=> $classify, 'url' => '', 'enable_students' => $enable_students, 'download_students' => $download_students_ids, 'pack_json' => json_encode($params), 'pack_api_url'=> $apiUrl . "/rest/download_week_pdf/index", 'auth_username'=> $this->authUsername, 'week_id' => $weekId ); } echo json_encode(array('status'=>1,'message'=>'ok', 'data'=>$task_info),true); exit; } //发送英语外刊产品云印任务 public function actionSendEnglishReadingTask() { $json_data = Req::post('json_data'); $is_filter = Req::post('is_filter'); $json_data = html_entity_decode($json_data); $json_arr = json_decode($json_data, true); $total_student_ids = array(); if(!isset($json_arr['data']) || empty($json_arr['data'])){ echo json_encode(array('status'=>0,'message'=>'网络异常,请重试'));exit; } $time = time(); $transaction = Yii::app()->businessDb->beginTransaction(); try { foreach ($json_arr['data'] as $key => &$item) { //是否过滤已下载的学生 $student_ids = $is_filter ? array_diff($item['enable_students'], $item['download_students']) : $item['enable_students']; //无可下载的学生则不发送任务 if (empty($student_ids)) { continue; } $str_ids = implode(',',$student_ids); $total_student_ids = array_merge($student_ids, $total_student_ids); // 总打印页数 总张数 学生打印张数 学生打印页数 $sql = "select student_id,is_week_download,week_pdf_time,week_page_num,week_sheet_num from english_reading_student where student_id in ({$str_ids}) and week_id = '{$item['week_id']}' and is_week_pdf = 1"; $res = $this->sConn->createCommand($sql)->queryAll(); $printPages = 0; $printSheets = 0; $student_info = array(); if (empty($res) || !is_array($res)) { echo json_encode(array('status' => 0, 'message' => '网络异常,请稍后重试')); exit; } foreach ($res as $key => $val) { $student_info[$key]['studentId'] = $val['student_id']; $student_info[$key]['printPages'] = isset($val['week_page_num']) ? $val['week_page_num'] : 0; $student_info[$key]['printSheets'] = isset($val['week_sheet_num']) ? $val['week_sheet_num'] : 0; $printPages += $student_info[$key]['printPages']; $printSheets += $student_info[$key]['printSheets']; } $item['printPages'] = $printPages; $item['printSheets'] = $printSheets; $item['printPeopleNum'] = count($student_info); $item['sendTime'] = date('Y-m-d H:i:s', time()); $item['taskDetailReqDTOList'] = $student_info; $pack_json = json_decode($item['pack_json'],true); $pack_json['studentIds'] = $student_ids; $item['pack_json'] = json_encode($pack_json,true); unset($item['complete_time']); unset($item['generate_count']); unset($item['dredge_count']); unset($item['download_count']); unset($item['enable_download_count']); unset($item['enable_students']); unset($item['download_students']); $time = time(); if($student_ids){ $sql = "update english_reading_student set is_week_download = 1,week_download_time={$time} where week_id = '{$item['week_id']}' and student_id in (".implode(',',$student_ids).")"; $this->sConn->createCommand($sql)->execute(); } } $studentNames = SStudentInfo::model()->getStudentNames($total_student_ids); //求学生名字 foreach ($json_arr['data'] as &$item) { foreach ($item['taskDetailReqDTOList'] as &$value) { $value['studentName'] = isset($studentNames[$value['studentId']]) ? $studentNames[$value['studentId']] : ''; } $cloudPrintModel = new BusinessCloudPrintTask(); $cloudPrintModel->redis_key_perfix = Yii::app()->getId(); $cloudPrintModel->redis_key = "cloud_print_task_english_reading".$item['week_id']; $cloudPrintModel->pack_json = $item['pack_json']; $cloudPrintModel->pack_api_url = $item['pack_api_url']; $cloudPrintModel->auth_username = $this->authUsername; $cloudPrintModel->create_time = $time; $cloudPrintModel->update_time = $time; if (!$cloudPrintModel->save()) { throw new Exception('数据库异常操作'); } else { $item['coachTaskId'] = $cloudPrintModel->primaryKey; $taskModelList[] = $cloudPrintModel; } } //请求新增云印任务接口 if(isset($taskModelList)) { $params = array("printTaskReqDTOList" => $json_arr['data']); $this->sendIms($params, $taskModelList); } $transaction->commit(); }catch (Exception $e){ $transaction->rollback(); echo json_encode(array('status' => 0, 'message' => $e->getMessage()));exit; } echo json_encode(array('status' => 1, 'message' => 'ok')); exit; } //初始化假期报告云印任务 public function actionGenerateHolidayExport() { set_time_limit(0); $json_params = file_get_contents('php://input'); $params_arr = json_decode($json_params, true); $task_info = array(); //获取云印点 $centerId = $this->getPrintCenter(); foreach ($params_arr as $param) { $reportId = isset($param['reportId']) ? $param['reportId'] : null; $params = array(); if (!$reportId) { echo json_encode(array("status" => 0, "message" => "缺少参数")); exit(); } $studentsIds = array(); $download_students_ids = array(); //已下载的学生id $pathArr = array(); //查找已生成学生 $sql = "select student_id,is_report_pdf,report_pdf_time,report_pdf_path,is_report_download from holiday_report_student where report_id = '{$reportId}' and is_report_pdf = 1"; $stuArr = $this->sConn->createCommand($sql)->queryAll(); if ($stuArr) { foreach ($stuArr as $k => $v) { $pathArr[] = $v['report_pdf_path']; $studentsIds[] = $v['student_id']; if($v['is_report_download']) { $download_students_ids[] = $v['student_id']; } } } $generate_count = count($studentsIds); if (!$studentsIds || empty($studentsIds)) { echo json_encode(array("status" => 0, "message" => "无生成的学生")); exit(); } $generate_students_ids = $studentsIds; //已生成的学生id //查找已下载学生 $params['reportId'] = $reportId; $sql = "select class_id,grade,create_time,semester_id,school_group_id from holiday_report_setting where report_id = '{$reportId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); if (!$msg) { echo json_encode(array("success" => 0, "message" => "假期报告设置信息错误")); exit(); } else { $school_group_id = $msg['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; } $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'])); //FIXME 20220519文件校验 if($pathArr) self::checkFile($apiUrl, $pathArr, $classinfo['class_name']); //查询开通学生 FIXME 假期报告不做订单校验 //$this->checkOrder($intarr,$studentsIds,$params,$dredge_count, true); $params["studentIds"] = $studentsIds; //开通数量 $dredge_count = count($studentsIds); $params['schoolId'] = $this->schoolId; $params['type'] = 4; $enable_students = array_intersect($params["studentIds"],$generate_students_ids); //FIXME 任务数据 待补齐 $task_info[] = array( 'complete_time'=>isset($stuArr[0]['report_pdf_time']) ? date('Y-m-d H:i:s',$stuArr[0]['report_pdf_time']) : '', 'generate_count' => $generate_count, 'dredge_count' => $dredge_count, 'download_count'=>count($download_students_ids), 'enable_download_count'=> count($enable_students), 'centerId' => $centerId, 'clazzId' => $msg['class_id'], 'clazzName'=> $classinfo['class_name'], 'examId' => 0, 'examName' => '', 'goodsName'=> '假期总结报告', //商品类目 TODO 'grade' => $classinfo['grade'], 'printPages'=> 0, //FIXME 待计算 'printPeopleNum' => 0, //FIXME 待计算 'printSheets'=> 0, //FIXME 待计算 'sendTime' => '', 'taskName' => $classinfo['class_name'].$code['semester_name'].'假期总结报告', 'subjectId'=> 3, 'goodsTypeId'=> 3, //商品类目 'productId'=> 10002, 'url' => '', 'enable_students' => $enable_students, 'download_students' => $download_students_ids, 'pack_json' => json_encode($params), 'pack_api_url'=> $apiUrl . "/rest/download_week_pdf/index", 'auth_username'=> $this->authUsername, 'report_id' => $reportId ); } echo json_encode(array('status'=>1,'message'=>'ok', 'data'=>$task_info),true); exit; } //发送假期报告云印任务 public function actionSendHolidayReport() { $json_data = Req::post('json_data'); $is_filter = Req::post('is_filter'); $json_data = html_entity_decode($json_data); $json_arr = json_decode($json_data, true); $total_student_ids = array(); if(!isset($json_arr['data']) || empty($json_arr['data'])){ echo json_encode(array('status'=>0,'message'=>'网络异常,请重试'));exit; } $time = time(); $transaction = Yii::app()->businessDb->beginTransaction(); try { foreach ($json_arr['data'] as $key => &$item) { //是否过滤已下载的学生 $student_ids = $is_filter ? array_diff($item['enable_students'], $item['download_students']) : $item['enable_students']; //无可下载的学生则不发送任务 if (empty($student_ids)) { continue; } $str_ids = implode(',',$student_ids); $total_student_ids = array_merge($student_ids, $total_student_ids); // 总打印页数 总张数 学生打印张数 学生打印页数 $sql = "select student_id,is_report_download,report_pdf_time,report_page_num from holiday_report_student where student_id in ({$str_ids}) and report_id = '{$item['report_id']}' and is_report_pdf = 1"; $res = $this->sConn->createCommand($sql)->queryAll(); $printPages = 0; $printSheets = 0; $student_info = array(); if (empty($res) || !is_array($res)) { echo json_encode(array('status' => 0, 'message' => '网络异常,请稍后重试')); exit; } foreach ($res as $key => $val) { $student_info[$key]['studentId'] = $val['student_id']; $student_info[$key]['printPages'] = isset($val['report_page_num']) ? $val['report_page_num'] : 0; $student_info[$key]['printSheets'] = ceil($student_info[$key]['printPages'] / 2); $printPages += $student_info[$key]['printPages']; $printSheets += $student_info[$key]['printSheets']; } $item['printPages'] = $printPages; $item['printSheets'] = $printSheets; $item['printPeopleNum'] = count($student_info); $item['sendTime'] = date('Y-m-d H:i:s', time()); $item['taskDetailReqDTOList'] = $student_info; $pack_json = json_decode($item['pack_json'],true); $pack_json['studentIds'] = $student_ids; $item['pack_json'] = json_encode($pack_json,true); unset($item['complete_time']); unset($item['generate_count']); unset($item['dredge_count']); unset($item['download_count']); unset($item['enable_download_count']); unset($item['enable_students']); unset($item['download_students']); } $studentNames = SStudentInfo::model()->getStudentNames($total_student_ids); //求学生名字 $taskModelList = array(); foreach ($json_arr['data'] as &$item) { foreach ($item['taskDetailReqDTOList'] as &$value) { $value['studentName'] = isset($studentNames[$value['studentId']]) ? $studentNames[$value['studentId']] : ''; } $cloudPrintModel = new BusinessCloudPrintTask(); $cloudPrintModel->redis_key_perfix = Yii::app()->getId(); $cloudPrintModel->redis_key = "cloud_print_holiday_report_".$item['report_id'];//TODO key修改 $cloudPrintModel->pack_json = $item['pack_json']; $cloudPrintModel->pack_api_url = $item['pack_api_url']; $cloudPrintModel->auth_username = $this->authUsername; $cloudPrintModel->create_time = $time; $cloudPrintModel->update_time = $time; if (!$cloudPrintModel->save()) { throw new Exception('数据库异常操作'); } else { $item['coachTaskId'] = $cloudPrintModel->primaryKey; $taskModelList[] = $cloudPrintModel; } } //请求新增云印任务接口 if(isset($taskModelList)) { $params = array("printTaskReqDTOList" => $json_arr['data']); $this->sendIms($params, $taskModelList); } $transaction->commit(); }catch (Exception $e){ $transaction->rollback(); echo json_encode(array('status' => 0, 'message' => $e->getMessage()));exit; } echo json_encode(array('status' => 1, 'message' => 'ok')); exit; } //初始化好题本 云印任务 public function actionGenerateHtb() { set_time_limit(0); $json_params = file_get_contents('php://input'); $params_arr = json_decode($json_params, true); $task_info = array(); //获取云印点 $centerId = $this->getPrintCenter(); foreach ($params_arr as $param) { $htb_id = isset($param['htb_id']) ? $param['htb_id'] : null; //TODO 参数待修改 $params = array(); if (!$htb_id) { echo json_encode(array("status" => 0, "message" => "缺少参数")); exit(); } $studentsIds = array(); $download_students_ids = array(); //已下载的学生id $pathArr = array(); //查找已生成学生 $sql = "select student_id,is_htb_download,htb_pdf_time,htb_pdf_path from math_htb_student where htb_id = '{$htb_id}' and is_htb_pdf = 1"; //TODO 参数待修改 $stuArr = $this->sConn->createCommand($sql)->queryAll(); if ($stuArr) { foreach ($stuArr as $k => $v) { $pathArr[] = $v['htb_pdf_path']; $studentsIds[] = $v['student_id']; if($v['is_htb_download']) { $download_students_ids[] = $v['student_id']; } } } $generate_count = count($studentsIds); if (!$studentsIds || empty($studentsIds)) { echo json_encode(array("status" => 0, "message" => "无生成的学生")); exit(); } $generate_students_ids = $studentsIds; //已生成的学生id //查找已下载学生 $params['htbId'] = $htb_id; $sql = "select class_id,grade,create_time,semester_id,name,school_group_id from math_htb_setting where htb_id = '{$htb_id}'"; $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(); $intarr = array( "schoolId" => $this->schoolId, "clazzId" => $msg['class_id'], "semester" => $code['refer_code'], "grade" => $msg['grade'], "students" => $studentsIds, "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(); } $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id'])); //FIXME 20220519文件地址校验 if($pathArr) self::checkFile($apiUrl, $pathArr, $classinfo['class_name']); $dredge_count = 0; //查询开通学生 $this->checkOrder($intarr,$studentsIds,$params,$dredge_count); $params['schoolId'] = $this->schoolId; $params['type'] = 5; $enable_students = array_intersect($params["studentIds"],$generate_students_ids); //FIXME 任务数据 待补齐 $task_info[] = array( 'generate_count' => $generate_count, 'dredge_count' => $dredge_count, 'download_count'=>count($download_students_ids), 'enable_download_count'=> count($enable_students), 'centerId' => $centerId, 'clazzId' => $msg['class_id'], 'clazzName'=> $classinfo['class_name'], 'examId' => 0, 'examName' => '', 'goodsName'=> '好题本', 'grade' => $classinfo['grade'], 'printPages'=> 0, //FIXME 待计算 'printPeopleNum' => 0, //FIXME 待计算 'printSheets'=> 0, //FIXME 待计算 'sendTime' => '', 'taskName' => $msg['name'], 'subjectId'=> 3, 'goodsTypeId'=> 9, 'productId'=> 9, 'url' => '', 'enable_students' => $enable_students, 'download_students' => $download_students_ids, 'pack_json' => json_encode($params), 'pack_api_url'=> $apiUrl . "/rest/download_week_pdf/index", 'auth_username'=> $this->authUsername, 'htb_id' => $htb_id ); } echo json_encode(array('status'=>1,'message'=>'ok', 'data'=>$task_info),true); exit; } //发送好题本云印任务 public function actionSendHtbTask() { $json_data = Req::post('json_data'); $is_filter = Req::post('is_filter'); $json_data = html_entity_decode($json_data); $json_arr = json_decode($json_data, true); $total_student_ids = array(); if(!isset($json_arr['data']) || empty($json_arr['data'])){ echo json_encode(array('status'=>0,'message'=>'网络异常,请重试'));exit; } $time = time(); $transaction = Yii::app()->businessDb->beginTransaction(); try { foreach ($json_arr['data'] as $key => &$item) { //是否过滤已下载的学生 $student_ids = $is_filter ? array_diff($item['enable_students'], $item['download_students']) : $item['enable_students']; //无可下载的学生则不发送任务 if (empty($student_ids)) { continue; } $str_ids = implode(',',$student_ids); $total_student_ids = array_merge($student_ids, $total_student_ids); // 总打印页数 总张数 学生打印张数 学生打印页数 $sql = "select student_id,is_htb_download,htb_pdf_time,htb_page_num,htb_sheet_num from math_htb_student where student_id in ({$str_ids}) and htb_id = '{$item['htb_id']}' and is_htb_pdf = 1"; $res = $this->sConn->createCommand($sql)->queryAll(); $printPages = 0; $printSheets = 0; $student_info = array(); if (empty($res) || !is_array($res)) { echo json_encode(array('status' => 0, 'message' => '网络异常,请稍后重试')); exit; } foreach ($res as $key => $val) { $student_info[$key]['studentId'] = $val['student_id']; $student_info[$key]['printPages'] = isset($val['htb_page_num']) ? $val['htb_page_num'] : 0; $student_info[$key]['printSheets'] = (isset($val['htb_sheet_num']) && $val['htb_sheet_num']) ? $val['htb_sheet_num'] : ceil($student_info[$key]['printPages'] / 2); $printPages += $student_info[$key]['printPages']; $printSheets += $student_info[$key]['printSheets']; } $item['printPages'] = $printPages; $item['printSheets'] = $printSheets; $item['printPeopleNum'] = count($student_info); $item['sendTime'] = date('Y-m-d H:i:s', time()); $item['taskDetailReqDTOList'] = $student_info; $pack_json = json_decode($item['pack_json'],true); $pack_json['studentIds'] = $student_ids; $item['pack_json'] = json_encode($pack_json,true); unset($item['generate_count']); unset($item['dredge_count']); unset($item['download_count']); unset($item['enable_download_count']); unset($item['enable_students']); unset($item['download_students']); } $studentNames = SStudentInfo::model()->getStudentNames($total_student_ids); //求学生名字 $taskModelList = array(); foreach ($json_arr['data'] as &$item) { foreach ($item['taskDetailReqDTOList'] as &$value) { $value['studentName'] = isset($studentNames[$value['studentId']]) ? $studentNames[$value['studentId']] : ''; } $cloudPrintModel = new BusinessCloudPrintTask(); $cloudPrintModel->redis_key_perfix = Yii::app()->getId(); $cloudPrintModel->redis_key = "cloud_print_task_htb_".$item['htb_id'];//TODO key修改 $cloudPrintModel->pack_json = $item['pack_json']; $cloudPrintModel->pack_api_url = $item['pack_api_url']; $cloudPrintModel->auth_username = $this->authUsername; $cloudPrintModel->create_time = $time; $cloudPrintModel->update_time = $time; if (!$cloudPrintModel->save()) { throw new Exception('数据库异常操作'); } else { $item['coachTaskId'] = $cloudPrintModel->primaryKey; $taskModelList[] = $cloudPrintModel; } } //请求新增云印任务接口 if(isset($taskModelList)) { $params = array("printTaskReqDTOList" => $json_arr['data']); $this->sendIms($params, $taskModelList); } $transaction->commit(); }catch (Exception $e){ $transaction->rollback(); echo json_encode(array('status' => 0, 'message' => $e->getMessage()));exit; } echo json_encode(array('status' => 1, 'message' => 'ok')); exit; } //初始化英语词汇宝云印任务 public function actionGenerateMagicWord() { set_time_limit(0); $json_params = file_get_contents('php://input'); $params_arr = json_decode($json_params, true); $task_info = array(); //获取云印点 $centerId = $this->getPrintCenter(); foreach ($params_arr as $param) { $weekId = isset($param['mw_id']) ? $param['mw_id'] : null; $params = array(); if (!$weekId) { echo json_encode(array("status" => 0, "message" => "缺少参数")); exit(); } $studentsIds = array(); $download_students_ids = array(); //已下载的学生id $pathArr = array(); //查找已生成学生 $sql = "select student_id,is_week_download,week_pdf_time,week_pdf_path from english_magic_word_student where mw_id = '{$weekId}' and is_week_pdf = 1"; $stuArr = $this->sConn->createCommand($sql)->queryAll(); if ($stuArr) { foreach ($stuArr as $k => $v) { $pathArr[] = $v['week_pdf_path']; $studentsIds[] = $v['student_id']; if($v['is_week_download']) { $download_students_ids[] = $v['student_id']; } } } $generate_count = count($studentsIds); if (!$studentsIds || empty($studentsIds)) { echo json_encode(array("status" => 0, "message" => "无生成的学生")); exit(); } $generate_students_ids = $studentsIds; //已生成的学生id //查找已下载学生 $params['mwId'] = $weekId; $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("status" => 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(); $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'])); //FIXME 20220519 文件校验 if($pathArr) self::checkFile($apiUrl, $pathArr, $classinfo['class_name']); $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 ); $dredge_count = 0; //查询开通学生 $this->checkOrder($intarr,$studentsIds,$params,$dredge_count); $params['schoolId'] = $this->schoolId; $params['type'] = 6; $enable_students = array_intersect($params["studentIds"],$generate_students_ids); //FIXME 任务数据 待补齐 $task_info[] = array( 'complete_time'=>isset($stuArr[0]['week_pdf_time']) ? date('Y-m-d H:i:s',$stuArr[0]['week_pdf_time']) : '', 'generate_count' => $generate_count, 'dredge_count' => $dredge_count, 'download_count'=>count($download_students_ids), 'enable_download_count'=> count($enable_students), 'centerId' => $centerId, 'clazzId' => $msg['class_id'], 'clazzName'=> $classinfo['class_name'], 'examId' => 0, 'examName' => '', 'goodsName'=> $classinfo['grade']==3?'魔法词汇宝':'趣味词汇宝', 'grade' => $classinfo['grade'], 'printPages'=> 0, //FIXME 待计算 'printPeopleNum' => 0, //FIXME 待计算 'printSheets'=> 0, //FIXME 待计算 'sendTime' => '', 'taskName' => $msg['name'], 'subjectId'=> 8, 'goodsTypeId'=> 11, 'productId'=> 11, 'url' => '', 'enable_students' => $enable_students, 'download_students' => $download_students_ids, 'pack_json' => json_encode($params), 'pack_api_url'=> $apiUrl . "/rest/download_week_pdf/index", 'auth_username'=> $this->authUsername, 'mw_id' => $weekId ); } echo json_encode(array('status'=>1,'message'=>'ok', 'data'=>$task_info),true); exit; } //发送英语词汇宝云印任务 public function actionSendMagicWordTask() { $json_data = Req::post('json_data'); $is_filter = Req::post('is_filter'); $json_data = html_entity_decode($json_data); $json_arr = json_decode($json_data, true); $total_student_ids = array(); if(!isset($json_arr['data']) || empty($json_arr['data'])){ echo json_encode(array('status'=>0,'message'=>'网络异常,请重试'));exit; } $time = time(); $transaction = Yii::app()->businessDb->beginTransaction(); try { foreach ($json_arr['data'] as $key => &$item) { //是否过滤已下载的学生 $student_ids = $is_filter ? array_diff($item['enable_students'], $item['download_students']) : $item['enable_students']; //无可下载的学生则不发送任务 if (empty($student_ids)) { continue; } $str_ids = implode(',',$student_ids); $total_student_ids = array_merge($student_ids, $total_student_ids); // 总打印页数 总张数 学生打印张数 学生打印页数 $sql = "select student_id,is_week_download,week_pdf_time,week_page_num,sheet_num from english_magic_word_student where student_id in ({$str_ids}) and mw_id = '{$item['mw_id']}' and is_week_pdf = 1"; $res = $this->sConn->createCommand($sql)->queryAll(); $printPages = 0; $printSheets = 0; $student_info = array(); if (empty($res) || !is_array($res)) { echo json_encode(array('status' => 0, 'message' => '网络异常,请稍后重试')); exit; } foreach ($res as $key => $val) { $student_info[$key]['studentId'] = $val['student_id']; $student_info[$key]['printPages'] = isset($val['week_page_num']) ? $val['week_page_num'] : 0; $student_info[$key]['printSheets'] = isset($val['sheet_num']) ? $val['sheet_num'] : 0; $printPages += $student_info[$key]['printPages']; $printSheets += $student_info[$key]['printSheets']; } $item['printPages'] = $printPages; $item['printSheets'] = $printSheets; $item['printPeopleNum'] = count($student_info); $item['sendTime'] = date('Y-m-d H:i:s', time()); $item['taskDetailReqDTOList'] = $student_info; $pack_json = json_decode($item['pack_json'],true); $pack_json['studentIds'] = $student_ids; $item['pack_json'] = json_encode($pack_json,true); unset($item['complete_time']); unset($item['generate_count']); unset($item['dredge_count']); unset($item['download_count']); unset($item['enable_download_count']); unset($item['enable_students']); unset($item['download_students']); $time = time(); if($student_ids){ $sql = "update english_magic_word_student set is_week_download = 1,week_download_time={$time} where mw_id = '{$item['mw_id']}' and student_id in (".implode(',',$student_ids).")"; $this->sConn->createCommand($sql)->execute(); } } $studentNames = SStudentInfo::model()->getStudentNames($total_student_ids); //求学生名字 foreach ($json_arr['data'] as &$item) { foreach ($item['taskDetailReqDTOList'] as &$value) { $value['studentName'] = isset($studentNames[$value['studentId']]) ? $studentNames[$value['studentId']] : ''; } $cloudPrintModel = new BusinessCloudPrintTask(); $cloudPrintModel->redis_key_perfix = Yii::app()->getId(); $cloudPrintModel->redis_key = "cloud_print_task_magic_word".$item['mw_id']; $cloudPrintModel->pack_json = $item['pack_json']; $cloudPrintModel->pack_api_url = $item['pack_api_url']; $cloudPrintModel->auth_username = $this->authUsername; $cloudPrintModel->create_time = $time; $cloudPrintModel->update_time = $time; if (!$cloudPrintModel->save()) { throw new Exception('数据库异常操作'); } else { $item['coachTaskId'] = $cloudPrintModel->primaryKey; $taskModelList[] = $cloudPrintModel; } } //请求新增云印任务接口 if(isset($taskModelList)) { $params = array("printTaskReqDTOList" => $json_arr['data']); $this->sendIms($params, $taskModelList); } $transaction->commit(); }catch (Exception $e){ $transaction->rollback(); echo json_encode(array('status' => 0, 'message' => $e->getMessage()));exit; } echo json_encode(array('status' => 1, 'message' => 'ok')); exit; } //初始化考试产品云印任务 public function actionGenerateExamProduct() { set_time_limit(0); $json_params = file_get_contents('php://input'); $params_arr = json_decode($json_params, true); $task_info = array(); //获取云印点 $centerId = $this->getPrintCenter(); foreach ($params_arr as $param) { $examId = isset($param['examId']) ? $param['examId'] : null; $type = isset($param['type']) ? $param['type'] : null; $params = array(); if (!$type || !$examId) { echo json_encode(array("status" => 0, "message" => "缺少参数")); exit(); } $studentsIds = array(); $download_students_ids = array(); //已下载的学生id $pathArr = array(); //查找已生成学生 $sql = "select student_id,is_download,pdf_create_time,pdf_path from exam_product_status where product_type={$type} and exam_id = '{$examId}' and is_create_pdf = 1"; $stuArr = $this->sConn->createCommand($sql)->queryAll(); if ($stuArr) { foreach ($stuArr as $k => $v) { $pathArr[] = $v['pdf_path']; $studentsIds[] = $v['student_id']; if($v['is_download']) { $download_students_ids[] = $v['student_id']; } } } $generate_count = count($studentsIds); if (!$studentsIds || empty($studentsIds)) { echo json_encode(array("status" => 0, "message" => "无生成的学生")); exit(); } $generate_students_ids = $studentsIds; //已生成的学生id //查找已下载学生 $params['examId'] = $examId; $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("status" => 0, "message" => "接口配置信息错误")); exit(); } $sql = "select e.class_id,c.grade,e.semester_id,e.name,c.semester_id,c.class_name from exam e inner join class c on e.class_id=c.class_id where exam_id = '{$examId}'"; $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(); //FIXME 20220519 文件校验 if($pathArr) self::checkFile($apiUrl, $pathArr, $msg['class_name']); $print_time = ClassExamPrinter::model()->findAll('exam_id=:exam_id and type=0', array(':exam_id' => $examId)); $intarr = array( "schoolId" => $this->schoolId, "clazzId" => $msg['class_id'], "semester" => $code['refer_code'], "grade" => $msg['grade'], "students" => $studentsIds, "examTime" => $print_time[0]->add_time ? $print_time[0]->add_time : time(), "classify" => $type, "subject" => $this->subjectId ); $dredge_count = 0; //查询开通学生 $this->checkOrder($intarr,$studentsIds,$params,$dredge_count); $params['schoolId'] = $this->schoolId; $params['type'] = $type; $enable_students = array_intersect($params["studentIds"],$generate_students_ids); $desc = ProductDownload::$desc; //FIXME 任务数据 待补齐 $task_info[] = array( 'complete_time'=>isset($stuArr[0]['pdf_create_time']) ? date('Y-m-d H:i:s',$stuArr[0]['pdf_create_time']) : '', 'generate_count' => $generate_count, 'dredge_count' => $dredge_count, 'download_count'=>count($download_students_ids), 'enable_download_count'=> count($enable_students), 'centerId' => $centerId, 'clazzId' => $msg['class_id'], 'clazzName'=> $msg['class_name'], 'examId' => $examId, 'examName' => '', 'goodsName'=> isset($desc[$type])?$desc[$type]:'unknown', 'grade' => $msg['grade'], 'printPages'=> 0, //FIXME 待计算 'printPeopleNum' => 0, //FIXME 待计算 'printSheets'=> 0, //FIXME 待计算 'sendTime' => '', 'taskName' => $msg['name'], 'subjectId'=> $this->subjectId, 'goodsTypeId'=> $type, 'productId'=> $type, 'url' => '', 'enable_students' => $enable_students, 'download_students' => $download_students_ids, 'pack_json' => json_encode($params), 'pack_api_url'=> $apiUrl . "/rest/download_exam_pdf/index", 'auth_username'=> $this->authUsername, 'type' => $type ); } echo json_encode(array('status'=>1,'message'=>'ok', 'data'=>$task_info),true); exit; } //发送考试产品云印任务 public function actionSendExamProductTask() { $json_data = Req::post('json_data'); $is_filter = Req::post('is_filter'); $json_data = html_entity_decode($json_data); $json_arr = json_decode($json_data, true); $total_student_ids = array(); if(!isset($json_arr['data']) || empty($json_arr['data'])){ echo json_encode(array('status'=>0,'message'=>'网络异常,请重试'));exit; } $time = time(); $transaction = Yii::app()->businessDb->beginTransaction(); try { foreach ($json_arr['data'] as $key => &$item) { //是否过滤已下载的学生 $student_ids = $is_filter ? array_diff($item['enable_students'], $item['download_students']) : $item['enable_students']; //无可下载的学生则不发送任务 if (empty($student_ids)) { continue; } $str_ids = implode(',',$student_ids); $total_student_ids = array_merge($student_ids, $total_student_ids); // 总打印页数 总张数 学生打印张数 学生打印页数 $sql = "select student_id,is_create_pdf,pdf_create_time,pdf_page_num,pdf_sheet_num from exam_product_status where student_id in ({$str_ids}) and exam_id = '{$item['examId']}' and product_type={$item['type']} and is_create_pdf = 1"; $res = $this->sConn->createCommand($sql)->queryAll(); $printPages = 0; $printSheets = 0; $student_info = array(); if (empty($res) || !is_array($res)) { echo json_encode(array('status' => 0, 'message' => '网络异常,请稍后重试')); exit; } foreach ($res as $key => $val) { $student_info[$key]['studentId'] = $val['student_id']; $student_info[$key]['printPages'] = isset($val['pdf_page_num']) ? $val['pdf_page_num'] : 0; $student_info[$key]['printSheets'] = isset($val['pdf_sheet_num']) ? $val['pdf_sheet_num'] : 0; $printPages += $student_info[$key]['printPages']; $printSheets += $student_info[$key]['printSheets']; } $item['printPages'] = $printPages; $item['printSheets'] = $printSheets; $item['printPeopleNum'] = count($student_info); $item['sendTime'] = date('Y-m-d H:i:s', time()); $item['taskDetailReqDTOList'] = $student_info; $pack_json = json_decode($item['pack_json'],true); $pack_json['studentIds'] = $student_ids; $item['pack_json'] = json_encode($pack_json,true); unset($item['complete_time']); unset($item['generate_count']); unset($item['dredge_count']); unset($item['download_count']); unset($item['enable_download_count']); unset($item['enable_students']); unset($item['download_students']); $time = time(); if($student_ids){ $sql = "update exam_product_status set is_download = 1,download_time={$time} where exam_id = '{$item['examId']}' and product_type={$item['type']} and student_id in (".implode(',',$student_ids).")"; $this->sConn->createCommand($sql)->execute(); } } $studentNames = SStudentInfo::model()->getStudentNames($total_student_ids); //求学生名字 foreach ($json_arr['data'] as &$item) { foreach ($item['taskDetailReqDTOList'] as &$value) { $value['studentName'] = isset($studentNames[$value['studentId']]) ? $studentNames[$value['studentId']] : ''; } $cloudPrintModel = new BusinessCloudPrintTask(); $cloudPrintModel->redis_key_perfix = Yii::app()->getId(); $cloudPrintModel->redis_key = sprintf("cloud_print_task:%s:%s:%s:%s", $this->schoolId,$item['clazzId'],$item['examId'],$item['goodsTypeId']); $cloudPrintModel->pack_json = $item['pack_json']; $cloudPrintModel->pack_api_url = $item['pack_api_url']; $cloudPrintModel->auth_username = $this->authUsername; $cloudPrintModel->create_time = $time; $cloudPrintModel->update_time = $time; if (!$cloudPrintModel->save()) { throw new Exception('数据库异常操作'); } else { ProductProcessTime::model()->updateDownloadTime($student_ids,$item['type'],$item['examId']); $item['coachTaskId'] = $cloudPrintModel->primaryKey; $taskModelList[] = $cloudPrintModel; } } //请求新增云印任务接口 if(isset($taskModelList)) { $params = array("printTaskReqDTOList" => $json_arr['data']); $this->sendIms($params, $taskModelList); } $transaction->commit(); }catch (Exception $e){ $transaction->rollback(); echo json_encode(array('status' => 0, 'message' => $e->getMessage()));exit; } echo json_encode(array('status' => 1, 'message' => 'ok')); exit; } //初始化通用非考试产品云印任务 public function actionGenerateGeneralProduct() { set_time_limit(0); $json_params = file_get_contents('php://input'); $params_arr = json_decode($json_params, true); $task_info = array(); //获取云印点 $centerId = $this->getPrintCenter(); foreach ($params_arr as $param) { $gpId = isset($param['gpId']) ? $param['gpId'] : null; $type = isset($param['type']) ? $param['type'] : null; $params = array(); if (!$gpId) { echo json_encode(array("status" => 0, "message" => "缺少参数")); exit(); } $studentsIds = array(); $download_students_ids = array(); //已下载的学生id $pathArr = array(); //查找已生成学生 $sql = "select student_id,is_download,pdf_create_time,pdf_path from general_product_student where gp_id = '{$gpId}' and is_create_pdf = 1 and is_teaching_pdf=0"; $stuArr = $this->sConn->createCommand($sql)->queryAll(); if ($stuArr) { foreach ($stuArr as $k => $v) { $pathArr[] = $v['pdf_path']; $studentsIds[] = $v['student_id']; if($v['is_download']) { $download_students_ids[] = $v['student_id']; } } } $generate_count = count($studentsIds); if (!$studentsIds || empty($studentsIds)) { echo json_encode(array("status" => 0, "message" => "无生成的学生")); exit(); } $generate_students_ids = $studentsIds; //已生成的学生id $params['gpId'] = $gpId; $params['type'] = $type; $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("status" => 0, "message" => "接口配置信息错误")); exit(); } $sql = "select p.class_id,p.grade,p.semester_id,p.name,c.class_name,p.create_time from general_product p inner join class c on p.class_id=c.class_id where p.gp_id = '{$gpId}'"; $msg = $this->sConn->createCommand($sql)->queryRow(); //FIXME 20220519 文件地址校验 if($pathArr) self::checkFile($apiUrl, $pathArr, $msg['class_name']); $Sem = new SSemester(); $code = $Sem->conn->createQuery() ->from('semester') ->where("semester_id = '" . $msg['semester_id'] . "'") ->limit(1) ->query() ->read(); $classifyArr = ProductDownload::$order_classify; if(!isset($classifyArr[$type])){ echo json_encode(array("status" => 0, "message" => "产品类型参数错误")); exit(); } $intarr = array( "schoolId" => $this->schoolId, "clazzId" => $msg['class_id'], "semester" => $code['refer_code'], "grade" => $msg['grade'], "students" => $studentsIds, "examTime" => $msg['create_time'] ? $msg['create_time'] : time(), "classify" => $classifyArr[$type], "subject" => $this->subjectId ); $dredge_count = 0; //查询开通学生 $this->checkOrder($intarr,$studentsIds,$params,$dredge_count); $params['schoolId'] = $this->schoolId; $enable_students = array_intersect($params["studentIds"],$generate_students_ids); $desc = ProductDownload::$desc; //FIXME 任务数据 待补齐 $task_info[] = array( 'complete_time'=>isset($stuArr[0]['pdf_create_time']) ? date('Y-m-d H:i:s',$stuArr[0]['pdf_create_time']) : '', 'generate_count' => $generate_count, 'dredge_count' => $dredge_count, 'download_count'=>count($download_students_ids), 'enable_download_count'=> count($enable_students), 'centerId' => $centerId, 'clazzId' => $msg['class_id'], 'clazzName'=> $msg['class_name'], 'examId' => 0, 'examName' => '', 'goodsName'=> isset($desc[$type])?$desc[$type]:'', 'grade' => $msg['grade'], 'printPages'=> 0, //FIXME 待计算 'printPeopleNum' => 0, //FIXME 待计算 'printSheets'=> 0, //FIXME 待计算 'sendTime' => '', 'taskName' => $msg['name'], 'subjectId'=> $this->subjectId, 'goodsTypeId'=> $type==29 ? 31 : $type, 'productId'=> $type, 'url' => '', 'enable_students' => $enable_students, 'download_students' => $download_students_ids, 'pack_json' => json_encode($params), 'pack_api_url'=> $apiUrl . "/rest/download_general_pdf/index", 'auth_username'=> $this->authUsername, 'type' => $type, 'gp_id' => $gpId, ); } echo json_encode(array('status'=>1,'message'=>'ok', 'data'=>$task_info),true); exit; } //发送化通用非考试产品云印任务 public function actionSendGeneralProductTask() { $json_data = Req::post('json_data'); $is_filter = Req::post('is_filter'); $json_data = html_entity_decode($json_data); $json_arr = json_decode($json_data, true); $total_student_ids = array(); if(!isset($json_arr['data']) || empty($json_arr['data'])){ echo json_encode(array('status'=>0,'message'=>'网络异常,请重试'));exit; } $time = time(); $transaction = Yii::app()->businessDb->beginTransaction(); try { foreach ($json_arr['data'] as $key => &$item) { //是否过滤已下载的学生 $student_ids = $is_filter ? array_diff($item['enable_students'], $item['download_students']) : $item['enable_students']; //无可下载的学生则不发送任务 if (empty($student_ids)) { continue; } $str_ids = implode(',',$student_ids); $total_student_ids = array_merge($student_ids, $total_student_ids); // 总打印页数 总张数 学生打印张数 学生打印页数 $sql = "select student_id,is_create_pdf,pdf_create_time,pdf_page_num,pdf_sheet_num from general_product_student where student_id in ({$str_ids}) and gp_id = '{$item['gp_id']}' and is_create_pdf = 1"; $res = $this->sConn->createCommand($sql)->queryAll(); $printPages = 0; $printSheets = 0; $student_info = array(); if (empty($res) || !is_array($res)) { echo json_encode(array('status' => 0, 'message' => '网络异常,请稍后重试')); exit; } foreach ($res as $key => $val) { $student_info[$key]['studentId'] = $val['student_id']; $student_info[$key]['printPages'] = isset($val['pdf_page_num']) ? $val['pdf_page_num'] : 0; $student_info[$key]['printSheets'] = isset($val['pdf_sheet_num']) ? $val['pdf_sheet_num'] : 0; $printPages += $student_info[$key]['printPages']; $printSheets += $student_info[$key]['printSheets']; } $item['printPages'] = $printPages; $item['printSheets'] = $printSheets; $item['printPeopleNum'] = count($student_info); $item['sendTime'] = date('Y-m-d H:i:s', time()); $item['taskDetailReqDTOList'] = $student_info; $pack_json = json_decode($item['pack_json'],true); $pack_json['studentIds'] = $student_ids; $item['pack_json'] = json_encode($pack_json,true); unset($item['complete_time']); unset($item['generate_count']); unset($item['dredge_count']); unset($item['download_count']); unset($item['enable_download_count']); unset($item['enable_students']); unset($item['download_students']); $time = time(); if($student_ids){ $sql = "update general_product_student set is_download = 1,download_time={$time} where gp_id = '{$item['gp_id']}' and student_id in (".implode(',',$student_ids).")"; $this->sConn->createCommand($sql)->execute(); } } $studentNames = SStudentInfo::model()->getStudentNames($total_student_ids); //求学生名字 foreach ($json_arr['data'] as &$item) { foreach ($item['taskDetailReqDTOList'] as &$value) { $value['studentName'] = isset($studentNames[$value['studentId']]) ? $studentNames[$value['studentId']] : ''; } $cloudPrintModel = new BusinessCloudPrintTask(); $cloudPrintModel->redis_key_perfix = Yii::app()->getId(); $cloudPrintModel->redis_key = sprintf("cloud_print_task:general_product:%s:%s:%s", $this->schoolId,$item['clazzId'],$item['gp_id']); $cloudPrintModel->pack_json = $item['pack_json']; $cloudPrintModel->pack_api_url = $item['pack_api_url']; $cloudPrintModel->auth_username = $this->authUsername; $cloudPrintModel->create_time = $time; $cloudPrintModel->update_time = $time; if (!$cloudPrintModel->save()) { throw new Exception('数据库异常操作'); } else { $item['coachTaskId'] = $cloudPrintModel->primaryKey; $taskModelList[] = $cloudPrintModel; } } //请求新增云印任务接口 if(isset($taskModelList)) { $params = array("printTaskReqDTOList" => $json_arr['data']); $this->sendIms($params, $taskModelList); } $transaction->commit(); }catch (Exception $e){ $transaction->rollback(); echo json_encode(array('status' => 0, 'message' => $e->getMessage()));exit; } echo json_encode(array('status' => 1, 'message' => 'ok')); exit; } /** * 发生ims超印接口 * @param $params * @param $taskModelList * @throws Exception */ private function sendIms($params, $taskModelList){ $http = http('cloud-print/task/coach/add', 'POST', $this->authUsername, $params); $response = formatResponse($http); if ($response['status']) { $task_list = $response['data']; //TODO 一天发送一次标记缓存 foreach ($task_list as $key=>$value){ BusinessCloudPrintTask::model()->updateByPk($value['coachTaskId'],array('cloud_print_id'=>$value['taskId'], 'update_time'=>time())); } //任务发送成功标记一天一次缓存 foreach ($taskModelList as $taskModel) { Yii::app()->cache->setValue($taskModel->redis_key,1); Yii::app()->cache->expire($taskModel->redis_key,86400); } } else { throw new Exception($response['data']); } } /** * 检查订单 * @param $intarr * @param $studentsIds * @param $params * @param $dredge_count */ private function checkOrder($intarr, $studentsIds, &$params, &$dredge_count, $isReport = false){ $params["studentIds"] = array(); if (Yii::app()->params["limit_open"]) { $classifies = is_array($intarr['classify']) ? $intarr['classify'] : array($intarr['classify']); foreach ($classifies as $classify) { $intarr['classify'] = $classify; $basic = imsBasicAuth($this->schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]); $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr), $basic)); if (!$rs) { echo json_encode(array("status" => 0, "message" => '接口错误')); exit(); } if ($rs->errCode != "00") { echo json_encode(array("status" => 0, "message" => $rs->errMsg)); exit(); } if (!empty($rs->data)) { $params["studentIds"] = array_merge($params["studentIds"],$rs->data); } } $params["studentIds"] = array_unique($params['studentIds']); //开通数量 $dredge_count = count($params['studentIds']); if(empty($params['studentIds'])){ echo json_encode(array("status" => 0, "message" => "请先购买商品")); exit(); } } else { if ($studentsIds) { $params["studentIds"] = $studentsIds; } } } //初始化英语写作宝云印任务 public function actionGenerateWriting() { set_time_limit(0); $json_params = file_get_contents('php://input'); $params_arr = json_decode($json_params, true); $task_info = array(); //获取云印点 $centerId = $this->getPrintCenter(); foreach ($params_arr as $param) { $weekId = isset($param['ew_id']) ? $param['ew_id'] : null; $params = array(); if (!$weekId) { echo json_encode(array("status" => 0, "message" => "缺少参数")); exit(); } $studentsIds = array(); $download_students_ids = array(); //已下载的学生id $pathArr = array(); //查找已生成学生 $sql = "select student_id,is_week_download,week_pdf_time,week_pdf_path from english_writing_student where ew_id = '{$weekId}' and is_week_pdf = 1"; $stuArr = $this->sConn->createCommand($sql)->queryAll(); if ($stuArr) { foreach ($stuArr as $k => $v) { $pathArr[] = $v['week_pdf_path']; $studentsIds[] = $v['student_id']; if($v['is_week_download']) { $download_students_ids[] = $v['student_id']; } } } $generate_count = count($studentsIds); if (!$studentsIds || empty($studentsIds)) { echo json_encode(array("status" => 0, "message" => "无生成的学生")); exit(); } $generate_students_ids = $studentsIds; //已生成的学生id //查找已下载学生 $params['ewId'] = $weekId; $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null; if (!$apiUrl) { echo json_encode(array("status" => 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(); $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'])); //FIXME 20220519 文件地址校验 if($pathArr) self::checkFile($apiUrl, $pathArr, $classinfo['class_name']); $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 ); $dredge_count = 0; //查询开通学生 if (Yii::app()->params["limit_open"]) { $basic = imsBasicAuth($this->schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]); $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr), $basic)); if (!$rs) { echo json_encode(array("status" => 0, "message" => '接口错误')); exit(); } if ($rs->errCode != "00") { echo json_encode(array("status" => 0, "message" => $rs->errMsg)); exit(); } if (!empty($rs->data)) { $params["studentIds"] = $rs->data; //开通数量 $dredge_count = count($rs->data); } else { echo json_encode(array("status" => 0, "message" => "请先购买商品")); exit(); } } else { if ($studentsIds) { $params["studentIds"] = $studentsIds; } } $params['schoolId'] = $this->schoolId; $params['type'] = 7; $enable_students = array_intersect($params["studentIds"],$generate_students_ids); //FIXME 任务数据 待补齐 $task_info[] = array( 'complete_time'=>isset($stuArr[0]['week_pdf_time']) ? date('Y-m-d H:i:s',$stuArr[0]['week_pdf_time']) : '', 'generate_count' => $generate_count, 'dredge_count' => $dredge_count, 'download_count'=>count($download_students_ids), 'enable_download_count'=> count($enable_students), 'centerId' => $centerId, 'clazzId' => $msg['class_id'], 'clazzName'=> $classinfo['class_name'], 'examId' => 0, 'examName' => '', 'goodsName'=> '写作宝', 'grade' => $classinfo['grade'], 'printPages'=> 0, //FIXME 待计算 'printPeopleNum' => 0, //FIXME 待计算 'printSheets'=> 0, //FIXME 待计算 'sendTime' => '', 'taskName' => $msg['name'], 'subjectId'=> 8, 'goodsTypeId'=> 32, 'productId'=> 32, 'url' => '', 'enable_students' => $enable_students, 'download_students' => $download_students_ids, 'pack_json' => json_encode($params), 'pack_api_url'=> $apiUrl . "/rest/download_week_pdf/index", 'auth_username'=> $this->authUsername, 'ew_id' => $weekId ); } echo json_encode(array('status'=>1,'message'=>'ok', 'data'=>$task_info),true); exit; } //发送英语词汇宝云印任务 public function actionSendWritingTask() { $json_data = Req::post('json_data'); $is_filter = Req::post('is_filter'); $json_data = html_entity_decode($json_data); $json_arr = json_decode($json_data, true); $total_student_ids = array(); if(!isset($json_arr['data']) || empty($json_arr['data'])){ echo json_encode(array('status'=>0,'message'=>'网络异常,请重试'));exit; } $time = time(); $transaction = Yii::app()->businessDb->beginTransaction(); try { foreach ($json_arr['data'] as $key => &$item) { //是否过滤已下载的学生 $student_ids = $is_filter ? array_diff($item['enable_students'], $item['download_students']) : $item['enable_students']; //无可下载的学生则不发送任务 if (empty($student_ids)) { continue; } $str_ids = implode(',',$student_ids); $total_student_ids = array_merge($student_ids, $total_student_ids); // 总打印页数 总张数 学生打印张数 学生打印页数 $sql = "select student_id,is_week_download,week_pdf_time,week_page_num,sheet_num from english_writing_student where student_id in ({$str_ids}) and ew_id = '{$item['ew_id']}' and is_week_pdf = 1"; $res = $this->sConn->createCommand($sql)->queryAll(); $printPages = 0; $printSheets = 0; $student_info = array(); if (empty($res) || !is_array($res)) { echo json_encode(array('status' => 0, 'message' => '网络异常,请稍后重试')); exit; } foreach ($res as $key => $val) { $student_info[$key]['studentId'] = $val['student_id']; $student_info[$key]['printPages'] = isset($val['week_page_num']) ? $val['week_page_num'] : 0; $student_info[$key]['printSheets'] = isset($val['sheet_num']) ? $val['sheet_num'] : 0; $printPages += $student_info[$key]['printPages']; $printSheets += $student_info[$key]['printSheets']; } $item['printPages'] = $printPages; $item['printSheets'] = $printSheets; $item['printPeopleNum'] = count($student_info); $item['sendTime'] = date('Y-m-d H:i:s', time()); $item['taskDetailReqDTOList'] = $student_info; $pack_json = json_decode($item['pack_json'],true); $pack_json['studentIds'] = $student_ids; $item['pack_json'] = json_encode($pack_json,true); unset($item['complete_time']); unset($item['generate_count']); unset($item['dredge_count']); unset($item['download_count']); unset($item['enable_download_count']); unset($item['enable_students']); unset($item['download_students']); $time = time(); if($student_ids){ $sql = "update english_writing_student set is_week_download = 1,week_download_time={$time} where ew_id = '{$item['ew_id']}' and student_id in (".implode(',',$student_ids).")"; $this->sConn->createCommand($sql)->execute(); } } $studentNames = SStudentInfo::model()->getStudentNames($total_student_ids); //求学生名字 foreach ($json_arr['data'] as &$item) { foreach ($item['taskDetailReqDTOList'] as &$value) { $value['studentName'] = isset($studentNames[$value['studentId']]) ? $studentNames[$value['studentId']] : ''; } $cloudPrintModel = new BusinessCloudPrintTask(); $cloudPrintModel->redis_key_perfix = Yii::app()->getId(); $cloudPrintModel->redis_key = "cloud_print_task:english_writing:".$item['ew_id']; $cloudPrintModel->pack_json = $item['pack_json']; $cloudPrintModel->pack_api_url = $item['pack_api_url']; $cloudPrintModel->auth_username = $this->authUsername; $cloudPrintModel->create_time = $time; $cloudPrintModel->update_time = $time; if (!$cloudPrintModel->save()) { throw new Exception('数据库异常操作'); } else { $item['coachTaskId'] = $cloudPrintModel->primaryKey; $taskModelList[] = $cloudPrintModel; } } //请求新增云印任务接口 $params = array("printTaskReqDTOList" => $json_arr['data']); $http = http('cloud-print/task/coach/add', 'POST', $this->authUsername, $params); $response = formatResponse($http); if ($response['status']) { $task_list = $response['data']; //TODO 一天发送一次标记缓存 foreach ($task_list as $key=>$value){ BusinessCloudPrintTask::model()->updateByPk($value['coachTaskId'],array('cloud_print_id'=>$value['taskId'], 'update_time'=>$time)); } $transaction->commit(); //任务发送成功标记一天一次缓存 foreach ($taskModelList as $taskModel) { Yii::app()->cache->setValue($taskModel->redis_key,1); Yii::app()->cache->expire($taskModel->redis_key,86400); } echo json_encode(array('status' => 1, 'message' => 'ok', 'data' => $response['data'])); exit; } else { throw new Exception($response['data']); } }catch (Exception $e){ $transaction->rollback(); echo json_encode(array('status' => 0, 'message' => $e->getMessage())); exit; } } /** * 检查文件是否失效 * @param $apiUrl * @param $pathArr * @param $className */ private static function checkFile($apiUrl, $pathArr, $className){ $sizeRs = Curl::post($apiUrl . "/rest/download_file_size/index", array('path_arr' => $pathArr)); if (!($sizeRs = json_decode($sizeRs))) { echo json_encode(array("status" => 0, "message" => '请求接口失败')); exit; } if (! isset($sizeRs->size)){ echo json_encode(array("status" => 0, "message" => $className.'未找到产品pdf')); exit; } } }