Add quantity field to purchasing tickets / Make Chapose the beneficiary (#302)

* Add quantity field to purchasing tickets

* Remove height requirement for div (manlets  seething)
master
outruncolors 2022-06-02 18:19:49 -05:00 committed by GitHub
parent 58c4b62163
commit dfd521b652
5 changed files with 95 additions and 75 deletions

View File

@ -1021,7 +1021,7 @@ if SITE_NAME == 'rDrama':
LOTTERY_TICKET_COST = 12
LOTTERY_SINK_RATE = 3
LOTTERY_ROYALTY_RATE = 1
LOTTERY_ROYALTY_ACCOUNT_ID = 8239 # (McCoxmaul)
LOTTERY_ROYALTY_ACCOUNT_ID = 1387 # (Chapose)
LOTTERY_MANAGER_ACCOUNT_ID = 11651 # (Lottershe)
else:
LOTTERY_ENABLED = False

View File

@ -73,32 +73,32 @@ def start_new_lottery_session():
g.db.commit()
def purchase_lottery_ticket(v):
if (v.coins < LOTTERY_TICKET_COST):
def purchase_lottery_tickets(v, quantity=1):
if (v.coins < LOTTERY_TICKET_COST * quantity):
return False, f'Lottery tickets cost {LOTTERY_TICKET_COST} dramacoins each.'
most_recent_lottery = get_active_lottery()
if (most_recent_lottery is None):
return False, "There is no active lottery."
v.coins -= LOTTERY_TICKET_COST
v.currently_held_lottery_tickets += 1
v.total_held_lottery_tickets += 1
v.coins -= LOTTERY_TICKET_COST * quantity
v.currently_held_lottery_tickets += quantity
v.total_held_lottery_tickets += quantity
net_ticket_value = LOTTERY_TICKET_COST - LOTTERY_SINK_RATE - LOTTERY_ROYALTY_RATE
net_ticket_value = (LOTTERY_TICKET_COST - LOTTERY_SINK_RATE - LOTTERY_ROYALTY_RATE) * quantity
most_recent_lottery.prize += net_ticket_value
most_recent_lottery.tickets_sold += 1
most_recent_lottery.tickets_sold += quantity
grant_lottery_proceeds_to_manager(net_ticket_value)
beneficiary = g.db.query(User).get(LOTTERY_ROYALTY_ACCOUNT_ID)
if beneficiary:
beneficiary.coins += LOTTERY_ROYALTY_RATE
beneficiary.coins += LOTTERY_ROYALTY_RATE * quantity
g.db.commit()
return True, 'Successfully purchased a lottery ticket!'
return True, f'Successfully purchased {quantity} lottery tickets!'
def grant_lottery_proceeds_to_manager(amount):
manager = g.db.query(User).get(LOTTERY_MANAGER_ACCOUNT_ID)

View File

@ -5,7 +5,7 @@ from files.helpers.get import *
from files.helpers.const import *
from files.helpers.wrappers import *
from files.helpers.lottery import *
import requests
@app.post("/lottery/end")
@admin_level_required(3)
@ -28,9 +28,11 @@ def lottery_start(v):
@auth_required
@lottery_required
def lottery_buy(v):
success, message = purchase_lottery_ticket(v)
quantity = int(request.values.get("quantity"))
success, message = purchase_lottery_tickets(v, quantity)
lottery, participants = get_active_lottery_stats()
if success:
return {"message": message, "stats": {"user": v.lottery_stats, "lottery": lottery, "participants": participants}}
else:

View File

@ -1,6 +1,4 @@
{% extends "default.html" %}
{% block content %}
{% extends "default.html" %} {% block content %}
<div>
<div class="lottery-page--wrapper">
<div class="lottery-page--image">
@ -15,7 +13,7 @@
{% if v.admin_level > 2 %}
<div
class="lottery-page--stat"
style="position: relative; padding-top: 1rem; overflow: hidden;"
style="position: relative; padding-top: 1rem; overflow: hidden"
>
<i
class="fas fa-broom"
@ -89,13 +87,36 @@
<div id="winnings">-</div>
</div>
</div>
<div class="lottery-page--stat">
<div class="lottery-page--stat-keys">
<div>Purchase Quantity</div>
</div>
<div class="lottery-page--stat-values">
<div>
<input
id="ticketPurchaseQuantity"
class="form-control"
autocomplete="off"
value="1"
min="1"
step="1"
aria-label="Quantity"
name="ticketPurchaseQuantity"
type="number"
style="flex: 1; max-width: 100px; text-align: center;"
/>
</div>
</div>
</div>
<button
type="button"
class="btn btn-success lottery-page--action"
id="purchaseTicket"
onclick="purchaseLotteryTicket()"
>
Purchase 1 for
Purchase <span id="totalQuantityOfTickets">1</span> for
<img
alt="coins"
class="mr-1 ml-1"
@ -107,65 +128,64 @@
aria-label="coins"
data-bs-original-title="coins"
/>
12
<span id="totalCostOfTickets">12</span>
</button>
</div>
</div>
<!-- Success -->
<div
class="toast"
id="lottery-post-success"
style="
position: fixed;
bottom: 1.5rem;
margin: 0 auto;
left: 0;
right: 0;
width: unset;
z-index: 1000;
"
role="alert"
aria-live="assertive"
aria-atomic="true"
data-bs-animation="true"
data-bs-autohide="true"
data-bs-delay="5000"
>
<div class="toast-body bg-success text-center text-white">
<i class="fas fa-comment-alt-smile mr-2"></i
><span id="lottery-post-success-text"></span>
<!-- Success -->
<div
class="toast"
id="lottery-post-success"
style="
position: fixed;
bottom: 1.5rem;
margin: 0 auto;
left: 0;
right: 0;
width: unset;
z-index: 1000;
"
role="alert"
aria-live="assertive"
aria-atomic="true"
data-bs-animation="true"
data-bs-autohide="true"
data-bs-delay="5000"
>
<div class="toast-body bg-success text-center text-white">
<i class="fas fa-comment-alt-smile mr-2"></i
><span id="lottery-post-success-text"></span>
</div>
</div>
<!-- Error -->
<div
class="toast"
id="lottery-post-error"
style="
position: fixed;
bottom: 1.5rem;
margin: 0 auto;
left: 0;
right: 0;
width: unset;
z-index: 1000;
"
role="alert"
aria-live="assertive"
aria-atomic="true"
data-bs-animation="true"
data-bs-autohide="true"
data-bs-delay="5000"
>
<div class="toast-body bg-danger text-center text-white">
<i class="fas fa-exclamation-circle mr-2"></i
><span id="lottery-post-error-text"></span>
</div>
</div>
</div>
<!-- Error -->
<div
class="toast"
id="lottery-post-error"
style="
position: fixed;
bottom: 1.5rem;
margin: 0 auto;
left: 0;
right: 0;
width: unset;
z-index: 1000;
"
role="alert"
aria-live="assertive"
aria-atomic="true"
data-bs-animation="true"
data-bs-autohide="true"
data-bs-delay="5000"
>
<div class="toast-body bg-danger text-center text-white">
<i class="fas fa-exclamation-circle mr-2"></i
><span id="lottery-post-error-text"></span>
</div>
</div>
<script src="{{asset('js/lottery.js')}}"></script>
</div>
<script src="{{asset('js/lottery.js')}}"></script>
</div>
{% endblock %}
{% endblock %}

View File

@ -16,8 +16,6 @@
</div>
</div>
</div>
{% endblock %}
{% block pagenav %}