OrderGetExpressEvent.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace common\events\mall;
  3. use common\enums\EventNameEnum;
  4. use common\events\data\ListEvent;
  5. use common\fixtures\ListData;
  6. /**
  7. * 商城获取物流事件
  8. * Class OrderGetExpressEvent
  9. */
  10. final class OrderGetExpressEvent extends ListEvent
  11. {
  12. /**
  13. * 触发事件名称(不可修改)
  14. *
  15. * @var string
  16. */
  17. public $name = EventNameEnum::ORDER_GET_EXPRESS;
  18. /**
  19. * 订单来源
  20. *
  21. * @var string
  22. */
  23. protected $source;
  24. /**
  25. * 订单ID
  26. *
  27. * @var int
  28. */
  29. protected $order_id;
  30. /**
  31. * @param integer $mall_id Mall Id
  32. * @param array $data 变更后的数据
  33. */
  34. public function __construct(int $mall_id, array $list = [], int $order_id, string $source)
  35. {
  36. parent::__construct($mall_id, $list);
  37. $this->source = $source;
  38. $this->order_id = $order_id;
  39. }
  40. /**
  41. * @return int
  42. */
  43. public function getOrderId()
  44. {
  45. return $this->order_id;
  46. }
  47. /**
  48. * @param string $source
  49. * @return boolean
  50. */
  51. public function isCurrentSource(string $source): bool
  52. {
  53. return $this->source == $source;
  54. }
  55. /**
  56. * @param ListData $obj
  57. * @param Object|array $ads_item
  58. * @param array $item
  59. * @return array
  60. */
  61. protected function getItem(ListData $obj, $ads_item, $item)
  62. {
  63. $express_log = is_object($ads_item)
  64. ? $ads_item->toArray()
  65. : ($ads_item === false ? $this->getDefaultValue($obj) : $ads_item);
  66. $item['express_log'] = $express_log['list']['Traces'] ?? [];
  67. return $item;
  68. }
  69. }