Screen.php 2.7 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()
    {
        $list = [];
        $data = db('screen')->where('is_view', 1)->find();
        $list['images'] = cdnurl($data['images'], true);
        $list['count_down'] = $data['endtime'];
        $list['screen_name'] = $data['title'];
        $list['campus_name'] = $data['campus'];
        $list['time'] = date('Y-m-d H:i:s', time());
        $list['team_rank'] = \db('team_score')
            ->where('ronda_id', $data['ronda_id'])
//            ->field('score as sum_score,team_id')
            ->order('score DESC')
            ->paginate(4)
            ->each(function ($item, $key) {
                $item['team_name'] = db('team')->where('id', $item['team_id'])->value('title');
                $item['team_score'] = $item['score'];
                $item['percent'] = $item['score'];
                $item['study'] = db('study_ronda_score l')
                    ->join('study s', 'l.sid = s.id')
                    ->where('l.team_id', $item['team_id'])
                    ->where('ronda_id', $item['ronda_id'])
                    ->field('s.name,score as sum_score,l.*')
                    ->order('score', 'desc')
                    ->select();
                return $item;
            });
        if (time() >= $data['endtime']) {
            //倒计时结束,清空大屏数据
            $find = db('team_score')->where('ronda_id', $data['ronda_id'])->column('team_id');
            db('team_score')
                ->where('ronda_id', $data['ronda_id'])
                ->update(['score' => 0]);
            foreach ($find as $k){
                db('team')->where('id',$k)->update(['score'=>0]);
            }
            $campus = db('screen')->where('is_view', 1)->find();
            $res = [];
            $res['images'] = cdnurl($campus['images'], true);
            $res['count_down'] = $campus['endtime'];
            $res['screen_name'] = $campus['title'];
            $res['campus_name'] = $campus['campus'];
            $this->success('获取成功', $res);
        }
        $this->success('获取成功', $list);
    }

}