diff --git a/routes/openclaw_bot_routes.py b/routes/openclaw_bot_routes.py index 3e0c746..3deea82 100644 --- a/routes/openclaw_bot_routes.py +++ b/routes/openclaw_bot_routes.py @@ -2442,6 +2442,21 @@ def _generate_ppt_cmd(sub_type: str, sub_arg: str, _chat_id: int, target: str, ms = query_monthly_summary(yr, mo) top_cats = query_category_monthly(yr, mo, lim=8) ms['top_categories'] = top_cats + + # 月對月 / 年對年 比較資料(市場專業標準必備) + prev_yr_mo = (yr if mo > 1 else yr - 1) + prev_mo_no = (mo - 1 if mo > 1 else 12) + try: + prev_mo_data = query_monthly_summary(prev_yr_mo, prev_mo_no) + except Exception: + prev_mo_data = {'found': False} + try: + prev_yr_data = query_monthly_summary(yr - 1, mo) + except Exception: + prev_yr_data = {'found': False} + ms['prev_month'] = prev_mo_data if prev_mo_data.get('found') else None + ms['prev_year'] = prev_yr_data if prev_yr_data.get('found') else None + aov = ms.get('avg_order', ms.get('revenue', 0) / ms.get('orders', 1) if ms.get('orders') else 0) top5_products = ms.get('top_products', [])[:5] top5_cats = top_cats[:5] @@ -4458,7 +4473,7 @@ def openclaw_answer(question: str, chat_id: int = None): " 「怎麼查看熱銷商品?」\n" " 「有什麼市場情報?」" ) - return wakeup_text, quick_menu_keyboard() + return wakeup_text, main_menu_keyboard() # ── 功能說明直接導 help ─────────────────────────────────── if _is_help_question(question): diff --git a/tests/test_openclaw_bot_routes_webhook.py b/tests/test_openclaw_bot_routes_webhook.py index 3b980bf..d2a5836 100644 --- a/tests/test_openclaw_bot_routes_webhook.py +++ b/tests/test_openclaw_bot_routes_webhook.py @@ -44,7 +44,7 @@ def test_openclaw_answer_wakeup_query_returns_menu(): text, kb = bot.openclaw_answer("小龍蝦") assert "OpenClaw(小O)" in text - assert kb == bot.quick_menu_keyboard() + assert kb == bot.main_menu_keyboard() def test_openclaw_answer_variants_are_menu_wakeup():