Pārlūkot izejas kodu

add author to notifications

Alexander Musikhin 1 mēnesi atpakaļ
vecāks
revīzija
1469f2b5fc

+ 2 - 2
app/Http/Controllers/OrderController.php

@@ -156,7 +156,7 @@ class OrderController extends Controller
             $order->update($data);
             $order->refresh();
             if($order->order_status_id != $status) {
-                $notificationService->notifyOrderStatusChanged($order);
+                $notificationService->notifyOrderStatusChanged($order, auth()->user());
             }
         } else {
             $data['order_status_id'] = Order::STATUS_NEW;
@@ -166,7 +166,7 @@ class OrderController extends Controller
                 . ' (' . $order->area->name . ')'
                 . ' - ' . $order->user->name;
             $order->update(['tg_group_name' => $tg_group_name]);
-            $notificationService->notifyOrderCreated($order);
+            $notificationService->notifyOrderCreated($order, auth()->user());
         }
 
         // меняем список товаров заказа только если статус новый

+ 3 - 3
app/Http/Controllers/ReclamationController.php

@@ -134,7 +134,7 @@ class ReclamationController extends Controller
         ]);
         $skus = $request->validated('skus');
         $reclamation->skus()->attach($skus);
-        $notificationService->notifyReclamationCreated($reclamation->fresh(['order', 'status']));
+        $notificationService->notifyReclamationCreated($reclamation->fresh(['order', 'status']), auth()->user());
         return redirect()->route('reclamations.show', ['reclamation' => $reclamation, 'previous_url' => url()->previous()]);
     }
 
@@ -184,7 +184,7 @@ class ReclamationController extends Controller
         $reclamation->update($data);
 
         if ((int) $oldStatusId !== (int) $reclamation->status_id) {
-            $notificationService->notifyReclamationStatusChanged($reclamation->fresh(['order', 'status']));
+            $notificationService->notifyReclamationStatusChanged($reclamation->fresh(['order', 'status']), auth()->user());
         }
 
         $previousUrl = $this->previousUrlForRedirect($request, 'previous_url_reclamations');
@@ -209,7 +209,7 @@ class ReclamationController extends Controller
         ]);
 
         $reclamation->update(['status_id' => $validated['status_id']]);
-        $notificationService->notifyReclamationStatusChanged($reclamation->fresh(['order', 'status']));
+        $notificationService->notifyReclamationStatusChanged($reclamation->fresh(['order', 'status']), auth()->user());
 
         return response()->noContent();
     }

+ 3 - 3
app/Http/Controllers/ScheduleController.php

@@ -223,7 +223,7 @@ class ScheduleController extends Controller
                 ]);
             if($first && isset($validated['send_notifications'])) {
                 $first = false;
-                $notificationService->notifyScheduleAdded($schedule->fresh(['brigadier']));
+                $notificationService->notifyScheduleAdded($schedule->fresh(['brigadier']), auth()->user());
             }
         }
         return redirect()->route('schedule.index');
@@ -288,7 +288,7 @@ class ScheduleController extends Controller
                 ]);
             if($first && isset($validated['send_notifications'])) {
                 $first = false;
-                $notificationService->notifyScheduleAdded($schedule->fresh(['brigadier']));
+                $notificationService->notifyScheduleAdded($schedule->fresh(['brigadier']), auth()->user());
             }
         }
         return redirect()->route('schedule.index');
@@ -322,7 +322,7 @@ class ScheduleController extends Controller
                     'transport' => $validated['transport'] ?? null,
                     'admin_comment' => $validated['admin_comment'] ?? null,
                 ]);
-            $notificationService->notifyScheduleAdded($schedule->fresh(['brigadier']));
+            $notificationService->notifyScheduleAdded($schedule->fresh(['brigadier']), auth()->user());
         }
 
         return redirect()->back();

+ 30 - 19
app/Services/NotificationService.php

@@ -68,55 +68,62 @@ class NotificationService
         }
     }
 
-    public function notifyOrderCreated(Order $order): void
+    public function notifyOrderCreated(Order $order, ?User $author = null): void
     {
         $statusName = $order->orderStatus?->name ?? (Order::STATUS_NAMES[$order->order_status_id] ?? '-');
+        $authorSuffix = $author ? sprintf(' Изменил %s.', $author->name) : '';
+        $authorSuffixHtml = $author ? sprintf(' Изменил %s.', e($author->name)) : '';
 
         $this->notifyOrderEvent(
             $order,
             UserNotification::EVENT_CREATED,
             'Площадки',
-            sprintf('Добавлена новая площадка %s', $order->object_address),
+            sprintf('Добавлена новая площадка %s.', $order->object_address) . $authorSuffix,
             sprintf(
                 'Добавлена новая площадка <a href="%s">%s</a>.',
                 route('order.show', ['order' => $order->id, 'sync_year' => 1]),
                 e($order->object_address)
-            ),
+            ) . $authorSuffixHtml,
             $statusName,
         );
     }
 
-    public function notifyOrderStatusChanged(Order $order): void
+    public function notifyOrderStatusChanged(Order $order, ?User $author = null): void
     {
         $statusName = $order->orderStatus?->name ?? (Order::STATUS_NAMES[$order->order_status_id] ?? '-');
+        $authorSuffix = $author ? sprintf(' Изменил %s.', $author->name) : '';
+        $authorSuffixHtml = $author ? sprintf(' Изменил %s.', e($author->name)) : '';
 
         $this->notifyOrderEvent(
             $order,
             UserNotification::EVENT_STATUS_CHANGED,
             'Площадки',
-            sprintf('Статус площадки %s изменен на %s', $order->object_address, $statusName),
+            sprintf('Статус площадки %s изменен на %s.', $order->object_address, $statusName) . $authorSuffix,
             sprintf(
                 'Статус площадки <a href="%s">%s</a> изменен на %s.',
                 route('order.show', ['order' => $order->id, 'sync_year' => 1]),
                 e($order->object_address),
                 e($statusName)
-            ),
+            ) . $authorSuffixHtml,
             $statusName,
         );
     }
 
-    public function notifyReclamationCreated(Reclamation $reclamation): void
+    public function notifyReclamationCreated(Reclamation $reclamation, ?User $author = null): void
     {
         $order = $reclamation->order;
         if (!$order) {
             return;
         }
 
+        $authorSuffix = $author ? sprintf(' Изменил %s.', $author->name) : '';
+        $authorSuffixHtml = $author ? sprintf(' Изменил %s.', e($author->name)) : '';
+
         $message = sprintf(
-            'Добавлена новая рекламация по адресу %s #%d',
+            'Добавлена новая рекламация по адресу %s #%d.',
             $order->object_address,
             $reclamation->id,
-        );
+        ) . $authorSuffix;
 
         $messageHtml = sprintf(
             'Добавлена новая рекламация по адресу <a href="%s">%s</a> <a href="%s">#%d</a>.',
@@ -124,7 +131,7 @@ class NotificationService
             e($order->object_address),
             route('reclamations.show', ['reclamation' => $reclamation->id]),
             $reclamation->id,
-        );
+        ) . $authorSuffixHtml;
 
         $this->notifyReclamationEvent(
             $reclamation,
@@ -136,7 +143,7 @@ class NotificationService
         );
     }
 
-    public function notifyReclamationStatusChanged(Reclamation $reclamation): void
+    public function notifyReclamationStatusChanged(Reclamation $reclamation, ?User $author = null): void
     {
         $order = $reclamation->order;
         if (!$order) {
@@ -144,13 +151,15 @@ class NotificationService
         }
 
         $statusName = $reclamation->status?->name ?? (Reclamation::STATUS_NAMES[$reclamation->status_id] ?? '-');
+        $authorSuffix = $author ? sprintf(' Изменил %s.', $author->name) : '';
+        $authorSuffixHtml = $author ? sprintf(' Изменил %s.', e($author->name)) : '';
 
         $message = sprintf(
-            'Статус рекламации %s #%d изменен на %s',
+            'Статус рекламации %s #%d изменен на %s.',
             $order->object_address,
             $reclamation->id,
             $statusName,
-        );
+        ) . $authorSuffix;
 
         $messageHtml = sprintf(
             'Статус рекламации по адресу <a href="%s">%s</a> <a href="%s">#%d</a> изменен на %s.',
@@ -159,7 +168,7 @@ class NotificationService
             route('reclamations.show', ['reclamation' => $reclamation->id]),
             $reclamation->id,
             e($statusName),
-        );
+        ) . $authorSuffixHtml;
 
         $this->notifyReclamationEvent(
             $reclamation,
@@ -171,7 +180,7 @@ class NotificationService
         );
     }
 
-    public function notifyScheduleAdded(Schedule $schedule): void
+    public function notifyScheduleAdded(Schedule $schedule, ?User $author = null): void
     {
         $sourceKey = $this->sourceToSettingKey((string)$schedule->source);
         if (!$sourceKey) {
@@ -180,6 +189,8 @@ class NotificationService
 
         $brigadierName = $schedule->brigadier?->name ?? '-';
         $date = DateHelper::getHumanDate((string)$schedule->installation_date, true);
+        $authorSuffix = $author ? sprintf(' Изменил %s.', $author->name) : '';
+        $authorSuffixHtml = $author ? sprintf(' Изменил %s.', e($author->name)) : '';
 
         if ((string)$schedule->source === 'Рекламации') {
             $reclamationId = $this->extractReclamationId((string)$schedule->address_code);
@@ -190,7 +201,7 @@ class NotificationService
                 $schedule->object_address,
                 $date,
                 $brigadierName,
-            );
+            ) . $authorSuffix;
 
             $reclamationLink = $reclamationId
                 ? route('reclamations.show', ['reclamation' => $reclamationId])
@@ -210,14 +221,14 @@ class NotificationService
                 $addressHtml,
                 e($date),
                 e($brigadierName),
-            );
+            ) . $authorSuffixHtml;
         } else {
             $message = sprintf(
                 '%s добавлено в график монтажей на %s, Бригадир %s.',
                 $schedule->object_address,
                 $date,
                 $brigadierName,
-            );
+            ) . $authorSuffix;
 
             $orderLink = $schedule->order_id
                 ? route('order.show', ['order' => $schedule->order_id, 'sync_year' => 1])
@@ -229,7 +240,7 @@ class NotificationService
                 e($schedule->object_address),
                 e($date),
                 e($brigadierName),
-            );
+            ) . $authorSuffixHtml;
         }
 
         $users = $this->scheduleRecipients($schedule);

+ 1 - 0
docker/php/local.ini

@@ -1,3 +1,4 @@
 upload_max_filesize=500M
 post_max_size=500M
 max_file_uploads=200
+memory_limit=512M