Index.php 12.1 KB
<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use app\common\library\Auth;
use app\common\model\TemplateView;
use app\school\model\basic\Teacher;
use app\school\model\content\Newscategory;
use app\school\model\ManystoreShop;
use EasyWeChat\Factory;
use Overtrue\Socialite\AuthorizeFailedException;
use think\Config;
use think\Cookie;
use think\Db;
use think\Exception;
use think\Request;

class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = 'default';
    protected $template = 'weilai';
    public function _initialize()
    {
        parent::_initialize(); // TODO: Change the autogenerated stub
        $template = TemplateView::getSchoolTemplate( $this->school_id);
        $this->layout = $template->layout ?? 'default';
        $this->template = $template->template_url;
    }

    public function index()
    {
        $newsCategoryVo = new Newscategory();
        $elegant_person  = Db::name("elegant")->where("school_id", $this->school_id)->where('type',1)->limit(3)->select();
        $elegant_product = Db::name("elegant")->where("school_id", $this->school_id)->where('type',2)->limit(3)->select();
        $baseDisplayCategory =  Db::name("basedisplay_category")->where("school_id", $this->school_id)->limit(4)->select();
        if(!empty($baseDisplayCategory)){

            $baseDisplay     = Db::name("base_display")->where("school_id", $this->school_id)->where("category_id",$baseDisplayCategory[0]['category_id'])->limit(3)->select();

        }else{
            $baseDisplay= null;
        }
        $achievementsCategory =  Db::name("achievements_category")->where("school_id", $this->school_id)->limit(4)->select();
        if(!empty($achievementsCategory)){
            $achievements     = Db::name("achievements")->where("school_id", $this->school_id)->where("category_id",$achievementsCategory[0]['category_id'])->limit(3)->select();

        }else{
            $achievements = null;
        }
        $newsCategory    = $newsCategoryVo ->where('flag','index')->where(['school_id' => $this->school_id,'status'=>["<>",'lock']])->where('type','新闻')->limit(3)->order('weigh','desc')->select();

        $links = Db::name("friend_link")->where("school_id", $this->school_id)->limit(4)->select();

        foreach ($links as $k=>$v){

            if(strpos($v['link_url'],'http://') !== 0 && strpos($v['link_url'],'https://') !== 0){
                $v['link_url'] = 'http://'.$v['link_url'];
            }

            $links[$k] = $v;
        }
        $double_list = Db::name("project_double")->where("school_id",$this->school_id)->order("id","desc")->limit(4)->select();
        $config = Config::get("upload");
        $this->assign('double_list',$double_list);
        $this->assign('category',$newsCategory);
        $this->assign('cdnurl',$config['cdnurl']);
        $this->assign('baseDisplayCategory',$baseDisplayCategory);
        $this->assign('baseDisplay',$baseDisplay);
        $this->assign('achievementsCategory',$achievementsCategory);
        $this->assign('achievements',$achievements);
        $this->assign('elegant_person',$elegant_person);
        $this->assign('elegant_product',$elegant_product);
        $this->assign('links',$links);
        $this->view->assign('index',$index='foot');//首页隐藏头部使用

        if (isWechat()){
            $config = [
                'app_id' => 'wx401d047673f1c578',
                'secret' => '2f99955f1964d30d6e962c345c268274',
                'response_type' => 'array',
            ];
            $app = Factory::officialAccount($config);
            try {
                $oauth = $app->oauth;
                $user = $oauth->user();
                session("open_id",$user->id);
            }catch (AuthorizeFailedException $e){
                $response = $app->oauth->scopes(['snsapi_userinfo'])
                    ->redirect($this->request->domain());
                $response->send();
            }
        }
        return $this->view->fetch("/index/school/{$this->template}");
    }

    // 导师风采
    public function teacherlist(){

        $param = $this->request->param();

        switch(intval($param['type'])){
            case 1://校园导师
                $list = Db::name("teacher")->where("type",1)->where("school_id",$this->school_id)->paginate(3,false,['param'=>request()->param()]);
                $text='校园导师';
                break;
            case 2://企业导师
                $list = Db::name("teacher")->where("type",2)->where("school_id",$this->school_id)->paginate(3,false,['param'=>request()->param()]);
                $text='企业导师';
                break;
            case 3://专家评委
                $list = Db::name("project_experts")->field('*,nickname as username')->where("school_id",$this->school_id)->paginate(3,false,['param'=>request()->param()]);;
                $text='专家评委';
                break;
            default:
                $text='校园导师';
                $list = Db::name("teacher")->where("type",1)->where("school_id",$this->school_id)->paginate(3,false,['param'=>request()->param()]);
        }

        $page = null;
        if(!empty($list)){
            $page = $list->render();
        }
        $this->assign("type",$param['type']);
        $this->assign("list",$list);
        $this->assign("text",$text);
        $this->assign("page",$page);
        $this->view->assign('index',$index='foot');//首页隐藏头部使用
        return $this->fetch();
    }
    // 教师团队详情页
    public function teacher_detail(){
        $param = $this->request->param();
        $teacherObj = new Teacher();

        switch(intval($param['type'])){
            case 1://校园导师
                $info = $teacherObj->where("id",$param['id'])->find();
                $text='校园导师';
                break;
            case 2://企业导师
                $info = $teacherObj->where("id",$param['id'])->find();
                $text='企业导师';
                break;
            case 3://专家评委
                $info = Db::name("project_experts")->where("id",$param['id'])->find();
//                $info = $teacherObj->where("id",$param['id'])->find();
                $text='专家评委';
                break;
            default:
                $text='校园导师';
                $info = $teacherObj->where("id",$param['id'])->find();
        }
//        dump($param);die;
        $info['project'] = Db::name("project_register")->field("project_name")->where("find_in_set(:id,`project_teacher_ids`)",["id"=>$info['id']])->limit(5)->select();
//        $match_items= Db::name("match_items_details")->whereraw("teacher_id = {$info['id']}")->column("match_items_id");
//        $matchs = Db::name("match_items")->whereIn("match_id",array_unique($match_items))->column("match_id");
//        $info["match"] =Db::name("match")->whereIn("id",$matchs)->select();
//        $info["match"] =Db::name("match")->whereIn("id",$matchs)->select();
        $this->assign("type",$param['type']);
        $this->assign("info",$info);
        $this->assign("text",$text);
        $this->view->assign('index',$index='foot');//首页隐藏头部使用
        return $this->fetch();
    }
    //创意产品展
    public function exhibition(){
        $elegant_list  = Db::name("elegant")->where("school_id", $this->school_id)->where('type',2)->paginate(10,false,['param'=>request()->param()]);
        $this->assign("list",$elegant_list);
        $this->view->assign('index',$index='foot');//首页隐藏头部使用
        return $this->fetch();
    }
    // 创意作品展详情
    public function exhibition_detail($id=0){
        Db::name("elegant")->where("elegant_id", $id)->setInc("visits_count");
        $info  = Db::name("elegant")->where("elegant_id", $id)->find();
        $this->assign("info",$info);
        $this->view->assign('index',$index='foot');//首页隐藏头部使用
        return $this->fetch();
    }
    //风云榜
    public function event_list(){
        $page= null;
        $uid = Cookie::get("uid");
        $elegant_list  = Db::name("elegant")->where("school_id", $this->school_id)->where('type',1)->paginate(3,false,['param'=>request()->param()]);
        foreach ($elegant_list as $k=>$v){
            $like =Db::name('like')->where(["user_id"=>$uid,'data_id'=>$v['elegant_id'],'table_name'=>'elegant'])->find();
            if(empty($like)){
                $v['like'] =0;
            }else{
                $v['like'] =1;
            }
            $elegant_list[$k] = $v;
        }
        $page = $elegant_list->render();
        $this->assign("page",$page);
        $this->assign("elegant_person",$elegant_list);
        $this->view->assign('index',$index='foot');//首页隐藏头部使用
        return $this->fetch();
    }
    //风云榜详情
    public function event_detail($id=0){
        $uid = Cookie::get("uid");
        Db::name("elegant")->where("elegant_id", $id)->setInc("visits_count",1);
        $info  = Db::name("elegant")->where("elegant_id", $id)->find();

//        $info_['college'] = $user['college'];
//        $info_['specialty'] = $user['specialty'];
//        $info_['bio'] = $user['bio'];
//        $info = array_merge($info,$info_);
        $this->assign("info",$info);
        $this->view->assign('index',$index='foot');//首页隐藏头部使用
        return $this->fetch();
    }

    public function getBasedisplay(){
        $param = $this->request->param();
        $baseDisplay     = Db::name("base_display")->where("school_id", $this->school_id)->where("category_id",$param['category_id'])->limit(3)->select();
        $data['data'] = $baseDisplay;
        $data['type'] = 1;
        $this->success('','',$data);
    }
    public function getAchievements(){
        $param = $this->request->param();
        $achievements    = Db::name("achievements")->where("school_id", $this->school_id)->where("category_id",$param['category_id'])->limit(3)->select();
        $data['data'] = $achievements;
        $data['type'] = 2;
        $this->success('','',$data);
    }

    //学校简介
    public function college_profile(){
        $schoolInfo = ManystoreShop::get($this->school_id);
        $this->view->assign('schoolinfo',$schoolInfo);
        $this->view->assign('index',$index='foot');//首页隐藏头部使用
        return $this->fetch();
    }
    //组织架构
    public function organizational(){
        $schoolInfo = ManystoreShop::get($this->school_id);
        $this->view->assign('schoolinfo',$schoolInfo);
        $this->view->assign('index',$index='foot');//首页隐藏头部使用
        return $this->fetch();
    }
    //政策制度
    public function policy_system(){

        $this->view->assign('index',$index='foot');//首页隐藏头部使用
        return $this->fetch();
    }
    //政策详情
    public function policy_detail(){
        $this->view->assign('index',$index='foot');//首页隐藏头部使用
        return $this->fetch();
    }

    public function Ilike_elegant(){
        $uid = Cookie::get("uid");
        if(empty($uid)){
            $this->error("请登录",url('student_login/index'));
        }
        $param = $this->request->param();
        if(!empty($param['id'])){
            $type = 0;
            $insert['user_id'] = $uid;
            $insert['data_id'] = $param['id'];
            $insert['table_name'] = 'elegant';
            $info = Db::name('like')->where($insert)->find();
            if(empty($info)){
                $insert['type'] = 0;
                $insert["create_time"] = time();
                $status = Db::name('like')->insert($insert);
                if($status){
                    $status =Db::name("elegant")->where("elegant_id",  $insert['data_id'])->setInc("like_count");
                    if($status){
                        $this->success('','',1);
                    }
                }
            }else{
                $status= Db::name('like')->where('id',$info['id'])->delete();
                if($status){
                    $status = Db::name("elegant")->where("elegant_id",  $insert['data_id'])->setDec("like_count");
                    if($status){
                        $this->success('','',2);
                    }
                }
            }

        }
    }

}