1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace App\Jobs;
- use App\Models\DepositOrder;
- use App\Models\RefundLog;
- use Carbon\Carbon;
- use EasyWeChat\Factory;
- use Illuminate\Database\Eloquent\Model;
- class CheckRedOrderJob extends Job
- {
- public $tries = 5;
- protected $refund_id = 0;
- /**
- * Create a new job instance.
- *
- * @return void
- */
- public function __construct($refund_id, Carbon $delay)
- {
- $this->refund_id = $refund_id;
- // 设置延迟的时间,delay() 方法的参数代表多少秒之后执行
- $this->delay($delay);
- }
- /**
- * Execute the job.
- *
- * @return
- */
- public function handle()
- {
- $refund = RefundLog::query()->where('id', $this->refund_id)->where('pay_status', RefundLog::PAY_STATUS_NO)->orderBy('id', 'desc')->first();
- if (!$refund) return false;
- if ((int)$refund->type !== RefundLog::TYPE_RED_PACKET) {
- return false;
- }
- $payment = app('wechat.payment'); // 微信支付
- $re = $payment->redpack->info($refund->no);
- if ($re['return_code'] === 'SUCCESS' && $re['result_code'] === 'SUCCESS') {
- switch ($re['status']) {
- //发放中
- case 'SENDING':
- $refund->remark = '超期押金退款红包发送中';
- break;
- //已发放待领取
- case 'SENT':
- $refund->remark = '超期押金退款红包已发放,请及时领取';
- break;
- //发放失败
- case 'FAILED':
- $refund->remark = '超期押金退款红包发放失败,请联系人工退还';
- $refund->pay_status = RefundLog::PAY_STATUS_ERROR;
- $refund->result = $re['err_code_des'];
- $refund->save();
- break;
- //已领取
- case 'RECEIVED':
- $refund->pay_time = $re['hblist']['hbinfo']['rcv_time'];
- $refund->pay_status = RefundLog::PAY_STATUS_OK;
- $refund->save();
- $refund->refund_order_callback();
- //退款中 //已退款
- case 'RFUND_ING':
- case 'REFUND':
- $refund->remark = '超时未领取异常';
- $refund->pay_status = RefundLog::PAY_STATUS_ERROR;
- $refund->result = $re['err_code_des'];
- $refund->save();
- break;
- }
- }
- return true;
- }
- }
|