Пример #1
0
def get_logistics():
    """
    根据寄件人电话号/快递编号查询物流信息
    :return: 
    """
    order_number = request.args.get('order_number', '')
    if not order_number:
        return ResponseUtil.error_response(msg='寄件人电话号和订单号必填一项')
    try:
        res = logistics_service.get_logistics_by_phone_and_order_number(
            order_number)
    except Exception as e:
        return ResponseUtil.error_response(msg=str(e))
    return ResponseUtil.success_response(data=res, msg='success')
Пример #2
0
def get_all_user_info():
    """
    得到所有用户信息
    status:查询普通用户/快递员
    :return:
    """
    user_id = request.cookies.get('login_token').split('-')[0]
    identity_type = request.args.get('identity_type')
    if not identity_type:
        return ResponseUtil.error_response('请填写查询类型')
    try:
        user_infos = user_service.get_all_user_infos(user_id, identity_type)
    except Exception as e:
        return ResponseUtil.error_response(data={}, msg=str(e))
    return ResponseUtil.success_response(data=user_infos, msg='success')
Пример #3
0
def update_status():
    """
    修改实验状态  审批/拒绝
    :return:
    """
    user_id = request.cookies.get('login_token').split('-')[0]
    try:
        eid = request.args.get('eid')
        status = request.args.get('status')
        if not eid or not status:
            return ResponseUtil.error_response(msg="缺少相关参数")
        experiment_service.update_experiment(user_id, eid, int(status))
    except Exception as e:
        return ResponseUtil.error_response(msg=str(e))
    return ResponseUtil.success_response(msg='success')
Пример #4
0
def make_employee_to_deliver():
    """
    指派快递员去派件
    :return:
    """
    user_id = request.cookies.get('login_token').split('-')[0]
    employee_name = request.args.get('employee_name')
    order_number = request.args.get('order_number')
    if not employee_name or not order_number:
        return ResponseUtil.error_response(msg='相关参数不能为空')
    try:
        logistics_service.make_employee_to_deliver(user_id, employee_name,
                                                   order_number)
    except Exception as e:
        return ResponseUtil.error_response(msg=str(e))
    return ResponseUtil.success_response(msg='success')
Пример #5
0
def check_token():
    """
    校验身份
    :return:
    """
    method = str(request.url_rule)
    if not method or method not in ALLOW_METHOD:
        login_token = request.cookies.get('login_token')
        if not login_token:
            return ResponseUtil.error_response(msg='no access')
        user_id = login_token.split('-')[0]
        real_token = redis_client.get(user_id)
        if real_token:
            # 因为python3 从redis返回的是b'', 即ascll码, py3是unicode
            real_token = real_token.decode()
        if login_token != real_token:
            return ResponseUtil.error_response(msg='no access')
    return
Пример #6
0
def get_all_user():
    """
    查询所有用户
    :return:
    """
    try:
        user_infos = user_service.get_user_infos()
    except Exception as e:
        return ResponseUtil.error_response(data=[], msg=str(e))
    return ResponseUtil.success_response(data=user_infos, msg='success')
Пример #7
0
def get_all_orders():
    """
    查询所有订单信息
    :return:
    """
    user_id = request.cookies.get('login_token').split('-')[0]
    try:
        res = order_service.get_all_orders(user_id)
    except Exception as e:
        return ResponseUtil.error_response(msg=str(e))
    return ResponseUtil.success_response(msg='success', data=res)
Пример #8
0
def logout():
    """
    用户注销
    :return:
    """
    user_id = request.cookies.get('login_token').split('-')[0]
    try:
        user_service.logout(user_id)
    except Exception as e:
        return ResponseUtil.error_response(msg=str(e))
    return ResponseUtil.success_response(msg='success')
Пример #9
0
def get_user_info():
    """
    获取当前登陆用户的信息
    :return:
    """
    user_id = request.cookies.get('login_token').split('-')[0]
    try:
        user_info = user_service.get_user_info(user_id)
    except Exception as e:
        return ResponseUtil.error_response(data={}, msg=str(e))
    return ResponseUtil.success_response(data=user_info, msg='success')
Пример #10
0
def get_msg():
    """
    显示站内信
    :return:
    """
    user_id = request.cookies.get('login_token').split('-')[0]
    try:
        res = email_service.get_all_msgs(user_id)
    except Exception as e:
        return ResponseUtil.error_response(data=[], msg=str(e))
    return ResponseUtil.success_response(data=res, msg='success')
Пример #11
0
def get_all_experiment_pass():
    """
    得到实验
    :return:
    """
    user_id = request.cookies.get('login_token').split('-')[0]
    try:
        experiment_infos = experiment_service.get_all_experiments_pass(user_id)
    except Exception as e:
        return ResponseUtil.error_response(data=[], msg=str(e))
    return ResponseUtil.success_response(data=experiment_infos, msg='success')
Пример #12
0
def register():
    """
    注册接口
    :return:
    """
    form = RegisterForm.from_json(formdata=request.json, meta={'locales': ['zh_CN', 'zh']})
    try:
        validate_form(form)
        user_service.user_register(form.data)
    except Exception as e:
        return ResponseUtil.error_response(msg=str(e))
    return ResponseUtil.success_response(msg='success')
Пример #13
0
def join_experiment():
    """
    参加实验, 学生可选
    :return:
    """
    user_id = request.cookies.get('login_token').split('-')[0]
    try:
        eid = request.args.get('eid')
        experiment_service.join_experiment(user_id, int(eid))
    except Exception as e:
        return ResponseUtil.error_response(msg=str(e))
    return ResponseUtil.success_response(msg='success')
Пример #14
0
def login():
    """
    登陆接口
    :return:
    """
    username = request.args.get('username')
    password = request.args.get('password')
    try:
        msg = user_service.user_login(username, password)
        resp = make_response('{"msg": "success", "code": 0, "data": null}')
        resp.set_cookie("login_token", msg, max_age=1 * 3600 * 24)
    except Exception as e:
        return ResponseUtil.error_response(msg=str(e))
    return resp
Пример #15
0
def update_status():
    """
    删除用户
    :return:
    """
    user_id = request.cookies.get('login_token').split('-')[0]
    username = request.args.get('username')
    if not username:
        raise Exception('相关参数不能为空')
    try:
        user_service.delete_user(user_id, username)
    except Exception as e:
        return ResponseUtil.error_response(data={}, msg=str(e))
    return ResponseUtil.success_response(msg='success')
Пример #16
0
def add_experiment():
    """
    录入实验
    :return:
    """
    form = ExperimentAdd.from_json(formdata=request.json,
                                   meta={'locales': ['zh_CN', 'zh']})
    user_id = request.cookies.get('login_token').split('-')[0]
    try:
        validate_form(form)
        experiment_service.add_experiment(form.data, user_id)
    except Exception as e:
        return ResponseUtil.error_response(msg=str(e))
    return ResponseUtil.success_response(msg='success')
Пример #17
0
def send_msg():
    """
    发送消息/公告
    :return:
    """
    user_id = request.cookies.get('login_token').split('-')[0]
    try:
        eid = request.args.get('eid')
        content = request.args.get('content')
        if not content:
            raise Exception('相关参数不能为空')
        email_service.send_msg_v1(user_id, eid, content)
    except Exception as e:
        return ResponseUtil.error_response(msg=str(e))
    return ResponseUtil.success_response(msg='发送成功')
Пример #18
0
def get_order_cost():
    """
    根据寄件人地址, 收件人地址, 物品重量获得价格
    :return:
    """
    form = GetOrderCost(request.args, meta={'locales': ['zh_CN', 'zh']})
    try:
        validate_form(form)
        send_pos, receive_pos, goods_weight = form.data.get('send_pos'), form.data.get('receive_pos'), \
                                              form.data.get('goods_weight')
        res = order_service.get_order_cost_by_pos(send_pos, receive_pos,
                                                  float(goods_weight))
    except Exception as e:
        return ResponseUtil.error_response(msg=str(e))
    return ResponseUtil.success_response(msg='success', data=res)
Пример #19
0
def do_order():
    """
    下单接口
    @:param username, password
    :return:
    {"msg": "34e3f953ee814a66a62b2cc2c02b1968", "code": 0, "data": null}
    """
    form = DoOrderForm.from_json(formdata=request.json,
                                 meta={'locales': ['zh_CN', 'zh']})
    try:
        validate_form(form)
        order_service.generate_order(form.data)
    except Exception as e:
        return ResponseUtil.error_response(msg=str(e))
    return ResponseUtil.success_response(msg='success')
Пример #20
0
def register():
    """
    注册接口
    @:param
    {"username":"******","password":"******"}
    :return:
    """
    form = RegisterForm.from_json(formdata=request.json,
                                  meta={'locales': ['zh_CN', 'zh']})
    try:
        validate_form(form)
        user_service.user_register(form.data)
    except Exception as e:
        return ResponseUtil.error_response(msg=str(e))
    return ResponseUtil.success_response(msg='success')