IndexController.php 26.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Powerless < wzxaini9@gmail.com>
// +----------------------------------------------------------------------
namespace app\user\controller;

use app\admin\model\HospitalModel;
use app\portal\model\OrderModel;
use app\user\model\TransferModel;
use app\user\model\UserModel;
use app\user\model\InquiryModel;
use cmf\controller\HomeBaseController;
use cmf\controller\WeChatBaseController;
use Qiniu\Auth;
use Qiniu\Storage\UploadManager;
use think\Db;
use EasyWeChat\Foundation\Application;
use think\Log;
use think\Request;



class IndexController extends WeChatBaseController
{

    protected $UserModel;

    public function __construct(UserModel $UserModel)
    {
        parent::__construct();
        $this->UserModel = $UserModel;
    }

    public function callback(){
        $appId=config('wechat_config.app_id');
        $secret=config('wechat_config.secret');
        $config = [
            'app_id'  => $appId,
            'secret'  => $secret,
        ];

        $app = new Application($config);
        $oauth = $app->oauth;
        $user = $oauth->user();
        $wechat_user = $user->toArray();
        if(isset($wechat_user['id'])){
            $openid=$wechat_user['id'];
            $findThirdPartyUser = Db::name("third_party_user")
                ->where('openid', $openid)
                ->where('app_id', $appId)
                ->find();
            if ($findThirdPartyUser) {
                $this->wechatUserLogin($findThirdPartyUser,$openid,$appId);
            }else{
                $this->wechatUserRegister($wechat_user,$openid,$appId);
            }
            $target_url=session('target_url');
            $targetUrl = empty($target_url) ? url('/') : $target_url;
            header('location:'. $targetUrl);
        }else{
            Log::write('获取微信用户数据失败');
            $this->error('获取微信用户数据失败');
        }

    }

    /**
     * 微信用户登录
     * @param $findThirdPartyUser
     * @param $openid
     * @param $appId
     */
    protected function wechatUserLogin($findThirdPartyUser,$openid,$appId){
        $currentTime = time();
        $ip          = $this->request->ip(0, true);
        $token = cmf_generate_user_token($findThirdPartyUser['user_id'], 'public');
        $userData = [
            'last_login_ip'   => $ip,
            'last_login_time' => $currentTime,
            'login_times'     => ['exp', 'login_times+1']
        ];
        $row1=Db::name("third_party_user")
            ->where('openid', $openid)
            ->where('app_id', $appId)
            ->update($userData);
        $userInfo=Db::name("third_party_user")
            ->where('openid', $openid)
            ->where('app_id', $appId)->find();
        unset($userData['login_times']);
        $row2=Db::name("user")
            ->where('id', $userInfo['user_id'])
            ->update($userData);
        if($row1!==false&&$row2!==false){
            $userModel=new UserModel();
            $user=$userModel->getUserInfo(['user_id'=>$userInfo['user_id'],'app_id'=>$appId]);
            cmf_update_current_user($user);
            session('token',$token);
            Db::commit();
        }else{
            Db::rollback();
        }
    }

    /**
     * 微信用户注册
     * @param $wechat_user
     * @param $openid
     * @param $appId
     */
    protected function wechatUserRegister($wechat_user,$openid,$appId){
        $currentTime = time();
        $ip          = $this->request->ip(0, true);
        Db::startTrans();
        $userId = Db::name("user")->insertGetId([
            'create_time'     => $currentTime,
            'user_status'     => 1,
            'user_type'       => 2,
            'sex'             => $wechat_user['original']['sex'],
            'user_nickname'   => $wechat_user['nickname'],
            'avatar'          => $wechat_user['avatar'],
            'last_login_ip'   => $ip,
            'last_login_time' => $currentTime,
        ]);

        $row=Db::name("third_party_user")->insert([
            'openid'          => $openid,
            'user_id'         => $userId,
            'third_party'     => 'public',
            'nickname'        => $wechat_user['nickname'],
            'app_id'          => $appId,
            'last_login_ip'   => $ip,
            'union_id'        => '',
            'last_login_time' => $currentTime,
            'create_time'     => $currentTime,
            'login_times'     => 1,
            'status'          => 1,
            'more'            => json_encode($wechat_user)
        ]);
        if($userId && $row){
            $token = cmf_generate_user_token($userId, 'public');
            $userModel=new UserModel();
            $user=$userModel->getUserInfo(['user_id'=>$userId,'app_id'=>$appId]);
            cmf_update_current_user($user);
            session('token',$token);
            Db::commit();
        }else{
            Db::rollback();
        }
    }

    /**
     * 前台用户首页(公开)
     */
    public function index_bak()
    {
        $id   = $this->request->param("id", 0, "intval");
        $userQuery = Db::name("User");
        $user = $userQuery->where('id',$id)->find();
        if (empty($user)) {
            session('user',null);
            $this->error("查无此人!");
        }
        $this->assign($user);
        return $this->fetch(":index");

    }

    /**
     * 个人首页
     * @return mixed
     */
    public function index(){
        $user=$this->UserModel->getMyself()->toArray();
        $message=$this->UserModel->userMessage()->toArray();
        if (empty($user['user_login'])){
            $targetUrl=url('portal/index/register');
            header('location:'. $targetUrl);
        }
        /*收货地址sdk*/

        $config=config('wechat_config');
        $Wechat=new Application($config);
        $userId=cmf_get_current_user_id();
        $where['expert_id|user_id']=$userId;
        $where1['user_id']=$userId;
        $count['0']=db('inquiry')->where($where)->where('status',0)->count('id');
        $count['1']=db('transfer')->where($where)->where('status',0)->count('id');
        $count['2']=db('engage')->where($where1)->where('state',0)->count('id');;
        $this->assign('count',$count);
        $js = $Wechat->js;
        $api[]='openAddress';
        $sdk=$js->config($api, false);
        $this->assign('sdk',$sdk);
        $message_count=count($message);
        $this->assign('user',$user);
        $this->assign('message_count',$message_count);
       return $this->fetch();
    }

    /**
     * 打卡页面
     * @return mixed
     */
    public function signIn(){
        $map['user_id']=cmf_get_current_user_id();
        $map['month']=date('m',time());
        $map['year']=date('Y',time());
        $this->assign(cmf_get_option('site_info'));
        $sign_info=\db('sign_in')->field('month,day')->where($map)->select()->toArray();
        $this->assign('sign_info',$sign_info);
        return $this->fetch();
    }

    /**
     * 打卡操作
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function doSignIn(){
        $data['user_id']=cmf_get_current_user_id();
        $data['month']=date('m',time());
        $data['year']=date('Y',time());
        $data['day']=date('d',time());
        $isin=\db('sign_in')->where($data)->find();
        if ($isin){
            $this->error('今日已打卡!');
        }
        $data['add_time']=time();
        $result=db('sign_in')->insert($data);
        if ($result){
            $site=cmf_get_option('site_info');
            addScore($data['user_id'],$site['sign_in'],'签到打卡');
            $this->success();
        }else{
            $this->error();
        }
    }
    /**
     * 前台ajax 判断用户登录状态接口
     */
    function isLogin()
    {
        if (cmf_is_user_login()) {
            $this->success("用户已登录",null,['user'=>cmf_get_current_user()]);
        } else {
            $this->error("此用户未登录!");
        }
    }

    /**
     * 退出登录
    */
    public function logout()
    {
        session("user", null);//只有前台用户退出
        return redirect($this->request->root() . "/");
    }


    /**
     * 我的积分页
     * @return mixed
     */
    public function myScore(){
        /*当前积分*/
        $user_id=cmf_get_current_user_id();
        $User=new UserModel();
        $user=$User->getMyself()->toArray();
        /*总收入*/
        $map['score']=['>',0];
        $map['user_id']=$user_id;
        $info['get']=\db('user_score_log')->where($map)->sum('score');
        /*已使用*/
        $map1['score']=['<',0];
        $map1['user_id']=$user_id;
        $info['used']=abs(\db('user_score_log')->where($map1)->sum('score'));
        $this->assign('score',$user['score']);
        $this->assign('info',$info);
        return $this->fetch();
    }

    /**
     * 我的积分收入
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function myScoreInInfo(){
        $map['user_id']=cmf_get_current_user_id();
        $map['score']=['>',0];
        $info=\db('user_score_log')->where($map)->order('id','desc')->select();
        $this->assign('info',$info);
        return $this->fetch();
    }

    /**
     * 我的积分消费
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function myScoreOutInfo(){
        $map['user_id']=cmf_get_current_user_id();
        $map['score']=['<',0];
        $info=\db('user_score_log')->where($map)->order('id','desc')->select();
        $this->assign('info',$info);
        return $this->fetch();
    }

    public function myData(){
        $id=cmf_get_current_user_id();
        $user=$this->UserModel->getUser($id)->toArray()[0];
        $user1=$this->UserModel->getMyself()->toArray();
        $user=array_merge($user1,$user);

        $this->assign('user',$user);
        return $this->fetch();
    }

    public function myOrder(){
        $Order=new  OrderModel();
        $user_id=cmf_get_current_user_id();
        $order=$Order->getOrderByType($user_id)->toArray();
        $order2=$Order->getOrderByType($user_id,2)->toArray();
        $order3=$Order->getOrderByType($user_id,3)->toArray();
        $this->assign('order',$order);
        $this->assign('order2',$order2);
        $this->assign('order3',$order3);
        return $this->fetch();
    }

    public function myAddress(){
        return $this->fetch();
    }

    public function myFriends(){
        return $this->fetch();
    }

    public function kefu(){

        $this->assign(cmf_get_option('site_info'));
        return $this->fetch();
    }


    public function editInfo(){
        $map['id']=cmf_get_current_user_id();
        $avatar=input('avatar');
        if(!empty($avatar)){
            $data['avatar']=input('avatar');
        }
        $data['user_login']=input('name');
        $data['mobile']=input('mobile');
        $result=$this->UserModel->where($map)->update($data);
        if ($result==1){
                $this->success();
        }else{
                $this->error();
        }
    }

    public function uploadavatar(){
        header("content-type:text/html;charset=utf-8");
        $allowedExts = array("gif", "jpeg", "jpg", "png");
        $temp = explode(".", $_FILES["image"]["name"]);
        $extension = end($temp);
        if ((($_FILES["image"]["type"] == "image/gif")
                || ($_FILES["image"]["type"] == "image/jpeg")
                || ($_FILES["image"]["type"] == "image/jpg")
                || ($_FILES["image"]["type"] == "image/pjpeg")
                || ($_FILES["image"]["type"] == "image/x-png")
                || ($_FILES["image"]["type"] == "image/png"))
            && ($_FILES["image"]["size"] < 2048000)
            && in_array($extension, $allowedExts)) {
            if ($_FILES["image"]["error"] > 0) {
                $list['ok'] = 0;
                $list['error'] = "上传错误";
//     echo json_encode($list);
            } else {
                if ($_FILES["image"]["type"] == "image/gif") {
                    $img = date('Ymdgi-s') . '.gif';
                } else if ($_FILES["image"]["type"] == "image/jpeg" || $_FILES["image"]["type"] == "image/jpg" || $_FILES["image"]["type"] == "image/pjpeg") {
                    $img = date('Ymdgi-s') . '.jpg';
                } else {
                    $img = date('Ymdgi-s') . '.png';
                }
                $path = ROOT_PATH . 'public' . DS . 'static' . DS . 'avatar/' . $img;
                move_uploaded_file($_FILES["image"]["tmp_name"], $path);
                $request = Request::instance();
                $domain = $request->domain();
                $url = $domain . "/static/avatar/" . $img;
                $image = \think\Image::open($path);
                $image->thumb(300, 300, \think\Image::THUMB_CENTER)->save($path);
                $msg['url'] = $url;
                $data['avatar']=$url;
                $result=$this->UserModel->where('id',cmf_get_current_user_id())->Update($data);
                if ($result==1){
                    $this->success('上传成功!');
                }else{
                    $this->error('上传失败!');
                }

            }
        } else {
            $list['ok'] = 2;
            $list['error'] = "无效的图像";
            $this->error('无效的图像');
        }

    }

    public function orderInfo(){
        $order_id=input('id');
        $Order=new OrderModel();
        $order=$Order->getOrderById($order_id)->toArray();
        $this->assign('order',$order);
        return $this->fetch();
    }

    /**
     * 我要问诊页面
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function inquiry(){
        $User=new UserModel();
        $user=$User->getUserInfo();
        if (empty($user['user_login'])){
            $targetUrl=url('portal/index/register');
            header('location:'. $targetUrl);
        }
        $Hospital= new HospitalModel();
        $config=config('wechat_config');
        $Wechat=new Application($config);
        $js = $Wechat->js;
        $api[]='startRecord';
        $api[]='stopRecord';
        $api[]='onVoiceRecordEnd';
        $api[]='playVoice';
        $api[]='pauseVoice';
        $api[]='stopVoice';
        $api[]='onVoicePlayEnd';
        $api[]='uploadVoice';
        $api[]='downloadVoice';
        $api[]='chooseImage';
        $api[]='previewImage';
        $api[]='uploadImage';
        $api[]='downloadImage';
        $api[]='translateVoice';
        $sdk=$js->config($api, false);
        $platment=$Hospital->getPaltform()->toArray();
        $hospital=$Hospital->getHospital()->toArray();
        $this->assign(cmf_get_option('site_info'));
        $this->assign('hospital',$hospital);
        $this->assign('platment',$platment);
        $this->assign('sdk',$sdk);
        return $this->fetch();
    }

    public function remmoedExpert(){
        $map['id']=input('id');
        $expert=\db('portal_category')->where($map)->value('expert');
        if(empty($expert)){
            $this->error('');
        }
        $expert=$this->UserModel->getExpert($expert)->toArray();
        if (!empty($expert)){
            $this->success('','',$expert['0']);
        }
    }

    public function inqueryPost(){
        $data=input();
        $insert['user_id']=cmf_get_current_user_id();
        $insert['expert_id']=$data['expert_id'];
        $model=new InquiryModel();
        $time=time()-30;
        $find=$model->where($insert)->order('addtime','desc')->find();
        $lastTime=empty($find['addtime'])?0:$find['addtime'];
        if($lastTime>$time){
            $this->error('您已经提交过了');
        }

        //病人主诉判断是音频还是文字
        $insert['patient']=$this->getSaveContent($data,'patient');
        $insert['problem']=$this->getSaveContent($data,'problem');
        $insert['diagnose']=$this->getSaveContent($data,'diagnose');
        $photos=[];
        if(!empty($data['photos'])){
            $photosMedia=explode(',',$data['photos']);
            foreach ($photosMedia as $k=>$v){
                if(!empty($v)){
                    $photos[]=$this->upload_wx_pic_mul($v);
                }
            }
        }

        $insert['report']=implode(',',$photos);
        $insert['addtime']=time();
        $insert['delete_time']=0;
        $model=new InquiryModel();
        $model->adminAdd($insert);
        $site=cmf_get_option('site_info');
        addScore($insert['user_id'],$site['inquiry'],'发送问诊');
        $this->success('',url('index'),$insert);

    }

    public function getSaveContent($input,$name){
        $return['type']=$input[$name.'_type'];
        if ($return['type']==1){
            $return['content']=explode(',',$input[$name]);
            $dir=[];
            foreach ($return['content'] as $k=>$v) {
                $dir[$k]=$this->saveWxVoice($v);
            }
            $return['dir']=$dir;
        }else{
            $return['content']=$input[$name];
        }
        return $return;
    }

    /**
     * 获取微信语音到本地
     * @param $audioID
     */
    public function saveWxVoice($mediaId){
        $config=config('wechat_config');
        $Wechat=new Application($config);
        $temporary = $Wechat->material_temporary;
        $dir=ROOT_PATH.'public/'.'upload/inquery'.'/';
        $name=date('YmdHis',time()).rand(1000,9999);
        $file=$name.'.amr';
        $data=$temporary->download($mediaId,"$dir", "$file");
        $filePath=$dir.$file;

        $result=$this->upChange($filePath,$name);
        if($result['err']==0){
            return $result['data'];
        }else{
            $this->error($result['msg']);
        }
    }

    /**
     * 录音文件amr转mp3
     * @param $filePath 文件绝对路径
     * @param $name 文件名不含后缀
     * @return mixed
     */
    protected function upChange($filePath,$name){

        //转码时使用的队列名称
        $pipeline = 'jyht_list';

        //要进行转码的转码操作
        $fops = "avthumb/mp3/ab/320k/ar/44100/acodec/libmp3lame";

        //可以对转码后的文件进行使用saveas参数自定义命名,当然也可以不指定文件会默认命名并保存在当间
        $savekey = \Qiniu\base64_urlSafeEncode("jyht:$name.mp3");//目标Bucket_Name:自定义文件key
        $fops = $fops.'|saveas/'.$savekey;

        $policy = array(
            'persistentOps' => $fops,
            'persistentPipeline' => $pipeline
        );
        $key = "$name.mp3";
        $ret=$this->uploadToQiniu($filePath,$key,$policy);
        return $ret;
    }

    /**
     * @return mixed
     * @throws \EasyWeChat\Core\Exceptions\InvalidArgumentException
     */
    public function upload_wx_pic_mul($mediaId)
    {
        $config=config('wechat_config');
        $Wechat=new Application($config);
        $temporary = $Wechat->material_temporary;
        $dir=ROOT_PATH.'public/'.'upload/friend'.'/';
        $name=date('YmdHis',time()).rand(1000,9999).'.jpg';
        $data=$temporary->download($mediaId,"$dir", "$name");
        $filePath=$dir.$name;
        $result=$this->uploadToQiniu($filePath,$name);
        if($result['err']===0){
            return $result['data'];
        }else{
            $this->error($result['msg']);
        }
        return $data;
    }

    /**
     * @param $filePath
     * @param $save_name
     * @param $policy
     * @return array
     */
    protected function uploadToQiniu($filePath,$save_name,$policy=null){
        $plugin=Db::name('plugin')->field('config')->where(['name'=>'Qiniu'])->find();
        $config=json_decode($plugin['config'],true);

        // 上传到七牛后保存的文件名
        $key =$save_name;

        require_once VENDOR_PATH . 'qiniu/php-sdk/autoload.php';

        // 需要填写你的 Access Key 和 Secret Key
        $accessKey = $config['accessKey'];
        $secretKey = $config['secretKey'];
        // 构建鉴权对象
        $auth = new Auth($accessKey,$secretKey);
        // 要上传的空间
        $bucket = $config['bucket'];
        $token = $auth->uploadToken($bucket, null, 3600, $policy);
        // 初始化 UploadManager 对象并进行文件的上传
        $uploadMgr = new UploadManager();
        // 调用 UploadManager 的 putFile 方法进行文件的上传
        list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);

        if ($err !== null) {
            return ["err"=>1,"msg"=>$err,"data"=>""];
        } else {
            unlink($filePath);
            return ["err"=>0,"msg"=>"上传完成","data"=>cmf_get_asset_url($ret['key'])];
        }
    }

    /**
     * 判断类型
     * @param $input
     * @return string
     */
    public function checkType($input){
        $isin=strstr($input,'wxLocalResource');
        if($isin==false){
            return 'text';
        }else{
            return 'voice';
        }
    }
    /**
     * 我要转诊
     */
    public function transfer(){
        $User=new UserModel();
        $user=$User->getUserInfo();
        if (empty($user['user_login'])){
            $targetUrl=url('portal/index/register');
            header('location:'. $targetUrl);
        }
        $Hospital= new HospitalModel();
        $config=config('wechat_config');
        $Wechat=new Application($config);
        $js = $Wechat->js;
        $api[]='startRecord';
        $api[]='stopRecord';
        $api[]='onVoiceRecordEnd';
        $api[]='playVoice';
        $api[]='pauseVoice';
        $api[]='stopVoice';
        $api[]='onVoicePlayEnd';
        $api[]='uploadVoice';
        $api[]='downloadVoice';
        $api[]='chooseImage';
        $api[]='previewImage';
        $api[]='uploadImage';
        $api[]='downloadImage';
        $api[]='translateVoice';
        $sdk=$js->config($api, false);
        $this->assign('sdk',$sdk);
        $platment=$Hospital->getPaltform()->toArray();
        $hospital=$Hospital->getHospital()->toArray();
        $this->assign(cmf_get_option('site_info'));
        $this->assign('hospital',$hospital);
        $this->assign('platment',$platment);
        $this->assign('sdk',$sdk);
        return $this->fetch();
    }

    /**
     * 转诊提交
     */
    public function transferPost(){
        $data=input();
        $insert['user_id']=cmf_get_current_user_id();
        $insert['expert_id']=$data['expert_id'];

        $model=new TransferModel();
        $time=time()-30;
        $find=$model->where($insert)->order('addtime','desc')->find();
        $lastTime=empty($find['addtime'])?0:$find['addtime'];
        if($lastTime>$time){
            $this->error('您已经提交过了');
        }

        //病人主诉判断是音频还是文字
        $insert['clinical']=$this->getSaveContent($data,'clinical');
        $insert['inspected']=$this->getSaveContent($data,'inspected');
        $insert['diagnose']=$this->getSaveContent($data,'diagnose');
        $insert['used_drugs']=$this->getSaveContent($data,'used_drugs');
        $insert['problem']=$this->getSaveContent($data,'problem');
        $photos=[];
        if(!empty($data['photos'])){
            $photosMedia=explode(',',$data['photos']);
            foreach ($photosMedia as $k=>$v){
                if(!empty($v)){
                    $photos[]=$this->upload_wx_pic_mul($v);
                }
            }
        }
        $insert['name']=$data['name'];
        $insert['sex']=$data['sex'];
        $insert['age']=$data['age'];
        $insert['address']=$data['address'];
        $insert['report']=implode(',',$photos);
        $insert['addtime']=time();
        $insert['delete_time']=0;
        $model=new TransferModel();
        $model->adminAdd($insert);
        $site=cmf_get_option('site_info');
        addScore($insert['user_id'],$site['transfer'],'提交转诊');
        $this->success('',url('index'),$insert);
    }

    /**
     * 我要进修
     */
    public function engage(){
        $User=new UserModel();
        $user=$User->getUserInfo();
        if (empty($user['user_login'])){
            $targetUrl=url('portal/index/register');
            header('location:'. $targetUrl);
        }
        $Hospital= new HospitalModel();
        $config=config('wechat_config');
        $Wechat=new Application($config);
        $js = $Wechat->js;
        $api[]='startRecord';
        $api[]='stopRecord';
        $api[]='onVoiceRecordEnd';
        $api[]='playVoice';
        $api[]='pauseVoice';
        $api[]='stopVoice';
        $api[]='onVoicePlayEnd';
        $api[]='uploadVoice';
        $api[]='downloadVoice';
        $api[]='chooseImage';
        $api[]='previewImage';
        $api[]='uploadImage';
        $api[]='downloadImage';
        $api[]='translateVoice';
        $sdk=$js->config($api, false);
        $platment=$Hospital->getPaltform()->toArray();
        $hospital=$Hospital->getHospital()->toArray();
        $this->assign(cmf_get_option('site_info'));
        $this->assign('hospital',$hospital);
        $this->assign('platment',$platment);
        $this->assign('sdk',$sdk);
        return $this->fetch();
    }

    /**
     * 通过平台获取专家
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getExportByPlatment(){
        $platment_id=input('platment_id');
        $Hospital= new HospitalModel();
        $User=new UserModel();
        $export=$User->getExpertByPlatment($platment_id)->toArray();
        $this->success('','',$export);
    }


    public function test(){
        var_dump(cache('inquiry_insert'),cache('photos1'));
    }

}