123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- <?php
- Yii::import('application.models.*');
- /**
- * 批量更新数学个性化学习宝生成版本字段(一次性)
- */
- class MathVersionBatchCommand extends CConsoleCommand
- {
- public function init()
- {
- parent::init();
- @ini_set('memory_limit', '1024M');
- set_time_limit(0);
- }
- public function actionIndex($YII_ENV = 'development')
- {
- echo 'start 初中数学产品设置初始化.....' . PHP_EOL;
- $schools = $this->getSchools();
- foreach ($schools as $school) {
- echo 'start' . $school['school_id'] . ' ' . $school['school_name'] . PHP_EOL;
- $con = $this->getSchoolDbCon($school['school_id']);
- if (!$con) {
- echo 'school database cannot connect' . PHP_EOL;
- continue;
- }
- try {
- //self::updateIspVersion($con);
- self::initTemplate3($con);
- echo $school['school_name'] . 'done' . PHP_EOL;
- } catch (\Exception $e) {
- echo $e->getMessage() . PHP_EOL;
- continue;
- }
- sleep(0.1);
- }
- echo 'end 处理完成' . PHP_EOL;
- exit;
- }
- /**
- * 获取所有正常可用的学校
- * @return mixed
- */
- private function getSchools()
- {
- $db = Yii::app()->businessDb;
- $sql = "SELECT school_id,school_name FROM `school` WHERE `status`=0 AND `section`=0";
- $schools = $db->createCommand($sql)->queryAll();
- $db->close();
- return $schools;
- }
- /**
- * 学校库连接
- * @param $schoolId
- * @return bool|CDbConnection
- */
- public function getSchoolDbCon($schoolId)
- {
- $db = BusinessDatabase::model()->find('school_id=:sid', array(':sid' => $schoolId));
- if (empty($db)) {
- return false;
- }
- $myDbDsn = 'mysql:host=' . $db->database_host . ';dbname=' . $db->database_name;
- $my_connection = new CDbConnection($myDbDsn, $db->database_user, $db->database_password);
- $my_connection->emulatePrepare = true;
- $my_connection->enableProfiling = true;
- $my_connection->enableParamLogging = true;
- $myDbDsn = null;
- return $my_connection;
- }
- /**
- * 初始化3.0模板数据
- * @param $con
- */
- private function initTemplate3($con)
- {
- //查询是否有默认模板
- $wrongBook = array();
- $isp = array();
- $templates = $con->createCommand("select template_id,template_name,product_type,subject_id,target_type,is_default from product_template where is_beta=0 and is_default=1 and subject_id = 41")->queryAll();
- //判断默认模板是否存在
- $wrongBookClassConfig = <<<TPL
- {
- "studentLevelDivide":{
- "studentLevel":3,
- "rankBase":"score",
- "levelDetails":[
- {
- "level":"A",
- "valueEnd":{
- "score":100,
- "grade":20
- },
- "valueStart":{
- "score":81,
- "grade":0
- },
- "errorPushDetail": {
- "smallTopic": 0,
- "largeTopic": 80,
- "difficulty": [1,2,3]
- }
- },
- {
- "level":"B",
- "valueEnd":{
- "score":80,
- "grade":60
- },
- "valueStart":{
- "score":61,
- "grade":21
- },
- "errorPushDetail": {
- "smallTopic": 0,
- "largeTopic": 80,
- "difficulty": [1,2,3]
- }
- },
- {
- "level":"C",
- "valueEnd":{
- "score":60,
- "grade":100
- },
- "valueStart":{
- "score":0,
- "grade":61
- },
- "errorPushDetail": {
- "smallTopic": 0,
- "largeTopic": 80,
- "difficulty": [1,2,3]
- }
- }
- ]
- },
- "errorTypeSetting":{
- "hasScoreDetail":true,
- "hasTips":true,
- "hasKnowledgeMap":true,
- "hasWrongTopic":true,
- "hasCorrection":true,
- "hasExactCheck":true,
- "hasSpecific":true,
- "hasCommon":true,
- "hasCommonFront": true,
- "hasAnswerTogether":true
- }
- }
- TPL;
- $wrongBookStudentConfig = <<<TPL
- {
- "studentLevelDivide":{
- "levelDetails":[
- {
- "errorPushDetail": {
- "smallTopic": 0,
- "largeTopic": 80,
- "difficulty": [1,2,3]
- }
- }
- ]
- },
- "errorTypeSetting":{
- "hasScoreDetail":true,
- "hasTips":true,
- "hasKnowledgeMap":true,
- "hasWrongTopic":true,
- "hasCorrection":true,
- "hasExactCheck":true,
- "hasSpecific":true,
- "hasCommon":true,
- "hasCommonFront": true,
- "hasAnswerTogether":true
- }
- }
- TPL;
- $ispClassConfig = <<<TPL
- {
- "commonTopicMethod":{
- "scoreRateStart":20,
- "scoreRateEnd":65
- },
- "studentLevelDivide":{
- "studentLevel":3,
- "rankBase":"score",
- "levelDetails":[
- {
- "level":"A",
- "valueEnd":{
- "score":100,
- "grade":20
- },
- "valueStart":{
- "score":81,
- "grade":0
- },
- "trainPushDetail":{
- "specificNumber":3,
- "maxMethodTopic":2,
- "methodTopicLevel":1
- },
- "errorPushDetail": {
- "smallTopic": 0,
- "largeTopic": 80,
- "difficulty": [1,2,3]
- }
- },
- {
- "level":"B",
- "valueEnd":{
- "score":80,
- "grade":60
- },
- "valueStart":{
- "score":61,
- "grade":21
- },
- "trainPushDetail":{
- "specificNumber":3,
- "maxMethodTopic":2,
- "methodTopicLevel":2
- },
- "errorPushDetail": {
- "smallTopic": 0,
- "largeTopic": 80,
- "difficulty": [1,2,3]
- }
- },
- {
- "level":"C",
- "valueEnd":{
- "score":60,
- "grade":100
- },
- "valueStart":{
- "score":0,
- "grade":61
- },
- "trainPushDetail":{
- "specificNumber":3,
- "maxMethodTopic":2,
- "methodTopicLevel":3
- },
- "errorPushDetail": {
- "smallTopic": 0,
- "largeTopic": 80,
- "difficulty": [1,2,3]
- }
- }
- ]
- },
- "errorTypeSetting":{
- "hasScoreDetail":true,
- "hasTips":true,
- "hasKnowledgeMap":true,
- "hasWrongTopic":true,
- "hasCorrection":true,
- "hasExactCheck":true,
- "hasSpecific":true,
- "hasCommon":true,
- "hasCommonFront": true,
- "hasAnswerTogether":true
- }
- }
- TPL;
- $ispStudentConfig = <<<TPL
- {
- "studentLevelDivide":{
- "levelDetails":[
- {
- "errorPushDetail": {
- "smallTopic": 0,
- "largeTopic": 80,
- "difficulty": [1,2,3]
- },
- "trainPushDetail":{
- "specificNumber":3,
- "maxMethodTopic":2,
- "methodTopicLevel":3
- }
- }
- ]
- },
- "errorTypeSetting":{
- "hasScoreDetail":true,
- "hasTips":true,
- "hasKnowledgeMap":true,
- "hasWrongTopic":true,
- "hasCorrection":true,
- "hasExactCheck":true,
- "hasSpecific":true,
- "hasCommon":true,
- "hasCommonFront": true,
- "hasAnswerTogether":true
- }
- }
- TPL;
- foreach ($templates as $template){
- if($template['product_type']==1 && $template['target_type']==1){
- $wrongBook['class'] = 1;
- }
- if($template['product_type']==1 && $template['target_type']==2){
- $wrongBook['student'] = 1;
- }
- if($template['product_type']==30 && $template['target_type']==1){
- $isp['class'] = 1;
- }
- if($template['product_type']==30 && $template['target_type']==2){
- $isp['student'] = 1;
- }
- }
- $values = array();
- if (!isset($wrongBook['class'])) {
- $values[] = "('班级默认模板',1,1,'" . $wrongBookClassConfig . "',41,1,'" . time() . "',0)";
- }
- if (!isset($wrongBook['student'])) {
- $values[] = "('学生默认模板',1,2,'" . $wrongBookStudentConfig . "',41,1,'" . time() . "',0)";
- }
- if (!isset($isp['class'])) {
- $values[] = "('班级默认模板',30,1,'" . $ispClassConfig . "',41,1,'" . time() . "',0)";
- }
- if (!isset($isp['student'])) {
- $values[] = "('学生默认模板',30,2,'" . $ispStudentConfig . "',41,1,'" . time() . "',0)";
- }
- if ($values) {
- $sql = "insert into product_template(`template_name`,`product_type`,`target_type`,`config_text`,`subject_id`,`is_default`,`create_time`,`is_beta`) values " . implode(',', $values);
- $con->createCommand($sql)->execute();
- }
- }
- }
|