PrintCloudController.php 128 KB

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