1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
handler.php
См. документацию.
1<?php
2
3namespace Sale\Handlers\PaySystem;
4
5use Bitrix\Main\Localization\Loc;
6use Bitrix\Main\Request;
7use Bitrix\Sale\PaySystem;
8use Bitrix\Sale\Payment;
9
10Loc::loadMessages(__FILE__);
11
15class CashOnDeliveryCalcHandler extends PaySystem\BaseServiceHandler implements PaySystem\IPayable
16{
22 public function initiatePay(Payment $payment, Request $request = null)
23 {
24 return new PaySystem\ServiceResult();
25 }
26
30 public function getCurrencyList()
31 {
32 return array('RUB');
33 }
34
39 public function getPrice(Payment $payment)
40 {
41 $result = 0;
42
44 $collection = $payment->getCollection();
45
47 $order = $collection->getOrder();
48
50 $propertyCollection = $order->getPropertyCollection();
51
53 $delivery = $propertyCollection->getDeliveryLocation();
54
55 if (!$delivery)
56 return $result;
57
58 $location = \CSaleLocation::GetByID($delivery->getValue());
59
60 $regId = $location['REGION_ID'] ?? 0;
61
62 $params = $this->service->getField('TARIF');
63
64 $tarifs = self::extractFromField($params);
65 $tarifs = isset($tarifs[$regId]) ? $tarifs[$regId] : $tarifs[0];
66
67 $fullPrice = $payment->getSum();
68
69 if ($fullPrice <= 1000)
70 $tariffNum = "0";
71 elseif ($fullPrice <= 5000)
72 $tariffNum = "1";
73 elseif ($fullPrice <= 20000)
74 $tariffNum = "2";
75 elseif ($fullPrice <= 500000)
76 $tariffNum = "3";
77
78 if (isset($tariffNum) && isset($tarifs["TARIFS"][$tariffNum]))
79 {
80 $percent = 0;
81 if ($tarifs["TARIFS"][$tariffNum]["UPPER_SUMM"] < $payment->getSum())
82 $percent = floatval($tarifs["TARIFS"][$tariffNum]["PERCENT"]) * floatval($payment->getSum()) / 100;
83 $result = floatval($tarifs["TARIFS"][$tariffNum]["FIX"]) + $percent;
84 }
85
86 return round($result, 2);
87 }
88
93 private static function extractFromField($params)
94 {
95 $result = array();
96 $tarifs = unserialize($params, ['allowed_classes' => false]);
97
98 if (!is_array($tarifs))
99 $tarifs = array();
100
101 $arRegIds = array_keys($tarifs);
102 $regNames = @\CSaleLocation::GetRegionsNamesByIds($arRegIds);
103
104 $csvTariffs = [];
105 if (isset($tarifs[0]))
106 {
107 $csvTariffs = self::getTariffArrayCSV($tarifs[0]);
108 }
109
110 $result[] = array(
111 'TARIFS' => $csvTariffs,
112 'REG_NAME' => Loc::getMessage('SALE_HPS_CASH_ON_DELIVERY_TARIF_DEFAULT')
113 );
114
115 foreach ($regNames as $regId => $regName)
116 {
117 if (in_array($regId, $arRegIds))
118 {
119 $result[$regId]["TARIFS"] = self::getTariffArrayCSV($tarifs[$regId]);
120 $result[$regId]["REG_NAME"] = $regName;
121 }
122 }
123
124 return $result;
125 }
126
131 private static function getTariffArrayCSV($tarifs)
132 {
133 $result = array();
134
135 if(is_array($tarifs) && count($tarifs) == 12)
136 {
137 for($i = 0; $i < 4; $i++)
138 {
139 $result[] = array(
140 "FIX" => $tarifs[$i*3],
141 "PERCENT" => $tarifs[$i*3+1],
142 "UPPER_SUMM" => $tarifs[$i*3+2]
143 );
144 }
145 }
146
147 return $result;
148 }
149
154 public static function getValues($paySystemId = 0)
155 {
156 $result = array();
157
158 if($paySystemId > 0)
159 {
160 $data = PaySystem\Manager::getById($paySystemId);
161 $result = self::extractFromField($data['TARIF']);
162 }
163
164 if (!$result)
165 {
166 $result = \CSaleHelper::getOptionOrImportValues(
167 'ps_payment_forward_calc_tarifs',
168 array(get_called_class(), 'getAllCMTarifsFromCsv')
169 );
170 }
171
172 return $result;
173 }
174
179 public static function prepareToField($tariff)
180 {
181 $arResult = array();
182
183 if (is_array($tariff))
184 {
185 foreach ($tariff as $id => $value)
186 {
187 if($id == "REG_NEW")
188 {
189 if ((int)$value > 0)
190 {
191 for ($i = 0; $i < 12; ++$i)
192 $arResult[$value][] = 0;
193 }
194 continue;
195 }
196 $tariffIds = explode('_', $id);
197
198 if (isset($tariffIds[2]))
199 {
200 $regionId = $tariffIds[2];
201
202 $arResult[$regionId][] = $value;
203 }
204 }
205 }
206 return serialize($arResult);
207 }
208
213 public static function getStructure($paySystemId = 0)
214 {
215 $arResult = array();
216
217 $arCmTarifs = self::getValues($paySystemId);
218
219 foreach ($arCmTarifs as $regionId => $arRegInfo)
220 {
221
222 $arResult[$regionId.'REG_ID'] = array(
223 'TYPE' => 'TEXT_CENTERED',
224 'TITLE' => $arRegInfo["REG_NAME"],
225 'BLOCK_HIDEABLE' => 'Y',
226 'BLOCK_LENGTH' => 4,
227 );
228
229 if($regionId != 0)
230 $arResult[$regionId.'REG_ID']['BLOCK_DELETABLE'] = 'Y';
231
232 self::setTariffConfig('TARIF_1_'.$regionId, Loc::getMessage('SALE_HPS_CASH_ON_DELIVERY_LESS_1K'), $arRegInfo["TARIFS"][0], $arResult);
233 self::setTariffConfig('TARIF_2_'.$regionId, Loc::getMessage('SALE_HPS_CASH_ON_DELIVERY_LESS_5K'), $arRegInfo["TARIFS"][1], $arResult);
234 self::setTariffConfig('TARIF_3_'.$regionId, Loc::getMessage('SALE_HPS_CASH_ON_DELIVERY_LESS_20K'), $arRegInfo["TARIFS"][2], $arResult);
235 self::setTariffConfig('TARIF_4_'.$regionId, Loc::getMessage('SALE_HPS_CASH_ON_DELIVERY_LESS_500K'), $arRegInfo["TARIFS"][3], $arResult);
236 }
237
238 $arResult['REG_NEW'] = array(
239 'TYPE' => 'DROPDOWN',
240 'TITLE' => Loc::getMessage('SALE_HPS_CASH_ON_DELIVERY_ADD_REGION'),
241 'VALUES' => self::getRegionsList(),
242 'ONCHANGE' => "document.forms['pay_sys_form'].elements['apply'].click();"
243 );
244
245 return $arResult;
246 }
247
254 private static function setTariffConfig($tariffId, $tariffTitle, $arTarifs, &$arConfig)
255 {
256 $arConfig[$tariffId.'_NAME'] = array('TYPE' => 'MULTI_CONTROL_STRING', 'MCS_ID' => $tariffId, 'TITLE' => $tariffTitle);
257 $arConfig[$tariffId.'_FIX'] = array('TYPE' => 'STRING', 'MCS_ID' => $tariffId, 'POST_TEXT' => Loc::getMessage('SALE_HPS_CASH_ON_DELIVERY_RUB'), 'SIZE' => 4, 'VALUE' => $arTarifs['FIX']);
258 $arConfig[$tariffId.'_PERCENT'] = array('TYPE' => 'STRING', 'MCS_ID' => $tariffId, 'PRE_TEXT' => ' + ', 'POST_TEXT' => ' % ', 'SIZE' => 3, 'VALUE' => $arTarifs['PERCENT']);
259 $arConfig[$tariffId.'_UPPER_SUMM'] = array('TYPE' => 'STRING', 'MCS_ID' => $tariffId, 'PRE_TEXT' => Loc::getMessage('SALE_HPS_CASH_ON_DELIVERY_SUMM_MORE'), 'POST_TEXT' => Loc::getMessage('SALE_HPS_CASH_ON_DELIVERY_RUB'), 'SIZE' => 7, 'VALUE' => $arTarifs['UPPER_SUMM']);
260 }
261
262 private static function getRegionsList()
263 {
264 $result = array(0 => Loc::getMessage('SALE_HPS_CASH_ON_DELIVERY_CHOOSE_REGION'));
265
267 $dbRes = \CSaleLocation::GetRegionList();
268 while ($region = $dbRes->Fetch())
269 $result[$region["ID"]] = $region["NAME"];
270
271 return $result;
272 }
273
278 public function getCMTarifsByRegionFromCsv($regionNameLang)
279 {
280 if(trim($regionNameLang) == '')
281 return false;
282
283 $csvFile = \CSaleHelper::getCsvObject(__DIR__.'/lang/ru/cm_tarif.csv');
284
285 $COL_REG_NAME = 0;
286 $arTarifs = array();
287
288 while ($arRes = $csvFile->Fetch())
289 {
290 if(mb_strtoupper(trim($regionNameLang)) === $arRes[$COL_REG_NAME])
291 {
292 $arTarifs = $arRes;
293 break;
294 }
295 }
296
297 $arTarifsResult = self::getTariffArrayCSV($arTarifs);
298
299 return $arTarifsResult;
300 }
301
305 public static function getAllCMTarifsFromCsv()
306 {
307 $csvFile = \CSaleHelper::getCsvObject(__DIR__.'/lang/ru/cm_tarif.csv');
308 $tarifs = array();
309 $regNames = array();
310 $result = array();
311
312 while ($arRes = $csvFile->Fetch())
313 {
314 $arRegName = array_shift($arRes);
315 $tarifs[$arRegName] = $arRes;
316
317 if($arRegName != 'default')
318 $regNames[] = $arRegName;
319 }
320
321 if(isset($tarifs['default']))
322 {
323 $result[0] = array(
324 "TARIFS" => self::getTariffArrayCSV($tarifs['default']),
325 "REG_NAME" => Loc::getMessage('SALE_HPS_CASH_ON_DELIVERY_TARIF_DEFAULT')
326 );
327 }
328
329 $regInfo = \CSaleLocation::GetRegionsIdsByNames($regNames);
330
331 foreach ($regInfo as $regName => $regId)
332 {
333 $result[$regInfo[$regName]]["TARIFS"] = self::getTariffArrayCSV($tarifs[$regName]);
334 $result[$regInfo[$regName]]["REG_NAME"] = $regName;
335 }
336
337 return $result;
338 }
339}
$arResult
Определения generate_coupon.php:16
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$region
Определения .description.php:13
getPrice(Payment $payment)
$value
Определения Param.php:39
if(!function_exists(__NAMESPACE__.'\\___972068685'))
Определения license.php:1
$payment
Определения payment.php:14
$order
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$location
Определения options.php:2729
$arRes
Определения options.php:104
$dbRes
Определения yandex_detail.php:168