123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/8/22 0022
- * Time: 15:53
- */
- class PrintCloudController extends Controller
- {
- //生成云印任务列表
- public function actionGenerateTaskList()
- {
- 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"] : '';
- $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;
- }
- }
- }
|