tick(1000 * 60 * 20, function () { $userBill = app()->make(UserBillRepository::class); request()->clearCache(); $timer = ((int)systemConfig('lock_brokerage_timer')); $time = date('Y-m-d H:i:s', $timer ? strtotime("- $timer day") : time()); $bills = $userBill->getTimeoutBrokerageBill($time); Db::transaction(function () use ($userBill, $bills) { foreach ($bills as $bill) { if ($bill->number > 0) { $brokerage = bcsub($bill->number, $userBill->refundBrokerage($bill->link_id, $bill->uid), 2); if ($brokerage > 0) { $bill->user->brokerage_price = bcadd($bill->user->brokerage_price, $brokerage, 2); $bill->user->save(); } } $bill->status = 1; $bill->balance = $bill->user->brokerage_price; $bill->save(); } }); }); } }