}
}
+
+ if (!empty($result['analysts_business_operations'])) {
+ $existingOperations = AnalystsBusinessOperations::find()
+ ->indexBy('id')
+ ->asArray()
+ ->all();
+ $existingTypes = AnalystsBusinessOperationsTypes::find()
+ ->indexBy('code')
+ ->asArray()
+ ->all();
+ foreach ($result["analysts_business_operations"] as $operation) {
+ if (!in_array($operation['id'], array_keys($existingOperations))) {
+ $newOperation = new AnalystsBusinessOperations();
+ $newOperation->id = $operation['id'];
+ $newOperation->name = $operation['name'];
+ $newOperation->type = (int)$operation['type'];
+ $newOperation->active = 1;
+ if (!in_array((int)$operation['type'], array_column($existingTypes, 'code'))) {
+ $newType = new AnalystsBusinessOperationsTypes();
+ $newType->code = (int)$operation['type'];
+ $newType->name = null;
+ $newType->alias = null;
+ $newType->created_at = date('Y-m-d H:i:s');
+ $newType->created_by = 1409;
+ if ($newType->save()) {
+ $newOperation->type_id = $newType->id;
+ } else {
+ $newOperation->type_id = null;
+ Yii::error('Ошибка сохранение типа ' . json_encode($newType->getErrors(), JSON_UNESCAPED_UNICODE), __METHOD__ );
+ LogService::apiErrorLog(
+ json_encode(
+ ["error_id" => 44.1, "error" => $newType->getErrors()],
+ JSON_UNESCAPED_UNICODE
+ )
+ );
+ }
+ } else {
+ $newOperation->type_id = $existingTypes[$operation['type']]['id'];
+ }
+ $newOperation->created_at = date('Y-m-d H:i:s');
+ if (!$newOperation->save()) {
+ LogService::apiErrorLog(
+ json_encode(
+ ["error_id" => 44.2, "error" => $newOperation->getErrors()],
+ JSON_UNESCAPED_UNICODE
+ )
+ );
+ }
+
+ } else {
+ if ($existingOperations[$operation['id']]['type'] !== (int)$operation['type']) {
+ $oldOperation = AnalystsBusinessOperations::findOne($operation['id']);
+ if (!in_array((int)$operation['type'], array_column($existingTypes, 'code'))) {
+ $newType = new AnalystsBusinessOperationsTypes();
+ $newType->code = (int)$operation['type'];
+ $newType->name = null;
+ $newType->alias = null;
+ $newType->created_at = date('Y-m-d H:i:s');
+ $newType->created_by = 1409;
+ if ($newType->save()) {
+ $oldOperation->type = (int)$operation['type'];
+ $oldOperation->type_id = $newType->id;
+ if (!$oldOperation->save()) {
+ LogService::apiErrorLog(
+ json_encode(
+ ["error_id" => 44.3, "error" => $oldOperation->getErrors()],
+ JSON_UNESCAPED_UNICODE
+ )
+ );
+ }
+ } else {
+ Yii::error('Ошибка сохранение типа ' . json_encode($newType->getErrors(), JSON_UNESCAPED_UNICODE), __METHOD__ );
+ LogService::apiErrorLog(
+ json_encode(
+ ["error_id" => 44.4, "error" => $oldOperation->getErrors()],
+ JSON_UNESCAPED_UNICODE
+ )
+ );
+ }
+ } else {
+ $oldOperation->type = (int)$operation['type'];
+ $oldOperation->type_id = AnalystsBusinessOperationsTypes::find()->where(['code' => (int)$operation['type']])->one()->id;
+ if (!$oldOperation->save()) {
+ LogService::apiErrorLog(
+ json_encode(
+ ["error_id" => 44.5, "error" => $oldOperation->getErrors()],
+ JSON_UNESCAPED_UNICODE
+ )
+ );
+ }
+ }
+ }
+ }
+
+ }
+ }
+ if (!empty($result['cancelled_orders'])) {
+ foreach ($result['cancelled_orders'] as $arr) {
+ $marketplaceOrders = null;
+ $marketplaceOrdersGuidArr = [];
+
+ $marketplaceOrders = MarketplaceOrders::find()->where(['guid' => $arr])->one();
+ $marketplaceOrdersGuidArr[] = $marketplaceOrders->guid;
+
+ if (!empty($marketplaceOrders)) {
+ /** @var MarketplaceOrders $marketplaceOrders */
+
+ if (!empty($arr["errors"]) || !empty($arr["error"]) || !empty($arr["errors_items"])) {
+ $errorText = '';
+ if (!empty($arr["errors"])) {
+
+
+ foreach ($arr["errors"] as $errorRow) {
+ if (!empty($errorRow['error'])) {
+ $errorText .= $errorRow['error'];
+
+ $errorText .= ' ,' . $errorRow['error_description'];
+ if (!empty($errorRow['error_json'])) {
+ foreach ($errorRow['error_json'] as $errorJsonRow) {
+ $errorText .= ' , поле: ' . $errorJsonRow['field'];
+ $errorText .= ' , ошибка: ' . $errorJsonRow['error'];
+ }
+ }
+ }
+ }
+ }
+
+ if (!empty($arr["error"])) {
+ //"error": "Ошибка преобразования ИД документа",
+ //"error_description": "ИД документа 01202307-2705-1039-09bc-100015809667 уже записан в системе",
+ $errorText .= $arr["error"];
+ $errorText .= ' ,' . $arr['error_description'];
+ }
+
+ $marketplaceOrders->status_1c = MarketplaceOrders::STATUSES_1C_ERROR_1C;
+ $marketplaceOrders->error_text = $errorText;
+ $marketplaceOrders->save();
+ if ($marketplaceOrders->getErrors()) {
+ LogService::apiErrorLog(
+ json_encode(
+ ["error_id" => 41, "error" => $marketplaceOrders->getErrors()],
+ JSON_UNESCAPED_UNICODE
+ )
+ );
+ }
+ } else {
+ $marketplaceOrder->cancelled_order_sent = MarketplaceOrders::STATUSES_1C_CANCELLED_ORDER_SENT_IN_1C;
+ $marketplaceOrders->save();
+ if ($marketplaceOrders->getErrors()) {
+ LogService::apiErrorLog(
+ json_encode(
+ ["error_id" => 41, "error" => $marketplaceOrders->getErrors()],
+ JSON_UNESCAPED_UNICODE
+ )
+ );
+ }
+ }
+ }
+ }
+
+
+
+ }
+
$mess['line'][] = __LINE__;
} catch (Exception $e) {
LogService::apiDataLogs(1, json_encode($mess, JSON_UNESCAPED_UNICODE), $requestIdText);