Информация по транзакциям
This commit is contained in:
gofnnp 2023-05-10 02:38:17 +04:00
parent 42b46bc478
commit 76f1799b22
5 changed files with 470 additions and 300 deletions

View File

@ -1,4 +1,4 @@
import {OrderStatus, Page, PageCode} from "./interface/data";
import {OrderStatus, Page, PageCode, lvlPeriod} from "./interface/data";
export const PageList: Page[] = [
{
@ -65,3 +65,29 @@ export const orderStatuses: OrderStatus = {
'Delivered': 'Выполнен',
'Closed': 'Выполнен',
};
export const lvlPeriods: lvlPeriod[] = [
{
percent: 3,
start: 0,
end: 1600,
color: '#f2c94c'
},
{
percent: 6,
start: 1601,
end: 3600,
color: '#f2994a'
},
{
percent: 10,
start: 3601,
end: 8600,
color: '#6fcf97'
},
{
percent: 15,
start: 8601,
color: '#6fcf97'
},
]

View File

@ -1,11 +1,9 @@
export enum PageCode {
Auth,
Orders,
BonusProgram,
RefSystem,
UserData
UserData,
}
export interface Page {
@ -15,7 +13,7 @@ export interface Page {
description?: string;
getMethod?: string;
resName?: string;
onSideBar: boolean
onSideBar: boolean;
}
export interface UserDataForm {
@ -42,12 +40,16 @@ export interface Purchase {
PurchaseDate: string;
PurchaseState?: number;
CardNumber?: number;
Address?: string
CheckSummary?: number
BonusSummary?: number
Address?: string;
CheckSummary?: number;
BonusSummary?: number;
ID: string;
Transactions: Transaction[];
IsSingleTransaction?: boolean;
transactionCreateDate?: string;
transactionType?: 'CancelPayFromWallet' | 'PayFromWallet' | 'RefillWallet';
transactionSum: number;
orderSum?: number;
}
export interface Transaction {
@ -69,6 +71,13 @@ export interface OrderStatus{
[key: string]: string;
}
export interface lvlPeriod {
percent: number;
start: number;
end?: number;
color: string;
}
export interface DeliveryType {
cost: number;
title: string;
@ -92,7 +101,7 @@ export interface AcceptedOrder {
total: number;
};
date_created: string;
items: OrderProduct[]
items: OrderProduct[];
}
export interface Product {
@ -136,8 +145,8 @@ export interface OrderProduct{
name: string;
price: number;
modifiers: {
[name: string]: OrderModifier[]
}
[name: string]: OrderModifier[];
};
}
export interface OrderModifier {

View File

@ -1,33 +1,33 @@
<app-navbar title="Карта гостя" (backEvent)="logout()"></app-navbar>
<ng-container
*ngTemplateOutlet="appTpl; context: { user: customerInfo | async }"
></ng-container>
<ng-template #appTpl let-user="user">
<div class="guest-card">
<div class="guest-card__qr" (click)="qrCodeClick()">
<ng-container *ngIf="customerInfo">
<qr-code
*ngIf="user; else spinner"
[value]="user?.customer_info?.phone.substr(2) || 'Данные не найдены'"
[value]="customerInfo?.phone.substr(2) || 'Данные не найдены'"
[margin]="0"
[size]="qrCodeSize"
errorCorrectionLevel="M"
></qr-code>
</ng-container>
<ng-container *ngIf="!customerInfo">
<ng-container
*ngTemplateOutlet="spinner; context: { $implicit: 85 }"
></ng-container>
</ng-container>
</div>
<div class="guest-card__user-description">
Текущий баланс бонусов:
<span *ngIf="user">
{{
getBalanceAmount(user?.customer_info?.walletBalances)
}}
<span *ngIf="customerInfo">
{{ getBalanceAmount(customerInfo?.walletBalances) }}
бонусов</span
>
</div>
<span id="bonuses-condition"></span>
<app-accordion header="Условия начисления бонусов">
<p>
Расчет начисления бонусов - 10% от суммы покупок за период с
11.01.2023г. по 31.03.2023 г.
Расчет начисления бонусов - 10% от суммы покупок за период с 11.01.2023г.
по 31.03.2023 г.
</p>
<p>
За период с 11.01.2023г. по 31.03.2023 г. сумма ваших покупок составила
@ -42,14 +42,14 @@
</p>
<p>
Списание Бонусов происходит из расчета 1:1 (один Бонус дает скидку 1
российский рубль / 1 тенге / 1 белорусский рубль. Скидка,
предоставляемая Участнику при списании Бонусов, уменьшает цену товаров в
заказе в соответствии с условиями ПЛ.
российский рубль / 1 тенге / 1 белорусский рубль. Скидка, предоставляемая
Участнику при списании Бонусов, уменьшает цену товаров в заказе в
соответствии с условиями ПЛ.
</p>
<p>
Для списания Бонусов Участник должен попросить об этом в кофе-баре сети
«COFFEE LIKE» кассира до момента пробития фискального чека, после чего
им будет проверена возможность списания Бонусов.
«COFFEE LIKE» кассира до момента пробития фискального чека, после чего им
будет проверена возможность списания Бонусов.
</p>
<p>
Для всех Участников возможно списание без использования мобильного
@ -79,8 +79,8 @@
Возврат покупки, которая была оплачена бонусами:
<li>
В случае предъявления Участником кассового или товарного чека, сумма
бонусов, списанная для оплаты возвращаемого товара, зачисляется на
счет участника.
бонусов, списанная для оплаты возвращаемого товара, зачисляется на счет
участника.
</li>
<li>
В случае возврата товара с применением оплаты бонусами, клиенту
@ -90,8 +90,22 @@
</ul>
</app-accordion>
<div class="guest-card__purchases-description">
Сумма ваших покупок за период с 01.04.2023г. - <span>1200 руб.</span>
<div
class="guest-card__purchases-description"
[ngStyle]="{
display: purchaseData.$loading ? 'grid' : 'block'
}"
>
Сумма ваших покупок за период с
{{ purchaseData.currentPeriod[0].format("DD.MM.yyyyг.") }} -
<span *ngIf="!purchaseData.$loading"
>{{ purchaseData.currentAmount }} руб.</span
>
<ng-container *ngIf="purchaseData.$loading">
<ng-container
*ngTemplateOutlet="spinner; context: { $implicit: 24 }"
></ng-container>
</ng-container>
</div>
<app-accordion header="Узнать % начисляемых бонусов">
<p>
@ -99,51 +113,74 @@
зависимости от уровня:
</p>
<ng-container
*ngFor="let item of lvlPeriods; let index = index; let last = last"
>
<ng-container *ngIf="!last">
<ul>
<span style="color: #f2c94c">Уровень 1</span>
<li>Сумма покупок за предыдущий период 0-1600 руб.</li>
<li>Начисляемый бонус 3% от суммы покупки</li>
<span [style]="{ color: item.color }">Уровень {{ index + 1 }}</span>
<li>
Сумма покупок за предыдущий период {{ item.start }}-{{ item.end }}
руб.
</li>
<li>Начисляемый бонус {{ item.percent }}% от суммы покупки</li>
</ul>
<br />
</ng-container>
<ng-container *ngIf="last">
<ul>
<span style="color: #f2994a">Уровень 2</span>
<li>Сумма покупок за предыдущий период 1601-3600 руб.</li>
<li>Начисляемый бонус 6% от суммы покупки</li>
</ul>
<br />
<ul>
<span style="color: #6fcf97">Уровень 3</span>
<li>Сумма покупок за предыдущий период  3601-8600 руб.</li>
<li>Начисляемый бонус 10% от суммы покупки</li>
</ul>
<br />
<ul>
<span style="color: #6fcf97">Уровень 4</span>
<li>Сумма покупок за предыдущий период — от 8601 руб.</li>
<li>Начисляемый бонус, в % от суммы покупки - 15%</li>
<span [style]="{ color: item.color }">Уровень {{ index + 1 }}</span>
<li>Сумма покупок за предыдущий период — от {{ item.start }} руб.</li>
<li>Начисляемый бонус, в % от суммы покупки - {{ item.percent }}%</li>
</ul>
</ng-container>
</ng-container>
</app-accordion>
<div class="guest-card__level-info">
<ng-container *ngIf="!purchaseData.$loading">
<ng-container *ngIf="currentLvlPeriod.end">
<h2>
До следующего уровня за период с 01.04.2023 по 30.06.2023г осталось
совершить покупки на 401 рублей
До следующего уровня за период с
{{ purchaseData.currentPeriod[0].format("DD.MM.yyyyг") }} по
{{ purchaseData.currentPeriod[1].format("DD.MM.yyyyг") }}
осталось совершить покупки на {{ currentLvlPeriod.end - (purchaseData.currentAmount || 0) + 1 }} рублей
</h2>
<input
type="range"
[(ngModel)]="discountLevel"
[min]="3"
[max]="6"
[step]="0.1"
[value]="purchaseData.currentAmount"
[min]="currentLvlPeriod.start"
[max]="currentLvlPeriod.end"
[step]="0.01"
disabled="true"
[ngStyle]="{
'background-size': ((discountLevel - 3) / (6 - 3)) * 100 + '% 100%'
'background-size': ((purchaseData.currentAmount! - currentLvlPeriod.start) / (currentLvlPeriod.end - currentLvlPeriod.start + 1)) * 100 + '% 100%'
}"
/>
</ng-container>
<ng-container *ngIf="!currentLvlPeriod.end">
<h2>
У Вас последний уровень бонусной программы. Процент начисляемых бонусов: {{currentLvlPeriod.percent}}%
</h2>
</ng-container>
</ng-container>
<ng-container *ngIf="purchaseData.$loading">
<ng-container
*ngTemplateOutlet="spinner; context: { $implicit: 48 }"
></ng-container>
</ng-container>
<p class="show-more">Узнать условия начисления бонусов</p>
<p class="show-more">
<a href="#bonuses-condition">
Узнать условия начисления бонусов
</a>
</p>
</div>
<hr />
<app-last-order></app-last-order>
<app-last-order
[lastOrder]="lastPurchase"
[loading]="purchaseData.$loading"
></app-last-order>
<hr />
<app-invite-friends></app-invite-friends>
<hr />
@ -155,8 +192,7 @@
Программы лояльности</a
>
</div>
</ng-template>
<ng-template #spinner>
<mat-spinner></mat-spinner>
<ng-template #spinner let-diameter>
<mat-spinner [strokeWidth]="3" [diameter]="diameter"></mat-spinner>
</ng-template>

View File

@ -62,6 +62,7 @@
font-size: 16px;
line-height: 19px;
letter-spacing: -0.5px;
grid-template-columns: calc(100% - 24px) 24px;
span {
color: #219653;
@ -70,6 +71,9 @@
&__level-info {
padding: 36px;
display: flex;
flex-direction: column;
align-items: center;
h2 {
font-style: normal;
@ -152,9 +156,12 @@
font-size: 12px;
line-height: 16px;
text-align: center;
a {
text-decoration: none;
color: #28af49;
}
}
}
&__download-app {
width: 100%;

View File

@ -7,9 +7,21 @@ import { CookiesService } from 'src/app/services/cookies.service';
import { WpJsonService } from 'src/app/services/wp-json.service';
import { environment } from 'src/environments/environment';
import moment from 'moment';
import { Purchase, lvlPeriod } from 'src/app/interface/data';
import { lvlPeriods } from 'src/app/app.constants';
interface Moment extends moment.Moment {}
export interface IPurchaseData {
currentPeriod: Moment[];
lastPeriod: Moment[];
lastPurchases: Purchase[];
currentPurchases: Purchase[];
lastAmount?: number;
currentAmount?: number;
$loading: boolean;
}
@Component({
selector: 'app-guest-card',
templateUrl: './guest-card.component.html',
@ -18,10 +30,35 @@ interface Moment extends moment.Moment {}
export class GuestCardComponent implements OnInit {
public qrCodeSize: number = 85;
private isQrCodeClicked: boolean = false;
public customerInfo!: Observable<any>;
public purchases!: Observable<any>;
public customerInfo!: any;
public purchases!: Purchase[];
public lastPurchase!: Purchase;
public purchaseData: IPurchaseData = {
currentPeriod: [],
lastPeriod: [],
lastPurchases: [],
currentPurchases: [],
$loading: true,
get currentAmount():number {
// const amount = this.currentPurchases.reduce((accumulator, currentValue) => {
// if (currentValue.transactionType !== 'PayFromWallet') return 0;
// return accumulator + currentValue.transactionSum;
// }, 0);
// return amount * -1
return 8601
},
get lastAmount():number {
const amount = this.lastPurchases.reduce((accumulator, currentValue) => {
if (currentValue.transactionType !== 'PayFromWallet') return 0;
return accumulator + currentValue.transactionSum;
}, 0);
return amount * -1
}
};
public discountLevel: number = 4.2;
public lvlPeriods: lvlPeriod[] = lvlPeriods;
public currentLvlPeriod!: lvlPeriod;
constructor(
private _bottomSheet: MatBottomSheet,
@ -32,13 +69,44 @@ export class GuestCardComponent implements OnInit {
ngOnInit(): void {
const token = this.cookiesService.getItem('token');
this.customerInfo = this.wpJsonService.getCustomerInfo(
this.getCurrentQuarterOfYear();
this.wpJsonService
.getCustomerInfo(
environment.systemId,
token || '',
environment.icardProxy
)
.subscribe({
next: (value) => {
this.customerInfo = value.customer_info;
this.getPurchases().subscribe((value) => {
this.purchases = value[this.customerInfo?.id].filter(
(purchase: Purchase) =>
[
'PayFromWallet',
'CancelPayFromWallet',
'RefillWallet',
].includes(purchase.transactionType || '')
);
this.purchases = this.getPurchases();
this.purchases.subscribe((value) => console.log(value));
this.lastPurchase = value[this.customerInfo?.id].filter(
(purchase: Purchase) =>
[
'PayFromWallet',
].includes(purchase.transactionType || '')
)[0]
this.purchaseData.lastPurchases = this.purchases.filter((value: Purchase) => {
return moment(value.transactionCreateDate).isBetween(this.purchaseData.lastPeriod[0], this.purchaseData.lastPeriod[1])
})
this.purchaseData.currentPurchases = this.purchases.filter((value: Purchase) => {
return moment(value.transactionCreateDate).isBetween(this.purchaseData.currentPeriod[0], this.purchaseData.currentPeriod[1])
})
const currentAmount = this.purchaseData.currentAmount || 0
this.currentLvlPeriod = this.lvlPeriods.find((item) => item.start <= currentAmount && currentAmount <= (item.end || Infinity))!
this.purchaseData.$loading = false;
});
},
});
}
qrCodeClick() {
@ -63,26 +131,50 @@ export class GuestCardComponent implements OnInit {
}
getPurchases(
start: Date | Moment = moment().startOf('month'),
start: Date | Moment = moment().subtract(1, 'months').startOf('month'),
end: Date | Moment = moment()
): Observable<any> {
const token = this.cookiesService.getItem('token');
const delta = moment(end).diff(moment(start), 'days');
return this.wpJsonService.getTransactionsInfo(
return this.wpJsonService.getTransactions(
environment.systemId,
token ?? '',
environment.icardProxy
);
}
getBalanceAmount(loyaltyPrograms: any[]) {
console.log(loyaltyPrograms);
getCurrentQuarterOfYear() {
const quarters = [
[
moment().subtract(1, 'years').endOf('year').subtract(3, 'months'),
moment().subtract(1, 'years').endOf('year'),
],
[moment().startOf('year'), moment().startOf('year').add(3, 'months')],
[
moment().startOf('year').add(3, 'months'),
moment().startOf('year').add(6, 'months'),
],
[
moment().startOf('year').add(6, 'months'),
moment().startOf('year').add(9, 'months'),
],
[
moment().startOf('year').add(9, 'months'),
moment().startOf('year').add(12, 'months'),
],
];
return loyaltyPrograms.reduce(
(accumulator, currentValue) => {
return accumulator + currentValue.balance
},
0
);
for (let i = 0; i < 4; i++) {
if (moment().isBetween(quarters[i][0], quarters[i][1])) {
this.purchaseData.lastPeriod = quarters[i - 1];
this.purchaseData.currentPeriod = quarters[i];
}
}
}
getBalanceAmount(loyaltyPrograms: any[]) {
return loyaltyPrograms.reduce((accumulator, currentValue) => {
return accumulator + currentValue.balance;
}, 0);
}
}