async def user_browse_history_search(ns={}): # 处理userid if ns.get('userid'): userid = ns.get('userid') else: userid = await get_user() if not userid: return { 'status': False, 'msg': 'no match user' } # 参数处理 product_id = ns.get('product_id') start_time = ns.get('start_time') end_time = ns.get('end_time') page_size = int(ns.get('page_size', 10)) current_page = int(ns.get('current_page', 1)) offset = (current_page - 1) * page_size db = DBPools() async with db.sqlorContext('kboss') as sor: try: # 基础查询条件 base_conditions = ["del_flg = '0'"] if userid: base_conditions.append(f"userid = '{userid}'") if product_id: base_conditions.append(f"product_id = '{product_id}'") if start_time and end_time: end_time += ' 23:59:59' base_conditions.append(f"browse_time BETWEEN '{start_time}' AND '{end_time}'") # 构建查询SQL where_clause = " AND ".join(base_conditions) # 根据product_id查询product_info find_sql = f""" SELECT * FROM user_browse_history WHERE {where_clause} ORDER BY browse_time DESC LIMIT {page_size} OFFSET {offset}; """ # 总数查询SQL count_sql = f""" SELECT COUNT(*) AS total_count FROM user_browse_history WHERE {where_clause}; """ # 执行查询 result = await sor.sqlExe(find_sql, {}) total_count = (await sor.sqlExe(count_sql, {}))[0]['total_count'] return { 'status': True, 'msg': 'Browse history retrieved successfully', 'data': { 'total_count': total_count, 'page_size': page_size, 'current_page': current_page, 'history_list': result } } except Exception as e: return { 'status': False, 'msg': 'Failed to retrieve browse history, %s' % str(e) } ret = await user_browse_history_search(params_kw) return ret