Browse Source

промокоды

master
gsd 3 months ago
parent
commit
87e0065f22
  1. 4
      src/app/app.module.ts
  2. 2
      src/app/pages/internal-components/abstract-search-table.component.ts
  3. 4
      src/app/pages/vip-page/VipFreeDialog.ts
  4. 163
      src/app/pages/vip-page/VipPromocodeDialog.ts
  5. 24
      src/app/services/promocode.service.ts
  6. 2
      src/app/services/vip.service.ts

4
src/app/app.module.ts

@ -65,6 +65,7 @@ import {VipBuyDialog} from "./pages/vip-page/VipBuyDialog";
import {VipFreeDialog} from "./pages/vip-page/VipFreeDialog"; import {VipFreeDialog} from "./pages/vip-page/VipFreeDialog";
import {VipPromocodeDialog} from "./pages/vip-page/VipPromocodeDialog"; import {VipPromocodeDialog} from "./pages/vip-page/VipPromocodeDialog";
import {MatCheckboxModule} from "@angular/material/checkbox"; import {MatCheckboxModule} from "@angular/material/checkbox";
import {PromocodeService} from "./services/promocode.service";
registerLocaleData(localeRu, "ru") registerLocaleData(localeRu, "ru")
@ -143,7 +144,8 @@ registerLocaleData(localeRu, "ru")
ServerService, ServerService,
Tf2dataService, Tf2dataService,
MatDatepickerModule, MatDatepickerModule,
VipService VipService,
PromocodeService
], ],
bootstrap: [AppComponent] bootstrap: [AppComponent]
}) })

2
src/app/pages/internal-components/abstract-search-table.component.ts

@ -46,7 +46,7 @@ export abstract class AbstractSearchTable<T,U extends SearchFilter> implements A
} }
ngAfterViewInit(): void { 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); this.filter.fromQuery(this.route.snapshot.queryParamMap, this.paginator);
else else
this.filter.addAccountToSearch(`[U:1:${this.account_id}]`); this.filter.addAccountToSearch(`[U:1:${this.account_id}]`);

4
src/app/pages/vip-page/VipFreeDialog.ts

@ -9,8 +9,8 @@ import {VipService} from "../../services/vip.service";
template:` template:`
<h1 mat-dialog-title style="color: black">Получение бесплатно</h1> <h1 mat-dialog-title style="color: black">Получение бесплатно</h1>
<mat-dialog-content> <mat-dialog-content>
<app-need-auth-to-continue *ngIf="authService.isAuth()"></app-need-auth-to-continue> <app-need-auth-to-continue *ngIf="!authService.isAuth()"></app-need-auth-to-continue>
<div *ngIf="!authService.isAuth()"> <div *ngIf="authService.isAuth()">
<p>Бесплатная випка отличный способ проверить ее перед "покупкой", но стоит знать что для ее получения стоит отыграть некоторое время на наших серверах. Бесплатную випку можно получать неограниченное количество раз, но с перерывами!</p> <p>Бесплатная випка отличный способ проверить ее перед "покупкой", но стоит знать что для ее получения стоит отыграть некоторое время на наших серверах. Бесплатную випку можно получать неограниченное количество раз, но с перерывами!</p>
<p *ngIf="text.length>0" [style]="{'color': text_color}">{{text}}</p> <p *ngIf="text.length>0" [style]="{'color': text_color}">{{text}}</p>
<button *ngIf="text.length==0" mat-button mat-raised-button style="width: 100%" (click)="getFreeVip()">Получить випку бесплатно</button> <button *ngIf="text.length==0" mat-button mat-raised-button style="width: 100%" (click)="getFreeVip()">Получить випку бесплатно</button>

163
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 {MAT_DIALOG_DATA} from "@angular/material/dialog";
import {VipBuy} from "../../entities/VipBuy"; 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({ @Component({
selector: "app-vip-buy-dialog", selector: "app-vip-buy-dialog",
template:` template:`
<h1 mat-dialog-title style="color: black">Получение через промокод</h1> <h1 mat-dialog-title style="color: black">Получение через промокод</h1>
<mat-dialog-content> <mat-dialog-content>
</mat-dialog-content> <app-need-auth-to-continue *ngIf="!authService.isAuth()"></app-need-auth-to-continue>
<mat-dialog-actions> <div *ngIf="authService.isAuth()">
<p>Промокод одноразовый, так что если его успели активировать до тебя, ты лох</p>
<p *ngIf="text.length>0" [style]="{'color': text_color}">{{text}}</p>
<mat-form-field style="width: 100%" appearance="fill">
<mat-label>Промокод</mat-label>
<input matInput placeholder="1488-228-VIP" [(ngModel)]="code">
</mat-form-field>
<button (click)="acceptPromocode()" [disabled]="code.length==0" mat-button mat-raised-button style="width: 100%">Активировать промокод</button>
<mat-accordion *ngIf="authService.isAdmin()">
<mat-expansion-panel hideToggle>
<mat-expansion-panel-header>
<mat-panel-title>
Генерация промокодов
</mat-panel-title>
</mat-expansion-panel-header>
<div>
<mat-form-field appearance="fill" style="width: 100%">
<mat-label>Генерировать код для</mat-label>
<mat-select [(ngModel)]="genV">
<mat-option *ngFor="let v of genVariants" [value]="v">
{{v}}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field style="width: 100%" appearance="fill">
<mat-label>Количество секунд</mat-label>
<input type="number" matInput placeholder="86400" [(ngModel)]="sec">
</mat-form-field>
<mat-form-field style="width: 100%" appearance="fill">
<mat-label>Приписка к коду</mat-label>
<input matInput placeholder="GOYDA" [(ngModel)]="append">
</mat-form-field>
<button (click)="createPromocode()" mat-button mat-raised-button style="width: 100%;">Создать промокод</button>
</div>
</mat-expansion-panel>
<mat-expansion-panel hideToggle>
<mat-expansion-panel-header>
<mat-panel-title>
Действующие промокоды
</mat-panel-title>
</mat-expansion-panel-header>
<div>
<mat-list>
<mat-list-item style="padding-bottom: 5%">Промокодов {{currentPromocodes.length}} <button mat-button (click)="copyCodes()">Скопировать в буфер обмена</button></mat-list-item>
<mat-list-item style="padding-bottom: 5%" *ngFor="let c of currentPromocodes">{{c.code}} дает {{c.action}} на {{c.seconds}} секунд</mat-list-item>
</mat-list>
</div>
</mat-expansion-panel>
</mat-accordion>
</mat-dialog-actions> <button (click)="dialogRef.close()" mat-button mat-raised-button style="width: 100%; margin-bottom: 2%">Закрыть</button>
</div>
</mat-dialog-content>
` `
}) })
export class VipPromocodeDialog { export class VipPromocodeDialog implements AfterViewInit {
constructor(@Inject(MAT_DIALOG_DATA) public vip:VipBuy) {} 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)';
}
}
}
)
}
} }

24
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<any> {
return this.http.get(PromocodeService.routeApi)
}
createVipPromocode(action: string, append: string): Observable<any> {
return this.http.post(PromocodeService.routeApi, {}, {params: {action, append}})
}
acceptPromocode(code: string): Observable<any> {
return this.http.put(PromocodeService.routeApi, {}, {params: {code}})
}
}

2
src/app/services/vip.service.ts

@ -15,6 +15,6 @@ export class VipService {
} }
getFreeVip(): Observable<any> { getFreeVip(): Observable<any> {
return this.http.get(`api/profile/current/freevip`); return this.http.post(`api/profile/current/freevip`, null);
} }
} }

Loading…
Cancel
Save