2020-07-22 15:11:27 +03:00
|
|
|
<?php
|
2020-09-28 13:02:03 +03:00
|
|
|
|
2024-04-29 11:44:31 +03:00
|
|
|
/**
|
|
|
|
* @category RetailCRM
|
|
|
|
* @package RetailCRM\Service
|
|
|
|
* @author RetailCRM <integration@retailcrm.ru>
|
|
|
|
* @license MIT
|
|
|
|
* @link http://retailcrm.ru
|
|
|
|
* @see http://retailcrm.ru/docs
|
|
|
|
*/
|
|
|
|
|
2024-01-24 15:01:13 +03:00
|
|
|
use Intaro\RetailCrm\Component\Constants;
|
|
|
|
|
2020-09-28 13:02:03 +03:00
|
|
|
/**
|
|
|
|
* Class RetailCrmService
|
2024-04-29 11:44:31 +03:00
|
|
|
*
|
|
|
|
* @category RetailCRM
|
|
|
|
* @package RetailCRM\Service
|
2020-09-28 13:02:03 +03:00
|
|
|
*/
|
2020-07-22 15:11:27 +03:00
|
|
|
class RetailCrmService
|
|
|
|
{
|
2020-09-28 13:02:03 +03:00
|
|
|
/**
|
|
|
|
* @param $order
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function unsetIntegrationDeliveryFields(array $order): array
|
2020-07-22 15:11:27 +03:00
|
|
|
{
|
2022-03-02 15:40:53 +03:00
|
|
|
$integrationDelivery = RetailcrmConfigProvider::getCrmIntegrationDelivery();
|
2023-05-29 14:13:05 +03:00
|
|
|
|
2020-09-28 13:02:03 +03:00
|
|
|
if (isset($order['delivery']['code'])) {
|
|
|
|
$deliveryCode = $order['delivery']['code'];
|
2021-04-19 15:38:09 +03:00
|
|
|
|
2020-09-28 13:02:03 +03:00
|
|
|
if (!empty($integrationDelivery[$deliveryCode])
|
|
|
|
&& $integrationDelivery[$deliveryCode] !== 'sdek'
|
|
|
|
&& $integrationDelivery[$deliveryCode] !== 'dpd'
|
|
|
|
&& $integrationDelivery[$deliveryCode] !== 'newpost'
|
2023-05-29 14:13:05 +03:00
|
|
|
&& $integrationDelivery[$deliveryCode] !== 'courier'
|
2020-09-28 13:02:03 +03:00
|
|
|
) {
|
|
|
|
unset($order['weight']);
|
|
|
|
unset($order['firstName']);
|
|
|
|
unset($order['lastName']);
|
|
|
|
unset($order['phone']);
|
|
|
|
unset($order['delivery']['cost']);
|
|
|
|
unset($order['paymentType']);
|
|
|
|
unset($order['shipmentStore']);
|
|
|
|
unset($order['delivery']['address']);
|
|
|
|
unset($order['delivery']['data']);
|
|
|
|
}
|
2021-04-19 15:38:09 +03:00
|
|
|
|
2020-07-22 15:11:27 +03:00
|
|
|
switch ($integrationDelivery[$deliveryCode]) {
|
|
|
|
case "sdek":
|
2020-09-28 13:02:03 +03:00
|
|
|
unset($order['weight']);
|
2020-07-22 15:11:27 +03:00
|
|
|
unset($order['length']);
|
|
|
|
unset($order['width']);
|
2020-09-28 13:02:03 +03:00
|
|
|
unset($order['height']);
|
|
|
|
unset($order['phone']);
|
|
|
|
unset($order['delivery']['cost']);
|
|
|
|
unset($order['paymentType']);
|
|
|
|
unset($order['shipmentStore']);
|
|
|
|
unset($order['number']);
|
|
|
|
unset($order['delivery']['address']);
|
|
|
|
unset($order['delivery']['data']);
|
2020-07-22 15:11:27 +03:00
|
|
|
break;
|
|
|
|
case "dpd":
|
2020-09-28 13:02:03 +03:00
|
|
|
unset($order['weight']);
|
2020-07-22 15:11:27 +03:00
|
|
|
unset($order['manager']);
|
2020-09-28 13:02:03 +03:00
|
|
|
unset($order['phone']);
|
2020-07-22 15:11:27 +03:00
|
|
|
unset($order['firstName']);
|
|
|
|
unset($order['lastName']);
|
2020-09-28 13:02:03 +03:00
|
|
|
unset($order['delivery']['cost']);
|
|
|
|
unset($order['paymentType']);
|
|
|
|
unset($order['shipmentStore']);
|
|
|
|
unset($order['delivery']['address']);
|
|
|
|
unset($order['delivery']['data']);
|
2020-07-22 15:11:27 +03:00
|
|
|
break;
|
|
|
|
case "newpost":
|
2020-09-28 13:02:03 +03:00
|
|
|
unset($order['weight']);
|
2020-07-22 15:11:27 +03:00
|
|
|
unset($order['customer']);
|
2020-09-28 13:02:03 +03:00
|
|
|
unset($order['phone']);
|
|
|
|
unset($order['shipmentStore']);
|
|
|
|
unset($order['paymentType']);
|
|
|
|
unset($order['delivery']['cost']);
|
|
|
|
unset($order['delivery']['address']);
|
|
|
|
unset($order['delivery']['data']);
|
2020-07-22 15:11:27 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-04-19 15:38:09 +03:00
|
|
|
|
2020-07-22 15:11:27 +03:00
|
|
|
return $order;
|
|
|
|
}
|
2021-04-19 15:38:09 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function selectIntegrationDeliveries(array $data): array
|
|
|
|
{
|
|
|
|
$result = [];
|
|
|
|
|
|
|
|
foreach ($data as $elem) {
|
|
|
|
if (!empty($elem['integrationCode'])) {
|
|
|
|
$result[$elem['code']] = $elem['integrationCode'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function selectIntegrationPayments(array $data): array
|
|
|
|
{
|
|
|
|
$result = [];
|
|
|
|
|
|
|
|
foreach ($data as $elem) {
|
|
|
|
if (!empty($elem['integrationModule'])) {
|
|
|
|
$result[] = $elem['code'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2021-09-08 13:00:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int|null $paySystemId
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function isIntegrationPayment(?int $paySystemId): bool {
|
|
|
|
return in_array(
|
|
|
|
RetailcrmConfigProvider::getPaymentTypes()[$paySystemId] ?? null,
|
|
|
|
RetailcrmConfigProvider::getIntegrationPaymentTypes(),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
2023-06-07 14:39:34 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array|null $availableSites
|
|
|
|
* @param array|null $types
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getAvailableTypes(?array $availableSites, ?array $types)
|
|
|
|
{
|
|
|
|
$result = [];
|
|
|
|
|
|
|
|
foreach ($types as $type) {
|
|
|
|
if ($type['active'] !== true) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($type['sites'])) {
|
2024-01-24 15:01:13 +03:00
|
|
|
$result[$type['code']] = $type;
|
2023-06-07 14:39:34 +03:00
|
|
|
} else {
|
|
|
|
foreach ($type['sites'] as $site) {
|
|
|
|
if (!empty($availableSites[$site])) {
|
2024-01-24 15:01:13 +03:00
|
|
|
$result[$type['code']] = $type;
|
2023-06-07 14:39:34 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2023-08-22 13:09:20 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $arFields
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function writeLogsSubscribe(array $arFields): void
|
|
|
|
{
|
|
|
|
if (array_key_exists('UF_SUBSCRIBE_USER_EMAIL', $arFields)) {
|
|
|
|
$actionSub = GetMessage('SUBSCRIBED_USER');
|
|
|
|
$fileSub = 'subscribe';
|
|
|
|
|
|
|
|
if (empty($arFields['UF_SUBSCRIBE_USER_EMAIL'])) {
|
|
|
|
$actionSub = GetMessage('UNSUBSCRIBED_USER');
|
|
|
|
$fileSub = 'unSubscribe';
|
|
|
|
}
|
|
|
|
|
|
|
|
$id = $arFields['ID'] ?? $arFields['USER_ID'];
|
|
|
|
|
|
|
|
Logger::getInstance()->write(
|
|
|
|
$actionSub . ' (' . $id . ')',
|
|
|
|
$fileSub
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-01-24 15:01:13 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $crmPayment
|
|
|
|
* @param array $bitrixPayment
|
|
|
|
* @param array $optionsPaymentTypes
|
|
|
|
* @return array mixed
|
|
|
|
*/
|
|
|
|
public static function preparePayment($crmPayment, $bitrixPayment, $optionsPaymentTypes)
|
|
|
|
{
|
|
|
|
$isIntegrationPayment = self::isIntegrationPayment($bitrixPayment['PAY_SYSTEM_ID'] ?? null);
|
|
|
|
|
|
|
|
if ($isIntegrationPayment && RetailcrmConfigProvider::getSyncIntegrationPayment() === 'Y') {
|
|
|
|
$crmPayment['type'] = $optionsPaymentTypes[$bitrixPayment['PAY_SYSTEM_ID']] .
|
|
|
|
Constants::CRM_PART_SUBSTITUTED_PAYMENT_CODE;
|
|
|
|
} else {
|
|
|
|
$crmPayment['type'] = $optionsPaymentTypes[$bitrixPayment['PAY_SYSTEM_ID']];
|
|
|
|
|
|
|
|
if ($isIntegrationPayment) {
|
|
|
|
unset($crmPayment['paidAt'], $crmPayment['status']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $crmPayment;
|
|
|
|
}
|
|
|
|
|
2020-07-22 15:11:27 +03:00
|
|
|
}
|