]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Добавление уведомлений
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 24 Feb 2025 09:12:50 +0000 (12:12 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 24 Feb 2025 09:12:50 +0000 (12:12 +0300)
erp24/media/controllers/NotificationController.php [new file with mode: 0644]

diff --git a/erp24/media/controllers/NotificationController.php b/erp24/media/controllers/NotificationController.php
new file mode 100644 (file)
index 0000000..7c3212f
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+
+namespace app\controllers;
+
+use Yii;
+use yii\filters\AccessControl;
+use yii\helpers\Json;
+use yii\rest\Controller;
+use yii\web\BadRequestHttpException;
+use yii\web\NotFoundHttpException;
+use yii_app\api3\core\exceptions\ErrorException;
+use yii_app\helpers\File;
+use yii_app\helpers\ImageHelper;
+use yii_app\records\Files;
+use yii_app\records\Images;
+use yii_app\records\MatrixErp;
+use yii_app\records\MatrixErpProperty;
+use yii_app\services\FileService;
+
+class NotificationController extends Controller
+{
+    public function actionTest() {
+        Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
+        return ['ok'];
+    }
+
+    public function actionNotification()
+    {
+        if (!Yii::$app->request->isPost) {
+            throw new BadRequestHttpException('Только Post');
+        }
+
+        $rawBody = Yii::$app->request->getRawBody();
+        $data = Json::decode($rawBody);
+
+        if (!isset($data['notificationType'])) {
+            throw new BadRequestHttpException('Неверное событие');
+        }
+
+        $eventType = $data['notificationType'];
+
+        try {
+            switch ($eventType) {
+                case 'PING':
+                    return $this->asJson(['version' => '1', 'name' => 'БазаЦветов24', 'timestamp' => date('Y-m-d H:i:s')]);
+
+                case 'ORDER_CREATED':
+                    break;
+
+                default:
+                    Yii::info("Неизвестный тип события: {$eventType}");
+                    return $this->asJson(['success' => true, 'message' => 'Unknown event ignored']);
+            }
+
+            return $this->asJson(['success' => true, 'message' => "Event {$eventType} processed successfully"]);
+        } catch (\Exception $e) {
+            Yii::error("Error processing event {$eventType}: " . $e->getMessage());
+            return $this->asJson(['success' => false, 'message' => 'Failed to process event']);
+        }
+    }
+}