dev #14494 WPA CoffeeLike изменить апи для получения последней транзакции
This commit is contained in:
parent
a8062667df
commit
eef97fd35f
@ -7,9 +7,9 @@ import { Purchase } from 'src/app/interface/data';
|
||||
styleUrls: ['./last-order.component.scss']
|
||||
})
|
||||
export class LastOrderComponent implements OnInit {
|
||||
@Input() lastOrder!: Purchase;
|
||||
@Input() lastOrder?: Purchase;
|
||||
@Input() loading!: boolean;
|
||||
|
||||
|
||||
constructor() { }
|
||||
|
||||
ngOnInit(): void {
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
Осталось купить на сумму
|
||||
<span class="price">{{
|
||||
loyaltyProgram.currentLvlPeriod.end -
|
||||
(loyaltyProgram.purchaseData.currentAmount || 0) +
|
||||
(customerInfo.OrdersSum) +
|
||||
1
|
||||
}}</span>
|
||||
рублей, тогда кэшбек будет
|
||||
@ -55,37 +55,8 @@
|
||||
</p>
|
||||
</div>
|
||||
<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
|
||||
[lastOrder]="lastPurchase"
|
||||
[lastOrder]="loyaltyProgram.purchaseData.lastPurchase"
|
||||
[loading]="loyaltyProgram.purchaseData.$loading"
|
||||
></app-last-order>
|
||||
<a class="guest-card__loyalty-program" routerLink="loyality-program"
|
||||
|
||||
@ -21,8 +21,6 @@ export class GuestCardComponent implements OnInit {
|
||||
public qrCodeSize: number = 85;
|
||||
private isQrCodeClicked: boolean = false;
|
||||
public customerInfo!: any;
|
||||
public purchases!: Purchase[];
|
||||
public lastPurchase!: Purchase;
|
||||
public Math: Math = Math;
|
||||
|
||||
constructor(
|
||||
@ -52,18 +50,12 @@ export class GuestCardComponent implements OnInit {
|
||||
this.customerInfo = value.customer_info;
|
||||
|
||||
this.cookiesService.setCookie('phone-number', this.customerInfo?.phone?.substr(2))
|
||||
this.getPurchases().subscribe((value) => {
|
||||
this.purchases = this.loyaltyProgram.filterPurchases(value[this.customerInfo?.id])
|
||||
this.lastPurchase = this.loyaltyProgram.getLastPurchase(this.purchases)
|
||||
this.loyaltyProgram.setCurrentLvl(this.customerInfo.OrdersSum);
|
||||
|
||||
this.loyaltyProgram.setLastPurchases(this.purchases)
|
||||
this.loyaltyProgram.setCurrentPurchases(this.purchases)
|
||||
|
||||
const currentAmount = this.loyaltyProgram.purchaseData.currentAmount || 0
|
||||
this.loyaltyProgram.setCurrentLvl(currentAmount)
|
||||
|
||||
this.loyaltyProgram.purchaseData.$loading = false;
|
||||
});
|
||||
this.loyaltyProgram.getLastPurchase(
|
||||
environment.systemId,
|
||||
token || '',
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2,15 +2,15 @@ import { Injectable } from '@angular/core';
|
||||
import moment from 'moment';
|
||||
import { Moment, Purchase, lvlPeriod } from '../interface/data';
|
||||
import { lvlPeriods } from '../app.constants';
|
||||
import { WpJsonService } from './wp-json.service';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
export interface IPurchaseData {
|
||||
currentPeriod: Moment[];
|
||||
lastPeriod: Moment[];
|
||||
lastPurchases: Purchase[];
|
||||
currentPurchases: Purchase[];
|
||||
lastAmount?: number;
|
||||
currentAmount?: number;
|
||||
$loading: boolean;
|
||||
lastPurchase?: Purchase;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
@ -19,59 +19,18 @@ export interface IPurchaseData {
|
||||
export class LoyaltyProgramService {
|
||||
public purchaseData: IPurchaseData = {
|
||||
currentPeriod: [],
|
||||
lastPeriod: [],
|
||||
lastPurchases: [],
|
||||
currentPurchases: [],
|
||||
lastPeriod: [],
|
||||
$loading: false,
|
||||
get currentAmount(): number {
|
||||
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;
|
||||
},
|
||||
lastPurchase: undefined,
|
||||
};
|
||||
|
||||
public currentLvl: number = 1;
|
||||
public currentLvlPeriod!: lvlPeriod;
|
||||
public lvlPeriods: lvlPeriod[] = lvlPeriods;
|
||||
public lvlPeriods: lvlPeriod[] = lvlPeriods;
|
||||
|
||||
constructor() {
|
||||
constructor(
|
||||
private wpJsonService: WpJsonService,
|
||||
) {
|
||||
this.getCurrentQuarterOfYear();
|
||||
}
|
||||
|
||||
@ -116,43 +75,6 @@ export class LoyaltyProgramService {
|
||||
}, 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) {
|
||||
const index = this.lvlPeriods.findIndex(
|
||||
(item) =>
|
||||
@ -170,4 +92,16 @@ export class LoyaltyProgramService {
|
||||
}
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {environment} from "../../environments/environment";
|
||||
import {HttpClient, HttpHeaders} from "@angular/common/http";
|
||||
import {CookiesService} from "./cookies.service";
|
||||
import {Observable, of, switchMap} from "rxjs";
|
||||
import {JsonRpcBody} from "./jsonrpc.service";
|
||||
import {DeliveryType, AcceptedOrder, Product} from "../interface/data";
|
||||
import {ActivatedRoute} from "@angular/router";
|
||||
import {Order} from "../models/order";
|
||||
import { environment } from "../../environments/environment";
|
||||
import { HttpClient, HttpHeaders } from "@angular/common/http";
|
||||
import { CookiesService } from "./cookies.service";
|
||||
import { Observable, of, switchMap } from "rxjs";
|
||||
import { JsonRpcBody } from "./jsonrpc.service";
|
||||
import { DeliveryType, AcceptedOrder, Product, Purchase } from "../interface/data";
|
||||
import { ActivatedRoute } from "@angular/router";
|
||||
|
||||
export enum Method {
|
||||
|
||||
@ -26,26 +25,26 @@ export class WpJsonService {
|
||||
private route: ActivatedRoute,
|
||||
) { }
|
||||
|
||||
getDeliveryTypes(): Observable<DeliveryType[]>{
|
||||
getDeliveryTypes(): Observable<DeliveryType[]> {
|
||||
return this._request('orders/delivery-types', 'GET');
|
||||
}
|
||||
|
||||
createOrder(order: any){
|
||||
createOrder(order: any) {
|
||||
return this._request('orders', 'POST', order);
|
||||
}
|
||||
|
||||
getOrders(): Observable<AcceptedOrder[]>{
|
||||
getOrders(): Observable<AcceptedOrder[]> {
|
||||
return this._request('orders', 'GET', null, true);
|
||||
}
|
||||
|
||||
getProductById(id: number): Observable<Product>{
|
||||
getProductById(id: number): Observable<Product> {
|
||||
return this._request(`products/${id}`, 'GET');
|
||||
}
|
||||
|
||||
getCustomerInfo(systemId: string, token: string, url: string): Observable<any> {
|
||||
return this._request(`customer_info/${systemId}/${token}/`, 'GET', null, false, url).pipe(
|
||||
switchMap((response) => {
|
||||
// TODO: typescript compile optional chaining ('response?.customer_info?.errorCode') without check ('response.customer_info.errorCode')
|
||||
// TODO: typescript compile optional chaining ('response?.customer_info?.errorCode') without check ('response.customer_info.errorCode')
|
||||
if (response && response.customer_info && response.customer_info.errorCode !== 'Customer_CustomerNotFound') {
|
||||
return of(response)
|
||||
} else {
|
||||
@ -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> {
|
||||
return this._request(`new_customer/${systemId}/${token}/`, 'GET', null, false, url)
|
||||
}
|
||||
@ -83,7 +86,7 @@ export class WpJsonService {
|
||||
headers = headers.set('Content-Type', 'application/json');
|
||||
let urlToken = '';
|
||||
if (token && token !== 'undefined' && auth) {
|
||||
urlToken = '?token=' + token;
|
||||
urlToken = '?token=' + token;
|
||||
}
|
||||
this.body = body;
|
||||
const options = {
|
||||
@ -96,6 +99,6 @@ export class WpJsonService {
|
||||
url = baseUrl
|
||||
}
|
||||
return this.http
|
||||
.request( method, url + path + urlToken, options);
|
||||
.request(method, url + path + urlToken, options);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ export const environment = {
|
||||
},
|
||||
version: packageJson.version,
|
||||
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',
|
||||
clientName: 'coffeelike'
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user