1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* INJI |
4
|
|
|
* |
5
|
|
|
* @author Alexey Krupskiy <[email protected]> |
6
|
|
|
* @link http://inji.ru/ |
7
|
|
|
* @copyright 2017 Alexey Krupskiy |
8
|
|
|
* @license https://github.com/injitools/Inji/blob/master/LICENSE |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Ecommerce\DeliveryProvider; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
class PickPoint extends \Ecommerce\DeliveryProvider { |
15
|
|
|
static $name = 'PickPoint - курьерская служба'; |
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param \Ecommerce\Cart $cart |
|
|
|
|
19
|
|
|
* @return \Money\Sums |
20
|
|
|
*/ |
21
|
|
|
static function curl_get_file_contents($URL, $data) { |
|
|
|
|
22
|
|
|
//var_dump($URL,$data); |
|
|
|
|
23
|
|
|
$xml = json_encode($data); |
24
|
|
|
$headers = array( |
25
|
|
|
"Content-type: text/json", |
26
|
|
|
"Content-length: " . strlen($xml), |
27
|
|
|
"Connection: close", |
28
|
|
|
); |
29
|
|
|
$c = curl_init(); |
30
|
|
|
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); |
31
|
|
|
curl_setopt($c, CURLOPT_URL, $URL); |
32
|
|
|
curl_setopt($c, CURLOPT_POST, 1); |
33
|
|
|
curl_setopt($c, CURLOPT_POSTFIELDS, $xml); |
34
|
|
|
curl_setopt($c, CURLOPT_HTTPHEADER, $headers); |
35
|
|
|
$contents = curl_exec($c); |
36
|
|
|
curl_close($c); |
37
|
|
|
|
38
|
|
|
if ($contents) return $contents; |
39
|
|
|
else return FALSE; |
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
static function deliveryTime($cart) { |
|
|
|
|
43
|
|
|
$result = self::request($cart); |
44
|
|
|
if (!empty($result['Zones'][0])) { |
45
|
|
|
return [ |
46
|
|
|
'min' => $result['Zones'][0]['DeliveryMin'], |
47
|
|
|
'max' => $result['Zones'][0]['DeliveryMax'] |
48
|
|
|
]; |
49
|
|
|
} |
50
|
|
|
return ['min' => 0, 'max' => 0]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/* $result = json_decode(self::curl_get_file_contents('https://e-solution.pickpoint.ru/api/CreateShipment', [ |
|
|
|
|
54
|
|
|
* 'SessionId' => $sessionId, |
55
|
|
|
* 'Sendings' => [[ |
56
|
|
|
* 'IKN' => $config['ikn']->value, |
57
|
|
|
* 'Invoice' => [ |
58
|
|
|
* 'Description' => 'test', |
59
|
|
|
* 'PostamatNumber' => $toId, |
60
|
|
|
* 'MobilePhone' => '+79999999999', |
61
|
|
|
* 'PostageType' => '10003', |
62
|
|
|
* 'GettingType' => '101', |
63
|
|
|
* 'PayType' => 1, |
64
|
|
|
* 'Sum' => '1000' |
65
|
|
|
* ] |
66
|
|
|
* ]], |
67
|
|
|
* ]), true); |
68
|
|
|
* var_dump($result); |
69
|
|
|
* $result = json_decode(self::curl_get_file_contents('https://e-solution.pickpoint.ru/api/calctariff', [ |
70
|
|
|
* 'SessionId' => $sessionId, |
71
|
|
|
* 'FromCity' => $senderCity, |
72
|
|
|
* 'IKN' => $config['ikn']->value, |
73
|
|
|
* 'PTNumber' => $toId, |
74
|
|
|
* 'Length' => 25, |
75
|
|
|
* 'Depth' => 25, |
76
|
|
|
* 'Width' => 25, |
77
|
|
|
* 'Weight' => 0.5, |
78
|
|
|
* ]), true); |
79
|
|
|
* |
80
|
|
|
* $summ = 0; |
81
|
|
|
* var_dump($result['Services']); |
82
|
|
|
* foreach ($result['Services'] as $service) { |
83
|
|
|
* $summ = $service['Tariff'] + $service['NDS']; |
84
|
|
|
* } |
85
|
|
|
* //$result = json_decode(self::curl_get_file_contents('https://e-solution.pickpoint.ru/api/cancelInvoice', ['SessionId' => $sessionId, 'InvoiceNumber' => '15938160323']), true); |
86
|
|
|
*/ |
87
|
|
|
static function request($cart) { |
|
|
|
|
88
|
|
|
$config = self::config(); |
89
|
|
|
$sessionId = \Cache::get('PickPointSession', [ |
90
|
|
|
'Login' => $config['login'], |
91
|
|
|
'Password' => $config['pass'], |
92
|
|
|
], function ($data) { |
93
|
|
|
$result = self::curl_get_file_contents('https://e-solution.pickpoint.ru/api/login', $data); |
94
|
|
|
return json_decode($result, true)['SessionId']; |
95
|
|
|
}, 12 * 60 * 60); |
96
|
|
|
$toId = ''; |
97
|
|
View Code Duplication |
foreach ($cart->delivery->fields as $field) { |
|
|
|
|
98
|
|
|
if ($field->code === 'pickpoint') { |
99
|
|
|
if (!empty($_POST['deliveryFields'][$field->id]) && is_string($_POST['deliveryFields'][$field->id])) { |
100
|
|
|
$toId = $_POST['deliveryFields'][$field->id]; |
101
|
|
|
} elseif (isset($cart->deliveryInfos[$field->id])) { |
102
|
|
|
$toId = $cart->deliveryInfos[$field->id]->value; |
103
|
|
|
} |
104
|
|
|
break; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
if (!$toId) { |
109
|
|
|
$fieldInfo = \Ecommerce\UserAdds\Field::get('deliveryfield_city', 'code'); |
110
|
|
|
$field = \Ecommerce\Delivery\Field::get('city', 'code'); |
111
|
|
|
if (isset($cart->infos[$fieldInfo->id])) { |
112
|
|
|
$item = \Ecommerce\Delivery\Field\Item::get([['id', $cart->infos[$fieldInfo->id]->value], ['delivery_field_id', $field->id]]); |
113
|
|
|
if ($item) { |
114
|
|
|
$data = json_decode($item->data, true); |
115
|
|
|
if (!empty($data['PostCodeList'])) { |
116
|
|
|
$post = explode(',', $data['PostCodeList'])[0]; |
117
|
|
|
$result = json_decode(self::curl_get_file_contents('https://e-solution.pickpoint.ru/api/postindexpostamatlist', ['PostIndex' => $post]), true); |
118
|
|
|
if (!empty($result['PostamatList'][0]['CitiName'])) { |
119
|
|
|
$toId = $result['PostamatList'][0]['Number']; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
if (!$toId) { |
127
|
|
|
return false; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
$senderCity = 'Москва'; |
131
|
|
|
|
132
|
|
|
return \Cache::get('pickPointCalc', [ |
133
|
|
|
'SessionId' => $sessionId, |
134
|
|
|
'IKN' => $config['ikn'], |
135
|
|
|
'FromCity' => $senderCity, |
136
|
|
|
'ToPT' => $toId, |
137
|
|
|
], function ($data) { |
138
|
|
|
return json_decode(self::curl_get_file_contents('https://e-solution.pickpoint.ru/api/getzone', $data), true); |
139
|
|
|
}); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param \Ecommerce\Cart $cart |
144
|
|
|
* @return \Money\Sums |
145
|
|
|
*/ |
146
|
|
|
static function calcPrice($cart) { |
|
|
|
|
147
|
|
|
$result = self::request($cart); |
148
|
|
|
if (!$result) { |
149
|
|
|
return new \Money\Sums([$cart->delivery->currency_id => 0]); |
150
|
|
|
} |
151
|
|
|
$zones = [ |
152
|
|
|
0 => 270, |
153
|
|
|
1 => 292, |
154
|
|
|
2 => 299, |
155
|
|
|
3 => 315, |
156
|
|
|
4 => 328, |
157
|
|
|
5 => 368, |
158
|
|
|
6 => 443, |
159
|
|
|
7 => 466, |
160
|
|
|
8 => 527, |
161
|
|
|
]; |
162
|
|
|
return new \Money\Sums([ |
163
|
|
|
$cart->delivery->currency_id => round($zones[$result['Zones'][0]['Zone']] * $result['Zones'][0]['Koeff'] * 1.1, 2) |
164
|
|
|
]); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
static function availablePayTypeGroups($cart) { |
|
|
|
|
168
|
|
|
return ['online']; |
169
|
|
|
} |
170
|
|
|
} |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.