Пример #1
0
def get_e_bike_model_information(name):
    """
    get information of an e-bike model
    :param name: name of the e-bike model
    :return: information
    """
    info = EBikeModel.get(name=name)
    return model_to_dict(info)
Пример #2
0
def add_appointment(**kwargs):
    user = kwargs["user"]
    e_bike_model = kwargs["e_bike_model"]
    color = kwargs["color"]
    e_bike_type = kwargs["type"]
    coupon = kwargs.get("coupon")
    rent_time_period = kwargs.get("rent_time_period")

    e_bike_model = EBikeModel.get(name=e_bike_model)

    # 检查库存量,虽然库存不足时前端会生不成订单
    if not storage_service.check_storage(model=e_bike_model, color=color):
        raise Error("没有足够的库存")

    # 检查该用户是否存在订单 (买车订单数)
    if not check_user_appointment(user=user, type=e_bike_type):
        raise Error("订单数目过多")

    # 租车订单 检查是否存在押金
    if e_bike_type == "租车":
        # virtual_card_service.check_deposit(username=user)
        virtual_card_service.check_status(username=user)

    if e_bike_type == "租车":
        price = e_bike_model.price[rent_time_period]
    else:
        price = e_bike_model.price

    # 库存-1
    storage_service.decrement_num(e_bike_model, color)

    # 使用优惠劵
    if coupon:
        reduced_price = coupon_service.use_coupon(user, coupon, price)
        price = price - reduced_price
        kwargs["reduced_price"] = reduced_price
    kwargs["price"] = price

    kwargs["appointment_fee_needed"] = \
        custom_constant.get_custom_const("DEFAULT_APPOINTMENT_FEE")

    appointment = add(**kwargs)

    # 获取有效的 serial_number
    serial_number = serial_number_service.get_available_code(appointment)
    # 更改 serial_number
    appointment.serial_number = serial_number
    appointment.save()
    return appointment
Пример #3
0
def get_by_name(name):
    return EBikeModel.get(EBikeModel.name == name)
Пример #4
0
def get(*query, **kwargs):
    e_bike_model = EBikeModel.get(*query, **kwargs)
    return e_bike_model