YearReportCommand.php 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  1. <?php
  2. class YearReportCommand extends CConsoleCommand {
  3. public function init() {
  4. parent::init();
  5. @ini_set('memory_limit', '1024M');
  6. set_time_limit(0);
  7. }
  8. public $authUsername = '';
  9. public function actionIndex($school_id='',$class_zip_id='',$YII_ENV='',$force='') {
  10. if(!$YII_ENV){
  11. $YII_ENV = "production";
  12. $file_html_url = "http://zsyas2.zhixinhuixue.com";
  13. }else{
  14. if($YII_ENV == 'development'){
  15. $YII_ENV = 'dev';
  16. }
  17. $file_html_url = "http://xbas2.".$YII_ENV.".xiaoben.com";
  18. }
  19. $semesterId = 0;
  20. $data = array();
  21. $coachName = array();
  22. $year = 2018;
  23. $year_next = $year+1;
  24. if ($year%4==0&&($year%100!=0 || $year%400==0)){
  25. $days = 366;
  26. }else{
  27. $days = 365;
  28. }
  29. $weeks = date("W", mktime(0, 0, 0, 12, 28, $year));
  30. $start_time = mktime(0,0,0,1,1,$year);
  31. $end_time = mktime(0,0,0,1,1,$year_next);
  32. // 连接业务库
  33. $school_dsn = 'mysql:host='.Yii::app()->params["default_server"]['addr'].';dbname='.Yii::app()->params["default_db"]['name'].';';
  34. $school_dbh = new PDO($school_dsn,Yii::app()->params["default_server"]['username'],Yii::app()->params["default_server"]['password'],array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES "utf8";'));
  35. if($class_zip_id && !$school_id){
  36. exit('请指定学校Id!');
  37. }
  38. $school_str = '';
  39. //测试
  40. // $school_id = 3854;
  41. if ($school_id) {
  42. $school_str = $school_id;
  43. } else {
  44. // 获取所有可用的学校
  45. $school_obj = $school_dbh->query('SELECT school_id FROM `school` WHERE `status`=0');
  46. $school_info= $school_obj->fetchAll(PDO::FETCH_ASSOC);
  47. if (empty($school_info)) {
  48. exit('未找到可用的学校!');
  49. }
  50. $school_array = array();
  51. foreach ($school_info as $school) {
  52. array_push($school_array, $school['school_id']);
  53. }
  54. $school_str = implode(',', $school_array);
  55. }
  56. if(!$school_str){
  57. exit('未找到学校数据库链接信息!');
  58. }
  59. // 找出学校的链接信息
  60. $data_obj = $school_dbh->query('SELECT * FROM `database` WHERE `school_id` IN ('.$school_str.')');
  61. if(!$data_obj){
  62. exit('未找到学校数据库链接信息!');
  63. }
  64. $data_info= $data_obj->fetchAll(PDO::FETCH_ASSOC);
  65. if (empty($data_info)) {
  66. exit('未找到学校数据库链接信息!');
  67. }
  68. $coach_obj = $school_dbh->query('select coach_id,coach_name,school_id from coach where `status` = 0 and school_id in ('.$school_str.')');
  69. if($coach_obj){
  70. $coach_info= $coach_obj->fetchAll(PDO::FETCH_ASSOC);//获取学管
  71. if($coach_info){
  72. foreach($coach_info as $k=>$v){
  73. $coachName['school_id'] = $v['coach_name'];
  74. }
  75. }
  76. }
  77. // 关闭链接
  78. $school_dbh = null;
  79. $my_path = dirname(dirname(dirname(__FILE__)));
  80. foreach ($data_info as $data) {
  81. echo 'STARTING==>'.$data['school_id']. "\n";
  82. $schoolId = $data['school_id'];
  83. $temp_dsn = 'mysql:host='.$data['database_host'].';dbname='.$data['database_name'].';';
  84. $temp_dbh = new PDO($temp_dsn,$data['database_user'],$data['database_password'],array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES "utf8";'));
  85. if(isset($coachName[$data['school_id']])){
  86. $this->authUsername = $data['school_id'].'_'.$coachName[$data['school_id']];
  87. }
  88. $temp_obj = $temp_dbh->query('select semester_id from semester where `status` = 1');
  89. $temp_info= $temp_obj->fetchAll(PDO::FETCH_ASSOC);//获取当前学期
  90. $temp_obj = $temp_dbh->query('select semester_id from semester where `status` = 1');
  91. $temp_info= $temp_obj->fetchAll(PDO::FETCH_ASSOC);//获取当前学期
  92. if($temp_info){
  93. foreach($temp_info as $sem){
  94. $semesterId = $sem['semester_id'];
  95. }
  96. if($semesterId){
  97. if($class_zip_id){
  98. $temp_obj = $temp_dbh->query("select class_id,class_name,report_status from class where class_id = {$class_zip_id} and semester_id = {$semesterId}");
  99. $temp_info= $temp_obj->fetchAll(PDO::FETCH_ASSOC);//获取当前指定学校指定班级
  100. if(!$temp_info){
  101. exit('学校Id或班级Id错误!');
  102. }else{
  103. $class_info= $temp_info;
  104. }
  105. }else{
  106. $class_obj = $temp_dbh->query("select class_id,class_name,report_status from class where semester_id = {$semesterId}");
  107. $class_info= $class_obj->fetchAll(PDO::FETCH_ASSOC);//获取学校下的班级
  108. }
  109. if($class_info){
  110. foreach($class_info as $class){
  111. // if($class['class_id'] != '25937518121715281'){
  112. // continue;
  113. // }
  114. if(!$force){
  115. if($class['report_status'] == 2){
  116. continue;
  117. }
  118. }
  119. echo 'STARTING==>'.$class['class_name']. "\n";
  120. $classId = $class['class_id'];
  121. $studentIds = array();
  122. $pdfArr = array();
  123. $pdfNames = array();
  124. $stu_obj = $temp_dbh->query("select student_id from student_class_relation where class_id = {$class['class_id']} and status = 0");
  125. $stu_info= $stu_obj->fetchAll(PDO::FETCH_ASSOC);//获取班级下的学生
  126. if($stu_info){
  127. if($class['report_status'] != 1){
  128. $temp_dbh->exec("update class set report_status = 1 where class_id = {$class['class_id']}");//正在生成
  129. }
  130. $class_name = $class['class_name'];//班级名称
  131. foreach($stu_info as $studentId){
  132. //初始化数据
  133. $methodIds = array();
  134. $bestExam = array();
  135. $totalExamIds = array();
  136. $totalExamIds_subjectId = array();
  137. $exam_count = array(
  138. 9=>array(//语文
  139. 'total_count' => 0,
  140. 'real_count' => 0,
  141. 'del_count' => 0
  142. ),
  143. 3=>array(//数学
  144. 'total_count' => 0,
  145. 'real_count' => 0,
  146. 'del_count' => 0
  147. ),
  148. 8=>array(//英语
  149. 'total_count' => 0,
  150. 'real_count' => 0,
  151. 'del_count' => 0
  152. ),
  153. 15=>array(//政治
  154. 'total_count' => 0,
  155. 'real_count' => 0,
  156. 'del_count' => 0
  157. ),
  158. 16=>array(//历史
  159. 'total_count' => 0,
  160. 'real_count' => 0,
  161. 'del_count' => 0
  162. ),
  163. 17=>array(//地理
  164. 'total_count' => 0,
  165. 'real_count' => 0,
  166. 'del_count' => 0
  167. ),
  168. 12=>array(//物理
  169. 'total_count' => 0,
  170. 'real_count' => 0,
  171. 'del_count' => 0
  172. ),
  173. 13=>array(//化学
  174. 'total_count' => 0,
  175. 'real_count' => 0,
  176. 'del_count' => 0
  177. ),
  178. 14=>array(//生物
  179. 'total_count' => 0,
  180. 'real_count' => 0,
  181. 'del_count' => 0
  182. ),
  183. 19=>array(//文综
  184. 'total_count' => 0,
  185. 'real_count' => 0,
  186. 'del_count' => 0
  187. ),
  188. 18=>array(//理综
  189. 'total_count' => 0,
  190. 'real_count' => 0,
  191. 'del_count' => 0
  192. ),
  193. );//考试状况
  194. $method_mes = array(
  195. 'count' => 0,
  196. 'name' => array(),
  197. );//数学考点状况
  198. $isp_mes = array(
  199. 'isp_days' => 0,
  200. 'isp_create' => 0,
  201. 'isp_down' => 0,
  202. 'isp_down_ratio' => 0
  203. );//数学个性化学习宝状况
  204. $best_exam_mes = array(
  205. 9=>array(//语文
  206. 'name' => '',
  207. 'score' => 0,
  208. 'scoring' => 0,
  209. 'grade_no' => 0,
  210. 'grade_total_no'=>0,
  211. 'class_no'=>0,
  212. 'class_total_no'=>0,
  213. ),
  214. 3=>array(//数学
  215. 'name' => '',
  216. 'score' => 0,
  217. 'scoring' => 0,
  218. 'grade_no' => 0,
  219. 'grade_total_no'=>0,
  220. 'class_no'=>0,
  221. 'class_total_no'=>0,
  222. ),
  223. 8=>array(//英语
  224. 'name' => '',
  225. 'score' => 0,
  226. 'scoring' => 0,
  227. 'grade_no' => 0,
  228. 'grade_total_no'=>0,
  229. 'class_no'=>0,
  230. 'class_total_no'=>0,
  231. ),
  232. 15=>array(//政治
  233. 'name' => '',
  234. 'score' => 0,
  235. 'scoring' => 0,
  236. 'grade_no' => 0,
  237. 'grade_total_no'=>0,
  238. 'class_no'=>0,
  239. 'class_total_no'=>0,
  240. ),
  241. 16=>array(//历史
  242. 'name' => '',
  243. 'score' => 0,
  244. 'scoring' => 0,
  245. 'grade_no' => 0,
  246. 'grade_total_no'=>0,
  247. 'class_no'=>0,
  248. 'class_total_no'=>0,
  249. ),
  250. 17=>array(//地理
  251. 'name' => '',
  252. 'score' => 0,
  253. 'scoring' => 0,
  254. 'grade_no' => 0,
  255. 'grade_total_no'=>0,
  256. 'class_no'=>0,
  257. 'class_total_no'=>0,
  258. ),
  259. 12=>array(//物理
  260. 'name' => '',
  261. 'score' => 0,
  262. 'scoring' => 0,
  263. 'grade_no' => 0,
  264. 'grade_total_no'=>0,
  265. 'class_no'=>0,
  266. 'class_total_no'=>0,
  267. ),
  268. 13=>array(//化学
  269. 'name' => '',
  270. 'score' => 0,
  271. 'scoring' => 0,
  272. 'grade_no' => 0,
  273. 'grade_total_no'=>0,
  274. 'class_no'=>0,
  275. 'class_total_no'=>0,
  276. ),
  277. 14=>array(//生物
  278. 'name' => '',
  279. 'score' => 0,
  280. 'scoring' => 0,
  281. 'grade_no' => 0,
  282. 'grade_total_no'=>0,
  283. 'class_no'=>0,
  284. 'class_total_no'=>0,
  285. ),
  286. 19=>array(//文综
  287. 'name' => '',
  288. 'score' => 0,
  289. 'scoring' => 0,
  290. 'grade_no' => 0,
  291. 'grade_total_no'=>0,
  292. 'class_no'=>0,
  293. 'class_total_no'=>0,
  294. ),
  295. 18=>array(//理综
  296. 'name' => '',
  297. 'score' => 0,
  298. 'scoring' => 0,
  299. 'grade_no' => 0,
  300. 'grade_total_no'=>0,
  301. 'class_no'=>0,
  302. 'class_total_no'=>0,
  303. ),
  304. );//最佳考试
  305. $score_mes = array(
  306. 9=>array(//语文
  307. 'rise_count' => 0,
  308. 'drop_count' => 0,
  309. 'class_top_ten' => 0,
  310. 'unified_top_ten' => 0,
  311. ),
  312. 3=>array(//数学
  313. 'rise_count' => 0,
  314. 'drop_count' => 0,
  315. 'class_top_ten' => 0,
  316. 'unified_top_ten' => 0,
  317. ),
  318. 8=>array(//英语
  319. 'rise_count' => 0,
  320. 'drop_count' => 0,
  321. 'class_top_ten' => 0,
  322. 'unified_top_ten' => 0,
  323. ),
  324. 15=>array(//政治
  325. 'rise_count' => 0,
  326. 'drop_count' => 0,
  327. 'class_top_ten' => 0,
  328. 'unified_top_ten' => 0,
  329. ),
  330. 16=>array(//历史
  331. 'rise_count' => 0,
  332. 'drop_count' => 0,
  333. 'class_top_ten' => 0,
  334. 'unified_top_ten' => 0,
  335. ),
  336. 17=>array(//地理
  337. 'rise_count' => 0,
  338. 'drop_count' => 0,
  339. 'class_top_ten' => 0,
  340. 'unified_top_ten' => 0,
  341. ),
  342. 12=>array(//物理
  343. 'rise_count' => 0,
  344. 'drop_count' => 0,
  345. 'class_top_ten' => 0,
  346. 'unified_top_ten' => 0,
  347. ),
  348. 13=>array(//化学
  349. 'rise_count' => 0,
  350. 'drop_count' => 0,
  351. 'class_top_ten' => 0,
  352. 'unified_top_ten' => 0,
  353. ),
  354. 14=>array(//生物
  355. 'rise_count' => 0,
  356. 'drop_count' => 0,
  357. 'class_top_ten' => 0,
  358. 'unified_top_ten' => 0,
  359. ),
  360. 19=>array(//文综
  361. 'rise_count' => 0,
  362. 'drop_count' => 0,
  363. 'class_top_ten' => 0,
  364. 'unified_top_ten' => 0,
  365. ),
  366. 18=>array(//理综
  367. 'rise_count' => 0,
  368. 'drop_count' => 0,
  369. 'class_top_ten' => 0,
  370. 'unified_top_ten' => 0,
  371. ),
  372. );//成绩状况
  373. $contin_weeks = 1;//连续周数
  374. $student_id = (string)$studentId['student_id'];
  375. //个性化学习宝使用天数
  376. $res = $this->getHttp('order/coach/days/'.$student_id.'/'.$year, 'get');
  377. if($res && $res['data']){
  378. $isp_mes['isp_days'] = $res['data'];
  379. }
  380. //获取学生姓名
  381. $stu_name_obj = $temp_dbh->query("select realname from student_info where student_id = {$student_id}");
  382. $stu_name_info= $stu_name_obj->fetchAll(PDO::FETCH_ASSOC);//获取学生姓名
  383. if($stu_name_info){
  384. foreach($stu_name_info as $realname){
  385. $stu_name = $realname['realname'];
  386. }
  387. }
  388. //考试状况
  389. $sql = "select e.create_time,e.name,e.exam_id,e.exam_group_id,e.subject_id,spr.is_del,spr.scoring,spr.is_isp_pdf,spr.is_wbisp_pdf,spr.is_two_isp_download,spr.is_three_isp_download,p.method_ids,p.score from exam e "
  390. . "left join exam_group eg on e.exam_group_id = eg.exam_group_id "
  391. . "left join paper p on p.exam_id = e.exam_id "
  392. . "left join student_paper_relation spr on e.exam_id = spr.exam_id "
  393. . "where spr.student_id = {$student_id} and e.status = 1 and e.upload_status = 2 and eg.status = 2 and eg.mark_status = 2 and e.create_time > {$start_time} and e.create_time < {$end_time} "
  394. . "order by e.create_time asc";
  395. $exam_obj = $temp_dbh->query($sql);
  396. $exam_info= $exam_obj->fetchAll(PDO::FETCH_ASSOC);//获取考试情况
  397. if($exam_info){
  398. foreach($exam_info as $k=>$v){
  399. //考试状况
  400. //var_dump($v);exit;
  401. if($v['subject_id'] == 3 || $v['subject_id'] == 6){
  402. $totalExamIds_subjectId[$v['exam_id']] = 3;
  403. $exam_count[3]['total_count'] ++;
  404. if($v['is_del'] == 1){
  405. $exam_count[3]['del_count'] ++;
  406. }else{
  407. $exam_count[3]['real_count'] ++;
  408. }
  409. //考点状况
  410. $methodArr = explode(",",$v['method_ids']);
  411. if($methodArr){
  412. foreach($methodArr as $method){
  413. if(is_numeric($method)){
  414. $methodIds[] = $method;
  415. }
  416. }
  417. }
  418. //个性化学习宝状况
  419. if($v['is_isp_pdf'] == 1){
  420. $isp_mes['isp_create'] ++;
  421. if($v['is_two_isp_download'] == 1){
  422. $isp_mes['isp_down'] ++;
  423. }
  424. }
  425. if($v['is_wbisp_pdf'] == 1){
  426. $isp_mes['isp_create'] ++;
  427. if($v['is_three_isp_download'] == 1){
  428. $isp_mes['isp_down'] ++;
  429. }
  430. }
  431. //最佳考试
  432. $bestExam[$v['exam_group_id']]['exam_id'] = $v['exam_id'];
  433. $bestExam[$v['exam_group_id']]['name'] = $v['name'];
  434. $bestExam[$v['exam_group_id']]['subject_id'] = 3;
  435. $bestExam[$v['exam_group_id']]['score'] = $v['score'];
  436. $bestExam[$v['exam_group_id']]['scoring'] = $v['scoring'];
  437. }else{
  438. $totalExamIds_subjectId[$v['exam_id']] = $v['subject_id'];
  439. $exam_count[$v['subject_id']]['total_count'] ++;
  440. if($v['is_del'] == 1){
  441. $exam_count[$v['subject_id']]['del_count'] ++;
  442. }else{
  443. $exam_count[$v['subject_id']]['real_count'] ++;
  444. }
  445. //最佳考试
  446. $bestExam[$v['exam_group_id']]['exam_id'] = $v['exam_id'];
  447. $bestExam[$v['exam_group_id']]['name'] = $v['name'];
  448. $bestExam[$v['exam_group_id']]['subject_id'] = $v['subject_id'];
  449. $bestExam[$v['exam_group_id']]['score'] = $v['score'];
  450. $bestExam[$v['exam_group_id']]['scoring'] = $v['scoring'];
  451. }
  452. //连续周数
  453. $totalExamIds[] = $v['exam_id'];
  454. if(!isset($current_week)){
  455. $current_week = date("W",$v['create_time']);
  456. }else{
  457. $week_cur = date("W",$v['create_time']);
  458. if($week_cur = $current_week + 1){
  459. $contin_weeks ++;
  460. }
  461. }
  462. }
  463. $totalExamIds = array_unique($totalExamIds);
  464. //考点状况
  465. if($methodIds){
  466. $count_methods = array();
  467. foreach($methodIds as $kmed=>$vmed){
  468. if(!isset($count_methods[$vmed])){
  469. $count_methods[$vmed] = 1;
  470. }else{
  471. $count_methods[$vmed]++;
  472. }
  473. }
  474. $method_mes['count'] = count(array_unique($methodIds));
  475. unset($methodIds);
  476. if($count_methods){
  477. arsort($count_methods);
  478. $i = 1;
  479. $methodArrIds = array();
  480. foreach($count_methods as $k=>$v){
  481. if($i < 6){
  482. $methodArrIds[] = $k;
  483. }
  484. $i++;
  485. }
  486. $methods = $this->apiPost('/special/methods', array('methodIds' => $methodArrIds));
  487. if($methods && !isset($methods->error)){
  488. foreach($methods as $k=>$v){
  489. $method_mes['name'][] = $v->method_name;
  490. }
  491. }
  492. }
  493. }
  494. //数学个性化学习宝状况
  495. if($isp_mes['isp_down'] && $isp_mes['isp_create']){
  496. $isp_mes['isp_down_ratio'] = round($isp_mes['isp_down']/$isp_mes['isp_create'],4) * 100 .'%';
  497. }
  498. //最佳考试信息
  499. if($bestExam){
  500. $best_exam_msg = array();
  501. foreach($bestExam as $k=>$v){
  502. $examIds = array();
  503. $examid_obj = $temp_dbh->query("select exam_id from exam where exam_group_id = {$k}");
  504. $examid_info= $examid_obj->fetchAll(PDO::FETCH_ASSOC);////获取groupId对应的examId
  505. if($examid_info){
  506. foreach($examid_info as $edata){
  507. $examIds[] = $edata['exam_id'];
  508. }
  509. }
  510. if($examIds){
  511. foreach($examIds as $examIdSc){
  512. $msg_obj = $temp_dbh->query("select class_id,student_id,is_del,scoring from student_paper_relation where exam_id = {$examIdSc} order by scoring desc");
  513. $msg_info= $msg_obj->fetchAll(PDO::FETCH_ASSOC);
  514. if($msg_info){
  515. $no = 1;
  516. $no_grade = 1;//年级排名
  517. $no_class = 1;//班级排名
  518. $stu_no_grade = 1;//学生年级排名
  519. $stu_no_class = 1;//学生班级排名
  520. $total_grade = 0;
  521. $total_real_grade = 0;
  522. $total_class = 0;
  523. $total_real_class = 0;
  524. foreach($msg_info as $kk=>$vv){
  525. if($no == 1){
  526. $current_scoring = $vv['scoring'];
  527. }else{
  528. if($vv['scoring'] < $current_scoring){
  529. $no_grade ++;
  530. }
  531. }
  532. if($vv['is_del'] == 0){
  533. $total_real_grade ++;
  534. }
  535. if((string)$vv['class_id'] === (string)$classId){
  536. if(!isset($current_class_scoring)){
  537. $current_class_scoring = $vv['scoring'];
  538. }else{
  539. if($vv['scoring'] < $current_class_scoring){
  540. $no_class ++;
  541. }
  542. }
  543. if($vv['is_del'] == 0){
  544. $total_real_class ++;
  545. }
  546. $total_class ++;
  547. }
  548. if((string)$vv['student_id'] === (string)$student_id){
  549. $stu_no_grade = $no_grade;
  550. $stu_no_class = $no_class;
  551. }
  552. $total_grade ++;
  553. $no++;
  554. }
  555. //最佳考试定义:数值“年级排名/年级有效人数”最小的一次考试
  556. if(!isset($best_exam_msg[$v['subject_id']])){
  557. if($stu_no_grade==0 || $total_real_grade==0){
  558. $temp_min = 0;
  559. }else{
  560. $temp_min = round($stu_no_grade/$total_real_grade,4);
  561. }
  562. if($temp_min != 0){
  563. $best_exam_mes[$v['subject_id']]['name'] = $v['name'];
  564. $best_exam_mes[$v['subject_id']]['score'] = $v['score'];
  565. $best_exam_mes[$v['subject_id']]['scoring'] = $v['scoring'];
  566. $best_exam_mes[$v['subject_id']]['grade_no'] = $stu_no_grade;
  567. $best_exam_mes[$v['subject_id']]['grade_total_no'] = $total_grade;
  568. $best_exam_mes[$v['subject_id']]['class_no'] = $stu_no_class;
  569. $best_exam_mes[$v['subject_id']]['class_total_no'] = $total_class;
  570. }
  571. }else{
  572. if($stu_no_grade==0 || $total_real_grade==0){
  573. $tep = 0;
  574. }else{
  575. $tep = round($stu_no_grade/$total_real_grade,4);
  576. }
  577. //$tep = round($stu_no_grade/$total_real_grade,4);
  578. if($tep < $temp_min && $tep!=0){
  579. $temp_min = $tep;
  580. $best_exam_mes[$v['subject_id']]['name'] = $v['name'];
  581. $best_exam_mes[$v['subject_id']]['score'] = $v['score'];
  582. $best_exam_mes[$v['subject_id']]['scoring'] = $v['scoring'];
  583. $best_exam_mes[$v['subject_id']]['grade_no'] = $stu_no_grade;
  584. $best_exam_mes[$v['subject_id']]['grade_total_no'] = $total_grade;
  585. $best_exam_mes[$v['subject_id']]['class_no'] = $stu_no_class;
  586. $best_exam_mes[$v['subject_id']]['class_total_no'] = $total_class;
  587. }
  588. }
  589. //成绩状况(统计班级上升下降次数,班级前十)
  590. if($stu_no_class <= $total_real_class * 0.1){
  591. $score_mes[$v['subject_id']]['class_top_ten']++;
  592. }
  593. if(!isset($current_class_no)){
  594. $current_class_no = $stu_no_class;
  595. }else{
  596. if($stu_no_class > $current_class_no){
  597. $score_mes[$v['subject_id']]['rise_count']++;
  598. }else if($stu_no_class < $current_class_no){
  599. $score_mes[$v['subject_id']]['drop_count']++;
  600. }
  601. }
  602. }
  603. unset($msg);
  604. }
  605. }
  606. }
  607. }
  608. //统考排名
  609. $tj_obj = $temp_dbh->query("select examinfo from cylet where cylet_type = 2 and create_time > {$start_time} and create_time < {$end_time}");
  610. $tj_info= $tj_obj->fetchAll(PDO::FETCH_ASSOC);//获取统考情况
  611. $cylet_exam_ids = array();
  612. if($tj_info){
  613. foreach($tj_info as $cylet){
  614. $cyletArr = json_decode($cylet['examinfo'],true);
  615. if(isset($cyletArr['exam'])){
  616. foreach($cyletArr['exam'] as $examCy){
  617. if(in_array($examCy,$totalExamIds)){
  618. $cylet_exam_ids[] = $examCy;
  619. }
  620. }
  621. }
  622. }
  623. unset($tj_info);
  624. }
  625. if($cylet_exam_ids){
  626. foreach($cylet_exam_ids as $cexamId){
  627. $tempp_obj = $temp_dbh->query("select class_id,student_id,is_del,scoring from student_paper_relation where exam_id = {$cexamId} order by scoring desc");
  628. $tempp_info= $tempp_obj->fetchAll(PDO::FETCH_ASSOC);//获取统考情况
  629. if($tempp_info){
  630. $no_cylet_grade = 1;//年级排名
  631. $stu_no_cylet_grade = 1;//学生年级排名
  632. $total_cylet_grade = 0;
  633. $total_cylet_real_grade = 0;
  634. foreach($tempp_info as $cyScore){
  635. if($cyScore['is_del'] == 0){
  636. $total_cylet_real_grade ++;
  637. }
  638. $total_cylet_grade ++;
  639. if(!isset($current_cylet_scoring)){
  640. $current_cylet_scoring = $cyScore['scoring'];
  641. }else{
  642. if($cyScore['scoring'] < $current_cylet_scoring){
  643. $no_cylet_grade ++;
  644. }
  645. }
  646. if((string)$vv['student_id'] === (string)$studentId){
  647. $stu_no_cylet_grade = $no_cylet_grade;
  648. }
  649. }
  650. if($stu_no_cylet_grade <= $total_cylet_real_grade * 0.1){
  651. $score_mes[$totalExamIds_subjectId[$cexamId]]['unified_top_ten']++;
  652. }
  653. }
  654. }
  655. }
  656. }
  657. unset($exam_info);
  658. //var_dump(dirname(dirname(dirname(__FILE__))));exit;
  659. $data['stu_name'] = isset($stu_name)?$stu_name:'';//学生姓名
  660. $data['class_name'] = isset($class_name)?$class_name:'';//班级名称
  661. $data['year'] = $year;
  662. $data['year_next'] = $year_next;
  663. $data['days'] = $days;
  664. $data['weeks'] = $weeks;
  665. $data['contin_weeks'] = $contin_weeks;
  666. $data['exam_count'] = $exam_count;//考试状况
  667. $data['score_mes'] = $score_mes;//成绩状况
  668. $data['best_exam_mes'] = $best_exam_mes;//最佳考试
  669. $data['method_mes'] = $method_mes;//考点状况
  670. $data['isp_mes'] = $isp_mes;//个性化学习宝状况
  671. $html = $this->viewRender("year_report", $data, true);
  672. $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/assets/'; //存放生成的HTML路径
  673. $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/assets/pdf/yearReport/' . $schoolId . "/"; //存放生成的PDF路径
  674. $pdfurl = '/assets/pdf/yearReport/' . $schoolId . "/";
  675. if (!is_dir($htmlpath)) {
  676. if (!mkdir($htmlpath, 0777, true)) {
  677. exit('Create directory fail: ' . $htmlpath);
  678. }
  679. }if (!is_dir($pdfpath)) {
  680. if (!mkdir($pdfpath, 0777, true)) {
  681. exit('Create directory fail1: ' . $pdfpath);
  682. }
  683. }
  684. $htmlpath.=$student_id . ".html";
  685. $f = fopen($htmlpath, "w");
  686. fwrite($f, $html);
  687. $htmlurl = '/assets/' . $student_id . ".html"; //访问HTML的路径
  688. if (Yii::app()->basePath == "C:\wamp\www\zsyas2\protected") {//本地的basePath
  689. $htmlurl = "http://zsyte.dev.xueping.com/html/%E9%A6%96%E9%A1%B5.html";
  690. // $pdffname = str_replace(".", "。", $exam_info['class_name'] . "-" . $exam_info['exam_name']);
  691. // $pdffname = str_replace(" ", "", $pdffname) . ".pdf";
  692. // $pdffname=iconv("UTF-8", "GBK",$pdffname);
  693. $pdffname=$classId."-".$studentId.".pdf";
  694. $pdfpath = $pdfpath . $pdffname;
  695. $pdfurl = $pdfurl . $pdffname;
  696. $commond = Yii::app()->params['phantomjs'] . " "
  697. . Yii::app()->params['html2pdf'] . " "
  698. . " file://" . $htmlpath
  699. . " {$pdfpath}"
  700. . " 176mm*250mm ''";
  701. } else {
  702. $htmlurl = $file_html_url . $htmlurl;
  703. // $htmlurl = "http://coa.cn/assets/25631607280893986.html";
  704. $pdffname=$classId.'-'.$student_id.".pdf";
  705. $pdfpath = $pdfpath . $pdffname;
  706. $pdfurl = $pdfurl . $pdffname;
  707. $top_meg = $class_name.'-'.$stu_name."-年度使用报告";
  708. $commond = Yii::app()->params['phantomjs_server'] . " "
  709. . Yii::app()->basePath . '/../js/html2pdf.js' . " "
  710. . " {$htmlurl}"
  711. . " {$pdfpath}"
  712. . " 176mm*250mm {$top_meg}";
  713. }
  714. $set_charset = 'export LANG=en_US.UTF-8;';
  715. exec($set_charset.$commond, $res, $code);
  716. if(isset($res[0])){
  717. if (strpos($res[0], 'succeed') !== false) {
  718. if ($this->file_exists($pdfpath)) {
  719. $pdfArr[] = $pdfpath;
  720. $pdfNames[] = $stu_name;
  721. echo $stu_name.'pdf生成成功!'. "\n";
  722. }
  723. } else {
  724. }
  725. @unlink($htmlpath);
  726. }
  727. }
  728. if($pdfArr){
  729. echo $class_name.'pdf生成成功!'. "\n";
  730. $report_name = $class_name.$year."年度报告.zip";
  731. $filepath = str_replace("protected", "", Yii::app()->basePath) . '/upload/year_report/'.$schoolId."/"; //存放生成的PDF路径
  732. if (!is_dir($filepath)) {
  733. if (!mkdir($filepath, 0777, true)) {
  734. echo 'Create directory fail1: ' . $filepath. "\n";
  735. }
  736. }
  737. $filename = dirname(dirname(dirname(__FILE__))).'/upload/year_report/'.$schoolId."/".$classId.'_'.$year.".zip"; //最终生成的文件名(含路径)
  738. $zip = new ZipArchive();//使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
  739. if ($zip->open($filename, ZIPARCHIVE::OVERWRITE)!==TRUE) {
  740. echo $class_name.'zip生成失败!'. "\n";
  741. }else{
  742. foreach ($pdfArr as $k=>$val) {
  743. $pdfNames[$k] = iconv("UTF-8","GBK//IGNORE",$pdfNames[$k]);
  744. $res=$zip->addFile($val,$classId.$pdfNames[$k].'.pdf');
  745. }
  746. $zip->close();//关闭
  747. //生成完成
  748. $filename = addslashes($filename);
  749. $temp_dbh->exec("update class set report_status = 2,report_url='{$filename}' where class_id = {$classId}");
  750. echo $class_name.'zip生成成功!'. "\n";
  751. }
  752. }else{
  753. echo $class_name.'pdf生成失败!'. "\n";
  754. }
  755. }
  756. }
  757. }
  758. unset($class_info);
  759. }
  760. }
  761. }
  762. }
  763. public function apiPost($path, $arr, $type = 0)
  764. {
  765. $ch = @curl_init();
  766. $result = FALSE;
  767. if ($ch) {
  768. $data = json_encode($arr);
  769. $url = Yii::app()->params['api'][$type]['prefix'] . $path;
  770. $username = Yii::app()->params['api'][$type]['username'];
  771. $password = Yii::app()->params['api'][$type]['password'];
  772. // Digest认证
  773. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  774. curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
  775. // 不输出头部
  776. curl_setopt($ch, CURLOPT_HEADER, 0);
  777. // curl_exec 获取到的内容不直接输出, 而是返回
  778. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  779. // 请求重启路由器的地址 传参 进行重启
  780. curl_setopt($ch, CURLOPT_URL, $url);
  781. curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)');
  782. curl_setopt($ch, CURLOPT_POST, 1);
  783. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  784. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  785. 'Content-Type: application/json',
  786. 'Content-Length: ' . strlen($data),
  787. ));
  788. if (!curl_errno($ch)) {
  789. $result = json_decode(curl_exec($ch));
  790. }
  791. // 释放资源
  792. curl_close($ch);
  793. }
  794. return $result;
  795. }
  796. private function check_zip($file_path) {
  797. if (substr($file_path, strlen($file_path) - 4, 4) == ".zip") {
  798. if (file_exists($file_path)) {
  799. return true;
  800. }
  801. }
  802. return false;
  803. }
  804. /**
  805. * 获取接口数据
  806. * @param $url
  807. * @param $method
  808. * @param array $params
  809. * @return array
  810. */
  811. private function getHttp($url,$method,$params = array()){
  812. $res = http($url, $method, $this->authUsername, $params);
  813. $res = $this->handleRes($res);
  814. return $res;
  815. }
  816. /**
  817. * 处理接口返回的数据
  818. * @param $res
  819. * @return array
  820. */
  821. public function handleRes($res){
  822. $result = array(
  823. 'status' => 0,
  824. 'data' => array(),
  825. 'msg' => '暂无数据',
  826. );
  827. if($res){
  828. $res = json_decode($res,true);
  829. if(isset($res['errCode']) && $res['errCode'] == '00'){
  830. $result['status'] = 1;
  831. $result['data'] = isset($res['data'])?$res['data']:array();
  832. $result['msg'] = $res['errMsg'];
  833. }else{
  834. if(isset($res['errMsg'])){
  835. $result['msg'] = $res['errMsg'];
  836. }
  837. }
  838. }
  839. unset($res);
  840. return $result;
  841. }
  842. function file_exists($url)
  843. {
  844. $ch = curl_init();
  845. $timeout = 10;
  846. curl_setopt($ch, CURLOPT_URL, $url);
  847. curl_setopt($ch, CURLOPT_HEADER, 1);
  848. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  849. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  850. $contents = curl_exec($ch);
  851. if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 404) {
  852. return false;
  853. }
  854. return true;
  855. // $ch = curl_init();
  856. // curl_setopt ($ch, CURLOPT_URL, $url);
  857. // //不下载
  858. // curl_setopt($ch, CURLOPT_NOBODY, 1);
  859. // //设置超时
  860. // curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 3);
  861. // curl_setopt($ch, CURLOPT_TIMEOUT, 3);
  862. // //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  863. // curl_exec($ch);
  864. // $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  865. // if($http_code == 200) {
  866. // return true;
  867. // }
  868. // return false;
  869. }
  870. public function viewRender($viewName, $data)
  871. {
  872. extract($data, EXTR_PREFIX_SAME,'data');
  873. ob_start();
  874. ob_implicit_flush(0);
  875. require(dirname(dirname(dirname(__FILE__))).'/protected/views/classes/'.$viewName . '.php');
  876. return ob_get_clean();
  877. }
  878. }