def get_dish_sort_by_brand(brand_id, package_id): temp = [] dishes = [] dish_sort_count = DishSort.query.filter( DishSort.brand_id == brand_id).count() package = Package.get_package_by_id(package_id) dish = get_session_dish() temp_bool = False # 判断是否是第一次 if dish is None: dish = Dish.get_dish_by_package(package) temp_bool = True if dish_sort_count > 1: dish_sort = DishSort.query.filter( DishSort.brand_id == brand_id).all() for d in dish_sort: temp.append(d) else: dish_sort = DishSort.query.filter( DishSort.brand_id == brand_id).first() temp.append(dish_sort) for di in dish: if temp_bool: try: di.number = 1 except: di['number'] = 1 d_pic = flatten(di) dishes.append(d_pic) set_session_dish(dishes) return temp
def get_dish_sort_by_brand(brand_id,package_id): temp = [] dishes = [] dish_sort_count = DishSort.query.filter(DishSort.brand_id == brand_id).count() package = Package.get_package_by_id(package_id) dish = get_session_dish() temp_bool = False # 判断是否是第一次 if dish is None: dish = Dish.get_dish_by_package(package) temp_bool = True if dish_sort_count >1: dish_sort = DishSort.query.filter(DishSort.brand_id == brand_id).all() for d in dish_sort: temp.append(d) else: dish_sort = DishSort.query.filter(DishSort.brand_id == brand_id).first() temp.append(dish_sort) for di in dish: if temp_bool: try: di.number = 1 except: di['number'] = 1 d_pic = flatten(di) dishes.append(d_pic) set_session_dish(dishes) return temp
def get(): # set_session_dish(None) parse = reqparse.RequestParser() parse.add_argument('dish_number', type=str, required=False) parse.add_argument('dish_id', type=int, required=True) parse.add_argument('package_id', type=str, required=False) parse.add_argument('dish_sort_id', type=str, required=False) parse.add_argument('operate', type=str, required=False) args = parse.parse_args() dish_number = args['dish_number'] dish_id = args['dish_id'] package_id = args['package_id'] dish_sort_id = args['dish_sort_id'] operate = args['operate'] #用户点菜加减数量操作处理 dishes = get_session_dish() has_dish = True # 判断用户添加的菜品是否在此套餐中 if dishes: temp_bool = False for d in dishes: if dish_id == d['id']: dish = None has_dish = False if operate == "add": d['number'] = int(d['number']) + 1 if int(d['number']) < 1: dishes.remove(d) if operate == "reduce": d['number'] = int(d['number']) - 1 temp_bool = False break else: temp_bool = True if temp_bool: dish = Dish.get_dish_by_id(dish_id) dish.number = 1 if dish: dish_pic = flatten(dish) dishes.append(dish_pic) else: dishes = [] if has_dish and operate == "add": dish = Dish.get_dish_by_id(dish_id) dish.number = 1 d_pic = flatten(dish) dishes.append(d_pic) set_session_dish(dishes)
def get_dish_sort_by_package(package_id): '''获取套餐所有分类''' package = Package.get_package_by_id(package_id) dish_sort_array = PackageServiceView.get_dish_sort_array(package) dish_sort = PackageServiceView.get_dish_sort(dish_sort_array) temp = [] dish = PackageServiceView.get_dish_by_brand_id(package) if dish: for d in dish: try: if d.package_id == int(package_id): d.number = 1 else: d.number = 0 except: if int(d['package_id']) == int(package_id): d['number'] = 1 else: d['numbre'] = 0 d_pic = flatten(d) temp.append(d_pic) set_session_dish(temp) return dish_sort, dish