deleteAll("grade=:grade",array(':grade'=>3,)); $textbookMap=array( array('old_textbook_id'=>43,'old_textbook_name'=>'新人教A版','new_textbook_name'=>'人教A版(2019)'), array('old_textbook_id'=>13,'old_textbook_name'=>'人教A版','new_textbook_name'=>'人教A版'), array('old_textbook_id'=>44,'old_textbook_name'=>'新人教B版','new_textbook_name'=>'人教B版(2019)'), array('old_textbook_id'=>14,'old_textbook_name'=>'人教B版','new_textbook_name'=>'人教B版'), array('old_textbook_id'=>45,'old_textbook_name'=>'新北师大版','new_textbook_name'=>'北师大版(2019)'), array('old_textbook_id'=>16,'old_textbook_name'=>'北师大版','new_textbook_name'=>'北师大版'), array('old_textbook_id'=>47,'old_textbook_name'=>'新湘教版','new_textbook_name'=>'湘教版(2019)'), array('old_textbook_id'=>32,'old_textbook_name'=>'湘教版','new_textbook_name'=>'湘教版'), array('old_textbook_id'=>46,'old_textbook_name'=>'新苏教版','new_textbook_name'=>'苏教版(2019)'), array('old_textbook_id'=>15,'old_textbook_name'=>'苏教版','new_textbook_name'=>'苏教版'), ); $textbookIds=array(); foreach($textbookMap as &$item){ if(!isset($textbooks[$item['new_textbook_name']])){ echo '无教材id:'.$item['new_textbook_name'].'\n'; continue; } $item['new_textbook_id']=$textbooks[$item['new_textbook_name']]; $textbookIds[$item['old_textbook_id']]=$textbooks[$item['new_textbook_name']]; } //线上教材数据自动转换为全学科题库教材版本数据 数据同步 foreach($textbookIds as $oldTextbookid=>$newTextbookId){ if(!SchoolTextbook::model()->updateAll(array('textbook_id'=>$newTextbookId,'subject_id'=>3),"textbook_id=:textbook_id",array(':textbook_id'=>$oldTextbookid))){ echo "教材id:{$oldTextbookid}无更新\n"; } } //线上教材数据自动转换为全学科题库教材版本数据 缓存同步 $sql="select school_id from school_textbook group by school_id"; $schoolIds=SchoolTextbook::model()->getDbConnection()->createCommand($sql)->queryAll(); foreach($schoolIds as $item){ //更新缓存 $check=SchoolTextbook::model()->findAll("school_id=:sid ",array(':sid'=>$item['school_id'])); $redisData=array(); foreach ($check as $item){ $redisData[]=array( 'grade'=>$item['grade'], 'textbook_id'=>$item['textbook_id'], 'subject_id'=>$item['subject_id'], 'school_id'=>$item['school_id'] ); } Yii::app()->school_textbook_setting->hmset('content:school_textbook:'.$item['school_id'],array('setting'=>jsonEncode($redisData))); echo "更新缓存数组school_id:{$item['school_id']}\n"; } echo 'end 同步教材数据\n'; } }