}
+ public function actionSetOrderDelivery()
+ {
+ $orders = MarketplaceOrders::find()->where(['delivery_to' => null])->all();
+
+ foreach ($orders as $order) {
+ $data = json_decode($order->raw_data, true);
+ if ($order->marketplace_id == 1 && isset($data['delivery'])) {
+ $deliveryText = (explode(',', $data['delivery']))[1] ?? '';
+ $deliveryText = trim(str_replace('Нижний Новгород', '', $deliveryText));
+
+ $months = [
+ 'января' => '01', 'февраля' => '02', 'марта' => '03',
+ 'апреля' => '04', 'мая' => '05', 'июня' => '06',
+ 'июля' => '07', 'августа' => '08', 'сентября' => '09',
+ 'октября' => '10', 'ноября' => '11', 'декабря' => '12',
+ ];
+
+ $date = null;
+
+ if (preg_match('/(\d{1,2})\s+([а-яА-Я]+)\s+(\d{4})/u', $deliveryText, $match)) {
+ [$__, $day, $monthName, $year] = $match;
+ $month = $months[mb_strtolower($monthName)] ?? null;
+ if ($month) {
+ $date = sprintf('%04d-%02d-%02d', $year, $month, $day);
+ }
+ }
+
+ $time = null;
+
+ // интервал: в 22:30—23:00
+ if (preg_match('/в\s+(\d{1,2}:\d{2})[—-](\d{1,2}:\d{2})/u', $deliveryText, $timeMatch)) {
+ $time = $timeMatch[1];
+ }
+ // вариант: с 16:26
+ elseif (preg_match('/с\s+(\d{1,2}:\d{2})/u', $deliveryText, $timeMatch)) {
+ $time = $timeMatch[1];
+ }
+
+ if ($date && $time) {
+ $order->delivery_to = "$date $time:00";
+
+ if (!$order->save()) {
+ Yii::error('Ошибка сохранения delivery_to: ' . json_encode($order->getErrors(), JSON_UNESCAPED_UNICODE), __METHOD__);
+ }
+ } else {
+ Yii::warning("Не удалось разобрать delivery: '{$deliveryText}'", __METHOD__);
+ }
+ } elseif ($order->marketplace_id == 2) {
+ // var_dump($data['delivery']['shipments']); die();
+ if (isset($data['delivery']) && isset($data['delivery']['shipments'])) {
+ $deliveryData = $data['delivery'];
+ $shipments = $deliveryData['shipments'];
+ $deliveryDates = isset($deliveryData['dates']) ? $deliveryData['dates'] : [];
+ foreach ($shipments as $shipment) {
+ $date = isset($shipment['shipmentDate']) ? $shipment['shipmentDate'] : null;
+ $time = isset($shipment['shipmentTime']) ? $shipment['shipmentTime'] : null;
+ if (!$date && !$time) {
+ continue;
+ } else {
+ $deliveryDateTo = $date ?? ($deliveryDates['fromDate'] ?? explode(' ', $order->creation_date)[0]);
+ $deliveryTimeTo = $time ?? ($deliveryDates['fromTime'] ?? explode(' ', $order->creation_date)[1]);
+ $datetimeString = $deliveryDateTo . ' ' . $deliveryTimeTo;
+ $order->delivery_to = date('Y-m-d H:i:s', strtotime($datetimeString));
+ if(!$order->save()) {
+ Yii::error('Ошибка сохранения Времени доставки' . json_encode($order->getErrors(), JSON_UNESCAPED_UNICODE), __METHOD__);
+ }
+ }
+ }
+ }
+ } else {
+ continue;
+ }
+ }
+ $this->redirect(['/marketplace-orders/index']);
+
+ }
+
public function actionUpdateToReadyStatus($id)
{
$model = $this->findModel($id);
* @property string|null $telegram_error ошибка телеграмма
* @property string|null $status_processing_1c Статус обработки заказа в 1С
* @property string|null $order_link Ссылка на заказ в МП
+ * @property string|null $delivery_to Сроки доставки заказа
*/
class MarketplaceOrders extends \yii\db\ActiveRecord
{
[['store_id', 'warehouse_guid', 'returned_at', 'return_data', 'raw_data', 'guid'], 'default', 'value' => null],
[['cancel_requested', 'status_telegram'], 'default', 'value' => 0],
[['marketplace_order_id', 'marketplace_id', 'marketplace_name', 'status_id', 'substatus_id', 'creation_date', 'updated_at', 'total', 'delivery_total', 'buyer_total_before_discount', 'tax_system', 'payment_type', 'payment_method'], 'required'],
- [['store_id', 'status_id', 'substatus_id', 'fake', 'cancel_requested', 'status_1c', 'status_processing_1c', 'order_link'], 'default', 'value' => null],
+ [['store_id', 'status_id', 'substatus_id', 'fake', 'cancel_requested', 'status_1c', 'status_processing_1c', 'order_link', 'delivery_to'], 'default', 'value' => null],
[[ 'fake'], 'default', 'value' => 0],
[['store_id', 'status_id', 'substatus_id', 'fake', 'cancel_requested', 'status_1c', 'marketplace_id', 'status_telegram', 'status_processing_1c'], 'integer'],
[['creation_date', 'updated_at', 'returned_at'], 'safe'],
- [['return_data', 'raw_data', 'marketplace_name', 'telegram_error', 'order_link'], 'string'],
+ [['return_data', 'raw_data', 'marketplace_name', 'telegram_error', 'order_link', 'delivery_to'], 'string'],
[['total', 'delivery_total', 'buyer_total_before_discount'], 'number'],
[['marketplace_order_id'], 'string', 'max' => 64],
[['number_1c'], 'string', 'max' => 100],
'telegram_error' => 'Ошибка телеграмма',
'status_processing_1c' => 'Статус обработки заказа в 1С',
'order_link' => 'Ссылка на заказ в МП',
+ 'delivery_to' => 'Сроки доставки заказа',
];
}
<?= Html::a('Назад', ['index'], ['class' => 'btn btn-primary my-4']) ?>
<?= Html::a('Ссылки на заказы', ['set-order-link'], ['class' => 'btn btn-primary my-4']) ?>
+ <?= Html::a('Проставить доставку', ['set-order-delivery'], ['class' => 'btn btn-primary my-4']) ?>
<h1><?= Html::encode($this->title) ?></h1>
<?php $form = ActiveForm::begin(); ?>
'warehouse_guid',
'creation_date',
'updated_at',
+ 'delivery_to',
'total',
'delivery_total',
'buyer_total_before_discount',