IndexController.php 7.5 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('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. 最新成交
        $where_new['status'] = 1;
        $final['new'] = Db::name('New')->where($where_new)->order('score desc')->select()->toArray();
//       4. 合作企业
        $where_coo['status'] = 1;
        $final['coop'] = Db::name('Cooperation')->where($where_coo)->order("score desc , create_time desc")->field('pic,jump')->select()->toArray();
        foreach ($final['coop'] as $coopk=>$coopv){
            if(empty($member['pic'])){
                $pic = "../themes/simpleboot3/public/assets/images/house.jpg";
            }else{
                $pic = $coopv['pic'];
            }
            $final['coop'][$coopk]['pic'] = cmf_get_image_url($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);
    }

//    public function a(){
//        //                推荐人处理
//        if(!empty($getParam['parent_id'])){
//            $where_parentAdd['id'] = $getParam['parent_id'];
//            $where_parentAdd['type'] = 2;
//            $where_reward['type'] = 2;
//            $where_reward['status'] = 1;
//            $reward = Db::name('Reward')->where($where_reward)->order('create_time')->field('number')->find();
//            if($reward){
//                $add_agencyScore = $user->where($where_parentAdd)->setInc('reputation',$reward['number']);
//                if(!$add_agencyScore){
//                    $this->apiResponse('0','推荐奖励增加失败');
//                }else{
////                           推荐记录表
//                    $add_log['type'] = 2;
//                    $add_log['number'] = $reward['number'];
//                    $add_log['referee'] = $getParam['parent_id'];
//                    $add_log['recommen'] = $uid;
//                    $add_log['create_time'] = time();
//                    $add_log['update_time'] = time();
//                    $log = Db::name('RewardLog')->insertGetId($add_log);
//                    if(!$log){
//                        Db::rollback();
//                    }
////                           信誉记录表
//                    $add_startlog['detail'] = "推荐".$getParam['parent'].'注册';
//                    $add_startlog['star'] = $reward['number'];
//                    $add_startlog['type'] = 3;
//                    $add_startlog['create_time'] = time();
//                    $add_startlog['update_time'] = time();
//                    $startLog = Db::name('StartDetail')->insertGetId($add_startlog);
//                    if(!$startLog){
//                        Db::rollback();
//                    }
//                }
//            }else{
//                Db::rollback();
//                $this->apiResponse('0','推荐奖励获取失败');
//            }
//        }
////                end
//    }


}