", " . ($marketplaceOrderDelivery->street ?? '') .
", " . ($marketplaceOrderDelivery->house ?? '') .
", " . ($marketplaceOrderDelivery->apartment ?? "");
- $deliveryToDate = null;
+ $deliveryToDate = null;
$deliveryToTime = null;
if ($marketplaceOrder->delivery_to) {
$deliveryTo = explode(' ', $marketplaceOrder->delivery_to);
'marketplace_name' => $marketplaceOrder->marketplace_name ?? 'ЯндексМаркет',
'link' => $marketplaceOrder->order_link ?? '',
'order_number' => $marketplaceOrder->marketplace_order_id,
- 'delivery_date' => $deliveryToDate ?? '',
+ 'delivery_date' => $deliveryToDate ? date('d.m.Y', strtotime($deliveryToDate)) : '',
'delivery_time' => $deliveryToTime ?? '',
'delivery_type' => $delivery_type,
'delivery_address' => $deliveryAddress,
->andWhere([
'between',
'creation_date',
- date('Y-m-d 00:00:00', strtotime('-3 weeks', time())),
+ date('Y-m-d 00:00:00', strtotime(time())),
date('Y-m-d 23:59:59', time())
])
->all();
/* @var MarketplaceOrders $marketplaceOrder */
$result[] = [
'order_id' => $marketplaceOrder->guid ];
- $marketplaceOrder->cancelled_order_sent = MarketplaceOrders::STATUSES_1C_CANCELLED_ORDER_SENT_IN_1C;
- if (!$marketplaceOrder->save()) {
+ // $marketplaceOrder->cancelled_order_date = date('Y-m-d H:m:s');
+
+ // $marketplaceOrder->cancelled_order_sent = MarketplaceOrders::STATUSES_1C_CANCELLED_ORDER_SENT_IN_1C;
+ /* if (!$marketplaceOrder->save()) {
LogService::apiErrorLog(json_encode(["error_id" => 0, "error" => $marketplaceOrder->getErrors()], JSON_UNESCAPED_UNICODE));
Yii::error('Ошибка сохранения ' . json_encode($marketplaceOrder->getErrors(), JSON_UNESCAPED_UNICODE));
- }
+ } */
}
return $result;
}
}
+ 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
+ )
+ );
+ }
+ }
+ }
+ }
+
+
+
+ }
+
} catch (Exception $e) {
file_put_contents(self::OUT_DIR . '/log_error.txt', PHP_EOL . date("d.m.Y H:i:s", time()) . $e->getMessage() . " " . $e->getLine(), FILE_APPEND);
} finally {
$marketplaceOrder->substatus_id = $substatus->id;
}
}
+ if (in_array($statusId1C->status_id, ['1013', '1006'])) {
+ $marketplaceOrder->cancelled_order_source = '1c';
+ $marketplaceOrder->cancelled_order_date = date('Y-m-d H:m:s');
+ }
$marketplaceOrder->status_processing_1c = $statusId1C->id;
$marketplaceOrder->seller_id = $mpOrder['seller_id'] ?? null;
$marketplaceOrder->number_1c = $mpOrder['number'] ?? null;
--- /dev/null
+<?php
+
+use yii\db\Migration;
+
+class m250718_093101_add_cancelled_order_source_date_fields_to_marketplace_orders_table extends Migration
+{
+ const TABLE_NAME = 'erp24.marketplace_orders';
+ /**
+ * {@inheritdoc}
+ */
+ public function safeUp()
+ {
+ $table = $this->db->schema->getTableSchema(self::TABLE_NAME);
+ if ($table === null) {
+ return;
+ }
+
+ if (!$this->db->schema->getTableSchema(self::TABLE_NAME, true)->getColumn('cancelled_order_source')) {
+ $this->addColumn(
+ self::TABLE_NAME,
+ 'cancelled_order_source',
+ $this->string()->null()->comment('Источник отмененного заказа')
+ );
+ }
+ if (!$this->db->schema->getTableSchema(self::TABLE_NAME, true)->getColumn('cancelled_order_date')) {
+ $this->addColumn(
+ self::TABLE_NAME,
+ 'cancelled_order_date',
+ $this->timestamp()->null()->comment('Время отправки отмененного заказа в 1С')
+ );
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ if ($this->db->schema->getTableSchema(self::TABLE_NAME, true)->getColumn('cancelled_order_source')) {
+ $this->dropColumn(self::TABLE_NAME, 'cancelled_order_source');
+ }
+ if ($this->db->schema->getTableSchema(self::TABLE_NAME, true)->getColumn('cancelled_order_date')) {
+ $this->dropColumn(self::TABLE_NAME, 'cancelled_order_date');
+ }
+ }
+
+ /*
+ // Use up()/down() to run migration code without a transaction.
+ public function up()
+ {
+
+ }
+
+ public function down()
+ {
+ echo "m250718_093101_add_cancelled_order_source_date_fields_to_marketplace_orders_table cannot be reverted.\n";
+
+ return false;
+ }
+ */
+}