123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- <?php
- class ProductexamController extends Controller
- {
- const PRODUCT_TYPE_WB = 1;
- const PRODUCT_TYPE_ZQB = 20;
- const PRODUCT_TYPE_METHOD = 31;
- static $productDesc = array(
- self::PRODUCT_TYPE_WB => '错题本',
- self::PRODUCT_TYPE_ZQB => '个性化学习宝',
- self::PRODUCT_TYPE_METHOD => '方法宝'
- );
- //产品班级页
- public function actionProduct()
- {
- $grade = Req::get("grade");
- $classId = Req::get("classId");
- $name = Req::get("name");
- $type = Req::get("type");
- if(!$type) self::responseMsg(0, '参数错误');
- $condition = array();
- if($name) $condition[] = "e.name like '%{$name}%'";
- if($grade) $condition[] = "c.grade = '{$grade}'";
- if($classId) $condition[] = "e.class_id = '{$classId}'";
- $condition[] = "eg.create_type in (0,1,2,3,5,6) and e.status=1 and cep.type={$type}";
- if (empty($grade)) {
- $grade = 'ALL';
- }
- $examProduct = new SExamProductStatus();
- $resultList = $examProduct->getProductList($condition,array('e.create_time desc'), $type);
- $printList = array();
- $productDesc = self::$productDesc;
- $desc = isset($productDesc[$type]) ? $productDesc[$type]: "";
- if($resultList["rs"]){
- foreach ($resultList['rs'] as $k=>$v) {
- $printList[$k] = $v;
- $printList[$k]['print_name'] = $v["exam_name"]. $desc;
- $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;
- }
- }
- $grade_class_array = array();
- if($grade) {
- $grade_class_data = $this->sConn->createCommand("select class_id,class_name from class where grade='{$grade}' and semester_id='{$this->semesterId}'")->queryAll();
- if ($grade_class_data) {
- foreach ($grade_class_data as $v) {
- $grade_class_array[$v['class_id']] = $v;
- }
- }
- }
- $data = array();
- $data['printList'] = $printList;
- $data['pages'] = $resultList['pager'];
- $data['page_total'] = $resultList['pager']->rowsCount;
- $data["printName"] = $name;
- $data["classes"] = $grade_class_array;
- $data["classId"] = $classId;
- $data["grade"] = $grade;
- $data['subjectId']=$this->subjectId;
- $data['type'] = $type;
- $data['desc'] = $desc;
- unset($resultList);
- $this->render('product',$data);
- }
- //产品学生页面
- public function actionProduct_stu(){
- $data = array();
- $sname = (string)Req::get("sname"); //学生名字
- $type = (int)Req::get("type"); //产品类型
- $examId = (string)Req::get("eid");
- $classId = (string)Req::get("cid");
- if(!$examId || !$classId || !$type){
- Yii::app()->jump->error('参数错误!');
- }
- //获取班级名称以及考试名称
- $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
- join class c on e.class_id = c.class_id where e.class_id = '{$classId}' and e.exam_id = '{$examId}'";
- $names = $this->sConn->createCommand($sql)->queryRow();
- if(!$names){
- $names = array();
- $names['name'] = '';
- $names['class_name'] = '';
- $names['grade'] = 0;
- }else{
- $data['name'] = isset($names['name']) && isset($names['class_name'])?$names['class_name'].$names['name']:'';
- }
- $sql = "select student_id,is_create_pdf from exam_product_status where product_type ='{$type}' and exam_id = '{$examId}'";
- $relateStudent = $this->sConn->createCommand($sql)->queryAll();
- $studentIds = array();
- $stuIsPdf = array();
- if($relateStudent){
- foreach ($relateStudent as $studentInfo) {
- $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_create_pdf'];
- }
- }
- $allStudent = SStudentClassRelation::model()->getStudentInfoByClassId($classId, $sname);
- $i = 1;
- foreach ($allStudent as $v) {
- $studentIds[] = (string)$v['student_id'];
- $data['list'][$i]['stu_id'] = (string)$v['student_id'];
- $data['list'][$i]['stu_name'] = $v['realname'];
- $data['list'][$i]['name'] = $names['class_name'] . $names['name'];
- $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$v['student_id']]) ? $stuIsPdf[(string)$v['student_id']] : 0;
- $i++;
- }
- $Sem=new SSemester();
- $code= $Sem->conn->createQuery()
- ->from('semester')
- ->where("semester_id = '".$names['semester_id']."'")
- ->limit(1)
- ->query()
- ->read();
- $intarr=array(
- "schoolId"=>$this->schoolId,
- "clazzId"=>$names['class_id'],
- "semester"=>$code['refer_code'],
- "grade"=>$names['grade'],
- "students"=>$studentIds,
- "examTime"=>$names['add_time'],
- "classify"=>$type,
- "subject"=>$this->subjectId
- );
- $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
- //TODO 订单
- // if(!$rs){
- // Yii::app()->jump->error("接口错误");
- // }
- // if($rs->errCode!="00"){
- // Yii::app()->jump->error($rs->errMsg);
- // }
- if(!empty($rs->data)){
- $data['limitstu']=$rs->data;
- }
- $productDesc = self::$productDesc;
- $data['examId'] = $examId;
- $data['classId'] = $classId;
- $data['sname'] = $sname;
- $data['type'] = $type;
- $data['desc'] = isset($productDesc[$type]) ? $productDesc[$type]: "";
- $this->render('product_stu',$data);
- }
- //FIXME 重置方法宝教师讲案
- public function actionResetMethodPdf()
- {
- $examId = (string)Req::get("examId"); //学生名字
- $type = (int)Req::get("type"); //产品类型
- if(!$examId || !$type){
- Yii::app()->jump->error('参数错误!');
- }
- $this->sConn->createCommand()->update("exam_teaching_product", array("is_create_pdf" => 0,"pdf_path"=>""), "exam_id = '{$examId}' and product_type={$type}");
- echo json_encode(array('status'=>1));exit;
- }
- //FIXME 方法宝教师讲案
- public function actionMethod_pdf(){
- $this->layout = false;
- set_time_limit (300);
- ini_set('memory_limit', '300M');
- $examId = (string)Req::get("examId");
- $productType = (string)Req::get("productType");
- require_once('TeachingMethod.php');
- $teachingPhysicsObj = new TeachingMethod($this);
- $result = $teachingPhysicsObj->getTeachingPdf($this->schoolId, $examId, $productType, $this->subjectId, 0, 1);
- if($result['pdf_url']){
- header('Content-Description: File Transfer');
- header('Content-Type: application/vnd.android.package-archive');
- header('Content-Disposition: attachment; filename=' . $this->filter_file_name(!empty($result['file_name'])?$result['file_name']:"方法宝教学宝") . ".pdf");
- header('Content-Transfer-Encoding: binary');
- header('Expires: 0');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Pragma: public');
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $result['pdf_url']);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
- curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) {
- echo $buffer;
- return strlen($buffer);
- });
- curl_exec($ch);
- curl_close($ch);
- }else{
- Yii::app()->jump->error($result['error']);
- }
- exit();
- }
- public function filter_file_name($filename){
- return str_replace(array(',','.','/','?','!','@','#','$','%','^','&','*','(',')','-','+','{','}','[',']',':',';','"','`','~'),
- array(',','。',' ','?','!',' ',' ',' ',' ','·',' ',' ','(',')','-','+','【','】','【','】',':',';','“',' ',' ')
- , $filename);
- }
- }
|