From: fomichev Date: Mon, 24 Feb 2025 09:12:50 +0000 (+0300) Subject: Добавление уведомлений X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=d5157be9d6c2c050e05c3868a89b2e574548badb;p=erp24_rep%2Fyii-erp24%2F.git Добавление уведомлений --- diff --git a/erp24/media/controllers/NotificationController.php b/erp24/media/controllers/NotificationController.php new file mode 100644 index 00000000..7c3212f8 --- /dev/null +++ b/erp24/media/controllers/NotificationController.php @@ -0,0 +1,61 @@ +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']); + } + } +}