ExamController.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  1. <?php
  2. /**
  3. * 考试全流程
  4. * Created by 上海互教教育科技有限公司.
  5. * User: li
  6. * Date: 2022/8/8
  7. * Time: 上午 10:32
  8. */
  9. class ExamController extends Controller
  10. {
  11. const PRODUCT_WB = 1;//错题本
  12. const PRODUCT_ISP = 2;//两步个性化学习宝
  13. const PRODUCT_WBISP = 3;//三步个性化学习宝
  14. const PRODUCT_METHOD = 31;//考后方法宝(高中)
  15. public $signatureType=array(
  16. 1=>7,
  17. 2=>8,
  18. 3=>9,
  19. 31=>31
  20. );
  21. // 首页 考试流程时间节点
  22. public function actionIndex(){
  23. $examGroupId = Req::post("examGroupId");
  24. if(!$examGroupId || !is_numeric($examGroupId)){
  25. $this->returnMsg(0,'考试Id格式不正确');
  26. }
  27. $result=array();
  28. $examGroup=SExamGroup::model()->find("exam_group_id=:id",array(":id"=>$examGroupId));
  29. if(!$examGroup) $this->returnMsg(0,'考试Id不正确');
  30. $result['exam_create']=array(); //组卷
  31. $result['exam_create']['is_third']=$examGroup['is_third'];
  32. $result['exam_create']['mark_type']=$examGroup['mark_type'];;
  33. $exam=Exam::model()->findAll("exam_group_id=:id",array(":id"=>$examGroupId));
  34. $result['exam_create']['create_time']=$exam[0]['create_time']; //发送打印,创建时间
  35. $result['exam_create']['order_time']=$exam[0]['create_time']; //排序字段
  36. $result['exam_create']['exam_name']=$exam[0]['name'];
  37. $result['exam_create']['import_score_type']=$examGroup['import_score_type'];
  38. $tplData=json_decode($exam[0]['tpl_data'],true);
  39. $result['exam_create']['exam_date']=$tplData['examDate'];
  40. $result['exam_create']['teacher']=$tplData['author'];
  41. $lastTime=$exam[0]['create_time']; //最后操作时间
  42. $examIds=array();
  43. $classIds=array();
  44. $classNames=array();
  45. $classExam=array();
  46. foreach ($exam as $value){
  47. $examIds[]=$value['exam_id'];
  48. $classIds[]=$value['class_id'];
  49. $classExam[(string)$value['exam_id']]=$value['class_id'];
  50. }
  51. $criteria = new CDbCriteria();
  52. $criteria->addInCondition('class_id',$classIds);
  53. $classes = ClassModel::model()->findAll($criteria);
  54. unset($criteria);
  55. $result['backlog']=array();
  56. $result['backlog']['order_time']=0;
  57. foreach ($classes as $class){
  58. $classNames[(string)$class['class_id']]=$class['class_name'];
  59. if($examGroup['mark_type']==0 || $examGroup['import_score_type']>0){
  60. $result['backlog']['classes'][(string)$class['class_id']]=array(
  61. 'class_id'=>$class['class_id'],
  62. 'time'=>0,
  63. 'class_name'=>$class['class_name']
  64. );
  65. }
  66. }
  67. $criteria = new CDbCriteria();
  68. $criteria->select = 'student_id';
  69. $criteria->addInCondition('exam_id',$examIds);
  70. $criteria->addCondition('is_del = 0');
  71. $allStudentPaper=SStudentPaperRelation::model()->count($criteria);
  72. //答题卡类型
  73. $thirdAnswerSheet=SThirdAnswerSheet::model()->find("exam_group_id=:id",array(":id"=>$examGroupId));
  74. if(!$thirdAnswerSheet){
  75. if($examGroup['is_third']==1){
  76. $this->returnMsg(1,'success',$result); //还没创建答题卡,流程结束
  77. }else{
  78. //查询下载答题卡时间
  79. $examPrint= ClassExamPrinter::model()->find("exam_id in (:ids)",array(':ids'=>implode(',',$examIds)));
  80. $result['card']['print_time']=$examPrint['print_time'];
  81. $result['card']['order_time']=$examPrint['print_time'];
  82. $lastTime<$examPrint['print_time'] && $lastTime=$examPrint['print_time'];
  83. }
  84. }else{
  85. $result['card']['online_card']=$thirdAnswerSheet['online_card']; //是否在线答题卡
  86. $result['card']['create_answer_card_time']=$thirdAnswerSheet['update_time']; //保存答题卡时间
  87. $result['card']['order_time']=$thirdAnswerSheet['create_time'];
  88. $lastTime<$thirdAnswerSheet['create_time'] && $lastTime=$thirdAnswerSheet['create_time'];
  89. if($thirdAnswerSheet['online_card']==1){
  90. $onlineCard=SOnlineCardMultiplex::model()->find("multiplex_id=:id",array(":id"=>$thirdAnswerSheet['multiplex_id']));
  91. if($onlineCard['is_download']==1 && !$thirdAnswerSheet['is_qrcode_online']){
  92. $result['card']['print_time']=$onlineCard['update_time'];
  93. $lastTime<$onlineCard['update_time'] && $lastTime=$onlineCard['update_time'];
  94. }
  95. //生成时间
  96. if($onlineCard['is_download']==1 && $thirdAnswerSheet['is_qrcode_online']==1){
  97. $criteria = new CDbCriteria();
  98. $criteria->select = 'create_time';
  99. $criteria->addInCondition('exam_id',$examIds);
  100. $criteria->addCondition('answer_card_online_created = 1');
  101. $criteria->order="create_time asc";
  102. $studentCard=SStudentAnswerCardOnline::model()->find($criteria);
  103. if($studentCard){
  104. $result['card']['generate_card_start_time']=$studentCard['create_time'];
  105. }
  106. $criteria = new CDbCriteria();
  107. $criteria->select = 'create_time';
  108. $criteria->addInCondition('exam_id',$examIds);
  109. $criteria->addCondition('answer_card_online_created = 1');
  110. $createdStudent=SStudentAnswerCardOnline::model()->count($criteria);
  111. if($createdStudent==$allStudentPaper){
  112. $criteria = new CDbCriteria();
  113. $criteria->select = 'create_time';
  114. $criteria->addInCondition('exam_id',$examIds);
  115. $criteria->addCondition('answer_card_online_created = 1');
  116. $criteria->order="create_time desc";
  117. $studentCardLast=SStudentAnswerCardOnline::model()->find($criteria);
  118. if($studentCardLast){
  119. $result['card']['generate_card_end_time']=$studentCardLast['create_time'];
  120. }
  121. }
  122. }
  123. }
  124. }
  125. //时间节点
  126. $examProcess=SExamProcess::model()->findAll("exam_group_id=:id",array(':id'=>$examGroupId));
  127. $cardPrintClass=array(); //答题卡打印班级
  128. if($examProcess){
  129. foreach ($examProcess as $val){
  130. $lastTime<$val['action_time'] && $lastTime=$val['action_time'];
  131. switch ($val['action_type']){
  132. case 1:
  133. if(!isset($result['label']['send_label_time']) || $val['action_time']<$result['label']['send_label_time']){
  134. $result['label']['send_label_time']=$val['action_time'];
  135. if(!isset($result['label']['order_time'])){
  136. $result['label']['order_time']=$val['action_time'];
  137. }
  138. }
  139. break;
  140. case 2:
  141. if($val['action_time']){
  142. $result['label']['label_complete_time'][]=$val['action_time'];
  143. }
  144. break;
  145. case 3:
  146. if(!isset($result['parse']['upload_topic_time']) || $result['parse']['upload_topic_time']>$val['action_time']){
  147. $result['parse']['upload_topic_time']=$val['action_time'];
  148. $result['parse']['upload_answer_time']=$val['action_time'];
  149. $result['parse']['order_time']=$val['action_time'];
  150. }
  151. break;
  152. case 4:
  153. $result['parse']['parse_complete_time']=$val['action_time'];
  154. break;
  155. case 5:
  156. if(!isset($result['parse']['upload_topic_time']) || $result['parse']['upload_topic_time']<$val['action_time']){
  157. $result['parse']['upload_topic_time']=$val['action_time'];
  158. $result['parse']['order_time']=$val['action_time'];
  159. }
  160. break;
  161. case 6:
  162. if(!isset($result['parse']['upload_answer_time']) || $result['parse']['upload_answer_time']<$val['action_time']){
  163. $result['parse']['upload_answer_time']=$val['action_time'];
  164. $result['parse']['order_time']=$val['action_time'];
  165. }
  166. break;
  167. case 7:
  168. //待办
  169. if(isset($result['backlog']['classes'][(string)$val['class_id']])){
  170. $result['backlog']['classes'][(string)$val['class_id']]['time']=$val['action_time'];
  171. }
  172. if($result['backlog']['order_time']>$val['action_time'] || $result['backlog']['order_time']==0){
  173. $result['backlog']['order_time']=$val['action_time'];
  174. }
  175. break;
  176. case 8:
  177. if(!isset($result['card']['create_answer_card_time']) || $result['card']['create_answer_card_time']<$val['action_time']){
  178. $result['card']['create_answer_card_time']=$val['action_time']; //保存答题卡时间
  179. }
  180. break;
  181. case 9:
  182. //答题卡下载
  183. $result['card']['print_time']=$val['action_time'];
  184. if(!isset($result['card']['print_start_time']) || $result['card']['print_start_time']>$val['action_time']){
  185. $result['card']['print_start_time']=$val['action_time'];
  186. }
  187. if(!isset($result['card']['print_end_time']) || $result['card']['print_end_time']<$val['action_time']){
  188. $result['card']['print_end_time']=$val['action_time'];
  189. }
  190. if($val['exam_id']){
  191. $cardPrintClass[$val['exam_id']]=$val['action_time'];
  192. }
  193. break;
  194. case 10:
  195. //重置
  196. break;
  197. case 11:
  198. //切换扫描方式
  199. $result['card']['change_scan_time']=$val['action_time'];
  200. if(!isset($result['card']['order_time']) || !$result['card']['order_time']){
  201. $result['card']['order_time']=$val['action_time'];
  202. }
  203. break;
  204. case 13:
  205. //在线答题卡生成开始排队时间
  206. if(!isset($result['card']['create_line_up_time']) || $result['card']['create_line_up_time']>$val['action_time']){
  207. $result['card']['create_line_up_time']=$val['action_time'];
  208. }
  209. break;
  210. case 14:
  211. //下载试卷时间
  212. $result['card']['download_paper_time']=$val['action_time'];
  213. default:
  214. }
  215. }
  216. }
  217. //判断是否打印答题卡完成
  218. if(count($cardPrintClass)!=count($examIds) && isset($result['card']['print_end_time'])){
  219. $result['card']['print_end_time']=0;
  220. }
  221. if(isset($result['backlog']['classes'])){
  222. $result['backlog']['classes']=array_values($result['backlog']['classes']);
  223. $lastOrder = $this->_array_column( $result['backlog']['classes'],'time');
  224. array_multisort($lastOrder,SORT_DESC,$result['backlog']['classes']);
  225. }
  226. if(isset($result['label']) ){
  227. if(isset($tplData["estimateTime"])){
  228. $result['label']['estimate_time'] = date('Y-m-d H:i:s',$tplData["estimateTime"]);
  229. }
  230. //判断标注类型
  231. $paper=SPaper::model()->find('exam_id=:eid',array(":eid"=>$exam[0]['exam_id']));
  232. if($paper['labelled_type']==2 && $paper['finish_labelled_time']){
  233. $result['label']['label_complete_time'][]=$paper['finish_labelled_time'];
  234. }
  235. if(isset($result['label']['label_complete_time']) && $result['label']['label_complete_time']){
  236. sort($result['label']['label_complete_time']);
  237. }
  238. }
  239. if($examGroup['is_third']==1 && isset($result['parse'])){
  240. $topicWord= STopicWord::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
  241. $result['exam_create']['topic_status']=$topicWord['status'];
  242. if($topicWord && !$topicWord['allsubject_file_path'] && isset($result['parse']['upload_answer_time'])){
  243. unset($result['parse']['upload_answer_time']);
  244. }
  245. }
  246. //扫描上传,第一个
  247. $criteria = new CDbCriteria();
  248. $criteria->select = 'feedback_time';
  249. $criteria->addInCondition('exam_id',$examIds);
  250. $criteria->addCondition('is_del = 0 and is_feedback=1');
  251. $criteria->order="feedback_time asc";
  252. $studentPaper=SStudentPaperRelation::model()->find($criteria);
  253. unset($criteria);
  254. if($studentPaper){
  255. $result['scan']['start_upload_card_time']=$studentPaper['feedback_time'];
  256. $result['scan']['order_time']=$studentPaper['feedback_time'];
  257. $lastTime<$studentPaper['feedback_time'] && $lastTime=$studentPaper['feedback_time'];
  258. $result['scan']['all_student']=$allStudentPaper;
  259. unset($criteria);
  260. $criteria = new CDbCriteria();
  261. $criteria->select = 'student_id,class_id';
  262. $criteria->addInCondition('exam_id',$examIds);
  263. $criteria->addCondition('is_del = 0 and is_feedback=1');
  264. $allUploadStudentPaper=SStudentPaperRelation::model()->count($criteria);
  265. $result['scan']['uploaded_student']=$allUploadStudentPaper;
  266. $allUploadStudentClass=SStudentPaperRelation::model()->findAll($criteria);
  267. $studentClass=array();
  268. foreach ($allUploadStudentClass as $item){
  269. $studentClass[(string)$item['class_id']]=$item['class_id'];
  270. }
  271. unset($criteria);
  272. $result['scan']['class_count']=count($studentClass);
  273. }
  274. //扫描上传,判断最后一个
  275. $theLast=false;
  276. if($examGroup['mark_type']==0 || $examGroup['import_score_type']>0){
  277. //判断全部点待办
  278. $isBacklog=false; //待办
  279. if($result['backlog']){
  280. $isBacklog=true;
  281. foreach ($result['backlog']['classes'] as $value){
  282. if(!$value['time']){
  283. $isBacklog=false;
  284. break;
  285. }
  286. }
  287. }
  288. if($isBacklog){
  289. $theLast=true;
  290. }
  291. }elseif($examGroup['mark_type']==3 && $examGroup['mark_status']==2){
  292. //混合阅卷
  293. $theLast=true;
  294. }elseif($examGroup['mark_type']==4){
  295. //单独阅卷
  296. $theLast=true;
  297. foreach ($exam as $value){
  298. if($value['status']!=1){
  299. $theLast=false;
  300. break;
  301. }
  302. }
  303. }
  304. if($theLast){
  305. $criteria = new CDbCriteria();
  306. $criteria->select = 'feedback_time';
  307. $criteria->addInCondition('exam_id',$examIds);
  308. $criteria->addCondition('is_del = 0 and is_feedback=1');
  309. $criteria->order="feedback_time desc";
  310. $studentPaper=SStudentPaperRelation::model()->find($criteria);
  311. unset($criteria);
  312. if($studentPaper){
  313. $result['scan']['end_upload_card_time']=$studentPaper['feedback_time'];
  314. $lastTime<$studentPaper['feedback_time'] && $lastTime=$studentPaper['feedback_time'];
  315. }
  316. //查询耗时
  317. $clientScanSpeed=ClientScanSpeedLog::model()->findAll("exam_group_id=:id",array(':id'=>$examGroupId));
  318. if($clientScanSpeed){
  319. $scanTimeAvg=0;
  320. $uploadCardTimeTotal=0;
  321. $uploadCardCount=0;
  322. $uploadPaperTimeTotal=0;
  323. $uploadPaperCount=0;
  324. foreach ($clientScanSpeed as $item){
  325. $scanTimeAvg+=$item['scan_time_avg'];
  326. $uploadCardTimeTotal+=$item['upload_card_time_total'];
  327. $uploadCardCount+=$item['upload_card_count'];
  328. $uploadPaperTimeTotal+=$item['upload_paper_time_total'];
  329. $uploadPaperCount+=$item['upload_paper_count'];
  330. }
  331. $result['scan']['scan_time_avg']=ceil($scanTimeAvg/count($clientScanSpeed)); //平均扫描时间
  332. if($uploadCardTimeTotal && $uploadCardCount){
  333. $result['scan']['upload_card_time_avg']=ceil($uploadCardTimeTotal/$uploadCardCount); //平均上传答卷耗时
  334. }
  335. if($uploadPaperTimeTotal && $uploadPaperCount){
  336. $result['scan']['upload_paper_time_avg']=ceil($uploadPaperTimeTotal/$uploadPaperCount); //平均上传原卷耗时
  337. }
  338. }
  339. }
  340. //阅卷
  341. if($examGroup['mark_type']>0){
  342. $markParam=array(
  343. 'examGroupIds'=>array($examGroupId),
  344. 'schoolId'=>$this->schoolId
  345. );
  346. $rs = http('/teacher/marking/v2/marking-info','POST',$this->schoolId,$markParam,'cgi');
  347. $rs=json_decode($rs,true);
  348. if(isset($rs['errCode']) && $rs['errCode']=='00' && $rs['data']){
  349. $result['marking']['marking_start_time']=strtotime($rs['data'][0]['markingStartTime']); //阅卷开始时间
  350. $result['marking']['marking_end_time']=strtotime($rs['data'][0]['markingEndTime']); //阅卷结束时间
  351. $result['marking']['marking_process']=$rs['data'][0]['markingProgress']['process']*100; //阅卷进度百分比
  352. $result['marking']['order_time']=strtotime($rs['data'][0]['markingStartTime']);
  353. $result['marking']['marking_start_time'] && $lastTime<$result['marking']['marking_start_time'] && $lastTime=$result['marking']['marking_start_time'];
  354. $result['marking']['marking_end_time'] && $lastTime<$result['marking']['marking_end_time'] && $lastTime=$result['marking']['marking_end_time'];
  355. if($rs['data'][0]['classMarkingInfos']){
  356. //单独阅卷
  357. foreach ($rs['data'][0]['classMarkingInfos'] as $val){
  358. $result['marking']['class_marking_info'][]=array(
  359. 'class_name'=>$classNames[(string)$val['classId']],
  360. 'class_marking_start_time'=>strtotime($val['markingStartTime']),
  361. 'class_marking_end_time'=>strtotime($val['markingEndTime']),
  362. 'class_marking_process'=>$val['markingProgress']['process']*100
  363. );
  364. }
  365. $lastOrder = $this->_array_column($result['marking']['class_marking_info'],'class_marking_process');
  366. array_multisort($lastOrder,SORT_DESC,$result['marking']['class_marking_info']);
  367. }
  368. }
  369. }
  370. //产品生成,下载
  371. if(!isset($result['label']) || ($paper['is_labelled']!=5 && $examGroup['is_tagging']!=5)){
  372. $productTimes=$this->getProduct($examIds);
  373. if($productTimes){
  374. $result['product']=$productTimes;
  375. if($productTimes['product_create_start_time']){
  376. $result['product']['order_time']=$productTimes['product_create_start_time'];
  377. }elseif(isset($productTimes['queue_create_time'])){
  378. $result['product']['order_time']=$productTimes['queue_create_time'];
  379. }
  380. if(isset($productTimes['product_last_download_time']) && $productTimes['product_last_download_time'] && $lastTime<$productTimes['product_last_download_time'] ){
  381. $lastTime=$productTimes['product_last_download_time'];
  382. }elseif(isset($productTimes['product_first_download_time']) && $productTimes['product_first_download_time'] && $lastTime<$productTimes['product_first_download_time']){
  383. $lastTime=$productTimes['product_first_download_time'];
  384. }elseif(isset($productTimes['product_create_last']) && $productTimes['product_create_last'] && $lastTime<$productTimes['product_create_last']){
  385. $lastTime=$productTimes['product_create_last'];
  386. }elseif(isset($productTimes['product_create_start_time']) && $productTimes['product_create_start_time'] && $lastTime<$productTimes['product_create_start_time']){
  387. $lastTime=$productTimes['product_create_start_time'];
  388. }
  389. //签收
  390. $imsClass=array();
  391. foreach ($productTimes['product_class_type'] as $eid => $v){
  392. $imsProductType=array();
  393. foreach ($v as $t){
  394. $imsProductType[]=$this->signatureType[$t];
  395. }
  396. $imsClass[]=array(
  397. 'clazzId'=>$classExam[$eid],
  398. 'productTypes'=>$imsProductType
  399. );
  400. }
  401. // $classExam
  402. $imsParam=array(
  403. 'businessId'=>$examGroupId,
  404. 'clazzList'=>$imsClass,
  405. );
  406. $http = http('order/deliver/coach/query/signature-time', 'POST', $this->authUsername,$imsParam);
  407. $response = formatResponse($http);
  408. if ($response['status']) {
  409. $result['product']['signature']['signature_begin_time']=strtotime($response['data']['beginTime']);
  410. $result['product']['signature']['signature_end_time']=strtotime($response['data']['endTime']);
  411. $response['data']['endTime'] && $lastTime<strtotime($response['data']['endTime']) && $lastTime=strtotime($response['data']['endTime']);
  412. $response['data']['beginTime'] && $lastTime<strtotime($response['data']['beginTime']) && $lastTime=strtotime($response['data']['beginTime']);
  413. }
  414. }
  415. }
  416. //按开始时间排序
  417. $lastOrder = $this->_array_column($result,'order_time');
  418. array_multisort($lastOrder,SORT_ASC,$result);
  419. //计算总耗时
  420. $result['exam_total_time_consuming']=consuming($lastTime,$exam[0]['create_time']);
  421. $this->returnMsg(1,'success',$result);
  422. }
  423. //产品生成详情,下载,签收
  424. public function actionProductDetail(){
  425. $examGroupId = Req::post("examGroupId");
  426. if(!$examGroupId || !is_numeric($examGroupId)){
  427. $this->returnMsg(0,'考试Id格式不正确');
  428. }
  429. $result=array();
  430. $examGroup=SExamGroup::model()->find("exam_group_id=:id",array(":id"=>$examGroupId));
  431. if(!$examGroup) $this->returnMsg(0,'考试Id不正确');
  432. $exam=Exam::model()->findAll("exam_group_id=:id",array(":id"=>$examGroupId));
  433. $examIds=array();
  434. $classIds=array();
  435. $classExam=array();
  436. foreach ($exam as $value){
  437. $examIds[]=$value['exam_id'];
  438. $classIds[]=$value['class_id'];
  439. $classExam[(string)$value['exam_id']]=$value['class_id'];
  440. }
  441. $criteria = new CDbCriteria();
  442. $criteria->addInCondition('class_id',$classIds);
  443. $classes = ClassModel::model()->findAll($criteria);
  444. unset($criteria);
  445. $result['backlog']=array();
  446. foreach ($classes as $class){
  447. $classNames[]=array(
  448. 'clazzId'=>$class['class_name'],
  449. 'clazzName'=>$class['class_name']
  450. );
  451. }
  452. $criteria = new CDbCriteria();
  453. $criteria->select = 'pdf_first_time,pdf_last_time,pdf_queue_time,queue_create_time,product_type,download_last_time,download_first_time,exam_id';
  454. $criteria->addInCondition('exam_id',$examIds);
  455. $criteria->order="pdf_last_time asc";
  456. $product=SProductProcessTime::model()->findAll($criteria);
  457. unset($criteria);
  458. $result=array();
  459. $downloadType=array();
  460. $productType=array();
  461. if($product){
  462. foreach ($product as $value){
  463. if(!isset($downloadType[$value['product_type']])){
  464. if($value['download_last_time']){
  465. $downloadType[$value['product_type']]=1; //已全部下载
  466. }else{
  467. $downloadType[$value['product_type']]=0; //未全部下载
  468. }
  469. }elseif($downloadType[$value['product_type']]==1 && !$value['download_last_time']){
  470. $downloadType[$value['product_type']]=0;
  471. }
  472. if(!isset($productType[$value['product_type']])){
  473. if($value['pdf_last_time']){
  474. $productType[$value['product_type']]=1; //已全部下载
  475. }else{
  476. $productType[$value['product_type']]=0; //未全部下载
  477. }
  478. }elseif($productType[$value['product_type']]==1 && !$value['pdf_last_time']){
  479. $productType[$value['product_type']]=0;
  480. }
  481. if(!isset($result[$value['product_type']])){
  482. $result[$value['product_type']]=array(
  483. 'create_start_time'=>$value['pdf_first_time'],
  484. 'create_end_time'=>$value['pdf_last_time'],
  485. 'student_count'=>1,
  486. 'download_first_time'=>$value['download_first_time'],
  487. 'download_last_time'=>$value['download_last_time'],
  488. 'signature'=>array(
  489. 'signature_begin_time'=>0,
  490. 'signature_end_time'=>0
  491. ),
  492. );
  493. }else{
  494. $result[$value['product_type']]['create_end_time']=$value['pdf_last_time'];
  495. $result[$value['product_type']]['student_count']++;
  496. if((!$result[$value['product_type']]['download_first_time'] || $value['download_first_time']< $result[$value['product_type']]['download_first_time']) && $value['download_first_time'] ){
  497. $result[$value['product_type']]['download_first_time']=$value['download_first_time'];
  498. }
  499. if((!$result[$value['product_type']]['download_last_time'] || $value['download_last_time']> $result[$value['product_type']]['download_last_time']) && $value['download_last_time'] ){
  500. $result[$value['product_type']]['download_last_time']=$value['download_last_time'];
  501. }
  502. if((!$result[$value['product_type']]['create_start_time'] || $value['pdf_first_time']< $result[$value['product_type']]['create_start_time']) && $value['pdf_first_time'] ){
  503. $result[$value['product_type']]['create_start_time']=$value['pdf_first_time'];
  504. }
  505. if((!$result[$value['product_type']]['create_end_time'] || $value['pdf_last_time']< $result[$value['product_type']]['create_end_time']) && $value['pdf_last_time'] ){
  506. $result[$value['product_type']]['create_end_time']=$value['pdf_last_time'];
  507. }
  508. }
  509. $productTypeClassCount[$value['product_type']][$value['exam_id']]=$value['exam_id'];
  510. }
  511. //签收
  512. foreach ($result as $type=>$item){
  513. if($productType[$type]==0){
  514. $result[$type]['create_end_time']=0;
  515. }
  516. if($downloadType[$type]==0){
  517. $result[$type]['download_last_time']=0;
  518. }
  519. $imsClass=array();
  520. foreach ($productTypeClassCount[$type] as $eid){
  521. $imsClass[]=$classExam[$eid];
  522. }
  523. $imsParam=array(
  524. 'businessId'=>$examGroupId,
  525. 'clazzList'=>$imsClass,
  526. 'productType'=>$this->signatureType[$type]
  527. );
  528. $http = http('order/deliver/coach/query/clazz/signature-time', 'POST', $this->authUsername,$imsParam);
  529. $response = formatResponse($http);
  530. if ($response['status']) {
  531. $result[$type]['signature']=array(
  532. 'signature_begin_time'=>$response['data']['beginTime'],
  533. 'signature_end_time'=>$response['data']['endTime'],
  534. );
  535. }else{
  536. $result[$type]['signature']=array(
  537. 'signature_begin_time'=>null,
  538. 'signature_end_time'=>null
  539. );
  540. }
  541. }
  542. }
  543. $this->returnMsg(1,'success',$result);
  544. }
  545. //产品班级生成详情,下载,签收
  546. public function actionProductClassDetail(){
  547. $examGroupId = Req::post("examGroupId");
  548. if(!$examGroupId || !is_numeric($examGroupId)){
  549. $this->returnMsg(0,'考试Id格式不正确');
  550. }
  551. $result=array();
  552. $examGroup=SExamGroup::model()->find("exam_group_id=:id",array(":id"=>$examGroupId));
  553. if(!$examGroup) $this->returnMsg(0,'考试Id不正确');
  554. $exam=Exam::model()->findAll("exam_group_id=:id",array(":id"=>$examGroupId));
  555. $examIds=array();
  556. $classIds=array();
  557. $classExam=array();
  558. foreach ($exam as $value){
  559. $examIds[]=$value['exam_id'];
  560. $classIds[]=$value['class_id'];
  561. $classExam[(string)$value['exam_id']]=$value['class_id'];
  562. }
  563. $criteria = new CDbCriteria();
  564. $criteria->addInCondition('class_id',$classIds);
  565. $classes = ClassModel::model()->findAll($criteria);
  566. unset($criteria);
  567. $classNames=array();
  568. foreach ($classes as $class){
  569. $classNames[(string)$class['class_id']]=$class['class_name'];
  570. $classParams[]=array(
  571. 'clazzId'=>$class['class_name'],
  572. 'clazzName'=>$class['class_name']
  573. );
  574. }
  575. $criteria = new CDbCriteria();
  576. $criteria->select = 'pdf_first_time,pdf_last_time,pdf_queue_time,queue_create_time,product_type,download_last_time,download_first_time,exam_id';
  577. $criteria->addInCondition('exam_id',$examIds);
  578. $criteria->order="pdf_last_time asc";
  579. $product=SProductProcessTime::model()->findAll($criteria);
  580. unset($criteria);
  581. $result=array();
  582. $typeStudentCount=0; //共需生成人数
  583. $typeConsuming=0; //耗时
  584. if($product){
  585. $productTypeClass=array();
  586. foreach ($product as $value){
  587. $productTypeClass[$value['product_type']][(string)$classExam[$value['exam_id']]]=$classExam[$value['exam_id']];
  588. if(!isset($result[$value['product_type']]['student_count'])){
  589. $result[$value['product_type']]['student_count']=1;
  590. }else{
  591. $result[$value['product_type']]['student_count']++;
  592. }
  593. if((!isset($result[$value['product_type']]['product_create_start_time']) || $value['pdf_first_time']<$result[$value['product_type']]['product_create_start_time']) && $value['pdf_first_time'] ){
  594. $result[$value['product_type']]['product_create_start_time']=$value['pdf_first_time'];
  595. }
  596. if((!isset($result[$value['product_type']]['product_create_end_time']) || $value['pdf_last_time']>$result[$value['product_type']]['product_create_end_time']) && $value['pdf_last_time']){
  597. $result[$value['product_type']]['product_create_end_time']=$value['pdf_last_time'];
  598. }
  599. if((!isset($result[$value['product_type']]['product_download_start_time']) || $value['download_first_time']<$result[$value['product_type']]['product_download_start_time']) && $value['download_first_time']){
  600. $result[$value['product_type']]['product_download_start_time']=$value['download_first_time'];
  601. }
  602. if((!isset($result[$value['product_type']]['product_download_end_time']) || $value['download_last_time']>$result[$value['product_type']]['product_download_end_time']) && $value['download_last_time']){
  603. $result[$value['product_type']]['product_download_end_time']=$value['download_last_time'];
  604. }
  605. if(!isset($result[$value['product_type']]['create'][(string)$classExam[$value['exam_id']]])){
  606. $result[$value['product_type']]['create'][(string)$classExam[$value['exam_id']]]=array(
  607. 'class_name'=>$classNames[(string)$classExam[$value['exam_id']]], //班级名称
  608. 'all_created'=>1, //默认全部生成
  609. 'product_create_time'=>0, //生成时间
  610. );
  611. }
  612. if(!isset($result[$value['product_type']]['download'][(string)$classExam[$value['exam_id']]])){
  613. $result[$value['product_type']]['download'][(string)$classExam[$value['exam_id']]]=array(
  614. 'class_name'=>$classNames[(string)$classExam[$value['exam_id']]], //班级名称
  615. 'all_downloaded'=>1, //默认全部下载
  616. 'product_download_time'=>0 //下载时间
  617. );
  618. }
  619. if($value['pdf_last_time']>$result[$value['product_type']]['create'][(string)$classExam[$value['exam_id']]]['product_create_time']){
  620. $result[$value['product_type']]['create'][(string)$classExam[$value['exam_id']]]['product_create_time']=$value['pdf_last_time'];
  621. }
  622. if(!$value['pdf_last_time']){
  623. $result[$value['product_type']]['create'][(string)$classExam[$value['exam_id']]]['all_created']=0; //未全部生成
  624. }
  625. if($value['download_last_time']>$result[$value['product_type']]['download'][(string)$classExam[$value['exam_id']]]['product_download_time']){
  626. $result[$value['product_type']]['download'][(string)$classExam[$value['exam_id']]]['product_download_time']=$value['download_last_time'];
  627. }
  628. if(!$value['download_last_time']){
  629. $result[$value['product_type']]['download'][(string)$classExam[$value['exam_id']]]['all_downloaded']=0; //未全部下载
  630. }
  631. }
  632. foreach ($result as $type =>$val){
  633. if($val['create']){
  634. foreach ($val['create'] as $item){
  635. if($item['all_created']==0){
  636. $result[$type]['product_create_end_time']=0;
  637. break;
  638. }
  639. }
  640. }
  641. if($val['download']){
  642. foreach ($val['download'] as $item){
  643. if($item['all_downloaded']==0){
  644. $result[$type]['product_download_end_time']=0;
  645. break;
  646. }
  647. }
  648. }
  649. }
  650. //签收
  651. foreach ($productTypeClass as $type=>$classes){
  652. $classTypeParams=array();
  653. foreach ($classes as $class){
  654. $classTypeParams[]=array(
  655. 'clazzId'=>$class,
  656. 'clazzName'=>$classNames[$class],
  657. );
  658. }
  659. $imsParam=array(
  660. 'businessId'=>$examGroupId,
  661. 'clazzReqList'=>$classTypeParams,
  662. 'productType'=>$this->signatureType[$type]
  663. );
  664. $http = http('order/deliver/coach/query/clazz-signature', 'POST', $this->authUsername,$imsParam);
  665. $response = formatResponse($http);
  666. if ($response['status'] && $response['data']) {
  667. $signStart=0;
  668. $signEnd=0;
  669. $notEnd=0;
  670. foreach ($response['data'] as $datum){
  671. if((!$signStart || $signStart>$datum['signatureTime']) && $datum['signatureTime']){
  672. $signStart=$datum['signatureTime'];
  673. }
  674. if(!$datum['signatureTime']){
  675. //有班级未签收
  676. $signEnd=0;
  677. $notEnd=1;
  678. }
  679. if((!$signEnd || $signEnd<$datum['signatureTime']) && !$notEnd && $datum['signatureTime']){
  680. $signEnd= $datum['signatureTime'];
  681. }
  682. $result[$type]['signature'][]=$datum;
  683. }
  684. $result[$type]['signature_begin_time']=$signStart;
  685. $result[$type]['signature_end_time']=$signEnd;
  686. }
  687. }
  688. //班级生成排序
  689. foreach ($result as $type =>$item){
  690. if(isset($item['create'])){
  691. $lastOrder = $this->_array_column($item['create'],'all_created');
  692. array_multisort($lastOrder,SORT_DESC,$result[$type]['create']);
  693. }
  694. if(isset($item['download'])){
  695. $lastOrder = $this->_array_column($item['download'],'all_downloaded');
  696. array_multisort($lastOrder,SORT_DESC,$result[$type]['download']);
  697. }
  698. if(isset($item['signature'])){
  699. $lastOrder = $this->_array_column($item['signature'],'signatureTime');
  700. array_multisort($lastOrder,SORT_DESC,$result[$type]['signature']);
  701. }
  702. }
  703. }
  704. $this->returnMsg(1,'success',$result);
  705. }
  706. function returnMsg($status = 0, $message = '', $data = false, $extendData = null)
  707. {
  708. header("Cache-Control:no-cache,no-store,max-age=0,must-revalidate");
  709. $msgData = array('status' => $status, 'message' => $message);
  710. if ($data !== false) {
  711. $msgData['data'] = $data;
  712. }
  713. if ($extendData) {
  714. $msgData['extend_data'] = $extendData;
  715. }
  716. exit(jsonEncode($msgData));
  717. }
  718. public function getProduct($examIds){
  719. $criteria = new CDbCriteria();
  720. $criteria->select = 'pdf_first_time,pdf_last_time,pdf_queue_time,queue_create_time,product_type,download_last_time,download_first_time,exam_id';
  721. $criteria->addInCondition('exam_id',$examIds);
  722. $criteria->order="pdf_last_time asc";
  723. $product=SProductProcessTime::model()->findAll($criteria);
  724. if(!$product) return null;
  725. unset($criteria);
  726. $productCreateStart=0; //是否开始生成
  727. $productAllCreated=1; //是否全部生成
  728. $productTypeCount=array(); //产品种类数量
  729. $startCreateTime=0; //开始生成时间
  730. $firstRecorder=array(); //第一条记录
  731. $lastRecorder=$product[count($product)-1]; //最后一条记录
  732. $firstDownload=0; //第一次下载时间
  733. $lastDownload=0; //最后一次下载时间
  734. $allDownload=1; //是否全部下载
  735. foreach ($product as $value){
  736. if($value['pdf_first_time']){
  737. $productCreateStart=1;
  738. if(!$startCreateTime || $startCreateTime>$value['pdf_first_time']){
  739. $startCreateTime=$value['pdf_first_time']; //开始生成时间
  740. $firstRecorder=$value;
  741. }
  742. }
  743. if($value['pdf_last_time']==0){
  744. $productAllCreated=0;
  745. }
  746. if($value['download_last_time']==0){
  747. $allDownload=0;
  748. }
  749. $productTypeClassCount[$value['exam_id']][$value['product_type']]=$value['product_type'];
  750. $productTypeCount[$value['product_type']]=$value['product_type'];
  751. if(!$firstDownload || ($firstDownload>$value['download_first_time'] && $value['download_first_time'])){
  752. $firstDownload=$value['download_first_time'];
  753. }
  754. if(!$lastDownload || ($lastDownload<$value['download_last_time'] && $value['download_last_time'])){
  755. $lastDownload=$value['download_last_time'];
  756. }
  757. }
  758. if(!$allDownload){
  759. $lastDownload=0;
  760. }
  761. $result=array();
  762. $result['student_count']=count($product);
  763. $result['product_create_start']=$productCreateStart;
  764. $queue=$this->sConn->createCommand("select pdf_queue_time,queue_create_time from product_process_time where exam_id in(".implode(',',$examIds).") and pdf_queue_time>0 order by html_start_time asc ")->queryRow();
  765. $result['queue_create_time']=(string)$queue['queue_create_time'];
  766. if(!$productCreateStart){
  767. if(time()>($queue['queue_create_time']+$queue['pdf_queue_time'])){
  768. $result['product_create_estimate']=0;
  769. }else{
  770. $result['product_create_estimate']=consuming(($queue['queue_create_time']+$queue['pdf_queue_time']),time()); //预计生成时间
  771. }
  772. }
  773. $result['product_create_start_time']=$startCreateTime;
  774. if($productAllCreated){
  775. $result['product_create_last']=$lastRecorder['pdf_last_time']; //最后一条生成时间
  776. $result['product_create_time_total']=consuming($lastRecorder['pdf_last_time'],$firstRecorder['pdf_first_time']); //耗时
  777. }
  778. $result['product_type']=array_values($productTypeCount); //产品种类
  779. $result['product_class_type']=$productTypeClassCount;
  780. $result['product_first_download_time']=$firstDownload;
  781. $result['product_last_download_time']=$lastDownload;
  782. //查询重置记录
  783. $criteria = new CDbCriteria();
  784. $criteria->select = 'exam_id';
  785. $criteria->addInCondition('exam_id',$examIds);
  786. $productReset=SProductResetLog::model()->find($criteria);
  787. if($productReset){
  788. $result['product_reset']=1;
  789. }else{
  790. $result['product_reset']=0;
  791. }
  792. return $result;
  793. }
  794. function _array_column(array $array, $column_key, $index_key=null){
  795. $result = array();
  796. foreach($array as $arr) {
  797. if(!is_array($arr)) continue;
  798. if(is_null($column_key)){
  799. $value = $arr;
  800. }else{
  801. $value = $arr[$column_key];
  802. }
  803. if(!is_null($index_key)){
  804. $key = $arr[$index_key];
  805. $result[$key] = $value;
  806. }else{
  807. $result[] = $value;
  808. }
  809. }
  810. return $result;
  811. }
  812. /*在线答题卡生成班级详情*/
  813. public function actionCardGenerate(){
  814. $examGroupId = Req::post("examGroupId");
  815. if(!$examGroupId || !is_numeric($examGroupId)){
  816. $this->returnMsg(0,'考试Id格式不正确');
  817. }
  818. $result=array();
  819. $examGroup=SExamGroup::model()->find("exam_group_id=:id",array(":id"=>$examGroupId));
  820. if(!$examGroup) $this->returnMsg(0,'考试Id不正确');
  821. $exam=Exam::model()->findAll("exam_group_id=:id",array(":id"=>$examGroupId));
  822. $examIds=array();
  823. $classIds=array();
  824. foreach ($exam as $value){
  825. $examIds[]=$value['exam_id'];
  826. $classIds[]=$value['class_id'];
  827. }
  828. $criteria = new CDbCriteria();
  829. $criteria->addInCondition('class_id',$classIds);
  830. $classes = ClassModel::model()->findAll($criteria);
  831. unset($criteria);
  832. foreach ($classes as $class){
  833. $classNames[(string)$class['class_id']]=$class['class_name'];
  834. }
  835. //生成时间
  836. $criteria = new CDbCriteria();
  837. $criteria->select = 'create_time';
  838. $criteria->addInCondition('exam_id',$examIds);
  839. $criteria->addCondition('answer_card_online_created = 1');
  840. $criteria->order="create_time asc";
  841. $studentCard=SStudentAnswerCardOnline::model()->find($criteria);
  842. if($studentCard){
  843. $result['generate_card_time']=$studentCard['create_time'];
  844. }
  845. //生成情况
  846. $model=new SStudentAnswerCardOnline();
  847. $generateData=$model->getTimeByExamId($examIds);
  848. $generateCount=array();
  849. if($generateData){
  850. foreach ($generateData as $item){
  851. $generateCount[$item['class_id']]=array(
  852. 'count'=>$item['count'],
  853. 'time'=>$item['create_time']
  854. );
  855. }
  856. }
  857. //获取班级考试的上传成绩
  858. $criteria = new CDbCriteria();
  859. $criteria->select= 'student_id,is_feedback,class_id';
  860. $criteria->addInCondition('exam_id',$examIds);
  861. $criteria->addCondition('is_del = 0');
  862. $student_paper_data = SStudentPaperRelation::model()->findAll($criteria);
  863. $classInfo=array();
  864. foreach ($student_paper_data as $datum){
  865. if(!isset($classInfo[$datum['class_id']])){
  866. $classInfo[$datum['class_id']]=array(
  867. 'all_student'=>0,
  868. 'generate_count'=>0,
  869. 'generate_time'=>0,
  870. 'class_name'=>$classNames[(string)$datum['class_id']],
  871. 'order'=>'9999999999'
  872. );
  873. }
  874. $classInfo[$datum['class_id']]['all_student']++;
  875. if(!$classInfo[$datum['class_id']]['generate_count'] && isset($generateCount[(string)$datum['class_id']])){
  876. $classInfo[$datum['class_id']]['generate_count'] =$generateCount[(string)$datum['class_id']]['count'];
  877. $classInfo[$datum['class_id']]['generate_time'] =$generateCount[(string)$datum['class_id']]['time'];
  878. $classInfo[$datum['class_id']]['order'] =$generateCount[(string)$datum['class_id']]['time'];
  879. $classInfo[$datum['class_id']]['date'] =date('Y-m-d H:i:s',$generateCount[(string)$datum['class_id']]['time']);
  880. }
  881. }
  882. $lastOrder = $this->_array_column($classInfo,'order');
  883. array_multisort($lastOrder,SORT_ASC,$classInfo);
  884. $result['class_list']=array_values($classInfo);
  885. $this->returnMsg(1,'success',$result);
  886. }
  887. /*在线答题卡打印班级详情*/
  888. public function actionCardPrint(){
  889. $examGroupId = Req::post("examGroupId");
  890. if(!$examGroupId || !is_numeric($examGroupId)){
  891. $this->returnMsg(0,'考试Id格式不正确');
  892. }
  893. $result=array();
  894. $examGroup=SExamGroup::model()->find("exam_group_id=:id",array(":id"=>$examGroupId));
  895. if(!$examGroup) $this->returnMsg(0,'考试Id不正确');
  896. $exam=Exam::model()->findAll("exam_group_id=:id",array(":id"=>$examGroupId));
  897. $examIds=array();
  898. $classIds=array();
  899. foreach ($exam as $value){
  900. $examIds[]=$value['exam_id'];
  901. $classIds[]=$value['class_id'];
  902. }
  903. $criteria = new CDbCriteria();
  904. $criteria->addInCondition('class_id',$classIds);
  905. $classes = ClassModel::model()->findAll($criteria);
  906. unset($criteria);
  907. $classInfo=array();
  908. foreach ($classes as $class){
  909. $classInfo[(string)$class['class_id']]=array(
  910. "class_name"=>$class['class_name'],
  911. "print_time"=>0,
  912. 'order'=>'9999999999'
  913. );
  914. $classNames[(string)$class['class_id']]=$class['class_name'];
  915. }
  916. $examProcess=SExamProcess::model()->findAll("exam_group_id=:id and action_type=9",array(':id'=>$examGroupId));
  917. if($examProcess){
  918. foreach ($examProcess as $item){
  919. if($item['class_id'] && isset($classInfo[(string)$item['class_id']])){
  920. $classInfo[$item['class_id']]['print_time']=$item['action_time'];
  921. $classInfo[$item['class_id']]['order'] =$item['action_time'];
  922. $classInfo[$item['class_id']]['date'] =date('Y-m-d H:i:s',$item['action_time']);
  923. }
  924. }
  925. }
  926. $lastOrder = $this->_array_column($classInfo,'order');
  927. array_multisort($lastOrder,SORT_ASC,$classInfo);
  928. $this->returnMsg(1,'success',array_values($classInfo));
  929. }
  930. }