Commit 59a3feaa by zhouhaibao

feat(data-process): 增加费用分摊逻辑优化与未匹配金额统计功能

- 引入 Decimal 精确计算和 logging 日志记录功能
- 添加服务商过滤机制,仅处理含"深圳嘀加"的服务商数据
- 实现装修摊销和门店耗材的未匹配金额统计与对账功能
- 新增 biz_unmatched_fee 表模型用于存储未匹配费用汇总
- 重构市场费分摊逻辑,支持单条记录、双品牌场景和 GMV 分摊
- 优化 GMV 查询和分摊算法,增加 only_dijia 参数控制分摊范围
- 添加处理器侧未匹配金额收集和数据库写入功能
- 修改返回值结构,统一返回 (更新行数, 未匹配金额) 元组格式
1 parent 72d8e8e4
...@@ -227,6 +227,35 @@ class BizBudgetAchieve(db.Model): ...@@ -227,6 +227,35 @@ class BizBudgetAchieve(db.Model):
} }
class BizUnmatchedFee(db.Model):
"""未匹配费用汇总表 — 7 类费用匹配失败的金额按 (task_id, stat_month, fee_type) 存储"""
__tablename__ = 'biz_unmatched_fee'
__table_args__ = (
db.UniqueConstraint('task_id', 'stat_month', 'fee_type',
name='uk_task_month_feetype'),
{'comment': '未匹配费用汇总表'},
)
id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='主键ID')
task_id = db.Column(db.Integer, nullable=False, comment='所属任务单据ID')
stat_month = db.Column(db.String(7), nullable=False, comment='统计月份YYYY-MM')
fee_type = db.Column(db.String(50), nullable=False, comment='费用类型: market_fee/external_construction/technician_salary/marketing_team_salary/rent_utilities/renovation_amortization/store_consumables')
unmatched_amount = db.Column(db.DECIMAL(15, 2), nullable=False, default=0, comment='未匹配金额(正数=未分摊的费用;负数=未冲减的金额)')
created_at = db.Column(db.DateTime, default=datetime.now, comment='创建时间')
updated_at = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now, comment='更新时间')
# fee_type 枚举常量
FEE_TYPES = [
'market_fee',
'external_construction',
'technician_salary',
'marketing_team_salary',
'rent_utilities',
'renovation_amortization',
'store_consumables',
]
class DataProcessSubtask(db.Model): class DataProcessSubtask(db.Model):
""" """
红黄门店盈利测算 - 子任务表。 红黄门店盈利测算 - 子任务表。
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!