deleteAll("grade=:grade",array(':grade'=>3,)); $textbookMap=array( array('old_textbook_id'=>43,'old_textbook_name'=>'新人教A版','new_textbook_name'=>'人教A版(2019)','new_textbook_id'=>6101,'subject_id'=>51,), array('old_textbook_id'=>13,'old_textbook_name'=>'人教A版','new_textbook_name'=>'人教A版','new_textbook_id'=>6100,'subject_id'=>3,), array('old_textbook_id'=>44,'old_textbook_name'=>'新人教B版','new_textbook_name'=>'人教B版(2019)','new_textbook_id'=>6103,'subject_id'=>51,), array('old_textbook_id'=>14,'old_textbook_name'=>'人教B版','new_textbook_name'=>'人教B版','new_textbook_id'=>6102,'subject_id'=>3,), array('old_textbook_id'=>45,'old_textbook_name'=>'新北师大版','new_textbook_name'=>'北师大版(2019)','new_textbook_id'=>6105,'subject_id'=>51,), array('old_textbook_id'=>16,'old_textbook_name'=>'北师大版','new_textbook_name'=>'北师大版','new_textbook_id'=>6104,'subject_id'=>3,), array('old_textbook_id'=>47,'old_textbook_name'=>'新湘教版','new_textbook_name'=>'湘教版(2019)','new_textbook_id'=>6109,'subject_id'=>51,), array('old_textbook_id'=>32,'old_textbook_name'=>'湘教版','new_textbook_name'=>'湘教版','new_textbook_id'=>6108,'subject_id'=>3,), array('old_textbook_id'=>46,'old_textbook_name'=>'新苏教版','new_textbook_name'=>'苏教版(2019)','new_textbook_id'=>6107,'subject_id'=>51,), array('old_textbook_id'=>15,'old_textbook_name'=>'苏教版','new_textbook_name'=>'苏教版','new_textbook_id'=>6106,'subject_id'=>3,), ); //更新教材数据 foreach($textbookMap as $item){ if(!SchoolTextbook::model()->updateAll(array('textbook_id'=>$item['old_textbook_id'],'subject_id'=>$item['subject_id']),"textbook_id=:textbook_id",array(':textbook_id'=>$item['new_textbook_id']))){ echo "教材id:{$item['new_textbook_id']}无更新\n"; } } //线上教材数据自动转换为全学科题库教材版本数据 缓存同步 $sql="select school_id from school_textbook group by school_id"; $schoolIds=SchoolTextbook::model()->getDbConnection()->createCommand($sql)->queryAll(); foreach($schoolIds as $item){ //初始化一条高三 $model=new SchoolTextbook(); $model->school_id=$item['school_id']; $model->subject_id=6; $model->grade=3; $model->textbook_id=28; $model->save(); //更新缓存 $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'; } }