MathVersionBatchCommand.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <?php
  2. Yii::import('application.models.*');
  3. /**
  4. * 批量更新数学个性化学习宝生成版本字段(一次性)
  5. */
  6. class MathVersionBatchCommand extends CConsoleCommand
  7. {
  8. public function init()
  9. {
  10. parent::init();
  11. @ini_set('memory_limit', '1024M');
  12. set_time_limit(0);
  13. }
  14. public function actionIndex($YII_ENV = 'development')
  15. {
  16. echo 'start 初中数学产品设置初始化.....' . PHP_EOL;
  17. $schools = $this->getSchools();
  18. foreach ($schools as $school) {
  19. echo 'start' . $school['school_id'] . ' ' . $school['school_name'] . PHP_EOL;
  20. $con = $this->getSchoolDbCon($school['school_id']);
  21. if (!$con) {
  22. echo 'school database cannot connect' . PHP_EOL;
  23. continue;
  24. }
  25. try {
  26. //self::updateIspVersion($con);
  27. self::initTemplate3($con);
  28. echo $school['school_name'] . 'done' . PHP_EOL;
  29. } catch (\Exception $e) {
  30. echo $e->getMessage() . PHP_EOL;
  31. continue;
  32. }
  33. sleep(0.1);
  34. }
  35. echo 'end 处理完成' . PHP_EOL;
  36. exit;
  37. }
  38. /**
  39. * 获取所有正常可用的学校
  40. * @return mixed
  41. */
  42. private function getSchools()
  43. {
  44. $db = Yii::app()->businessDb;
  45. $sql = "SELECT school_id,school_name FROM `school` WHERE `status`=0 AND `section`=0";
  46. $schools = $db->createCommand($sql)->queryAll();
  47. $db->close();
  48. return $schools;
  49. }
  50. /**
  51. * 学校库连接
  52. * @param $schoolId
  53. * @return bool|CDbConnection
  54. */
  55. public function getSchoolDbCon($schoolId)
  56. {
  57. $db = BusinessDatabase::model()->find('school_id=:sid', array(':sid' => $schoolId));
  58. if (empty($db)) {
  59. return false;
  60. }
  61. $myDbDsn = 'mysql:host=' . $db->database_host . ';dbname=' . $db->database_name;
  62. $my_connection = new CDbConnection($myDbDsn, $db->database_user, $db->database_password);
  63. $my_connection->emulatePrepare = true;
  64. $my_connection->enableProfiling = true;
  65. $my_connection->enableParamLogging = true;
  66. $myDbDsn = null;
  67. return $my_connection;
  68. }
  69. /**
  70. * 初始化3.0模板数据
  71. * @param $con
  72. */
  73. private function initTemplate3($con)
  74. {
  75. //查询是否有默认模板
  76. $wrongBook = array();
  77. $isp = array();
  78. $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();
  79. //判断默认模板是否存在
  80. $wrongBookClassConfig = <<<TPL
  81. {
  82. "studentLevelDivide":{
  83. "studentLevel":3,
  84. "rankBase":"score",
  85. "levelDetails":[
  86. {
  87. "level":"A",
  88. "valueEnd":{
  89. "score":100,
  90. "grade":20
  91. },
  92. "valueStart":{
  93. "score":81,
  94. "grade":0
  95. },
  96. "errorPushDetail": {
  97. "smallTopic": 0,
  98. "largeTopic": 80,
  99. "difficulty": [1,2,3]
  100. }
  101. },
  102. {
  103. "level":"B",
  104. "valueEnd":{
  105. "score":80,
  106. "grade":60
  107. },
  108. "valueStart":{
  109. "score":61,
  110. "grade":21
  111. },
  112. "errorPushDetail": {
  113. "smallTopic": 0,
  114. "largeTopic": 80,
  115. "difficulty": [1,2,3]
  116. }
  117. },
  118. {
  119. "level":"C",
  120. "valueEnd":{
  121. "score":60,
  122. "grade":100
  123. },
  124. "valueStart":{
  125. "score":0,
  126. "grade":61
  127. },
  128. "errorPushDetail": {
  129. "smallTopic": 0,
  130. "largeTopic": 80,
  131. "difficulty": [1,2,3]
  132. }
  133. }
  134. ]
  135. },
  136. "errorTypeSetting":{
  137. "hasScoreDetail":true,
  138. "hasTips":true,
  139. "hasKnowledgeMap":true,
  140. "hasWrongTopic":true,
  141. "hasCorrection":true,
  142. "hasExactCheck":true,
  143. "hasSpecific":true,
  144. "hasCommon":true,
  145. "hasCommonFront": true,
  146. "hasAnswerTogether":true
  147. }
  148. }
  149. TPL;
  150. $wrongBookStudentConfig = <<<TPL
  151. {
  152. "studentLevelDivide":{
  153. "levelDetails":[
  154. {
  155. "errorPushDetail": {
  156. "smallTopic": 0,
  157. "largeTopic": 80,
  158. "difficulty": [1,2,3]
  159. }
  160. }
  161. ]
  162. },
  163. "errorTypeSetting":{
  164. "hasScoreDetail":true,
  165. "hasTips":true,
  166. "hasKnowledgeMap":true,
  167. "hasWrongTopic":true,
  168. "hasCorrection":true,
  169. "hasExactCheck":true,
  170. "hasSpecific":true,
  171. "hasCommon":true,
  172. "hasCommonFront": true,
  173. "hasAnswerTogether":true
  174. }
  175. }
  176. TPL;
  177. $ispClassConfig = <<<TPL
  178. {
  179. "commonTopicMethod":{
  180. "scoreRateStart":20,
  181. "scoreRateEnd":65
  182. },
  183. "studentLevelDivide":{
  184. "studentLevel":3,
  185. "rankBase":"score",
  186. "levelDetails":[
  187. {
  188. "level":"A",
  189. "valueEnd":{
  190. "score":100,
  191. "grade":20
  192. },
  193. "valueStart":{
  194. "score":81,
  195. "grade":0
  196. },
  197. "trainPushDetail":{
  198. "specificNumber":3,
  199. "maxMethodTopic":2,
  200. "methodTopicLevel":1
  201. },
  202. "errorPushDetail": {
  203. "smallTopic": 0,
  204. "largeTopic": 80,
  205. "difficulty": [1,2,3]
  206. }
  207. },
  208. {
  209. "level":"B",
  210. "valueEnd":{
  211. "score":80,
  212. "grade":60
  213. },
  214. "valueStart":{
  215. "score":61,
  216. "grade":21
  217. },
  218. "trainPushDetail":{
  219. "specificNumber":3,
  220. "maxMethodTopic":2,
  221. "methodTopicLevel":2
  222. },
  223. "errorPushDetail": {
  224. "smallTopic": 0,
  225. "largeTopic": 80,
  226. "difficulty": [1,2,3]
  227. }
  228. },
  229. {
  230. "level":"C",
  231. "valueEnd":{
  232. "score":60,
  233. "grade":100
  234. },
  235. "valueStart":{
  236. "score":0,
  237. "grade":61
  238. },
  239. "trainPushDetail":{
  240. "specificNumber":3,
  241. "maxMethodTopic":2,
  242. "methodTopicLevel":3
  243. },
  244. "errorPushDetail": {
  245. "smallTopic": 0,
  246. "largeTopic": 80,
  247. "difficulty": [1,2,3]
  248. }
  249. }
  250. ]
  251. },
  252. "errorTypeSetting":{
  253. "hasScoreDetail":true,
  254. "hasTips":true,
  255. "hasKnowledgeMap":true,
  256. "hasWrongTopic":true,
  257. "hasCorrection":true,
  258. "hasExactCheck":true,
  259. "hasSpecific":true,
  260. "hasCommon":true,
  261. "hasCommonFront": true,
  262. "hasAnswerTogether":true
  263. }
  264. }
  265. TPL;
  266. $ispStudentConfig = <<<TPL
  267. {
  268. "studentLevelDivide":{
  269. "levelDetails":[
  270. {
  271. "errorPushDetail": {
  272. "smallTopic": 0,
  273. "largeTopic": 80,
  274. "difficulty": [1,2,3]
  275. },
  276. "trainPushDetail":{
  277. "specificNumber":3,
  278. "maxMethodTopic":2,
  279. "methodTopicLevel":3
  280. }
  281. }
  282. ]
  283. },
  284. "errorTypeSetting":{
  285. "hasScoreDetail":true,
  286. "hasTips":true,
  287. "hasKnowledgeMap":true,
  288. "hasWrongTopic":true,
  289. "hasCorrection":true,
  290. "hasExactCheck":true,
  291. "hasSpecific":true,
  292. "hasCommon":true,
  293. "hasCommonFront": true,
  294. "hasAnswerTogether":true
  295. }
  296. }
  297. TPL;
  298. foreach ($templates as $template){
  299. if($template['product_type']==1 && $template['target_type']==1){
  300. $wrongBook['class'] = 1;
  301. }
  302. if($template['product_type']==1 && $template['target_type']==2){
  303. $wrongBook['student'] = 1;
  304. }
  305. if($template['product_type']==30 && $template['target_type']==1){
  306. $isp['class'] = 1;
  307. }
  308. if($template['product_type']==30 && $template['target_type']==2){
  309. $isp['student'] = 1;
  310. }
  311. }
  312. $values = array();
  313. if (!isset($wrongBook['class'])) {
  314. $values[] = "('班级默认模板',1,1,'" . $wrongBookClassConfig . "',41,1,'" . time() . "',0)";
  315. }
  316. if (!isset($wrongBook['student'])) {
  317. $values[] = "('学生默认模板',1,2,'" . $wrongBookStudentConfig . "',41,1,'" . time() . "',0)";
  318. }
  319. if (!isset($isp['class'])) {
  320. $values[] = "('班级默认模板',30,1,'" . $ispClassConfig . "',41,1,'" . time() . "',0)";
  321. }
  322. if (!isset($isp['student'])) {
  323. $values[] = "('学生默认模板',30,2,'" . $ispStudentConfig . "',41,1,'" . time() . "',0)";
  324. }
  325. if ($values) {
  326. $sql = "insert into product_template(`template_name`,`product_type`,`target_type`,`config_text`,`subject_id`,`is_default`,`create_time`,`is_beta`) values " . implode(',', $values);
  327. $con->createCommand($sql)->execute();
  328. }
  329. }
  330. }