-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmarketplaceMethods.js
150 lines (132 loc) · 4.76 KB
/
marketplaceMethods.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
function createFullEpObjFromOrder(obj)
{
let commentary = `!auto! Ep ${obj.comment}`;
const statusOfPayment = obj.address.shipment.paymentStatus;
if(statusOfPayment=='hold_set')
commentary+='$Кабинет эпицентра!';
const shipmentMethod = obj.address.shipment.provider;
const direction= obj.office.title;
let typeMail;
let ukrMail={WarehouseNumber: ''};
let novaMail={WarehouseNumber: '', city: ''};
if(shipmentMethod=='nova_poshta')
{
typeMail='id_9';
novaMail.WarehouseNumber = direction.substring(direction.indexOf('№')+2, direction.indexOf(','));
novaMail.city= obj.settlement.title;
}else{
typeMail='id_17';
ukrMail.WarehouseNumber=direction.substring(direction.indexOf('№')+2, direction.indexOf(','));
}
const products =[];
obj.items.forEach(item=>{
products.push({id: item.sku, costPerItem: item.price, amount: item.quantity})
});
return {
getResultData: '1',
products: products,
comment: commentary,
externalId: obj.number,
fName: obj.address.firstName,
lName: obj.address.lastName,
mName: obj.address?.patronymic || '',
phone: obj.address.phone,
email: obj.address?.email || '',
shipping_address: direction,
shipping_method: typeMail,
payment_method: "id_14",
novaposhta: novaMail,
ukrposhta: ukrMail,
sajt: "inbasket.com.ua",
salesdrive_manager: '3'
};
}
export class MarketplaceMethods{
createObjWithoutUserData(obj)
{
let commentary = `*auto* Ep ${obj.comment}`;
const shipmentMethod = obj.address.shipment.provider;
const direction= obj.office.title;
let typeMail;
let ukrMail={WarehouseNumber: ''};
let novaMail={WarehouseNumber: '', city: ''};
if(shipmentMethod=='nova_poshta')
{
typeMail='id_9';
novaMail.WarehouseNumber = direction.substring(direction.indexOf('№')+2, direction.indexOf(','));
novaMail.city= obj.settlement.title;
}else{
typeMail='id_17';
ukrMail.WarehouseNumber=direction.substring(direction.indexOf('№')+2, direction.indexOf(','));
}
const products =[];
obj.items.forEach(item=>{
products.push({id: item.sku, costPerItem: item.price, amount: item.quantity})
});
return {
getResultData: '1',
products: products,
comment: commentary,
externalId: obj.number,
shipping_address: direction,
shipping_method: typeMail,
payment_method: "id_14",
novaposhta: novaMail,
ukrposhta: ukrMail,
sajt: "inbasket.com.ua",
prodex24content: obj.id
}
}
createClientDataObj(obj)
{
let commentary = `*Ep* ${obj.comment}`;
const statusOfPayment = obj.address.shipment.paymentStatus;
switch (statusOfPayment) {
case 'hold_set':
commentary+='\n$Кабинет эпицентра!'
break;
case 'payment_waiting':
commentary=`easypay ${commentary}`;
break;
}
return {
getResultData: '1',
data:{
fName: obj.address.firstName,
lName: obj.address.lastName,
mName: obj.address?.patronymic || '',
phone: obj.address.phone,
email: obj.address?.email || '',
comment: commentary
}
};
}
comparisonObjects(salesObj, epObj)
{
const comprasion ={isSamePhone:true, isSameDelivery: true}
if(salesObj.data.contacts[0].phone[0] !== epObj.address.phone)
comprasion.isSamePhone=false;
const typeMail = salesObj.data.ord_delivery == 'novaposhta' ? 'nova_poshta' : salesObj.data.ord_delivery;
if(typeMail !== epObj.address.shipment.provider)
comprasion.isSameDelivery=false;
return comprasion;
}
differenceBTWCreateTime(crTime)
{
const realTime = GetOurDateTime();
const difference = 11100000 - (new Date(realTime) - new Date(crTime));
if(difference>0)
return difference;
else
return 5000;
}
}
export function GetOurDateTime()
{
const date = new Date();
const UATime = date.toLocaleString("ru-RU", {timeZone: "Europe/Kyiv"});
const arrs = UATime.split(',');
let result=arrs[1];
result=`${arrs[0].split('.').reverse().join('-')}${result}`;
return result;
}