IndexController.php 8.2 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)
    {
//        推荐人
        $getParam = $request->param();
        if(!empty($getParam['uid'])){
            $where_parent['id'] = $getParam['uid'];
            $parent = Db::name('Member')->where($where_parent)->field('id as parent_id,tel as parent_tel')->find();
            $final['parent'] = $parent;
        }
//        1.首页轮播
        $where_banner['status'] = 1;
        $final['banner'] = Db::name('Banner')->where($where_banner)
            ->field("pic")
            ->order("score desc,create_time desc")->select()->toArray();
        foreach ($final['banner'] as $bannerk=>$bannerv){
            $final['banner'][$bannerk]['pic'] = cmf_get_image_url($bannerv['pic']);
        }
//        2.交易流程
        $where_process['status'] = 1;
        $where_process['type'] = $request->param('chooseType');
        $final['process'] = Db::name('Process')->where($where_process)
            ->field("content")
            ->order('create_time desc')
            ->find();
        $final['process']['content'] = cmf_replace_content_file_url(htmlspecialchars_decode($final['process']['content']));
//        3. 最新成交
        $where_new['status'] = 1;
        $final['new'] = Db::name('New')->where($where_new)->order('score desc')->select()->toArray();
        if($final['new']){
            foreach ($final['new'] as $cok=>$cov){
                $exp = explode('.',$cov['save']);
                if($exp[1] == 0){
                    $final['new'][$cok]['save'] = $exp[0];
                }else{
                    $else = str_split($exp[1]);
                    if($else[1] == 0){
                        $final['new'][$cok]['save'] = $exp[0].'.'.$else[0];
                    }
                }
            }
        }
//       4. 合作企业
        $where_coo['status'] = 1;
        if(!empty($getParam['chooseType'])){
            $where_coo['type'] = $getParam['chooseType'];
        }else{
            $this->apiResponse('0','类型错误');
        }
        $final['coop'] = Db::name('Cooperation')->where($where_coo)->order("score desc , create_time desc")->field('pic,jump')->limit(40)->select()->toArray();
        foreach ($final['coop'] as $coopk=>$coopv){
            if(empty($coopv['pic'])){
                $final['coop'][$coopk]['pic'] = "../themes/simpleboot3/public/assets/images/house.jpg";
            }else{
                $final['coop'][$coopk]['pic'] = cmf_get_image_url($coopv['pic']);
            }

        }
//        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);
    }

    /**
     * @title  两分钟视频
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/Index/video
     * @method POST
     */
    public function video(){
        $where_video['status'] = 1;
        $find = Db::name('Video')->where($where_video)->order('create_time desc')->find();
        $this->apiResponse('1','成功',$find);
    }


    /**
     * @title  首页二维码
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/Index/code
     * @method POST
     */
    public function code(){
        $where_video['status'] = 1;
        $find = Db::name('Qrcode')->where($where_video)->order('create_time desc')->select()->toArray();
        if($find){
            foreach ($find as $k=>$v){
                $find[$k]['path'] = cmf_get_image_url($v['path']);
            }
        }
        $this->apiResponse('1','成功',$find);
    }


    /**
     * @title  首页推广
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/Index/share
     * @method POST
     */
    public function share(){
        $where_push['status'] = 1;
        $list = Db::name('Push')->where($where_push)->find();
        if($list){
            $list['content'] = htmlspecialchars_decode($list['content']);
        }
        $final['content'] = $list;
        $this->apiResponse('1','成功',$final);
    }



    /**
     * @title  客服消息
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/Index/conf
     * @method POST
     */
    public function conf(){
        $where_push['status'] = 1;
        $list = Db::name('Conf')->where($where_push)->select()->toArray();
        if($list){
            foreach ($list as $listk=>$listv){
                $list[$listk]['wx_public'] = cmf_get_image_url($listv['wx_public']);
                $list[$listk]['wx_service'] = cmf_get_image_url($listv['wx_service']);
            }
        }
        $final['content'] = $list;
        $this->apiResponse('1','成功',$final);
    }
}