Index.php 6.5 KB
<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['index','banner','about','kefu','teacher','teacher_detail','center','zan'];
    protected $noNeedRight = ['*'];

    /**
     * @ApiTitle    (首页顶部图片)
     * @ApiSummary  (首页顶部图片)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/index/index)
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "id"://ID
    "image"://图片
    }
    })
     */
    public function index()
    {
        $qiniu = get_addon_config('qiniu')['cdnurl'];
        $data = Db::name('image')->where('id',1)->field('id,image')->find();
        $data['image'] = $qiniu.$data['image'];
        $this->success('success',$data);
    }

    /**
     * @ApiTitle    (首页轮播图片)
     * @ApiSummary  (首页轮播图片)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/index/banner)
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "id"://ID
    "image"://图片
    "url"://链接
    }
    })
     */
    public function banner()
    {
        $qiniu = get_addon_config('qiniu')['cdnurl'];
        $data = Db::name('banner')
            ->field('id,image,url')
            ->order('id desc')
            ->limit(5)
            ->select();
        foreach ($data as &$v){
            $v['image'] = $qiniu.$v['image'];
        }
        $this->success('success',$data);
    }

    /**
     * @ApiTitle    (首页平台简介)
     * @ApiSummary  (首页平台简介)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/index/about)
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "id"://ID
    "content"://平台简介内容
    }
    })
     */
    public function about()
    {
        $qiniu = get_addon_config('qiniu')['cdnurl'];
        $data = Db::name('about')
            ->where('id',1)
            ->field('id,image,content')
            ->find();
        $data['image'] = $qiniu.$data['image'];
        $this->success('success',$data);
    }


    /**
     * @ApiTitle    (联系客服/下载APP)
     * @ApiSummary  (联系客服/下载APP)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/index/kefu)
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "id"://ID
    "downloadimage"://下载APP图片
    "image"://联系客服图片
    "work"://工作时长
    "phone"://客服电话1
    "phone1"://客服电话2
    }
    })
     */
    public function kefu()
    {
        $qiniu = get_addon_config('qiniu')['cdnurl'];
        $data = Db::name('kefu')
            ->where('id',1)
            ->field('createtime',true)
            ->find();
        $data['downloadimage'] = $qiniu.$data['downloadimage'];
        $data['image'] = $qiniu.$data['image'];
        $this->success('success',$data);
    }



    /**
     * @ApiTitle    (首页师资力量)
     * @ApiSummary  (首页师资力量)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/index/teacher)
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "id"://ID
    "name"://名称
    "image"://头像
    "title"://头衔
    "age_num"://从业年限
    "order_num"://成单量
    "good_num"://好评率
    "desc"://擅长领域
    "createtime"://创建时间
    }
    })
     */
    public function teacher()
    {
        $qiniu = get_addon_config('qiniu')['cdnurl'];
        $data = Db::name('teacher')
            ->field('updatetime',true)
            ->order('createtime desc')
            ->select();
        foreach ($data as &$v){
            $v['image'] = $qiniu.$v['image'];
            $v['age_num'] = $v['age_num'].'年';
            $v['order_num'] = $v['order_num'].'单';
            $v['createtime'] = datetime('Y-m-d H:i:s',$v['createtime']);
        }
        $this->success('success',$data);
    }

    /**
     * @ApiTitle    (老师详情)
     * @ApiSummary  (老师详情)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/index/teacher_detail)
     *
     * @ApiParams   (name="teacher_id", type="int", required=true, description="老师ID")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "id"://ID
    "name"://名称
    "image"://头像
    "title"://头衔
    "age_num"://从业年限
    "order_num"://成单量
    "good_num"://好评率
    "desc"://擅长领域
    "createtime"://创建时间
    }
    })
     */
    public function teacher_detail()
    {
        $qiniu = get_addon_config('qiniu')['cdnurl'];
        $teacher_id = $this->request->param('teacher_id');
        if(empty($teacher_id)){
            $this->error('缺少必要参数');
        }
        $data = Db::name('teacher')->field('updatetime',true)->where('id',$teacher_id)->find();
        $data['age_num'] = $data['age_num'].'年';
        $data['order_num'] = $data['order_num'].'单';
        $data['image'] = $qiniu.$data['image'];
        $data['createtime'] = date('Y-m-d H:i:s',$data['createtime']);
        $this->success('success',$data);
    }

    /**
     * @ApiTitle    (系统中心)
     * @ApiSummary  (系统中心)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/index/center)
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "id"://ID
    "name"://名称
    "image"://图标
    "url"://跳转链接
    "createtime"://创建时间
    }
    })
     */
    public function center()
    {
        $qiniu = get_addon_config('qiniu')['cdnurl'];
        $data = Db::name('center')
            ->field('updatetime',true)
            ->order('id desc')
            ->select();
        foreach ($data as &$v){
            $v['image'] = $qiniu.$v['image'];
            $v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
        }
        $this->success('success',$data);
    }

    /**
     * @ApiTitle    (设置自动暂停)
     * @ApiSummary  (设置自动暂停)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/index/zan)
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "id"://ID
    "stopnum"://暂停间隔
    "switch"://是否开启1开启0关闭
    }
    })
     */
    public function zan()
    {
        $data = Db::name('set')->where('id',1)->field('stopnum,switch')->find();
        $data['stopnum'] = $data['stopnum'] * 60;
        $this->success('success',$data);
    }
}