Skip to content

Commit

Permalink
feat: add field buy_count
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Jan 19, 2025
1 parent 3128b7a commit 3aa3272
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Bill(Model):
plan_id = CharField()
user_id = CharField()
created_at = DateTimeField()
buy_count = IntegerField()
actually_paid = CharField()
original_price = CharField()
raw_data = TextField()
Expand Down
4 changes: 3 additions & 1 deletion src/order/afdian/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ async def process_order(out_trade_no: str) -> Tuple[Any, str]:
order = order[0]

now = datetime.now()
buy_count = order.get("sku_detail", [{}])[0].get("count", 1)
try:
bill = Bill.get_or_create(
platform="afdian",
Expand All @@ -36,6 +37,7 @@ async def process_order(out_trade_no: str) -> Tuple[Any, str]:
"plan_id": order["plan_id"],
"user_id": order["user_id"],
"created_at": now,
"buy_count": buy_count,
"actually_paid": order["total_amount"],
"original_price": order["show_amount"],
"raw_data": json.dumps(response),
Expand Down Expand Up @@ -68,7 +70,7 @@ async def process_order(out_trade_no: str) -> Tuple[Any, str]:
logger.error(f"Plan not found, out_trade_no: {out_trade_no}, error: {e}")
return None, "Plan not found"

expired = now + timedelta(days=plan.valid_days)
expired = now + timedelta(days=plan.valid_days * buy_count)
cdk = await acquire_cdk(expired)
if not cdk:
logger.error(f"Query CDK failed, out_trade_no: {out_trade_no}")
Expand Down

0 comments on commit 3aa3272

Please sign in to comment.