From 93aad6d1242d7912c266ec92fad0933fb32d8820 Mon Sep 17 00:00:00 2001 From: marina Date: Wed, 4 Jun 2025 09:10:28 +0300 Subject: [PATCH] =?utf8?q?ERP-423=20Api=20=D0=B4=D0=BB=D1=8F=20=D0=BE?= =?utf8?q?=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B2=201=D1=81=20?= =?utf8?q?=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/api2/controllers/OrdersController.php | 67 +++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/erp24/api2/controllers/OrdersController.php b/erp24/api2/controllers/OrdersController.php index d96e3d84..ee41a894 100644 --- a/erp24/api2/controllers/OrdersController.php +++ b/erp24/api2/controllers/OrdersController.php @@ -8,9 +8,11 @@ use Yii; use yii\helpers\ArrayHelper; use yii\helpers\Json; use yii\web\Response; +use yii_app\records\CityStore; use yii_app\records\MarketplaceOrder1cStatuses; use yii_app\records\MarketplaceOrders; use yii_app\records\MarketplaceOrderStatusTypes; +use yii_app\records\Products1c; use yii_app\services\LogService; use yii_app\services\MarketplaceService; @@ -180,4 +182,69 @@ class OrdersController extends BaseController } return $this->asJson($mess); } + + public function actionGetOrders() + { + Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; + + try { + $rawBody = Yii::$app->request->getRawBody(); + if (empty($rawBody)) { + throw new \Exception('Пустое тело запроса'); + } + + $data = json_decode($rawBody, true); + if (json_last_error() !== JSON_ERROR_NONE) { + throw new \Exception('Некорректный JSON'); + } + + $storesGuidId = array_flip(array_filter(CityStore::getAllActiveGuidId(), fn($v) => is_int($v) || is_string($v))); + $storeGuid = $data['store-guid'] ?? null; + if (empty($storeGuid)) { + throw new \Exception('store-guid не передан или пуст'); + } + + $storeId = $storesGuidId[$storeGuid]; + $currentTime = new \DateTime(); + $startTime = (clone $currentTime)->modify('-24 hours'); + + $orders = MarketplaceOrders::find() + ->with('items') + ->where(['store_id' => $storeId]) + ->andWhere(['>=', 'creation_date', $startTime->format('Y-m-d H:i:s')]) + ->andWhere(['<=', 'creation_date', $currentTime->format('Y-m-d H:i:s')]) + ->orderBy(['id' => SORT_DESC]) + ->all(); + + $result = []; + foreach ($orders as $order) { + $orderProducts = []; + + foreach ($order->items as $product) { + $product1c = Products1c::findOne(['articule' => $product->shop_sku])->id ?? null; + $orderProducts[] = [ + $product1c => $product->count + ]; + } + + $result[] = [ + 'order_id' => $order->guid, + 'status' => $order->status_id, + 'products' => $orderProducts, + ]; + } + + return [ + 'success' => true, + 'result' => $result, + ]; + + } catch (\Exception $e) { + Yii::error($e->getMessage(), 'api'); + return [ + 'success' => false, + 'error' => $e->getMessage(), + ]; + } + } } -- 2.39.5