From 847056fe05c5a654fff9fa1421dc87430d7a5f71 Mon Sep 17 00:00:00 2001 From: aaron <> Date: Tue, 4 Mar 2025 15:12:13 +0800 Subject: [PATCH] update --- app/api/endpoints/community_timeperiod.py | 24 +++++++++++------------ app/api/endpoints/wecom.py | 6 ++---- app/core/wecomclient.py | 10 +++++++++- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/app/api/endpoints/community_timeperiod.py b/app/api/endpoints/community_timeperiod.py index 645d4ba..b2a5486 100644 --- a/app/api/endpoints/community_timeperiod.py +++ b/app/api/endpoints/community_timeperiod.py @@ -114,22 +114,20 @@ async def get_community_time_periods( """获取社区的配送时段列表""" try: # 查询社区的配送时段 - community_time_periods = db.query(CommunityTimePeriodDB).filter( + community_time_periods = db.query(CommunityTimePeriodDB, TimePeriodDB.name.label("time_period_name"),TimePeriodDB.from_time.label("time_period_from_time"), TimePeriodDB.to_time.label("time_period_to_time")).join(TimePeriodDB).filter( CommunityTimePeriodDB.community_id == community_id - ).all() - - # 获取时段详情 + ).order_by(TimePeriodDB.from_time).all() + result = [] for ctp in community_time_periods: - time_period = db.query(TimePeriodDB).filter(TimePeriodDB.id == ctp.time_period_id).first() - if time_period: - ctp_info = CommunityTimePeriodWithDetail.model_validate(ctp) - ctp_info.time_period = TimePeriodInfo.model_validate(time_period) - result.append(ctp_info) - - # 按时段开始时间排序 - result.sort(key=lambda x: x.time_period.from_time if x.time_period else None) - + result.append({ + "time_period_id": ctp.CommunityTimePeriodDB.time_period_id, + "time_period_name": ctp.time_period_name, + "capacity": ctp.CommunityTimePeriodDB.capacity, + "from_time": ctp.time_period_from_time, + "to_time": ctp.time_period_to_time + }) + return success_response(data=result) except Exception as e: diff --git a/app/api/endpoints/wecom.py b/app/api/endpoints/wecom.py index fbfca60..f8154ac 100644 --- a/app/api/endpoints/wecom.py +++ b/app/api/endpoints/wecom.py @@ -135,10 +135,8 @@ async def wechat_corp_callback( # 处理进群事件 if update_detail == 'add_member': - userid = msg_root.find('MemChangeList')[0].find('Item').text - print(f"userid: {userid}") - unionid = await wecom_client.get_unionid_from_userid(userid) - print(f"根据userid获取unionid结果: {unionid}") + # 发送欢迎消息 + await wecom_client.send_welcome_message(chat_id) return Response(content="success", media_type="text/plain") diff --git a/app/core/wecomclient.py b/app/core/wecomclient.py index 104e89a..4457573 100644 --- a/app/core/wecomclient.py +++ b/app/core/wecomclient.py @@ -128,7 +128,15 @@ class WecomClient: "chatid": group_id, "msgtype": "text", "text": { - "content": f"欢迎 @{user_info['name']} 加入群聊!\n我们为您准备了专属优惠券,请查收~" + "content": f"""🥳 欢迎您进群,在群内可以享受📦【代取快递】跑腿服务。 + + ‼ 微信下单,快递到家 ‼ + + 🎁 新人礼包 + 𝟏 赠送𝟏𝟓张【𝟑元跑腿券】 + 𝟐 赠送𝟔枚鲜鸡蛋【首次下单】 + ━ ━ ━ ━ ━🎊━ ━ ━ ━ ━ + ↓点击↓小程序领券下单 &""" } }