优化 代码

This commit is contained in:
iVampireSP.com 2022-11-20 21:41:56 +08:00
parent 44d2b71327
commit 6213a50b4c
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132

View File

@ -111,7 +111,6 @@ protected static function boot()
if ($model->managed_price !== null) {
$model->managed_price = round($model->managed_price, 2);
}
});
@ -121,7 +120,6 @@ protected static function boot()
});
static::updating(function ($model) {
if ($model->isDirty('status')) {
if ($model->status == 'suspended') {
$model->suspended_at = now();
@ -132,12 +130,10 @@ protected static function boot()
if ($model->isDirty('price')) {
$model->price = round($model->price, 2);
}
if ($model->isDirty('managed_price') && $model->managed_price !== null) {
$model->managed_price = round($model->managed_price, 2);
}
broadcast(new UserEvent($model->user_id, 'hosts.updating', $model));
@ -150,7 +146,6 @@ protected static function boot()
Cache::forget('user_hosts_' . $model->user_id);
Cache::forget('user_tasks_' . $model->user_id);
broadcast(new UserEvent($model->user_id, 'hosts.updated', $model));
});
@ -170,8 +165,6 @@ protected static function boot()
});
}
// module
public function getUserHosts($user_id = null)
{
return $this->where('user_id', $user_id)->with('module', function ($query) {
@ -179,15 +172,11 @@ public function getUserHosts($user_id = null)
})->get();
}
// workOrders
public function user(): BelongsToAlias
{
return $this->belongsTo(User::class);
}
// scope
public function module(): BelongsToAlias
{
return $this->belongsTo(Module::class);
@ -301,7 +290,6 @@ public function safeDelete(): bool
public function cost($amount = null, $auto = true): bool
{
$this->load('user');
$real_price = $amount ?? $this->price;
@ -312,9 +300,6 @@ public function cost($amount = null, $auto = true): bool
}
}
// 测试 余额支付
// echo '拿到的价格' . $real_price . '元' . PHP_EOL;
if ($auto) {
// 获取本月天数
$days = now()->daysInMonth;