create corp history
This commit is contained in:
parent
9b1347e710
commit
38bdcd0389
8 changed files with 162 additions and 33 deletions
|
@ -452,6 +452,8 @@ class RCrmActions
|
|||
case 'customersEdit':
|
||||
case 'customersСorporateGet':
|
||||
return self::proxy($api, $methodApi, $method, array($params, 'externalId', $site));
|
||||
case 'customersGetById':
|
||||
return self::proxy($api, 'customersGet', $method, array($params, 'id', $site));
|
||||
|
||||
case 'paymentEditById':
|
||||
return self::proxy($api, 'ordersPaymentEdit', $method, array($params, 'id', $site));
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<field id="cumulative_discount" group="customer">cumulativeDiscount</field>
|
||||
<field id="personal_discount" group="customer">personalDiscount</field>
|
||||
<field id="discount_card_number" group="customer">discountCardNumber</field>
|
||||
|
||||
|
||||
<field id="address.index" group="customerAddress">index</field>
|
||||
<field id="address.country" group="customerAddress">countryIso</field>
|
||||
<field id="address.region" group="customerAddress">region</field>
|
||||
|
@ -28,7 +28,7 @@
|
|||
<field id="address.intercom_code" group="customerAddress">intercomCode</field>
|
||||
<field id="address.metro" group="customerAddress">metro</field>
|
||||
<field id="address.notes" group="customerAddress">notes</field>
|
||||
|
||||
|
||||
<field id="contragent.contragent_type" group="customerContragent">contragentType</field>
|
||||
<field id="contragent.legal_name" group="customerContragent">legalName</field>
|
||||
<field id="contragent.legal_address" group="customerContragent">legalAddress</field>
|
||||
|
@ -38,7 +38,7 @@
|
|||
<field id="contragent.bank_address" group="customerContragent">bankAddress</field>
|
||||
<field id="contragent.corr_account" group="customerContragent">corrAccount</field>
|
||||
<field id="contragent.bank_account" group="customerContragent">bankAccount</field>
|
||||
|
||||
|
||||
<field id="id" group="order">id</field>
|
||||
<field id="created_at" group="order">createdAt</field>
|
||||
<field id="order_type" group="order">orderType</field>
|
||||
|
@ -52,7 +52,7 @@
|
|||
<field id="patronymic" group="order">patronymic</field>
|
||||
<field id="phone" group="order">phone</field>
|
||||
<field id="additional_phone" group="order">additionalPhone</field>
|
||||
<field id="email" group="order">email</field>
|
||||
<field id="email" group="order">email</field>
|
||||
<field id="payment_type" group="order">paymentType</field>
|
||||
<field id="payment_status" group="order">paymentStatus</field>
|
||||
<field id="discount" group="order">discount</field>
|
||||
|
@ -64,7 +64,7 @@
|
|||
<field id="shipment_date" group="order">shipmentDate</field>
|
||||
<field id="shipped" group="order">shipped</field>
|
||||
<!--<field id="order_product" group="order">item</field>-->
|
||||
|
||||
|
||||
<field id="order_product.id" group="item">id</field>
|
||||
<field id="order_product.initial_price" group="item">initialPrice</field>
|
||||
<field id="order_product.discount" group="item">discount</field>
|
||||
|
@ -72,20 +72,20 @@
|
|||
<field id="order_product.quantity" group="item">quantity</field>
|
||||
<field id="order_product.status" group="item">status</field>
|
||||
<field id="order_product.discount_total" group="item">discountTotal</field>
|
||||
|
||||
|
||||
<field id="payments.status" group="payment">status</field>
|
||||
<field id="payments.type" group="payment">type</field>
|
||||
<field id="payments.external_id" group="payment">externalId</field>
|
||||
<field id="payments.amount" group="payment">amount</field>
|
||||
<field id="payments.comment" group="payment">comment</field>
|
||||
|
||||
|
||||
<field id="delivery_type" group="delivery">code</field>
|
||||
<field id="delivery_service" group="delivery">service</field>
|
||||
<field id="delivery_date" group="delivery">date</field>
|
||||
<field id="delivery_time" group="delivery">time</field>
|
||||
<field id="delivery_cost" group="delivery">cost</field>
|
||||
<field id="delivery_net_cost" group="delivery">netCost</field>
|
||||
|
||||
|
||||
<field id="delivery_address.country" group="orderAddress">country</field>
|
||||
<field id="delivery_address.index" group="orderAddress">index</field>
|
||||
<field id="delivery_address.region" group="orderAddress">region</field>
|
||||
|
@ -93,16 +93,15 @@
|
|||
<field id="delivery_address.street" group="orderAddress">street</field>
|
||||
<field id="delivery_address.building" group="orderAddress">building</field>
|
||||
<field id="delivery_address.house" group="orderAddress">house</field>
|
||||
<field id="delivery_address.housing" group="orderAddress">housing</field>
|
||||
<field id="delivery_address.block" group="orderAddress">block</field>
|
||||
<field id="delivery_address.flat" group="orderAddress">flat</field>
|
||||
<field id="delivery_address.floor" group="orderAddress">floor</field>
|
||||
<field id="delivery_address.intercom_code" group="orderAddress">intercomCode</field>
|
||||
<field id="delivery_address.metro" group="orderAddress">metro</field>
|
||||
<field id="delivery_address.notes" group="orderAddress">notes</field>
|
||||
|
||||
|
||||
<field id="integration_delivery_data.status" group="integrationDelivery">status</field>
|
||||
<field id="integration_delivery_data.track_number" group="integrationDelivery">trackNumber</field>
|
||||
<field id="integration_delivery_data.courier" group="integrationDelivery">courier</field>
|
||||
</fields>
|
||||
</options>
|
||||
</options>
|
|
@ -18,8 +18,7 @@
|
|||
<field id="intercomcode">Домофон</field>
|
||||
<field id="floor">Этаж</field>
|
||||
<field id="block">Подъезд</field>
|
||||
<field id="house">Строение</field>
|
||||
<field id="housing">Корпус</field>
|
||||
<field id="house">Строение / корпус</field>
|
||||
|
||||
<field id="legalName" group="legal-entity, enterpreneur">Полное наименование</field>
|
||||
<field id="legalAddress" group="legal-entity, enterpreneur">Адрес регистрации (Юридический адрес)</field>
|
||||
|
@ -30,13 +29,13 @@
|
|||
<field id="bankAddress" group="legal-entity, enterpreneur">Адрес банка</field>
|
||||
<field id="corrAccount" group="legal-entity, enterpreneur">Корреспондентский счет</field>
|
||||
<field id="bankAccount" group="legal-entity, enterpreneur">Расчетный счет</field>
|
||||
|
||||
|
||||
<field id="KPP" group="legal-entity">КПП</field>
|
||||
<field id="OGRN" group="legal-entity">ОГРН</field>
|
||||
|
||||
|
||||
<field id="OGRNIP" group="enterpreneur">ОГРНИП</field>
|
||||
<field id="certificateNumber" group="enterpreneur">Номер свидетельства</field>
|
||||
<field id="certificateDate" group="enterpreneur">Дата свидетельства</field>
|
||||
|
||||
</fields>
|
||||
</options>
|
||||
</options>
|
|
@ -331,14 +331,41 @@ class RetailCrmHistory
|
|||
continue;
|
||||
}
|
||||
|
||||
if ($optionsSitesList) {
|
||||
$site = array_search($order['site'], $optionsSitesList);
|
||||
} else {
|
||||
$site = CSite::GetDefSite();
|
||||
}
|
||||
|
||||
if (empty($site)) {
|
||||
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'Bitrix\Sale\Order::create', 'Site = ' . $order['site'] . ' not found in setting. Order crm id=' . $order['id']);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($order['customer']['externalId']) && !is_numeric($order['customer']['externalId'])) {
|
||||
unset($order['customer']['externalId']);
|
||||
}
|
||||
|
||||
if ($order['customer']['type'] == 'customer_corporate') {
|
||||
// TODO Устанавливать идентификатор пользователя равным идентификатору контактного лица для корректной синхронизщации данных пользователя
|
||||
//$order['customer']['externalId'] = $order['customer']['mainCustomerContact']['customer']['externalId'];
|
||||
$order['customer']['email'] = $order['email'];
|
||||
if ($order['customer']['type'] == 'customer_corporate') {
|
||||
$contact = false;
|
||||
|
||||
if (isset($order['contact']['externalId'])) {
|
||||
$contact = RCrmActions::apiMethod($api, 'customersGet', __METHOD__, $order['contact']['externalId'], $order['site']);
|
||||
} elseif (isset($order['contact']['id'])) {
|
||||
$contact = RCrmActions::apiMethod($api, 'customersGetById', __METHOD__, $order['contact']['id'], $order['site']);
|
||||
}
|
||||
|
||||
if (!$contact || empty($contact['customer'])) {
|
||||
$log->write(sprintf(
|
||||
'cannot sync order - no customer found. order: %s',
|
||||
print_r($order, true)
|
||||
), 'orderHistory');
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$order['customer'] = $contact['customer'];
|
||||
}
|
||||
|
||||
if (!isset($order['externalId'])) {
|
||||
|
@ -405,17 +432,6 @@ class RetailCrmHistory
|
|||
$order['customer']['externalId'] = $registeredUserID;
|
||||
}
|
||||
|
||||
if ($optionsSitesList) {
|
||||
$site = array_search($order['site'], $optionsSitesList);
|
||||
} else {
|
||||
$site = CSite::GetDefSite();
|
||||
}
|
||||
if (empty($site)) {
|
||||
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'Bitrix\Sale\Order::create', 'Site = ' . $order['site'] . ' not found in setting. Order crm id=' . $order['id']);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$newOrder = Bitrix\Sale\Order::create($site, $order['customer']['externalId'], $currency);
|
||||
|
||||
if (!is_object($newOrder) || !$newOrder instanceof \Bitrix\Sale\Order) {
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
IncludeModuleLangFile(__FILE__);
|
||||
class RetailCrmCorporateClient
|
||||
{
|
||||
public static $MODULE_ID = 'intaro.retailcrm';
|
||||
public static $CRM_SITES_LIST = 'shops-corporate';
|
||||
public static $CRM_CORP_NAME = 'nickName-corporate';
|
||||
public static $CRM_LEGAL_DETAILS = 'legal_details';
|
||||
public static $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
|
||||
public static $CRM_CORP_ADRES = 'adres-corporate';
|
||||
public static $CRM_ORDER_PROPS = 'order_props';
|
||||
|
||||
public static function clientSend($arOrder, $api, $contragentType, $send = false, $site = null)
|
||||
{
|
||||
if (!$api || empty($contragentType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$shops = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_SITES_LIST, 0));
|
||||
$corpName = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CORP_NAME, 0));
|
||||
$corpAdres = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CORP_ADRES, 0));
|
||||
$arUser = Bitrix\Main\UserTable::getById($arOrder['USER_ID'])->fetch();
|
||||
$optionsLegalDetails = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_LEGAL_DETAILS, 0));
|
||||
|
||||
if (count($shops) == 0) {
|
||||
RCrmActions::eventLog('RetailCrmCorporateClient::clientSend()', '$shops', 'No stores selected for download');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($arOrder['PROPS']['properties'] as $prop) {
|
||||
if ($prop['CODE'] == $corpName) {
|
||||
$nickName = $prop['VALUE'][0];
|
||||
}
|
||||
|
||||
if ($prop['CODE'] == $corpAdres) {
|
||||
$adres = $prop['VALUE'][0];
|
||||
}
|
||||
|
||||
if (!empty($optionsLegalDetails)
|
||||
&& $search = array_search($prop['CODE'], $optionsLegalDetails[$arOrder['PERSON_TYPE_ID']])
|
||||
) {
|
||||
$contragent[$search] = $prop['VALUE'][0];//legal order data
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($nickName)) {
|
||||
$nickName = $arUser['WORK_COMPANY'];
|
||||
}
|
||||
|
||||
if (!empty($contragentType)) {
|
||||
$contragent['contragentType'] = $contragentType;
|
||||
}
|
||||
|
||||
foreach ($shops as $shop) {
|
||||
$customerCorporate = array(
|
||||
'createdAt' => $arOrder['DATE_INSERT'],
|
||||
"nickName" => $nickName,
|
||||
'customerContacts' => array(
|
||||
array(
|
||||
'isMain' => true,
|
||||
'customer' => array(
|
||||
'externalId' => $arUser['ID'],
|
||||
'site' => $shop
|
||||
)
|
||||
)
|
||||
),
|
||||
'companies' => array(
|
||||
array(
|
||||
'name' => $nickName,
|
||||
'isMain' => true,
|
||||
)
|
||||
),
|
||||
'addresses' => array(
|
||||
array(
|
||||
'name' => $nickName,
|
||||
'isMain' => true,
|
||||
'text' => $adres
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($customerCorporate) {
|
||||
if ($send && isset($_COOKIE['_rc']) && $_COOKIE['_rc'] != '') {
|
||||
$customerCorporate['browserId'] = $_COOKIE['_rc'];
|
||||
}
|
||||
|
||||
$normalizer = new RestNormalizer();
|
||||
$customerCorporate = $normalizer->normalize($customerCorporate, 'customerCorporate');
|
||||
|
||||
$log = new Logger();
|
||||
$log->write($customerCorporate, 'clientCorporate');
|
||||
|
||||
if ($send) {
|
||||
$result = RCrmActions::apiMethod($api, 'customersСorporateСreate', __METHOD__, $customerCorporate, $site);
|
||||
|
||||
if (!$result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$customerCorporate['id'] = $result['id'];
|
||||
}
|
||||
|
||||
return $customerCorporate;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,2 +1 @@
|
|||
- Улучшена работа со скидками
|
||||
- Добавлен сброс закупочной цены в icml при её отсутствии
|
||||
- Добавлена поддержка корпоративных клиентов
|
||||
|
|
|
@ -22,5 +22,6 @@ CModule::AddAutoloadClasses(
|
|||
'RetailCrm\Response\ApiResponse' => 'classes/general/Response/ApiResponse.php',
|
||||
'RetailCrm\Exception\InvalidJsonException' => 'classes/general/Exception/InvalidJsonException.php',
|
||||
'RetailCrm\Exception\CurlException' => 'classes/general/Exception/CurlException.php',
|
||||
'RetailCrmCorporateClient' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmCorporateClient.php') ? '../../php_interface/retailcrm/RetailCrmCorporateClient.php' : 'classes/general/user/RetailCrmCorporateClient.php',
|
||||
)
|
||||
);
|
||||
|
|
|
@ -93,3 +93,8 @@ $MESS ['INDEX_UA'] = 'Индекс пользовательского парам
|
|||
|
||||
$MESS ['API_NOT_FOUND'] = 'Неверная версия API';
|
||||
$MESS ['API_NOT_WORK'] = 'Выбранная версия API не поддерживается';
|
||||
|
||||
$MESS['CORP_CLIENTE'] = 'Корпоративный клиент';
|
||||
$MESS['CORP_NAME'] = "Наименование";
|
||||
$MESS['CORP_ADRESS'] = "Адрес";
|
||||
$MESS['CORP_LABEL'] = "Магазины в которые будут грузиться корпоративные клиенты";
|
||||
|
|
Loading…
Add table
Reference in a new issue