| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace app\model\api;
- use think\Model;
- class Education extends Model
- {
- protected $table = 'table_education_gr';
- /**
- * 获取教育组列表
- * @param array $where
- * @param int $limit
- * @param string $order
- * @return \think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getEducationGrList($where = [], $limit = 20, $order = 'od asc,recommend desc,gr_id desc')
- {
- $query = $this->where($where)->limit($limit)->order($order);
- $grList = $query->select();
- foreach ($grList as &$gr) {
- $count = $this->getCourseCount($gr['gr_id']);
- $gr['count'] = $count['count'];
- $gr['alll'] = $count['alll'] + $gr['times'];
- }
- return $grList;
- }
- /**
- * 获取课程总数和播放量
- * @param $grId
- * @return array|int[]|Model
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getCourseCount($grId)
- {
- $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();
- return $count ?: ['count' => 0, 'alll' => 0];
- }
- /**
- * 获取推荐教育组列表
- * @param int $limit
- * @param string $order
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getRecommendEducationGrList($limit = 9, $order = 'od asc,recommend desc,gr_id desc')
- {
- $recommendList = $this->where(['recommend' => 1])->limit($limit)->order($order)->select();
- $recommendListResult = [];
- foreach ($recommendList as $recommend) {
- $recommendListResult[] = [
- 'img' => $recommend['indeximg'],
- 'href' => url('kcz', ['gr_id' => $recommend['gr_id']]),
- ];
- }
- return $recommendListResult;
- }
- }
|