コード例 #1
0
def admin_query_ongoing_orders():
    """
    @api {POST} /order/admin/query/ongoing 管理员查询用户对应的进行中的购货订单信息
    @apiGroup Order
    @apiVersion 0.0.1
    @apiDescription 用于查询用户进行中的购货订单信息
    @apiParamExample {json} 请求样例:
                    {
                        ["nickName": "guest"],
                        ["orderId": "123"],
                        ["fromDate": "2018-02-01"],
                        ["toDate": "2018-03-01"]
                    }
    @apiSuccess (200) {String} msg 信息
    @apiSuccess (200) {int} code 0 代表无错误 1代表有错误
    @apiSuccessExample {json} 返回样例:
                        {
                            "payload": {
                                "12": {
                                "user_id": 123,
                                "order_id": 12,
                                "quantity": 1,
                                "origin_cost": 22.0,
                                "pay_status": 1,
                                "order_status": 1,
                                "actual_cost": 22.0,
                                "delivery_status": 1
                                }
                            },
                            "status": "ok"
                        }

    @apiError (400) {String} msg 信息
    @apiErrorExample {json} 返回样例:
                   {"status": "fail", "message": "用户不存在"}
    """
    from_date = request.json.get('fromDate')
    to_date = request.json.get('toDate')
    order_id = request.json.get('orderId')
    nick_name = request.json.get('nickName')
    user_id = None

    if nick_name:
        user_id = UserService.get_id_by_nickname(nick_name)

        if not user_id:
            return make_api_response(message="用户不存在", statusCode=400)

    orders = OrderService.admin_order_query_by_uid_date(
        user_id, order_id, 1, from_date, to_date, 2)

    return make_api_response(payload=orders)
コード例 #2
0
def register():
    """
    @api {POST} /register 注册用户
    @apiGroup Users
    @apiVersion 0.0.1
    @apiDescription 用于注册用户
    @apiParam {String} username 用户账户名
    @apiParam {String} nickname 昵称
    @apiParam {String} realname 真实姓名
    @apiParam {String} password 密码
    @apiParam {String} pwdquestion 密码提示问题
    @apiParam {String} pwdanswer 密码提示问题答案
    @apiParam {String} gender 性别
    @apiParam {String} mail 邮箱
    @apiParam {String} phone 联系电话
    @apiParam {String} qq QQ
    @apiParamExample {json} 请求样例:
                    {
                        "username": "******",
                        "nickname": "guest",
                        "realname": "132",
                        "password": "******",
                        "pwdquestion": "none",
                        "pwdanswer": "none",
                        "gender": "23",
                        "mail": "*****@*****.**",
                        "phone": 1231232,
                        "qq":12312
                    }
    @apiSuccess (200) {String} msg 信息
    @apiSuccess (200) {int} code 0 代表无错误 1代表有错误
    @apiSuccessExample {json} 返回样例:
                   {"status":"ok", "message": ""}

    @apiError (400) {String} msg 信息
    @apiErrorExample {json} 返回样例:
                   {"status": "fail", "message": "参数错误:缺少用户名或密码"}
                   {"status": "fail", "message": "参数错误:用户名已存在"}
    """
    # 获取参数
    user_name = request.json['username']
    display_name = request.json['nickname']
    real_name = request.json['realname']
    password = request.json['password']
    pwd_question = request.json['pwdquestion']
    pwd_answer = request.json['pwdanswer']
    gender = request.json['gender']
    mail = request.json['mail']
    phone = request.json['phone']
    qq = request.json['qq']

    if not user_name or not password:
        return make_api_response(message='参数错误:缺少用户名或密码', statusCode=400)

    user = UserService.query_user_by_name(username=user_name)
    if user is not None:
        return make_api_response(message='用户名已存在', statusCode=400)

    user = UserService.get_id_by_nickname(nickname=display_name)
    if user is not None:
        return make_api_response(message='昵称已存在', statusCode=400)

    user = UserService.query_user_by_phone(phone=phone)
    if user is not None:
        return make_api_response(message='手机号已存在', statusCode=400)

    userinfo = {
        'username': user_name,
        'nickname': display_name,
        'realname': real_name,
        'password': password,
        'question': pwd_question,
        'answer': pwd_answer,
        'gender': gender,
        'mail': mail,
        'phone': phone,
        'qq': qq
    }
    # 创建用户的操作
    ok = UserService.create_user(userinfo)
    db.session.commit()

    return make_api_response()