IntermediaryController.php 4.7 KB
<?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 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:密码
     */

    public function join(Request $request)
    {
        if($request->Post()){
//            验证
            $validate = Loader::validate('Intermediary');
            if(!$validate->scene('add')->check($_POST)){
                return json(array('code'=>0,'msg'=>$validate->getError()));
            }
//            密码
            $_POST['password'] = $this->md5($_POST['password']);
//            确认密码
            if($_POST['password'] != $_POST['sure_password']){
                $this->apiResponse('0','两次密码不一致');
            }
//            短信验证码(未完)

//            判断手机号是否已注册
            $user = new MemberModel($_POST);
            $where_user['tel'] = $_POST['tel'];
            $is_isset = $user->where($where_user)->find();
            if($is_isset){
                $this->apiResponse('0','您已注册过,请直接登录');
            }
            echo "<pre/>";
            print_r('1111');
            die;
            $str = rand('1000,9999').time().rand('100,999');
            $_POST['token'] = $this->md5($str);
            $add = $user->allowField(true)->save();
            if($add){
                echo "<pre/>";
                print_r('1');
                die;
            }else{
                echo "<pre/>";
                print_r('2');
                die;
            }

        }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")->find();
//              推荐人(未完)


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

        }
    }


//    登录
    public function login(Request $request){
        if($request->post()){
//            登录验证
//            判空
            $tel = $request->param('tel');
            $password = $request->param('password');
            $true = $request->param('true');
            $token = $request->param('token');
            if(empty($tel)){
                $this->apiResponse('0','手机号不能为空');
            }else if(empty($password)){
                $this->apiResponse('0','密码不能为空');
            }else if(empty($true)){
                $this->apiResponse('0','验证码不能为空');
            }
//            验证
            $where_member['tel'] = $tel;
            $where_member['password'] = $password;
//            $where_member['token'] = $token;
            $member = Db::name('Member')->where($where_member)->find();
            if($member){
                if($member['token'] != $token){
                    $this->apiResponse('0','登录失败');
                }
                if($member['update_time'] >= (time()+604800)){
                    $this->apiResponse('0','请重新登录');
                }else{
                    $this->apiResponse('1','登录成功');
                }
            }else{
                $this->apiResponse('0','您输入的账号或密码不正确');
            }


        }else{
//            返回验证码图片

        }
    }
}