WIP
parent
b09fc5e01e
commit
21ab5b4fc4
|
|
@ -5,7 +5,7 @@ namespace App\Endpoint\Api\Http\Controllers\Product;
|
|||
use App\Endpoint\Api\Http\Controllers\Controller;
|
||||
use App\Endpoint\Api\Http\Resources\ProduckSkuResource;
|
||||
use App\Endpoint\Api\Http\Resources\ProductSkuTinyResource;
|
||||
use App\Events\ProductSku\Viewed;
|
||||
use App\Events\ProductSkuViewed;
|
||||
use App\Helpers\Paginator;
|
||||
use App\Models\ProductSku;
|
||||
use App\Models\ProductSkuFavorite;
|
||||
|
|
@ -89,7 +89,7 @@ class ProductSkuController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
Viewed::dispatch($user, $sku, now());
|
||||
ProductSkuViewed::dispatch($user, $sku, now());
|
||||
|
||||
// 是否收藏商品
|
||||
$isCollected = (bool) $user?->skuFavorites()->where('sku_id', $sku->id)->exists();
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events\ProductSku;
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\ProductSku;
|
||||
use App\Models\User;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class Viewed
|
||||
class ProductSkuViewed
|
||||
{
|
||||
use Dispatchable;
|
||||
use SerializesModels;
|
||||
|
|
@ -24,4 +25,14 @@ class Viewed
|
|||
public Carbon $viewedAt,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return \Illuminate\Broadcasting\Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
||||
|
|
@ -2,19 +2,23 @@
|
|||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\ProductSku\Viewed;
|
||||
use App\Events\ProductSkuViewed;
|
||||
use App\Models\ProductViewLog;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Throwable;
|
||||
|
||||
class CreateProductViewLog
|
||||
class CreateProductViewLog implements ShouldQueue
|
||||
{
|
||||
use InteractsWithQueue;
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param \App\Events\ProductSku\Viewed $event
|
||||
* @param \App\Events\ProductSkuViewed $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Viewed $event)
|
||||
public function handle(ProductSkuViewed $event)
|
||||
{
|
||||
if ($event->user === null) {
|
||||
return;
|
||||
|
|
@ -28,7 +32,7 @@ class CreateProductViewLog
|
|||
], [
|
||||
'sku_id' => $event->sku->id,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
} catch (Throwable $e) {
|
||||
report($e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class EventServiceProvider extends ServiceProvider
|
|||
* @var array
|
||||
*/
|
||||
protected $listen = [
|
||||
\App\Events\ProductSku\Viewed::class => [
|
||||
\App\Events\ProductSkuViewed::class => [
|
||||
\App\Listeners\CreateProductViewLog::class,
|
||||
],
|
||||
\App\Events\OrderPaid::class => [
|
||||
|
|
|
|||
Loading…
Reference in New Issue