Commit ff9b7788 by zhouhaibao

feat(data-process): 新增管理和阳光激励费用字段及处理逻辑

- 在 light_reform_inshop_processor.py 中新增 mgmt_market_fee 和 sunshine_incentive_fee 字段
- 修改市场费用计算逻辑,根据一线激励情况选择不同费用组合
- 更新 report_utils.py 中的列匹配逻辑,支持整数索引方式获取列数据
- 在数据库查询中新增 mgmt_market_fee 和 sunshine_incentive_fee 字段统计
- 添加费用类别的条件判断,将不同费用归类到对应字段
- 更新数据处理流程以支持新的费用字段解析和存储
1 parent 72c02e7e
......@@ -203,6 +203,8 @@ class LightReformInshopProcessor:
'store_share': fs.get('store_share', Decimal('0')),
'construction_income': fs.get('construction_income', Decimal('0')),
'market_fee': fs.get('market_fee', Decimal('0')),
'mgmt_market_fee': fs.get('mgmt_market_fee', Decimal('0')),
'sunshine_incentive_fee': fs.get('sunshine_incentive_fee', Decimal('0')),
}
# ========== Step3: 上月预算明细(已在 Step1 从 Excel 解析) ==========
......@@ -280,7 +282,8 @@ class LightReformInshopProcessor:
store_share = sql_data.get('store_share', Decimal('0'))
construction_income = sql_data.get('construction_income', Decimal('0'))
market_fee_raw = sql_data.get('market_fee', Decimal('0'))
mgmt_market_fee = sql_data.get('mgmt_market_fee', Decimal('0'))
sunshine_incentive_fee = sql_data.get('sunshine_incentive_fee', Decimal('0'))
# —— 商务政策(店中店)——
# 先精确匹配,失败则 fuzzy 包含匹配
......@@ -390,9 +393,11 @@ class LightReformInshopProcessor:
product_cost_ratio = safe_div_pct_decimal(product_cost_finance, store_output_value)
# 市场费:若一线激励存在(不为 0),则只算管理层市场费1+2
# 这里 market_fee_raw 已经是 TODO 占位值,先原样取
market_fee = market_fee_raw
# 市场费:若一线激励存在(> 0),则只算管理层市场费1+2;否则管理层+阳光激励全算
if frontline_incentive and frontline_incentive > 0:
market_fee = mgmt_market_fee
else:
market_fee = mgmt_market_fee + sunshine_incentive_fee
market_fee_ratio = safe_div_pct_decimal(market_fee, store_output_value)
# 营销人员成本
......
......@@ -267,7 +267,14 @@ def match_columns(columns, keywords_map):
"""
result = {}
# —— 先处理带 ordinal 的(返回 int 索引,因为列名相同无法区分)——
# —— 先处理直接传 int 索引的(比如 AF 列 = 31)——
for std, keywords in keywords_map.items():
for kw in keywords:
if isinstance(kw, int) and 0 <= kw < len(columns):
result[std] = kw
break
# —— 再处理带 ordinal 的(返回 int 索引,因为列名相同无法区分)——
for std, keywords in keywords_map.items():
for kw in keywords:
if isinstance(kw, tuple) and len(kw) == 2 and isinstance(kw[1], int):
......@@ -1263,7 +1270,7 @@ def parse_labor_cost(file_path, biz_type='1.1', password='2026'):
df.columns = [str(c).strip() if c else '' for c in df.columns]
col_map = match_columns(df.columns, {
'store_name': ['入驻门店', '门店名称', '门店名'],
'verify': ['检核业务线'],
'verify': [31], # AF 列,直接按索引取
'biz_type': ['人员业务归属', '业务类型', '业务线'],
'position': ['岗位', '职位'],
})
......@@ -1280,16 +1287,18 @@ def parse_labor_cost(file_path, biz_type='1.1', password='2026'):
result = {}
skip_verify = skip_biz = skip_pos = 0
for _, row in df.iterrows():
# 检核业务线 = True
if verify_col:
v = row.get(verify_col)
if v is not True:
# 检核列:truthy = True / 1 / '1' / '是' / 'TRUE' / 'TUER'(兼容各种 Excel 值)
# verify_col 可能是 int(按索引取)或 str(按列名取)
if verify_col is not None:
v = row.iloc[verify_col] if isinstance(verify_col, int) else row.get(verify_col)
v_norm = str(v).strip().upper() if v is not None else ''
if v is None or v_norm in ('', '0', '否', 'FALSE', 'NAN', 'NONE'):
skip_verify += 1
continue
# 人员业务归属 = biz_type
if biz_col:
bt_raw = row.get(biz_col)
if biz_col is not None:
bt_raw = row.iloc[biz_col] if isinstance(biz_col, int) else row.get(biz_col)
bt = str(bt_raw).strip() if bt_raw is not None else ''
# pandas 可能把 '1.1' 读成 float 1.1
try:
......@@ -1302,13 +1311,15 @@ def parse_labor_cost(file_path, biz_type='1.1', password='2026'):
continue
# 岗位筛选
if pos_col:
pos = str(row.get(pos_col, '')).strip()
if pos_col is not None:
pos_raw = row.iloc[pos_col] if isinstance(pos_col, int) else row.get(pos_col)
pos = str(pos_raw).strip() if pos_raw is not None else ''
if pos and not any(t in pos for t in target_positions):
skip_pos += 1
continue
sn = str(row.get(col_map['store_name'], '')).strip()
sn_raw = row.iloc[col_map['store_name']] if isinstance(col_map['store_name'], int) else row.get(col_map['store_name'], '')
sn = str(sn_raw).strip() if sn_raw is not None else ''
if not sn or sn in ('nan', 'None', ''):
continue
result[sn] = result.get(sn, 0) + 1
......@@ -2194,7 +2205,9 @@ def fetch_light_reform_finance_stats(start_date, end_date, scene_type=1):
SUM(t.premium_cost) AS premium_cost,
SUM(t.store_share) AS store_share,
SUM(t.construction_income) AS construction_income,
SUM(t.market_fee) AS market_fee
SUM(t.market_fee) AS market_fee,
SUM(t.mgmt_market_fee) AS mgmt_market_fee,
SUM(t.sunshine_incentive_fee) AS sunshine_incentive_fee
FROM (
SELECT
......@@ -2241,7 +2254,9 @@ def fetch_light_reform_finance_stats(start_date, end_date, scene_type=1):
-- construction_income / market_fee: MAX 取单次值
MAX(IFNULL(gopa2.custom_common_cost, 0)) AS construction_income,
MAX(IFNULL(fee.total, 0)) AS market_fee
MAX(IFNULL(fee.total, 0)) AS market_fee,
MAX(IFNULL(fee.mgmt_fee, 0)) AS mgmt_market_fee,
MAX(IFNULL(fee.sunshine_fee, 0)) AS sunshine_incentive_fee
FROM dj_car_life_goods_order_profit_allocation gopa
INNER JOIN dj_car_life_goods_order go
......@@ -2258,6 +2273,8 @@ def fetch_light_reform_finance_stats(start_date, end_date, scene_type=1):
LEFT JOIN (
SELECT
ecc.order_code,
SUM(IF(ecc.expense_category_id IN (706, 808), ecc.expense_category_result, 0)) AS mgmt_fee,
SUM(IF(ecc.expense_category_id IN (809, 901), ecc.expense_category_result, 0)) AS sunshine_fee,
SUM(ecc.expense_category_result) AS total
FROM dj_car_life_order_expense_category_calculated ecc
INNER JOIN dj_car_life_goods_order go ON ecc.order_code = go.order_code AND go.deleted_flag = 'N'
......@@ -2298,6 +2315,8 @@ def fetch_light_reform_finance_stats(start_date, end_date, scene_type=1):
'store_share': Decimal(str(r['store_share'] or Decimal('0'))).quantize(Decimal('0.01'), ROUND_HALF_UP),
'construction_income': Decimal(str(r['construction_income'] or Decimal('0'))).quantize(Decimal('0.01'), ROUND_HALF_UP),
'market_fee': Decimal(str(r['market_fee'] or Decimal('0'))).quantize(Decimal('0.01'), ROUND_HALF_UP),
'mgmt_market_fee': Decimal(str(r.get('mgmt_market_fee', Decimal('0')))).quantize(Decimal('0.01'), ROUND_HALF_UP),
'sunshine_incentive_fee': Decimal(str(r.get('sunshine_incentive_fee', Decimal('0')))).quantize(Decimal('0.01'), ROUND_HALF_UP),
}
logger.info(f"[BizSQL-轻改财务] 完成, {len(out)} 个门店")
return out
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!