UserController.php 32.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 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: wuwu <15093565100@163.com>
// +----------------------------------------------------------------------
namespace api\portal\controller;


use api\portal\model\CodeModel;
use api\portal\model\MemberModel;
use api\portal\model\PortalPostModel;
use cmf\controller\RestBaseController;
use think\Db;
use think\Request;
use think\Loader;
use think\Config;
use think\captcha\Captcha;
use think\Url;
use SmsDemo;
//use think\Route;
/**
 * @title 用户接口
 * @description 接口说明
 * @group 接口分组
 */

class UserController extends CommonController
{
    protected $postModel;
    public function __construct(PortalPostModel $postModel)
    {
        parent::__construct();
        $this->postModel = $postModel;
    }

//   验证码图片
    public function getImgUrl($id = "")
    {
        \think\Route::get('captcha/[:id]', "\\think\\captcha\\CaptchaController@index");
        \think\Validate::extend('captcha', function ($value, $id = "") {
            return captcha_check($value, $id, (array)\think\Config::get('captcha'));
        });

        $middle_url =  \think\Url::build('/captcha/new' . ($id ? "/{$id}" : ''));
        $rand = str_replace(".","",substr(microtime(true),-5)).rand(1000,9999);
        $imgUrl = $middle_url."&time=".$rand;
        return $imgUrl;
    }



    /**
     * @title  获取短信验证码(sure1)
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/User/getSmsResult
     * @method POST
     * @param name:tel type:int require:1 default: other: desc:手机号
     * @param name:imgCode type:int require:1 default: other:genre=2时传 desc:图片验证码
     * @param name:genre type:int require:1 default: other: desc:类型(1->用户注册/中介注册,2->密码找回,3->发布需求,4->修改手机号,5->绑定银行卡)
     * @param name:connect   type:int require:1 default: other:1 登录注册 ,2其他 desc:1
     */
//    获取短信验证码(登录)
    public function getSmsResult(Request $request){
        //            短信验证码
//        查询以前发过的验证码,并删除
        $data = $request->param();
        $where_isDouble['status'] = 1;
        $where_isDouble['type'] = $data['genre'];
        $where_isDouble['tel'] = $data['tel'];
        $updateDouble['status'] = 9;
        $updateD = Db::name('Code')->where($where_isDouble)->update($updateDouble);
        if(!$request->param('tel')){
            $this->apiResponse('0','请输入手机号');
        }else{
            $tel = $request->param('tel');
        }

        if(!$request->param('genre')){
            $this->apiResponse('0','请选择类型');
        }else{
            $genre = $request->param('genre');
            if($genre == 1 ){
                $code = 'SMS_137416617';
                $type = 1;
            }else  if($genre == 2 ){
                //            验证图形验证码
                //            验证码
                session_start();
                if(!$request->param('imgCode')){
                    $this->apiResponse('0','请先输入图形验证码');
                }
                $result = cmf_captcha_check($request->param('imgCode'));
                if(!$result) {
                    $this->apiResponse('0','验证码错误');
                }
                $code = 'SMS_137411611';
                $type = 2;
            }else  if($genre == 3 ){
                $code = 'SMS_137426773';
                $type = 3;
            }else  if($genre == 4 ){
                $code = 'SMS_137421639';
                $type = 4;
            }else  if($genre == 5 ){
                $code = 'SMS_137416654';
                $type = 5;
            }

            $tel = $request->param('tel');
        }

        $this->SmsResult($tel,$code,$type);
    }

    /**
     * @title  用户注册(sure)
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/User/join
     * @method POST
     * @param name:name type:int require:1 default: other: desc:姓名
     * @param name:tel type:int require:1 default: other: desc:手机号
     * @param name:password type:int require:1 default: other: desc:密码
     * @param name:sure_password type:int require:1 default: other: desc:确认密码
     * @param name:code type:int require:1 default: other: desc:验证码
     * @param name:connect   type:int require:1 default: other:1 登录注册 ,2其他 desc:1
     * @return data:'token'
     */
    public function join(Request $request)
    {
        if($request->Post() && $request->Post('name')) {
            Db::startTrans();
//            验证
            $validate = Loader::validate('User');
            if (!$validate->scene('user')->check($_POST)) {
                return json(array('code' => 0, 'msg' => $validate->getError()));
            }
            $data['password'] = $this->md5($_POST['password']);
            $sure_password = $this->md5($_POST['sure_password']);
//            确认密码
            if ($data['password'] != $sure_password) {
                Db::rollback();
                $this->apiResponse('0', '两次密码不一致');
            }

//           验证码
            $data['tel'] = $_POST['tel'];
            $code = $request->param('code');
            $where_code['tel'] = $data['tel'];
            $where_code['type'] = 1;
            $where_code['create_time'] = array('lt',(time()+300));
            $find_code = Db::name('Code')->where($where_code)->order('create_time desc')->field('code')->find();
            if(!$find_code){
                Db::rollback();
                $this->apiResponse('0','验证码错误,请重新获取1');
            }
            if($code != $find_code['code']){
                Db::rollback();
                $this->apiResponse('0','验证码错误,请重新获取');
            }else{
                $updateCode['status'] = 9;
                Db::name('Code')->where($where_code)->update($updateCode);
            }

            $data['name'] = $_POST['name'];

//            判断手机号是否已注册
            $user = new MemberModel();
            $where_user['tel'] = $data['tel'];
            $is_isset = $user->where($where_user)->find();
            if($is_isset){
                $this->apiResponse('0','您已注册过,请直接登录');
            }
            $str = rand(1000,9999).time().rand(100,999);
            $data['token'] = $this->md5($str);
            $data['type'] = 1;
            $data['start'] = 50;
            $add = $user->allowField(true)->save($data);
            $uid = $user->id;
            if($add){
                $startAdd['detail'] = '注册获得';
                $startAdd['star'] = 50;
                $startAdd['type'] = 1;
                $startAdd['create_time'] = time();
                $startAdd['update_time'] = time();
                $star = Db::name('StartDetail')->insertGetId($startAdd);
                if($star){
                    Db::commit();
                    $final['token'] = $data['token'];
                    $final['uid'] = $uid;
                    $this->apiResponse('1','注册成功',$final);
                }else{
                    Db::rollback();
                    $this->apiResponse('0','注册失败');
                }
            }else{
                Db::rollback();
                $this->apiResponse('0','注册失败');
            }

        }else{
//            服务协议
            $where_pro['status'] = 1;
            $where_pro['type'] = 1;
            $list = Db::name('Protocol')->where($where_pro)->order("update_time desc")->field("title,content")->find();
            $list['content'] = htmlspecialchars_decode($list['content']);
//              推荐人(未完)


            if($list){
                $this->apiResponse('1','成功',$list);
            }else{
                $this->apiResponse('0','暂无内容');
            }

        }
    }

    /**
     * @title  用户登录(sure)
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/User/login
     * @method POST
     * @param name:tel type:int require:1 default: other: desc:手机号
     * @param name:password type:int require:1 default: other: desc:密码
     * @param name:imgCode type:int require:1 default: other: desc:验证码
     * @param name:connect   type:int require:1 default: other:1 登录注册 ,2其他 desc:1
     * @return data:''@
     * @data type:'1->用户,2->中介'
     */
//    登录
    public function login(Request $request){
        if($request->post() && $request->Post('tel')){
//            登录验证
//            判空
            $tel = $request->param('tel');
            $password = $request->param('password');
            $true = $request->param('imgCode');
            if(empty($tel)){
                $this->apiResponse('0','手机号不能为空');
            }else if(empty($password)){
                $this->apiResponse('0','密码不能为空');
            }else
                if(empty($true)){
                $this->apiResponse('0','验证码不能为空');
            }
//            验证
//            验证码
            session_start();
            $result = cmf_captcha_check($true);
            if(!$result) {
                $this->apiResponse('0','验证码错误');
            }
//            手机、密码
            $memberModel = new MemberModel();
            $where_member['tel'] = $tel;
            $where_member['password'] = $this->md5($password);
            $uid = Db::name('Member')->where($where_member)->field('id,token,type')->find();
            if($uid){
//                登录重置token
                $token_str = rand(1000,9999).time().rand(100,999);
                $update_member['id'] = $uid['id'];
                $update_member['token'] = $this->md5($token_str);
//                $update_member['update_time'] = time();
                $member = $memberModel->isUpdate(true)->save($update_member);
                if($member){
                    session('uid',$uid['id']);
                    session('token',$uid['token']);
                    $final['token'] = $uid['token'];
                    $final['uid'] = $uid['id'];
                    $final['type'] = $uid['type'];
                    $this->apiResponse('1','登录成功',$final);
                }else{
                    $this->apiResponse('0','您输入的账号或密码不正确');
                }
            }
        }else{
//            返回验证码图片
            $img = $this->getImgUrl();
            $this->apiResponse('1','成功',$img);
        }
    }


    /**
     * @title  用户退出登录
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/User/outLogin
     * @method POST
     * @param name:user_id type:int require:1 default: other: desc:user_id
     * @param name:connect   type:int require:1 default: other:1 登录注册 ,2其他 desc:2
     * @param name:token type:int require:1 default: other: desc:token
     */
//    退出登录
    public function outLogin(Request $request){
//        重置token
        $str = rand(1000,9999).time().rand(100,999);
        $change['token'] = $this->md5($str);
        $where_member['id'] = $request->param('user_id');
        $where_member['token'] = $request->param('token');
        $model = new MemberModel();
        $member = $model->where($where_member)->find();
        if($member){
            $where_change['id'] = $request->param('user_id');
//            $update = $model->isUpdate(true)->allowField(true)->save($change);
            $change['update_time'] = time();
            $update = $model->where($where_change)->update($change);
            if($update){
//                unset($_SESSION['user_id']);
                $this->apiResponse('1','退出成功');
            }else{
                $this->apiResponse('0','退出失败');
            }
        }else{
            $this->apiResponse('0','用户信息错误');
        }
    }

    /**
     * @title  用户修改手机号(第一步)(sure)
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/User/changetTel
     * @method POST
     * @param name:Password type:int require:1 default: other: desc:登录密码
     * @param name:token type:int require:1 default: other: desc:token
     */
    public function changetTel(){
        $data = $this->request->param();
        $user = $this->myleft($data['token']);
        if(!empty($data['password'])){
            $userModel = new MemberModel();
            $where_change['status'] = 1;
            $where_change['token'] = $data['token'];
            $where_change['password'] = $this->md5($data['password']);
            $findChange = $userModel->where($where_change)->find();
            if($findChange){
                $this->apiResponse('1','验证成功');
            }else{
                $this->apiResponse('0','验证失败');
            }
        }else{
            $final['user'] = $user;
            $this->apiResponse('1','成功',$final);
        }

    }

    /**
     * @title  用户修改手机号(第二步)
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/User/changetTelNext
     * @method POST
     * @param name:newTel type:int require:1 default: other: desc:新手机号
     * @param name:code type:int require:1 default: other: desc:验证码
     * @param name:token type:int require:1 default: other: desc:token
     */
    public function changetTelNext(){
        $data = $this->request->param();
        $user = $this->myleft($data['token']);
        if(!empty($data['newTel'])){
            if(empty($data['code'])){
                $this->apiResponse('0','验证码不能为空');
            }
            $codeModel = new CodeModel();
            $where_code['status'] = 1;
            $where_code['type'] = 4;
            $where_code['tel'] = $data['newTel'];
            $findCode = $codeModel->where($where_code)->find();
            if($findCode['code'] != $data['code']){
                $this->apiResponse('0','验证码错误');
            }
            $userModel = new MemberModel();
//            $change['token'] = $data['token'];
            $change['id'] = $user['id'];
            $change['tel'] = $data['newTel'];
            $findChange = $userModel->isUpdate(true)->save($change);
            if($findChange){
                $this->apiResponse('1','修改成功');
            }else{
                $this->apiResponse('0','修改失败');
            }
        }else{
            $final['user'] = $user;
            $this->apiResponse('1','成功',$final);
        }

    }



    /**
     * @title  用户修改密码
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/User/changePassword
     * @method POST
     * @param name:password type:int require:1 default: other: desc:旧密码
     * @param name:newPassword type:int require:1 default: other: desc:新密码
     * @param name:sureNewPassword type:int require:1 default: other: desc:确认新密码
     * @param name:connect   type:int require:1 default: other:1 登录注册 ,2其他 desc:2
     * @param name:token type:int require:1 default: other: desc:token
     */
    //  修改密码
    public function  changePassword(Request $request){
        $data = $request->param();
        if(empty($data['password'])){
            $this->apiResponse('0','请输入原密码');
        }
        if(empty($data['newPassword'])){
            $this->apiResponse('0','请输入新密码');
        }
        if(empty($data['sureNewPassword'])){
            $this->apiResponse('0','请输入确认新密码');
        }
        $where_member['password'] = $this->md5($data['password']);
        $where_member['id'] = $data['user_id'];
        $user_id = Db::name('Member')->where($where_member)->field('id')->find();
        if($user_id){
            if($data['newPassword'] == $data['sureNewPassword']){
                $where_update['id'] = $user_id['id'];
                $middleStr = rand(1000,9999).time().rand(100,999);
                $update['token'] = $this->md5($middleStr);
                $update['password'] = $this->md5($data['newPassword']);
                $is_update = Db::name('Member')->where($where_update)->update($update);
                if($is_update){
                    $this->apiResponse('1','成功',$update['token']);
                }else{
                    $this->apiResponse('0','修改失败');
                }
            }else{
                $this->apiResponse('0','两次密码输入不一致');
            }
        }else{
            $this->apiResponse('0','原密码输入错误');
        }
    }


    /**
     * @title  密码找回
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/User/findPassword
     * @method POST
     * @param name:tel type:int require:1 default: other: desc:手机号
     * @param name:imgCode type:int require:1 default: other: desc:图片验证码
     * @param name:code type:int require:1 default: other: desc:短信验证码
     * @param name:newPassword type:int require:1 default: other: desc:新密码
     * @param name:sureNewPassword type:int require:1 default: other: desc:确认新密码
     * @param name:connect   type:int require:1 default: other:1 登录注册 ,2其他 desc:2
     */
    public function  findPassword(Request $request){
        $data = $request->param();
        if($data){
            if(empty($data['tel'])){
                $this->apiResponse('0','请输入手机号');
            }
            if(empty($data['imgCode'])){
                $this->apiResponse('0','请输入图片验证码');
            }
            if(empty($data['code'])){
                $this->apiResponse('0','请输入短信验证码');
            }
            if(empty($data['newPassword'])){
                $this->apiResponse('0','请输入新密码');
            }
            if(empty($data['sureNewPassword'])){
                $this->apiResponse('0','请输入确认新密码');
            }
//            验证手机验证码
            $where_Code['tel'] = $data['tel'];
            $where_Code['type'] = 2;
            $code = Db::name('Code')->where($where_Code)->order('create_time desc')->find();
            if($code['code'] != $data['code']){
                $this->apiResponse('0','短信验证码错误');
            }
            $where_tel['tel'] = $data['tel'];
            $is_isset = Db::name('Member')->where($where_tel)->field('id')->find();
            if(!$is_isset){
                $this->apiResponse('0','该手机号暂未注册');
            }
            if($data['newPassword'] == $data['sureNewPassword']){
                    $where_update['tel'] = $data['tel'];
                    $middleStr = rand(1000,9999).time().rand(100,999);
                    $update['token'] = $this->md5($middleStr);
                    $update['password'] = $this->md5($data['newPassword']);
                    $is_update = Db::name('Member')->where($where_update)->update($update);
                    if($is_update){
                        $this->apiResponse('1','成功',$update['token']);
                    }else{
                        $this->apiResponse('0','修改失败');
                    }
            }else{
                    $this->apiResponse('0','两次密码输入不一致');
                }

        }else{
            //            返回验证码图片
            $img = $this->getImgUrl();
            $this->apiResponse('1','成功',$img);
        }
    }



    /**
     * @title  绑定银行卡
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/User/myCard
     * @method POST
     * @param name:token type:int require:1 default: other: desc:token
     * @param name:card_name type:int require:1 default: other: desc:银行名称
     * @param name:card_num type:int require:1 default: other: desc:银行卡号
     */
    public function myCard(Request $request){
        $data = $request->param();
        $where_member['token'] = $data['token'];
        $where_member['status'] = 1;
        $member = Db::name('Member')->where($where_member)->field('id,name,tel')->find();
        if(!empty($data['card_num'])){
//            验证码
            $where_code['type'] = 5;
            $code = Db::name('Code')->where($where_code)->order('create_time desc')->limit(1)->find();
            if($code != $data['code']){
                $this->apiResponse('0','验证码错误');
            }
            $add['card_name'] = $data['card_name'];
            $add['card_num'] = $data['card_num'];
            $add['create_time'] = time();
            $add['update_time'] = time();
            $add['user_id'] = $member['id'];
            $add_final = Db::name('Card')->insertGetId($add);
            if($add_final){
                $this->apiResponse('1','成功',$add_final);
            }else{
                $this->apiResponse('0','添加失败');
            }
        }else{
            $this->apiResponse('1','成功',$member);
        }
    }

    /**
     * @title  银行卡解除绑定
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/User/delMyCard
     * @method POST
     * @param name:token type:int require:1 default: other: desc:token
     * @param name:card_id type:int require:1 default: other: desc:银行id
     */
    public function delMyCard(Request $request){
        $data = $request->param();
        $where_mem['token'] = $data['token'];
        $where_mem['status'] = 1;
        $user_id = Db::name('Member')->where($where_mem)->field('id')->find();
        $where_card['status'] = 1;
        $where_card['user_id'] = $user_id['id'];
        $where_card['id'] = $data['card_id'];
        $card = Db::name('Card')->where($where_card)->find();
        if($card){
            $save['status'] = 9;
            $save['create_time'] = time();
            $where_cardNext['id'] = $data['card_id'];
            $card = Db::name('Card')->where($where_cardNext)->update($save);
            if($card){
                $this->apiResponse('1','成功');
            }else{
                $this->apiResponse('0','解除绑定失败');
            }

        }else{
            $this->apiResponse('0','解除绑定失败');
        }
    }



    /**
     * @title  用户个人中心首页(over)
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/User/myIndex
     * @method POST
     * @param name:token type:int require:1 default: other: desc:token
     */
    public function myIndex(Request $request){
        $token = $request->param('token');
        $where_member['token'] = $token;
        $where_member['status'] = 1;
        $member = Db::name('Member')->where($where_member)->field('tel,id')->find();
        if(!$member){
            $this->apiResponse('0','用户信息错误');
        }
        $final['user'] = $member;
        $where_userNeed['user_id'] = $member['id'];
        $user_need = Db::name('UserNeed')->where($where_userNeed)->order('create_time desc')->select();
        if($user_need){
            $final['user_need'] = $user_need;
        }else{
            $final['user_need'] = array();
        }
        $this->apiResponse('1','成功',$final);
    }







//    用户信息
    public function myleft($token){
        $where_member['token'] = $token;
        $where_member['status'] = 1;
        $member = Db::name('Member')->where($where_member)->field('tel,id,name,referee_tel')->find();
        if(!$member){
            $this->apiResponse('0','用户信息错误');
        }
        return $member;
    }



    /**
     * @title  用户个人中心我的比价/比价详情(over)
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/User/myIndex
     * @method POST
     * @param name:token type:int require:1 default: other: desc:token
     * @return data:''@
     * @data status:'状态(1->待发布,2->已发布,待报价,3->已成交,4->未交保证金,5->已过期,6->未选择中介,7->中介未确认,8->报价人数不足,9->删除)'
     */
    public function myNeed(Request $request){
        $token = $request->param('token');
        $member = $this->myleft($token);
        $final['user'] = $member;
        $where_userNeed['user_id'] = $member['id'];
        $where_userNeed['status'] = array('neq',9);
        $user_need = Db::name('UserNeed')->where($where_userNeed)->order('create_time desc')->select();
        if($user_need){
            $final['user_need'] = $user_need;
        }else{
            $final['user_need'] = array();
        }
        $final['user'] = $member;
        $this->apiResponse('1','成功',$final);
    }


    /**
     * @title  我的比价明细
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/User/compareDetail
     * @method POST
     * @param name:token type:int require:1 default: other: desc:token
     * @param name:need_id type:int require:1 default: other: desc:需求id
     */
    public function compareDetail(Request $request){
        $token = $request->param('token');
        $member = $this->myleft($token);
        $data = $request->param();
        $where_need['id'] = $data['need_id'];
        $where_need['user_id'] = $member['id'];
        $where_need['status'] = 5;
        $userNeed = Db::name('UserNeed')->where($where_need)->find();
        $final['need'] = $userNeed;
        $final['user'] = $member;
        if($userNeed){
//            查询报价
            $where_agency['need_id'] = $data['need_id'];
            $where_agency['status'] = 4;
            $agency = Db::name('Agency')->alias('a')
                ->where($where_agency)
                ->join("hp_Member m", 'm.id = a.agency_id')
                ->field('a.*,a.id as agency_id,
                m.id as user_id,m.name,m.company,m.store,m.tel,m.reputation,m.start')
                ->select()->toArray();
            if($agency){
                $final['agency'] = $agency;
                $this->apiResponse('1','成功',$final);
            }else{
                $this->apiResponse('0','中介报价有误');
            }
        }else{
            $this->apiResponse('0','当前状态不支持查看报价');
        }


    }

    /**
     * @title  我的资料(sure)
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/User/myMes
     * @method POST
     * @param name:token type:int require:1 default: other: desc:token
     * @return data:''@
     */
    public function myMes(Request $request){
        $data = $request->param();
        $user = $this->myleft($data['token']);
        $where_card['status'] = 1;
        $where_card['user_id'] = $user['id'];
        $card = Db::name('Card')->where($where_card)->field('id,card_name,card_num')->select()->toArray();
        foreach ($card as $cardk=>$cardv){
            $card[$cardk]['user_name'] = $user['name'];
        }
        $final['card'] = $card;
        $final['user'] = $user;
        if($card){
            $this->apiResponse('1','成功',$final);
        }else{
            $this->apiResponse('0','失败');
        }

    }


    /**
     * @title  确认成交
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/User/sureAgency
     * @method POST
     * @param name:token type:int require:1 default: other: desc:token
     * @param name:need_id type:int require:1 default: other: desc:需求id
     * @param name:agency_id type:int require:1 default: other: desc:中介报价id
     * @return data:''@
     */
    public function sureAgency(Request $request){
        $data = $request->param();
        if(!$data['need_id'] || !$data['agency_id'] ){
            $this->apiResponse('0','参数错误');
        }
        $where_bid['need_id'] = $data['need_id'];
        $where_bid['id'] = $data['agency_id'];
        $where_bid['status'] = 4;
        $is_isset = Db::name('Agency')->where($where_bid)->find();
        if($is_isset){
            $where_ag['id'] = $data['agency_id'];
            $add['status'] = 5;
            $add['update_time'] = time();
            $save = Db::name('Agency')->where($where_ag)->update($add);
            if($save){
                $this->apiResponse('1','操作失败');
            }else{
                $this->apiResponse('0','成交失败');
            }
        }else{
            $this->apiResponse('0','报价选择有误');
        }
    }


    /**
     * @title  查看评价
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/User/comment
     * @method POST
     * @param name:token type:int require:1 default: other: desc:token
     * @param name:agency_id type:int require:1 default: other: desc:中介id
     */
    public function comment(Request $request){
        $data = $request->param();
        $where_isset['id'] = $data['agency_id'];
        $agency_id = Db::name('Member')->where($where_isset)->field('id,name,pic,reputation,start')->find();
        if($agency_id){
            $where_comment['c.agency_id'] = $agency_id['id'];
            $where_comment['c.status'] = 1;
            $comment = Db::name('Comment')->alias('c')
                ->where($where_comment)
                ->join("hp_member m",'m.id = c.user_id')
                ->field('m.tel , c.content,c.create_time')
                ->select()->toArray();
            if($comment){
                foreach ($comment as $ck=>$cv){
                    $middle = str_split($cv['tel'],3);
                    $comment[$ck]['tel'] = $middle[0].'********';
                }
                $this->apiResponse('1','成功',$comment);
            }else{
                $this->apiResponse('1','暂无评价');
            }
        }else{
            $this->apiResponse('0','中介不存在');
        }

    }




    /**
     * @title  投诉
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/User/complaint
     * @method POST
     * @param name:token type:int require:1 default: other: desc:token
     * @param name:need_id type:int require:1 default: other: desc:需求id
     * @param name:agency_id type:int require:1 default: other: desc:中介报价id
     * @param name:intermediary_id type:int require:1 default: other: desc:中介id
     * @param name:content type:int require:1 default: other: desc:投诉内容
     * @param name:type type:int require:1 default: other: desc:1->用户投诉,2->中介投诉
     */
    public function complaint(Request $request){
        $token = $request->param('token');
        $member = $this->myleft($token);
        $final['user'] = $member;
        $data = $request->param();
        $where_isset['user_id'] = $member['id'];
        $where_isset['need_id'] = $data['need_id'];
        $where_isset['agency_id'] = $data['agency_id'];
        $where_isset['intermediary_id'] = $data['intermediary_id'];
        $is_isset= Db::name('Complaint')->where($where_isset)->field('id')->find();
        if($is_isset){
            $this->apiResponse('0','您已投诉');
        }

        $add['user_id'] = $member['id'];
        $add['need_id'] = $data['need_id'];

        $add['agency_id'] = $data['agency_id'];
        $add['intermediary_id'] = $data['intermediary_id'];
        $add['content'] = $data['content'];
        $add['type'] = $data['type'];

        $is_add = Db::name('Complaint')->insertGetId($add);
        if($is_add){
            $final['complaint_id'] = $is_add;
            $this->apiResponse('1','投诉成功',$final);
        }else{
            $this->apiResponse('0','投诉失败');
        }
    }

    /**
     * @title  我的账户
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/User/orderDetail
     * @method POST
     * @param name:token type:int require:1 default: other: desc:token
     */
    public function orderDetail(Request $request){
        $data = $request->param();
        $get_msg = $this->myleft($data['token']);
        $where_order['user_id'] = $get_msg['id'];
        $where_order['status'] = array('neq',9);
        $order_list = Db::name('UsermoneyDetail')->where($where_order)->select()->toArray();
        if($order_list){
            foreach ($order_list as $ok=>$ov){

            }


        }else{
            $result = array();
        }
    }







}