def set_food_activity(): """ 设置食物活动 """ restaurant_ids, category_ids, food_ids, restaurant_id, category_id, \ food_id = parse_args1() _food_ids = copy.copy(food_ids) with thrift_client('ers') as ers: for _id in restaurant_ids: food_query = thirdparty_svc.ers.TFoodQuery() food_query.restaurant_id = _id food_query.is_valid = True food_query.limit = 1000 foods = ers.query_food(food_query) _food_ids.extend([food.id for food in foods]) for _id in category_ids: food_query = thirdparty_svc.ers.TFoodQuery() food_query.category_id = _id food_query.is_valid = True food_query.limit = 1000 foods = ers.query_food(food_query) _food_ids.extend([food.id for food in foods]) _food_ids = list(set(_food_ids)) act_id = request.json.get('activity_id', None) weekdays = request.json.get('weekdays', []) with thrift_client('ers') as ers: if act_id: ers.add_food_activity(act_id, _food_ids, weekdays) else: ers.clear_food_activity(_food_ids, weekdays) return ''
def set_packing_fee(): """ 设置餐盒费 """ restaurant_ids, category_ids, food_ids, restaurant_id, category_id, \ food_id = parse_args1() packing_fee = request.json['packing_fee'] _food_ids = copy.copy(food_ids) with thrift_client('ers') as ers: for _restaurant_id in restaurant_ids: food_query = thirdparty_svc.ers.TFoodQuery() food_query.restaurant_id = _restaurant_id food_query.is_valid = True food_query.limit = 1000 foods = ers.query_food(food_query) _food_ids.extend([_food.id for _food in foods]) for _category_id in category_ids: food_query = thirdparty_svc.ers.TFoodQuery() food_query.category_id = _category_id food_query.is_valid = True food_query.limit = 1000 foods = ers.query_food(food_query) _food_ids.extend([_food.id for _food in foods]) for _food_id in set(_food_ids): food = thirdparty_svc.ers.TFood() food.packing_fee = packing_fee result = ers.save_food(_food_id, food) return ''
def set_discount(): """ 设置食物折扣 """ restaurant_ids, category_ids, food_ids, restaurant_id, category_id, \ food_id = parse_args1() discount = float(request.json['discount']) with thrift_client('ers') as ers: for _id in restaurant_ids: ers.set_restaurant_food_eleme_buy_discount(_id, discount) _food_ids = copy.copy(food_ids) for _id in category_ids: food_query = thirdparty_svc.ers.TFoodQuery() food_query.category_id = _id food_query.is_valid = True food_query.limit = 1000 foods = ers.query_food(food_query) _food_ids.extend([food.id for food in foods]) foods = ers.mget_food(_food_ids) for food in foods: fix_food_b2f(food) food.attribute['eleme_buy_discount'] = discount food.attribute = jsonpickle_dumps(food.attribute) for k in food.__dict__.iterkeys(): if k not in ['id', 'attribute']: setattr(food, k, None) result = ers.save_food(food.id, food) return ''
def food_activity_map(): restaurant_ids, category_ids, food_ids, restaurant_id, category_id, \ food_id = parse_args1() _food_ids = copy.copy(food_ids) with thrift_client('ers') as ers: if not category_ids and not food_ids and len(restaurant_ids) == 1: _map = ers.get_weekday_food_activity_id_map([], restaurant_id) else: for _id in restaurant_ids: food_query = thirdparty_svc.ers.TFoodQuery() food_query.restaurant_id = _id food_query.is_valid = True food_query.limit = 1000 foods = ers.query_food(food_query) _food_ids.extend([food.id for food in foods]) for _id in category_ids: food_query = thirdparty_svc.ers.TFoodQuery() food_query.category_id = _id food_query.is_valid = True food_query.limit = 1000 foods = ers.query_food(food_query) _food_ids.extend([food.id for food in foods]) _food_ids = list(set(_food_ids)) _map = ers.get_weekday_food_activity_id_map(_food_ids, None) return _map
def _set_stock(is_max): restaurant_ids, category_ids, food_ids, restaurant_id, category_id, \ food_id = parse_args1() with thrift_client('ers') as ers: _category_ids = copy.copy(category_ids) categories = ers.query_food_category_by_restaurant(restaurant_id) _category_ids.extend([c.id for c in categories]) for _category_id in _category_ids: ers.mset_food_stock_by_category(_category_id, is_max) for _food_id in food_ids: ers.mset_food_stock_by_food_ids(_food_id, is_max) return ''