IndexController.php 3.0 KB
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\portal\controller;

use cmf\controller\HomeBaseController;
use think\Db;
use app\activity\model\ActivityModel;
use EasyWeChat\Foundation\Application;

/**
 * @title 欢迎页
 * @description 欢迎使用在线接口文档
 */
class IndexController extends HomeBaseController
{

    function _initialize()
    {
        session('user.id', 2);
    }

    /**
     * @title 接口返回参数说明
     * @description 默认访问接口
     * @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
     * @url /portal/index/api
     * @method GET
     *
     * @return version:版本号
     * @return code:错误码
     */
    public function api()
    {
        $data = [
            'version' => '1.0.0',
            'code' => [
                '20000' => '默认成功返回码',
                '40000' => '默认错误返回码',
                '40001' => '未登录或登录失效',
                '40002' => '签名验证失败',
                '40003' => '缺少必要参数或参数格式错误',
                '40004' => '登录失败',
            ]
        ];
        echo json_encode(['msg' => $data]);
        exit();
    }


    /**
     * @title 首页
     * @description 默认访问接口
     * @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
     * @url /portal/Index/index
     * @method POST
     *
     * @return version:版本号
     * @return code:错误码
     */
    public function index()
    {
        //首页轮播图
        $banner = Db::name('slide_item')->field('image,url')->where(['slide_id' => 1])->order('list_order')->select();
        foreach ($banner as $k => $v) {
            $v['image'] = cmf_get_image_url($v['image']);
            $banner[$k] = $v;
        }
        //分类
        $type = Db::name('type')->field('id as t_id,type_name,type_url,type_icon')->order('listorder')->select();
        //活动
        $model = new ActivityModel;
        $t_id = request()->param('t_id');
        $keyword = request()->param('keyword');
        $is_new = $model->activityList($t_id, time(), session('user.id'), $keyword, 1, '');
        $is_hot = $model->activityList($t_id, time(), session('user.id'), $keyword, '', 1);
        $result = [
            'banner' => $banner,
            'type' => $type,
            'is_new' => $is_new,
            'is_hot' => $is_hot
        ];
        if (request()->isPost()) {
            echo json_encode(['data' => $result, 'code' => 20000]);
            exit();
        } else {
            return $this->fetch('', [
                'result' => $result
            ]);
        }
    }

}