def get_shop_list(shop_type=None,cat=None,price_range=None,trade_mark_style=None,region=None,\ trade_mark_transfer=None, is_all_red=None, is_no_punishment=None, sort=None, page=1,per_page=5): price_ranges=[(0,3),(3,5),(5,10),(10,20),(20,30),(30,50),(50,1000)] shop_type_filter=Shop.shop_type==shop_type if shop_type else None price_filter=Shop.price.between(price_ranges[price_range][0],price_ranges[price_range][1])\ if price_range in [0,1,2,3,4,5,6] else None category_filter=Shop.category==cat if cat else None region_filter=Shop.region==region if region else None trade_mark_filter=Trademark.mark_type==trade_mark_style if trade_mark_style else None trade_mark_transfer_filter = Trademark.transfer==trade_mark_transfer if trade_mark_transfer else None is_all_red_filter = Shop.is_all_red==True if is_all_red else None is_no_punishment_filter = Shop.is_no_punishment==True if is_no_punishment else None multi_filter=[] for i in [shop_type_filter,category_filter,price_filter,region_filter,trade_mark_filter,\ trade_mark_transfer_filter,is_all_red_filter,is_no_punishment_filter]: if i: multi_filter.append(i) if multi_filter: if trade_mark_filter or trade_mark_transfer_filter: query = Shop.select().join(Trademark).where(*multi_filter) else: query = Shop.select().where(*multi_filter) else: query =Shop.select() # 排序 if sort == 'time': query = query.order_by(Shop.level.desc(), Shop.created_datetime.desc()) elif sort == 'price': query = query.order_by(Shop.price.asc(), Shop.level.desc()) # 分页 shops =query.paginate(page=page,paginate_by=per_page) return { 'code': 0, 'total_count':query.count(), 'data': [q.get_display_data() for q in shops], 'message': u'正常' }
def list_shops(bot: Bot, update: Update) -> None: logger.debug("Entering: list_shops") chat = update.effective_chat # type: Chat msg = update.effective_message # type: Message usr = update.effective_user # type: User responses = [] with orm.db_session: shops = dbShop.select(lambda s: s).order_by(dbShop.kind, dbShop.ownerCastle) num = shops.count() for page in range(1, ceil(num / config.RESULT_SIZE) + 1): response = '' for shop in shops.page(page, pagesize=config.RESULT_SIZE): response += f'<a href="https://t.me/share/url?url=/ws_{shop.link}">{shop.kind}{shop.name}</a> ' response += f'<i>{shop.mana}💧</i> by <b>{shop.ownerCastle}{shop.ownerName}</b>' response += '\n\n' responses.append(response) for response in responses: msg.reply_text(response, parse_mode='HTML')
def getById(id): return Shop.select().where(Shop.id == id)
def find(keyword): return Shop.select().where(Shop.name.contains(keyword))
def getAll(): return Shop.select()