IndexController.php 4.6 KB
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace api\portal\controller;
use think\Controller;
//use api\portal\model\MemberModel;
//use api\portal\model\UserModel;
//use api\portal\service\PostService;
use think\Db;
use think\Request;
use think\Loader;
/**
 * @title 首页接口
 * @description 接口说明
 * @group 接口分组
 */

class IndexController extends CommonController
{
    /**
     * @title  首页
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/Index/index
     * @method POST
     * @param name:chooseType type:int require:1 default: other: desc:类型:1手机站,2PC站


     */

    public function index(Request $request)
    {
//        1.首页轮播
        $where_banner['status'] = 1;
        $final['banner'] = Db::name('Banner')->where($where_banner)
            ->field("pic")
            ->order("score desc,create_time desc")->select()->toArray();
//        2.交易流程
        $where_process['status'] = 1;
        $where_process['type'] = $request->param('type');
        $final['process'] = Db::name('Process')->where($where_process)
            ->field("content")
            ->order('create_time desc')
            ->find();
        $final['process']['content'] = htmlspecialchars_decode($final['process']['content']);
//        3. 最新成交
//        Db::name('Agency')->where()




//       4. 合作企业
        $where_coo['status'] = 1;
        $final['coop'] = Db::name('Cooperation')->where($where_coo)->order("score desc , create_time desc")->field('pic,jump')->select()->toArray();
//        5. 文章
        $where_cate['c.delete_time'] = 0;
        $where_cate['c.status'] = 1;
        $where_cate['j.status'] = 1;
//        分类
        $connect = Db::name('PortalCategoryPost')->alias('j')
            ->where($where_cate)
            ->join("PortalCategory c",'c.id = j.category_id')
//            ->join("PortalPost p",'p.id = j.post_id')
//            ->group('j.category_id')
            ->field("j.id as jid ,j.post_id,j.category_id,c.name")
            ->select()->toArray();
        $cate_arr = array();
        $post_arr = array();
        $connect_arr = array();
//        处理分类id
        foreach ($connect as $conk=>$conv){
            $cate_arr[] = $conv['category_id'];
            $post_arr[] = $conv['post_id'];
            $connect_arr[$conk]['category_id'] = $conv['category_id'];
            $connect_arr[$conk]['post_id'] = $conv['post_id'];
        }
        $cate_arr = array_values(array_unique($cate_arr));
//        查询分类
        $where_cateNext['id'] = array('in',$cate_arr);
        $cateNext_list = Db::name('PortalCategory')->where($where_cateNext)->field('id,name')->select()->toArray();
//        查文章
        $where_arr['post_status'] =  1;
        $where_arr['id'] =  array('in',$post_arr);
        $artcile = Db::name('PortalPost')
            ->where($where_arr)
            ->field('id,post_title')
            ->order("create_time desc")
            ->select()->toArray();
        $middle =array();
//        拼数组
//        循环关联
        foreach ($connect_arr as $conNextk=>$conNextv){
//            循环类
            foreach ($cateNext_list as $catNextk=>$catNextv){
                $middle[$catNextk]['id'] =  $catNextv['id'];
                $middle[$catNextk]['name'] =  $catNextv['name'];
//                循环文章
                foreach ($artcile as $artNextk=>$artNextv){
                    if($conNextv['category_id'] == $catNextv['id']){
//                        $key = $catNextv['name'];
                        if($conNextv['post_id'] == $artNextv['id']){
//                            $middle[$key][$artNextk]['title'] = $artNextv['post_title'];
//                            $middle[$key][$artNextk]['id'] = $artNextv['id'];
                            $middle[$catNextk]['list'][$artNextk]['id'] =  $artNextv['id'];
                            $middle[$catNextk]['list'][$artNextk]['title'] =  $artNextv['post_title'];
                        }
                    }
                }
            }
        }
        $final['article'] = $middle;

        $this->apiResponse('1','成功',$final);
    }

}