ProductdownloadController.php 138 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039
  1. <?php
  2. /**
  3. * Class ProductdownloadController
  4. */
  5. class ProductdownloadController extends Controller
  6. {
  7. /**
  8. * 下载错题本/二步/三步产品文件
  9. */
  10. public function actionGetImproveFile()
  11. {
  12. $examId = Req::get("examId");
  13. $classId = Req::get("classId");
  14. $type = Req::get("type");
  15. $studentsIds = Req::get("studentsIds");
  16. $printType = Req::get("printType");
  17. $absentFilter = Req::get("absent_filter");
  18. $classDownload = $studentsIds ? false : true;
  19. if (!$examId || !$classId || !$type) {
  20. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  21. exit();
  22. }
  23. if (!in_array($type, array(1, 2, 3))) {
  24. echo json_encode(array("success" => 0, "message" => "参数错误[1]"));
  25. exit();
  26. }
  27. $groupInfo = Exam::model()->getGroupInfo($examId);
  28. if (empty($groupInfo)) exit(json_encode(array("success" => 0, "message" => "考试信息错误")));
  29. $typeRel = array('1' => 'wb_group_id', '2' => 'isp_group_id', '3' => 'wbisp_group_id');
  30. $groupId = $groupInfo[$typeRel[$type]];
  31. if (!empty($groupId)) {
  32. $apiUrl = isset(Yii::app()->params["improve_url"][$groupId]) ? Yii::app()->params["improve_url"][$groupId] : null;
  33. } else {
  34. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  35. }
  36. if (!$apiUrl) {
  37. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  38. exit();
  39. }
  40. $params = array(
  41. "schoolId" => $this->schoolId,
  42. "examId" => $examId,
  43. "classId" => $classId,
  44. "type" => $type,
  45. "studentIds" => array(),
  46. );
  47. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $classId));
  48. $Sem = new SSemester();
  49. $code = $Sem->conn->createQuery()->from('semester')->where("semester_id = '" . $classinfo['semester_id'] . "'")
  50. ->limit(1)
  51. ->query()
  52. ->read();
  53. $print_time = ClassExamPrinter::model()->findAll('exam_id=:exam_id and class_id=:classid and type=0', array(':exam_id' => $examId, ':classid' => $classId));
  54. $intarr = array(
  55. "schoolId" => $this->schoolId,
  56. "clazzId" => $classId,
  57. "semester" => $code['refer_code'],
  58. "grade" => $classinfo['grade'],
  59. "students" => array(),
  60. "examTime" => $print_time[0]->add_time,
  61. "classify" => $type,
  62. );
  63. //判断学科
  64. $examInfo = Exam::model()->findByPk($examId);
  65. $intarr['subject'] = $examInfo['subject_id'];
  66. if (in_array($intarr['subject'], $this->mathSubjectId)) {
  67. $intarr['subject'] = 3;
  68. }
  69. if ($type == 1) {
  70. $productName = $examInfo->name . '"错题本"';
  71. $pdfPathColumn = 'wrongbook_pdf_path';
  72. $isGenerateColumn = 'is_wrongbook_pdf';
  73. $isDownloadColumn = 'is_wrongbook_download';
  74. $downloadTimeCoulmn = 'download_wrongbook_time';
  75. } elseif ($type == 2) {
  76. $productName = $examInfo->name . '"个性化学习方案"';
  77. $pdfPathColumn = 'isp_pdf_path';
  78. $isGenerateColumn = 'is_isp_pdf';
  79. $isDownloadColumn = 'is_two_isp_download';
  80. $downloadTimeCoulmn = 'download_two_isp_time';
  81. } else {
  82. $productName = $examInfo->name . '"个性化学习宝"';
  83. $pdfPathColumn = 'wbisp_pdf_path';
  84. $isGenerateColumn = 'is_wbisp_pdf';
  85. $isDownloadColumn = 'is_three_isp_download';
  86. $downloadTimeCoulmn = 'download_three_isp_time';
  87. }
  88. $productDownload = new ProductDownload($type);
  89. //*****获取生成的学生***//
  90. $generateStu = $productDownload->getGenerateStu('student_paper_relation', 'exam_id', $pdfPathColumn, $isGenerateColumn, $examId, $studentsIds, $absentFilter);
  91. if(!$generateStu){
  92. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  93. }
  94. $params['studentIds'] = $generateStu['studentIds'];
  95. $pathArr = $generateStu['pathArr'];
  96. if ($printType == 'third_isp') {
  97. $params["subjectId"] = 8;
  98. $params["type"] = 3;
  99. }
  100. if (Yii::app()->params["limit_open"]) {
  101. $params["studentIds"] = $productDownload->getCanDownloadStu($generateStu['studentIds'], $intarr, $this->schoolId);
  102. }
  103. ProductProcessTime::model()->updateDownloadTime($params["studentIds"],$type,$examId);
  104. //**************** Step-2 判断是否已经存在下载任务 ********************//
  105. if ($classDownload) {
  106. $packTask = $this->getExistTask($examId, $classId, $type, count($params['studentIds']));
  107. if (isset($packTask->pack_status) && $packTask->pack_status == 0) {
  108. echo json_encode(array("success" => 3, "message" => ""));
  109. exit;
  110. }
  111. if (isset($packTask->pack_url) && $packTask->pack_url) {
  112. if($this->updateIspDownloadStatus($params["studentIds"],$classId,$examId,$isDownloadColumn,$downloadTimeCoulmn) !== false){
  113. ProductProcessTime::model()->updateDownloadTime($params["studentIds"],$type,$examId);
  114. }
  115. echo json_encode(array("success" => 1, "downloadPath" => $packTask->pack_url));
  116. exit;
  117. }
  118. }
  119. //**************** Step-3 根据接口获取文件大小来判断走原有接口打包流程还是走脚本任务 ************//
  120. $sizeRs = Curl::post($apiUrl . "/rest/download_file_size/index", array('path_arr' => $pathArr));
  121. if (!($sizeRs = json_decode($sizeRs))) {
  122. echo json_encode(array("success" => 0, "downloadPath" => '请求接口失败'));
  123. exit;
  124. }
  125. if (isset($sizeRs->size)) {
  126. //************ Step-3-1 大于限定值 发送任务到后台打包 ******//
  127. if (Yii::app()->params["pack_product_file_limit"] < $sizeRs->size) {
  128. $packProductModel = new BusinessPackProductTask();
  129. $packProductModel->school_id = $this->schoolId;
  130. $packProductModel->auth_username = $this->authUsername;
  131. $packProductModel->product_type = $type;
  132. $packProductModel->product_name = $productName;
  133. $packProductModel->subject_id = $this->subjectId;
  134. $packProductModel->class_id = $classId;
  135. $packProductModel->class_name = $classinfo['class_name'];
  136. $packProductModel->unique_key = $examId;
  137. $packProductModel->student_count = count($params["studentIds"]);
  138. $packProductModel->pack_json = json_encode($params);
  139. $packProductModel->pack_api_url = $apiUrl . "/rest/download_pdf/index";
  140. $packProductModel->create_time = time();
  141. $packProductModel->save();
  142. $this->updateIspDownloadStatus($params["studentIds"],$classId,$examId,$isDownloadColumn,$downloadTimeCoulmn);
  143. echo json_encode(array("success" => 3, "message" => ""));
  144. exit;
  145. } else {
  146. //************ Step-3-2 小于限定值 原有接口流程 ******//
  147. $rs = Curl::post($apiUrl . "/rest/download_pdf/index", $params);
  148. if (!($rs = json_decode($rs))) {
  149. $rs = array("success" => 0, "message" => "请求接口失败",);
  150. }
  151. if ($printType != 'third_wb') {
  152. if ($rs->success != 0) {
  153. $rs->success = 2;
  154. }
  155. }
  156. if (isset($rs->downloadPath)) {
  157. if($this->updateIspDownloadStatus($params["studentIds"],$classId,$examId,$isDownloadColumn,$downloadTimeCoulmn) !== false){
  158. ProductProcessTime::model()->updateDownloadTime($params["studentIds"],$type,$examId);
  159. }
  160. }
  161. if ($groupId && isset($rs->downloadPath)) {
  162. if (YII_ENV == 'pro' || YII_ENV == 'production') {
  163. $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/', 'http://zstatic' . $groupId, $rs->downloadPath);
  164. }
  165. }
  166. echo json_encode($rs);
  167. exit;
  168. }
  169. } else {
  170. echo json_encode(array("success" => 0, "message" => $sizeRs->message));
  171. exit;
  172. }
  173. }
  174. /**
  175. * 更新个性化学习宝下载状态
  176. * @param array $studentIds
  177. * @param $classId
  178. * @param $examId
  179. * @param $isDownloadColumn
  180. * @param $downloadTimeCoulmn
  181. * @return mixed
  182. */
  183. private function updateIspDownloadStatus($studentIds=array(), $classId, $examId, $isDownloadColumn, $downloadTimeCoulmn)
  184. {
  185. $criteria = new CDbCriteria();
  186. if ($studentIds) {
  187. $criteria->addInCondition('student_id', $studentIds);
  188. } else {
  189. $criteria->addCondition('(is_complete = :is_complete and is_feedback = :is_complete) or is_del = :is_complete ');
  190. $criteria->params[':is_complete'] = 1;
  191. $criteria->params[':is_feedback'] = 1;
  192. $criteria->params[':is_del'] = 1;
  193. }
  194. $criteria->addCondition('class_id=:class_id');
  195. $criteria->params[':class_id'] = $classId;
  196. $criteria->addCondition('exam_id=:exam_id');
  197. $criteria->addCondition("{$isDownloadColumn}=:is_download");
  198. $criteria->params[':exam_id'] = $examId;
  199. $criteria->params[':is_download'] = 0;
  200. return SStudentPaperRelation::model()->updateAll(array($isDownloadColumn => 1, $downloadTimeCoulmn => time()), $criteria);
  201. }
  202. //添加错题本/两步/三步提分下载任务
  203. public function actionAddIspTask()
  204. {
  205. $examId = Req::get("examId");
  206. $classId = Req::get("classId");
  207. $type = Req::get("type");
  208. $studentsIds = Req::get("studentsIds");
  209. $printType = Req::get("printType");
  210. $absentFilter = Req::get("absent_filter");
  211. if (!$examId || !$classId || !$type) {
  212. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  213. exit();
  214. }
  215. if (!in_array($type, array(1, 2, 3))) {
  216. echo json_encode(array("success" => 0, "message" => "参数错误[1]"));
  217. exit();
  218. }
  219. $groupInfo = Exam::model()->getGroupInfo($examId);
  220. if (empty($groupInfo)) exit(json_encode(array("success" => 0, "message" => "考试信息错误")));
  221. $typeRel = array('1' => 'wb_group_id', '2' => 'isp_group_id', '3' => 'wbisp_group_id');
  222. $groupId = $groupInfo[$typeRel[$type]];
  223. if (!empty($groupId)) {
  224. $apiUrl = isset(Yii::app()->params["improve_url"][$groupId]) ? Yii::app()->params["improve_url"][$groupId] : null;
  225. } else {
  226. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  227. }
  228. if (!$apiUrl) {
  229. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  230. exit();
  231. }
  232. $params = array(
  233. "schoolId" => $this->schoolId,
  234. "examId" => $examId,
  235. "classId" => $classId,
  236. "type" => $type,
  237. "studentIds" => array(),
  238. );
  239. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $classId));
  240. $Sem = new SSemester();
  241. $code = $Sem->conn->createQuery()->from('semester')->where("semester_id = '" . $classinfo['semester_id'] . "'")
  242. ->limit(1)
  243. ->query()
  244. ->read();
  245. $print_time = ClassExamPrinter::model()->findAll('exam_id=:exam_id and class_id=:classid and type=0', array(':exam_id' => $examId, ':classid' => $classId));
  246. $intarr = array(
  247. "schoolId" => $this->schoolId,
  248. "clazzId" => $classId,
  249. "semester" => $code['refer_code'],
  250. "grade" => $classinfo['grade'],
  251. "students" => array(),
  252. "examTime" => $print_time[0]->add_time,
  253. "classify" => $type,
  254. );
  255. //判断学科
  256. $examInfo = Exam::model()->findByPk($examId);
  257. $intarr['subject'] = $examInfo['subject_id'];
  258. if (in_array($intarr['subject'], $this->mathSubjectId)) {
  259. $intarr['subject'] = 3;
  260. }
  261. if ($type == 1) {
  262. $productName = $examInfo->name . '"错题本"';
  263. $pdfPathColumn = 'wrongbook_pdf_path';
  264. $isGenerateColumn = 'is_wrongbook_pdf';
  265. $isDownloadColumn = 'is_wrongbook_download';
  266. $downloadTimeCoulmn = 'download_wrongbook_time';
  267. } elseif ($type == 2) {
  268. $productName = $examInfo->name . '"个性化学习方案"';
  269. $pdfPathColumn = 'isp_pdf_path';
  270. $isGenerateColumn = 'is_isp_pdf';
  271. $isDownloadColumn = 'is_two_isp_download';
  272. $downloadTimeCoulmn = 'download_two_isp_time';
  273. } else {
  274. $productName = $examInfo->name . '"个性化学习宝"';
  275. $pdfPathColumn = 'wbisp_pdf_path';
  276. $isGenerateColumn = 'is_wbisp_pdf';
  277. $isDownloadColumn = 'is_three_isp_download';
  278. $downloadTimeCoulmn = 'download_three_isp_time';
  279. }
  280. $productDoanload = new ProductDownload($type);
  281. //*****获取生成的学生***//
  282. $generateStu = $productDoanload->getGenerateStu('student_paper_relation', 'exam_id', $pdfPathColumn, $isGenerateColumn, $examId, $studentsIds, $absentFilter);
  283. if(!$generateStu){
  284. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  285. }
  286. $params['studentIds'] = $generateStu['studentIds'];
  287. if ($printType == 'third_isp') {
  288. $params["subjectId"] = 8;
  289. $params["type"] = 3;
  290. }
  291. if (Yii::app()->params["limit_open"]) {
  292. $params["studentIds"] = $productDoanload->getCanDownloadStu($generateStu['studentIds'], $intarr, $this->schoolId);
  293. }
  294. $packProductModel = new BusinessPackProductTask();
  295. $packProductModel->school_id = $this->schoolId;
  296. $packProductModel->auth_username = $this->authUsername;
  297. $packProductModel->product_type = $type;
  298. $packProductModel->product_name = $productName;
  299. $packProductModel->subject_id = $this->subjectId;
  300. $packProductModel->class_id = $classId;
  301. $packProductModel->class_name = $classinfo['class_name'];
  302. $packProductModel->unique_key = $examId;
  303. $packProductModel->student_count = count($params['studentIds']);
  304. $packProductModel->pack_json = json_encode($params);
  305. $packProductModel->pack_api_url = $apiUrl . "/rest/download_pdf/index";
  306. $packProductModel->create_time = time();
  307. $packProductModel->save();
  308. if($this->updateIspDownloadStatus($params["studentIds"],$classId,$examId,$isDownloadColumn,$downloadTimeCoulmn) !== false){
  309. ProductProcessTime::model()->updateDownloadTime($params["studentIds"],$type,$examId);
  310. }
  311. echo json_encode(array("success" => 3, "message" => ""));
  312. exit;
  313. }
  314. //阶段复习个性化学习宝下载
  315. public function actionDownload_student_product()
  316. {
  317. $classId = Req::get("classId");
  318. $type = Req::get("type");
  319. $studentsIds = Req::get("studentsIds");
  320. $classDownload = $studentsIds ? false : true;
  321. if (!$classId || !$type) {
  322. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  323. exit();
  324. }
  325. if (!in_array($type, array(1, 2, 3))) {
  326. echo json_encode(array("success" => 0, "message" => "参数错误[1]"));
  327. exit();
  328. }
  329. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  330. if (!$apiUrl) {
  331. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  332. exit();
  333. }
  334. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $classId));
  335. $student_class_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status', array(':class_id' => $classId, ':status' => 0));
  336. if ($student_class_data) {
  337. if (!$studentsIds) {
  338. $studentsIds = array();
  339. foreach ($student_class_data as $v) {
  340. $studentsIds[] = $v->student_id;
  341. }
  342. }
  343. }else{
  344. echo json_encode(array("success" => 0, "message" => "班级暂无学生"));
  345. exit;
  346. }
  347. if(in_array($this->subjectId,$this->mathSubjectId)){
  348. $subjectId=3;
  349. }else{
  350. $subjectId=$this->subjectId;
  351. }
  352. $params = array(
  353. "schoolId" => $this->schoolId,
  354. "classId" => $classId,
  355. "type" => $type,
  356. 'subjectId'=>$subjectId
  357. );
  358. if ($studentsIds) {
  359. if (!is_array($studentsIds)) {
  360. $studentsIds = explode(',', $studentsIds);
  361. }
  362. $stuids = array();
  363. if (Yii::app()->params["limit_open"]) {
  364. $semester = new SSemester();
  365. $nowsem = $semester->getCurrentSemester();
  366. $intarr = array(
  367. "schoolId" => $this->schoolId,
  368. "clazzId" => $classId,
  369. "semester" => $nowsem['refer_code'],
  370. "grade" => $classinfo['grade'],
  371. "examTime" => time(),
  372. "classify" => 1,
  373. "subject" => $subjectId,
  374. "students" => $studentsIds
  375. );
  376. $this->getStuOrder($intarr, $stuids);
  377. } else {
  378. $stuids = $studentsIds;
  379. }
  380. if (!$stuids) {
  381. echo json_encode(array("success" => 0, "message" => "所选的学生没有下载权限"));
  382. exit;
  383. }
  384. $params['studentIds'] = $stuids;
  385. $_students = array();
  386. if ($params["studentIds"]) {
  387. $_students = $params["studentIds"];
  388. }
  389. $_student_product_data=SStudentProductModel::model()->getStudentCreate($_students,$subjectId,$type,$this->semesterId);
  390. if (!$_student_product_data) {
  391. echo json_encode(array("success" => 0, "message" => "所选的学生尚未生成PDF"));
  392. exit;
  393. }
  394. }
  395. $planId=SStudentProductModel::model()->getPlanId($classId,$subjectId,$type);
  396. $params['planId']=$planId;
  397. //**************** Step-2 判断是否已经存在下载任务 ********************//
  398. if ($classDownload) {
  399. $packTask = $this->getExistTask($this->semesterId . '_' . $type, $classId, ProductDownload::PRODUCT_TYPE_STAGE_REVIEW, count($studentsIds));
  400. if (isset($packTask->pack_status) && $packTask->pack_status == 0) {
  401. echo json_encode(array("success" => 3, "message" => ""));
  402. exit;
  403. }
  404. if (isset($packTask->pack_url) && $packTask->pack_url) {
  405. $this->updateSpDownloadStatus($params['studentIds'],$type,$planId);
  406. echo json_encode(array("success" => 1, "downloadPath" => $packTask->pack_url));
  407. exit;
  408. }
  409. }
  410. //**************** Step-3 根据接口获取文件大小来判断走原有接口打包流程还是走脚本任务 ************//
  411. $pathArr = array();
  412. if (isset($_student_product_data)) {
  413. foreach ($_student_product_data as $item) {
  414. $pathArr[] = $item['pdf_path'];
  415. }
  416. }
  417. $sizeRs = Curl::post($apiUrl . "/rest/download_file_size/index", array('path_arr' => $pathArr));
  418. if (!($sizeRs = json_decode($sizeRs))) {
  419. echo json_encode(array("success" => 0, "message" => "请求接口失败"));
  420. exit;
  421. }
  422. if (isset($sizeRs->size)) {
  423. //************ Step-3-1 大于限定值 发送任务到后台打包 ******//
  424. if (Yii::app()->params["pack_product_file_limit"] < $sizeRs->size) {
  425. $semesterName = isset($nowsem->semester_name) ? $nowsem->semester_name : '';
  426. if ($type == 1) {
  427. $productName = $semesterName . '"期中阶段复习个性化学习宝"';
  428. } elseif ($type == 2) {
  429. $productName = $semesterName . '"期末阶段复习个性化学习宝"';
  430. } else {
  431. $productName = $semesterName . '"总复习个性化学习宝"';
  432. }
  433. $packProductModel = new BusinessPackProductTask();
  434. $packProductModel->school_id = $this->schoolId;
  435. $packProductModel->auth_username = $this->authUsername;
  436. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_STAGE_REVIEW;
  437. $packProductModel->product_name = $productName;
  438. $packProductModel->subject_id = $this->subjectId;
  439. $packProductModel->class_id = $classId;
  440. $packProductModel->class_name = $classinfo['class_name'];
  441. $packProductModel->unique_key = $this->semesterId . '_' . $type;
  442. $packProductModel->student_count = count($params['studentIds']);
  443. $packProductModel->pack_json = json_encode($params);
  444. $packProductModel->pack_api_url = $apiUrl . "/rest/download_sp/index";
  445. $packProductModel->create_time = time();
  446. $packProductModel->save();
  447. $this->updateSpDownloadStatus($params['studentIds'],$type,$planId);
  448. echo json_encode(array("success" => 3, "message" => ""));
  449. exit;
  450. } else {
  451. //************ Step-3-2 小于限定值 走原有api流程 ******//
  452. $rs = Curl::post($apiUrl . "/rest/download_sp/index", $params);
  453. if (!($rs = json_decode($rs))) {
  454. echo json_encode(array("success" => 0, "message" => "请求接口失败"));
  455. exit;
  456. }
  457. if ($rs->success != 0) {
  458. $rs->success = 2;
  459. $rs->limitinfo = '全班允许下载';
  460. }
  461. if ($params["studentIds"] && ($rs->success == 1 || $rs->success == 2)) {
  462. $this->updateSpDownloadStatus($params['studentIds'],$type,$planId);
  463. }
  464. echo json_encode($rs);
  465. exit;
  466. }
  467. } else {
  468. echo json_encode(array("success" => 0, "message" => $sizeRs->message));
  469. exit;
  470. }
  471. }
  472. /**
  473. * 更新阶段复习个性化学习宝下载状态
  474. * @param $studentIds
  475. * @param $type
  476. */
  477. private function updateSpDownloadStatus($studentIds, $type,$planId)
  478. {
  479. $criteria = new CDbCriteria();
  480. $criteria->addInCondition('student_id', $studentIds);
  481. $criteria->addCondition('type=:type');
  482. $criteria->addCondition('plan_id=:pid');
  483. $criteria->params[':type'] = $type;
  484. $criteria->params[':pid'] = $planId;
  485. SStudentProductModel::model()->updateAll(array('is_download' => 1, 'download_time' => time()), $criteria);
  486. }
  487. //添加阶段复习个性化学习宝下载任务
  488. public function actionAddSpTask()
  489. {
  490. $classId = Req::get("classId");
  491. $type = Req::get("type");
  492. $studentsIds = Req::get("studentsIds");
  493. if (!$classId || !$type) {
  494. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  495. exit();
  496. }
  497. if (!in_array($type, array(1, 2, 3))) {
  498. echo json_encode(array("success" => 0, "message" => "参数错误[1]"));
  499. exit();
  500. }
  501. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  502. if (!$apiUrl) {
  503. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  504. exit();
  505. }
  506. $params = array(
  507. "schoolId" => $this->schoolId,
  508. "classId" => $classId,
  509. "type" => $type,
  510. );
  511. $student_class_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status', array(':class_id' => $classId, ':status' => 0));
  512. if ($student_class_data) {
  513. if (!$studentsIds) {
  514. $studentsIds = array();
  515. foreach ($student_class_data as $v) {
  516. $studentsIds[] = $v->student_id;
  517. }
  518. }
  519. } else {
  520. echo json_encode(array("success" => 0, "message" => "班级暂无学生"));
  521. exit;
  522. }
  523. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $classId));
  524. if ($studentsIds) {
  525. if (!is_array($studentsIds)) {
  526. $studentsIds = explode(',', $studentsIds);
  527. }
  528. $stuids = array();
  529. if (Yii::app()->params["limit_open"]) {
  530. $semester = new SSemester();
  531. $nowsem = $semester->getCurrentSemester();
  532. $intarr = array(
  533. "schoolId" => $this->schoolId,
  534. "clazzId" => $classId,
  535. "semester" => $nowsem['refer_code'],
  536. "grade" => $classinfo['grade'],
  537. "examTime" => time(),
  538. "classify" => 1,
  539. "subject" => 3,
  540. "students" => $studentsIds
  541. );
  542. $this->getStuOrder($intarr, $stuids);
  543. } else {
  544. $stuids = $studentsIds;
  545. }
  546. if (!$stuids) {
  547. echo json_encode(array("success" => 0, "message" => "所选的学生没有下载权限"));
  548. exit;
  549. }
  550. $params['studentIds'] = $stuids;
  551. $criteria = new CDbCriteria();
  552. $_students = array();
  553. if ($params["studentIds"]) {
  554. $_students = $params["studentIds"];
  555. }
  556. $criteria->addInCondition('student_id',$_students);
  557. $criteria->addCondition('semester_id=:semester_id');
  558. $criteria->addCondition('type=:type');
  559. $criteria->addCondition('is_pdf_created=:is_pdf_created');
  560. $criteria->params[':semester_id'] = $this->semesterId;
  561. $criteria->params[':type'] = $type;
  562. $criteria->params[':is_pdf_created'] = 1;
  563. $_student_product_data = SStudentProductModel::model()->findAll($criteria);
  564. if (!$_student_product_data) {
  565. echo json_encode(array("success" => 0, "message" => "所选的学生尚未生成PDF"));
  566. exit;
  567. }
  568. }
  569. $semesterName = isset($nowsem->semester_name) ? $nowsem->semester_name : '';
  570. if ($type == 1) {
  571. $productName = $semesterName . '"期中阶段复习个性化学习宝"';
  572. } elseif ($type == 2) {
  573. $productName = $semesterName . '"期末阶段复习个性化学习宝"';
  574. } else {
  575. $productName = $semesterName . '"总复习个性化学习宝"';
  576. }
  577. $packProductModel = new BusinessPackProductTask();
  578. $packProductModel->school_id = $this->schoolId;
  579. $packProductModel->auth_username = $this->authUsername;
  580. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_STAGE_REVIEW;
  581. $packProductModel->product_name = $productName;
  582. $packProductModel->subject_id = $this->subjectId;
  583. $packProductModel->class_id = $classId;
  584. $packProductModel->class_name = $classinfo['class_name'];
  585. $packProductModel->unique_key = $this->semesterId . '_' . $type;
  586. $packProductModel->student_count = count($params['studentIds']);
  587. $packProductModel->pack_json = json_encode($params);
  588. $packProductModel->pack_api_url = $apiUrl . "/rest/download_sp/index";
  589. $packProductModel->create_time = time();
  590. $packProductModel->save();
  591. $this->updateSpDownloadStatus($params['studentIds'],$type);
  592. echo json_encode(array("success" => 3, "message" => ""));
  593. exit;
  594. }
  595. /**
  596. * 下载二轮复习个性化提分手册
  597. */
  598. public function actionGetMathReviewFile()
  599. {
  600. $mrId = (string)Req::get("mrId");
  601. $studentsIds = Req::get("studentsIds");
  602. $classDownload = $studentsIds ? false : true;
  603. $params = array();
  604. if (!$mrId) {
  605. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  606. exit();
  607. }
  608. //*****获取生成的学生***//
  609. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_SECOND_RUN);
  610. $generateStu = $productDownload->getGenerateStu('math_review_student', 'mr_id', 'review_pdf_path', 'is_review_pdf', $mrId, $studentsIds);
  611. if(!$generateStu){
  612. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  613. }
  614. $params['studentIds'] = $generateStu['studentIds'];
  615. $pathArr = $generateStu['pathArr'];
  616. $params['mrId'] = $mrId;
  617. $sql = "select class_id,grade,create_time,semester_id,school_group_id,`name` from math_review_setting where mr_id = '{$mrId}'";
  618. $msg = $this->sConn->createCommand($sql)->queryRow();
  619. $Sem = new SSemester();
  620. $code = $Sem->conn->createQuery()
  621. ->from('semester')
  622. ->where("semester_id = '" . $msg['semester_id'] . "'")
  623. ->limit(1)
  624. ->query()
  625. ->read();
  626. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  627. $intarr = array(
  628. "schoolId" => $this->schoolId,
  629. "clazzId" => $msg['class_id'],
  630. "semester" => $code['refer_code'],
  631. "grade" => $msg['grade'],
  632. "students" => $studentsIds,
  633. "examTime" => $msg['create_time'],
  634. "classify" => 5,
  635. "subject" => 3
  636. );
  637. if (isset($msg['school_group_id']) && $msg['school_group_id']) {
  638. $apiUrl = isset(Yii::app()->params["improve_url"][$msg['school_group_id']]) ? Yii::app()->params["improve_url"][$msg['school_group_id']] : null;
  639. } else {
  640. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  641. }
  642. if (!$apiUrl) {
  643. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  644. exit();
  645. }
  646. //************ Step-1 判断是否有订单 *************//
  647. if (Yii::app()->params["limit_open"]) {
  648. if (Yii::app()->params["limit_open"]) {
  649. $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId);
  650. }
  651. }
  652. $params['schoolId'] = $this->schoolId;
  653. $params['type'] = 1;
  654. //**************** Step-2 判断是否已经存在下载任务 ********************//
  655. if ($classDownload) {
  656. $packTask = $this->getExistTask($mrId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_SECOND_RUN, count($params["studentIds"]));
  657. if (isset($packTask->pack_status) && $packTask->pack_status == 0) {
  658. echo json_encode(array("success" => 3, "message" => ""));
  659. exit;
  660. }
  661. if (isset($packTask->pack_url) && $packTask->pack_url) {
  662. $this->updateSecondRunDownloadStatus($params['studentIds'],$mrId);
  663. echo json_encode(array("success" => 1, "downloadPath" => $packTask->pack_url));
  664. exit;
  665. }
  666. }
  667. //**************** Step-3 根据接口获取文件大小来判断走原有接口打包流程还是走脚本任务 ************//
  668. $sizeRs = Curl::post($apiUrl . "/rest/download_file_size/index", array('path_arr' => $pathArr));
  669. if (!($sizeRs = json_decode($sizeRs))) {
  670. echo json_encode(array("success" => 0, "message" => "请求接口失败"));
  671. exit;
  672. }
  673. if (isset($sizeRs->size)) {
  674. //************ Step-3-1 大于限定值 发送任务到后台打包 ******//
  675. if (Yii::app()->params["pack_product_file_limit"] < $sizeRs->size) {
  676. $packProductModel = new BusinessPackProductTask();
  677. $packProductModel->school_id = $this->schoolId;
  678. $packProductModel->auth_username = $this->authUsername;
  679. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_SECOND_RUN;
  680. $packProductModel->product_name = $msg['name'].'二轮复习提分手册';
  681. $packProductModel->subject_id = $this->subjectId;
  682. $packProductModel->class_id = $msg['class_id'];
  683. $packProductModel->class_name = $classinfo['class_name'];
  684. $packProductModel->unique_key = $mrId;
  685. $packProductModel->student_count = count($params['studentIds']);
  686. $packProductModel->pack_json = json_encode($params);
  687. $packProductModel->pack_api_url = $apiUrl . "/rest/download_math_pdf/index";
  688. $packProductModel->create_time = time();
  689. $packProductModel->save();
  690. $this->updateSecondRunDownloadStatus($params['studentIds'],$mrId);
  691. echo json_encode(array("success" => 3, "message" => ""));
  692. exit;
  693. } else {
  694. $rs = Curl::post($apiUrl . "/rest/download_math_pdf/index", $params);
  695. if (!($rs = json_decode($rs))) {
  696. echo json_encode(array("success" => 0, "message" => '请求接口失败'));
  697. exit;
  698. } else {
  699. //更新下载时间
  700. if ($rs->success == 1 || $rs->success == 2) {
  701. $this->updateSecondRunDownloadStatus($params['studentIds'],$mrId);
  702. }
  703. }
  704. if (isset($msg['school_group_id']) && $msg['school_group_id'] && isset($rs->downloadPath)) {
  705. if (YII_ENV == 'pro' || YII_ENV == 'production') {
  706. $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/', 'http://zstatic' . $msg['school_group_id'], $rs->downloadPath);
  707. }
  708. }
  709. echo json_encode($rs);
  710. exit;
  711. }
  712. } else {
  713. echo json_encode(array("success" => 0, "message" => $sizeRs->message));
  714. exit;
  715. }
  716. }
  717. /**
  718. * 更新二轮下载状态
  719. * @param $studentsIds
  720. * @param $mrId
  721. */
  722. private function updateSecondRunDownloadStatus($studentsIds, $mrId)
  723. {
  724. $time = time();
  725. $sql = "update math_review_student set is_review_download = 1,review_download_time={$time} where mr_id = '{$mrId}' and student_id in (" . implode(',', $studentsIds) . ")";
  726. $this->sConn->createCommand($sql)->execute();
  727. }
  728. /**
  729. * 添加二轮提分手册下载任务
  730. */
  731. public function actionAddSecondRunTask()
  732. {
  733. $mrId = (string)Req::get("mrId");
  734. $studentsIds = Req::get("studentsIds");
  735. $params = array();
  736. if (!$mrId) {
  737. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  738. exit();
  739. }
  740. //*****获取生成的学生***//
  741. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_SECOND_RUN);
  742. $generateStu = $productDownload->getGenerateStu('math_review_student', 'mr_id', 'review_pdf_path', 'is_review_pdf', $mrId, $studentsIds);
  743. if(!$generateStu){
  744. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  745. }
  746. $params['studentIds'] = $generateStu['studentIds'];
  747. $sql = "select class_id,grade,create_time,semester_id,school_group_id,`name` from math_review_setting where mr_id = '{$mrId}'";
  748. $msg = $this->sConn->createCommand($sql)->queryRow();
  749. $Sem = new SSemester();
  750. $code = $Sem->conn->createQuery()
  751. ->from('semester')
  752. ->where("semester_id = '" . $msg['semester_id'] . "'")
  753. ->limit(1)
  754. ->query()
  755. ->read();
  756. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  757. $intarr = array(
  758. "schoolId" => $this->schoolId,
  759. "clazzId" => $msg['class_id'],
  760. "semester" => $code['refer_code'],
  761. "grade" => $msg['grade'],
  762. "examTime" => $msg['create_time'],
  763. "classify" => 5,
  764. "subject" => 3
  765. );
  766. if (isset($msg['school_group_id']) && $msg['school_group_id']) {
  767. $apiUrl = isset(Yii::app()->params["improve_url"][$msg['school_group_id']]) ? Yii::app()->params["improve_url"][$msg['school_group_id']] : null;
  768. } else {
  769. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  770. }
  771. if (!$apiUrl) {
  772. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  773. exit();
  774. }
  775. //************ Step-1 判断是否有订单 *************//
  776. if (Yii::app()->params["limit_open"]) {
  777. if (Yii::app()->params["limit_open"]) {
  778. $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId);
  779. }
  780. }
  781. $params['mrId'] = $mrId;
  782. $params['schoolId'] = $this->schoolId;
  783. $params['type'] = 1;
  784. $packProductModel = new BusinessPackProductTask();
  785. $packProductModel->school_id = $this->schoolId;
  786. $packProductModel->auth_username = $this->authUsername;
  787. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_SECOND_RUN;
  788. $packProductModel->product_name = $msg['name'].'二轮复习提分手册';
  789. $packProductModel->subject_id = $this->subjectId;
  790. $packProductModel->class_id = $msg['class_id'];
  791. $packProductModel->class_name = $classinfo['class_name'];
  792. $packProductModel->unique_key = $mrId;
  793. $packProductModel->student_count = count($params['studentIds']);
  794. $packProductModel->pack_json = json_encode($params);
  795. $packProductModel->pack_api_url = $apiUrl . "/rest/download_math_pdf/index";
  796. $packProductModel->create_time = time();
  797. $packProductModel->save();
  798. $this->updateSecondRunDownloadStatus($params['studentIds'],$mrId);
  799. echo json_encode(array("success" => 3, "message" => ""));
  800. exit;
  801. }
  802. /**
  803. * 下载好题本
  804. */
  805. public function actionGetHtbFile()
  806. {
  807. $htbId = (string)Req::get("htbId");
  808. $studentsIds = Req::get("studentsIds");
  809. $classDownload = $studentsIds ? false : true;
  810. $params = array();
  811. if (!$htbId) {
  812. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  813. exit();
  814. }
  815. //*****获取生成的学生***//
  816. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_HTB);
  817. $generateStu = $productDownload->getGenerateStu('math_htb_student', 'htb_id', 'htb_pdf_path', 'is_htb_pdf', $htbId, $studentsIds);
  818. if(!$generateStu){
  819. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  820. }
  821. $params['studentIds'] = $generateStu['studentIds'];
  822. $pathArr = $generateStu['pathArr'];
  823. $sql = "select class_id,grade,create_time,semester_id,school_group_id,name from math_htb_setting where htb_id = '{$htbId}'";
  824. $msg = $this->sConn->createCommand($sql)->queryRow();
  825. $Sem = new SSemester();
  826. $code = $Sem->conn->createQuery()
  827. ->from('semester')
  828. ->where("semester_id = '" . $msg['semester_id'] . "'")
  829. ->limit(1)
  830. ->query()
  831. ->read();
  832. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  833. $intarr = array(
  834. "schoolId" => $this->schoolId,
  835. "clazzId" => $msg['class_id'],
  836. "semester" => $code['refer_code'],
  837. "grade" => $msg['grade'],
  838. "examTime" => $msg['create_time'],
  839. "classify" => 9,
  840. "subject" => 3
  841. );
  842. if (isset($msg['school_group_id']) && $msg['school_group_id']) {
  843. $apiUrl = isset(Yii::app()->params["improve_url"][$msg['school_group_id']]) ? Yii::app()->params["improve_url"][$msg['school_group_id']] : null;
  844. } else {
  845. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  846. }
  847. if (!$apiUrl) {
  848. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  849. exit();
  850. }
  851. //************ Step-1 判断是否有订单 *************//
  852. if (Yii::app()->params["limit_open"]) {
  853. if (Yii::app()->params["limit_open"]) {
  854. $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId);
  855. }
  856. }
  857. $params['schoolId'] = $this->schoolId;
  858. $params['type'] = 5;
  859. $params['htbId'] = $htbId;
  860. //**************** Step-2 判断是否已经存在下载任务 ********************//
  861. if ($classDownload) {
  862. $packTask = $this->getExistTask($htbId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_HTB, count($params["studentIds"]));
  863. if (isset($packTask->pack_status) && $packTask->pack_status == 0) {
  864. echo json_encode(array("success" => 3, "message" => ""));
  865. exit;
  866. }
  867. if (isset($packTask->pack_url) && $packTask->pack_url) {
  868. $this->updateHtbDownloadStatus($params['studentIds'],$htbId);
  869. echo json_encode(array("success" => 1, "downloadPath" => $packTask->pack_url));
  870. exit;
  871. }
  872. }
  873. //**************** Step-3 根据接口获取文件大小来判断走原有接口打包流程还是走脚本任务 ************//
  874. $sizeRs = Curl::post($apiUrl . "/rest/download_file_size/index", array('path_arr' => $pathArr));
  875. if (!($sizeRs = json_decode($sizeRs))) {
  876. echo json_encode(array("success" => 0, "message" => "请求接口失败"));
  877. exit;
  878. }
  879. if (isset($sizeRs->size)) {
  880. //************ Step-3-1 大于限定值 发送任务到后台打包 ******//
  881. if (Yii::app()->params["pack_product_file_limit"] < $sizeRs->size) {
  882. $packProductModel = new BusinessPackProductTask();
  883. $packProductModel->school_id = $this->schoolId;
  884. $packProductModel->auth_username = $this->authUsername;
  885. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_HTB;
  886. $packProductModel->product_name = $msg['name'].'好题本';
  887. $packProductModel->subject_id = $this->subjectId;
  888. $packProductModel->class_id = $msg['class_id'];
  889. $packProductModel->class_name = $classinfo['class_name'];
  890. $packProductModel->unique_key = $htbId;
  891. $packProductModel->student_count = count($params['studentIds']);
  892. $packProductModel->pack_json = json_encode($params);
  893. $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index";
  894. $packProductModel->create_time = time();
  895. $packProductModel->save();
  896. $this->updateHtbDownloadStatus($params['studentIds'],$htbId);
  897. echo json_encode(array("success" => 3, "message" => ""));
  898. exit;
  899. } else {
  900. $rs = Curl::post($apiUrl . "/rest/download_week_pdf/index", $params);
  901. if (!($rs = json_decode($rs))) {
  902. echo json_encode(array("success" => 0, "message" => '请求接口失败'));
  903. exit;
  904. } else {
  905. //更新下载时间
  906. if ($rs->success == 1 || $rs->success == 2) {
  907. $this->updateHtbDownloadStatus($params['studentIds'],$htbId);
  908. }
  909. }
  910. if (isset($msg['school_group_id']) && $msg['school_group_id'] && isset($rs->downloadPath)) {
  911. if (YII_ENV == 'pro' || YII_ENV == 'production') {
  912. $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/', 'http://zstatic' . $msg['school_group_id'], $rs->downloadPath);
  913. }
  914. }
  915. echo json_encode($rs);
  916. exit;
  917. }
  918. } else {
  919. echo json_encode(array("success" => 0, "message" => $sizeRs->message));
  920. exit;
  921. }
  922. }
  923. /**
  924. * 更新好题本下载状态
  925. * @param $studentsIds
  926. * @param $htbId
  927. */
  928. private function updateHtbDownloadStatus($studentsIds, $htbId)
  929. {
  930. $time = time();
  931. $sql = "update math_htb_student set is_htb_download = 1,htb_download_time={$time} where htb_id = '{$htbId}' and student_id in (" . implode(',', $studentsIds) . ")";
  932. $this->sConn->createCommand($sql)->execute();
  933. }
  934. /**
  935. * 添加好题本下载任务
  936. */
  937. public function actionAddHtbTask()
  938. {
  939. $htbId = (string)Req::get("htbId");
  940. $studentsIds = Req::get("studentsIds");
  941. $params = array();
  942. if (!$htbId) {
  943. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  944. exit();
  945. }
  946. //*****获取生成的学生***//
  947. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_HTB);
  948. $generateStu = $productDownload->getGenerateStu('math_htb_student', 'htb_id', 'htb_pdf_path', 'is_htb_pdf', $htbId, $studentsIds);
  949. if(!$generateStu){
  950. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  951. }
  952. $params['studentIds'] = $generateStu['studentIds'];
  953. $sql = "select class_id,grade,create_time,semester_id,school_group_id from math_htb_setting where htb_id = '{$htbId}'";
  954. $msg = $this->sConn->createCommand($sql)->queryRow();
  955. $Sem = new SSemester();
  956. $code = $Sem->conn->createQuery()
  957. ->from('semester')
  958. ->where("semester_id = '" . $msg['semester_id'] . "'")
  959. ->limit(1)
  960. ->query()
  961. ->read();
  962. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  963. $intarr = array(
  964. "schoolId" => $this->schoolId,
  965. "clazzId" => $msg['class_id'],
  966. "semester" => $code['refer_code'],
  967. "grade" => $msg['grade'],
  968. "examTime" => $msg['create_time'],
  969. "classify" => 9,
  970. "subject" => 3
  971. );
  972. if (isset($msg['school_group_id']) && $msg['school_group_id']) {
  973. $apiUrl = isset(Yii::app()->params["improve_url"][$msg['school_group_id']]) ? Yii::app()->params["improve_url"][$msg['school_group_id']] : null;
  974. } else {
  975. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  976. }
  977. if (!$apiUrl) {
  978. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  979. exit();
  980. }
  981. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_HTB);
  982. //************ Step-1 判断是否有订单 *************//
  983. if (Yii::app()->params["limit_open"]) {
  984. if (Yii::app()->params["limit_open"]) {
  985. $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId);
  986. }
  987. }
  988. $params['schoolId'] = $this->schoolId;
  989. $params['type'] = 5;
  990. $params['htbId'] = $htbId;
  991. $packProductModel = new BusinessPackProductTask();
  992. $packProductModel->school_id = $this->schoolId;
  993. $packProductModel->auth_username = $this->authUsername;
  994. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_HTB;
  995. $packProductModel->product_name = $msg['name']."好题本";
  996. $packProductModel->subject_id = $this->subjectId;
  997. $packProductModel->class_id = $msg['class_id'];
  998. $packProductModel->class_name = $classinfo['class_name'];
  999. $packProductModel->unique_key = $htbId;
  1000. $packProductModel->student_count = count($params['studentIds']);
  1001. $packProductModel->pack_json = json_encode($params);
  1002. $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index";
  1003. $packProductModel->create_time = time();
  1004. $packProductModel->save();
  1005. $this->updateHtbDownloadStatus($params['studentIds'],$htbId);
  1006. echo json_encode(array("success" => 3, "message" => ""));
  1007. exit;
  1008. }
  1009. /**
  1010. * 下载假期报告
  1011. */
  1012. public function actionGetHolidayReportFile()
  1013. {
  1014. $reportId = (string)Req::get("reportId");
  1015. $studentsIds = Req::get("studentsIds");
  1016. $classDownload = $studentsIds ? false : true;
  1017. $params = array();
  1018. if (!$reportId) {
  1019. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  1020. exit();
  1021. }
  1022. //获取组ID
  1023. $sql = "select school_group_id,semester_id from holiday_report_setting where report_id = '{$reportId}'";
  1024. $report_settint_data = $this->sConn->createCommand($sql)->queryRow();
  1025. if (!$report_settint_data) {
  1026. echo json_encode(array("success" => 0, "message" => "设置信息错误"));
  1027. exit();
  1028. } else {
  1029. $school_group_id = $report_settint_data['school_group_id'];
  1030. }
  1031. if (isset($school_group_id) && $school_group_id) {
  1032. $apiUrl = isset(Yii::app()->params["improve_url"][$school_group_id]) ? Yii::app()->params["improve_url"][$school_group_id] : null;
  1033. } else {
  1034. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  1035. }
  1036. //*****获取生成的学生***//
  1037. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_HOLIDAY_REPORT);
  1038. $generateStu = $productDownload->getGenerateStu('holiday_report_student', 'report_id', 'report_pdf_path', 'is_report_pdf', $reportId, $studentsIds);
  1039. if(!$generateStu){
  1040. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  1041. }
  1042. $params['studentIds'] = $generateStu['studentIds'];
  1043. $pathArr = $generateStu['pathArr'];
  1044. if (!$apiUrl) {
  1045. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  1046. exit();
  1047. }
  1048. $sql = "select class_id,grade,create_time,semester_id from holiday_report_setting where report_id = '{$reportId}'";
  1049. $msg = $this->sConn->createCommand($sql)->queryRow();
  1050. $Sem = new SSemester();
  1051. $code = $Sem->conn->createQuery()
  1052. ->from('semester')
  1053. ->where("semester_id = '" . $msg['semester_id'] . "'")
  1054. ->limit(1)
  1055. ->query()
  1056. ->read();
  1057. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  1058. $intarr = array(
  1059. "subject" => 3,
  1060. "grade" => $msg['grade'],
  1061. "examTime" => $msg['create_time'],
  1062. );
  1063. //************ Step-1 判断是否有订单 *************//
  1064. $params["studentIds"] = $params['studentIds'];
  1065. // if (Yii::app()->params["limit_open"]) {
  1066. // $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId);
  1067. // }
  1068. $params['schoolId'] = $this->schoolId;
  1069. $params['type'] = 4;
  1070. $params['reportId'] = $reportId;
  1071. //**************** Step-2 判断是否已经存在下载任务 ********************//
  1072. if ($classDownload) {
  1073. $packTask = $this->getExistTask($reportId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_HOLIDAY_REPORT, count($params["studentIds"]));
  1074. if (isset($packTask->pack_status) && $packTask->pack_status == 0) {
  1075. echo json_encode(array("success" => 3, "message" => ""));
  1076. exit;
  1077. }
  1078. if (isset($packTask->pack_url) && $packTask->pack_url) {
  1079. $this->updateHrpDownloadStatus($params['studentIds'],$reportId);
  1080. echo json_encode(array("success" => 1, "downloadPath" => $packTask->pack_url));
  1081. exit;
  1082. }
  1083. }
  1084. //**************** Step-3 根据接口获取文件大小来判断走原有接口打包流程还是走脚本任务 ************//
  1085. $sizeRs = Curl::post($apiUrl . "/rest/download_file_size/index", array('path_arr' => $pathArr));
  1086. if (!($sizeRs = json_decode($sizeRs))) {
  1087. echo json_encode(array("success" => 0, "message" => "请求接口失败"));
  1088. exit;
  1089. }
  1090. $smeName = isset($code['name'] ) ? $code['name'] : '';
  1091. if (isset($sizeRs->size)) {
  1092. //************ Step-3-1 大于限定值 发送任务到后台打包 ******//
  1093. if (Yii::app()->params["pack_product_file_limit"] < $sizeRs->size) {
  1094. $packProductModel = new BusinessPackProductTask();
  1095. $packProductModel->school_id = $this->schoolId;
  1096. $packProductModel->auth_username = $this->authUsername;
  1097. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_HOLIDAY_REPORT;
  1098. $packProductModel->product_name = $classinfo['class_name'].$smeName . '假期总结报告';
  1099. $packProductModel->subject_id = $this->subjectId;
  1100. $packProductModel->class_id = $msg['class_id'];
  1101. $packProductModel->class_name = $classinfo['class_name'];
  1102. $packProductModel->unique_key = $reportId;
  1103. $packProductModel->student_count = count($params['studentIds']);
  1104. $packProductModel->pack_json = json_encode($params);
  1105. $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index";
  1106. $packProductModel->create_time = time();
  1107. $packProductModel->save();
  1108. $this->updateHrpDownloadStatus($params['studentIds'],$reportId);
  1109. echo json_encode(array("success" => 3, "message" => ""));
  1110. exit;
  1111. } else {
  1112. $rs = Curl::post($apiUrl . "/rest/download_week_pdf/index", $params);
  1113. if (!($rs = json_decode($rs))) {
  1114. $rs = array(
  1115. "success" => 0,
  1116. "message" => "请求接口失败",
  1117. );
  1118. } else {
  1119. //更新下载时间
  1120. $this->updateHrpDownloadStatus($params['studentIds'],$reportId);
  1121. }
  1122. if (isset($school_group_id) && $school_group_id && isset($rs->downloadPath)) {
  1123. if (YII_ENV == 'pro' || YII_ENV == 'production') {
  1124. $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/', 'http://zstatic' . $school_group_id, $rs->downloadPath);
  1125. }
  1126. }
  1127. echo json_encode($rs);
  1128. exit;
  1129. }
  1130. } else {
  1131. echo json_encode(array("success" => 0, "message" => $sizeRs->message));
  1132. exit;
  1133. }
  1134. }
  1135. /**
  1136. * 更新假期报告下载状态
  1137. * @param $studentsIds
  1138. * @param $reportId
  1139. */
  1140. private function updateHrpDownloadStatus($studentsIds, $reportId){
  1141. $time = time();
  1142. $sql = "update holiday_report_student set is_report_download = 1,report_download_time={$time} where report_id = '{$reportId}' and student_id in (" . implode(',', $studentsIds) . ") and report_download_time = 0";
  1143. $this->sConn->createCommand($sql)->execute();
  1144. }
  1145. /**
  1146. * 添加假期报告下载任务
  1147. */
  1148. public function actionAddHolidayReportTask()
  1149. {
  1150. $reportId = (string)Req::get("reportId");
  1151. $studentsIds = Req::get("studentsIds");
  1152. $params = array();
  1153. if (!$reportId) {
  1154. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  1155. exit();
  1156. }
  1157. //获取组ID
  1158. $sql = "select school_group_id,semester_id from holiday_report_setting where report_id = '{$reportId}'";
  1159. $report_settint_data = $this->sConn->createCommand($sql)->queryRow();
  1160. if (!$report_settint_data) {
  1161. echo json_encode(array("success" => 0, "message" => "设置信息错误"));
  1162. exit();
  1163. } else {
  1164. $school_group_id = $report_settint_data['school_group_id'];
  1165. }
  1166. if (isset($school_group_id) && $school_group_id) {
  1167. $apiUrl = isset(Yii::app()->params["improve_url"][$school_group_id]) ? Yii::app()->params["improve_url"][$school_group_id] : null;
  1168. } else {
  1169. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  1170. }
  1171. //*****获取生成的学生***//
  1172. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_HOLIDAY_REPORT);
  1173. $generateStu = $productDownload->getGenerateStu('holiday_report_student', 'report_id', 'report_pdf_path', 'is_report_pdf', $reportId, $studentsIds);
  1174. if(!$generateStu){
  1175. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  1176. }
  1177. $params['studentIds'] = $generateStu['studentIds'];
  1178. if (!$apiUrl) {
  1179. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  1180. exit();
  1181. }
  1182. $sql = "select class_id,grade,create_time,semester_id from holiday_report_setting where report_id = '{$reportId}'";
  1183. $msg = $this->sConn->createCommand($sql)->queryRow();
  1184. $Sem = new SSemester();
  1185. $code = $Sem->conn->createQuery()
  1186. ->from('semester')
  1187. ->where("semester_id = '" . $msg['semester_id'] . "'")
  1188. ->limit(1)
  1189. ->query()
  1190. ->read();
  1191. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  1192. $intarr = array(
  1193. "subject" => 3,
  1194. "grade" => $msg['grade'],
  1195. "examTime" => $msg['create_time'],
  1196. );
  1197. //************ Step-1 判断是否有订单 *************//
  1198. if (Yii::app()->params["limit_open"]) {
  1199. $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId);
  1200. }
  1201. $params['schoolId'] = $this->schoolId;
  1202. $params['type'] = 4;
  1203. $params['reportId'] = $reportId;
  1204. $smeName = isset($code['name'] ) ? $code['name'] : '';
  1205. $packProductModel = new BusinessPackProductTask();
  1206. $packProductModel->school_id = $this->schoolId;
  1207. $packProductModel->auth_username = $this->authUsername;
  1208. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_HOLIDAY_REPORT;
  1209. $packProductModel->product_name = $classinfo['class_name'].$smeName . '假期总结报告';
  1210. $packProductModel->subject_id = $this->subjectId;
  1211. $packProductModel->class_id = $msg['class_id'];
  1212. $packProductModel->class_name = $classinfo['class_name'];
  1213. $packProductModel->unique_key = $reportId;
  1214. $packProductModel->student_count = count($params['studentIds']);
  1215. $packProductModel->pack_json = json_encode($params);
  1216. $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index";
  1217. $packProductModel->create_time = time();
  1218. $packProductModel->save();
  1219. $this->updateHrpDownloadStatus($params['studentIds'],$reportId);
  1220. echo json_encode(array("success" => 3, "message" => ""));
  1221. exit;
  1222. }
  1223. /**
  1224. * 下载晨读词汇
  1225. */
  1226. public function actionGetEnglishFile()
  1227. {
  1228. $weekId = (string)Req::get("weekId");
  1229. $studentsIds = Req::get("studentsIds");
  1230. $classDownload = $studentsIds ? false : true;
  1231. $params = array();
  1232. if (!$weekId) {
  1233. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  1234. exit();
  1235. }
  1236. //*****获取生成的学生***//
  1237. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_EN_MRV);
  1238. $generateStu = $productDownload->getGenerateStu('english_week_student', 'week_id', 'week_pdf_path', 'is_week_pdf', $weekId, $studentsIds);
  1239. if(!$generateStu){
  1240. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  1241. }
  1242. $params['studentIds'] = $generateStu['studentIds'];
  1243. $pathArr = $generateStu['pathArr'];
  1244. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  1245. if (!$apiUrl) {
  1246. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  1247. exit();
  1248. }
  1249. $sql = "select class_id,grade,create_time,semester_id,`name` from english_week where week_id = '{$weekId}'";
  1250. $msg = $this->sConn->createCommand($sql)->queryRow();
  1251. $Sem = new SSemester();
  1252. $code = $Sem->conn->createQuery()
  1253. ->from('semester')
  1254. ->where("semester_id = '" . $msg['semester_id'] . "'")
  1255. ->limit(1)
  1256. ->query()
  1257. ->read();
  1258. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  1259. $intarr = array(
  1260. "schoolId" => $this->schoolId,
  1261. "clazzId" => $msg['class_id'],
  1262. "semester" => $code['refer_code'],
  1263. "grade" => $msg['grade'],
  1264. "examTime" => $msg['create_time'],
  1265. "classify" => 3,
  1266. "subject" => 8
  1267. );
  1268. //************ Step-1 判断是否有订单 *************//
  1269. if (Yii::app()->params["limit_open"]) {
  1270. if (Yii::app()->params["limit_open"]) {
  1271. $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId);
  1272. }
  1273. }
  1274. $params['schoolId'] = $this->schoolId;
  1275. $params['type'] = 1;
  1276. $params['weekId'] = $weekId;
  1277. //**************** Step-2 判断是否已经存在下载任务 ********************//
  1278. if($classDownload) {
  1279. $packTask = $this->getExistTask($weekId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_EN_MRV, count($params["studentIds"]));
  1280. if (isset($packTask->pack_status) && $packTask->pack_status == 0) {
  1281. echo json_encode(array("success" => 3, "message" => ""));
  1282. exit;
  1283. }
  1284. if (isset($packTask->pack_url) && $packTask->pack_url) {
  1285. $this->updateEnMrvDownloadStatus($params['studentIds'],$weekId);
  1286. echo json_encode(array("success" => 1, "downloadPath" => $packTask->pack_url));
  1287. exit;
  1288. }
  1289. }
  1290. //**************** Step-3 根据接口获取文件大小来判断走原有接口打包流程还是走脚本任务 ************//
  1291. $sizeRs = Curl::post($apiUrl . "/rest/download_file_size/index", array('path_arr' => $pathArr));
  1292. if (!($sizeRs = json_decode($sizeRs))) {
  1293. echo json_encode(array("success" => 0, "message" => "请求接口失败"));
  1294. exit;
  1295. }
  1296. if (isset($sizeRs->size)) {
  1297. //************ Step-3-1 大于限定值 发送任务到后台打包 ******//
  1298. if (Yii::app()->params["pack_product_file_limit"] < $sizeRs->size) {
  1299. $packProductModel = new BusinessPackProductTask();
  1300. $packProductModel->school_id = $this->schoolId;
  1301. $packProductModel->auth_username = $this->authUsername;
  1302. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_EN_MRV;
  1303. $packProductModel->product_name = $msg['name'] . '晨读词汇';
  1304. $packProductModel->subject_id = $this->subjectId;
  1305. $packProductModel->class_id = $msg['class_id'];
  1306. $packProductModel->class_name = $classinfo['class_name'];
  1307. $packProductModel->unique_key = $weekId;
  1308. $packProductModel->student_count = count($params['studentIds']);
  1309. $packProductModel->pack_json = json_encode($params);
  1310. $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index";
  1311. $packProductModel->create_time = time();
  1312. $packProductModel->save();
  1313. $this->updateEnMrvDownloadStatus($params['studentIds'],$weekId);
  1314. echo json_encode(array("success" => 3, "message" => ""));
  1315. exit;
  1316. } else {
  1317. $rs = Curl::post($apiUrl . "/rest/download_week_pdf/index", $params);
  1318. if (!($rs = json_decode($rs))) {
  1319. $rs = array(
  1320. "success" => 0,
  1321. "message" => "请求接口失败",
  1322. );
  1323. } else {
  1324. //更新下载时间
  1325. if ($rs->success == 1 || $rs->success == 2) {
  1326. $this->updateEnMrvDownloadStatus($params['studentIds'],$weekId);
  1327. }
  1328. }
  1329. echo json_encode($rs);
  1330. exit;
  1331. }
  1332. } else {
  1333. echo json_encode(array("success" => 0, "message" => $sizeRs->message));
  1334. exit;
  1335. }
  1336. }
  1337. /**
  1338. * 更新晨读词汇下载状态
  1339. * @param $studentsIds
  1340. * @param $weekId
  1341. */
  1342. private function updateEnMrvDownloadStatus($studentsIds, $weekId)
  1343. {
  1344. $time = time();
  1345. $sql = "update english_week_student set is_week_download = 1,week_download_time={$time} where week_id = '{$weekId}' and student_id in (" . implode(',', $studentsIds) . ")";
  1346. $this->sConn->createCommand($sql)->execute();
  1347. }
  1348. /**
  1349. * 添加晨读词汇下载任务
  1350. */
  1351. public function actionAddEnMrvTask()
  1352. {
  1353. $weekId = (string)Req::get("weekId");
  1354. $studentsIds = Req::get("studentsIds");
  1355. $params = array();
  1356. if (!$weekId) {
  1357. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  1358. exit();
  1359. }
  1360. //*****获取生成的学生***//
  1361. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_EN_MRV);
  1362. $generateStu = $productDownload->getGenerateStu('english_week_student', 'week_id', 'week_pdf_path', 'is_week_pdf', $weekId, $studentsIds);
  1363. if(!$generateStu){
  1364. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  1365. }
  1366. $params['studentIds'] = $generateStu['studentIds'];
  1367. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  1368. if (!$apiUrl) {
  1369. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  1370. exit();
  1371. }
  1372. $sql = "select class_id,grade,create_time,semester_id,`name` from english_week where week_id = '{$weekId}'";
  1373. $msg = $this->sConn->createCommand($sql)->queryRow();
  1374. $Sem = new SSemester();
  1375. $code = $Sem->conn->createQuery()
  1376. ->from('semester')
  1377. ->where("semester_id = '" . $msg['semester_id'] . "'")
  1378. ->limit(1)
  1379. ->query()
  1380. ->read();
  1381. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  1382. $intarr = array(
  1383. "schoolId" => $this->schoolId,
  1384. "clazzId" => $msg['class_id'],
  1385. "semester" => $code['refer_code'],
  1386. "grade" => $msg['grade'],
  1387. "examTime" => $msg['create_time'],
  1388. "classify" => 3,
  1389. "subject" => 8
  1390. );
  1391. //************ Step-1 判断是否有订单 *************//
  1392. if (Yii::app()->params["limit_open"]) {
  1393. if (Yii::app()->params["limit_open"]) {
  1394. $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId);
  1395. }
  1396. }
  1397. $params['schoolId'] = $this->schoolId;
  1398. $params['type'] = 1;
  1399. $params['weekId'] = $weekId;
  1400. $packProductModel = new BusinessPackProductTask();
  1401. $packProductModel->school_id = $this->schoolId;
  1402. $packProductModel->auth_username = $this->authUsername;
  1403. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_EN_MRV;
  1404. $packProductModel->product_name = $msg['name'] . '晨读词汇';
  1405. $packProductModel->subject_id = $this->subjectId;
  1406. $packProductModel->class_id = $msg['class_id'];
  1407. $packProductModel->class_name = $classinfo['class_name'];
  1408. $packProductModel->unique_key = $weekId;
  1409. $packProductModel->student_count = count($params['studentIds']);
  1410. $packProductModel->pack_json = json_encode($params);
  1411. $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index";
  1412. $packProductModel->create_time = time();
  1413. $packProductModel->save();
  1414. $this->updateEnMrvDownloadStatus($params['studentIds'],$weekId);
  1415. echo json_encode(array("success" => 3, "message" => ""));
  1416. exit;
  1417. }
  1418. /**
  1419. * 下载外刊美文个性化学习宝
  1420. */
  1421. public function actionGetEnglishReadingFile()
  1422. {
  1423. $weekId = (string)Req::get("weekId");
  1424. $studentsIds = Req::get("studentsIds");
  1425. $classDownload = $studentsIds ? false : true;
  1426. $params = array();
  1427. if (!$weekId) {
  1428. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  1429. exit();
  1430. }
  1431. $sql = "select class_id,er.grade,er.create_time,er.semester_id,name,ers.category,ers.product_type from english_reading er join english_reading_setting ers on ers.reading_id=er.reading_id where week_id = '{$weekId}'";
  1432. $msg = $this->sConn->createCommand($sql)->queryRow();
  1433. $Sem = new SSemester();
  1434. $code = $Sem->conn->createQuery()
  1435. ->from('semester')
  1436. ->where("semester_id = '" . $msg['semester_id'] . "'")
  1437. ->limit(1)
  1438. ->query()
  1439. ->read();
  1440. $classify=6;
  1441. if($msg['category']==2){
  1442. if($msg['product_type']==1){
  1443. $classify=57;
  1444. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_EN_READING_JICHU);
  1445. }elseif($msg['product_type']==2){
  1446. $classify=61;
  1447. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_EN_READING_WAIKAN);
  1448. }elseif($msg['product_type']==3){
  1449. $classify=58;
  1450. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_EN_READING_REDIAN);
  1451. }
  1452. }else{
  1453. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_EN_READING);
  1454. }
  1455. //*****获取生成的学生***//
  1456. $generateStu = $productDownload->getGenerateStu('english_reading_student', 'week_id', 'week_pdf_path', 'is_week_pdf', $weekId, $studentsIds);
  1457. if(!$generateStu){
  1458. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  1459. }
  1460. $params['studentIds'] = $generateStu['studentIds'];
  1461. $pathArr = $generateStu['pathArr'];
  1462. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  1463. if (!$apiUrl) {
  1464. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  1465. exit();
  1466. }
  1467. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  1468. $intarr = array(
  1469. "schoolId" => $this->schoolId,
  1470. "clazzId" => $msg['class_id'],
  1471. "semester" => $code['refer_code'],
  1472. "grade" => $msg['grade'],
  1473. "students" => $studentsIds,
  1474. "examTime" => $msg['create_time'],
  1475. "classify" => $classify,
  1476. "subject" => 8
  1477. );
  1478. //************ Step-1 判断是否有订单 *************//
  1479. if (Yii::app()->params["limit_open"]) {
  1480. if (Yii::app()->params["limit_open"]) {
  1481. $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId);
  1482. }
  1483. }
  1484. $params['schoolId'] = $this->schoolId;
  1485. $params['type'] = 3;
  1486. $params['weekId'] = $weekId;
  1487. //**************** Step-2 判断是否已经存在下载任务 ********************//
  1488. if($classDownload) {
  1489. $packTask = $this->getExistTask($weekId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_EN_READING, count($params["studentIds"]));
  1490. if (isset($packTask->pack_status) && $packTask->pack_status == 0) {
  1491. echo json_encode(array("success" => 3, "message" => ""));
  1492. exit;
  1493. }
  1494. if (isset($packTask->pack_url) && $packTask->pack_url) {
  1495. $this->updateEnreadingDownloadStatus($params['studentIds'],$weekId);
  1496. echo json_encode(array("success" => 1, "downloadPath" => $packTask->pack_url));
  1497. exit;
  1498. }
  1499. }
  1500. //**************** Step-3 根据接口获取文件大小来判断走原有接口打包流程还是走脚本任务 ************//
  1501. $sizeRs = Curl::post($apiUrl . "/rest/download_file_size/index", array('path_arr' => $pathArr));
  1502. if (!($sizeRs = json_decode($sizeRs))) {
  1503. echo json_encode(array("success" => 0, "message" => "请求接口失败"));
  1504. exit;
  1505. }
  1506. if (isset($sizeRs->size)) {
  1507. //************ Step-3-1 大于限定值 发送任务到后台打包 ******//
  1508. if (Yii::app()->params["pack_product_file_limit"] < $sizeRs->size) {
  1509. $packProductModel = new BusinessPackProductTask();
  1510. $packProductModel->school_id = $this->schoolId;
  1511. $packProductModel->auth_username = $this->authUsername;
  1512. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_EN_READING;
  1513. $packProductModel->product_name = $msg['name'] . '外刊宝';
  1514. $packProductModel->subject_id = $this->subjectId;
  1515. $packProductModel->class_id = $msg['class_id'];
  1516. $packProductModel->class_name = $classinfo['class_name'];
  1517. $packProductModel->unique_key = $weekId;
  1518. $packProductModel->student_count = count($params['studentIds']);
  1519. $packProductModel->pack_json = json_encode($params);
  1520. $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index";
  1521. $packProductModel->create_time = time();
  1522. $packProductModel->save();
  1523. $this->updateEnreadingDownloadStatus($params['studentIds'],$weekId);
  1524. echo json_encode(array("success" => 3, "message" => ""));
  1525. exit;
  1526. } else {
  1527. $rs = Curl::post($apiUrl . "/rest/download_week_pdf/index", $params);
  1528. if (!($rs = json_decode($rs))) {
  1529. $rs = array(
  1530. "success" => 0,
  1531. "message" => "请求接口失败",
  1532. );
  1533. } else {
  1534. //更新下载时间
  1535. if ($rs->success == 1 || $rs->success == 2) {
  1536. $this->updateEnreadingDownloadStatus($params['studentIds'],$weekId);
  1537. }
  1538. }
  1539. echo json_encode($rs);
  1540. exit;
  1541. }
  1542. } else {
  1543. echo json_encode(array("success" => 0, "message" => $sizeRs->message));
  1544. exit;
  1545. }
  1546. }
  1547. /**
  1548. * 更新外刊下载状态
  1549. * @param $studentsIds
  1550. * @param $weekId
  1551. */
  1552. private function updateEnreadingDownloadStatus($studentsIds, $weekId)
  1553. {
  1554. $time = time();
  1555. $sql = "update english_reading_student set is_week_download = 1,week_download_time={$time} where week_id = '{$weekId}' and student_id in (" . implode(',', $studentsIds) . ") and week_download_time = 0";
  1556. $this->sConn->createCommand($sql)->execute();
  1557. }
  1558. /**
  1559. * 添加外刊美文个性化学习宝下载任务
  1560. */
  1561. public function actionAddEnReadingTask()
  1562. {
  1563. $weekId = (string)Req::get("weekId");
  1564. $studentsIds = Req::get("studentsIds");
  1565. if (!$weekId) {
  1566. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  1567. exit();
  1568. }
  1569. //*****获取生成的学生***//
  1570. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_EN_READING);
  1571. $generateStu = $productDownload->getGenerateStu('english_reading_student', 'week_id', 'week_pdf_path', 'is_week_pdf', $weekId, $studentsIds);
  1572. if(!$generateStu){
  1573. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  1574. }
  1575. $params['studentIds'] = $generateStu['studentIds'];
  1576. $sql = "select class_id,grade,create_time,semester_id,name from english_reading where week_id = '{$weekId}'";
  1577. $msg = $this->sConn->createCommand($sql)->queryRow();
  1578. $Sem = new SSemester();
  1579. $code = $Sem->conn->createQuery()
  1580. ->from('semester')
  1581. ->where("semester_id = '" . $msg['semester_id'] . "'")
  1582. ->limit(1)
  1583. ->query()
  1584. ->read();
  1585. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  1586. $intarr = array(
  1587. "schoolId" => $this->schoolId,
  1588. "clazzId" => $msg['class_id'],
  1589. "semester" => $code['refer_code'],
  1590. "grade" => $msg['grade'],
  1591. "students" => $studentsIds,
  1592. "examTime" => $msg['create_time'],
  1593. "classify" => 6,
  1594. "subject" => 8
  1595. );
  1596. //************ Step-1 判断是否有订单 *************//
  1597. //$params = array();
  1598. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  1599. if (!$apiUrl) {
  1600. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  1601. exit();
  1602. }
  1603. if (Yii::app()->params["limit_open"]) {
  1604. if (Yii::app()->params["limit_open"]) {
  1605. $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId);
  1606. }
  1607. }
  1608. //*******产品接口参数******//
  1609. $params['weekId'] = $weekId;
  1610. $params['schoolId'] = $this->schoolId;
  1611. $params['type'] = 3;
  1612. $packProductModel = new BusinessPackProductTask();
  1613. $packProductModel->school_id = $this->schoolId;
  1614. $packProductModel->auth_username = $this->authUsername;
  1615. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_EN_READING;
  1616. $packProductModel->product_name = $msg['name'] . '外刊宝';
  1617. $packProductModel->subject_id = $this->subjectId;
  1618. $packProductModel->class_id = $msg['class_id'];
  1619. $packProductModel->class_name = $classinfo['class_name'];
  1620. $packProductModel->unique_key = $weekId;
  1621. $packProductModel->student_count = count($params['studentIds']);
  1622. $packProductModel->pack_json = json_encode($params);
  1623. $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index";
  1624. $packProductModel->create_time = time();
  1625. $packProductModel->save();
  1626. $this->updateEnreadingDownloadStatus($params['studentIds'],$weekId);
  1627. echo json_encode(array("success" => 3, "message" => ""));
  1628. exit;
  1629. }
  1630. /**
  1631. * 获取已存在的下载任务
  1632. * @param $unique_id
  1633. * @param $class_id
  1634. * @param $type
  1635. * @param $studentCount
  1636. * @return bool|mixed
  1637. */
  1638. private function getExistTask($unique_id, $class_id, $type, $studentCount)
  1639. {
  1640. $schoolId = $this->schoolId;
  1641. $subjectId = $this->subjectId;
  1642. $effectTime = time() - 86400;
  1643. $sql = <<<SQL
  1644. select pack_status,pack_url from pack_product_task where unique_key='{$unique_id}' and school_id={$schoolId} and subject_id={$subjectId}
  1645. and product_type={$type} and class_id='{$class_id}' and student_count={$studentCount} and pack_status<>2 and create_time>{$effectTime} order by create_time desc limit 1;
  1646. SQL;
  1647. $rs = BusinessPackProductTask::model()->findBySql($sql);
  1648. return $rs;
  1649. }
  1650. /**
  1651. * 获取学生是否有订单
  1652. * @param $intarr
  1653. * @param $stuids
  1654. */
  1655. protected function getStuOrder($intarr, &$stuids)
  1656. {
  1657. $basic = imsBasicAuth($this->schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]);
  1658. foreach (array(1, 2, 3) as $type) {
  1659. $intarr['classify'] = $type;
  1660. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr), $basic));
  1661. if (!$rs) {
  1662. Yii::app()->jump->error("接口错误");
  1663. }
  1664. if ($rs->errCode != "00") {
  1665. Yii::app()->jump->error($rs->errMsg);
  1666. }
  1667. $stuids = array_unique(array_merge($stuids, $rs->data));
  1668. }
  1669. }
  1670. //批量下载假期报告
  1671. public function actionBatchHoliday(){
  1672. $json_params = file_get_contents('php://input');
  1673. $params_arr = json_decode($json_params, true);
  1674. $notFound = 0;
  1675. foreach ($params_arr as $param) {
  1676. $reportId = isset($param['reportId']) ? $param['reportId'] : null;
  1677. if (!$reportId) {
  1678. echo json_encode(array("status" => 0, "message" => "缺少参数"));exit();
  1679. }
  1680. $params = array();
  1681. //获取组ID
  1682. $sql = "select school_group_id,semester_id from holiday_report_setting where report_id = '{$reportId}'";
  1683. $report_settint_data = $this->sConn->createCommand($sql)->queryRow();
  1684. if (!$report_settint_data) {
  1685. echo json_encode(array("success" => 0, "message" => "设置信息错误"));
  1686. exit();
  1687. } else {
  1688. $school_group_id = $report_settint_data['school_group_id'];
  1689. }
  1690. if (isset($school_group_id) && $school_group_id) {
  1691. $apiUrl = isset(Yii::app()->params["improve_url"][$school_group_id]) ? Yii::app()->params["improve_url"][$school_group_id] : null;
  1692. } else {
  1693. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  1694. }
  1695. //*****获取生成的学生***//
  1696. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_HOLIDAY_REPORT);
  1697. $generateStu = $productDownload->getGenerateStu('holiday_report_student', 'report_id', 'report_pdf_path', 'is_report_pdf', $reportId, array());
  1698. if(!$generateStu){
  1699. $notFound++;
  1700. continue;
  1701. }
  1702. $params['studentIds'] = $generateStu['studentIds'];
  1703. if (!$apiUrl) {
  1704. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  1705. exit();
  1706. }
  1707. $sql = "select class_id,grade,create_time,semester_id from holiday_report_setting where report_id = '{$reportId}'";
  1708. $msg = $this->sConn->createCommand($sql)->queryRow();
  1709. $Sem = new SSemester();
  1710. $code = $Sem->conn->createQuery()
  1711. ->from('semester')
  1712. ->where("semester_id = '" . $msg['semester_id'] . "'")
  1713. ->limit(1)
  1714. ->query()
  1715. ->read();
  1716. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  1717. $params['schoolId'] = $this->schoolId;
  1718. $params['type'] = 4;
  1719. $params['reportId'] = $reportId;
  1720. //**************** Step-2 判断是否已经存在下载任务 ********************//
  1721. $packTask = $this->getExistTask($reportId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_HOLIDAY_REPORT, count($params["studentIds"]));
  1722. if ($packTask) {
  1723. continue;
  1724. }
  1725. $smeName = isset($code['name'] ) ? $code['name'] : '';
  1726. //************ 批量直接发送任务到后台打包 ******//
  1727. $packProductModel = new BusinessPackProductTask();
  1728. $packProductModel->school_id = $this->schoolId;
  1729. $packProductModel->auth_username = $this->authUsername;
  1730. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_HOLIDAY_REPORT;
  1731. $packProductModel->product_name = $classinfo['class_name'].$smeName . '假期总结报告';
  1732. $packProductModel->subject_id = $this->subjectId;
  1733. $packProductModel->class_id = $msg['class_id'];
  1734. $packProductModel->class_name = $classinfo['class_name'];
  1735. $packProductModel->unique_key = $reportId;
  1736. $packProductModel->student_count = count($params['studentIds']);
  1737. $packProductModel->pack_json = json_encode($params);
  1738. $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index";
  1739. $packProductModel->create_time = time();
  1740. $packProductModel->save();
  1741. $this->updateHrpDownloadStatus($params['studentIds'],$reportId);
  1742. }
  1743. if($notFound == count($params_arr)){
  1744. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  1745. }
  1746. echo json_encode(array("success" => 1, "message" => "success"));
  1747. }
  1748. //批量下载错题本 提分方案 个性化学习宝
  1749. public function actionBatchIsp()
  1750. {
  1751. $json_params = file_get_contents('php://input');
  1752. $params_arr = json_decode($json_params, true);
  1753. $notFound = 0;
  1754. foreach ($params_arr as $param) {
  1755. $examId = isset($param['examId']) ? $param['examId'] : null;
  1756. $classId = isset($param['classId']) ? $param['classId'] : null;
  1757. $type = isset($param['type']) ? $param['type'] : null;
  1758. $printType = isset($param['printType']) ? $param['printType'] : null;
  1759. $absentFilter = isset($param['absent_filter']) ? $param['absent_filter'] : false;
  1760. if (!$examId || !$classId || !$type) {
  1761. echo json_encode(array("success" => 0, "message" => "缺少参数"));exit();
  1762. }
  1763. if (!in_array($type, array(1, 2, 3))) {
  1764. echo json_encode(array("success" => 0, "message" => "参数错误[1]"));exit();
  1765. }
  1766. $groupInfo = Exam::model()->getGroupInfo($examId);
  1767. if (empty($groupInfo)) exit(json_encode(array("success" => 0, "message" => "考试信息错误")));
  1768. $typeRel = array('1' => 'wb_group_id', '2' => 'isp_group_id', '3' => 'wbisp_group_id');
  1769. $groupId = $groupInfo[$typeRel[$type]];
  1770. if (!empty($groupId)) {
  1771. $apiUrl = isset(Yii::app()->params["improve_url"][$groupId]) ? Yii::app()->params["improve_url"][$groupId] : null;
  1772. } else {
  1773. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  1774. }
  1775. if (!$apiUrl) {
  1776. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  1777. exit();
  1778. }
  1779. $params = array(
  1780. "schoolId" => $this->schoolId,
  1781. "examId" => $examId,
  1782. "classId" => $classId,
  1783. "type" => $type,
  1784. "studentIds" => array(),
  1785. );
  1786. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $classId));
  1787. //判断学科
  1788. $examInfo = Exam::model()->findByPk($examId);
  1789. if ($type == 1) {
  1790. $productName = $examInfo->name . '"错题本"';
  1791. $pdfPathColumn = 'wrongbook_pdf_path';
  1792. $isGenerateColumn = 'is_wrongbook_pdf';
  1793. $isDownloadColumn = 'is_wrongbook_download';
  1794. $downloadTimeCoulmn = 'download_wrongbook_time';
  1795. } elseif ($type == 2) {
  1796. $productName = $examInfo->name . '"个性化学习方案"';
  1797. $pdfPathColumn = 'isp_pdf_path';
  1798. $isGenerateColumn = 'is_isp_pdf';
  1799. $isDownloadColumn = 'is_two_isp_download';
  1800. $downloadTimeCoulmn = 'download_two_isp_time';
  1801. } else {
  1802. $productName = $examInfo->name . '"个性化学习宝"';
  1803. $pdfPathColumn = 'wbisp_pdf_path';
  1804. $isGenerateColumn = 'is_wbisp_pdf';
  1805. $isDownloadColumn = 'is_three_isp_download';
  1806. $downloadTimeCoulmn = 'download_two_isp_time';
  1807. }
  1808. $productDownload = new ProductDownload($type);
  1809. //*****获取生成的学生***//
  1810. $generateStu = $productDownload->getGenerateStu('student_paper_relation', 'exam_id', $pdfPathColumn, $isGenerateColumn, $examId, array(), $absentFilter);
  1811. if(!$generateStu){
  1812. $notFound++;
  1813. continue;
  1814. }
  1815. $params['studentIds'] = $generateStu['studentIds'];
  1816. if ($printType == 'third_isp') {
  1817. $params["subjectId"] = 8;
  1818. $params["type"] = 3;
  1819. }
  1820. ProductProcessTime::model()->updateDownloadTime($params["studentIds"],$type,$examId);
  1821. //**************** Step-2 判断是否已经存在下载任务 ********************//
  1822. $packTask = $this->getExistTask($examId, $classId, $type, count($params['studentIds']));
  1823. if ($packTask) {
  1824. continue;
  1825. }
  1826. //************Step-3 批量直接发送任务到后台打包 ******//
  1827. $packProductModel = new BusinessPackProductTask();
  1828. $packProductModel->school_id = $this->schoolId;
  1829. $packProductModel->auth_username = $this->authUsername;
  1830. $packProductModel->product_type = $type;
  1831. $packProductModel->product_name = $productName;
  1832. $packProductModel->subject_id = $this->subjectId;
  1833. $packProductModel->class_id = $classId;
  1834. $packProductModel->class_name = $classinfo['class_name'];
  1835. $packProductModel->unique_key = $examId;
  1836. $packProductModel->student_count = count($params["studentIds"]);
  1837. $packProductModel->pack_json = json_encode($params);
  1838. $packProductModel->pack_api_url = $apiUrl . "/rest/download_pdf/index";
  1839. $packProductModel->create_time = time();
  1840. $packProductModel->save();
  1841. $this->updateIspDownloadStatus($params["studentIds"],$classId,$examId,$isDownloadColumn,$downloadTimeCoulmn);
  1842. }
  1843. if($notFound == count($params_arr)){
  1844. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  1845. }
  1846. echo json_encode(array("success" => 1, "message" => "success"));
  1847. }
  1848. //批量下载阶段复习个性化学习宝
  1849. public function actionBatchSp()
  1850. {
  1851. $json_params = file_get_contents('php://input');
  1852. $params_arr = json_decode($json_params, true);
  1853. $notFound = 0;
  1854. foreach ($params_arr as $param) {
  1855. $classId = isset($param['classId'])?$param['classId']:null;
  1856. $type = isset($param['type'])?$param['type']:null;
  1857. if (!$classId || !$type) {
  1858. echo json_encode(array("success" => 0, "message" => "缺少参数"));exit();
  1859. }
  1860. if (!in_array($type, array(1, 2, 3))) {
  1861. echo json_encode(array("success" => 0, "message" => "参数错误[1]"));exit();
  1862. }
  1863. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  1864. if (!$apiUrl) {
  1865. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  1866. exit();
  1867. }
  1868. $params = array(
  1869. "schoolId" => $this->schoolId,
  1870. "classId" => $classId,
  1871. "type" => $type,
  1872. );
  1873. $studentsIds = array();
  1874. $student_class_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status', array(':class_id' => $classId, ':status' => 0));
  1875. if ($student_class_data) {
  1876. foreach ($student_class_data as $v) {
  1877. $studentsIds[] = $v->student_id;
  1878. }
  1879. } else {
  1880. echo json_encode(array("success" => 0, "message" => "班级暂无学生"));
  1881. exit;
  1882. }
  1883. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $classId));
  1884. $params['studentIds'] = $studentsIds;
  1885. if(in_array($this->subjectId,$this->mathSubjectId)){
  1886. $subjectId=3;
  1887. }else{
  1888. $subjectId=$this->subjectId;
  1889. }
  1890. $_student_product_data=SStudentProductModel::model()->getStudentCreate($studentsIds,$subjectId,$type,$this->semesterId);
  1891. if (!$_student_product_data) {
  1892. //echo json_encode(array("success" => 0, "message" => $classinfo['class_name']."学生尚未生成PDF"));
  1893. $notFound++;
  1894. continue;
  1895. }
  1896. $planId=SStudentProductModel::model()->getPlanId($classId,$subjectId,$type);
  1897. $params['planId']=$planId;
  1898. //************ 判断是否已经存在下载任务 **********//
  1899. $packTask = $this->getExistTask($this->semesterId . '_' . $type, $classId, ProductDownload::PRODUCT_TYPE_STAGE_REVIEW, count($_student_product_data));
  1900. if ($packTask) {
  1901. continue;
  1902. }
  1903. $semester = new SSemester();
  1904. $nowsem = $semester->getCurrentSemester();
  1905. $semesterName = isset($nowsem->semester_name) ? $nowsem->semester_name : '';
  1906. if ($type == 1) {
  1907. $productName = $semesterName . '"期中阶段复习个性化学习宝"';
  1908. } elseif ($type == 2) {
  1909. $productName = $semesterName . '"期末阶段复习个性化学习宝"';
  1910. } else {
  1911. $productName = $semesterName . '"总复习个性化学习宝"';
  1912. }
  1913. $packProductModel = new BusinessPackProductTask();
  1914. $packProductModel->school_id = $this->schoolId;
  1915. $packProductModel->auth_username = $this->authUsername;
  1916. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_STAGE_REVIEW;
  1917. $packProductModel->product_name = $productName;
  1918. $packProductModel->subject_id = $this->subjectId;
  1919. $packProductModel->class_id = $classId;
  1920. $packProductModel->class_name = $classinfo['class_name'];
  1921. $packProductModel->unique_key = $this->semesterId . '_' . $type;
  1922. $packProductModel->student_count = count($_student_product_data);
  1923. $packProductModel->pack_json = json_encode($params);
  1924. $packProductModel->pack_api_url = $apiUrl . "/rest/download_sp/index";
  1925. $packProductModel->create_time = time();
  1926. $packProductModel->save();
  1927. $this->updateSpDownloadStatus($params['studentIds'], $type,$planId);
  1928. }
  1929. if($notFound == count($params_arr)){
  1930. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  1931. }
  1932. echo json_encode(array("success" => 1, "message" => "success"));
  1933. }
  1934. //批量下载二轮复习提分手册
  1935. public function actionBatchMathReview(){
  1936. $json_params = file_get_contents('php://input');
  1937. $params_arr = json_decode($json_params, true);
  1938. $notFound = 0;
  1939. foreach ($params_arr as $param) {
  1940. $mrId = isset($param['mrId'])?$param['mrId']:null;
  1941. $params = array();
  1942. if (!$mrId) {
  1943. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  1944. exit();
  1945. }
  1946. //*****获取生成的学生***//
  1947. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_SECOND_RUN);
  1948. $generateStu = $productDownload->getGenerateStu('math_review_student', 'mr_id', 'review_pdf_path', 'is_review_pdf', $mrId, array());
  1949. if(!$generateStu){
  1950. $notFound++;
  1951. continue;
  1952. }
  1953. $params['studentIds'] = $generateStu['studentIds'];
  1954. $sql = "select class_id,grade,create_time,semester_id,school_group_id,`name` from math_review_setting where mr_id = '{$mrId}'";
  1955. $msg = $this->sConn->createCommand($sql)->queryRow();
  1956. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  1957. if (isset($msg['school_group_id']) && $msg['school_group_id']) {
  1958. $apiUrl = isset(Yii::app()->params["improve_url"][$msg['school_group_id']]) ? Yii::app()->params["improve_url"][$msg['school_group_id']] : null;
  1959. } else {
  1960. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  1961. }
  1962. if (!$apiUrl) {
  1963. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  1964. exit();
  1965. }
  1966. $packTask = $this->getExistTask($mrId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_SECOND_RUN, count($params["studentIds"]));
  1967. if ($packTask) {
  1968. continue;
  1969. }
  1970. $params['mrId'] = $mrId;
  1971. $params['schoolId'] = $this->schoolId;
  1972. $params['type'] = 1;
  1973. $packProductModel = new BusinessPackProductTask();
  1974. $packProductModel->school_id = $this->schoolId;
  1975. $packProductModel->auth_username = $this->authUsername;
  1976. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_SECOND_RUN;
  1977. $packProductModel->product_name = $msg['name'] . '二轮复习学习手册';
  1978. $packProductModel->subject_id = $this->subjectId;
  1979. $packProductModel->class_id = $msg['class_id'];
  1980. $packProductModel->class_name = $classinfo['class_name'];
  1981. $packProductModel->unique_key = $mrId;
  1982. $packProductModel->student_count = count($params['studentIds']);
  1983. $packProductModel->pack_json = json_encode($params);
  1984. $packProductModel->pack_api_url = $apiUrl . "/rest/download_math_pdf/index";
  1985. $packProductModel->create_time = time();
  1986. $packProductModel->save();
  1987. $this->updateSecondRunDownloadStatus($params['studentIds'], $mrId);
  1988. }
  1989. if($notFound == count($params_arr)){
  1990. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  1991. }
  1992. echo json_encode(array("success" => 1, "message" => "success"));
  1993. }
  1994. //批量下载好题本
  1995. public function actionBatchHtb()
  1996. {
  1997. $json_params = file_get_contents('php://input');
  1998. $params_arr = json_decode($json_params, true);
  1999. $notFound = 0;
  2000. foreach ($params_arr as $param) {
  2001. $htbId = isset($param['htbId']) ? $param['htbId'] : null;
  2002. $params = array();
  2003. if (!$htbId) {
  2004. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  2005. exit();
  2006. }
  2007. //*****获取生成的学生***//
  2008. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_HTB);
  2009. $generateStu = $productDownload->getGenerateStu('math_htb_student', 'htb_id', 'htb_pdf_path', 'is_htb_pdf', $htbId, array());
  2010. if(!$generateStu){
  2011. $notFound++;
  2012. continue;
  2013. }
  2014. $params['studentIds'] = $generateStu['studentIds'];
  2015. $sql = "select class_id,grade,create_time,semester_id,school_group_id from math_htb_setting where htb_id = '{$htbId}'";
  2016. $msg = $this->sConn->createCommand($sql)->queryRow();
  2017. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  2018. if (isset($msg['school_group_id']) && $msg['school_group_id']) {
  2019. $apiUrl = isset(Yii::app()->params["improve_url"][$msg['school_group_id']]) ? Yii::app()->params["improve_url"][$msg['school_group_id']] : null;
  2020. } else {
  2021. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  2022. }
  2023. if (!$apiUrl) {
  2024. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  2025. exit();
  2026. }
  2027. $packTask = $this->getExistTask($htbId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_HTB, count($params["studentIds"]));
  2028. if ($packTask) {
  2029. continue;
  2030. }
  2031. $params['schoolId'] = $this->schoolId;
  2032. $params['type'] = 5;
  2033. $params['htbId'] = $htbId;
  2034. $packProductModel = new BusinessPackProductTask();
  2035. $packProductModel->school_id = $this->schoolId;
  2036. $packProductModel->auth_username = $this->authUsername;
  2037. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_HTB;
  2038. $packProductModel->product_name = $msg['name']."好题本";
  2039. $packProductModel->subject_id = $this->subjectId;
  2040. $packProductModel->class_id = $msg['class_id'];
  2041. $packProductModel->class_name = $classinfo['class_name'];
  2042. $packProductModel->unique_key = $htbId;
  2043. $packProductModel->student_count = count($params['studentIds']);
  2044. $packProductModel->pack_json = json_encode($params);
  2045. $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index";
  2046. $packProductModel->create_time = time();
  2047. $packProductModel->save();
  2048. $this->updateHtbDownloadStatus($params['studentIds'],$htbId);
  2049. }
  2050. if($notFound == count($params_arr)){
  2051. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  2052. }
  2053. echo json_encode(array("success" => 1, "message" => "success"));
  2054. }
  2055. //批量晨读词汇
  2056. public function actionBatchEnMrv()
  2057. {
  2058. $json_params = file_get_contents('php://input');
  2059. $params_arr = json_decode($json_params, true);
  2060. $notFound = 0;
  2061. foreach ($params_arr as $param) {
  2062. $weekId = isset($param['weekId']) ? $param['weekId'] : null;
  2063. $params = array();
  2064. if (!$weekId) {
  2065. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  2066. exit();
  2067. }
  2068. //*****获取生成的学生***//
  2069. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_EN_MRV);
  2070. $generateStu = $productDownload->getGenerateStu('english_week_student', 'week_id', 'week_pdf_path', 'is_week_pdf', $weekId, array());
  2071. if(!$generateStu){
  2072. $notFound++;
  2073. continue;
  2074. }
  2075. $params['studentIds'] = $generateStu['studentIds'];
  2076. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  2077. if (!$apiUrl) {
  2078. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  2079. exit();
  2080. }
  2081. $sql = "select class_id,grade,create_time,semester_id,`name` from english_week where week_id = '{$weekId}'";
  2082. $msg = $this->sConn->createCommand($sql)->queryRow();
  2083. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  2084. //************ 判断是任务是否存在 *************//
  2085. $packTask = $this->getExistTask($weekId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_EN_MRV, count($params["studentIds"]));
  2086. if ($packTask) {
  2087. continue;
  2088. }
  2089. $params['schoolId'] = $this->schoolId;
  2090. $params['type'] = 1;
  2091. $params['weekId'] = $weekId;
  2092. $packProductModel = new BusinessPackProductTask();
  2093. $packProductModel->school_id = $this->schoolId;
  2094. $packProductModel->auth_username = $this->authUsername;
  2095. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_EN_MRV;
  2096. $packProductModel->product_name = $msg['name'] . '晨读词汇';
  2097. $packProductModel->subject_id = $this->subjectId;
  2098. $packProductModel->class_id = $msg['class_id'];
  2099. $packProductModel->class_name = $classinfo['class_name'];
  2100. $packProductModel->unique_key = $weekId;
  2101. $packProductModel->student_count = count($params['studentIds']);
  2102. $packProductModel->pack_json = json_encode($params);
  2103. $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index";
  2104. $packProductModel->create_time = time();
  2105. $packProductModel->save();
  2106. $this->updateEnMrvDownloadStatus($params['studentIds'], $weekId);
  2107. }
  2108. if($notFound == count($params_arr)){
  2109. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  2110. }
  2111. echo json_encode(array("success" => 1, "message" => "success"));
  2112. }
  2113. /**
  2114. * 批量外刊美文个性化学习宝
  2115. */
  2116. public function actionBatchEnReading()
  2117. {
  2118. $json_params = file_get_contents('php://input');
  2119. $params_arr = json_decode($json_params, true);
  2120. $notFound = 0;
  2121. foreach ($params_arr as $param) {
  2122. $weekId = isset($param['weekId']) ? (string)$param['weekId'] : null;
  2123. $params = array();
  2124. if (!$weekId) {
  2125. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  2126. exit();
  2127. }
  2128. //*****获取生成的学生***//
  2129. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_EN_READING);
  2130. $generateStu = $productDownload->getGenerateStu('english_reading_student', 'week_id', 'week_pdf_path', 'is_week_pdf', $weekId, array());
  2131. if(!$generateStu){
  2132. $notFound++;
  2133. continue;
  2134. }
  2135. $params['studentIds'] = $generateStu['studentIds'];
  2136. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  2137. if (!$apiUrl) {
  2138. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  2139. exit();
  2140. }
  2141. $sql = "select class_id,grade,create_time,semester_id,name from english_reading where week_id = '{$weekId}'";
  2142. $msg = $this->sConn->createCommand($sql)->queryRow();
  2143. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  2144. $params['schoolId'] = $this->schoolId;
  2145. $params['type'] = 3;
  2146. $params['weekId'] = $weekId;
  2147. //**************** Step-2 判断是否已经存在下载任务 ********************//
  2148. $packTask = $this->getExistTask($weekId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_EN_READING, count($params["studentIds"]));
  2149. if($packTask){
  2150. continue;
  2151. }
  2152. $packProductModel = new BusinessPackProductTask();
  2153. $packProductModel->school_id = $this->schoolId;
  2154. $packProductModel->auth_username = $this->authUsername;
  2155. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_EN_READING;
  2156. $packProductModel->product_name = $msg['name'] . '外刊宝';
  2157. $packProductModel->subject_id = $this->subjectId;
  2158. $packProductModel->class_id = $msg['class_id'];
  2159. $packProductModel->class_name = $classinfo['class_name'];
  2160. $packProductModel->unique_key = $weekId;
  2161. $packProductModel->student_count = count($params['studentIds']);
  2162. $packProductModel->pack_json = json_encode($params);
  2163. $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index";
  2164. $packProductModel->create_time = time();
  2165. $packProductModel->save();
  2166. $this->updateEnreadingDownloadStatus($params['studentIds'], $weekId);
  2167. }
  2168. if($notFound == count($params_arr)){
  2169. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  2170. }
  2171. echo json_encode(array("success" => 1, "message" => "success"));
  2172. }
  2173. /**
  2174. * 下载词汇宝
  2175. */
  2176. public function actionGetMagicWordFile()
  2177. {
  2178. $mwId = (string)Req::get("mw_id");
  2179. $studentsIds = Req::get("studentsIds");
  2180. $classDownload = $studentsIds ? false : true;
  2181. $params = array();
  2182. if (!$mwId) {
  2183. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  2184. exit();
  2185. }
  2186. $sql = "select class_id,grade,create_time,semester_id,name from english_magic_word where mw_id = '{$mwId}'";
  2187. $msg = $this->sConn->createCommand($sql)->queryRow();
  2188. //*****获取生成的学生***//
  2189. $productDownload = new ProductDownload($msg['grade']==3?ProductDownload::PRODUCT_TYPE_EN_MAGIC_WORD:ProductDownload::PRODUCT_TYPE_EN_INTEREST_WORD);
  2190. $generateStu = $productDownload->getGenerateStu('english_magic_word_student', 'mw_id', 'week_pdf_path', 'is_week_pdf', $mwId, $studentsIds);
  2191. if(!$generateStu){
  2192. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  2193. }
  2194. $params['studentIds'] = $generateStu['studentIds'];
  2195. $pathArr = $generateStu['pathArr'];
  2196. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  2197. if (!$apiUrl) {
  2198. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  2199. exit();
  2200. }
  2201. $Sem = new SSemester();
  2202. $code = $Sem->conn->createQuery()
  2203. ->from('semester')
  2204. ->where("semester_id = '" . $msg['semester_id'] . "'")
  2205. ->limit(1)
  2206. ->query()
  2207. ->read();
  2208. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  2209. $intarr = array(
  2210. "schoolId" => $this->schoolId,
  2211. "clazzId" => $msg['class_id'],
  2212. "semester" => $code['refer_code'],
  2213. "grade" => $msg['grade'],
  2214. "students" => $studentsIds,
  2215. "examTime" => $msg['create_time'],
  2216. "classify" => 11,
  2217. "subject" => 8
  2218. );
  2219. //************ Step-1 判断是否有订单 *************//
  2220. if (Yii::app()->params["limit_open"]) {
  2221. if (Yii::app()->params["limit_open"]) {
  2222. $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId);
  2223. }
  2224. }
  2225. $params['schoolId'] = $this->schoolId;
  2226. $params['type'] = 6;
  2227. $params['mwId'] = $mwId;
  2228. //**************** Step-2 判断是否已经存在下载任务 ********************//
  2229. if($classDownload) {
  2230. $packTask = $this->getExistTask($mwId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_EN_MAGIC_WORD, count($params["studentIds"]));
  2231. if (isset($packTask->pack_status) && $packTask->pack_status == 0) {
  2232. echo json_encode(array("success" => 3, "message" => ""));
  2233. exit;
  2234. }
  2235. if (isset($packTask->pack_url) && $packTask->pack_url) {
  2236. $this->updateMagicWordDownloadStatus($params['studentIds'],$mwId);
  2237. echo json_encode(array("success" => 1, "downloadPath" => $packTask->pack_url));
  2238. exit;
  2239. }
  2240. }
  2241. //**************** Step-3 根据接口获取文件大小来判断走原有接口打包流程还是走脚本任务 ************//
  2242. $sizeRs = Curl::post($apiUrl . "/rest/download_file_size/index", array('path_arr' => $pathArr));
  2243. if (!($sizeRs = json_decode($sizeRs))) {
  2244. echo json_encode(array("success" => 0, "message" => "请求接口失败"));
  2245. exit;
  2246. }
  2247. if (isset($sizeRs->size)) {
  2248. //************ Step-3-1 大于限定值 发送任务到后台打包 ******//
  2249. if (Yii::app()->params["pack_product_file_limit"] < $sizeRs->size) {
  2250. $packProductModel = new BusinessPackProductTask();
  2251. $packProductModel->school_id = $this->schoolId;
  2252. $packProductModel->auth_username = $this->authUsername;
  2253. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_EN_READING;
  2254. $packProductModel->product_name = $msg['name'] . '词汇宝';
  2255. $packProductModel->subject_id = $this->subjectId;
  2256. $packProductModel->class_id = $msg['class_id'];
  2257. $packProductModel->class_name = $classinfo['class_name'];
  2258. $packProductModel->unique_key = $mwId;
  2259. $packProductModel->student_count = count($params['studentIds']);
  2260. $packProductModel->pack_json = json_encode($params);
  2261. $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index";
  2262. $packProductModel->create_time = time();
  2263. $packProductModel->save();
  2264. $this->updateMagicWordDownloadStatus($params['studentIds'],$mwId);
  2265. echo json_encode(array("success" => 3, "message" => ""));
  2266. exit;
  2267. } else {
  2268. $rs = Curl::post($apiUrl . "/rest/download_week_pdf/index", $params);
  2269. if (!($rs = json_decode($rs))) {
  2270. $rs = array(
  2271. "success" => 0,
  2272. "message" => "请求接口失败",
  2273. );
  2274. } else {
  2275. //更新下载时间
  2276. if ($rs->success == 1 || $rs->success == 2) {
  2277. $this->updateMagicWordDownloadStatus($params['studentIds'],$mwId);
  2278. }
  2279. }
  2280. echo json_encode($rs);
  2281. exit;
  2282. }
  2283. } else {
  2284. echo json_encode(array("success" => 0, "message" => $sizeRs->message));
  2285. exit;
  2286. }
  2287. }
  2288. /**
  2289. * 更新词汇宝下载状态
  2290. * @param $studentsIds
  2291. * @param $weekId
  2292. */
  2293. private function updateMagicWordDownloadStatus($studentsIds, $weekId)
  2294. {
  2295. $time = time();
  2296. $sql = "update english_magic_word_student set is_week_download = 1,week_download_time={$time} where mw_id = '{$weekId}' and student_id in (" . implode(',', $studentsIds) . ") and week_download_time = 0";
  2297. $this->sConn->createCommand($sql)->execute();
  2298. }
  2299. /**
  2300. * 更新词汇宝批改后检测卡下载状态
  2301. * @param $studentsIds
  2302. * @param $weekId
  2303. */
  2304. private function updateMagicWordAfterDownloadStatus($studentsIds, $weekId)
  2305. {
  2306. $time = time();
  2307. $sql = "update english_magic_word_student set is_card_download = 1,card_download_time={$time} where mw_id = '{$weekId}' and student_id in (" . implode(',', $studentsIds) . ") and card_download_time = 0";
  2308. $this->sConn->createCommand($sql)->execute();
  2309. }
  2310. /**
  2311. * 添加词汇宝下载任务
  2312. */
  2313. public function actionAddMagicWordTask()
  2314. {
  2315. $weekId = (string)Req::get("mw_id");
  2316. $studentsIds = Req::get("studentsIds");
  2317. if (!$weekId) {
  2318. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  2319. exit();
  2320. }
  2321. $sql = "select class_id,grade,create_time,semester_id,name from english_magic_word where mw_id = '{$weekId}'";
  2322. $msg = $this->sConn->createCommand($sql)->queryRow();
  2323. //*****获取生成的学生***//
  2324. $productDownload = new ProductDownload($msg['grade']==3?ProductDownload::PRODUCT_TYPE_EN_MAGIC_WORD:ProductDownload::PRODUCT_TYPE_EN_INTEREST_WORD);
  2325. $generateStu = $productDownload->getGenerateStu('english_magic_word_student', 'mw_id', 'week_pdf_path', 'is_week_pdf', $weekId, $studentsIds);
  2326. if(!$generateStu){
  2327. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  2328. }
  2329. $params['studentIds'] = $generateStu['studentIds'];
  2330. $Sem = new SSemester();
  2331. $code = $Sem->conn->createQuery()
  2332. ->from('semester')
  2333. ->where("semester_id = '" . $msg['semester_id'] . "'")
  2334. ->limit(1)
  2335. ->query()
  2336. ->read();
  2337. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  2338. $intarr = array(
  2339. "schoolId" => $this->schoolId,
  2340. "clazzId" => $msg['class_id'],
  2341. "semester" => $code['refer_code'],
  2342. "grade" => $msg['grade'],
  2343. "students" => $studentsIds,
  2344. "examTime" => $msg['create_time'],
  2345. "classify" => 11,
  2346. "subject" => 8
  2347. );
  2348. //************ Step-1 判断是否有订单 *************//
  2349. $params = array();
  2350. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  2351. if (!$apiUrl) {
  2352. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  2353. exit();
  2354. }
  2355. if (Yii::app()->params["limit_open"]) {
  2356. if (Yii::app()->params["limit_open"]) {
  2357. $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId);
  2358. }
  2359. }
  2360. //*******产品接口参数******//
  2361. $params['mwId'] = $weekId;
  2362. $params['schoolId'] = $this->schoolId;
  2363. $params['type'] = 6;
  2364. $packProductModel = new BusinessPackProductTask();
  2365. $packProductModel->school_id = $this->schoolId;
  2366. $packProductModel->auth_username = $this->authUsername;
  2367. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_EN_MAGIC_WORD;
  2368. $packProductModel->product_name = $msg['name'] . '词汇宝';
  2369. $packProductModel->subject_id = $this->subjectId;
  2370. $packProductModel->class_id = $msg['class_id'];
  2371. $packProductModel->class_name = $classinfo['class_name'];
  2372. $packProductModel->unique_key = $weekId;
  2373. $packProductModel->student_count = count($params['studentIds']);
  2374. $packProductModel->pack_json = json_encode($params);
  2375. $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index";
  2376. $packProductModel->create_time = time();
  2377. $packProductModel->save();
  2378. $this->updateMagicWordDownloadStatus($params['studentIds'],$weekId);
  2379. echo json_encode(array("success" => 3, "message" => ""));
  2380. exit;
  2381. }
  2382. /**
  2383. * 批量词汇宝下载
  2384. */
  2385. public function actionBatchMagicWord()
  2386. {
  2387. $json_params = file_get_contents('php://input');
  2388. $params_arr = json_decode($json_params, true);
  2389. $notFound = 0;
  2390. foreach ($params_arr as $param) {
  2391. $weekId = isset($param['mw_id']) ? (string)$param['mw_id'] : null;
  2392. $params = array();
  2393. if (!$weekId) {
  2394. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  2395. exit();
  2396. }
  2397. //*****获取生成的学生***//
  2398. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_EN_MAGIC_WORD);
  2399. $generateStu = $productDownload->getGenerateStu('english_magic_word_student', 'mw_id', 'week_pdf_path', 'is_week_pdf', $weekId, array());
  2400. if(!$generateStu){
  2401. $notFound++;
  2402. continue;
  2403. }
  2404. $params['studentIds'] = $generateStu['studentIds'];
  2405. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  2406. if (!$apiUrl) {
  2407. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  2408. exit();
  2409. }
  2410. $sql = "select class_id,grade,create_time,semester_id,name from english_magic_word where mw_id = '{$weekId}'";
  2411. $msg = $this->sConn->createCommand($sql)->queryRow();
  2412. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  2413. $params['schoolId'] = $this->schoolId;
  2414. $params['type'] = 6;
  2415. $params['mwId'] = $weekId;
  2416. //**************** Step-2 判断是否已经存在下载任务 ********************//
  2417. $packTask = $this->getExistTask($weekId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_EN_MAGIC_WORD, count($params["studentIds"]));
  2418. if($packTask){
  2419. continue;
  2420. }
  2421. $packProductModel = new BusinessPackProductTask();
  2422. $packProductModel->school_id = $this->schoolId;
  2423. $packProductModel->auth_username = $this->authUsername;
  2424. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_EN_MAGIC_WORD;
  2425. $packProductModel->product_name = $msg['name'] . '词汇宝';
  2426. $packProductModel->subject_id = $this->subjectId;
  2427. $packProductModel->class_id = $msg['class_id'];
  2428. $packProductModel->class_name = $classinfo['class_name'];
  2429. $packProductModel->unique_key = $weekId;
  2430. $packProductModel->student_count = count($params['studentIds']);
  2431. $packProductModel->pack_json = json_encode($params);
  2432. $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index";
  2433. $packProductModel->create_time = time();
  2434. $packProductModel->save();
  2435. $this->updateMagicWordDownloadStatus($params['studentIds'], $weekId);
  2436. }
  2437. if($notFound == count($params_arr)){
  2438. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  2439. }
  2440. echo json_encode(array("success" => 1, "message" => "success"));
  2441. }
  2442. /**
  2443. * 下载词汇宝检测卡
  2444. */
  2445. public function actionGetMagicWordCard()
  2446. {
  2447. $mwId = (string)Req::get("mw_id");
  2448. $params = array();
  2449. if (!$mwId) {
  2450. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  2451. exit();
  2452. }
  2453. $sql = "select student_id from english_magic_word_student where mw_id = '{$mwId}' and is_card_pdf = 1";
  2454. $stuArr = $this->getDbConnection()->createCommand($sql)->queryAll();
  2455. if ($stuArr) {
  2456. foreach ($stuArr as $k => $v) {
  2457. $params['studentIds'][] = $v['student_id'];
  2458. }
  2459. }else{
  2460. echo json_encode(array("success" => 0, "message" => "未找到生成的检测卡"));
  2461. exit();
  2462. }
  2463. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  2464. if (!$apiUrl) {
  2465. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  2466. exit();
  2467. }
  2468. $params['schoolId'] = $this->schoolId;
  2469. $params['type'] = 6;
  2470. $params['mwId'] = $mwId;
  2471. $params['isMwCard'] = 1;
  2472. $rs = Curl::post($apiUrl . "/rest/download_week_pdf/index", $params);
  2473. if (!($rs = json_decode($rs))) {
  2474. $rs = array(
  2475. "success" => 0,
  2476. "message" => "请求接口失败",
  2477. );
  2478. } else {
  2479. //更新下载时间
  2480. if ($rs->success == 1 || $rs->success == 2) {
  2481. $this->updateMagicWordAfterDownloadStatus($params['studentIds'],$mwId);
  2482. }
  2483. }
  2484. echo json_encode($rs);
  2485. exit;
  2486. }
  2487. /**
  2488. * 下载写作宝
  2489. */
  2490. public function actionGetWritingFile()
  2491. {
  2492. $ewId = (string)Req::get("ew_id");
  2493. $studentsIds = Req::get("studentsIds");
  2494. $classDownload = $studentsIds ? false : true;
  2495. $params = array();
  2496. if (!$ewId) {
  2497. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  2498. exit();
  2499. }
  2500. $sql = "select class_id,grade,create_time,semester_id,name from english_writing where ew_id = '{$ewId}'";
  2501. $msg = $this->sConn->createCommand($sql)->queryRow();
  2502. //*****获取生成的学生***//
  2503. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_WRITING);
  2504. $generateStu = $productDownload->getGenerateStu('english_writing_student', 'ew_id', 'week_pdf_path', 'is_week_pdf', $ewId, $studentsIds);
  2505. if(!$generateStu){
  2506. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  2507. }
  2508. $params['studentIds'] = $generateStu['studentIds'];
  2509. $pathArr = $generateStu['pathArr'];
  2510. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  2511. if (!$apiUrl) {
  2512. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  2513. exit();
  2514. }
  2515. $Sem = new SSemester();
  2516. $code = $Sem->conn->createQuery()
  2517. ->from('semester')
  2518. ->where("semester_id = '" . $msg['semester_id'] . "'")
  2519. ->limit(1)
  2520. ->query()
  2521. ->read();
  2522. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  2523. $intarr = array(
  2524. "schoolId" => $this->schoolId,
  2525. "clazzId" => $msg['class_id'],
  2526. "semester" => $code['refer_code'],
  2527. "grade" => $msg['grade'],
  2528. "students" => $studentsIds,
  2529. "examTime" => $msg['create_time'],
  2530. "classify" => 32,
  2531. "subject" => 8
  2532. );
  2533. //************ Step-1 判断是否有订单 *************//
  2534. if (Yii::app()->params["limit_open"]) {
  2535. if (Yii::app()->params["limit_open"]) {
  2536. $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId);
  2537. }
  2538. }
  2539. $params['schoolId'] = $this->schoolId;
  2540. $params['type'] = 7;
  2541. $params['ewId'] = $ewId;
  2542. //**************** Step-2 判断是否已经存在下载任务 ********************//
  2543. if($classDownload) {
  2544. $packTask = $this->getExistTask($ewId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_WRITING, count($params["studentIds"]));
  2545. if (isset($packTask->pack_status) && $packTask->pack_status == 0) {
  2546. echo json_encode(array("success" => 3, "message" => ""));
  2547. exit;
  2548. }
  2549. if (isset($packTask->pack_url) && $packTask->pack_url) {
  2550. $this->updateWritingDownloadStatus($params['studentIds'],$ewId);
  2551. echo json_encode(array("success" => 1, "downloadPath" => $packTask->pack_url));
  2552. exit;
  2553. }
  2554. }
  2555. //**************** Step-3 根据接口获取文件大小来判断走原有接口打包流程还是走脚本任务 ************//
  2556. $sizeRs = Curl::post($apiUrl . "/rest/download_file_size/index", array('path_arr' => $pathArr));
  2557. if (!($sizeRs = json_decode($sizeRs))) {
  2558. echo json_encode(array("success" => 0, "message" => "请求接口失败"));
  2559. exit;
  2560. }
  2561. if (isset($sizeRs->size)) {
  2562. //************ Step-3-1 大于限定值 发送任务到后台打包 ******//
  2563. if (Yii::app()->params["pack_product_file_limit"] < $sizeRs->size) {
  2564. $packProductModel = new BusinessPackProductTask();
  2565. $packProductModel->school_id = $this->schoolId;
  2566. $packProductModel->auth_username = $this->authUsername;
  2567. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_WRITING;
  2568. $packProductModel->product_name = $msg['name'] . '写作宝';
  2569. $packProductModel->subject_id = $this->subjectId;
  2570. $packProductModel->class_id = $msg['class_id'];
  2571. $packProductModel->class_name = $classinfo['class_name'];
  2572. $packProductModel->unique_key = $ewId;
  2573. $packProductModel->student_count = count($params['studentIds']);
  2574. $packProductModel->pack_json = json_encode($params);
  2575. $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index";
  2576. $packProductModel->create_time = time();
  2577. $packProductModel->save();
  2578. $this->updateWritingDownloadStatus($params['studentIds'],$ewId);
  2579. echo json_encode(array("success" => 3, "message" => ""));
  2580. exit;
  2581. } else {
  2582. $rs = Curl::post($apiUrl . "/rest/download_week_pdf/index", $params);
  2583. if (!($rs = json_decode($rs))) {
  2584. $rs = array(
  2585. "success" => 0,
  2586. "message" => "请求接口失败",
  2587. );
  2588. } else {
  2589. //更新下载时间
  2590. if ($rs->success == 1 || $rs->success == 2) {
  2591. $this->updateWritingDownloadStatus($params['studentIds'],$ewId);
  2592. }
  2593. }
  2594. echo json_encode($rs);
  2595. exit;
  2596. }
  2597. } else {
  2598. echo json_encode(array("success" => 0, "message" => $sizeRs->message));
  2599. exit;
  2600. }
  2601. }
  2602. /**
  2603. * 更新写作宝下载状态
  2604. * @param $studentsIds
  2605. * @param $weekId
  2606. */
  2607. private function updateWritingDownloadStatus($studentsIds, $weekId)
  2608. {
  2609. $time = time();
  2610. $sql = "update english_writing_student set is_week_download = 1,week_download_time={$time} where ew_id = '{$weekId}' and student_id in (" . implode(',', $studentsIds) . ") and week_download_time = 0";
  2611. $this->sConn->createCommand($sql)->execute();
  2612. }
  2613. /**
  2614. * 添加写作宝下载任务
  2615. */
  2616. public function actionAddWritingTask()
  2617. {
  2618. $weekId = (string)Req::get("ew_id");
  2619. $studentsIds = Req::get("studentsIds");
  2620. if (!$weekId) {
  2621. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  2622. exit();
  2623. }
  2624. $sql = "select class_id,grade,create_time,semester_id,name from english_writing where ew_id = '{$weekId}'";
  2625. $msg = $this->sConn->createCommand($sql)->queryRow();
  2626. //*****获取生成的学生***//
  2627. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_WRITING);
  2628. $generateStu = $productDownload->getGenerateStu('english_writing_student', 'ew_id', 'week_pdf_path', 'is_week_pdf', $weekId, $studentsIds);
  2629. if(!$generateStu){
  2630. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  2631. }
  2632. $params['studentIds'] = $generateStu['studentIds'];
  2633. $Sem = new SSemester();
  2634. $code = $Sem->conn->createQuery()
  2635. ->from('semester')
  2636. ->where("semester_id = '" . $msg['semester_id'] . "'")
  2637. ->limit(1)
  2638. ->query()
  2639. ->read();
  2640. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  2641. $intarr = array(
  2642. "schoolId" => $this->schoolId,
  2643. "clazzId" => $msg['class_id'],
  2644. "semester" => $code['refer_code'],
  2645. "grade" => $msg['grade'],
  2646. "students" => $studentsIds,
  2647. "examTime" => $msg['create_time'],
  2648. "classify" => 32,
  2649. "subject" => 8
  2650. );
  2651. //************ Step-1 判断是否有订单 *************//
  2652. $params = array();
  2653. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  2654. if (!$apiUrl) {
  2655. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  2656. exit();
  2657. }
  2658. if (Yii::app()->params["limit_open"]) {
  2659. if (Yii::app()->params["limit_open"]) {
  2660. $params["studentIds"] = $productDownload->getCanDownloadStu($params['studentIds'], $intarr, $this->schoolId);
  2661. }
  2662. }
  2663. //*******产品接口参数******//
  2664. $params['ewId'] = $weekId;
  2665. $params['schoolId'] = $this->schoolId;
  2666. $params['type'] = 7;
  2667. $packProductModel = new BusinessPackProductTask();
  2668. $packProductModel->school_id = $this->schoolId;
  2669. $packProductModel->auth_username = $this->authUsername;
  2670. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_WRITING;
  2671. $packProductModel->product_name = $msg['name'] . '写作宝';
  2672. $packProductModel->subject_id = $this->subjectId;
  2673. $packProductModel->class_id = $msg['class_id'];
  2674. $packProductModel->class_name = $classinfo['class_name'];
  2675. $packProductModel->unique_key = $weekId;
  2676. $packProductModel->student_count = count($params['studentIds']);
  2677. $packProductModel->pack_json = json_encode($params);
  2678. $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index";
  2679. $packProductModel->create_time = time();
  2680. $packProductModel->save();
  2681. $this->updateWritingDownloadStatus($params['studentIds'],$weekId);
  2682. echo json_encode(array("success" => 3, "message" => ""));
  2683. exit;
  2684. }
  2685. /**
  2686. * 批量写作宝下载
  2687. */
  2688. public function actionBatchWriting()
  2689. {
  2690. $json_params = file_get_contents('php://input');
  2691. $params_arr = json_decode($json_params, true);
  2692. $notFound = 0;
  2693. foreach ($params_arr as $param) {
  2694. $weekId = isset($param['ew_id']) ? (string)$param['ew_id'] : null;
  2695. $params = array();
  2696. if (!$weekId) {
  2697. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  2698. exit();
  2699. }
  2700. //*****获取生成的学生***//
  2701. $productDownload = new ProductDownload(ProductDownload::PRODUCT_TYPE_WRITING);
  2702. $generateStu = $productDownload->getGenerateStu('english_writing_student', 'ew_id', 'week_pdf_path', 'is_week_pdf', $weekId, array());
  2703. if(!$generateStu){
  2704. $notFound++;
  2705. continue;
  2706. }
  2707. $params['studentIds'] = $generateStu['studentIds'];
  2708. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  2709. if (!$apiUrl) {
  2710. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  2711. exit();
  2712. }
  2713. $sql = "select class_id,grade,create_time,semester_id,name from english_writing where ew_id = '{$weekId}'";
  2714. $msg = $this->sConn->createCommand($sql)->queryRow();
  2715. $classinfo = ClassModel::model()->find("class_id=:id", array(":id" => $msg['class_id']));
  2716. $params['schoolId'] = $this->schoolId;
  2717. $params['type'] = 7;
  2718. $params['ewId'] = $weekId;
  2719. //**************** Step-2 判断是否已经存在下载任务 ********************//
  2720. $packTask = $this->getExistTask($weekId, $msg['class_id'], ProductDownload::PRODUCT_TYPE_WRITING, count($params["studentIds"]));
  2721. if($packTask){
  2722. continue;
  2723. }
  2724. $packProductModel = new BusinessPackProductTask();
  2725. $packProductModel->school_id = $this->schoolId;
  2726. $packProductModel->auth_username = $this->authUsername;
  2727. $packProductModel->product_type = ProductDownload::PRODUCT_TYPE_WRITING;
  2728. $packProductModel->product_name = $msg['name'] . '写作宝';
  2729. $packProductModel->subject_id = $this->subjectId;
  2730. $packProductModel->class_id = $msg['class_id'];
  2731. $packProductModel->class_name = $classinfo['class_name'];
  2732. $packProductModel->unique_key = $weekId;
  2733. $packProductModel->student_count = count($params['studentIds']);
  2734. $packProductModel->pack_json = json_encode($params);
  2735. $packProductModel->pack_api_url = $apiUrl . "/rest/download_week_pdf/index";
  2736. $packProductModel->create_time = time();
  2737. $packProductModel->save();
  2738. $this->updateWritingDownloadStatus($params['studentIds'], $weekId);
  2739. }
  2740. if($notFound == count($params_arr)){
  2741. echo json_encode(array("success" => 0, "message" => "无生成的学生"));exit();
  2742. }
  2743. echo json_encode(array("success" => 1, "message" => "success"));
  2744. }
  2745. /**
  2746. * 下载写作宝检测卡
  2747. */
  2748. public function actionGetWritingCard()
  2749. {
  2750. $ewId = (string)Req::get("ew_id");
  2751. $params = array();
  2752. if (!$ewId) {
  2753. echo json_encode(array("success" => 0, "message" => "缺少参数"));
  2754. exit();
  2755. }
  2756. $sql = "select student_id from english_writing_student where ew_id = '{$ewId}' and is_card_pdf = 1";
  2757. $stuArr = $this->getDbConnection()->createCommand($sql)->queryAll();
  2758. if ($stuArr) {
  2759. foreach ($stuArr as $k => $v) {
  2760. $params['studentIds'][] = $v['student_id'];
  2761. }
  2762. }else{
  2763. echo json_encode(array("success" => 0, "message" => "未找到生成的检测卡"));
  2764. exit();
  2765. }
  2766. $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
  2767. if (!$apiUrl) {
  2768. echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
  2769. exit();
  2770. }
  2771. $params['schoolId'] = $this->schoolId;
  2772. $params['type'] = 7;
  2773. $params['ewId'] = $ewId;
  2774. $params['isMwCard'] = 1;
  2775. $rs = Curl::post($apiUrl . "/rest/download_week_pdf/index", $params);
  2776. if (!($rs = json_decode($rs))) {
  2777. $rs = array(
  2778. "success" => 0,
  2779. "message" => "请求接口失败",
  2780. );
  2781. } else {
  2782. //更新下载时间
  2783. if ($rs->success == 1 || $rs->success == 2) {
  2784. $time = time();
  2785. $sql = "update english_writing_student set is_card_download = 1,card_download_time={$time} where ew_id = '{$ewId}' and student_id in (" . implode(',', $params['studentIds']) . ")";
  2786. $this->sConn->createCommand($sql)->execute();
  2787. }
  2788. }
  2789. echo json_encode($rs);
  2790. exit;
  2791. }
  2792. }