parent
e1fef25690
commit
e67d7e70c2
@ -30,6 +30,8 @@ import { DropdownModule } from 'primeng/dropdown';
|
||||
import { ChipsModule } from 'primeng/chips';
|
||||
import { ButtonModule } from 'primeng/button';
|
||||
import {MultiSelectModule} from 'primeng/multiselect';
|
||||
import { PaymentTypePipe } from './pipes/payment-type.pipe';
|
||||
import { PaymentStatusPipe } from './pipes/payment-status.pipe';
|
||||
|
||||
const routes = [
|
||||
{ path: 'clients', component: ClientsComponent },
|
||||
@ -52,7 +54,9 @@ const routes = [
|
||||
DivisionsComponent,
|
||||
AreasComponent,
|
||||
MenuComponent,
|
||||
ExitComponentComponent
|
||||
ExitComponentComponent,
|
||||
PaymentTypePipe,
|
||||
PaymentStatusPipe
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
|
||||
@ -147,14 +147,20 @@
|
||||
<p-table [value]="order[0].payment">
|
||||
<ng-template pTemplate="header">
|
||||
<tr>
|
||||
<th width="50%">Сумма оплаты по безналу:</th>
|
||||
<th width="50%">Тип оплаты:</th>
|
||||
<th>Сумма оплаты</th>
|
||||
<th>Тип оплаты</th>
|
||||
<th *ngIf="order[0].payment[0]?.type !== 'CASH'">Статус оплаты</th>
|
||||
<th *ngIf="['PAID', 'NOTIFIED', 'INTERNAL_ERROR', 'PROCESSING'].includes(order[0].payment[0]?.payload?.status || '') && order[0].payment[0]?.type !== 'CASH'">Отмена заказа</th>
|
||||
</tr>
|
||||
</ng-template>
|
||||
<ng-template pTemplate="body" let-pay>
|
||||
<tr>
|
||||
<td>{{pay.summ}}</td>
|
||||
<td>{{pay.type}}</td>
|
||||
<td>{{pay.type | paymentType}}</td>
|
||||
<td *ngIf="pay.type !== 'CASH'">{{pay.payload.status | paymentStatus}}</td>
|
||||
<td *ngIf="['PAID', 'NOTIFIED', 'INTERNAL_ERROR', 'PROCESSING'].includes(order[0].payment[0]?.payload?.status || '') && order[0].payment[0]?.type !== 'CASH'">
|
||||
<button (click)="cancelOrder(pay.payload?.id)">Отменить</button>
|
||||
</td>
|
||||
</tr>
|
||||
</ng-template>
|
||||
</p-table>
|
||||
|
||||
@ -18,7 +18,8 @@ import {
|
||||
SelectItem,
|
||||
} from 'primeng/api';
|
||||
import { OrderTypes } from 'src/app/data/data';
|
||||
import { catchError, map } from 'rxjs';
|
||||
import { catchError, forkJoin, map } from 'rxjs';
|
||||
import { environment } from 'src/environments/environment';
|
||||
/*import { SwPush, NewsletterService } from '@angular/service-worker*/
|
||||
|
||||
@Component({
|
||||
@ -265,7 +266,7 @@ export class OrdersComponent implements OnInit {
|
||||
|
||||
async vievOrder(id: any) {
|
||||
this.dis = false;
|
||||
await this.jsonRpcService
|
||||
this.jsonRpcService
|
||||
.rpc2(
|
||||
{
|
||||
method: 'getOrders',
|
||||
@ -279,6 +280,7 @@ export class OrdersComponent implements OnInit {
|
||||
let data = result.result;
|
||||
this.order = data;
|
||||
this.selectedStatus = this.order[0].status_h
|
||||
this.getPaymentData();
|
||||
},
|
||||
error: (err) => {
|
||||
console.log('ERROR: ', err);
|
||||
@ -292,6 +294,114 @@ export class OrdersComponent implements OnInit {
|
||||
setTimeout(() => this.getOrderRefunds(this.order[0].external_id), 400);
|
||||
}
|
||||
|
||||
getPaymentData() {
|
||||
forkJoin([
|
||||
this.jsonRpcService.rpc2(
|
||||
{
|
||||
method: 'getPaymentData',
|
||||
params: {
|
||||
system_id: environment.systemId,
|
||||
order_id: String(this.order[0].external_id),
|
||||
},
|
||||
},
|
||||
RpcService.authService,
|
||||
false,
|
||||
location.origin
|
||||
),
|
||||
this.jsonRpcService.rpc2(
|
||||
{
|
||||
method: 'getPaymentStatus',
|
||||
params: {
|
||||
system_id: environment.systemId,
|
||||
order_id: String(this.order[0].external_id),
|
||||
},
|
||||
},
|
||||
RpcService.authService,
|
||||
false,
|
||||
location.origin
|
||||
),
|
||||
]).subscribe({
|
||||
next: ([paymentData, paymentStatus]) => {
|
||||
const payment_request = paymentData.result.payment_request;
|
||||
this.order[0].payment.push({
|
||||
summ: payment_request.amount,
|
||||
type: payment_request.type,
|
||||
payload: {
|
||||
id: payment_request.id,
|
||||
status: paymentStatus.result.status,
|
||||
},
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.log('ERROR: ', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Произошла ошибка!',
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
cancelOrder(payment_request_id: string) {
|
||||
this.jsonRpcService
|
||||
.rpc2(
|
||||
{
|
||||
method: 'cancelPayment',
|
||||
params: {
|
||||
payment_request_id,
|
||||
system_id: environment.systemId,
|
||||
},
|
||||
},
|
||||
RpcService.authService,
|
||||
false,
|
||||
location.origin
|
||||
)
|
||||
.subscribe({
|
||||
next: (value) => {
|
||||
this.changeOrderStatus(this.order[0].id, 'cancel');
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Заказ отменен успешно!',
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.log('ERROR: ', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Произошла ошибка!',
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
changeOrderStatus(orderId: number, status: string) {
|
||||
this.jsonRpcService
|
||||
.rpc2(
|
||||
{
|
||||
method: 'changeOrderStatusForOperator',
|
||||
params: [Number(this.choose), Number(orderId), status],
|
||||
},
|
||||
RpcService.authService,
|
||||
false
|
||||
)
|
||||
.subscribe({
|
||||
next: (value) => {
|
||||
this.order[0].status = status;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Статус заказа успешно изменён!',
|
||||
});
|
||||
},
|
||||
error: (err) => {
|
||||
console.log('ERROR: ', err);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Произошла ошибка!',
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async getOrderRefunds(id: any) {
|
||||
await this.jsonRpcService
|
||||
.rpc2(
|
||||
|
||||
22
src/app/pipes/payment-status.pipe.ts
Normal file
22
src/app/pipes/payment-status.pipe.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'paymentStatus'
|
||||
})
|
||||
export class PaymentStatusPipe implements PipeTransform {
|
||||
private statuses = {
|
||||
NEW: 'Новый',
|
||||
CREATED: 'Новый',
|
||||
CANCELED: 'Отменен',
|
||||
OVERDUE: 'Отменен',
|
||||
PAID: 'Оплачено',
|
||||
NOTIFIED: 'Оплачено',
|
||||
INTERNAL_ERROR: 'Ошибка',
|
||||
PROCESSING: 'В процессе',
|
||||
}
|
||||
|
||||
transform(value: string, ...args: unknown[]): unknown {
|
||||
return this.statuses[value as keyof typeof this.statuses] || value;
|
||||
}
|
||||
|
||||
}
|
||||
18
src/app/pipes/payment-type.pipe.ts
Normal file
18
src/app/pipes/payment-type.pipe.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'paymentType'
|
||||
})
|
||||
export class PaymentTypePipe implements PipeTransform {
|
||||
|
||||
private types = {
|
||||
CASH: 'Наличные',
|
||||
CARD: 'Карта',
|
||||
SBP: 'СБП'
|
||||
}
|
||||
|
||||
transform(value: unknown, ...args: unknown[]): unknown {
|
||||
return this.types[value as keyof typeof this.types] || value;
|
||||
}
|
||||
|
||||
}
|
||||
@ -64,7 +64,7 @@ export class JsonrpcService {
|
||||
}
|
||||
}
|
||||
|
||||
rpc2(data: { method: string, params: any }, service: RpcService, auth = false): Observable<any> {
|
||||
rpc2(data: { method: string, params: any }, service: RpcService, auth = false, url: string = ''): Observable<any> {
|
||||
let headers = new HttpHeaders();
|
||||
const token = decodeURI(this.cookiesService.getItem('token') ?? '');
|
||||
|
||||
@ -78,11 +78,11 @@ export class JsonrpcService {
|
||||
id: uuidv4(),
|
||||
jsonrpc: this.jsonrpc,
|
||||
method: data.method,
|
||||
params: { ...data.params },
|
||||
params: data.params,
|
||||
};
|
||||
try {
|
||||
return this.http
|
||||
.post(environment.appSelfDeliveryEndPoint, this.body, options)
|
||||
.post(url.length ? (url + "/api/payment") : (location.origin + "/api"), this.body, options)
|
||||
.pipe(map((res: any) => res));
|
||||
} catch (error) {
|
||||
return new Observable()
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
export const environment = {
|
||||
production: true,
|
||||
appSelfDeliveryEndPoint: 'http://selfdelivery-pitsburg.mydatahosting.ru/admin_api',
|
||||
systemId: 'dfe16ca16a3598b812',
|
||||
systemId: 'd0b89b219e1feb3d7',
|
||||
};
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
export const environment = {
|
||||
production: false,
|
||||
appSelfDeliveryEndPoint: 'http://localhost:4200/api',
|
||||
systemId: 'dfe16ca16a3598b812',
|
||||
systemId: 'd0b89b219e1feb3d7',
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user