TextbookSyncNewCommand.php 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. Yii::import('application.models.*');
  3. /**
  4. * 处理晨读词汇历史批次id数据脚本(一次性)
  5. */
  6. class TextbookSyncNewCommand extends CConsoleCommand {
  7. public function init() {
  8. parent::init();
  9. @ini_set('memory_limit', '1024M');
  10. set_time_limit(0);
  11. }
  12. public function actionIndex($YII_ENV='development')
  13. {
  14. echo "start 同步教材数据.....\n";
  15. //先删除高三数据
  16. SchoolTextbook::model()->deleteAll("grade=:grade",array(':grade'=>3,));
  17. $textbookMap=array(
  18. array('old_textbook_id'=>43,'old_textbook_name'=>'新人教A版','new_textbook_name'=>'人教A版(2019)','new_textbook_id'=>6101,'subject_id'=>51,),
  19. array('old_textbook_id'=>13,'old_textbook_name'=>'人教A版','new_textbook_name'=>'人教A版','new_textbook_id'=>6100,'subject_id'=>3,),
  20. array('old_textbook_id'=>44,'old_textbook_name'=>'新人教B版','new_textbook_name'=>'人教B版(2019)','new_textbook_id'=>6103,'subject_id'=>51,),
  21. array('old_textbook_id'=>14,'old_textbook_name'=>'人教B版','new_textbook_name'=>'人教B版','new_textbook_id'=>6102,'subject_id'=>3,),
  22. array('old_textbook_id'=>45,'old_textbook_name'=>'新北师大版','new_textbook_name'=>'北师大版(2019)','new_textbook_id'=>6105,'subject_id'=>51,),
  23. array('old_textbook_id'=>16,'old_textbook_name'=>'北师大版','new_textbook_name'=>'北师大版','new_textbook_id'=>6104,'subject_id'=>3,),
  24. array('old_textbook_id'=>47,'old_textbook_name'=>'新湘教版','new_textbook_name'=>'湘教版(2019)','new_textbook_id'=>6109,'subject_id'=>51,),
  25. array('old_textbook_id'=>32,'old_textbook_name'=>'湘教版','new_textbook_name'=>'湘教版','new_textbook_id'=>6108,'subject_id'=>3,),
  26. array('old_textbook_id'=>46,'old_textbook_name'=>'新苏教版','new_textbook_name'=>'苏教版(2019)','new_textbook_id'=>6107,'subject_id'=>51,),
  27. array('old_textbook_id'=>15,'old_textbook_name'=>'苏教版','new_textbook_name'=>'苏教版','new_textbook_id'=>6106,'subject_id'=>3,),
  28. );
  29. //更新教材数据
  30. foreach($textbookMap as $item){
  31. 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']))){
  32. echo "教材id:{$item['new_textbook_id']}无更新\n";
  33. }
  34. }
  35. //线上教材数据自动转换为全学科题库教材版本数据 缓存同步
  36. $sql="select school_id from school_textbook group by school_id";
  37. $schoolIds=SchoolTextbook::model()->getDbConnection()->createCommand($sql)->queryAll();
  38. foreach($schoolIds as $item){
  39. //初始化一条高三
  40. $model=new SchoolTextbook();
  41. $model->school_id=$item['school_id'];
  42. $model->subject_id=6;
  43. $model->grade=3;
  44. $model->textbook_id=28;
  45. $model->save();
  46. //更新缓存
  47. $check=SchoolTextbook::model()->findAll("school_id=:sid ",array(':sid'=>$item['school_id']));
  48. $redisData=array();
  49. foreach ($check as $item){
  50. $redisData[]=array(
  51. 'grade'=>$item['grade'],
  52. 'textbook_id'=>$item['textbook_id'],
  53. 'subject_id'=>$item['subject_id'],
  54. 'school_id'=>$item['school_id']
  55. );
  56. }
  57. Yii::app()->school_textbook_setting->hmset('content:school_textbook:'.$item['school_id'],array('setting'=>jsonEncode($redisData)));
  58. echo "更新缓存数组school_id:{$item['school_id']}\n";
  59. }
  60. echo 'end 同步教材数据\n';
  61. }
  62. }