Activity.php 4.2 KB
<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 活动接口
 * @ApiWeigh    (97)
 */
class Activity extends Api
{
    protected $noNeedLogin = [''];
    protected $noNeedRight = ['*'];

    /**
     * @ApiTitle (活动首页)
     */
    public function index()
    {
        $data = db('activity')
            ->order('createtime DESC')
            ->select();
        if (!$data) {
            $this->error('当前还没有活动', ['status' => 2]);
        }
        foreach ($data as $k => $v) {
            $data[$k]['images'] = cdnurl($v['images'], true);
            $data[$k]['createtime'] = date('Y-m-d', $v['createtime']);
        }
        $this->success('全部项目', $data);

    }

    /**
     * @ApiTitle (项目校区)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="id", type="string", required=false, description="活动id")
     * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码")
     * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
    "code":"状态码",
    "msg": "提示消息",
    "data": {}
    })
     */
    public function getSchoolItem()
    {
        $id = $this->request->param('id');
        if (empty($id)) {
            $this->error('参数错误', ['status' => 3]);
        }
        $data = db('campus c')
            ->join('activity a','a.id = c.activity_id')
            ->join('school s','s.id = c.school_id')
            ->where('c.activity_id', $id)
            ->field('c.*,a.title as activity_name,s.title as school_name')
            ->paginate(10,false);
        if (empty($data)) {
            $this->error('空空', ['status' => 3]);
        }
        $this->success('项目校区', $data);
    }

    /**
     * @ApiTitle (项目日期场次)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="id", type="string", required=false, description="校区id")
     * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码")
     * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
    "code":"状态码",
    "msg": "提示消息",
    "data": {
    "school": [学校]
    "ronda": [
    "item": 项目
    "item_details": 项目详情
    ]
    }
    })
     */
    public function getItemRonda()
    {
        $id = $this->request->param('id');
        $data['school_name'] = db('school s')
            ->join('activity a','s.activity_id = a.id')
            ->field('s.*,a.title as activity_name')
            ->where('s.id', $id)
            ->find();
        $data['ronda'] = db('ronda')
            ->where('xq_id', $id)
            ->paginate(10)
            ->each(function ($item, $k) {
                $data['item'] = db('item')->where('ronda_id', $item['id'])->find();
                $data['item_details'] = db('item_details')->where('item_id', $data['item']['id'])->find();
                return $data;
            });
        $this->success('项目场次日期', $data);
    }

    /**
     * @ApiTitle (项目详情)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="id", type="string", required=false, description="项目id")
     * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码")
     * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
    "code":"状态码",
    "msg": "提示消息",
    "data": {
    "school_name": 校区信息{},
    "ronda": 场次信息{
    "data": [{
    "item": 场次对应的项目信息{},
    ]}
    })
     */
    public function getItemDetails()
    {
        $id = $this->request->param('id');
        $data = db('item_details')
            ->where('item_id', $id)
            ->find();
        $this->success('', $data);
    }
}