Переделал 'Ваша карта лояльности' и 'Ваши чеки' на icard-proxy
This commit is contained in:
gofnnp 2022-11-08 10:28:10 +04:00
parent 352986de93
commit 5a5acb53fd
11 changed files with 129 additions and 150 deletions

View File

@ -20,6 +20,7 @@
"builder": "@angular-devkit/build-angular:browser", "builder": "@angular-devkit/build-angular:browser",
"options": { "options": {
"outputPath": "/var/www/html/lk.crm4retail.ru/sakura", "outputPath": "/var/www/html/lk.crm4retail.ru/sakura",
"deleteOutputPath": false,
"baseHref": "/", "baseHref": "/",
"index": "src/index.html", "index": "src/index.html",
"main": "src/main.ts", "main": "src/main.ts",
@ -30,11 +31,10 @@
"src/favicon.ico", "src/favicon.ico",
"src/assets", "src/assets",
"src/manifest.webmanifest", "src/manifest.webmanifest",
"src/firebase-messaging-sw.js", "src/firebase-messaging-sw.js"
"src/static"
], ],
"styles": [ "styles": [
"node_modules/primeng/resources/themes/bootstrap4-light-blue/theme.css", "node_modules/primeng/resources/themes/saga-blue/theme.css",
"node_modules/primeicons/primeicons.css", "node_modules/primeicons/primeicons.css",
"node_modules/primeng/resources/primeng.min.css", "node_modules/primeng/resources/primeng.min.css",
"node_modules/ngx-sharebuttons/themes/modern.scss", "node_modules/ngx-sharebuttons/themes/modern.scss",
@ -85,7 +85,8 @@
"browserTarget": "sakura:build:production" "browserTarget": "sakura:build:production"
}, },
"development": { "development": {
"browserTarget": "sakura:build:development" "browserTarget": "sakura:build:development",
"proxyConfig": "proxy.confi.json"
} }
}, },
"defaultConfiguration": "development" "defaultConfiguration": "development"

View File

@ -36,20 +36,20 @@ export const PageListWithBonus: Page[] = [
resName: 'orders', resName: 'orders',
onSideBar: true, onSideBar: true,
}, },
{ // {
code: PageCode.UserData, // code: PageCode.UserData,
name: 'Заполнить анкету', // name: 'Заполнить анкету',
description: '', // description: '',
resName: 'user-data', // resName: 'user-data',
onSideBar: true // onSideBar: true
}, // },
{ // {
code: PageCode.RefSystem, // code: PageCode.RefSystem,
name: 'Пригласить друга', // name: 'Пригласить друга',
description: '', // description: '',
resName: 'ref-system', // resName: 'ref-system',
onSideBar: true, // onSideBar: true,
}, // },
]; ];
export const PageListMain: Page[] = [ export const PageListMain: Page[] = [

View File

@ -32,29 +32,32 @@ export interface UserDataForm {
} }
export interface BonusProgramAccount { export interface BonusProgramAccount {
BonusProgramName: string; // BonusProgramName: string;
BonusProgramTypeID: string; // BonusProgramTypeID: string;
CardNumber: number; CardNumber: number;
Bonuses: number; Bonuses: number;
HoldedBonuses: number; // HoldedBonuses: number;
BonusProgramAccounts: BonusProgramAccount[]; // BonusProgramAccounts: BonusProgramAccount[];
DateBonusBurn: string; // DateBonusBurn: string;
_links: any[]; // _links: any[];
_embedded: any; // _embedded: any;
} }
export interface Purchase { export interface Purchase {
PurchaseId?: string; // PurchaseId?: string;
CustomerId?: string; // CustomerId?: string;
PurchaseDate: string; // PurchaseDate: string;
PurchaseState?: number; // PurchaseState?: number;
CardNumber?: number; // CardNumber?: number;
Address?: string // Address?: string
CheckSummary?: number // CheckSummary?: number
BonusSummary?: number // BonusSummary?: number
ID: string; // ID: string;
Transactions: Transaction[]; // Transactions: Transaction[];
IsSingleTransaction?: boolean; // IsSingleTransaction?: boolean;
transactionCreateDate: string;
orderSum: number;
transactionSum: number;
} }
export interface Transaction { export interface Transaction {

View File

@ -32,7 +32,7 @@
<app-auth [handleHttpError]="handleHttpErrorFunc" (phoneConfirmed)="phoneConfirmed()"></app-auth> <app-auth [handleHttpError]="handleHttpErrorFunc" (phoneConfirmed)="phoneConfirmed()"></app-auth>
</ng-container> </ng-container>
<ng-container *ngSwitchCase="PageCode.Orders"> <ng-container *ngSwitchCase="PageCode.Orders">
<app-orders></app-orders> <app-orders (deauthorization)="changePage(pageList[0])"></app-orders>
</ng-container> </ng-container>
<ng-container *ngSwitchCase="PageCode.BonusProgram"> <ng-container *ngSwitchCase="PageCode.BonusProgram">
<app-bonus-program (deauthorization)="changePage(pageList[0])"></app-bonus-program> <app-bonus-program (deauthorization)="changePage(pageList[0])"></app-bonus-program>

View File

@ -83,11 +83,11 @@ export class AuthComponent {
next: (result) => { next: (result) => {
if (result.code === 0) { if (result.code === 0) {
this.cookiesService.setCookie('token', result?.data?.token); this.cookiesService.setCookie('token', result?.data?.token);
this.router.navigate(['/auth'], { // this.router.navigate(['/auth'], {
queryParams: { // queryParams: {
token: result?.data?.token // token: result?.data?.token
}, // },
}); // });
this.phoneConfirmed.emit(null); this.phoneConfirmed.emit(null);
} else { } else {
this.errorConfirmCode = true; this.errorConfirmCode = true;

View File

@ -10,6 +10,7 @@ import { AppleWalletService } from 'src/app/services/apple-wallet.service';
import { CookiesService } from 'src/app/services/cookies.service'; import { CookiesService } from 'src/app/services/cookies.service';
import { DOCUMENT } from '@angular/common'; import { DOCUMENT } from '@angular/common';
import { HttpClient, HttpHeaders } from '@angular/common/http'; import { HttpClient, HttpHeaders } from '@angular/common/http';
import { WpJsonService } from 'src/app/services/wp-json.service';
@Component({ @Component({
selector: 'app-bonus-program', selector: 'app-bonus-program',
@ -34,94 +35,47 @@ export class BonusProgramComponent implements OnInit {
private cookiesService: CookiesService, private cookiesService: CookiesService,
@Inject(DOCUMENT) private document: Document, @Inject(DOCUMENT) private document: Document,
private http: HttpClient, private http: HttpClient,
private wpJsonService: WpJsonService,
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
this.getAccountData(); this.getAccountData();
this.getTypeDevice() this.getTypeDevice();
} }
getTypeDevice() { getAccountData() {
const userAgent = window.navigator.userAgent.toLowerCase() const token = this.cookiesService.getItem('token')
const ios = /iphone|ipod|ipad/.test( userAgent ); if (!token) {
this.deviceType = ios ? 'ios' : 'android' this.cookiesService.deleteCookie('token')
} this.deauthorization.emit(true)
return
async getAccountData(): Promise<void>{ }
this.loadingBonuses = true; this.loadingBonuses = true;
this.wpJsonService.getCustomerInfo(environment.systemId, token, environment.icardProxy).subscribe({
this.jsonrpc.rpc({
method: 'getAdditionalInfo',
params: []
}, RpcService.authService, true).subscribe({
next: (res) => { next: (res) => {
if (res.code == 334) { this.userName = res.customer_info.name
this.cookiesService.deleteCookie('token') this.accountData = {
this.deauthorization.emit(true) CardNumber: res.customer_info.cards[0].Number,
return Bonuses: res.customer_info.walletBalances[0].balance
} }
this.userName = res.data.first_name barcode("#barcode")
.options({ font: "OCR-B" }) // Will affect all barcodes
.EAN13(`${this.accountData.CardNumber}`.padStart(12, "0"), { fontSize: 18, textMargin: 0 })
.render();
this.loadingBonuses = false;
}, },
error: (err) => { error: (err) => {
console.error('Error: ', err) console.error('Error: ', err)
} }
}); })
}
this.accountData = (await lastValueFrom( getTypeDevice() {
this.jsonrpc.rpc({ const userAgent = window.navigator.userAgent.toLowerCase()
method: 'GetAccounts', const ios = /iphone|ipod|ipad/.test(userAgent);
params: [] this.deviceType = ios ? 'ios' : 'android'
},
RpcService.bonusService
)))['Cards'][0];
this.loadingBonuses = false;
barcode("#barcode")
.options({font: "OCR-B"}) // Will affect all barcodes
.EAN13(`${this.accountData.CardNumber}`.padStart(12, "0"), {fontSize: 18, textMargin: 0})
.render();
const transactions: Transaction[] = (await lastValueFrom(
this.jsonrpc.rpc(
{
method: 'GetAccountTransactions',
params: []
},
RpcService.bonusService
)))['Transactions'];
const purchases: Purchase[] = (await lastValueFrom(
this.jsonrpc.rpc(
{
method: 'GetAccountPurchase',
params: []
},
RpcService.bonusService
)))['Purchases'];
this.purchases = purchases.map<Purchase>((purchase) => {
const id = purchase.ID.slice(0,36).toLowerCase();
purchase.Transactions = transactions.filter((transaction) => {
const same = transaction.Purchase === id;
transaction.HasPurchase = same;
return same;
});
return purchase;
});
transactions.forEach((transaction) => {
if(!transaction.HasPurchase){
this.purchases.push({
ID: transaction.ID,
PurchaseDate: transaction.Date,
Transactions: [transaction],
IsSingleTransaction: true,
})
}
});
this.purchases = this.purchases.sort((a,b) => {
return moment(a.PurchaseDate).date() - moment(b.PurchaseDate).date();
});
} }
@ -146,11 +100,11 @@ export class BonusProgramComponent implements OnInit {
}, },
error: (err) => { error: (err) => {
console.log('Error: ', err); console.log('Error: ', err);
} }
}) })
} }
} }
} }

View File

@ -9,11 +9,11 @@
> >
<span class="nobr">Дата</span> <span class="nobr">Дата</span>
</th> </th>
<th <!-- <th
class="woocommerce-orders-table__header woocommerce-orders-table__header-order-status" class="woocommerce-orders-table__header woocommerce-orders-table__header-order-status"
> >
<span class="nobr">Место покупки</span> <span class="nobr">Место покупки</span>
</th> </th> -->
<th <th
class="woocommerce-orders-table__header woocommerce-orders-table__header-order-total" class="woocommerce-orders-table__header woocommerce-orders-table__header-order-total"
> >
@ -35,33 +35,33 @@
class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-date" class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-date"
data-title="Дата" data-title="Дата"
> >
<time [dateTime]="purchase.PurchaseDate">{{ <time [dateTime]="purchase.transactionCreateDate">{{
moment(purchase.PurchaseDate).format("DD.MM.YYYY") moment(purchase.transactionCreateDate).format("DD.MM.YYYY")
}}</time> }}</time>
</td> </td>
<td <!-- <td
class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-status" class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-status"
data-title="Место покупки" data-title="Место покупки"
> >
{{ purchase.Address }} {{ purchase.Address }}
</td> </td> -->
<td <td
class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-total" class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-total"
data-title="Сумма чека" data-title="Сумма чека"
> >
<span class="woocommerce-Price-amount amount"> <span class="woocommerce-Price-amount amount">
{{ purchase.CheckSummary }} {{ purchase.orderSum }}
</span> </span>
</td> </td>
<td <td
class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-actions" class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-actions"
data-title="Бонусы" data-title="Бонусы"
[ngClass]="{ [ngClass]="{
'red-color': purchase.BonusSummary ? purchase.BonusSummary < 0 : false, 'red-color': purchase.transactionSum ? purchase.transactionSum < 0 : false,
'green-color': purchase.BonusSummary ? purchase.BonusSummary > 0 : false 'green-color': purchase.transactionSum ? purchase.transactionSum > 0 : false
}" }"
> >
{{ purchase.BonusSummary }} {{ purchase.transactionSum }}
</td> </td>
</tr> </tr>
</tbody> </tbody>

View File

@ -1,10 +1,13 @@
import { HttpErrorResponse } from '@angular/common/http'; import { HttpErrorResponse } from '@angular/common/http';
import { Component, Input, OnInit } from '@angular/core'; import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { Purchase } from 'src/app/interface/data'; import { Purchase } from 'src/app/interface/data';
import * as moment from 'moment-timezone'; import * as moment from 'moment-timezone';
import { lastValueFrom } from 'rxjs'; import { lastValueFrom } from 'rxjs';
import { JsonrpcService, RpcService } from 'src/app/services/jsonrpc.service'; import { JsonrpcService, RpcService } from 'src/app/services/jsonrpc.service';
import { WpJsonService } from 'src/app/services/wp-json.service';
import { environment } from 'src/environments/environment';
import { CookiesService } from 'src/app/services/cookies.service';
@Component({ @Component({
selector: 'app-orders', selector: 'app-orders',
@ -13,6 +16,7 @@ import { JsonrpcService, RpcService } from 'src/app/services/jsonrpc.service';
}) })
export class OrdersComponent implements OnInit { export class OrdersComponent implements OnInit {
@Input() handleHttpError!: (error: HttpErrorResponse) => void; @Input() handleHttpError!: (error: HttpErrorResponse) => void;
@Output() deauthorization = new EventEmitter<boolean>(false)
public lastViewOrder: number = 3; public lastViewOrder: number = 3;
public ordersLoadingStatus: boolean = true; public ordersLoadingStatus: boolean = true;
readonly moment = moment; readonly moment = moment;
@ -23,31 +27,34 @@ export class OrdersComponent implements OnInit {
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router, private router: Router,
private jsonrpc: JsonrpcService, private jsonrpc: JsonrpcService,
private wpJsonService: WpJsonService,
private cookiesService: CookiesService,
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
this.getOrders() this.getOrders()
} }
async getOrders(){ async getOrders() {
const purchases: Purchase[] = (await lastValueFrom( const token = this.cookiesService.getItem('token')
this.jsonrpc.rpc( if (!token) {
{ this.cookiesService.deleteCookie('token')
method: 'GetAccountPurchase', this.deauthorization.emit(true)
params: [] return
}, }
RpcService.bonusService const purchases = (await lastValueFrom(
)))['Purchases']; this.wpJsonService.getTransactions(environment.systemId, token, environment.icardProxy, 30)
));
this.purchases = purchases.map<Purchase>((purchase) => { // this.purchases = purchases.map<Purchase>((purchase) => {
const id = purchase.ID.slice(0,36).toLowerCase(); // const id = purchase.ID.slice(0,36).toLowerCase();
// purchase.Transactions = transactions.filter((transaction) => { // // purchase.Transactions = transactions.filter((transaction) => {
// const same = transaction.Purchase === id; // // const same = transaction.Purchase === id;
// transaction.HasPurchase = same; // // transaction.HasPurchase = same;
// return same; // // return same;
// }); // // });
return purchase; // return purchase;
}); // });
this.purchasesShortArray = this.purchases.slice(0, this.lastViewOrder) this.purchasesShortArray = this.purchases.slice(0, this.lastViewOrder)
this.ordersLoadingStatus = false; this.ordersLoadingStatus = false;
} }

View File

@ -17,7 +17,7 @@ export enum Method {
}) })
export class WpJsonService { export class WpJsonService {
protected readonly api = environment.appWPEndpoint; protected readonly api = environment.defaultUrl;
private body!: JsonRpcBody; private body!: JsonRpcBody;
constructor( constructor(
@ -42,8 +42,20 @@ export class WpJsonService {
return this._request(`products/${id}`, 'GET'); return this._request(`products/${id}`, 'GET');
} }
getAllData(): Observable<any> { getAllData(fileName: string): Observable<any> {
return this._request('static/nomen_1eb3fb56-3c4c-43b7-9a04-ce532ab7548f.json', 'GET') return this._request(`/static/${fileName}.json`, 'GET')
}
getTerminalList(): Observable<any> {
return this._request('/static/terminal_list.json', 'GET')
}
getCustomerInfo(systemId: string, token: string, url: string): Observable<any> {
return this._request(`customer_info/${systemId}/${token}/`, 'GET', null, false, url)
}
getTransactions(systemId: string, token: string, url: string, delta: number): Observable<any> {
return this._request(`trans/${systemId}/${token}`, 'GET', null, false, url)
} }
_request(path: string, method: string, body?: any, auth = false, baseUrl?: string): Observable<any> { _request(path: string, method: string, body?: any, auth = false, baseUrl?: string): Observable<any> {

View File

@ -6,7 +6,7 @@ export const environment = {
appBonusEndpoint: 'https://customerapi2.mi.crm4retail.ru/json.rpc/', appBonusEndpoint: 'https://customerapi2.mi.crm4retail.ru/json.rpc/',
appWPEndpoint: 'http://213.239.210.240:4500/wp-json/woofood/v1/', appWPEndpoint: 'http://213.239.210.240:4500/wp-json/woofood/v1/',
hasBonusProgram: true, hasBonusProgram: true,
systemId: 'g6zyv8tj53w28ov7cl', systemId: 'StyrkNFW9vKga1KlJP',
defaultUrl: 'https://sakura.lk.crm4retail.ru', defaultUrl: 'https://sakura.lk.crm4retail.ru',
firebase: { firebase: {
apiKey: "AIzaSyCnKvln5itnrBj62POCPHxshAN_Vmd0zds", apiKey: "AIzaSyCnKvln5itnrBj62POCPHxshAN_Vmd0zds",
@ -21,6 +21,7 @@ export const environment = {
appleWalletEndpoint: 'https://apple-push-notifications.it-retail.tech/apns/api', appleWalletEndpoint: 'https://apple-push-notifications.it-retail.tech/apns/api',
appleWalletSecret: 'Token F5mbzEERAznGKVbB6l', appleWalletSecret: 'Token F5mbzEERAznGKVbB6l',
webhookItRetail: 'https://webhook.it-retail.tech/handlers/tillda/1eb3fb56-3c4c-43b7-9a04-ce532ab7548f', webhookItRetail: 'https://webhook.it-retail.tech/handlers/tillda/1eb3fb56-3c4c-43b7-9a04-ce532ab7548f',
icardProxy: 'https://p1.icard-proxy.crm4retail.ru/',
clientName: 'Sakura', clientName: 'Sakura',
cities: ['Менделеевск'], cities: ['Менделеевск'],
} }

View File

@ -6,7 +6,7 @@ export const environment = {
appBonusEndpoint: 'https://customerapi2.mi.crm4retail.ru/json.rpc/', appBonusEndpoint: 'https://customerapi2.mi.crm4retail.ru/json.rpc/',
appWPEndpoint: './', appWPEndpoint: './',
hasBonusProgram: true, hasBonusProgram: true,
systemId: 'g6zyv8tj53w28ov7cl', systemId: 'StyrkNFW9vKga1KlJP',
defaultUrl: 'http://192.168.0.179:4200', defaultUrl: 'http://192.168.0.179:4200',
firebase: { firebase: {
apiKey: 'AIzaSyCnKvln5itnrBj62POCPHxshAN_Vmd0zds', apiKey: 'AIzaSyCnKvln5itnrBj62POCPHxshAN_Vmd0zds',
@ -21,6 +21,7 @@ export const environment = {
appleWalletEndpoint: 'http://192.168.0.179:4200/apns/api', appleWalletEndpoint: 'http://192.168.0.179:4200/apns/api',
appleWalletSecret: 'Token F5mbzEERAznGKVbB6l', appleWalletSecret: 'Token F5mbzEERAznGKVbB6l',
webhookItRetail: 'https://webhook.it-retail.tech/handlers/tillda/1eb3fb56-3c4c-43b7-9a04-ce532ab7548f', webhookItRetail: 'https://webhook.it-retail.tech/handlers/tillda/1eb3fb56-3c4c-43b7-9a04-ce532ab7548f',
icardProxy: 'http://192.168.0.12:4200/icard-proxy/',
clientName: 'Sakura', clientName: 'Sakura',
cities: ['Менделеевск'], cities: ['Менделеевск'],
}; };