diff --git a/apps/payment/views.py b/apps/payment/views.py index 846b5a4a..8b1c2544 100644 --- a/apps/payment/views.py +++ b/apps/payment/views.py @@ -98,16 +98,17 @@ class SchoolBuyView(TemplateView): host = urlsplit(self.request.META.get('HTTP_REFERER')) host = str(host[0]) + '://' + str(host[1]) weekdays = set(request.GET.getlist('weekdays', [])) + use_bonuses = request.GET.get('use_bonuses') add_days = 'add_days' in request.GET roistat_visit = request.COOKIES.get('roistat_visit', None) if not weekdays: messages.error(request, 'Выберите несколько дней недели.') - return redirect('school:summer-school') + return redirect('school:school') try: weekdays = [int(weekday) for weekday in weekdays] except ValueError: messages.error(request, 'Ошибка выбора дней недели.') - return redirect('school:summer-school') + return redirect('school:school') if add_days: _school_payment = SchoolPayment.objects.filter( user=request.user, @@ -128,7 +129,7 @@ class SchoolBuyView(TemplateView): ) if school_payment.amount <= 0: messages.error(request, 'Выбранные дни отсутствуют в оставшемся периоде подписки') - return redirect(reverse_lazy('school:summer-school')) + return redirect(reverse_lazy('school:school')) else: school_payment = SchoolPayment.objects.create( user=request.user, diff --git a/apps/user/templates/blocks/profile-menu.html b/apps/user/templates/blocks/profile-menu.html index 35c4df2d..9db83d44 100644 --- a/apps/user/templates/blocks/profile-menu.html +++ b/apps/user/templates/blocks/profile-menu.html @@ -1,9 +1,14 @@
diff --git a/apps/user/templates/user/bonus-history.html b/apps/user/templates/user/bonus-history.html index 43e45fbd..b5461970 100644 --- a/apps/user/templates/user/bonus-history.html +++ b/apps/user/templates/user/bonus-history.html @@ -3,7 +3,7 @@ {% load rupluralize from plural %} {% block content %} -{% include "../blocks/profile-menu.html" %} +{% include "../blocks/profile-menu.html" with active="bonuses" %}
@@ -37,11 +37,7 @@ Школа. {% if payment.date_start and payment.date_end %}{{ payment.date_start }} - {{ payment.date_end }}{% endif %}
{% endif %} - {% if payment.balance %} -
{{payment.balance.amount}}
- {% else %} -
{{payment.amount|floatformat }}
- {% endif %} +
{{payment.amount }}
{% if bonus.referral %}
{{ bonus.referral.referral.get_full_name }}
{% endif %} diff --git a/apps/user/templates/user/notification-settings.html b/apps/user/templates/user/notification-settings.html index 725922bd..b73bb35d 100644 --- a/apps/user/templates/user/notification-settings.html +++ b/apps/user/templates/user/notification-settings.html @@ -1,5 +1,5 @@ {% extends "templates/lilcity/index.html" %} {% load static %} {% block content %} -{% include "../blocks/profile-menu.html" %} +{% include "../blocks/profile-menu.html" with active="notifications" %} {% if not user.is_email_proved %}
diff --git a/apps/user/templates/user/payment-history.html b/apps/user/templates/user/payment-history.html index 798ffb2b..8b7d332c 100644 --- a/apps/user/templates/user/payment-history.html +++ b/apps/user/templates/user/payment-history.html @@ -1,5 +1,5 @@ {% extends "templates/lilcity/index.html" %} {% load static %} {% block content %} -{% include "../blocks/profile-menu.html" %} +{% include "../blocks/profile-menu.html" with active="payments" %} {% if not user.is_email_proved %}
diff --git a/apps/user/templates/user/profile-settings.html b/apps/user/templates/user/profile-settings.html index 1d0619cf..08e56da8 100644 --- a/apps/user/templates/user/profile-settings.html +++ b/apps/user/templates/user/profile-settings.html @@ -1,5 +1,5 @@ {% extends "templates/lilcity/index.html" %} {% load static %} {% load thumbnail %} {% block content %} -{% include "../blocks/profile-menu.html" %} +{% include "../blocks/profile-menu.html" with active="profile" %} {% if not user.is_email_proved %}
diff --git a/apps/user/views.py b/apps/user/views.py index 7ff653b5..ee027821 100644 --- a/apps/user/views.py +++ b/apps/user/views.py @@ -158,7 +158,7 @@ class NotificationEditView(TemplateView): request.user.email_subscription.categories.set( SubscriptionCategory.objects.filter(id__in=categories) ) - return redirect('user-edit-notifications', request.user.id) + return redirect('user-edit-notifications') def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) @@ -195,7 +195,7 @@ class PaymentHistoryView(FormView): return self.form_invalid(form) def get_success_url(self): - success_url = reverse_lazy('user-edit-payments', args=[self.request.user.id]) + success_url = reverse_lazy('user-edit-payments') return success_url diff --git a/project/templates/blocks/popup_buy.html b/project/templates/blocks/popup_buy.html index 0321b2ea..cf21ff64 100644 --- a/project/templates/blocks/popup_buy.html +++ b/project/templates/blocks/popup_buy.html @@ -88,11 +88,19 @@
ШКОЛА
-
Вторник, Четверг, Воскресенье
+
+ {% if request.user.bonuses %} + + {% endif %}
Итого, за месяц:
-
1800р.
+
diff --git a/project/templates/blocks/user_menu.html b/project/templates/blocks/user_menu.html index 1e20df2d..a1fdbca8 100644 --- a/project/templates/blocks/user_menu.html +++ b/project/templates/blocks/user_menu.html @@ -12,7 +12,7 @@
{# FIXME #} {% if request.user.role >= request.user.AUTHOR_ROLE %} - + {{ request.user.balance }} руб. {% endif %} diff --git a/project/urls.py b/project/urls.py index 88966a06..fc5f9ee2 100644 --- a/project/urls.py +++ b/project/urls.py @@ -70,8 +70,8 @@ urlpatterns = [ path('user/profile/', ProfileView.as_view(), name='user-profile'), path('user/profile/edit', ProfileEditView.as_view(), name='user-edit-profile'), path('user//', UserView.as_view(), name='user'), - path('user//notifications', NotificationEditView.as_view(), name='user-edit-notifications'), - path('user//payments', PaymentHistoryView.as_view(), name='user-edit-payments'), + path('user/notifications', NotificationEditView.as_view(), name='user-edit-notifications'), + path('user/payments', PaymentHistoryView.as_view(), name='user-edit-payments'), path('user/bonuses', BonusHistoryView.as_view(), name='user-bonuses'), path('user/resend-email-verify', resend_email_verify, name='resend-email-verify'), path('subscribe', SubscribeView.as_view(), name='subscribe'), diff --git a/web/src/js/modules/popup.js b/web/src/js/modules/popup.js index 25295f7b..b303d7a6 100644 --- a/web/src/js/modules/popup.js +++ b/web/src/js/modules/popup.js @@ -145,10 +145,18 @@ $(document).ready(function () { updateCart(); }); + $(document).on('change', '[data-bonuses]', function(){ + updateCart(); + }); + function updateCart(){ var $orderPrice = $('.order_price_text'); var days = ['', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота', 'Воскресенье']; var weekdays = [], daysText = []; + var $bonuses = $('.buy__bonuses'); + var $bonusesCheckbox = $('[data-bonuses]'); + var useBonuses = $bonusesCheckbox.prop('checked'); + var bonuses = +$bonusesCheckbox.data('bonuses'); $('[data-day]').each(function() { var weekday = $(this).data('day'); if($(this).is(':checked')) { @@ -161,10 +169,17 @@ $(document).ready(function () { api.getPaymentAmount({ user: window.LIL_STORE.user.id, weekdays: weekdays }) .then((response) => { var text = ''; - if(response.data.price != response.data.amount) { - text = ''+response.data.price+' '+response.data.amount+'р.'; + var amount = +response.data.amount; + if(bonuses && bonuses >= amount){ + $bonuses.show(); + } + if(useBonuses){ + amount = 0; + } + if(response.data.price != amount) { + text = '' + response.data.price+' ' + amount + 'р.'; } else { - text = response.data.amount+'p.'; + text = amount + 'p.'; } $orderPrice.html(text); }); @@ -177,7 +192,7 @@ $(document).ready(function () { var link = $('.but_btn_popup').data('link'); - link = link+'?'+decodeURIComponent($.param({weekdays: weekdays}, true)); + link = link+'?'+decodeURIComponent($.param({weekdays: weekdays, use_bonuses: useBonuses || ''}, true)); $('.but_btn_popup').attr('href', link); }