]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Merge branch 'refs/heads/develop' into feature_fomichev_erp-371_FW_status_from_email_2
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 18 Apr 2025 11:44:08 +0000 (14:44 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 18 Apr 2025 11:44:08 +0000 (14:44 +0300)
# Conflicts:
# erp24/services/MarketplaceService.php

1  2 
erp24/services/MarketplaceService.php

index 0081fee326e540b6bc1d2629d96d42ec26d119d1,d765084f794942b7671c021ce4a7d13cbefe784d..f9e57f46bfe5e9eaf5e4e04d9671825a3fbd0ad1
@@@ -2150,106 -2102,12 +2155,113 @@@ class MarketplaceServic
              }
          }
      }
+     public static function extractArticleCode($productName)
+     {
+         if (preg_match('/\(([^()]+)\)\s*$/u', $productName, $matches)) {
+             return $matches[1];
+         }
+         return null;
+     }
  
 +    public static function saveFromDeliveryText(int $orderId, string $deliveryText): bool
 +    {
 +        $model = new MarketplaceOrderDelivery();
 +        $model->order_id = $orderId;
 +        $model->country = 'Россия';
 +        $model->postcode = null;
 +        $model->apartment = null;
 +        $model->courier_full_name = null;
 +        $model->courier_phone = null;
 +        $model->courier_extension = null;
 +        $model->courier_vehicle_number = null;
 +        $model->courier_vehicle_description = null;
 +
 +        if (stripos($deliveryText, 'Доставка') !== false) {
 +            $model->type = 'DELIVERY';
 +            $model->service_name = 'FLOWWOW';
 +            $model->partner_type = 'FLOWWOW';
 +        } elseif (stripos($deliveryText, 'Самовывоз') !== false) {
 +            $model->type = 'PICKUP';
 +            $model->service_name = 'UNKNOWN';
 +            $model->partner_type = 'UNKNOWN';
 +        } else {
 +            return false;
 +        }
 +
 +        $date = null;
 +
 +        if (preg_match('/(?:сегодня|завтра|послезавтра)?[,]?\s*(\d{1,2})\s+([а-яА-Я]+)\s+(\d{4})/u', $deliveryText, $match)) {
 +            [$__, $day, $monthName, $year] = $match;
 +
 +            $months = [
 +                'января' => '01', 'февраля' => '02', 'марта' => '03',
 +                'апреля' => '04', 'мая' => '05', 'июня' => '06',
 +                'июля' => '07', 'августа' => '08', 'сентября' => '09',
 +                'октября' => '10', 'ноября' => '11', 'декабря' => '12',
 +            ];
 +
 +            $month = $months[mb_strtolower($monthName)] ?? null;
 +
 +            if ($month) {
 +                $date = sprintf('%04d-%02d-%02d', $year, $month, $day);
 +            }
 +        }
 +
 +        if ($date && preg_match('/в\s+(\d{1,2}:\d{2})—(\d{1,2}:\d{2})/u', $deliveryText, $timeMatch)) {
 +            $model->delivery_start = $date . ' ' . $timeMatch[1] . ':00';
 +            $model->delivery_end = $date . ' ' . $timeMatch[2] . ':00';
 +        } elseif ($date && preg_match('/с\s+(\d{1,2}:\d{2})/u', $deliveryText, $timeMatch)) {
 +            $model->delivery_start = $date . ' ' . $timeMatch[1] . ':00';
 +            $model->delivery_end = null;
 +        }
 +
 +        $address = self::parseAddressFromDeliveryText($deliveryText);
 +        $model->city = $address['city'];
 +        $model->street = $address['street'];
 +        $model->house = $address['house'];
 +        $model->latitude = $address['latitude'];
 +        $model->longitude = $address['longitude'];
 +
 +        return $model->save();
 +    }
 +
 +    public static function parseAddressFromDeliveryText(string $text): array
 +    {
 +        $city = 'Уточняется';
 +        $street = 'Уточняется';
 +        $house = 'Уточняется';
 +        $latitude = 0.0;
 +        $longitude = 0.0;
 +
 +        $parts = explode(',', $text);
 +        $parts = array_map('trim', $parts);
 +        $count = count($parts);
 +
 +        if ($count >= 3) {
 +            $city = $parts[$count - 3];
 +            $street = $parts[$count - 2];
 +            $house = $parts[$count - 1];
 +        }
 +
 +        switch (mb_strtolower($city)) {
 +            case 'нижний новгород':
 +                $latitude = 56.3269;
 +                $longitude = 44.0042;
 +                break;
 +            case 'москва':
 +                $latitude = 55.7400;
 +                $longitude = 37.6100;
 +                break;
 +        }
 +
 +        return [
 +            'city' => $city,
 +            'street' => $street,
 +            'house' => $house,
 +            'latitude' => $latitude,
 +            'longitude' => $longitude,
 +        ];
 +    }
 +
 +
  }