改进 计费周期
This commit is contained in:
parent
3872b5a9bb
commit
04c2a75883
@ -61,7 +61,7 @@ public function destroy(HostRequest $request, Host $host): JsonResponse
|
||||
}
|
||||
|
||||
// 如果时间大于 5 分钟,不满 1 小时
|
||||
if (now()->diffInMinutes($host->updated_at) > 5 && now()->diffInMinutes($host->updated_at) < 60) {
|
||||
if (! $host->isCycle() && now()->diffInMinutes($host->updated_at) > 5 && now()->diffInMinutes($host->updated_at) < 60) {
|
||||
$host->cost();
|
||||
}
|
||||
|
||||
|
45
app/Http/Controllers/Web/HostController.php
Normal file
45
app/Http/Controllers/Web/HostController.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Host;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class HostController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$hosts = Host::thisUser()->with(['user', 'module'])->paginate(20);
|
||||
|
||||
return view('hosts.index', compact('hosts'));
|
||||
}
|
||||
|
||||
public function renew(Host $host)
|
||||
{
|
||||
if ($host->renew()) {
|
||||
return back()->with('success', '续费成功,新的到期时间为:'.$host->next_due_at);
|
||||
}
|
||||
|
||||
return back()->with('error', '续费失败,请检查是否有足够的余额。');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param Host $host
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function destroy(Host $host): RedirectResponse
|
||||
{
|
||||
$host->safeDelete();
|
||||
|
||||
return back()->with('success', '已添加到销毁队列。');
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ class DispatchHostCostQueueJob implements ShouldQueue
|
||||
use InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected int $minute;
|
||||
|
||||
protected ?Host $host;
|
||||
|
||||
/**
|
||||
|
@ -27,7 +27,6 @@ public function __construct(Module $module = null)
|
||||
$this->module = $module;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
@ -39,7 +38,6 @@ public function handle(): void
|
||||
(new Module)->whereNotNull('url')->chunk(100, function ($modules) {
|
||||
foreach ($modules as $module) {
|
||||
dispatch(new self($module));
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ public function isCycle(): bool
|
||||
public function safeDelete(): bool
|
||||
{
|
||||
// 如果创建时间大于大于 1 小时
|
||||
if ($this->created_at->diffInHours(now()) > 1) {
|
||||
if (! $this->isCycle() && $this->created_at->diffInHours(now()) > 1) {
|
||||
// 如果当前时间比扣费时间小,则说明没有扣费。执行扣费。
|
||||
if (now()->minute < $this->minute_at) {
|
||||
$this->cost();
|
||||
|
Loading…
Reference in New Issue
Block a user