SpecialOrderHook.php 969 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. declare(strict_types=1);
  3. namespace SixShop\WechatPay\Hook;
  4. use SixShop\Core\Attribute\Hook;
  5. use SixShop\Payment\Event\PaymentSuccessEvent;
  6. use SixShop\WechatPay\Config;
  7. use SixShop\WechatPay\Trait\MiniAppTrait;
  8. use think\facade\Log;
  9. class SpecialOrderHook
  10. {
  11. use MiniAppTrait;
  12. public function __construct(private Config $config)
  13. {
  14. }
  15. /**
  16. * 调试模式进行测试报备
  17. */
  18. #[Hook(PaymentSuccessEvent::class)]
  19. public function debugMode(PaymentSuccessEvent $event): void
  20. {
  21. if ($this->config->debug) {
  22. try {
  23. $this->opSpecialOrder($event->orderNo, 2);
  24. Log::info('特殊订单报备成功{order_no}', ['order_no' => $event->orderNo]);
  25. } catch (\Exception $e) {
  26. Log::error('特殊订单报备失败{order_no}--{code}--{msg}', ['order_no' => $event->orderNo, 'code' => $e->getCode(), 'msg' => $e->getMessage()]);
  27. }
  28. }
  29. }
  30. }