def setItems(member_id=0, food_id=0, number=0): if member_id < 1 or food_id < 1 or number < 1: return False # 一种是添加,一种是编辑 print("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&") cart_info = MemberCart.query.filter_by(food_id=food_id, member_id=member_id).first() print(cart_info) if cart_info: print("$$$$$$$$$$$$$$$$$") print(cart_info.id) print(cart_info.member_id) model_cart = cart_info else: print("test") model_cart = MemberCart() model_cart.member_id = member_id model_cart.created_time = getCurrentDate() model_cart.food_id = food_id model_cart.quantity = number model_cart.updated_time = getCurrentDate() db.session.add(model_cart) db.session.commit() print('test/////') return True
def setItems(member_id=0,food_id=0,number=0): if member_id < 1 or food_id < 1 or number < 1: return False cart_info = MemberCart.query.filter_by(food_id=food_id,member_id=member_id).first() if cart_info: model_cart = cart_info else: model_cart = MemberCart() model_cart.member_id = member_id model_cart.created_time = getCurrentDate() model_cart.food_id = food_id model_cart.quantity = number model_cart.updated_time = getCurrentDate() db.session.add(model_cart) db.session.commit() return True
def setItems( member_id = 0,food_id = 0,number = 0 ): # 用户id,商品id,添加数量 if member_id < 1 or food_id < 1 or number < 1: # 如果任何一个值小于1 return False # 添加和更新,判断这个信息是否存在(用户和商品 id 是否相同) cart_info = MemberCart.query.filter_by( food_id = food_id, member_id= member_id ).first() if cart_info: # 如果购物车数据表,有这个添加信息。就是set更新 model_cart = cart_info else: # 没有就是,添加新的信息 model_cart = MemberCart() model_cart.member_id = member_id model_cart.created_time = getCurrentData() model_cart.food_id = food_id model_cart.quantity = number model_cart.updated_time = getCurrentData() db.session.add(model_cart) db.session.commit() return True