CheckRedOrderJob.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Jobs;
  3. use App\Models\DepositOrder;
  4. use App\Models\RefundLog;
  5. use Carbon\Carbon;
  6. use EasyWeChat\Factory;
  7. use Illuminate\Database\Eloquent\Model;
  8. class CheckRedOrderJob extends Job
  9. {
  10. public $tries = 5;
  11. protected $refund_id = 0;
  12. /**
  13. * Create a new job instance.
  14. *
  15. * @return void
  16. */
  17. public function __construct($refund_id, Carbon $delay)
  18. {
  19. $this->refund_id = $refund_id;
  20. // 设置延迟的时间,delay() 方法的参数代表多少秒之后执行
  21. $this->delay($delay);
  22. }
  23. /**
  24. * Execute the job.
  25. *
  26. * @return
  27. */
  28. public function handle()
  29. {
  30. $refund = RefundLog::query()->where('id', $this->refund_id)->where('pay_status', RefundLog::PAY_STATUS_NO)->orderBy('id', 'desc')->first();
  31. if (!$refund) return false;
  32. if ((int)$refund->type !== RefundLog::TYPE_RED_PACKET) {
  33. return false;
  34. }
  35. $payment = app('wechat.payment'); // 微信支付
  36. $re = $payment->redpack->info($refund->no);
  37. if ($re['return_code'] === 'SUCCESS' && $re['result_code'] === 'SUCCESS') {
  38. switch ($re['status']) {
  39. //发放中
  40. case 'SENDING':
  41. $refund->remark = '超期押金退款红包发送中';
  42. break;
  43. //已发放待领取
  44. case 'SENT':
  45. $refund->remark = '超期押金退款红包已发放,请及时领取';
  46. break;
  47. //发放失败
  48. case 'FAILED':
  49. $refund->remark = '超期押金退款红包发放失败,请联系人工退还';
  50. $refund->pay_status = RefundLog::PAY_STATUS_ERROR;
  51. $refund->result = $re['err_code_des'];
  52. $refund->save();
  53. break;
  54. //已领取
  55. case 'RECEIVED':
  56. $refund->pay_time = $re['hblist']['hbinfo']['rcv_time'];
  57. $refund->pay_status = RefundLog::PAY_STATUS_OK;
  58. $refund->save();
  59. $refund->refund_order_callback();
  60. //退款中 //已退款
  61. case 'RFUND_ING':
  62. case 'REFUND':
  63. $refund->remark = '超时未领取异常';
  64. $refund->pay_status = RefundLog::PAY_STATUS_ERROR;
  65. $refund->result = $re['err_code_des'];
  66. $refund->save();
  67. break;
  68. }
  69. }
  70. return true;
  71. }
  72. }