ProductexamController.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. class ProductexamController extends Controller
  3. {
  4. const PRODUCT_TYPE_WB = 1;
  5. const PRODUCT_TYPE_ZQB = 20;
  6. const PRODUCT_TYPE_METHOD = 31;
  7. static $productDesc = array(
  8. self::PRODUCT_TYPE_WB => '错题本',
  9. self::PRODUCT_TYPE_ZQB => '个性化学习宝',
  10. self::PRODUCT_TYPE_METHOD => '方法宝'
  11. );
  12. //产品班级页
  13. public function actionProduct()
  14. {
  15. $grade = Req::get("grade");
  16. $classId = Req::get("classId");
  17. $name = Req::get("name");
  18. $type = Req::get("type");
  19. if(!$type) self::responseMsg(0, '参数错误');
  20. $condition = array();
  21. if($name) $condition[] = "e.name like '%{$name}%'";
  22. if($grade) $condition[] = "c.grade = '{$grade}'";
  23. if($classId) $condition[] = "e.class_id = '{$classId}'";
  24. $condition[] = "eg.create_type in (0,1,2,3,5,6) and e.status=1 and cep.type={$type}";
  25. if (empty($grade)) {
  26. $grade = 'ALL';
  27. }
  28. $examProduct = new SExamProductStatus();
  29. $resultList = $examProduct->getProductList($condition,array('e.create_time desc'), $type);
  30. $printList = array();
  31. $productDesc = self::$productDesc;
  32. $desc = isset($productDesc[$type]) ? $productDesc[$type]: "";
  33. if($resultList["rs"]){
  34. foreach ($resultList['rs'] as $k=>$v) {
  35. $printList[$k] = $v;
  36. $printList[$k]['print_name'] = $v["exam_name"]. $desc;
  37. $printList[$k]['is_cloud_print'] = Yii::app()->cache->getValue(sprintf("cloud_print_task:%s:%s:%s:%s", $this->schoolId,$v['class_id'],$v['exam_id'],$type)) ? 1 : 0;
  38. }
  39. }
  40. $grade_class_array = array();
  41. if($grade) {
  42. $grade_class_data = $this->sConn->createCommand("select class_id,class_name from class where grade='{$grade}' and semester_id='{$this->semesterId}'")->queryAll();
  43. if ($grade_class_data) {
  44. foreach ($grade_class_data as $v) {
  45. $grade_class_array[$v['class_id']] = $v;
  46. }
  47. }
  48. }
  49. $data = array();
  50. $data['printList'] = $printList;
  51. $data['pages'] = $resultList['pager'];
  52. $data['page_total'] = $resultList['pager']->rowsCount;
  53. $data["printName"] = $name;
  54. $data["classes"] = $grade_class_array;
  55. $data["classId"] = $classId;
  56. $data["grade"] = $grade;
  57. $data['subjectId']=$this->subjectId;
  58. $data['type'] = $type;
  59. $data['desc'] = $desc;
  60. unset($resultList);
  61. $this->render('product',$data);
  62. }
  63. //产品学生页面
  64. public function actionProduct_stu(){
  65. $data = array();
  66. $sname = (string)Req::get("sname"); //学生名字
  67. $type = (int)Req::get("type"); //产品类型
  68. $examId = (string)Req::get("eid");
  69. $classId = (string)Req::get("cid");
  70. if(!$examId || !$classId || !$type){
  71. Yii::app()->jump->error('参数错误!');
  72. }
  73. //获取班级名称以及考试名称
  74. $sql = "select e.name,c.class_name,c.grade,e.class_id,p.add_time,e.semester_id from exam e join class_exam_printer p on p.exam_id=e.exam_id
  75. join class c on e.class_id = c.class_id where e.class_id = '{$classId}' and e.exam_id = '{$examId}'";
  76. $names = $this->sConn->createCommand($sql)->queryRow();
  77. if(!$names){
  78. $names = array();
  79. $names['name'] = '';
  80. $names['class_name'] = '';
  81. $names['grade'] = 0;
  82. }else{
  83. $data['name'] = isset($names['name']) && isset($names['class_name'])?$names['class_name'].$names['name']:'';
  84. }
  85. $sql = "select student_id,is_create_pdf from exam_product_status where product_type ='{$type}' and exam_id = '{$examId}'";
  86. $relateStudent = $this->sConn->createCommand($sql)->queryAll();
  87. $studentIds = array();
  88. $stuIsPdf = array();
  89. if($relateStudent){
  90. foreach ($relateStudent as $studentInfo) {
  91. $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_create_pdf'];
  92. }
  93. }
  94. $allStudent = SStudentClassRelation::model()->getStudentInfoByClassId($classId, $sname);
  95. $i = 1;
  96. foreach ($allStudent as $v) {
  97. $studentIds[] = (string)$v['student_id'];
  98. $data['list'][$i]['stu_id'] = (string)$v['student_id'];
  99. $data['list'][$i]['stu_name'] = $v['realname'];
  100. $data['list'][$i]['name'] = $names['class_name'] . $names['name'];
  101. $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$v['student_id']]) ? $stuIsPdf[(string)$v['student_id']] : 0;
  102. $i++;
  103. }
  104. $Sem=new SSemester();
  105. $code= $Sem->conn->createQuery()
  106. ->from('semester')
  107. ->where("semester_id = '".$names['semester_id']."'")
  108. ->limit(1)
  109. ->query()
  110. ->read();
  111. $intarr=array(
  112. "schoolId"=>$this->schoolId,
  113. "clazzId"=>$names['class_id'],
  114. "semester"=>$code['refer_code'],
  115. "grade"=>$names['grade'],
  116. "students"=>$studentIds,
  117. "examTime"=>$names['add_time'],
  118. "classify"=>$type,
  119. "subject"=>$this->subjectId
  120. );
  121. $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
  122. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
  123. //TODO 订单
  124. // if(!$rs){
  125. // Yii::app()->jump->error("接口错误");
  126. // }
  127. // if($rs->errCode!="00"){
  128. // Yii::app()->jump->error($rs->errMsg);
  129. // }
  130. if(!empty($rs->data)){
  131. $data['limitstu']=$rs->data;
  132. }
  133. $productDesc = self::$productDesc;
  134. $data['examId'] = $examId;
  135. $data['classId'] = $classId;
  136. $data['sname'] = $sname;
  137. $data['type'] = $type;
  138. $data['desc'] = isset($productDesc[$type]) ? $productDesc[$type]: "";
  139. $this->render('product_stu',$data);
  140. }
  141. //FIXME 重置方法宝教师讲案
  142. public function actionResetMethodPdf()
  143. {
  144. $examId = (string)Req::get("examId"); //学生名字
  145. $type = (int)Req::get("type"); //产品类型
  146. if(!$examId || !$type){
  147. Yii::app()->jump->error('参数错误!');
  148. }
  149. $this->sConn->createCommand()->update("exam_teaching_product", array("is_create_pdf" => 0,"pdf_path"=>""), "exam_id = '{$examId}' and product_type={$type}");
  150. echo json_encode(array('status'=>1));exit;
  151. }
  152. //FIXME 方法宝教师讲案
  153. public function actionMethod_pdf(){
  154. $this->layout = false;
  155. set_time_limit (300);
  156. ini_set('memory_limit', '300M');
  157. $examId = (string)Req::get("examId");
  158. $productType = (string)Req::get("productType");
  159. require_once('TeachingMethod.php');
  160. $teachingPhysicsObj = new TeachingMethod($this);
  161. $result = $teachingPhysicsObj->getTeachingPdf($this->schoolId, $examId, $productType, $this->subjectId, 0, 1);
  162. if($result['pdf_url']){
  163. header('Content-Description: File Transfer');
  164. header('Content-Type: application/vnd.android.package-archive');
  165. header('Content-Disposition: attachment; filename=' . $this->filter_file_name(!empty($result['file_name'])?$result['file_name']:"方法宝教学宝") . ".pdf");
  166. header('Content-Transfer-Encoding: binary');
  167. header('Expires: 0');
  168. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  169. header('Pragma: public');
  170. $ch = curl_init();
  171. curl_setopt($ch, CURLOPT_URL, $result['pdf_url']);
  172. curl_setopt($ch, CURLOPT_HEADER, 0);
  173. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  174. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
  175. curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) {
  176. echo $buffer;
  177. return strlen($buffer);
  178. });
  179. curl_exec($ch);
  180. curl_close($ch);
  181. }else{
  182. Yii::app()->jump->error($result['error']);
  183. }
  184. exit();
  185. }
  186. public function filter_file_name($filename){
  187. return str_replace(array(',','.','/','?','!','@','#','$','%','^','&','*','(',')','-','+','{','}','[',']',':',';','"','`','~'),
  188. array(',','。',' ','?','!',' ',' ',' ',' ','·',' ',' ','(',')','-','+','【','】','【','】',':',';','“',' ',' ')
  189. , $filename);
  190. }
  191. }