Provider Remote
This commit is contained in:
parent
40e30e3d8c
commit
50378a5e84
@ -2,11 +2,27 @@
|
||||
|
||||
namespace App\Http\Controllers\Remote;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Server\Status;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class ServerController extends Controller
|
||||
{
|
||||
// protected $cache;
|
||||
|
||||
// public function __construct() {
|
||||
// $this->cache = Cache::tags(['remote']);
|
||||
|
||||
// // 临时修改 prefix
|
||||
// $this->cache->setPrefix('remote_' . auth('remote')->id());
|
||||
// }
|
||||
|
||||
// public function all() {
|
||||
// return $this->cache->get('servers', function () {
|
||||
// return [];
|
||||
// });
|
||||
// }
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
@ -14,7 +30,14 @@ class ServerController extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
// //
|
||||
// $servers = $this->cache->get('servers', function () {
|
||||
// return [];
|
||||
// });
|
||||
|
||||
$servers = Status::provider()->get();
|
||||
|
||||
return $this->success($servers);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -23,22 +46,26 @@ public function index()
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
// 远程服务器汇报服务器状态
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
public function store(Request $request, Status $status)
|
||||
{
|
||||
//
|
||||
$request->validate([
|
||||
'name' => 'required|string',
|
||||
'ip' => 'sometimes|ip',
|
||||
'status' => 'required|string',
|
||||
]);
|
||||
|
||||
$status = $status->create([
|
||||
'name' => $request->name,
|
||||
'ip' => $request->ip,
|
||||
'status' => $request->status,
|
||||
'provider_id' => auth('remote')->id()
|
||||
]);
|
||||
|
||||
return $this->success($status);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
@ -46,9 +73,22 @@ public function show($id)
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
public function update(Request $request, Status $status)
|
||||
{
|
||||
//
|
||||
// update
|
||||
$request->validate([
|
||||
'name' => 'sometimes|string',
|
||||
'ip' => 'sometimes|ip',
|
||||
'status' => 'sometimes|string',
|
||||
]);
|
||||
|
||||
$status->provider()->update([
|
||||
'name' => $request->name,
|
||||
'ip' => $request->ip,
|
||||
'status' => $request->status,
|
||||
]);
|
||||
|
||||
return $this->updated($status);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,8 +97,11 @@ public function update(Request $request, $id)
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
public function destroy(Status $status)
|
||||
{
|
||||
//
|
||||
// delete
|
||||
$status->provider()->delete();
|
||||
return $this->deleted();
|
||||
|
||||
}
|
||||
}
|
||||
|
26
app/Models/Server/Status.php
Normal file
26
app/Models/Server/Status.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Server;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Status extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'server_status';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'ip',
|
||||
'status',
|
||||
'provider_id',
|
||||
];
|
||||
|
||||
// scope
|
||||
public function scopeProvider($query)
|
||||
{
|
||||
return $query->where('provider_id', auth('remote')->id());
|
||||
}
|
||||
}
|
@ -37,6 +37,10 @@ public function boot()
|
||||
->prefix('admin')
|
||||
->group(base_path('routes/api/admin.php'));
|
||||
|
||||
Route::middleware('auth:admin')
|
||||
->prefix('admin')
|
||||
->group(base_path('routes/api/remote.php'));
|
||||
|
||||
Route::middleware('web')
|
||||
->group(base_path('routes/web.php'));
|
||||
});
|
||||
|
@ -21,7 +21,8 @@ public function up()
|
||||
$table->string('remote_id')->index();
|
||||
|
||||
// drops id
|
||||
$table->foreignIdFor(Drop::class)->index();
|
||||
$table->unsignedBigInteger('drops_id')->index();
|
||||
$table->foreign('drops_id')->references('id')->on('drops');
|
||||
|
||||
// payment
|
||||
$table->string('payment')->index();
|
||||
|
@ -22,10 +22,12 @@ public function up()
|
||||
$table->string('name')->index();
|
||||
|
||||
// provider id
|
||||
$table->foreignIdFor(ProviderModule::class)->index();
|
||||
$table->unsignedBigInteger('provider_id')->index();
|
||||
$table->foreign('provider_id')->references('id')->on('providers')->onDelete('cascade');
|
||||
|
||||
// user_id
|
||||
$table->foreignIdFor(User::class)->index();
|
||||
$table->unsignedBigInteger('user_id')->index();
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
|
||||
// price
|
||||
$table->double('price', 60, 8)->index();
|
||||
|
@ -27,10 +27,12 @@ public function up()
|
||||
$table->text('content');
|
||||
|
||||
// user id
|
||||
$table->foreignIdFor(User::class)->index();
|
||||
$table->unsignedBigInteger('user_id')->index();
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
|
||||
// host id
|
||||
$table->foreignIdFor(Host::class)->index()->nullable();
|
||||
$table->unsignedBigInteger('host_id')->index();
|
||||
$table->foreign('host_id')->references('id')->on('hosts')->onDelete('cascade');
|
||||
|
||||
// status
|
||||
$table->enum('status', ['open', 'user_read', 'closed', 'user_replied', 'replied', 'read', 'on_hold', 'in_progress', 'error', 'pending'])->default('pending')->index();
|
||||
|
@ -22,10 +22,12 @@ public function up()
|
||||
$table->text('content');
|
||||
|
||||
// workorder id (on delete cascade)
|
||||
$table->foreignIdFor(WorkOrder::class)->index()->onDelete('cascade');
|
||||
$table->unsignedBigInteger('workorder_id')->index();
|
||||
$table->foreign('workorder_id')->references('id')->on('workorders')->onDelete('cascade');
|
||||
|
||||
// user id
|
||||
$table->foreignIdFor(User::class)->index();
|
||||
$table->unsignedBigInteger('user_id')->index();
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
|
||||
|
||||
$table->boolean('is_pending')->default(false)->index();
|
||||
|
@ -20,10 +20,12 @@ public function up()
|
||||
$table->id();
|
||||
|
||||
// provider id (on delete cascade)
|
||||
$table->foreignIdFor(Provider::class)->index()->onDelete('cascade');
|
||||
$table->unsignedBigInteger('provider_id')->index();
|
||||
$table->foreign('provider_id')->references('id')->on('providers')->onDelete('cascade');
|
||||
|
||||
// module id
|
||||
$table->foreignIdFor(Module::class)->index();
|
||||
$table->unsignedBigInteger('module_id')->index();
|
||||
$table->foreign('module_id')->references('id')->on('modules')->onDelete('cascade');
|
||||
|
||||
// api_token
|
||||
// $table->string('api_token')->index()->unique();
|
||||
|
@ -28,13 +28,16 @@ public function up()
|
||||
$table->enum('status', ['pending', 'done', 'success', 'failed', 'error', 'cancelled', 'processing', 'need_operation'])->index();
|
||||
|
||||
// user id
|
||||
$table->foreignIdFor(User::class)->index();
|
||||
$table->unsignedBigInteger('user_id')->index();
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
|
||||
// provider module id
|
||||
$table->foreignIdFor(ProviderModule::class)->index();
|
||||
$table->unsignedBigInteger('provider_module_id')->index();
|
||||
$table->foreign('provider_module_id')->references('id')->on('provider_modules')->onDelete('cascade');
|
||||
|
||||
// host id
|
||||
$table->foreignIdFor(Host::class)->index();
|
||||
$table->unsignedBigInteger('host_id')->index();
|
||||
$table->foreign('host_id')->references('id')->on('hosts')->onDelete('cascade');
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Module\Provider;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('server_status', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->string('name');
|
||||
|
||||
$table->string('ip')->nullable();
|
||||
|
||||
$table->string('status');
|
||||
|
||||
// provider foreign key
|
||||
$table->unsignedBigInteger('provider_id')->index();
|
||||
$table->foreign('provider_id')->references('id')->on('providers')->onDelete('cascade');
|
||||
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('server_status');
|
||||
}
|
||||
};
|
10
routes/api/remote.php
Normal file
10
routes/api/remote.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers;
|
||||
use App\Http\Controllers\Admin\User\DropController;
|
||||
use App\Models\Admin\Admin;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::name('remote.')->middleware(['api', 'auth:remote'])->group(function () {
|
||||
// Route::apiResource('users', Controllers\User\UserController::class);
|
||||
});
|
Loading…
Reference in New Issue
Block a user