IntermediaryController.php 15.4 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
<?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  房产中介注册
     * @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: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:服务小区
     */

    public function join(Request $request)
    {
        if($request->Post()){
//            验证
            $validate = Loader::validate('User');
            if(!$validate->scene('intermediary')->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){
                $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')->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  中介个人中心首页(over)
     * @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  中介个人中心匹配需求详情(over)
     * @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")
            ->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  中介个人中心我的报价
     * @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['agency_id'] = $my['id'];
         $page = $data['page'];
         $need = Db::name('Agency')->where($where_need)->limit(10)->page($page)->select()->toArray();
         if($need){
             $final['need'] = $need;
         }else{
             $final['need'] = array();
         }
         $this->apiResponse('1','成功',$final);
     }

    /**
     * @title  中介个人中心我的报价详情
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/Intermediary/myDetail
     * @method POST
     * @param name:token type:int require:1 default: other: desc:token
     * @param name:intermediaryNeed_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['intermediaryNeed_id'];
        $need = Db::name('Agency')->alias('i')
            ->where($where_need)
            ->join("hp_user_need u",'u.id = i.need_id')
            ->find();
        if($need){
            $final['need'] = $need;
        }else{
            $final['need'] = array();
        }
        $this->apiResponse('1','成功',$final);
    }



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

    /**
     * @title  中介资料修改
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/Intermediary/myIndex
     * @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){

        $update_member = $request->param();
        $update_member['status'] = 1;
        $update_member['type'] = 2;
        $model = new MemberModel();
        $member = $model->update($update_member);
        if(!$member){
            $this->apiResponse('0','更新失败');
        }else{
            $this->apiResponse('1','更新成功');
        }

    }


    /**
     * @title  中介签到
     * @description 接口说明
     * @author 开发者
     * @url /api/portal/Intermediary/checkIn
     * @method POST
     * @param name:token type:int require:1 default: other: desc:token
     * @return data:''@
     */
    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','您已签到');
        }
    }





}