HistoryProductController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <?php
  2. /**
  3. * 打印过期产品
  4. * User: Administrator
  5. * Date: 2020/5/20 0020
  6. * Time: 18:07
  7. */
  8. class HistoryProductController extends Controller
  9. {
  10. /**
  11. * 显示出过期有学生下订单的产品列表
  12. */
  13. public function actionViewProduct()
  14. {
  15. $data = $error = array();
  16. $data['status'] = 0;
  17. $data['message'] = '';
  18. $data['data'] = array();
  19. $printType = Req::post("printType");
  20. $productTypeArr = array('wtb'=>1, 'isp'=>2, 'studytrend'=>3,'third_wb'=>1,'third_isp'=>3);
  21. $subjectId = Yii::app()->session['session_duoxueke_subject_id']?Yii::app()->session['session_duoxueke_subject_id']:3;
  22. if(in_array($subjectId,$this->mathSubjectId)){
  23. $exam_subject_id = $this->mathSubjectId;
  24. }else{
  25. $exam_subject_id = array($subjectId);
  26. }
  27. $examNum = 0;//可生成的考试数量
  28. $studentNum = 0;//可生成的学生数量
  29. $examAddTime = array();//考试发送打印时间
  30. if (!isset($productTypeArr[$printType])) {
  31. $error[] = '产品类型参数不正确';
  32. }
  33. //获取本学期7天外的考试
  34. if (!$error) {
  35. $time = time() - 7 * 24 * 3600;
  36. $criteria = new CDbCriteria();
  37. $criteria->select= 'exam_id,exam_group_id,class_id,is_backlog,subject_id';
  38. $criteria->addCondition('`semester_id` = '.$this->semesterId);
  39. $criteria->addInCondition('subject_id',$exam_subject_id);
  40. $criteria->addCondition('`status` = 1');
  41. $criteria->addCondition('complete_time < '.$time);
  42. $result = Exam::model()->findAll($criteria);
  43. if (!$result) {
  44. $error[] = '没有需要处理的考试';
  45. }
  46. }
  47. //判断有没有发送打印
  48. if (!$error) {
  49. $examInfo = array();
  50. foreach ($result as $value) {
  51. $examInfo[$value->exam_id] = array(
  52. 'is_backlog'=>$value->is_backlog,
  53. 'class_id'=>$value->class_id,
  54. 'exam_group_id'=>$value->exam_group_id,
  55. 'subject_id'=>$value->subject_id,
  56. );
  57. }
  58. unset($result);
  59. $examIds = array_keys($examInfo);
  60. $criteria = new CDbCriteria();
  61. $criteria->select= 'exam_id';
  62. $criteria->addInCondition('exam_id',$examIds);
  63. $criteria->addCondition('`type` = '.$productTypeArr[$printType]);
  64. $result = ClassExamPrinter::model()->findAll($criteria);
  65. if ($result) {
  66. foreach ($result as $value) {
  67. if (isset($examInfo[$value->exam_id])) {
  68. unset($examInfo[$value->exam_id]);
  69. }
  70. }
  71. }
  72. unset($result);
  73. if (!$examInfo) {
  74. $error[] = '没有需要处理的考试';
  75. }
  76. }
  77. //获取发送打印时间
  78. if (!$error) {
  79. $examIds = array_keys($examInfo);
  80. $criteria = new CDbCriteria();
  81. $criteria->select= 'exam_id,add_time';
  82. $criteria->addInCondition('exam_id',$examIds);
  83. $criteria->addCondition('`type` = 0');
  84. $result = ClassExamPrinter::model()->findAll($criteria);
  85. if ($result) {
  86. foreach ($result as $value) {
  87. if (isset($examInfo[$value->exam_id])) {
  88. $examAddTime[$value->exam_id] = $value->add_time;
  89. }
  90. }
  91. }
  92. }
  93. //过滤标注
  94. if (!$error) {
  95. $examIds = array_keys($examInfo);
  96. $criteria = new CDbCriteria();
  97. $criteria->select= 'exam_id';
  98. $criteria->addInCondition('exam_id',$examIds);
  99. $criteria->addCondition('`is_labelled` = 1');
  100. $result = SPaper::model()->findAll($criteria);
  101. $_examInfo = array();
  102. if ($result) {
  103. foreach ($result as $value) {
  104. if (isset($examInfo[$value->exam_id])) {
  105. $_examInfo[$value->exam_id] = $examInfo[$value->exam_id];
  106. }
  107. }
  108. }
  109. if ($_examInfo) {
  110. $examInfo = $_examInfo;
  111. unset($_examInfo);
  112. }else{
  113. $error[] = '没有需要处理的考试';
  114. }
  115. }
  116. //导入成绩和线下阅卷必须点代办
  117. if (!$error) {
  118. $examGroupIds = array();
  119. $offlineExam = array();//线下考试
  120. $importScoreExam = array();//导入成绩的考试
  121. foreach ($examInfo as $value) {
  122. $examGroupIds[$value['exam_group_id']] = $value['exam_group_id'];
  123. }
  124. if ($examGroupIds) {
  125. $examGroupIds = array_keys($examGroupIds);
  126. $criteria = new CDbCriteria();
  127. $criteria->select= 'exam_group_id,import_score_type,mark_type';
  128. $criteria->addInCondition('exam_group_id',$examGroupIds);
  129. // $criteria->addCondition('`mark_type` = 0');
  130. $result = SExamGroup::model()->findAll($criteria);
  131. if ($result) {
  132. foreach ($result as $value) {
  133. if ($value->mark_type == 0) {
  134. $offlineExam[$value->exam_group_id] = $value->exam_group_id;
  135. }
  136. if ($value->import_score_type == 3) {
  137. $importScoreExam[$value->exam_group_id] = $value->exam_group_id;
  138. }
  139. }
  140. }
  141. }
  142. //删除线下阅卷没点代办
  143. foreach ($examInfo as $examId => $value) {
  144. if ((isset($offlineExam[$value['exam_group_id']]) && $value['is_backlog'] == 0) || (isset($importScoreExam[$value['exam_group_id']]) && $value['is_backlog'] == 0)) {
  145. unset($examInfo[$examId]);
  146. }
  147. }
  148. if (!$examInfo) {
  149. $error[] = '没有需要处理的考试';
  150. }
  151. }
  152. //过滤没下订单的考试
  153. if (!$error) {
  154. foreach ($examInfo as $examId => $value) {
  155. $classId = $value['class_id'];
  156. $semester=new SSemester();
  157. $nowsem = $semester->getCurrentSemester();
  158. $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$classId));
  159. //考试关联的学生
  160. $criteria = new CDbCriteria();
  161. $criteria->select= 'student_id';
  162. $criteria->addCondition('`exam_id` = '.$examId);
  163. $result = SStudentPaperRelation::model()->findAll($criteria);
  164. $studentsIds = $this->getColumns($result, 'student_id');
  165. unset($result);
  166. $orderStudentIds = array();
  167. $errorMsg = '';
  168. if ($studentsIds) {
  169. if(in_array($value['subject_id'],$this->mathSubjectId)){
  170. $int_subject_id = 3;
  171. }else{
  172. $int_subject_id = $value['subject_id'];
  173. }
  174. $intarr=array(
  175. "schoolId"=>$this->schoolId,
  176. "clazzId"=>$classId,
  177. "semester"=>$nowsem['refer_code'],
  178. "grade"=>$classinfo['grade'],
  179. "students"=>$studentsIds,
  180. "examTime"=>isset($examAddTime[$examId])?$examAddTime[$examId]:0,
  181. "classify"=>$productTypeArr[$printType],
  182. "subject"=>$int_subject_id,
  183. );
  184. list($orderStudentIds,$errorMsg) = $this->getStuOrder($intarr);
  185. if ($errorMsg) {
  186. $error[] = $errorMsg;
  187. }
  188. }
  189. if (!$orderStudentIds) {
  190. unset($examInfo[$examId]);
  191. }else{
  192. $examNum += 1;
  193. $studentNum += count($orderStudentIds);
  194. }
  195. }
  196. if (!$examInfo) {
  197. $error[] = '没有需要处理的考试';
  198. }
  199. }
  200. //插入数据
  201. if (!$error) {
  202. $time = time();
  203. $value_arr = array();
  204. foreach ($examInfo as $examId => $value) {
  205. $value_arr[] = "({$value['class_id']},{$examId},{$productTypeArr[$printType]},0,0,0,{$time},{$time})";
  206. }
  207. $sql = "insert into class_exam_printer (class_id,exam_id,`type`,is_print,is_print_online,is_checked,print_time,add_time) values ".implode(',',$value_arr);
  208. $dbConn = ClassExamPrinter::model()->getDbConnection();
  209. $bool = $dbConn->createCommand($sql)->execute();
  210. if ($bool === false) {
  211. $error[] = '操作失败';
  212. }
  213. }
  214. if (!$error) {
  215. $data['status'] = 1;
  216. $data['data'] = array(
  217. 'exam_num' => $examNum,
  218. 'student_num' => $studentNum,
  219. );
  220. }else{
  221. $data['message'] = implode(PHP_EOL, $error);
  222. }
  223. exit(json_encode($data));
  224. }
  225. /**
  226. * 获取学生是否有订单
  227. * @param $intarr
  228. * @param $stuids
  229. */
  230. protected function getStuOrder($intarr){
  231. $msg = '';
  232. $stuids = array();
  233. $basic = imsBasicAuth($this->schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]);
  234. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr), $basic));
  235. if (!$rs) {
  236. $msg = '订单接口错误';
  237. }else{
  238. if (!empty($rs->data)) {
  239. $stuids = $rs->data;
  240. }
  241. }
  242. return array($stuids,$msg);
  243. }
  244. protected function getColumns($obj,$key)
  245. {
  246. $rs = array();
  247. if ($obj) {
  248. foreach ($obj as $_obj) {
  249. if (isset($_obj->$key)) {
  250. $_key = (string)$_obj->$key;
  251. $rs[$_key] = $_key;
  252. }
  253. }
  254. }
  255. if ($rs) {
  256. $rs = array_values($rs);
  257. }
  258. return $rs;
  259. }
  260. }