Screen.php 2.0 KB
<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 数据大屏
 * @ApiWeigh    (95)
 */
class Screen extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * @ApiTitle (大屏管理)
     * @ApiMethod (POST)
     * @ApiReturn   ({"code":状态码,
    "msg":"提示信息"
    "time": "时间戳",
    "data": "大屏图片",
    "time": "当前时间",
    "campus": "活动名称",
    "team_rank": 战队排行[从高到底排],
    "study_rank": 个人排行[每个战队中从高到低排]
    }
     */
    public function index(){
        $time = time();
        $list = [];
        $data = db('data_screen')->find();
        $list['images'] = cdnurl($data['images'],true);
        if ($data['starttime']<=$time || $data['endtime']>=$time){
            $times = $data['endtime'] - $time;
            $data['count_down'] = date('H:i:s',$times);
        }
        $res = db('campus c')
            ->join('school s','c.school_id = s.id')
            ->join('activity a','c.activity_id = a.id')
            ->where('c.id',$data['campus_id'])
            ->field('c.activity_id,c.school_id,c.date,s.title as school_name,a.title as activity_name')
            ->find();
        $list['time'] = date('Y-m-d H:i:s',time());
        $list['campus'] = $res['date'].$res['school_name'].$res['activity_name'];
        $list['team_rank'] = \db('study_score_log')
            ->field('SUM(score) as sum_score,team_id')
            ->where('campus_id',$data['campus_id'])
            ->group('team_id')
            ->order('sum_score DESC')
            ->limit(4)
            ->select();
        $list['study_rank'] = db('study_score_log')
            ->field('study_id,SUM(score) as sum_score,team_id')
            ->where('campus_id',$data['campus_id'])
            ->order('sum_score DESC')
            ->group('study_id')
            ->limit('0,10')
            ->select();
        $this->success('获取成功',$list);
    }

}