Activity.php 7.2 KB
<?php

namespace app\api\controller;

use app\common\controller\Api;

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

    /**
     * @ApiTitle (活动首页)
     * @ApiMethod (POST)
     * @ApiParams   (name="row", type="string", required=false, description="每页显示行数[非必填]")
     * @ApiParams   (name="page", type="string", required=false, description="当前页[非必填]")
     * @ApiReturn   ({"code":状态码,
    "msg":"提示信息"
    "time": "时间戳",
    "data": [
    "id": 1,
    "title": "活动名称",
    "images": "活动图片",
    "depict": "描述",
    ]
    })
     */
    public function index()
    {
        $row = $this->request->param('row');
        $page = $this->request->param('page');
        $row = $row ? $row : 10;
        $page = $page ? $page : 1;
        $data = db('activity')
            ->order('createtime DESC')
            ->paginate($row,false,['page'=>$page])
            ->each(function ($item,$key){
                $item['images'] = cdnurl($item['images'], true);
                $item['createtime'] = date('Y-m-d', $item['createtime']);
                return $item;
        });
        if (!$data) {
            $this->error('当前还没有活动', ['status' => 2]);
        }
        $this->success('全部项目', $data);

    }

    /**
     * @ApiTitle (项目校区)
     * @ApiMethod (POST)
     * @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()
    {
        $data = db('campus c')
            ->join('activity a','a.id = c.activity_id')
            ->join('school s','s.id = c.school_id')
            ->field('c.*,a.title as activity_name,s.title as school_name')
            ->paginate(10,false);
        if (empty($data)) {
            $this->error('当前还没有校区', ['status' => 2]);
        }
        $this->success('项目校区', $data);
    }

    /**
     * @ApiTitle (场次筛选)
     * @ApiMethod (POST)
     * @ApiParams   (name="cid", 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": {
    "campus_title": "校区名称",
    "ronda_title": "场次",
    "ronda_holdtime": "场次时间",
    }
    })
     */
    public function getRonda()
    {
        $cid = $this->request->param('cid');
        if (empty($cid)) {
            $this->error('参数错误', ['status' => 2]);
        }
        $data = db('ronda r')
            ->join('campus c','c.id = r.campus_id')
            ->field('r.id as rid,c.title as campus_title,r.title as ronda_title,r.holdtime as ronda_holdtime')
            ->where('r.campus_id',$cid)
            ->paginate(10,false)
            ->each(function ($item,$key){
                $item['holdtime'] = date('Y-m-d',$item['ronda_holdtime']);
                return $item;
            });
        $this->success('获取场次列表成功', $data);
    }

    /**
     * @ApiTitle (项目筛选)
     * @ApiMethod (POST)
     * @ApiParams   (name="rid", 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": {
    "campus_title": "校区名称",
    "ronda_title": "场次",
    "ronda_holdtime": "场次时间",
    }
    })
     */
    public function getItem()
    {
        $rid = $this->request->param('rid');
        if (empty($rid)) {
            $this->error('参数错误', ['status' => 2]);
        }
        $data = db('item i')
            ->join('ronda r','r.id = i.ronda_id')
            ->join('campus c','r.campus_id as c.id')
            ->field('i.*,c.title as campus_title')
            ->where([
                'i.ronda_id' => $rid
            ])
            ->paginate(10,false);
        $this->success('获取项目列表成功', $data);
    }

    /**
     * @ApiTitle (场次详情)
     * @ApiMethod (POST)
     * @ApiParams   (name="rid", 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": {
    "images": "场次图片",
    "details": "场次详情"
    })
     */
    public function getRondaDetails()
    {
        $rid = $this->request->param('rid');
        $data = db('ronda')
            ->where('id', $rid)
            ->find();
        $data['images'] = cdnurl($data['images'], true);
        $this->success('获取场次详情成功', $data);
    }

    /**
     * @ApiTitle (项目详情)
     * @ApiMethod (POST)
     * @ApiParams   (name="rid", type="string", required=false, description="场次id")
     * @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": {
    "campus_title": "校区名称",
    "ronda_title": "场次名称",
    "images": "项目图片",
    "details": "项目详情"
    })
     */
    public function getItemDetails()
    {
        $rid = $this->request->param('rid');
        $id = $this->request->param('id');
        $data = db('item i')
            ->join('item_details d','d.item_id = i.id')
            ->join('ronda r','i.ronda_id = r.id')
            ->join('campus c','c.id = r.campus_id')
            ->field('c.title as campus_title,r.title as ronda_title,r.holdtime,d.images,i.details')
            ->where([
                'i.ronda_id'=>$rid,
                'i.id'=> $id,
            ])
            ->find();
        $data['images'] = cdnurl($data['images'], true);
        $data['holdtime'] = date('Ymd',$data['holdtime']);
        $this->success('获取项目详情成功', $data);
    }
}