123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690 |
- <?php
- /**
- *
- * 专题宝
- *
- */
- class SpecialController extends Controller
- {
- //产品内容 关联方法配置id
- const METHOD_CONFIG_ID_TEST = 276;
- //const METHOD_CONFIG_ID_TEST = 303;
- const METHOD_CONFIG_ID_PROD = 276;
- /**
- * 产品列表
- */
- public function actionIndex()
- {
- Url::clean();
- $data = array();
- $printName = Req::get("name");
- $classId = Req::get("classId");
- $newCondition=array();
- $newCondition[] = 'g.product_type=' . ProductDownload::PRODUCT_TYPE_SPECIAL;
- if ($printName) {
- $newCondition[] = 'p.name like "%' . $printName . '%"';
- }
- if ($classId) {
- $newCondition[] = 'p.class_id=' . $classId;
- }
- $newCondition[] = "p.semester_id = '{$this->semesterId}'";
- $magicWordModel = new SGeneralProductSetting();
- $resultList = $magicWordModel->getList($newCondition, array('p.create_time desc'), 9);
- $printList = array();
- if ($resultList["rs"]) {
- foreach ($resultList['rs'] as $k => $v) {
- $printList[$k] = $v;
- $printList[$k]['is_cloud_print'] = Yii::app()->cache->getValue(sprintf("cloud_print_task:general_product:%s:%s:%s", $this->schoolId,$v['class_id'],$v['gp_id']));
- }
- }
- $type = ProductDownload::PRODUCT_TYPE_SPECIAL;
- $productDesc = ProductDownload::$desc;
- $desc = isset($productDesc[$type]) ? $productDesc[$type]: "";
- $classes = $this->schoolManager->getClasses(3);
- $data['pages'] = $resultList['pager'];
- $data['page_total'] = $resultList['pager']->rowsCount;
- $data['printList'] = $printList;
- $data["printName"] = $printName;
- $data["classes"] = $classes;
- $data["classId"] = $classId;
- $data["grade"] = 3;
- $data['printType'] = 'special';
- $data['subjectId'] = $this->subjectId;
- $data['desc'] = $desc;
- $data['type'] = $type;
- // debug($printList);
- $this->render('index', $data);
- }
- /**
- * 学生列表
- */
- public function actionStu()
- {
- $data = array();
- $sname = (string)Req::get("sname"); //学生名字
- $gpId = (string)Req::get("gp_id");
- if (!$gpId) {
- Yii::app()->jump->error('参数错误!');
- }
- //获取班级名称以及产品名称
- $sql = "select g.name,c.class_name,g.class_id,g.create_time,g.semester_id from general_product g join class c on g.class_id = c.class_id where g.gp_id = '{$gpId}'";
- $names = $this->sConn->createCommand($sql)->queryRow();
- if (empty($names)) {
- Yii::app()->jump->error('数据错误!');
- }
- $names['grade'] = 3;
- $data['name'] = isset($names['name']) && isset($names['class_name']) ? $names['class_name'] . $names['name'] : '';
- $sql = "select student_id,is_create_pdf from general_product_student where gp_id = '{$gpId}'";
- $relateStudent = $this->sConn->createCommand($sql)->queryAll();
- $studentIds = array();
- $stuIsPdf = array();
- if ($relateStudent) {
- foreach ($relateStudent as $studentInfo) {
- $studentIds[] = (string)$studentInfo['student_id'];
- $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_create_pdf'];
- }
- }
- if ($studentIds) {
- $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字
- if ($studentNames) {
- if ($sname) {
- $i = 1;
- foreach ($studentNames as $k => $v) {
- if (strpos($v, $sname) !== false) {
- $data['list'][$i]['stu_id'] = (string)$k;
- $data['list'][$i]['stu_name'] = $v;
- $data['list'][$i]['name'] = $names['class_name'] . $v . $names['name'];
- $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k]) ? $stuIsPdf[(string)$k] : 0;
- $i++;
- }
- }
- } else {
- $i = 1;
- foreach ($studentNames as $k => $v) {
- $data['list'][$i]['stu_id'] = (string)$k;
- $data['list'][$i]['stu_name'] = $v;
- $data['list'][$i]['name'] = $names['class_name'] . $v . $names['name'];
- $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k]) ? $stuIsPdf[(string)$k] : 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['create_time'],
- "classify" => 31,
- "subject" => 3
- );
- $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));
- if (!$rs) {
- Yii::app()->jump->error("接口错误");
- }
- if ($rs->errCode != "00") {
- Yii::app()->jump->error($rs->errMsg);
- }
- if (!empty($rs->data)) {
- $data['limitstu'] = $rs->data;
- }
- $data['gp_id'] = $gpId;
- $data['class_id'] = $names['class_id'];
- $data['sname'] = $sname;
- $data['type'] = ProductDownload::PRODUCT_TYPE_SPECIAL;
- $data['printType'] = 'general_product';
- $this->render('stu', $data);
- }
- /**
- * 专题宝设置
- */
- public function actionSetting()
- {
- $rs = $this->apiPost('/product/studentProductMenu', array(
- 'product_id' => 17
- ));
- if ($rs->status != 1 && !empty($rs->error)) {
- Yii::app()->jump->error($rs->error);
- }
- //顶级节点即专题数据
- $data = array();
- if ($rs->data) {
- $data['topNode'] = $rs->data;
- } else {
- Yii::app()->jump->error('brain接口异常!');
- }
- $this->render('setting', $data);
- }
- //获取专题下讲列表和试卷列表
- public function actionAjaxSpecialChild()
- {
- $pcId = (string)Req::post("pc_id");
- if (!$pcId) {
- Yii::app()->jump->error('参数错误!');
- }
- $rs = $this->apiPost('/product/studentProductMenu', array(
- 'product_id' => 17
- ));
- if ($rs->status != 1 && !empty($rs->error)) {
- echo json_encode(array("status" => 0, "message" => $rs->error));
- exit();
- }
- $lectureList = array();
- if ($rs->data) {
- foreach ($rs->data as $item) {
- if ($item->pc_id == $pcId) {
- $lectureList = $item->child;
- }
- }
- }
- $paper = $this->apiPost('/all_content/detail', array(
- 'catalogIds' => array($pcId)
- ));
- if ($paper->status != 1 && !empty($paper->error)) {
- echo json_encode(array("status" => 0, "message" => $paper->error));
- exit();
- }
- $paperList = array();
- if($paper->data) {
- foreach ($paper->data as $item){
- if($item->paper_id){
- array_push($paperList,array('paper_id'=>$item->paper_id,'paper_name'=>isset($item->paper_name)?$item->paper_name:"试卷".$item->paper_id));
- }
- }
- }
- echo json_encode(array('status' => 1, 'data' => array('lectureList' => $lectureList,'paperList'=>$paperList)));
- exit;
- }
- //获取每一讲下面方法列表
- public function actionAjaxMethod()
- {
- $pcId = (string)Req::post("pc_id");
- if (!$pcId) {
- Yii::app()->jump->error('参数错误!');
- }
- $rs = $this->apiPost('/all_content/detail', array(
- 'catalogIds' => array($pcId)
- ));
- if ($rs->status != 1 && !empty($rs->error)) {
- echo json_encode(array("status" => 0, "message" => $rs->error));
- exit();
- }
- $methodConfigId = YII_ENV == 'pro' || YII_ENV == 'production' ? self::METHOD_CONFIG_ID_PROD : self::METHOD_CONFIG_ID_TEST;
- $methodList = array();
- if ($rs->data) {
- foreach ($rs->data as $item) {
- if ($item->column_id == $methodConfigId) {
- array_push($methodList, array('method_id' => $item->tag_extend_id, 'method_name' => $item->tag_extend_name));
- }
- }
- }
- echo json_encode(array('status' => 1, 'data' => array('methodList' => $methodList)));
- exit;
- }
- private function getMethodList($pcId){
- $rs = $this->apiPost('/all_content/detail', array(
- 'catalogIds' => array($pcId)
- ));
- if ($rs->status != 1 && !empty($rs->error)) {
- echo json_encode(array("status" => 0, "message" => $rs->error));
- exit();
- }
- $methodConfigId = YII_ENV == 'pro' || YII_ENV == 'production' ? self::METHOD_CONFIG_ID_PROD : self::METHOD_CONFIG_ID_TEST;
- $methodList = array();
- if ($rs->data) {
- foreach ($rs->data as $item) {
- if ($item->column_id == $methodConfigId) {
- array_push($methodList, array('method_id' => $item->tag_extend_id, 'method_name' => $item->tag_extend_name));
- }
- }
- }
- return $methodList;
- }
- /**
- * 生成设置保存
- */
- public function actionAjaxSaveSetting()
- {
- $error = array();
- if (!Yii::app()->request->isAjaxRequest OR !Yii::app()->request->isPostRequest) {
- $error[] = '错误的来源!';
- } else {
- $grade = (int)Req::post('grade');
- $unitIds = (array)Req::post('unitIds');
- $specialIds = (array)Req::post('specialIds');
- $createType = (int)Req::post('createType');
- $isAnswerMerge = (int)Req::post('isAnswerMerge');
- //$trainPushType = (int)Req::post('trainPushType');
- $classIds = (array)Req::post('selectClassIds');
- $names = (array)Req::post('names');
- $specialNames = (array)Req::post('specialNames');
- $specialNodeId = 0;
- $paperIds = (array)Req::post('paperIds');
- $paperNames = (array)Req::post('paperNames');
- $pcIds = array();
- $existMethodIds = array();
- if ($createType == 1) {
- foreach ($specialIds as $key => $specialId) {
- $specialNodeId = $specialId;
- //array_push($pcIds, array('pc_id' => $specialId, 'pc_name' => $specialNames[$key], 'parent_id' => 0, 'children' => array()));
- $rs = $this->apiPost('/product/studentProductMenu', array(
- 'product_id' => 17
- ));
- //专题下的讲列表
- if ($rs->data) {
- foreach ($rs->data as $item) {
- if ($item->pc_id == $specialId) {
- $lectureList = $item->child;
- if($lectureList) {
- foreach ($lectureList as $lecture) {
- $methodList = $this->getMethodList($lecture->pc_id);
- $_methodIds = _array_column($methodList,'method_id');
- $methodIds = array();
- foreach ($_methodIds as $_methodId){
- if(!in_array($_methodId,$existMethodIds)){
- $methodIds[] = $_methodId;
- array_push($existMethodIds,$_methodId);
- }
- }
- $pcItem = array('pc_id' => $specialId, 'pc_name' => $specialNames[$key], 'parent_id' => 0, 'children' => array(
- 'pc_id' => $lecture->pc_id, 'pc_name' => $lecture->pc_name, 'parent_id' => $specialId, 'method_ids' => $methodIds
- ));
- array_push($pcIds, $pcItem);
- }
- }
- }
- }
- }
- //专题下所有试卷 FIXME 220104
- $paper = $this->apiPost('/all_content/detail', array(
- 'catalogIds' => array($specialId)
- ));
- if ($paper->status != 1 && !empty($paper->error)) {
- echo json_encode(array("status" => 0, "message" => $paper->error));
- exit();
- }
- if($paper->data) {
- foreach ($paper->data as $item){
- if($item->paper_id){
- array_push($paperIds, $item->paper_id);
- }
- }
- }
- }
- if (count($specialIds) > 1) {
- echo json_encode(array('status' => 0, 'error' => '专题选择超出限制'));
- exit;
- }
- } else {
- $lectures = array();
- $pcIds = array();
- $specialID = array();
- $pcArr = array();
- foreach ($unitIds as $key => $unitId) {
- $ids = explode('_', $unitId);
- $specialID[$ids[0]] = $ids[0];
- $specialNodeId = $ids[0];
- $nameArr = explode('_', $names[$key]);
- $lectures[$ids[0]][$ids[1]]['pc_id'] = $ids[1];
- $lectures[$ids[0]][$ids[1]]['pc_name'] = $nameArr[1];
- $lectures[$ids[0]][$ids[1]]['parent_id'] = $ids[0];
- if(!isset($lectures[$ids[0]][$ids[1]]['method_ids'])){
- $lectures[$ids[0]][$ids[1]]['method_ids'] = array();
- }
- if(!in_array($ids[2],$existMethodIds)){
- $lectures[$ids[0]][$ids[1]]['method_ids'][] = $ids[2];
- array_push($existMethodIds,$ids[2]);
- }
- $specialNames[] = $nameArr[0];
- $pcArr = array('pc_id' => $ids[0], 'pc_name' => $nameArr[0], 'parent_id' => 0);
- }
- if (count($specialID) > 1) {
- echo json_encode(array('status' => 0, 'error' => '专题选择超出限制'));
- exit;
- }
- foreach ($lectures as $key=>$lecture){
- foreach ($lecture as $item){
- $pcArr['children'] = $item;
- array_push($pcIds, $pcArr);
- }
- }
- }
- if($createType==1 && empty($pcIds)){
- echo json_encode(array('status'=>0, 'error'=> '专题内容无数据!'));exit;
- }
- $limit = SGeneralProductSetting::model()->classHistory($specialNodeId, 29, implode(',',$classIds));
- if($limit){
- echo json_encode(array('status'=>0, 'error'=> implode(',',$limit).'该专题生成次数超出限制'));exit;
- }
- $setting = array(
- 'product_id' => 17,
- 'pc_ids' => empty($pcIds) ? array(array("pc_id"=>$specialIds[0],"pc_name"=>$specialNames[0],"parent_id"=>0,"children"=>null)) : $pcIds,
- 'paper_ids' => $paperIds, //TODO 试卷
- 'create_type' => $createType,
- 'is_answer_merge' => $isAnswerMerge ? false : true,
- //'train_push_type' => $trainPushType,
- );
- $time = time();
- $transaction = $this->sConn->beginTransaction();
- try {
- $groupId = getUniqueId($this->schoolId);
- $strModel = new SStudentClassRelation();
- $this->sConn->createCommand()->insert('general_product_setting', array(
- 'gp_group_id' => $groupId,
- 'grade' => $grade,
- 'product_type' => 29,
- 'subject_id' => $this->subjectId,
- 'semester_id' => $this->semesterId,
- 'setting' => json_encode($setting, true),
- 'create_time' => $time,
- 'update_time' => $time,
- ));
- $gpIds = array();
- foreach ($classIds as $classId) {
- $gpId = getUniqueId($this->schoolId);
- $this->sConn->createCommand()->insert('general_product', array(
- 'gp_id' => $gpId,
- 'gp_group_id' => $groupId,
- 'class_id' => $classId,
- 'grade' => 3,
- 'name' => $specialNames ? implode(',',array_unique($specialNames)).date('YmdHis',$time) : implode(',',array_unique($paperNames)).date('YmdHis',$time),
- 'subject_id' => $this->subjectId,
- 'semester_id' => $this->semesterId,
- 'create_time' => $time,
- 'update_time' => $time,
- ));
- //获取班级学生
- $stuData = $strModel->getRelationsByClassId_Status_0($classId);
- foreach ($stuData as $kk => $vv) {
- $this->sConn->createCommand()->insert('general_product_student', array(
- 'gp_id' => $gpId,
- 'student_id' => $vv['student_id'],
- ));
- }
- //插入一条学生id为0的作为教师产品
- $this->sConn->createCommand()->insert('general_product_student', array(
- 'gp_id' => $gpId,
- 'student_id' => 0,
- 'is_teaching_pdf' => 1,
- ));
- array_push($gpIds, $gpId);
- }
- //发送消息
- //{"school_id":"599","msg_type":90,"subject_id":3,"send_type":"special","product_type":29,"gp_group_id":"780620754713923584","gp_ids":["780620755246600192","780620755766693888"]}
- $sendMsg=array(
- 'school_id'=>$this->schoolId,
- 'msg_type'=>1,
- 'subject_id'=>$this->subjectId,
- 'send_type'=>'special',
- 'product_type'=>29,
- 'gp_group_id'=>$groupId,
- 'gp_ids'=>$gpIds
- );
- $transaction->commit();
- sendDataToKafka('php-product-html',$sendMsg);
- } catch (Exception $e) {
- $transaction->rollBack();
- if (YII_ENV == 'production') {
- $error[] = '系统错误[SQL]';
- } else {
- $error[] = $e->getMessage();
- }
- }
- }
- if ($error) {
- echo json_encode(array('status' => 0, 'error' => $error));
- exit;
- } else {
- echo json_encode(array('status' => 1));
- exit;
- }
- }
- //获取专题宝产品班级
- public function actionAjaxGetClasses()
- {
- $result = array();
- $grade = (int)Req::post('grade');
- if ($grade) {
- $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and class_type = 1 and is_hide=0";
- $data = $this->sConn->createCommand($sql)->queryAll();
- if ($data) {
- $basic = imsBasicAuth($this->schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]);
- $Sem = new SSemester();
- $code = $Sem->conn->createQuery()
- ->from('semester')
- ->where("semester_id = '" . $this->semesterId . "'")
- ->limit(1)
- ->query()
- ->read();
- foreach ($data as $k => $v) {
- $studentIds = SStudentClassRelation::model()->getStudentIdsByClassId_Status_0($v['class_id']);
- if($studentIds) {
- $intarr = array(
- "schoolId" => $this->schoolId,
- "clazzId" => $v['class_id'],
- "semester" => $code['refer_code'],
- "grade" => 3,
- "students" => $studentIds,
- "examTime" => time(),
- "classify" => 31,
- "subject" => 3
- );
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr), $basic));
- if (!$rs) {
- echo json_encode(array('status' => 0, 'error' => '接口错误'));
- exit;
- }
- if ($rs->errCode != "00") {
- echo json_encode(array('status' => 0, 'error' => $rs->errMsg));
- exit;
- }
- if (!empty($rs->data)) {
- array_push($result, array('class_id' => $v['class_id'], 'class_name' => $v['class_name']));
- }
- }
- }
- }
- }
- echo json_encode($result);
- exit;
- }
- //专题宝班级重置页面
- public function actionClasses()
- {
- $groupId = Req::get('gp_group_id');
- $name = Req::get('name');
- if (empty($groupId) || empty($name)) {
- Yii::app()->jump->error('参数异常');
- }
- $newCondition[] = 'g.gp_group_id=' . $groupId;
- $model = new SGeneralProductSetting();
- $rs = $model->getList($newCondition, array('g.create_time desc'), 100);
- if (!isset($rs['rs'])) {
- Yii::app()->jump->error('获取班级数据失败');
- }
- $resetTotal=3;//学管重置总次数
- foreach($rs['rs'] as $key=>$item){
- //学管剩余重置次数
- $item['learn_tube_reset_residue_count']=$resetTotal>$item['learn_tube_reset_count']?$resetTotal-$item['learn_tube_reset_count']:0;
- //学管30分钟内只能重置一次
- $item['is_cool_down']=time()-$item['learn_tube_reset_time']<=1800?0:1;
- //冷却文字提示 30分钟内并且剩余次数大于0
- $item['is_cool_down_prompt']=!$item['is_cool_down'] && $item['learn_tube_reset_residue_count']?true:false;
- $rs['rs'][$key]=$item;
- }
- //是不是技术支持
- $isTechnicalSupport=1;
- if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']!=1 ){
- $isTechnicalSupport=0;
- }
- $data['resultList'] = $rs['rs'];
- $data['productName'] = $name;
- $data['currentWeek'] = date('W');
- $data['is_technical_support']=$isTechnicalSupport;
- $this->render('reset', $data);
- }
- //重置操作
- public function actionReset()
- {
- $gpIds = Req::post('classExam');
- if (!$gpIds || !is_array($gpIds)) {
- echo json_encode(array("status" => 0, "message" => "参数错误!"));
- exit;
- }
- $transaction = $this->sConn->beginTransaction();
- try {
- $gpIdsStr=implode(',',$gpIds);
- $sql="select gp_id,reset_times,learn_tube_reset_count from general_product where gp_id in ({$gpIdsStr})";
- $generalProducts=$this->sConn->createCommand($sql)->queryAll();
- $learnTubeResetCounts=_array_column($generalProducts,'learn_tube_reset_count','gp_id');
- foreach ($gpIds as $gpId) {
- $this->sConn->createCommand()->update("general_product_student", array(
- 'is_create_html' => 90,
- 'is_create_pdf' => 90,
- 'is_download' => 0,
- 'pdf_page_num' => 0,
- 'pdf_sheet_num' => 0,), "gp_id = '{$gpId}'");
- if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']!=1 ) {
- if(!isset($learnTubeResetCounts[$gpId])){
- continue;
- }
- $learnTubeResetCount=$learnTubeResetCounts[$gpId]+1;
- $this->sConn->createCommand()->update("general_product", array('reset_times' => new CDbExpression('reset_times+1'),'learn_tube_reset_count'=>$learnTubeResetCount,'learn_tube_reset_time'=>time()), "gp_id = '{$gpId}'");
- }else{
- $this->sConn->createCommand()->update("general_product", array('reset_times' => new CDbExpression('reset_times+1')), "gp_id = '{$gpId}'");
- }
- }
- //发送消息
- $groupModel = SGeneralProduct::model()->find('gp_id=:gp_id',array('gp_id'=>$gpIds[0]));
- if(!$groupModel){
- echo json_encode(array("status" => 0, "message" => "数据异常!"));
- exit;
- }
- // setting更新补提信息
- $this->sConn->createCommand()->update("general_product_setting", array('status' =>1), "gp_group_id = '{$groupModel['gp_group_id']}'");
- $sendMsg=array(
- 'school_id'=>$this->schoolId,
- 'msg_type'=>90,
- 'subject_id'=>$this->subjectId,
- 'send_type'=>'special',
- 'product_type'=>29,
- 'gp_group_id'=>$groupModel['gp_group_id'],
- 'gp_ids'=>$gpIds
- );
- $transaction->commit();
- sendDataToKafka('php-product-html',$sendMsg);
- } catch (\Exception $e) {
- $transaction->rollBack();
- echo json_encode(array('status' => 0, 'message' => $e->getMessage()));
- exit;
- }
- echo json_encode(array('status' => 1));
- exit;
- }
- //专题宝教师版
- public function actionTeaching()
- {
- $gpId = Req::get('gpId');
- if (!$gpId) {
- echo json_encode(array("status" => 0, "message" => "参数错误!"));
- exit;
- }
- $rs = SGeneralProductStudent::model()->find('gp_id=:gp_id and is_teaching_pdf=1 and is_create_pdf=1',array('gp_id'=>$gpId));
- if(empty($rs) && empty($rs['pdf_path'])){
- echo json_encode(array("status" => 0, "message" => "pdf未生成"));
- exit;
- }
- if($rs['pdf_create_time']<(time()-604800)){
- echo json_encode(array("status" => 0, "message" => "pdf已失效,请重新生成!"));
- exit;
- }
- echo json_encode(array('status'=>1, 'url'=>Yii::app()->params['static_url'][$this->schoolGroupId].$rs['pdf_path']));exit;
- }
- public function actionDownloadDir(){
- $filename= dirname(dirname(dirname(__FILE__))).'/assets/data/special_method.pdf';
- if (FALSE!== ($handler = fopen($filename, 'r')))
- {
- header('Content-Description: File Transfer');
- header('Content-Type: application/octet-stream');
- header('Content-Disposition: attachment; filename=专题宝方法对应目录.pdf');
- header('Content-Transfer-Encoding: chunked'); //changed to chunked
- header('Expires: 0');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Pragma: public');
- while (!feof($handler)) {
- file_put_contents("php://output", fread($handler, 4096));
- }
- fclose($handler);
- }
- }
- }
|