Education.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace app\model\api;
  3. use think\model;
  4. class Education extends model
  5. {
  6. protected $table = 'education_gr';
  7. // 获取教育组列表
  8. public function getEducationGrList($where = [], $limit = 20, $order = 'od asc,recommend desc,gr_id desc')
  9. {
  10. $query = $this->where($where)->limit($limit)->order($order);
  11. $grList = $query->select();
  12. foreach ($grList as &$gr) {
  13. $count = $this->getCourseCount($gr['gr_id']);
  14. $gr['count'] = $count['count'];
  15. $gr['alll'] = $count['alll'] + $gr['times'];
  16. }
  17. return $grList;
  18. }
  19. // 获取课程总数和播放总数
  20. public function getCourseCount($grId)
  21. {
  22. $count = $this->table('education_course')->where(['gr_id' => $grId, 'course_status' => 1, 'course_audit' => 1])->field('count(*) as count, sum(course_play_count) as alll')->find();
  23. return $count ?: ['count' => 0, 'alll' => 0];
  24. }
  25. // 获取推荐教育组列表
  26. public function getRecommendEducationGrList($limit = 9, $order = 'od asc,recommend desc,gr_id desc')
  27. {
  28. $recommendList = $this->where(['recommend' => 1])->limit($limit)->order($order)->select();
  29. $recommendListResult = [];
  30. foreach ($recommendList as $recommend) {
  31. $recommendListResult[] = [
  32. 'img' => $recommend['indeximg'],
  33. 'href' => url('kcz', ['gr_id' => $recommend['gr_id']]),
  34. ];
  35. }
  36. return $recommendListResult;
  37. }
  38. }