Просмотр исходного кода

问题件日志添加同步包裹异常状态更新事件

ANG YU 5 лет назад
Родитель
Сommit
d3de29ed2f

+ 46 - 0
app/Events/OrderIssueProcessLogCreateEvent.php

@@ -0,0 +1,46 @@
+<?php
+
+namespace App\Events;
+
+use Illuminate\Broadcasting\Channel;
+use Illuminate\Broadcasting\InteractsWithSockets;
+use Illuminate\Broadcasting\PresenceChannel;
+use Illuminate\Broadcasting\PrivateChannel;
+use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
+use Illuminate\Foundation\Events\Dispatchable;
+use Illuminate\Queue\SerializesModels;
+
+class OrderIssueProcessLogCreateEvent
+{
+    use Dispatchable, InteractsWithSockets, SerializesModels;
+
+    public $orderPackageIds;
+    /**
+     * @var int
+     * 1 返回派件
+     * 2 已收件
+     */
+    public $status;
+
+    /**
+     * OrderIssueProcessLogCreateEvent constructor.
+     * @param array $orderPackageIds
+     * @param int $status
+     */
+    public function __construct(array $orderPackageIds, int $status)
+    {
+        $this->orderPackageIds = $orderPackageIds;
+        $this->status = $status;
+    }
+
+
+    /**
+     * Get the channels the event should broadcast on.
+     *
+     * @return \Illuminate\Broadcasting\Channel|array
+     */
+    public function broadcastOn()
+    {
+        return new PrivateChannel('channel-name');
+    }
+}

+ 46 - 0
app/Listeners/UpdateOrderPackageExceptionListener.php

@@ -0,0 +1,46 @@
+<?php
+
+namespace App\Listeners;
+
+use App\Events\OrderIssueProcessLogCreateEvent;
+use App\OrderPackage;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Queue\InteractsWithQueue;
+
+class UpdateOrderPackageExceptionListener
+{
+    /**
+     * Create the event listener.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        //
+    }
+
+    /**
+     * Handle the event.
+     *
+     * @param OrderIssueProcessLogCreateEvent $event
+     * @return void
+     */
+    public function handle(OrderIssueProcessLogCreateEvent $event)
+    {
+        switch ($event->status) {
+            case 1:
+                $status = '返回派件';
+                break;
+            case 2:
+                $status = '已收件';
+                break;
+            default:
+                $status = '无';
+        }
+        OrderPackage::query()->whereIn('id', $event->orderPackageIds)->update([
+            'exception_type' => '无',
+            'exception' => '否',
+            'status' => $status,
+        ]);
+    }
+}

+ 3 - 0
app/Providers/EventServiceProvider.php

@@ -38,6 +38,9 @@ class EventServiceProvider extends ServiceProvider
         'App\Events\AddOrUpdateOrderIssues' => [
             'App\Listeners\AddOrUpdateOrderIssuesListener',
         ],
+        'App\Events\OrderIssueProcessLogCreateEvent' => [
+            'App\Listeners\UpdateOrderPackageExceptionListener',
+        ],
     ];
 
     /**