commit
627fa97775
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Recharge;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class SyncAlipayRechargeState extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'sync-recharge-pay-state:alipay';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'sync alipay recharge pay state';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$threshold = 5;
|
||||
$offset_seconds = 40; //支付发起后多少秒开始轮询
|
||||
$due_minutes = 5; //支付发起后第一次开始轮询的时间往后延迟5分钟后不再轮询
|
||||
$last_id = cache("last_sync_alipay_recharge_id", 0);
|
||||
|
||||
DB::enableQueryLog();
|
||||
$recharges = (new Recharge())
|
||||
->where("id", ">", $last_id)
|
||||
->whereNull("paid_at")
|
||||
->where("payment", "alipay")
|
||||
->whereRaw("UNIX_TIMESTAMP(`created_at`) between " . (time() + $offset_seconds) . " and " . (time() + $due_minutes * 60 + $offset_seconds))
|
||||
->limit($threshold)
|
||||
->get();
|
||||
if (!$recharges->count()) {
|
||||
cache(['last_sync_alipay_recharge_id' => null], now()->addSeconds(90));
|
||||
echo "nothing";
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($recharges as $recharge) {
|
||||
$result = (new WxMicroPay())->manualQuery($recharge);
|
||||
dump($result);
|
||||
}
|
||||
|
||||
cache(['last_sync_alipay_recharge_id' => $recharges->last()->id], now()->addSeconds(90));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue