MicroProduct.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020/7/29 0029
  6. * Time: 11:02
  7. */
  8. class MicroProduct extends Model{
  9. /**
  10. * 微产品
  11. */
  12. public function getList($condition = array(), $orderBy = array("m.create_time desc"), $pageSize = 10)
  13. {
  14. $condition = Arr::merge($condition, array("m.semester_id = '{$this->semester["id"]}'"));
  15. $condition = $this->condition($condition);
  16. $orderBy = $this->orderBy($orderBy);
  17. $handle = $this->sConn->createCommand("
  18. select m.micro_id,m.name,c.grade,c.class_id,c.class_name from math_micro_setting m join class c on m.class_id= c.class_id
  19. {$condition}
  20. group by m.micro_id
  21. {$orderBy}
  22. ")->query();
  23. $rs = $this->paging($this->sConn, $handle, $pageSize);
  24. if ($rs['rs']) {
  25. foreach ($rs['rs'] as $k => $v) {
  26. $rs['rs'][$k]['totalCount'] = 0;
  27. $rs['rs'][$k]['pdfCount'] = 0;
  28. $rs['rs'][$k]['isDown'] = 0;
  29. $rs['rs'][$k]['downTime'] = '';
  30. $micro_id = $v['micro_id'];
  31. $sql = "select COUNT(student_id) AS totalCount,SUM(CASE WHEN is_micro_pdf = 1 THEN 1 ELSE 0 END) AS pdfCount from math_micro_student where micro_id = '{$micro_id}'";
  32. $countArr = $this->sConn->createCommand($sql)->queryRow();
  33. if ($countArr) {
  34. $rs['rs'][$k]['totalCount'] = isset($countArr['totalCount']) ? $countArr['totalCount'] : 0;
  35. $rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount']) ? $countArr['pdfCount'] : 0;
  36. }
  37. $sql = "select micro_download_time from math_micro_student where micro_id = '{$micro_id}' and is_micro_download = 1 order by micro_download_time desc limit 1";
  38. $isDownArr = $this->sConn->createCommand($sql)->queryRow();
  39. if ($isDownArr) {
  40. $rs['rs'][$k]['isDown'] = 1;
  41. $rs['rs'][$k]['downTime'] = isset($isDownArr['micro_download_time']) ? date("Y-m-d H:i", $isDownArr['micro_download_time']) : '';
  42. }
  43. }
  44. }
  45. return $rs;
  46. }
  47. }