Lae/app/Jobs/CheckAndChargeBalance.php

52 lines
1.1 KiB
PHP
Raw Normal View History

2022-09-18 06:28:29 +00:00
<?php
namespace App\Jobs;
2022-11-06 11:28:22 +00:00
use App\Http\Controllers\Api\BalanceController;
use App\Models\Balance;
2022-09-18 06:28:29 +00:00
class CheckAndChargeBalance extends Job
{
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//
$bc = new BalanceController();
Balance::where('paid_at', null)->chunk(100, function ($balances) use ($bc) {
foreach ($balances as $balance) {
if (!$bc->checkAndCharge($balance)) {
if (now()->diffInDays($balance->created_at) > 1) {
$balance->delete();
}
}
}
});
// 删除所有未付款并且大于两天的订单
Balance::where('paid_at', null)->where('created_at', '<', now()->subDays(2))->delete();
2022-09-18 06:28:29 +00:00
// Balance::chunk(100, function ($balances) use ($bc) {
// foreach ($balances as $balance) {
// $bc->checkAndCharge($balance);
// }
// });
}
}