IndexController.php 5.3 KB
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\portal\controller;

use app\admin\model\HospitalModel;
use app\admin\model\JobModel;
use app\portal\model\PortalPostModel;
use app\user\model\UserModel;
use cmf\controller\HomeBaseController;
use EasyWeChat\Foundation\Application;
use cmf\controller\WeChatBaseController;
use think\Log;


class IndexController extends WeChatBaseController
{
    public function index()
    {
        $User=new UserModel();
        $user=$User->getUserInfo();
        if (empty($user['user_login'])){
            $targetUrl=url('register');
            header('location:'. $targetUrl);
        }
        $Article=new PortalPostModel();
        $article=$Article->getRecommend()->toArray();
        $this->assign('article',$article);
        return $this->fetch();
    }

    public function register()
    {
        /*检查用户是否注册成功*/
        $User=new UserModel();
        $user=$User->getMyself()->toArray();
        if($user['user_login']!=null){
            $this->error('已经注册过相关信息!','/');
        }
        $Hospital = new HospitalModel();
        $hospital = $Hospital->getHospital();
        $platform = $Hospital->getPlatment()->toArray();
        $Job = new JobModel();
        $jobs = $Job->getJob()->toArray();
        $this->assign('jobs', $jobs);
        $this->assign('platform', $platform);
        $this->assign('hospital', $hospital);
        return $this->fetch();
    }



    public function registerPost(){
        $info=input();
        /*验证验证码*/
       $check=cmf_check_verification_code($info['tel'], $info['verify_code'], $clear = false);
       if (!empty($check)){
            $this->error($check);
       }
        /*验证器检查参数*/
        $result = $this->validate($info, 'admin/Register');
        if ($result !== true) {
            $this->error($result);
        }
        /*查找openid用户进行添加信息*/
        $user_id=cmf_get_current_user_id();
        if (empty($user_id)){
            $this->error('内部错误');
        }else{
            /*添加相应的信息到用户表*/
            $insert['platform']=$info['platform'];
            $insert['hospital']=$info['hospital'];
            $insert['office']=$info['office'];
            $insert['job']=$info['job'];
            $insert['province']=$info['province'];
            $insert['city']=$info['city'];
            $insert['town']=$info['town'];
            $insert['mobile']=$info['tel'];
            $insert['user_login']=$info['user_name'];
            $User=new UserModel();
            $result=$User->register($user_id,$insert);
            if ($result==1){
                addScore($user_id,100,'注册完善信息');
                $this->success('注册成功!');
            }else{
                $this->error('注册失败!');
            }
        }
    }

    /**
     * 发送短信验证码
     * @param $tel
     */
   public function sendVerifyCode(){
        $tel=input('tel');
        $code=cmf_get_verification_code($tel, $length = 6);
        if ($code===false){
            $this->error('短信发送失败!');
        }
        $text='【金域医聊圈】您好,您的验证为'.$code.',请于5分钟内使用,如非本人操作,可忽略此消息。';
        $data = array(
            'content' 	=> $text,
            'mobile' 	=> $tel,
            'productid' => '676767',
            'xh'		=> ''
        );
        $return=send_sms($data);
        $ret=explode(',',$return);
        if ($ret[0]=='1'){
            cmf_verification_code_log($tel,$code);
            $this->success('验证码已经发送成功');
        }else{
            $info=date('Y-m-d H:i:s')." 短信发送失败 error:".$return;
            Log::write($info,'ERROR');
            $this->error('短信发送失败!');
        }
    }

    /**
     * 平台
     */
    public function platform()
    {
        $this->success('');
    }

    /**
     * 专家搜索
     */
    public function search()
    {
        return $this->fetch();
    }

    /**
     * 获取平台下的医院
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getHospital(){
        $platform=input('platform');
        if(empty($platform)){
            $this->error();
        }
        $Hospital=new HospitalModel();
        $hospital=$Hospital->getHospitalByPaltform($platform);
        $this->success('','',$hospital);
    }

    public function getOffice(){
        $platform_id=input('platform_id');
        $hospital_id=input('hospital_id');

        if (empty($platform_id)||empty($hospital_id)){
            $this->error('缺少参数');
        }
        $Hospital=new HospitalModel();
        $office=$Hospital->getOfficeByHP($platform_id,$hospital_id);

        $this->success('','',$office);
    }

    public function getJob(){

    }


}