You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.9 KiB

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