改进 暂停逻辑
This commit is contained in:
parent
3b1e919d4b
commit
7ef301ceff
@ -85,7 +85,7 @@ public function update(Request $request, Host $host)
|
|||||||
// 'managed_price' => 'sometimes|numeric|nullable',
|
// 'managed_price' => 'sometimes|numeric|nullable',
|
||||||
|
|
||||||
// 如果是立即扣费
|
// 如果是立即扣费
|
||||||
'cost_once' => 'sometimes|boolean|nullable',
|
'cost_once' => 'sometimes|numeric|nullable',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// if has cost_once
|
// if has cost_once
|
||||||
@ -95,7 +95,12 @@ public function update(Request $request, Host $host)
|
|||||||
return $this->updated($request->cost_once);
|
return $this->updated($request->cost_once);
|
||||||
}
|
}
|
||||||
|
|
||||||
$host->update($request->all());
|
$update = $request->all();
|
||||||
|
// module_id 不能被更新
|
||||||
|
unset($update['module_id']);
|
||||||
|
unset($update['user_id']);
|
||||||
|
|
||||||
|
$host->update($update);
|
||||||
|
|
||||||
return $this->updated($host);
|
return $this->updated($host);
|
||||||
}
|
}
|
||||||
|
@ -42,8 +42,8 @@ public function handle()
|
|||||||
$http = Http::remote($this->host->module->api_token, $this->host->module->url);
|
$http = Http::remote($this->host->module->api_token, $this->host->module->url);
|
||||||
|
|
||||||
switch ($this->type) {
|
switch ($this->type) {
|
||||||
case 'put':
|
case 'patch':
|
||||||
$response = $http->put('hosts/' . $this->host->id, $this->host->toArray());
|
$response = $http->patch('hosts/' . $this->host->id, $this->host->toArray());
|
||||||
break;
|
break;
|
||||||
case 'post':
|
case 'post':
|
||||||
$response = $http->post('hosts', $this->host->toArray());
|
$response = $http->post('hosts', $this->host->toArray());
|
||||||
|
@ -27,7 +27,9 @@ class Host extends Model
|
|||||||
];
|
];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'configuration' => 'array'
|
// 'configuration' => 'array',
|
||||||
|
'suspended_at' => 'datetime',
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
@ -89,7 +91,7 @@ public function cost($price = null)
|
|||||||
} else {
|
} else {
|
||||||
$user = Cache::put($cache_key, $this->user, now()->addDay());
|
$user = Cache::put($cache_key, $this->user, now()->addDay());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Log::debug($user);
|
// Log::debug($user);
|
||||||
|
|
||||||
@ -102,7 +104,7 @@ public function cost($price = null)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$user->drops -= $this->price;
|
$user->drops -= (int) $this->price;
|
||||||
|
|
||||||
// update cache
|
// update cache
|
||||||
Cache::put($cache_key, $user, now()->addDay());
|
Cache::put($cache_key, $user, now()->addDay());
|
||||||
@ -119,40 +121,48 @@ public function cost($price = null)
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
// on create
|
// on create
|
||||||
// protected static function boot()
|
protected static function boot()
|
||||||
// {
|
{
|
||||||
// parent::boot();
|
parent::boot();
|
||||||
|
|
||||||
// // static::creating(function ($model) {
|
// static::creating(function ($model) {
|
||||||
// // // if sanctum
|
// // if sanctum
|
||||||
// // // if (auth('sanctum')->check()) {
|
// // if (auth('sanctum')->check()) {
|
||||||
// // // $model->user_id = auth('sanctum')->id();
|
// // $model->user_id = auth('sanctum')->id();
|
||||||
// // // } else {
|
// // } else {
|
||||||
// // // // if user_id is null
|
// // // if user_id is null
|
||||||
// // // // check user_id is exists
|
// // // check user_id is exists
|
||||||
// // // throw_if(!User::find($model->user_id), CommonException::class, 'user is not exists');
|
// // throw_if(!User::find($model->user_id), CommonException::class, 'user is not exists');
|
||||||
// // // }
|
// // }
|
||||||
|
|
||||||
// // // // set price to 0
|
// // // set price to 0
|
||||||
// // // $model->price = 0;
|
// // $model->price = 0;
|
||||||
|
|
||||||
// // // $model->load('module');
|
// // $model->load('module');
|
||||||
// // // $model->module->load(['provider', 'module']);
|
// // $model->module->load(['provider', 'module']);
|
||||||
|
|
||||||
// // // add to queue
|
// // add to queue
|
||||||
|
|
||||||
// // });
|
// });
|
||||||
|
|
||||||
// // when Updated
|
static::updating(function ($model) {
|
||||||
// static::updated(function ($model) {
|
if ($model->status == 'suspended') {
|
||||||
// dispatch(new \App\Jobs\Remote\Host($model, 'put'));
|
$model->suspended_at = now();
|
||||||
// });
|
} else if ($model->status == 'running') {
|
||||||
|
$model->suspended_at = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// // when delete
|
// when Updated
|
||||||
// static::deleting(function ($model) {
|
static::updated(function ($model) {
|
||||||
// // return false;
|
dispatch(new \App\Jobs\Remote\Host($model, 'patch'));
|
||||||
|
});
|
||||||
|
|
||||||
// dispatch(new \App\Jobs\Remote\Host($model, 'delete'));
|
// // when delete
|
||||||
// });
|
// static::deleting(function ($model) {
|
||||||
// }
|
// // return false;
|
||||||
|
|
||||||
|
// // dispatch(new \App\Jobs\Remote\Host($model, 'delete'));
|
||||||
|
// });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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::table('hosts', function (Blueprint $table) {
|
||||||
|
//
|
||||||
|
$table->timestamp('suspended_at')->nullable()->index()->after('status');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('hosts', function (Blueprint $table) {
|
||||||
|
//
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user