BarCodePayStatusListen.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\listens\pay;
  12. use app\common\repositories\store\order\StoreGroupOrderRepository;
  13. use app\common\repositories\store\order\StoreOrderRepository;
  14. use crmeb\interfaces\ListenerInterface;
  15. use crmeb\services\PayStatusService;
  16. use crmeb\services\TimerService;
  17. use think\facade\Cache;
  18. use think\facade\Log;
  19. class BarCodePayStatusListen extends TimerService implements ListenerInterface
  20. {
  21. public function handle($data): void
  22. {
  23. $this->tick(1000 * 10, function () {
  24. try {
  25. $redisData = Cache::store('redis')->handler()->rPop('bar_code_pay');
  26. if($redisData) {
  27. $redisData = json_decode($redisData, true);
  28. $groupOrder = app()->make(StoreGroupOrderRepository::class)->detail($redisData['uid'], $redisData['order_id'], false);
  29. $payStatus = (new PayStatusService($redisData['pay_type'], $groupOrder->getPayParams()))->query();
  30. // 如果支付成功,则更新订单状态
  31. if (!empty($payStatus)) {
  32. app()->make(StoreOrderRepository::class)->paySuccess($groupOrder, 0, $payStatus, 1);
  33. }
  34. }
  35. } catch (\Exception $e) {
  36. Log::error('BarCodePayStatusListen 订单结果变更错误:' . $e->getMessage());
  37. }
  38. });
  39. }
  40. }