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)
def modify_by_name(name, **modify_json): """ :param name: :type name: :param modify_json: :type modify_json: :return: number of row update, 0 if not find, error if modify_json is wrong :rtype: int """ query = EBikeModel.update(**modify_json).where(EBikeModel.name == name) return query.execute()
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
def add(**kwargs): """ add e_bike_model eg = { "name": "E100小龟", "category": "小龟", "price": 2000, "colors": "红,蓝,绿", "introduction": "小龟电动车", } :param kwargs: :type kwargs: :return: the added json :rtype: json """ e_bike_model = EBikeModel.create(**kwargs) return e_bike_model
def remove_by_name(name): query = EBikeModel.delete().where(EBikeModel.name == name) return query.execute()
def num_sold_increment(name): query = EBikeModel.update(num_view=EBikeModel.num_sold + 1) \ .where(EBikeModel.name == name) return query.execute()
def num_view_increment(name): # 获取num_view # 递增num_view query = EBikeModel.update(num_view=EBikeModel.num_view + 1) \ .where(EBikeModel.name == name) return query.execute()
def get_by_category(category): e_bike_models = EBikeModel.select().where(EBikeModel.category == category) return e_bike_models
def get_by_name(name): return EBikeModel.get(EBikeModel.name == name)
def count_all(): count = EBikeModel.select().count() return count
def get_all_paginate(): e_bike_models = EBikeModel.select() return e_bike_models
def get_all(page, paginate_by): e_bike_models = EBikeModel.select().paginate(page, paginate_by) return e_bike_models
def get(*query, **kwargs): e_bike_model = EBikeModel.get(*query, **kwargs) return e_bike_model