123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace app\api\controller;
- use Alipay\EasySDK\Kernel\Base;
- use app\model\api\EducationCourse;
- use think\facade\Db;
- class Education
- {
-
- public function index()
- {
- $EducationModel = new \app\model\api\Education();
- $where["audit"] = 1;
- $type1 = input("type1", "");
- if ($type1 !== "") {
- $where["type1"] = $type1;
- } else {
- $type1 = 2;
- }
- if ($type1 == 0) {
- $where["type1"] = 0;
- } elseif ($type1 == 1) {
- $where["type1"] = 1;
- }
- $page = input('page/d', 1);
- $pageSize = input('pageSize/d', 20);
- $grlist = $EducationModel->where($where)
- ->order("od asc,recommend desc,gr_id desc")
- ->paginate($pageSize, false, ['page' => $page]);
- $result = ['grlist' => $grlist->items(), 'total' => $grlist->total()];
- $result['grlist'] = $this->getCountAndAlll($result['grlist']);
- return app('json')->success($result);
- }
-
- public function recommend()
- {
- $EducationModel = new \app\model\api\Education();
- $where = [
- 'audit' => 1,
- 'recommend' => 1,
- ];
- $recommendList = $EducationModel->getEducationGrList($where, 9, "od asc,recommend desc,gr_id desc");
- $result = ['recommendList' => $recommendList];
- return app('json')->success($result);
- }
-
- private function getCountAndAlll($grlist)
- {
- foreach ($grlist as &$v) {
- $count = EducationCourse::where('course_status', 1)
- ->where('gr_id', $v['gr_id'])
- ->where('course_audit', 1)
- ->field('count(*) as count,sum(course_play_count) as alll')
- ->find();
- $v['count'] = $count['count'];
- $count['alll'] += $v['times'];
- $v['alll'] = $count['alll'] ? $count['alll'] : 0;
- }
- return $grlist;
- }
-
- public function getCourseList($gr_id)
- {
- $courseList = EducationCourse::where('course_status', 1)
- ->where('gr_id', $gr_id)
- ->where('course_audit', 1)
- ->select();
- return json([
- 'code' => 200,
- 'msg' => 'ok',
- 'data' => $courseList
- ]);
- }
- }
|