SGeneralProductSetting.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2021/11/23 0023
  6. * Time: 15:20
  7. */
  8. class SGeneralProductSetting extends MyActiveRecord
  9. {
  10. public static function model($className = __CLASS__)
  11. {
  12. return parent::model($className);
  13. }
  14. public function tableName()
  15. {
  16. return 'general_product_setting';
  17. }
  18. /**
  19. * 产品列表
  20. * @param array $condition
  21. * @param array $orderBy
  22. * @param int $pageSize
  23. * @return array
  24. * @throws CDbException
  25. * @throws CException
  26. */
  27. public function getList($condition = array(), $orderBy = array("p.create_time desc"), $pageSize = 10)
  28. {
  29. $condition = $this->condition($condition);
  30. $orderBy = $this->orderBy($orderBy);
  31. $con = $this->getDbConnection();
  32. $handle = $con->createCommand("
  33. select p.gp_id,p.name,p.reset_times,g.gp_group_id,g.setting,g.status,g.repair_info,c.grade,c.class_id,c.class_name,p.learn_tube_reset_count,p.learn_tube_reset_time,p.create_time from general_product p join general_product_setting g on g.gp_group_id=p.gp_group_id join class c on p.class_id= c.class_id
  34. {$condition}
  35. group by p.gp_id
  36. {$orderBy}
  37. ")->query();
  38. $rs = $this->paging($this->getDbConnection(), $handle, $pageSize);
  39. if ($rs['rs']) {
  40. foreach ($rs['rs'] as $k => $v) {
  41. $setting = json_decode($v['setting'],true);
  42. $rs['rs'][$k]['totalCount'] = 0;
  43. $rs['rs'][$k]['pdfCount'] = 0;
  44. $rs['rs'][$k]['isDown'] = 0;
  45. $rs['rs'][$k]['downTime'] = '';
  46. $rs['rs'][$k]['createType'] = isset($setting['create_type'])?$setting['create_type']:0;
  47. $gp_id = $v['gp_id'];
  48. $sql = "select COUNT(distinct s.student_id) AS totalCount,SUM(CASE WHEN s.is_create_pdf = 1 THEN 1 ELSE 0 END) AS pdfCount from general_product_student s inner join student_info i on s.student_id=i.student_id where s.gp_id = '{$gp_id}'";
  49. $countArr = $con->createCommand($sql)->queryRow();
  50. if ($countArr) {
  51. $rs['rs'][$k]['totalCount'] = isset($countArr['totalCount']) ? $countArr['totalCount'] : 0;
  52. $rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount']) ? $countArr['pdfCount'] : 0;
  53. }
  54. $sql = "select download_time from general_product_student where gp_id = '{$gp_id}' and is_download = 1 order by download_time desc limit 1";
  55. $isDownArr = $con->createCommand($sql)->queryRow();
  56. if ($isDownArr) {
  57. $rs['rs'][$k]['isDown'] = 1;
  58. $rs['rs'][$k]['downTime'] = isset($isDownArr['download_time']) ? date("Y-m-d H:i", $isDownArr['download_time']) : '';
  59. }
  60. }
  61. }
  62. return $rs;
  63. }
  64. public function paging($conn, $handle, $pageSize){
  65. $pager = new CPagination($handle->rowCount, $pageSize);
  66. $handle = $conn->createCommand($handle->queryString." limit :offset, :limit");
  67. $handle->bindValue(":offset", $pager->currentPage * $pager->pageSize);
  68. $handle->bindValue(":limit", $pager->pageSize);
  69. $rs = $handle->queryAll();
  70. return array("rs" => $rs, "pager" => $pager);
  71. }
  72. public function condition($condition = array()){
  73. return $condition ? " where ".implode(" and ", $condition) : "";
  74. }
  75. public function orderBy($orderBy = array()){
  76. return $orderBy ? " order by ".implode(",", $orderBy) : "";
  77. }
  78. /**
  79. * 专题超出次数的班级
  80. * @param $gpId
  81. * @param $productType
  82. * @param $classIds
  83. * @return array
  84. * @throws CDbException
  85. * @throws CException
  86. */
  87. public function classHistory($gpId, $productType,$classIds){
  88. $list = array();
  89. $rs = $this->getDbConnection()->createCommand("select g.setting,c.class_id,c.class_name from general_product p join general_product_setting g
  90. on g.gp_group_id=p.gp_group_id join class c on p.class_id= c.class_id where g.product_type={$productType} and p.class_id in ($classIds)")->queryAll();
  91. if($rs){
  92. foreach ($rs as $item){
  93. $setting = json_decode($item['setting'],true);
  94. $specialId = isset($setting['pc_ids'][0]['pc_id']) ? $setting['pc_ids'][0]['pc_id'] : 0;
  95. if($specialId && $gpId==$specialId){
  96. $list[$item['class_id']]['class_name'] = $item['class_name'];
  97. if(isset($list[$item['class_id']]['special_count'])){
  98. $list[$item['class_id']]['special_count']++;
  99. }else{
  100. $list[$item['class_id']]['special_count'] = 1;
  101. }
  102. }
  103. }
  104. }
  105. $limitClass = array();
  106. if($list){
  107. foreach ($list as $key=>$item){
  108. if($item['special_count']>=3){
  109. array_push($limitClass,$item['class_name']);
  110. }
  111. }
  112. }
  113. return $limitClass;
  114. }
  115. //校本纠错本班级列表
  116. public function getCorrectClassList($gpGroupId){
  117. $conn = $this->getDbConnection();
  118. $sql="select gp_id,gp.class_id,c.class_name,gp.name,create_time,c.grade from general_product gp left join class c on c.class_id=gp.class_id where gp_group_id='{$gpGroupId}'";
  119. $result=$conn->createCommand($sql)->queryAll();
  120. return $result;
  121. }
  122. //纠错本学生
  123. public function getCorrectStudent($gpId){
  124. $conn = $this->getDbConnection();
  125. $sql="select gp_id,student_id,is_create_pdf,download_time,is_download from general_product_student where gp_id='{$gpId}'";
  126. $result=$conn->createCommand($sql)->queryAll();
  127. return $result;
  128. }
  129. //读取纠错本配置信息
  130. public function getGeneralSetting($gpGroupId){
  131. $conn = $this->getDbConnection();
  132. $sql="select setting from general_product_setting where gp_group_id='{$gpGroupId}'";
  133. $result=$conn->createCommand($sql)->queryRow();
  134. if($result){
  135. return $result['setting'];
  136. }else{
  137. return null;
  138. }
  139. }
  140. }