ShopItemPurchased.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Module\Shop\Events;
  3. use App\Module\Shop\Models\ShopItem;
  4. use Illuminate\Broadcasting\InteractsWithSockets;
  5. use Illuminate\Foundation\Events\Dispatchable;
  6. use Illuminate\Queue\SerializesModels;
  7. /**
  8. * 商品购买事件
  9. *
  10. * 当用户成功购买商品时触发此事件。
  11. * 其他模块可以监听此事件,以便在用户购买商品后执行相应的操作。
  12. */
  13. class ShopItemPurchased
  14. {
  15. use Dispatchable, InteractsWithSockets, SerializesModels;
  16. /**
  17. * 用户ID
  18. *
  19. * @var int
  20. */
  21. public int $userId;
  22. /**
  23. * 商品
  24. *
  25. * @var ShopItem
  26. */
  27. public ShopItem $shopItem;
  28. /**
  29. * 购买数量
  30. *
  31. * @var int
  32. */
  33. public int $quantity;
  34. /**
  35. * 总价
  36. *
  37. * @var int
  38. */
  39. public int $totalPrice;
  40. /**
  41. * 购买记录ID
  42. *
  43. * @var int
  44. */
  45. public int $purchaseLogId;
  46. /**
  47. * 创建一个新的事件实例
  48. *
  49. * @param int $userId 用户ID
  50. * @param ShopItem $shopItem 商品
  51. * @param int $quantity 购买数量
  52. * @param int $totalPrice 总价
  53. * @param int $purchaseLogId 购买记录ID
  54. * @return void
  55. */
  56. public function __construct(int $userId, ShopItem $shopItem, int $quantity, int $totalPrice, int $purchaseLogId)
  57. {
  58. $this->userId = $userId;
  59. $this->shopItem = $shopItem;
  60. $this->quantity = $quantity;
  61. $this->totalPrice = $totalPrice;
  62. $this->purchaseLogId = $purchaseLogId;
  63. }
  64. }