From 87e0065f220ef18e67815763d1533b5147b63ffa Mon Sep 17 00:00:00 2001 From: gsd Date: Sun, 13 Apr 2025 14:18:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=BC=D0=BE=D0=BA=D0=BE?= =?UTF-8?q?=D0=B4=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/app.module.ts | 4 +- .../abstract-search-table.component.ts | 2 +- src/app/pages/vip-page/VipFreeDialog.ts | 4 +- src/app/pages/vip-page/VipPromocodeDialog.ts | 163 +++++++++++++++++- src/app/services/promocode.service.ts | 24 +++ src/app/services/vip.service.ts | 2 +- 6 files changed, 188 insertions(+), 11 deletions(-) create mode 100644 src/app/services/promocode.service.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index b7e2b6f..6453787 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -65,6 +65,7 @@ import {VipBuyDialog} from "./pages/vip-page/VipBuyDialog"; import {VipFreeDialog} from "./pages/vip-page/VipFreeDialog"; import {VipPromocodeDialog} from "./pages/vip-page/VipPromocodeDialog"; import {MatCheckboxModule} from "@angular/material/checkbox"; +import {PromocodeService} from "./services/promocode.service"; registerLocaleData(localeRu, "ru") @@ -143,7 +144,8 @@ registerLocaleData(localeRu, "ru") ServerService, Tf2dataService, MatDatepickerModule, - VipService + VipService, + PromocodeService ], bootstrap: [AppComponent] }) diff --git a/src/app/pages/internal-components/abstract-search-table.component.ts b/src/app/pages/internal-components/abstract-search-table.component.ts index 155aa45..1b1babc 100644 --- a/src/app/pages/internal-components/abstract-search-table.component.ts +++ b/src/app/pages/internal-components/abstract-search-table.component.ts @@ -46,7 +46,7 @@ export abstract class AbstractSearchTable implements A } ngAfterViewInit(): void { - if (this.account_id == null || this.use_query) + if (this.account_id == null || !this.use_query) this.filter.fromQuery(this.route.snapshot.queryParamMap, this.paginator); else this.filter.addAccountToSearch(`[U:1:${this.account_id}]`); diff --git a/src/app/pages/vip-page/VipFreeDialog.ts b/src/app/pages/vip-page/VipFreeDialog.ts index fa12ff9..e00ddef 100644 --- a/src/app/pages/vip-page/VipFreeDialog.ts +++ b/src/app/pages/vip-page/VipFreeDialog.ts @@ -9,8 +9,8 @@ import {VipService} from "../../services/vip.service"; template:`

Получение бесплатно

- -
+ +

Бесплатная випка отличный способ проверить ее перед "покупкой", но стоит знать что для ее получения стоит отыграть некоторое время на наших серверах. Бесплатную випку можно получать неограниченное количество раз, но с перерывами!

{{text}}

diff --git a/src/app/pages/vip-page/VipPromocodeDialog.ts b/src/app/pages/vip-page/VipPromocodeDialog.ts index def6ea7..ef0d6e2 100644 --- a/src/app/pages/vip-page/VipPromocodeDialog.ts +++ b/src/app/pages/vip-page/VipPromocodeDialog.ts @@ -1,18 +1,169 @@ -import {Component, Inject} from "@angular/core"; +import {AfterViewInit, Component, Inject} from "@angular/core"; import {MAT_DIALOG_DATA} from "@angular/material/dialog"; import {VipBuy} from "../../entities/VipBuy"; +import {AuthService} from "../../services/auth.service"; +import {PromocodeService} from "../../services/promocode.service"; +import {DialogRef} from "@angular/cdk/dialog"; +import {ActionService} from "../../services/action.service"; @Component({ selector: "app-vip-buy-dialog", template:`

Получение через промокод

- - + +
+

Промокод одноразовый, так что если его успели активировать до тебя, ты лох

+

{{text}}

+ + Промокод + + + + + + + + + Генерация промокодов + + +
+ + Генерировать код для + + + {{v}} + + + + + Количество секунд + + + + Приписка к коду + + + +
+
+ + + + Действующие промокоды + + +
+ + Промокодов {{currentPromocodes.length}} + {{c.code}} дает {{c.action}} на {{c.seconds}} секунд + +
+
+
- + +
+ ` }) -export class VipPromocodeDialog { - constructor(@Inject(MAT_DIALOG_DATA) public vip:VipBuy) {} +export class VipPromocodeDialog implements AfterViewInit { + code: string = ""; + text: string = ''; + text_color: string = 'black'; + + genVariants: string[] = ['VIP'] + genV: string = 'VIP'; + sec: number = 86400; + append: string = 'YALOX'; + + currentPromocodes:{code: string, action: string, seconds: number}[] = [] + constructor(@Inject(MAT_DIALOG_DATA) public vip:VipBuy, + public authService: AuthService, + private promocodeService: PromocodeService, + public dialogRef: DialogRef, + private actionService: ActionService) {} + + ngAfterViewInit(): void { + this.getCurrentPromocodes(); + } + + createPromocode() { + this.promocodeService.createVipPromocode(`${this.genV}:${this.sec}`, this.append).subscribe( + () => {}, + (err) => { + if (err.status == 201) { + this.actionService.showSnack('Код сгенерирован'); + this.getCurrentPromocodes(); + } + else + this.actionService.showSnack('Ошибка генерации кода'); + } + ) + } + + getCurrentPromocodes() { + this.currentPromocodes = []; + this.promocodeService.getPromoCodes().subscribe( + (res) => { + const cl = Object.keys(res); + cl.forEach((code) => { + const s = res[code].split(":"); + this.currentPromocodes.push({code: code, action: s[0], seconds: parseInt(s[1])}); + }) + } + ) + } + + copyCodes() { + let text = ''; + this.currentPromocodes.forEach((c) => { + text += `${c.code} дает ${c.action} на ${c.seconds} секунд\n`; + }) + this.actionService.copyToClipboard(text); + } + + acceptPromocode() { + this.promocodeService.acceptPromocode(this.code).subscribe( + (res) => { + this.text = 'Промокод активирован, твой ВИП был продлен'; + this.text_color = '#54911b'; + }, + (err) => { + switch (err.status) { + case 204: { + this.text = 'Промокод активирован, но тебе это ничего не даст'; + this.text_color = '#54911b'; + break; + } + case 201: { + this.text = 'Промокод активирован, випка была добавлена к тебе на аккаунт'; + this.text_color = '#54911b'; + break; + } + case 423: + case 404: { + this.text = 'Такого промокода не существует'; + this.text_color = '#bd2200'; + break; + } + case 410: { + this.text = 'Промокод был уже активирован'; + this.text_color = 'rgba(253,136,70,0.4)'; + break; + } + case 409: { + this.text = 'Ты уже активировал ранее промокод, подожди перед активацией нового'; + this.text_color = 'rgba(253,136,70,0.4)'; + break; + } + default: { + this.text = 'Ошибка сервера, попробуй еще раз'; + this.text_color = 'rgb(255,40,40)'; + } + } + } + ) + } } diff --git a/src/app/services/promocode.service.ts b/src/app/services/promocode.service.ts new file mode 100644 index 0000000..58f4ba4 --- /dev/null +++ b/src/app/services/promocode.service.ts @@ -0,0 +1,24 @@ +import { Injectable } from '@angular/core'; +import {HttpClient} from "@angular/common/http"; +import {Observable} from "rxjs"; + +@Injectable({ + providedIn: 'root' +}) +export class PromocodeService { + static routeApi:string = "api/promocode"; + + constructor(private http: HttpClient) { } + + getPromoCodes():Observable { + return this.http.get(PromocodeService.routeApi) + } + + createVipPromocode(action: string, append: string): Observable { + return this.http.post(PromocodeService.routeApi, {}, {params: {action, append}}) + } + + acceptPromocode(code: string): Observable { + return this.http.put(PromocodeService.routeApi, {}, {params: {code}}) + } +} diff --git a/src/app/services/vip.service.ts b/src/app/services/vip.service.ts index 4f51ff2..a102c29 100644 --- a/src/app/services/vip.service.ts +++ b/src/app/services/vip.service.ts @@ -15,6 +15,6 @@ export class VipService { } getFreeVip(): Observable { - return this.http.get(`api/profile/current/freevip`); + return this.http.post(`api/profile/current/freevip`, null); } }