Education.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace app\model\api;
  3. use think\Model;
  4. class Education extends Model
  5. {
  6. protected $table = 'table_education_gr';
  7. /**
  8. * 获取教育组列表
  9. * @param array $where
  10. * @param int $limit
  11. * @param string $order
  12. * @return \think\Collection
  13. * @throws \think\db\exception\DataNotFoundException
  14. * @throws \think\db\exception\DbException
  15. * @throws \think\db\exception\ModelNotFoundException
  16. */
  17. public function getEducationGrList($where = [], $limit = 20, $order = 'od asc,recommend desc,gr_id desc')
  18. {
  19. $query = $this->where($where)->limit($limit)->order($order);
  20. $grList = $query->select();
  21. foreach ($grList as &$gr) {
  22. $count = $this->getCourseCount($gr['gr_id']);
  23. $gr['count'] = $count['count'];
  24. $gr['alll'] = $count['alll'] + $gr['times'];
  25. }
  26. return $grList;
  27. }
  28. /**
  29. * 获取课程总数和播放量
  30. * @param $grId
  31. * @return array|int[]|Model
  32. * @throws \think\db\exception\DataNotFoundException
  33. * @throws \think\db\exception\DbException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. */
  36. public function getCourseCount($grId)
  37. {
  38. $count = $this->table('table_education_course')->where(['gr_id' => $grId, 'course_status' => 1, 'course_audit' => 1])->field('count(*) as count, sum(course_play_count) as alll')->find();
  39. return $count ?: ['count' => 0, 'alll' => 0];
  40. }
  41. /**
  42. * 获取推荐教育组列表
  43. * @param int $limit
  44. * @param string $order
  45. * @return array
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\DbException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. */
  50. public function getRecommendEducationGrList($limit = 9, $order = 'od asc,recommend desc,gr_id desc')
  51. {
  52. $recommendList = $this->where(['recommend' => 1])->limit($limit)->order($order)->select();
  53. $recommendListResult = [];
  54. foreach ($recommendList as $recommend) {
  55. $recommendListResult[] = [
  56. 'img' => $recommend['indeximg'],
  57. 'href' => url('kcz', ['gr_id' => $recommend['gr_id']]),
  58. ];
  59. }
  60. return $recommendListResult;
  61. }
  62. }