Index.php 12.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
<?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','information','policy','download','image_policy','enter'];
    protected $noNeedRight = ['*'];

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

    /**
     * @ApiTitle    (首页轮播图片)
     * @ApiSummary  (首页轮播图片)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/index/banner)
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
    "id"://ID
    "image"://图片
    "title"://标题
    "url"://链接
    }
    })
     */
    public function banner()
    {
        $data = Db::name('banner')
            ->field('id,image,title,url')
            ->order('id desc')
            ->limit(5)
            ->select();
        foreach ($data as &$v){
            $v['image'] = cdnurl($v['image'],true);
        }
        $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()
    {
        $data = Db::name('about')
            ->where('id',1)
            ->field('id,image,content')
            ->find();
        $data['image'] = cdnurl($data['image'],true);
        $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()
    {
        $data = Db::name('kefu')
            ->where('id',1)
            ->field('createtime',true)
            ->find();
        $data['downloadimage'] = cdnurl($data['downloadimage'],true);
        $data['image'] = cdnurl($data['image'],true);
        $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()
    {
        $data = Db::name('teacher')
            ->field('updatetime',true)
            ->order('createtime desc')
            ->select();
        foreach ($data as &$v){
            $v['image'] = cdnurl($v['image'],true);
            $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()
    {
        $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'] = cdnurl($data['image'],true);
        $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()
    {
        $data = Db::name('center')
            ->field('updatetime',true)
            ->order('id desc')
            ->select();
        foreach ($data as &$v){
            $v['image'] = cdnurl($v['image'],true);
            $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);
    }

    /**
     * @ApiTitle    (通知公告)
     * @ApiSummary  (通知公告)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/index/information)
     *
     * @ApiReturn({
        "code": 1,
        "msg": "success",
        "time": "1611025227",
        "data": [{
            "id": 10, //ID
            "title": "关于2021年度施工企业安管人员第一期网络继续教育的通知", //标题
            "is_up": "0", //是否上架0否1是
            "desc": "", //简介
            "createtime": "2020-12-31 14:42:39" //发布时间
        }]
    })
     */
    public function information()
    {
        $list = Db::name('information')
            ->field('id,title,is_up,desc,createtime')
            ->order('is_up desc,createtime desc')
            ->limit(8)
            ->select();
        foreach ($list as &$v){
            $v['createtime'] = date('m-d',$v['createtime']);
        }
        $this->success('success',$list);
    }

    /**
     * @ApiTitle    (政策动态)
     * @ApiSummary  (政策动态)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/index/policy)
     *
     * @ApiReturn({
        "code": 1,
        "msg": "success",
        "time": "1611025227",
        "data": [{
            "id": 10, //ID
            "title": "关于2021年度施工企业安管人员第一期网络继续教育的通知", //标题
            "is_up": "0", //是否上架0否1是
            "desc": "", //简介
            "createtime": "2020-12-31 14:42:39" //发布时间
        }]
    })
     */
    public function policy()
    {
        $list = Db::name('policy')
            ->field('id,title,is_up,desc,createtime')
            ->order('is_up desc,createtime desc')
            ->limit(9)
            ->select();
        foreach ($list as &$v){
            $v['createtime'] = date('m-d',$v['createtime']);
        }
        $this->success('success',$list);
    }

    /**
     * @ApiTitle    (下载专区)
     * @ApiSummary  (下载专区)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/index/download)
     *
     * @ApiReturn({
        "code": 1,
        "msg": "success",
        "time": "1611025227",
        "data": [{
            "id": 10, //ID
            "title": "关于2021年度施工企业安管人员第一期网络继续教育的通知", //标题
            "is_up": "0", //是否上架0否1是
            "desc": "", //简介
            "createtime": "2020-12-31 14:42:39" //发布时间
        }]
    })
     */
    public function download()
    {
        $list = Db::name('download')
            ->field('id,title,is_up,desc,createtime')
            ->order('is_up desc,createtime desc')
            ->limit(9)
            ->select();
        foreach ($list as &$v){
            $v['createtime'] = date('m-d',$v['createtime']);
        }
        $this->success('success',$list);
    }

    /**
     * @ApiTitle    (政策动态和下载专区图片)
     * @ApiSummary  (政策动态和下载专区图片)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/index/image_policy)
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1571492001",
        "data": {
            "policy": "http://qizhibang.brotop.cn/uploads/20210126/FkbcIo7GagNaDB_TruhfxLBfLL4h.png", //政策动态图片
            "download": "http://qizhibang.brotop.cn/uploads/20210126/FgEcWB_NtmGGS3hG1svBOAAkA4qV.png" //下载专区图片
        }
    })
     */
    public function image_policy()
    {
        $policy = Db::name('image_policy')->where('id',1)->value('image');
        $download = Db::name('image_download')->where('id',1)->value('image');
        $this->success('success',[
            'policy' => cdnurl($policy,true),
            'download' => cdnurl($download,true)
        ]);
    }

    /**
     * @ApiTitle    (模块入口)
     * @ApiSummary  (模块入口)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/index/enter)
     *
     * @ApiReturn({
        "code": 1,
        "msg": "success",
        "time": "1611660171",
        "data": {
            "study": [{ //学习平台入口
                "title": "天津市二级建造师课程", //标题
                "image": "http://qizhibang.brotop.cn/uploads/20210127/Fowbl73z1EpqVj0cBILbJL06myDf.png", //图片
                "type_id": 3, //科目分类ID
                "is_enter": 1 //是否可进入:0=否,1=是
            }],
            "class": { //优选课程入口
                "title": "2020版一建二建课程" //标题
            },
            "about": { //联系我们入口
                "phone1": "022-321321321", //联系电话一
                "phone2": "135897213233" //联系电话二
            }
        }
    })
     */
    public function enter()
    {
        // 学习平台入口
        $study = Db::name('enter_study')
            ->field('id,title,image,type_id')
            ->order('createtime desc')
            ->select();
        foreach ($study as &$v){
            $v['image'] = cdnurl($v['image'],true);
            $where = [
                'a.type_id' => $v['type_id'],
                'b.third_id' => $this->auth->id
            ];
            $erzi = Db::name('type')->where('id',$v['type_id'])->field('id,pid')->select();
            if(!empty($erzi)){
                $erzi_id = array_column($erzi,"id");
                $sunzi = Db::name('type')->where(['pid'=>['in',$erzi_id]])->field("id")->select();
                $sunzi_id = array_column($sunzi,"id");
                $son = array_merge($sunzi_id,$erzi_id);
                $where['a.type_id'] = ['in',$son];
            }
            $list = Db::name('study')
                ->alias('a')
                ->join('third_study b','b.study_id = a.id')
                ->where($where)
                ->select();
            $v['is_enter'] = count($list) > 0 ? 1 : 0;
        }
        // 优选课程入口
        $class = Db::name('enter_class')->where('id',1)->field('title')->find();
        // 联系我们入口
        $about = Db::name('enter_about')->where('id',1)->field('phone1,phone2')->find();
        $this->success('success',compact('study','class','about'));
    }
}