array('old_textbook_id' => 43, 'old_textbook_name' => '新人教A版', 'new_textbook_name' => '人教A版(2019)', 'new_textbook_id' => 6101, 'subject_id' => 51,), 13 => array('old_textbook_id' => 13, 'old_textbook_name' => '人教A版', 'new_textbook_name' => '人教A版', 'new_textbook_id' => 6100, 'subject_id' => 3,), 44 => array('old_textbook_id' => 44, 'old_textbook_name' => '新人教B版', 'new_textbook_name' => '人教B版(2019)', 'new_textbook_id' => 6103, 'subject_id' => 51,), 14 => array('old_textbook_id' => 14, 'old_textbook_name' => '人教B版', 'new_textbook_name' => '人教B版', 'new_textbook_id' => 6102, 'subject_id' => 3,), 45 => array('old_textbook_id' => 45, 'old_textbook_name' => '新北师大版', 'new_textbook_name' => '北师大版(2019)', 'new_textbook_id' => 6105, 'subject_id' => 51,), 16 => array('old_textbook_id' => 16, 'old_textbook_name' => '北师大版', 'new_textbook_name' => '北师大版', 'new_textbook_id' => 6104, 'subject_id' => 3,), 47 => array('old_textbook_id' => 47, 'old_textbook_name' => '新湘教版', 'new_textbook_name' => '湘教版(2019)', 'new_textbook_id' => 6109, 'subject_id' => 51,), 32 => array('old_textbook_id' => 32, 'old_textbook_name' => '湘教版', 'new_textbook_name' => '湘教版', 'new_textbook_id' => 6108, 'subject_id' => 3,), 46 => array('old_textbook_id' => 46, 'old_textbook_name' => '新苏教版', 'new_textbook_name' => '苏教版(2019)', 'new_textbook_id' => 6107, 'subject_id' => 51,), 15 => array('old_textbook_id' => 15, 'old_textbook_name' => '苏教版', 'new_textbook_name' => '苏教版', 'new_textbook_id' => 6106, 'subject_id' => 3,), ); // 教材列表 public function actionIndex() { //判断全学科试用学校 $rs = http('/cms/api/qxk-math-trial-school/' . $this->schoolId, 'GET', $this->schoolId, array(), 'cgi'); $rs = json_decode($rs, true); //是不是试用全学科学校 0:不是 1:是。跟school_textbook表is_qxk:是否全学科教材:0-不是1-是,默认0 值一致 $isTrial = 0; if (isset($rs['errCode']) && $rs['errCode'] == '00' && $rs['data'] == true) { $isTrial = 1; } $schoolTextBookSet = SchoolTextbook::model()->findAll("school_id=:sid and is_qxk=:is_qxk", array(':sid' => $this->schoolId,':is_qxk'=>$isTrial)); $textbookArr=array(); if (!$isTrial) { if ($schoolTextBookSet) { foreach ($schoolTextBookSet as $key => $val) { $textbookArrTemp = array( 'grade_id' => $val['grade'], 'subject_id' => $val['subject_id'], 'textbook_id' => $val['textbook_id'], 'grade' => Yii::app()->params['grade_config'][$val['grade']]['grade_name'], 'subject' => Yii::app()->params['subjectId'][$val['subject_id']], ); if (isset($this->textBookType['3'][$val['textbook_id']])) { $textbookArrTemp['textbook_name'] = $this->textBookType['3'][$val['textbook_id']]; } if (isset($this->textBookType['51'][$val['textbook_id']])) { $textbookArrTemp['textbook_name'] = $this->textBookType['51'][$val['textbook_id']]; } if (isset($this->textBookType['6'][$val['textbook_id']])) { $textbookArrTemp['textbook_name'] = $this->textBookType['6'][$val['textbook_id']]; } if (empty($textbookArrTemp['textbook_name'])) { $textbookArrTemp['textbook_name'] = ''; } $textbookArr[] = $textbookArrTemp; } } else { //初始化一条高三 $model = new SchoolTextbook(); $model->school_id = $this->schoolId; $model->subject_id = 6; $model->grade = 3; $model->textbook_id = 28; $model->save(); $textbookArr[] = array( 'grade_id' => 3, 'subject_id' => 6, 'textbook_id' => 28, 'grade' => '高三', 'subject' => '数学', 'textbook_name' => '高三通用', ); } $view = 'index'; $data = array('data' => $textbookArr, 'textbookArr' => $this->textBookType); } else { $json_material = $this->apiPost('all_textbook/tree', array('subjectId' => 3)); $json_material = json_decode(json_encode($json_material), true); $textbooksData = isset($json_material['status']) && $json_material['status'] && isset($json_material['data']) ? $json_material['data'] : array(); $textbooks = array(); foreach ($textbooksData as $item) { $textbooks[$item['textbook_id']] = $item['textbook_name']; } foreach ($schoolTextBookSet as $key => $val) { $textbookArr[] = array( 'grade_id' => $val['grade'], 'subject_id' => $val['subject_id'], 'textbook_id' => $val['textbook_id'], 'grade' => Yii::app()->params['grade_config'][$val['grade']]['grade_name'], 'subject' => Yii::app()->params['subjectId'][$val['subject_id']], 'textbook_name' => isset($textbooks[$val['textbook_id']]) ? $textbooks[$val['textbook_id']] : '', ); } $view = 'index2'; $data = array('data' => $textbookArr, 'textbookArr' => $textbooks); } $this->render($view, $data); } //添加教材 public function actionAdd(){ $subject = Req::post('subject'); $grade = Req::post('grade'); $textbook = Req::post('textbook'); $isQxk = Req::post('isQxk'); $result['status']=0; //判断科目id if(!$textbook){ exit(jsonEncode($result)); } if(!$isQxk) { foreach ($this->textBookType as $key => $val) { if (isset($val[$textbook])) { $subject = $key; } } }else{ $subject=3; } $check=SchoolTextbook::model()->find("school_id=:sid and grade=:grade and is_qxk=:is_qxk",array(':sid'=>$this->schoolId,':grade'=>$grade,':is_qxk'=>$isQxk)); if($check){ $result['msg']=Yii::app()->params['grade_config'][$grade]['grade_name'].Yii::app()->params['subjectId'][$subject].'已经有设置内容,不能重复设置'; exit(jsonEncode($result)); }else{ $transaction = $this->conn->beginTransaction(); try { $sql="insert into school_textbook(school_id,grade,textbook_id,subject_id,is_qxk) values({$this->schoolId},{$grade},{$textbook},{$subject},{$isQxk})"; $this->conn->createCommand($sql)->execute(); if(!$isQxk && isset($this->textbookMap[$textbook])){ $newTextbookId=$this->textbookMap[$textbook]['new_textbook_id']; $qxkTextbook = SchoolTextbook::model()->find("school_id=:sid and grade=:grade and is_qxk=:is_qxk", array(':sid' => $this->schoolId, ':grade' => $grade, ':is_qxk' => 1)); if($qxkTextbook){ if($qxkTextbook['textbook_id']!=$newTextbookId){ $sql="update school_textbook set textbook_id={$newTextbookId} where school_id={$this->schoolId} and grade={$grade} and is_qxk=1"; $this->conn->createCommand($sql)->execute(); } }else{ $sql="insert into school_textbook(school_id,grade,textbook_id,subject_id,is_qxk) values({$this->schoolId},{$grade},{$newTextbookId},3,1)"; $this->conn->createCommand($sql)->execute(); } } $transaction->commit(); $result['status']=1; }catch (\Exception $e){ $transaction->rollBack(); $result['msg']=$e->getMessage(); exit(jsonEncode($result)); } } if($result['status']==1){ //更新缓存 $check=SchoolTextbook::model()->findAll("school_id=:sid ",array(':sid'=>$this->schoolId)); $redisData=array(); foreach ($check as $item){ $redisData[]=array( 'grade'=>$item['grade'], 'textbook_id'=>$item['textbook_id'], 'subject_id'=>$item['subject_id'], 'school_id'=>$this->schoolId, 'is_qxk'=>$item['is_qxk'], ); } Yii::app()->school_textbook_setting->hmset('content:school_textbook:'.$this->schoolId,array('setting'=>jsonEncode($redisData))); } exit(jsonEncode($result)); } //编辑教材 public function actionEdit(){ $subject = Req::post('subject'); $grade = Req::post('grade'); $textbook = Req::post('textbook'); $isQxk = Req::post('isQxk'); $result['status']=0; //判断科目id if(!$textbook){ exit(jsonEncode($result)); } if(!$isQxk) { foreach ($this->textBookType as $key => $val) { if (isset($val[$textbook])) { $subject = $key; } } }else{ $subject=3; } $check=SchoolTextbook::model()->find("school_id=:sid and grade=:grade and is_qxk=:is_qxk",array(':sid'=>$this->schoolId,':grade'=>$grade,':is_qxk'=>$isQxk)); if($check){ if($check['textbook_id']==$textbook ){ $result['msg']=Yii::app()->params['grade_config'][$grade]['grade_name'].Yii::app()->params['subjectId'][$subject].'教材已有相同设置,不能重复设置'; exit(jsonEncode($result)); }else{ $transaction = $this->conn->beginTransaction(); try { $sql="update school_textbook set textbook_id={$textbook},subject_id={$subject} where school_id={$this->schoolId} and grade={$grade} and is_qxk={$isQxk}"; $this->conn->createCommand($sql)->execute(); if(!$isQxk && isset($this->textbookMap[$textbook])){ $newTextbookId=$this->textbookMap[$textbook]['new_textbook_id']; $qxkTextbook = SchoolTextbook::model()->find("school_id=:sid and grade=:grade and is_qxk=:is_qxk", array(':sid' => $this->schoolId, ':grade' => $grade, ':is_qxk' => 1)); if($qxkTextbook){ if($qxkTextbook['textbook_id']!=$newTextbookId){ $sql="update school_textbook set textbook_id={$newTextbookId} where school_id={$this->schoolId} and grade={$grade} and is_qxk=1"; $this->conn->createCommand($sql)->execute(); } }else{ $sql="insert into school_textbook(school_id,grade,textbook_id,subject_id,is_qxk) values({$this->schoolId},{$grade},{$newTextbookId},3,1)"; $this->conn->createCommand($sql)->execute(); } } $transaction->commit(); $result['status']=1; }catch (\Exception $e){ $transaction->rollBack(); $result['msg']=$e->getMessage(); exit(jsonEncode($result)); } } } if($result['status']==1){ //更新缓存 $check=SchoolTextbook::model()->findAll("school_id=:sid ",array(':sid'=>$this->schoolId)); $redisData=array(); foreach ($check as $item){ $redisData[]=array( 'grade'=>$item['grade'], 'textbook_id'=>$item['textbook_id'], 'subject_id'=>$item['subject_id'], 'school_id'=>$this->schoolId, 'is_qxk'=>$item['is_qxk'], ); } Yii::app()->school_textbook_setting->hmset('content:school_textbook:'.$this->schoolId,array('setting'=>jsonEncode($redisData))); } exit(jsonEncode($result)); } }