支持 Managed Price
This commit is contained in:
parent
59729277bb
commit
4b9d6213a3
@ -5,6 +5,7 @@
|
|||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Host;
|
use App\Models\Host;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
class HostController extends Controller
|
class HostController extends Controller
|
||||||
{
|
{
|
||||||
@ -58,9 +59,11 @@ public function show(Host $host)
|
|||||||
* @param \App\Models\Host $host
|
* @param \App\Models\Host $host
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function edit(Host $host)
|
public function edit(Host $host): View
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
|
||||||
|
return view('admin.hosts.edit', compact('host'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,6 +76,15 @@ public function edit(Host $host)
|
|||||||
public function update(Request $request, Host $host)
|
public function update(Request $request, Host $host)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
|
||||||
|
$request->validate([
|
||||||
|
'name' => 'required|string|max:255',
|
||||||
|
'managed_price' => 'nullable|numeric',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$host->update($request->all());
|
||||||
|
|
||||||
|
return back()->with('success', '此主机已更新。');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,6 +101,11 @@ public function edit(User $user)
|
|||||||
public function update(Request $request, User $user)
|
public function update(Request $request, User $user)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
$request->validate([
|
||||||
|
|
||||||
|
'balance' => 'nullable|numeric|min:0.01|max:1000',
|
||||||
|
'drops' => 'nullable|numeric|min:1|max:10000',
|
||||||
|
]);
|
||||||
|
|
||||||
$transaction = new Transaction();
|
$transaction = new Transaction();
|
||||||
|
|
||||||
|
@ -4,24 +4,27 @@
|
|||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\WorkOrder\WorkOrder;
|
use App\Models\WorkOrder\WorkOrder;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
class WorkOrderController extends Controller
|
class WorkOrderController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return View
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index(WorkOrder $workOrder): View
|
||||||
{
|
{
|
||||||
//
|
$workOrders = $workOrder->with('user')->paginate(100);
|
||||||
|
return view('admin.work-orders.index', compact('workOrders'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the form for creating a new resource.
|
* Show the form for creating a new resource.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
@ -32,7 +35,7 @@ public function create()
|
|||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
@ -43,22 +46,26 @@ public function store(Request $request)
|
|||||||
* Display the specified resource.
|
* Display the specified resource.
|
||||||
*
|
*
|
||||||
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
||||||
* @return \Illuminate\Http\Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function show(WorkOrder $workOrder)
|
public function show(WorkOrder $workOrder)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the form for editing the specified resource.
|
* Show the form for editing the specified resource.
|
||||||
*
|
*
|
||||||
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
||||||
* @return \Illuminate\Http\Response
|
*
|
||||||
|
* @return View
|
||||||
*/
|
*/
|
||||||
public function edit(WorkOrder $workOrder)
|
public function edit(WorkOrder $workOrder): View
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
|
||||||
|
return view('admin.work-orders.edit', compact('workOrder'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,18 +73,27 @@ public function edit(WorkOrder $workOrder)
|
|||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
||||||
* @return \Illuminate\Http\Response
|
*
|
||||||
|
* @return RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function update(Request $request, WorkOrder $workOrder)
|
public function update(Request $request, WorkOrder $workOrder): RedirectResponse
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
|
||||||
|
$request->validate([
|
||||||
|
'title' => 'required|string|max:255',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$workOrder->update($request->all());
|
||||||
|
|
||||||
|
return back()->with('success', '工单更新成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
||||||
* @return \Illuminate\Http\Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function destroy(WorkOrder $workOrder)
|
public function destroy(WorkOrder $workOrder)
|
||||||
{
|
{
|
||||||
|
@ -38,57 +38,6 @@ class Host extends Model
|
|||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
// get user hosts
|
|
||||||
|
|
||||||
protected static function boot()
|
|
||||||
{
|
|
||||||
parent::boot();
|
|
||||||
|
|
||||||
static::created(function ($model) {
|
|
||||||
broadcast(new UserEvent($model->user_id, 'hosts.created', $model));
|
|
||||||
});
|
|
||||||
|
|
||||||
static::updating(function ($model) {
|
|
||||||
|
|
||||||
if ($model->isDirty('status')) {
|
|
||||||
if ($model->status == 'suspended') {
|
|
||||||
$model->suspended_at = now();
|
|
||||||
} else {
|
|
||||||
$model->suspended_at = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
broadcast(new UserEvent($model->user_id, 'hosts.updating', $model));
|
|
||||||
});
|
|
||||||
|
|
||||||
// when Updated
|
|
||||||
static::updated(function ($model) {
|
|
||||||
dispatch(new \App\Jobs\Module\Host($model, 'patch'));
|
|
||||||
|
|
||||||
Cache::forget('user_hosts_' . $model->user_id);
|
|
||||||
Cache::forget('user_tasks_' . $model->user_id);
|
|
||||||
|
|
||||||
|
|
||||||
broadcast(new UserEvent($model->user_id, 'hosts.updated', $model));
|
|
||||||
});
|
|
||||||
|
|
||||||
//
|
|
||||||
// static::deleting(function ($model) {
|
|
||||||
// broadcast(new UserEvent($model->user_id, 'hosts.deleting', $model));
|
|
||||||
// });
|
|
||||||
|
|
||||||
static::deleting(function ($model) {
|
|
||||||
Cache::forget('user_tasks_' . $model->user_id);
|
|
||||||
});
|
|
||||||
|
|
||||||
static::deleted(function ($model) {
|
|
||||||
broadcast(new UserEvent($model->user_id, 'hosts.deleted', $model));
|
|
||||||
Cache::forget('user_tasks_' . $model->user_id);
|
|
||||||
Cache::forget('user_hosts_' . $model->user_id);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// user
|
// user
|
||||||
|
|
||||||
public function getUserHosts($user_id = null)
|
public function getUserHosts($user_id = null)
|
||||||
@ -121,7 +70,7 @@ public function workOrders(): HasManyAlias
|
|||||||
|
|
||||||
public function scopeActive($query)
|
public function scopeActive($query)
|
||||||
{
|
{
|
||||||
return $query->where('status', 'running')->where('price', '!=', 0);
|
return $query->whereIn('status', ['running', 'stopped'])->where('price', '!=', 0)->where('managed_price', '!=', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -147,7 +96,12 @@ public function cost($price = null, $auto = true): bool
|
|||||||
if ($price !== null) {
|
if ($price !== null) {
|
||||||
$real_price = $price;
|
$real_price = $price;
|
||||||
} else {
|
} else {
|
||||||
|
if ($this->managed_price === null) {
|
||||||
$real_price = $this->price;
|
$real_price = $this->price;
|
||||||
|
} else {
|
||||||
|
$real_price = $this->managed_price;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($real_price == 0) {
|
if ($real_price == 0) {
|
||||||
@ -239,4 +193,52 @@ public function costBalance($amount = 1): bool
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static function boot()
|
||||||
|
{
|
||||||
|
parent::boot();
|
||||||
|
|
||||||
|
static::created(function ($model) {
|
||||||
|
broadcast(new UserEvent($model->user_id, 'hosts.created', $model));
|
||||||
|
});
|
||||||
|
|
||||||
|
static::updating(function ($model) {
|
||||||
|
|
||||||
|
if ($model->isDirty('status')) {
|
||||||
|
if ($model->status == 'suspended') {
|
||||||
|
$model->suspended_at = now();
|
||||||
|
} else {
|
||||||
|
$model->suspended_at = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
broadcast(new UserEvent($model->user_id, 'hosts.updating', $model));
|
||||||
|
});
|
||||||
|
|
||||||
|
// when Updated
|
||||||
|
static::updated(function ($model) {
|
||||||
|
dispatch(new \App\Jobs\Module\Host($model, 'patch'));
|
||||||
|
|
||||||
|
Cache::forget('user_hosts_' . $model->user_id);
|
||||||
|
Cache::forget('user_tasks_' . $model->user_id);
|
||||||
|
|
||||||
|
|
||||||
|
broadcast(new UserEvent($model->user_id, 'hosts.updated', $model));
|
||||||
|
});
|
||||||
|
|
||||||
|
//
|
||||||
|
// static::deleting(function ($model) {
|
||||||
|
// broadcast(new UserEvent($model->user_id, 'hosts.deleting', $model));
|
||||||
|
// });
|
||||||
|
|
||||||
|
static::deleting(function ($model) {
|
||||||
|
Cache::forget('user_tasks_' . $model->user_id);
|
||||||
|
});
|
||||||
|
|
||||||
|
static::deleted(function ($model) {
|
||||||
|
broadcast(new UserEvent($model->user_id, 'hosts.deleted', $model));
|
||||||
|
Cache::forget('user_tasks_' . $model->user_id);
|
||||||
|
Cache::forget('user_hosts_' . $model->user_id);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
33
resources/views/admin/hosts/edit.blade.php
Normal file
33
resources/views/admin/hosts/edit.blade.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
@extends('layouts.admin')
|
||||||
|
|
||||||
|
@section('title', '主机:' . $host->name)
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
|
||||||
|
<h3>{{ $host->name }}</h3>
|
||||||
|
|
||||||
|
{{-- 修改主机 --}}
|
||||||
|
<form method="post" action="{{ route('admin.hosts.update', $host) }}">
|
||||||
|
@csrf
|
||||||
|
@method('PUT')
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name" class="col-sm-2 col-form-label">名称</label>
|
||||||
|
<input type="text" class="form-control" id="name" name="name" value="{{ $host->name }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="managed_price" class="col-sm-2 col-form-label">新的价格 (Drops)</label>
|
||||||
|
<input type="text" class="form-control" id="managed_price" name="managed_price"
|
||||||
|
value="{{ $host->managed_price }}" placeholder="{{ $host->price }}">
|
||||||
|
留空以使用默认价格
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" class="btn btn-primary mt-3">修改</button>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@endsection
|
@ -19,12 +19,12 @@
|
|||||||
@foreach ($hosts as $host)
|
@foreach ($hosts as $host)
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ route('admin.hosts.show', $host) }}">
|
<a href="{{ route('admin.hosts.edit', $host) }}">
|
||||||
{{ $host->id }}
|
{{ $host->id }}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<span class="module_name" module="{{ $host->module_id }}">{{ $host->module_id }}</span>
|
<a href="{{ route('admin.hosts.edit', $host) }}" class="module_name" module="{{ $host->module_id }}">{{ $host->module_id }}</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ $host->name }}
|
{{ $host->name }}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<h3>{{ $user->name }}</h3>
|
<h3>{{ $user->name }}</h3>
|
||||||
<a href="{{ route('admin.users.show', $user) }}">切换到 {{ $user->name }}</a>
|
<a href="{{ route('admin.users.show', $user) }}">作为 {{ $user->name }} 登录</a>
|
||||||
|
|
||||||
@if ($user->banned_at)
|
@if ($user->banned_at)
|
||||||
<p class="text-danger">已被封禁,原因: {{ $user->banned_reason }}</p>
|
<p class="text-danger">已被封禁,原因: {{ $user->banned_reason }}</p>
|
||||||
@ -44,13 +44,13 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>{{ $host->name }}</td>
|
<td>{{ $host->name }}</td>
|
||||||
<td>
|
<td>
|
||||||
<span>{{ $host->price }} Drops</span>
|
<span>{{ $host->managed_price ?? $host->price }} Drops</span>
|
||||||
≈
|
≈
|
||||||
<span>{{ round($host->price / $drops_rage * (30 * 24 * 60 / 5), 2) }} 元 / 月</span>
|
<span>{{ round($host->managed_price ?? $host->price / $drops_rage * (30 * 24 * 60 / 5), 2) }} 元 / 月</span>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ route('admin.hosts.show', $host) }}" class="btn btn-primary btn-sm">查看</a>
|
<a href="{{ route('admin.hosts.edit', $host) }}" class="btn btn-primary btn-sm">查看</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
@ -79,7 +79,7 @@
|
|||||||
<x-work-order-status :status="$workOrder->status"/>
|
<x-work-order-status :status="$workOrder->status"/>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ route('admin.work-orders.show', $host) }}" class="btn btn-primary btn-sm">查看</a>
|
<a href="{{ route('admin.work-orders.show', $host) }}" class="btn btn-primary btn-sm">编辑</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
@ -136,12 +136,12 @@
|
|||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="balance">充值余额(元)</label>
|
<label for="balance">充值余额(元)</label>
|
||||||
<input type="number" class="form-control" id="balance" name="balance" placeholder="充值金额">
|
<input type="text" class="form-control" id="balance" name="balance" placeholder="充值金额">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="drops">充值 Drops</label>
|
<label for="drops">充值 Drops</label>
|
||||||
<input type="number" class="form-control" id="drops" name="drops" placeholder="充值 Drops">
|
<input type="text" class="form-control" id="drops" name="drops" placeholder="充值 Drops">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{-- 封禁 --}}
|
{{-- 封禁 --}}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
<th>用户名</th>
|
<th>用户名</th>
|
||||||
<th>邮箱</th>
|
<th>邮箱</th>
|
||||||
<th>金额</th>
|
<th>余额</th>
|
||||||
<th>注册时间</th>
|
<th>注册时间</th>
|
||||||
<th>操作</th>
|
<th>操作</th>
|
||||||
</thead>
|
</thead>
|
||||||
|
28
resources/views/admin/work-orders/edit.blade.php
Normal file
28
resources/views/admin/work-orders/edit.blade.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
@extends('layouts.admin')
|
||||||
|
|
||||||
|
@section('title', '工单: ' . $workOrder->title)
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
|
||||||
|
<form method="post" action="{{ route('admin.work-orders.update', $workOrder) }}">
|
||||||
|
@csrf
|
||||||
|
@method('PUT')
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="title" class="col-sm-2 col-form-label">标题</label>
|
||||||
|
<input type="text" class="form-control" id="title" name="title" value="{{ $workOrder->title }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{-- <div class="form-group">--}}
|
||||||
|
{{-- <textaera name="title">--}}
|
||||||
|
{{-- {{ $workOrder->title }}--}}
|
||||||
|
{{-- </textaera>--}}
|
||||||
|
{{-- </div>--}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<button type="submit" class="btn btn-primary mt-3">修改</button>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
@endsection
|
58
resources/views/admin/work-orders/index.blade.php
Normal file
58
resources/views/admin/work-orders/index.blade.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
@extends('layouts.admin')
|
||||||
|
|
||||||
|
@section('title', '工单')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
|
||||||
|
<div class="overflow-auto">
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>标题</th>
|
||||||
|
<th>模块</th>
|
||||||
|
<th>发起者</th>
|
||||||
|
<th>操作</th>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
@foreach ($workOrders as $workOrder)
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<a href="{{ route('admin.work-orders.show', $workOrder) }}">
|
||||||
|
{{ $workOrder->id }}
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="{{ route('admin.work-orders.show', $workOrder) }}">
|
||||||
|
{{ $workOrder->title }}
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a
|
||||||
|
href="{{ route('admin.modules.show', $workOrder->module_id) }}"
|
||||||
|
class="module_name"
|
||||||
|
module="{{ $workOrder->module_id }}">{{ $workOrder->module_id }}
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="{{ route('admin.users.edit', $workOrder->user_id) }}">{{ $workOrder->user->name }}</a>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
<a href="{{ route('admin.work-orders.edit', $workOrder) }}"
|
||||||
|
class="btn btn-primary btn-sm">编辑</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{-- 分页 --}}
|
||||||
|
{{ $workOrders->links() }}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@endsection
|
Loading…
Reference in New Issue
Block a user