Skip to content

Commit

Permalink
fix:error
Browse files Browse the repository at this point in the history
  • Loading branch information
rocknroll17 committed Nov 3, 2024
1 parent f8ec4f6 commit 556c835
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 4 additions & 1 deletion Service/purchase_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ def purchase_history_list_db(item: ItemAdd):
with get_db() as db:
for item_add in item.items:
item_id = db.query(UserItem).filter(UserItem.user_id == item_add.user_id, UserItem.item_name == item_add.item_name).first().item_id
data_list.append(PurchaseHistory(user_id=item_add.user_id, item_id=item_id, price=item_add.price, count=item_add.count, date=item_add.purchase_date))
if item_add.count > item_add.price:
data_list.append(PurchaseHistory(user_id=item_add.user_id, item_id=item_id, price=item_add.count, count=item_add.price, date=item_add.purchase_date))
else:
data_list.append(PurchaseHistory(user_id=item_add.user_id, item_id=item_id, price=item_add.price, count=item_add.count, date=item_add.purchase_date))
return data_list


Expand Down
7 changes: 4 additions & 3 deletions Service/useritem_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ def add_userItems(itemAdd : ItemAdd):
with get_db() as db:
for addItem in itemAdd.items:
useritem = db.query(UserItem).filter(UserItem.user_id == addItem.user_id, UserItem.item_name == addItem.item_name).first()

if useritem.consume_date is None or useritem.count == 0:
useritem.consume_date = addItem.purchase_date

useritem.count += addItem.count
if addItem.count > addItem.price:
useritem.count += addItem.price
else:
useritem.count += addItem.count
useritem.consume_date += timedelta(days=useritem.consume_expectation * addItem.count)
db.commit()
return True
Expand Down

0 comments on commit 556c835

Please sign in to comment.