Register.php 1.8 KB
<?php
/**
 * Created by PhpStorm.
 * User: 86132
 * Date: 2020/7/4
 * Time: 9:50
 */

namespace app\api\controller;

use think\Db;
use app\common\controller\Api;

/**
 * 注册接口
 */
class Register extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }


    /**
     * @ApiTitle    (注册接口-注册)
     * @ApiSummary  (注册)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/register/RegisterSign)
     * @ApiParams   (name="mobile", type="integer", required=true, description="手机号")
     * @ApiParams   (name="password", type="string", required=true, description="密码")
     * @ApiParams   (name="code", type="string", required=true, description="验证码")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功'
    "data": "1"
    })
     */
    public function RegisterSign()
    {
        $param = $this->request->param();
        if (empty($param['password']||$param['password'] =="")) {
            $is_user = Db::name('user')->where(['mobile' => $param['mobile']])->find();
            if ($is_user) {
                $this->error('您已注册过,请直接登陆', 0);
            } else {
                $this->CheckCode($param['mobile'], $param['code']);
            }
        } else {
            $model=new \app\common\model\User();
            $res = $model->save(['mobile' => $param['mobile'], 'username'=>$param['mobile'],'password' => $param['password']]);
            if ($res) {
                $this->success('成功', 1);
            } else {
                $this->error('失败', 0);
            }
        }
    }
}