| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace App\Module\Shop\Events;
- use App\Module\Shop\Models\ShopItem;
- use Illuminate\Broadcasting\InteractsWithSockets;
- use Illuminate\Foundation\Events\Dispatchable;
- use Illuminate\Queue\SerializesModels;
- /**
- * 商品购买事件
- *
- * 当用户成功购买商品时触发此事件。
- * 其他模块可以监听此事件,以便在用户购买商品后执行相应的操作。
- */
- class ShopItemPurchased
- {
- use Dispatchable, InteractsWithSockets, SerializesModels;
- /**
- * 用户ID
- *
- * @var int
- */
- public int $userId;
- /**
- * 商品
- *
- * @var ShopItem
- */
- public ShopItem $shopItem;
- /**
- * 购买数量
- *
- * @var int
- */
- public int $quantity;
- /**
- * 总价
- *
- * @var int
- */
- public int $totalPrice;
- /**
- * 购买记录ID
- *
- * @var int
- */
- public int $purchaseLogId;
- /**
- * 创建一个新的事件实例
- *
- * @param int $userId 用户ID
- * @param ShopItem $shopItem 商品
- * @param int $quantity 购买数量
- * @param int $totalPrice 总价
- * @param int $purchaseLogId 购买记录ID
- * @return void
- */
- public function __construct(int $userId, ShopItem $shopItem, int $quantity, int $totalPrice, int $purchaseLogId)
- {
- $this->userId = $userId;
- $this->shopItem = $shopItem;
- $this->quantity = $quantity;
- $this->totalPrice = $totalPrice;
- $this->purchaseLogId = $purchaseLogId;
- }
- }
|