public function actionIndex()
 {
     $data = Json::decode(Yii::$app->request->rawBody);
     if (is_array($data) === true) {
         // sort by event name
         $eventsNames = array_keys(array_reduce($data, function ($carry, $item) {
             if (isset($item['eventName'])) {
                 $carry[$item['eventName']] = 1;
             }
             return $carry;
         }, []));
         // preload all events into identity map
         Events::findByNames($eventsNames);
         // now we can handle it all
         foreach ($data as $eventItem) {
             if (isset($eventItem['eventName'], $eventItem['event'], $eventItem['timestamp']) === true) {
                 $eventModel = Events::findByName($eventItem['eventName']);
                 if ($eventModel !== null) {
                     $className = $eventModel->event_class_name;
                     $specialEvent = new $className($eventItem['event']);
                     EventTriggeringHelper::triggerSpecialEvent($specialEvent);
                 }
             }
         }
     }
 }
예제 #2
0
 /**
  * @param null $id
  * @return Response
  * @throws NotFoundHttpException
  * @throws \yii\base\Exception
  */
 public function actionStageLeaf($id = null)
 {
     if (empty($id)) {
         return $this->redirect(Url::to(['stage']));
     }
     /** @var OrderStageLeaf $orderStageLeaf */
     $orderStageLeaf = OrderStageLeaf::findOne(['id' => $id]);
     if (empty($orderStageLeaf)) {
         return $this->redirect(Url::to(['stage']));
     }
     $order = $this->loadOrder(false, false);
     if (empty($order)) {
         return $this->redirect(Url::to(['index']));
     }
     $orderStage = $order->stage;
     if ($orderStage->id !== $orderStageLeaf->stage_from_id && $orderStage->id !== $orderStageLeaf->stage_to_id) {
         return $this->redirect(Url::to(['stage']));
     }
     if (null !== Yii::$app->request->get('previous') && 1 !== intval($orderStageLeaf->stageFrom->immutable_by_user)) {
         $order->order_stage_id = $orderStageLeaf->stageFrom->id;
         $order->save();
     } else {
         /** @var Events $eventClassName */
         $eventClassName = Events::findByName($orderStageLeaf->event_name);
         if (!empty($eventClassName) && is_subclass_of($eventClassName->event_class_name, OrderStageLeafEvent::className())) {
             /** @var OrderStageLeafEvent $event */
             $event = new $eventClassName->event_class_name();
             EventTriggeringHelper::triggerSpecialEvent($event);
             if ($event->getStatus()) {
                 $order->order_stage_id = $order->order_stage_id == $orderStageLeaf->stage_to_id ? $orderStageLeaf->stage_from_id : $orderStageLeaf->stage_to_id;
                 $order->save();
                 Yii::$app->session->set('OrderStageReach', true);
             }
         }
     }
     return $this->redirect(Url::to(['stage']));
 }