dev #14494 WPA CoffeeLike изменить апи для получения последней транзакции

This commit is contained in:
nikolay 2023-06-15 15:40:19 +04:00
parent a8062667df
commit eef97fd35f
6 changed files with 49 additions and 163 deletions

View File

@ -7,7 +7,7 @@ import { Purchase } from 'src/app/interface/data';
styleUrls: ['./last-order.component.scss'] styleUrls: ['./last-order.component.scss']
}) })
export class LastOrderComponent implements OnInit { export class LastOrderComponent implements OnInit {
@Input() lastOrder!: Purchase; @Input() lastOrder?: Purchase;
@Input() loading!: boolean; @Input() loading!: boolean;
constructor() { } constructor() { }

View File

@ -33,7 +33,7 @@
Осталось купить на сумму Осталось купить на сумму
<span class="price">{{ <span class="price">{{
loyaltyProgram.currentLvlPeriod.end - loyaltyProgram.currentLvlPeriod.end -
(loyaltyProgram.purchaseData.currentAmount || 0) + (customerInfo.OrdersSum) +
1 1
}}</span> }}</span>
рублей, тогда кэшбек будет рублей, тогда кэшбек будет
@ -55,37 +55,8 @@
</p> </p>
</div> </div>
<span id="bonuses-condition"></span> <span id="bonuses-condition"></span>
<!-- <div class="guest-card__level-info"> -->
<!-- <ng-container *ngIf="!purchaseData.$loading"> -->
<!-- <ng-container *ngIf="currentLvlPeriod.end"> -->
<!-- <\!-- <input -\-> -->
<!-- <\!-- type="range" -\-> -->
<!-- <\!-- [value]="purchaseData.currentAmount" -\-> -->
<!-- <\!-- [min]="currentLvlPeriod.start" -\-> -->
<!-- <\!-- [max]="currentLvlPeriod.end" -\-> -->
<!-- <\!-- [step]="0.01" -\-> -->
<!-- <\!-- disabled="true" -\-> -->
<!-- <\!-- [ngStyle]="{ -\-> -->
<!-- <\!-- '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> -->
<!-- </div> -->
<app-last-order <app-last-order
[lastOrder]="lastPurchase" [lastOrder]="loyaltyProgram.purchaseData.lastPurchase"
[loading]="loyaltyProgram.purchaseData.$loading" [loading]="loyaltyProgram.purchaseData.$loading"
></app-last-order> ></app-last-order>
<a class="guest-card__loyalty-program" routerLink="loyality-program" <a class="guest-card__loyalty-program" routerLink="loyality-program"

View File

@ -21,8 +21,6 @@ export class GuestCardComponent implements OnInit {
public qrCodeSize: number = 85; public qrCodeSize: number = 85;
private isQrCodeClicked: boolean = false; private isQrCodeClicked: boolean = false;
public customerInfo!: any; public customerInfo!: any;
public purchases!: Purchase[];
public lastPurchase!: Purchase;
public Math: Math = Math; public Math: Math = Math;
constructor( constructor(
@ -52,18 +50,12 @@ export class GuestCardComponent implements OnInit {
this.customerInfo = value.customer_info; this.customerInfo = value.customer_info;
this.cookiesService.setCookie('phone-number', this.customerInfo?.phone?.substr(2)) this.cookiesService.setCookie('phone-number', this.customerInfo?.phone?.substr(2))
this.getPurchases().subscribe((value) => { this.loyaltyProgram.setCurrentLvl(this.customerInfo.OrdersSum);
this.purchases = this.loyaltyProgram.filterPurchases(value[this.customerInfo?.id])
this.lastPurchase = this.loyaltyProgram.getLastPurchase(this.purchases)
this.loyaltyProgram.setLastPurchases(this.purchases) this.loyaltyProgram.getLastPurchase(
this.loyaltyProgram.setCurrentPurchases(this.purchases) environment.systemId,
token || '',
const currentAmount = this.loyaltyProgram.purchaseData.currentAmount || 0 );
this.loyaltyProgram.setCurrentLvl(currentAmount)
this.loyaltyProgram.purchaseData.$loading = false;
});
}, },
}); });
} }
@ -108,18 +100,4 @@ export class GuestCardComponent implements OnInit {
}, },
}); });
} }
getPurchases(
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.getTransactions(
environment.systemId,
token ?? '',
environment.icardProxy
);
}
} }

View File

@ -2,15 +2,15 @@ import { Injectable } from '@angular/core';
import moment from 'moment'; import moment from 'moment';
import { Moment, Purchase, lvlPeriod } from '../interface/data'; import { Moment, Purchase, lvlPeriod } from '../interface/data';
import { lvlPeriods } from '../app.constants'; import { lvlPeriods } from '../app.constants';
import { WpJsonService } from './wp-json.service';
import { Observable } from 'rxjs';
export interface IPurchaseData { export interface IPurchaseData {
currentPeriod: Moment[]; currentPeriod: Moment[];
lastPeriod: Moment[]; lastPeriod: Moment[];
lastPurchases: Purchase[];
currentPurchases: Purchase[];
lastAmount?: number;
currentAmount?: number; currentAmount?: number;
$loading: boolean; $loading: boolean;
lastPurchase?: Purchase;
} }
@Injectable({ @Injectable({
@ -20,58 +20,17 @@ export class LoyaltyProgramService {
public purchaseData: IPurchaseData = { public purchaseData: IPurchaseData = {
currentPeriod: [], currentPeriod: [],
lastPeriod: [], lastPeriod: [],
lastPurchases: [],
currentPurchases: [],
$loading: false, $loading: false,
get currentAmount(): number { lastPurchase: undefined,
const amount = this.currentPurchases.reduce(
(accumulator, currentValue) => {
if (
['CancelPayFromWallet', 'CancelRefillWalletFromOrder'].includes(
currentValue.transactionType || ''
)
) {
return accumulator - currentValue.orderSum!;
} else if (
['PayFromWallet', 'RefillWalletFromOrder'].includes(
currentValue.transactionType || ''
)
) {
return accumulator + currentValue.orderSum!;
}
return accumulator;
},
0
);
return amount * 1;
},
get lastAmount(): number {
const amount = this.lastPurchases.reduce((accumulator, currentValue) => {
if (
['CancelPayFromWallet', 'CancelRefillWalletFromOrder'].includes(
currentValue.transactionType || ''
)
) {
return accumulator - currentValue.orderSum!;
} else if (
['PayFromWallet', 'RefillWalletFromOrder'].includes(
currentValue.transactionType || ''
)
) {
return accumulator + currentValue.orderSum!;
}
return accumulator;
}, 0);
return amount * 1;
},
}; };
public currentLvl: number = 1; public currentLvl: number = 1;
public currentLvlPeriod!: lvlPeriod; public currentLvlPeriod!: lvlPeriod;
public lvlPeriods: lvlPeriod[] = lvlPeriods; public lvlPeriods: lvlPeriod[] = lvlPeriods;
constructor() { constructor(
private wpJsonService: WpJsonService,
) {
this.getCurrentQuarterOfYear(); this.getCurrentQuarterOfYear();
} }
@ -116,43 +75,6 @@ export class LoyaltyProgramService {
}, 0); }, 0);
} }
setLastPurchases(purchases: Purchase[]) {
this.purchaseData.lastPurchases = (purchases || []).filter((value: Purchase) => {
return moment(value.transactionCreateDate).isBetween(
this.purchaseData.lastPeriod[0],
this.purchaseData.lastPeriod[1]
);
});
}
setCurrentPurchases(purchases: Purchase[]) {
this.purchaseData.currentPurchases = (purchases || []).filter((value: Purchase) => {
return moment(value.transactionCreateDate).isBetween(
this.purchaseData.currentPeriod[0],
this.purchaseData.currentPeriod[1]
);
});
}
filterPurchases(purchases: Purchase[]) {
return (purchases || []).filter((purchase: Purchase) =>
[
'PayFromWallet',
'RefillWalletFromOrder',
'CancelPayFromWallet',
'CancelRefillWalletFromOrder',
].includes(purchase.transactionType || '')
);
}
getLastPurchase(purchases: Purchase[]) {
return purchases.filter((purchase: Purchase) =>
['PayFromWallet', 'RefillWalletFromOrder'].includes(
purchase.transactionType || ''
)
)[0];
}
setCurrentLvl(currentAmount: number) { setCurrentLvl(currentAmount: number) {
const index = this.lvlPeriods.findIndex( const index = this.lvlPeriods.findIndex(
(item) => (item) =>
@ -170,4 +92,16 @@ export class LoyaltyProgramService {
} }
return lvlPeriods[this.currentLvl]; return lvlPeriods[this.currentLvl];
} }
getLastPurchase(systemId: string, token: string) {
this.purchaseData.$loading = true;
this.wpJsonService.getLastPurchase(systemId, token).subscribe({
next: (res) => {
this.purchaseData.lastPurchase = res;
},
complete: () => {
this.purchaseData.$loading = false;
}
});
}
} }

View File

@ -1,12 +1,11 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import {environment} from "../../environments/environment"; import { environment } from "../../environments/environment";
import {HttpClient, HttpHeaders} from "@angular/common/http"; import { HttpClient, HttpHeaders } from "@angular/common/http";
import {CookiesService} from "./cookies.service"; import { CookiesService } from "./cookies.service";
import {Observable, of, switchMap} from "rxjs"; import { Observable, of, switchMap } from "rxjs";
import {JsonRpcBody} from "./jsonrpc.service"; import { JsonRpcBody } from "./jsonrpc.service";
import {DeliveryType, AcceptedOrder, Product} from "../interface/data"; import { DeliveryType, AcceptedOrder, Product, Purchase } from "../interface/data";
import {ActivatedRoute} from "@angular/router"; import { ActivatedRoute } from "@angular/router";
import {Order} from "../models/order";
export enum Method { export enum Method {
@ -26,19 +25,19 @@ export class WpJsonService {
private route: ActivatedRoute, private route: ActivatedRoute,
) { } ) { }
getDeliveryTypes(): Observable<DeliveryType[]>{ getDeliveryTypes(): Observable<DeliveryType[]> {
return this._request('orders/delivery-types', 'GET'); return this._request('orders/delivery-types', 'GET');
} }
createOrder(order: any){ createOrder(order: any) {
return this._request('orders', 'POST', order); return this._request('orders', 'POST', order);
} }
getOrders(): Observable<AcceptedOrder[]>{ getOrders(): Observable<AcceptedOrder[]> {
return this._request('orders', 'GET', null, true); return this._request('orders', 'GET', null, true);
} }
getProductById(id: number): Observable<Product>{ getProductById(id: number): Observable<Product> {
return this._request(`products/${id}`, 'GET'); return this._request(`products/${id}`, 'GET');
} }
@ -57,6 +56,10 @@ export class WpJsonService {
) )
} }
getLastPurchase(systemId: string, token: string): Observable<Purchase> {
return this._request(`last_trans/${systemId}/${token}/`, 'GET', null, false, environment.icardProxy);
}
newCustomer(systemId: string, token: string, url: string): Observable<any> { newCustomer(systemId: string, token: string, url: string): Observable<any> {
return this._request(`new_customer/${systemId}/${token}/`, 'GET', null, false, url) return this._request(`new_customer/${systemId}/${token}/`, 'GET', null, false, url)
} }
@ -96,6 +99,6 @@ export class WpJsonService {
url = baseUrl url = baseUrl
} }
return this.http return this.http
.request( method, url + path + urlToken, options); .request(method, url + path + urlToken, options);
} }
} }

View File

@ -19,7 +19,7 @@ export const environment = {
}, },
version: packageJson.version, version: packageJson.version,
appleWalletEndpoint: 'https://apple-wallet-iiko.it-retail.tech/apns/api', appleWalletEndpoint: 'https://apple-wallet-iiko.it-retail.tech/apns/api',
icardProxy: 'http://localhost:4200/icard-proxy/', icardProxy: 'https://coffee-like-test.lk.crm4retail.ru/api/icard-proxy/',
appleWalletSecret: 'Token F5mbzEERAznGKVbB6l', appleWalletSecret: 'Token F5mbzEERAznGKVbB6l',
clientName: 'coffeelike' clientName: 'coffeelike'
}; };