调整估值与交易逻辑

This commit is contained in:
邹方成 2025-11-27 16:35:36 +08:00
parent 97b872aa9b
commit 7df2bde70b
7 changed files with 31 additions and 10 deletions

View File

@ -141,8 +141,7 @@ async def get_quota(current_user: AppUser = Depends(get_current_app_user)):
- 若后续接入配额系统可从数据库中读取真实值
"""
remaining_count = current_user.remaining_quota
user_type = "体验用户"
return Success(data={"remaining_count": remaining_count, "user_type": user_type})
return Success(data={"remaining_count": remaining_count})
@router.put("/profile", response_model=BasicResponse[dict], summary="更新用户信息")

View File

@ -232,6 +232,7 @@ async def _perform_valuation_calculation(user_id: int, data: UserValuationCreate
market_value_c=calculation_result.get('market_value_c'),
final_value_ab=calculation_result.get('final_value_ab'),
calculation_result=calculation_result,
status='pending',
)
)
logger.info(
@ -468,7 +469,6 @@ async def calculate_valuation(
operator_name=user.alias or user.username or user.phone or "",
before_count=before,
after_count=before - 1,
op_type="consume",
remark="发起估值"
)
except Exception:

View File

@ -103,7 +103,7 @@ async def send_email(payload: SendEmailRequest = Body(...)):
except Exception as e:
result = {"status": "FAIL", "error": str(e)}
body_summary = payload.body[:500]
body_summary = payload.body
status = result.get("status")
error = result.get("error")
first_name = attachments[0][1] if attachments else None
@ -128,6 +128,14 @@ async def send_email(payload: SendEmailRequest = Body(...)):
if r:
r.extra = (r.extra or {}) | payload.model_dump()
await r.save()
try:
inv = await r.invoice
if inv:
inv.status = "invoiced"
await inv.save()
logger.info("transactions.invoice_mark_invoiced receipt_id={} invoice_id={}", payload.receipt_id, inv.id)
except Exception as e2:
logger.warning("transactions.invoice_mark_invoiced_fail receipt_id={} err={}", payload.receipt_id, str(e2))
except Exception as e:
logger.error("transactions.email_extra_save_fail id={} err={}", payload.receipt_id, str(e))

View File

@ -491,7 +491,7 @@ class ValuationController:
await valuation.update_from_dict(update_data)
await valuation.save()
from datetime import datetime
valuation.status = "success"
valuation.status = update_data.get("status", "pending")
if not getattr(valuation, "audited_at", None):
valuation.audited_at = datetime.now()
await valuation.save()

View File

@ -106,7 +106,7 @@ class BasicValueB11Calculator:
# 使用两个增长率的平均值
avg_growth_rate = (growth_rate_1 + growth_rate_2) / 2
return avg_growth_rate
return max(avg_growth_rate, 0.0)
def calculate_legal_strength_l(self,
patent_score: float,
@ -379,4 +379,4 @@ if __name__ == "__main__":
# print(f"增长率: {growth_rate*100}%")
# print(f"(1+14%)^5 = {growth_factor:.4f}")
# print(f"2333 × {growth_factor:.4f} = {initial_value * growth_factor:.2f}")
# print(f"再除以5: {initial_value * growth_factor:.2f} ÷ 5 = {result:.2f}")
# print(f"再除以5: {initial_value * growth_factor:.2f} ÷ 5 = {result:.2f}")

View File

@ -48,6 +48,20 @@ class TrafficFactorB12Calculator:
traffic_factor = (math.log(search_index_s1 / industry_average_s2) * 0.3 +
social_media_spread_s3 * 0.7)
"""
为什么需要
- 经济价值 B1 的公式是 B1 = B11 × (1 + B12) × B13 app/utils/calculation_engine/economic_value_b1/economic_value_b1.py:34-45
- 如果 B12 < -1 (1 + B12) 会变成负数导致 B1 翻成负值并把模型估值 Bfinal_value_ab/model_value_b.py:48-50拉到巨负
- 通过设置 B12 -0.9 确保 (1 + B12) 0.1 即乘数始终为正且不至于过小
直观示例
- 原始计算得到 B12 = -1.8 例如 ln(S1/S2) 很大负社交传播度 S3 又很低 (1 + B12) = -0.8 会让 B1 变负
- 裁剪后 B12 = -0.9 (1 + B12) = 0.1 B1 保持为正避免最终估值出现大幅负值
"""
if traffic_factor < -0.9:
traffic_factor = -0.9
return traffic_factor
@ -346,4 +360,4 @@ if __name__ == "__main__":
print(f"覆盖人群指数: {coverage_index:.4f}")
print(f"转化效率: {conversion_efficiency:.4f}")
print(f"社交媒体传播度S3: {social_media_spread_s3:.4f}")
print(f"流量因子B12: {traffic_factor:.4f}")
print(f"流量因子B12: {traffic_factor:.4f}")

View File

@ -37,8 +37,8 @@
export DOCKER_DEFAULT_PLATFORM=linux/amd64
docker build -t zfc931912343/guzhi-fastapi-admin:v2.0 .
docker push zfc931912343/guzhi-fastapi-admin:v2.0
docker build -t zfc931912343/guzhi-fastapi-admin:v2.1 .
docker push zfc931912343/guzhi-fastapi-admin:v2.1
# 运行容器