修复分润的 bug
This commit is contained in:
parent
86a11d5f67
commit
00e63d8ad2
@ -265,13 +265,6 @@ async def daily_partner_settlement():
|
||||
if existing_settlement:
|
||||
logger.info(f"小区 {stat.community_name} 已存在结算记录,跳过结算")
|
||||
continue
|
||||
|
||||
|
||||
# 结算明细
|
||||
settle_details = {
|
||||
"total_order_amount": stat.total_original_amount,
|
||||
"total_pay_amount": stat.total_final_amount
|
||||
}
|
||||
|
||||
print(f"日期:{stat.stats_date} 小区: {stat.community_name} 订单数: {stat.order_count} 订单金额: {stat.total_original_amount} 支付金额: {stat.total_final_amount}")
|
||||
total_order_count += stat.order_count
|
||||
@ -298,38 +291,45 @@ async def daily_partner_settlement():
|
||||
platform_profit_sharing = community.community_profit_sharing.platform_rate
|
||||
|
||||
# 计算运营商分成金额
|
||||
partner_profit = stat.total_final_amount * (float(partner_profit_sharing)) / 100
|
||||
admin_profit = stat.total_final_amount * (float(admin_profit_sharing) / 100)
|
||||
delivery_profit = stat.total_final_amount * (float(delivery_profit_sharing) / 100)
|
||||
partner_profit = round(stat.total_final_amount * (float(partner_profit_sharing)) / 100, 2)
|
||||
admin_profit = round(stat.total_final_amount * (float(admin_profit_sharing) / 100), 2)
|
||||
delivery_profit = round(stat.total_final_amount * (float(delivery_profit_sharing) / 100), 2)
|
||||
platform_profit = stat.total_final_amount * (float(platform_profit_sharing) / 100)
|
||||
|
||||
# 结算明细
|
||||
settle_details = {
|
||||
"total_order_amount": stat.total_original_amount,
|
||||
"total_pay_amount": stat.total_final_amount,
|
||||
"total_partner_profit": partner_profit,
|
||||
"total_admin_profit": admin_profit,
|
||||
"total_delivery_profit": delivery_profit,
|
||||
"total_platform_profit": platform_profit
|
||||
}
|
||||
|
||||
# 如果没有运营商、服务商,则需要沉淀到平台
|
||||
profit_sediment = {
|
||||
"partner_profit": partner_profit,
|
||||
"admin_profit": admin_profit
|
||||
}
|
||||
total_profit_sediment = 0
|
||||
|
||||
# 计算每个运营商的分成金额
|
||||
for partner_id in partner_ids:
|
||||
if len(partner_ids) > 0:
|
||||
per_partner_profit = partner_profit / len(partner_ids)
|
||||
print(f"运营商 {partner_id} 分成金额: {per_partner_profit}")
|
||||
total_partner_profit += per_partner_profit
|
||||
for partner_id in partner_ids:
|
||||
print(f"运营商({partner_profit_sharing/100}%) {partner_id} 分成金额: {per_partner_profit}")
|
||||
total_partner_profit += per_partner_profit
|
||||
|
||||
settle_details["partner_profit"] = {
|
||||
"user_id": partner_id,
|
||||
"profit": per_partner_profit
|
||||
}
|
||||
# 更新运营商账户余额
|
||||
if per_partner_profit > 0:
|
||||
account_manager = AccountManager(db)
|
||||
account_manager.change_balance(partner_id, per_partner_profit, f"{stat.community_name} 订单收益")
|
||||
|
||||
# 计算沉淀金额
|
||||
profit_sediment["partner_profit"] -= per_partner_profit
|
||||
settle_details[f"partner_profit_{partner_id}"] = {
|
||||
"user_id": partner_id,
|
||||
"profit": per_partner_profit
|
||||
}
|
||||
# 更新运营商账户余额
|
||||
if per_partner_profit > 0:
|
||||
account_manager = AccountManager(db)
|
||||
account_manager.change_balance(partner_id, per_partner_profit, f"{stat.community_name} 订单收益")
|
||||
else:
|
||||
total_profit_sediment += partner_profit
|
||||
|
||||
|
||||
# 计算服务商分成
|
||||
print(f"服务商分成金额: {admin_profit}")
|
||||
print(f"服务商({admin_profit_sharing/100}%) {community.admin_id} 分成金额: {admin_profit}")
|
||||
total_admin_profit += admin_profit
|
||||
|
||||
settle_details["admin_profit"] = {
|
||||
@ -341,11 +341,10 @@ async def daily_partner_settlement():
|
||||
account_manager = AccountManager(db)
|
||||
account_manager.change_balance(community.admin_id, admin_profit, f"{stat.community_name} 订单收益")
|
||||
else:
|
||||
# 计算沉淀金额
|
||||
profit_sediment["admin_profit"] -= admin_profit
|
||||
total_profit_sediment += admin_profit
|
||||
|
||||
# 计算配送员分成
|
||||
print(f"配送员分成金额: {delivery_profit}")
|
||||
print(f"配送员({delivery_profit_sharing/100}%) 分成金额: {delivery_profit}")
|
||||
total_delivery_profit += delivery_profit
|
||||
|
||||
settle_details["delivery_profit"] = {
|
||||
@ -356,17 +355,15 @@ async def daily_partner_settlement():
|
||||
|
||||
# 计算平台分成
|
||||
# 计算分成 + 沉淀金额
|
||||
final_platform_profit = platform_profit + profit_sediment["partner_profit"] + profit_sediment["admin_profit"]
|
||||
final_platform_profit = platform_profit + total_profit_sediment
|
||||
|
||||
print(f"平台分成 + 沉淀金额: {final_platform_profit}")
|
||||
print(f"平台({platform_profit_sharing/100}%) 分成: {platform_profit} + 沉淀金额: {total_profit_sediment}")
|
||||
total_platform_profit += final_platform_profit
|
||||
|
||||
|
||||
settle_details["platform_profit"] = {
|
||||
"user_id": settings.PLATFORM_USER_ID,
|
||||
"profit": final_platform_profit
|
||||
}
|
||||
|
||||
|
||||
if final_platform_profit > 0:
|
||||
account_manager = AccountManager(db)
|
||||
@ -392,14 +389,14 @@ async def daily_partner_settlement():
|
||||
|
||||
### 订单汇总
|
||||
> - 订单总数: {total_order_count}
|
||||
> - 订单总金额: {total_original_amount:.1f}
|
||||
> - 支付总金额: {total_final_amount:.1f}
|
||||
> - 订单总金额: {total_original_amount:.2f}
|
||||
> - 支付总金额: {total_final_amount:.2f}
|
||||
|
||||
### 分润汇总
|
||||
> - 运营商分成: {total_partner_profit:.1f}
|
||||
> - 服务商分成: {total_admin_profit:.1f}
|
||||
> - 配送员分成: {total_delivery_profit:.1f}
|
||||
> - 平台分成: {total_platform_profit:.1f}
|
||||
> - 运营商分成: {total_partner_profit:.2f}
|
||||
> - 服务商分成: {total_admin_profit:.2f}
|
||||
> - 配送员分成: {total_delivery_profit:.2f}
|
||||
> - 平台分成: {total_platform_profit:.2f}
|
||||
|
||||
"""
|
||||
|
||||
|
||||
BIN
jobs.sqlite
BIN
jobs.sqlite
Binary file not shown.
Loading…
Reference in New Issue
Block a user