edca9b4c77
- wa-friends 逐员工抓取:全局查询~1万行硬上限(云客11931只翻到10000), uid=员工WA号过滤(真机验证 declared 1145→1149),total-aware翻页 - declared-total 分渠道:Σ wechat/whatsapp_account.contacts_num(8590/11915) - 消息增量同步顺带刷新 customer.last_chat_time(云客列表按最近沟通实时 排序,快照每日一次导致顺序滞后;微信1:1+WA都加) Co-Authored-By: Claude <noreply@anthropic.com>
38 lines
1.4 KiB
Python
38 lines
1.4 KiB
Python
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# GET /api/customers/declared-total — 云客口径合计(页脚对齐云客显示,2026-08-20)
|
|
# ---------------------------------------------------------------------------
|
|
|
|
async def _seed_accounts_for_declared(session):
|
|
from app.db.models import WechatAccount
|
|
|
|
session.add_all([
|
|
WechatAccount(wx_id="w1", contacts_num=100),
|
|
WechatAccount(wx_id="w2", contacts_num=23),
|
|
WechatAccount(wx_id="w3", contacts_num=None),
|
|
])
|
|
await session.commit()
|
|
|
|
|
|
async def test_declared_total_sums_contacts_num(make_client):
|
|
"""分渠道 declared_total = Σ 员工账号表 contacts_num(云客含重复口径)。"""
|
|
from app.db.models import WhatsappAccount
|
|
|
|
async def seed_both(session):
|
|
await _seed_accounts_for_declared(session)
|
|
session.add_all([
|
|
WhatsappAccount(uid="a1@s.whatsapp.net", contacts_num=10),
|
|
WhatsappAccount(uid="a2@s.whatsapp.net", contacts_num=5),
|
|
])
|
|
await session.commit()
|
|
|
|
client = await make_client(seed_both)
|
|
r = await client.get("/api/customers/declared-total")
|
|
assert r.status_code == 200
|
|
body = r.json()
|
|
assert body["wechat"]["declared_total"] == 123
|
|
assert body["wechat"]["account_count"] == 2 # 只计有值的员工
|
|
assert body["whatsapp"]["declared_total"] == 15
|
|
assert body["whatsapp"]["account_count"] == 2
|