IntermediaryController.php 19.0 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
<?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\PortalPostModel;
use cmf\controller\RestBaseController;
use api\portal\model\MemberModel;
use think\Db;
use think\Request;
use think\Loader;

/**
 * @title 中介接口
 * @description 接口说明
 * @group 接口分组
 */

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

    //    登录,注册
//tel 手机号
//password  密码
//sure_password  确认密码
//name 真实姓名
    /**
     * @title  房产中介注册(sure)
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/Intermediary/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:city type:int require:1 default: other: desc:城市
     * @param name:company type:int require:1 default: other: desc:所属公司
     * @param name:store type:int require:1 default: other: desc:门店
     * @param name:quarters type:int require:1 default: other: desc:服务小区
     * @param name:connect   type:int require:1 default: other:1 登录注册 ,2其他 desc:1
     */

    public function join(Request $request)
    {
        $data = $request->Post();
        if(!empty($data['name'])){
//            验证
            $validate = Loader::validate('User');
            if(!$validate->scene('intermediary')->check($data)){
                return json(array('code'=>0,'msg'=>$validate->getError()));
            }
            $data['password'] = $this->md5($data['password']);
            $sure_password = $this->md5($data['sure_password']);
//            确认密码
            if($data['password'] != $sure_password){
                $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){
                $this->apiResponse('0','验证码错误,请重新获取');
            }
            if($code != $find_code['code']){
                $this->apiResponse('0','验证码错误,请重新获取');
            }else{
                Db::name('Code')->where($where_code)->delete();
            }
//            $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'] = 2;
            $data['city'] = $request->param('city');
            $data['company'] = $request->param('company');
            $data['store'] = $request->param('store');
            $data['quarters'] = $request->param('quarters');

            $add = $user->allowField(true)->save($data);
            if($add){
                $this->apiResponse('1','注册成功');
            }else{
                $this->apiResponse('0','注册失败');
            }

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


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

        }
    }

//    中介个人中心左侧信息
    public function left($token){
        $where_member['token'] = $token;
        $where_member['status'] = 1;
        $member = Db::name('Member')->where($where_member)->field('name,id,start,reputation,company,store,quarters,tel,city,pic,money,get_money,referee_tel')->find();
        if(!$member){
            $this->apiResponse('0','用户信息错误');
        }
//        查询签到信息
        $where_checkin['agency_id'] = $member['id'];
        $tme_str = date('Y-m-d',time());
        $where_checkin['create_time'] = strtotime($tme_str);
        $is_check = Db::name('Checkin')->where($where_checkin)->find();
        if($is_check){
            $member['is_checkin'] = 1;
        }else{
            $member['is_checkin'] = 0;
        }
        return $member;
    }


    /**
     * @title  中介个人中心首页(sure)
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/Intermediary/myIndex
     * @method POST
     * @param name:token type:int require:1 default: other: desc:token
     * @param name:page type:int require:1 default: other: desc:页码
     */
    public function myIndex(Request $request){
        $token = $request->param('token');
        $member = $this->left($token);
        $final['intermediary'] = $member;
        $where_need['city'] = $member['city'];
        $where_need['status'] = 2;
        $where_need['quarters'] = array('like','%'.$member['quarters'].'%');
        $page = $request->param('page');
        $need_list = Db::name('UserNeed')->where($where_need)->field("id,city,quarters,room,floor,house_type,renovation,quotation_time,create_time,people")->limit(10)->page($page)->select()->toArray();
        if($need_list){
            $final['intermediary_need'] = $need_list;
        }else{
            $final['intermediary_need'] = array();
        }
        $this->apiResponse('1','成功',$final);
    }


    /**
     * @title  中介个人中心匹配需求详情(sure)
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/Intermediary/mySend
     * @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 mySend(Request $request){
        $token = $request->param('token');
        $member = $this->left($token);
        $final['intermediary'] = $member;
        if(!$request->param('need_id')){
            $this->apiResponse('0','请选择需求id');
        }
        $where_need['id'] = $request->param('need_id');
        $where_need['status'] = 2;
        $need_list = Db::name('UserNeed')->where($where_need)
            ->field("id,user_id,city,quarters,room,floor,house_type,renovation,area,is_first,loan,contract,quotation_time,create_time,people,else")
            ->find();
        if($need_list){
            $final['intermediary_need'] = $need_list;
        }else{
            $final['intermediary_need'] = array();
        }
        $this->apiResponse('1','成功',$final);
    }

//    查询中介报价
//  $need_id 需求id
    public function agencyOffer($user_id,$need_id){
        $where_agency['status'] = 2;
        $where_agency['create_time'] = array('lt',time());
        $where_agency['need_id'] = $need_id;
        $agency_list = Db::name('Agency')
            ->where($where_agency)
            ->field("id,housing_price,assessment_tax,security_tax,else_tax,service_charge")
            ->select()->toArray();
        $final_list = array();
        $add_arr = array();
        if($agency_list){
            foreach ($agency_list as $agencyk=>$agencyv){
                $final_list[$agencyk]['need_id'] = $need_id;
                $final_list[$agencyk]['agency_id'] = $agencyv['id'];
                $final_list[$agencyk]['user_id'] = $user_id;
                $money = $agencyv['housing_price']*10000 + $agencyv['assessment_tax'] + $agencyv['security_tax'] + $agencyv['else_tax'] + $agencyv['service_charge'] ;
                $money_arr[] = $money;
                $fianlMoney = substr($money, 0,-4);
                $final_list[$agencyk]['true_money'] = $money;
                $final_list[$agencyk]['money'] = $fianlMoney;
            }
            sort($money_arr);
            foreach ($final_list as $finalk=>$finalv){
                if($finalv['true_money'] == $money_arr[0]){
                    $add_arr['need_id'] = $finalv['need_id'];
                    $add_arr['agency_id'] = $finalv['agency_id'];
                    $add_arr['user_id'] = $finalv['user_id'];
                    $add_arr['money'] = $finalv['money'];
                    $add_arr['create_time'] = time();
                    $add_arr['update_time'] = time();
                }
            }
            $save = Db::name('See')->insertGetId($add_arr);
            $return['id'] = $save;
            $return['money'] = $add_arr['money'];
            $return['time'] = time();
            return $return;
        }
    }




//    透视卡
//token
//need_id
    public function see(Request $request){
        $data = $request->param();
        $user = $this->left($data['token']);
        $user_id = $user['id'];
//        购买支付



//        成功加入记录
//        加订单
        $add = array();
        $add['name'] = '购买透视卡';
        $add['order_sn'] = $this->getmath();
        $add['type'] = 3;
        $add['need_id'] = $data['need_id'];
        $add['is_get'] = 2;
//        查询透视卡金额
        $add['money'] = 2;

        $add['status'] = 1;
        $add['create_time'] = time();
        $add['update_time'] = time();
        $order_id = Db::name('Order')->insertGetId($add);
        if(!$order_id){
            $this->apiResponse('0','购买失败');
        }

//        支付成功
//        修改订单状态
        $where_order['order_sn'] = $data['order_sn'];
        $save['update_time'] = time();
        $save['pay_time'] = time();
        $is_save = Db::name('Order')->where($where_order)->update($save);
        if($is_save){
            return true;
        }else{
            return false;
        }
//         查询报价
        $money = $this->agencyOffer($user_id,$data['need_id']);

    }

    /**
     * @title  中介个人中心我的报价(sure)
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/Intermediary/myMoney
     * @method POST
     * @param name:token type:int require:1 default: other: desc:token
     * @param name:page type:int require:1 default: other: desc:页码
     */
     public function myMoney(Request $request){
         $data = $request->param();
         $my = $this->left($data['token']);
         $final['intermediary'] = $my;
         $where_need['a.agency_id'] = $my['id'];
         $page = $data['page'];
         $need = Db::name('Agency')->alias('a')
             ->where($where_need)
             ->join("UserNeed n",'n.id = a.need_id')
             ->field("n.city,n.quarters,n.room,n.floor,n.house_type,n.renovation,n.status as need_status,n.create_time as need_time,n.quotation_time,
             a.all_price,a.create_time,a.status,a.id as intermediaryNeed_id
             ")
             ->limit(10)->page($page)
             ->select()->toArray();
         if($need){
             foreach ($need as $nk=>$nv){
                 $changeInt = (int)$nv['all_price'];
                 $need[$nk]['intPrice'] = substr($changeInt,0,-4);
             }
             $final['need'] = $need;
         }else{
             $final['need'] = array();
         }
         $this->apiResponse('1','成功',$final);
     }

    /**
     * @title  中介个人中心我的报价详情(sure)
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/Intermediary/myDetail
     * @method POST
     * @param name:token type:int require:1 default: other: desc:token
     * @param name:intermediary_id type:int require:1 default: other: desc:报价id
     */
    public function myDetail(Request $request){
        $data = $request->param();
        $my = $this->left($data['token']);
        $final['intermediary'] = $my;
        $where_need['agency_id'] = $my['id'];
        $where_need['i.id'] = $data['intermediary_id'];
        $need = Db::name('Agency')->alias('i')
            ->where($where_need)
            ->join("hp_user_need u",'u.id = i.need_id')
            ->field("i.id as intermediaryNeed_id ,i.*,
                    u.status as need_status ,u.*
            ")
            ->find();
        if($need){
            $final['need'] = $need;
        }else{
            $final['need'] = array();
        }
        $this->apiResponse('1','成功',$final);
    }

    /**
     * @title  中介个人中心查看评价(sure)
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/Intermediary/comment
     * @method POST
     * @param name:token type:int require:1 default: other: desc:token
     * @param name:intermediary_id type:int require:1 default: other: desc:报价id
     */
    public function comment(Request $request){
        $data = $request->param();
//        $my = $this->left($data['token']);
        if(empty($data['intermediary_id'])){
            $this->apiResponse('0','报价id不能为空');
        }
        $where_agency['id'] = $data['intermediary_id'];
        $agency = Db::name('Agency')->where($where_agency)->find();
        if($agency){
            $where_comment['need_id'] = $agency['need_id'];
            $where_comment['agency_id'] = $agency['id'];
            $where_comment['intermediary_id'] = $agency['agency_id'];
            $where_comment['status'] = 1;
            $comment = Db::name('Comment')->where($where_comment)->find();
            if($comment){
                $this->apiResponse('1','成功',$comment);
            }else{
                $this->apiResponse('0','暂无评价');
            }
        }else{
            $this->apiResponse('0','状态错误');
        }
    }


    /**
     * @title  中介个人中心我的资料(sure)
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/Intermediary/mySelf
     * @method POST
     * @param name:token type:int require:1 default: other: desc:token
     */
    public function mySelf(Request $request){
        $data = $request->param();
        $my = $this->left($data['token']);
        $final['intermediary'] = $my;
        $where_card['c.user_id'] = $my['id'];
        $where_card['c.status'] = 1;
        $card = Db::name('Card')->alias('c')
            ->where($where_card)
            ->join("Bank b",'b.id=c.bank_id')
            ->field('c.id,b.name,c.card_num')
            ->select()->toArray();
        $final['card'] = $card;
        $this->apiResponse('1','成功',$final);
    }

    /**
     * @title  中介资料修改(sure)
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/Intermediary/myChange
     * @method POST
     * @param name:token type:int require:1 default: other: desc:token
     * @param name:company type:int require:1 default: other: desc:所属公司
     * @param name:store type:int require:1 default: other: desc:门店
     * @param name:quarters type:int require:1 default: other: desc:服务小区
     * @return data:''@
     * @data status:'状态(1->待发布,2->已发布,待报价,3->已成交,4->未交保证金,5->已过期,6->未选择中介,7->中介未确认,8->报价人数不足,9->删除)'
     */
    public function myChange(Request $request){
        $data = $request->param();
        $where_member['token'] = $data['token'];
        $where_member['status'] = 1;
        $member = Db::name('Member')->where($where_member)->find();
        if(!empty($data['company'])){
            $update_member['company'] = $data['company'];
            $update_member['id'] = $member['id'];
            $update_member['store'] = $data['store'];
            $update_member['quarters'] = $data['quarters'];
            $model = new MemberModel();
            $member = $model->isUpdate(true)->save($update_member);
            if(!$member){
                $this->apiResponse('0','中介信息有误');
            }else{
                $this->apiResponse('1','成功');
            }
        }else{
            if(!$member){
                $this->apiResponse('0','中介信息有误');
            }else{
                $this->apiResponse('1','成功',$member);
            }
        }
    }


    /**
     * @title  中介签到(sure)
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/Intermediary/checkIn
     * @method POST
     * @param name:token type:int require:1 default: other: desc:token
     */
    public function checkIn(Request $request){
        $data = $request->param();
        $mes = $this->left($data['token']);
        if($mes['is_checkin'] == 0){
            $add['agency_id'] = $mes['id'];
            $time = date('Y-m-d',time());
            $add['create_time'] = strtotime($time);
            $add['update_time'] = time();
            $result = Db::name('Checkin')->insertGetId($add);
            if($request){
                $where_addStart['id'] = $mes['id'];
                $addStart = Db::name('Member')->where($where_addStart)->setInc('start',1);
                if($addStart){
                    $this->apiResponse('1','签到成功');
                }else{
                    $this->apiResponse('0','签到失败');
                }
            }else{
                $this->apiResponse('0','签到失败');
            }
        }else{
            $this->apiResponse('0','您已签到');
        }
    }

    /**
     * @title  我的账户(sure)
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/Intermediary/orderDetail
     * @method POST
     * @param name:token type:int require:1 default: other: desc:token
     */
    public function orderDetail(Request $request){
        $data = $request->param();
        $user = $this->left($data['token']);
        $where_umoney['user_id'] = $user['id'];
        $where_umoney['status'] = 1;
        $order_list = Db::name('AmoenyDetail')->where($where_umoney)->select()->toArray();
        $final['user'] = $user;
        if($order_list){
            $final['detail'] = $order_list;
        }else{
            $final['detail'] = array();
        }
        if($final){
            $this->apiResponse('1','成功',$final);
        }else{
            $this->apiResponse('0','失败');
        }
    }




}