优化 代码
This commit is contained in:
parent
44d2b71327
commit
6213a50b4c
@ -111,7 +111,6 @@ protected static function boot()
|
|||||||
|
|
||||||
if ($model->managed_price !== null) {
|
if ($model->managed_price !== null) {
|
||||||
$model->managed_price = round($model->managed_price, 2);
|
$model->managed_price = round($model->managed_price, 2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -121,7 +120,6 @@ protected static function boot()
|
|||||||
});
|
});
|
||||||
|
|
||||||
static::updating(function ($model) {
|
static::updating(function ($model) {
|
||||||
|
|
||||||
if ($model->isDirty('status')) {
|
if ($model->isDirty('status')) {
|
||||||
if ($model->status == 'suspended') {
|
if ($model->status == 'suspended') {
|
||||||
$model->suspended_at = now();
|
$model->suspended_at = now();
|
||||||
@ -132,12 +130,10 @@ protected static function boot()
|
|||||||
|
|
||||||
if ($model->isDirty('price')) {
|
if ($model->isDirty('price')) {
|
||||||
$model->price = round($model->price, 2);
|
$model->price = round($model->price, 2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($model->isDirty('managed_price') && $model->managed_price !== null) {
|
if ($model->isDirty('managed_price') && $model->managed_price !== null) {
|
||||||
$model->managed_price = round($model->managed_price, 2);
|
$model->managed_price = round($model->managed_price, 2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
broadcast(new UserEvent($model->user_id, 'hosts.updating', $model));
|
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_hosts_' . $model->user_id);
|
||||||
Cache::forget('user_tasks_' . $model->user_id);
|
Cache::forget('user_tasks_' . $model->user_id);
|
||||||
|
|
||||||
|
|
||||||
broadcast(new UserEvent($model->user_id, 'hosts.updated', $model));
|
broadcast(new UserEvent($model->user_id, 'hosts.updated', $model));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -170,8 +165,6 @@ protected static function boot()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// module
|
|
||||||
|
|
||||||
public function getUserHosts($user_id = null)
|
public function getUserHosts($user_id = null)
|
||||||
{
|
{
|
||||||
return $this->where('user_id', $user_id)->with('module', function ($query) {
|
return $this->where('user_id', $user_id)->with('module', function ($query) {
|
||||||
@ -179,15 +172,11 @@ public function getUserHosts($user_id = null)
|
|||||||
})->get();
|
})->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
// workOrders
|
|
||||||
|
|
||||||
public function user(): BelongsToAlias
|
public function user(): BelongsToAlias
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
// scope
|
|
||||||
|
|
||||||
public function module(): BelongsToAlias
|
public function module(): BelongsToAlias
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Module::class);
|
return $this->belongsTo(Module::class);
|
||||||
@ -301,7 +290,6 @@ public function safeDelete(): bool
|
|||||||
|
|
||||||
public function cost($amount = null, $auto = true): bool
|
public function cost($amount = null, $auto = true): bool
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->load('user');
|
$this->load('user');
|
||||||
|
|
||||||
$real_price = $amount ?? $this->price;
|
$real_price = $amount ?? $this->price;
|
||||||
@ -312,9 +300,6 @@ public function cost($amount = null, $auto = true): bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 测试 余额支付
|
|
||||||
// echo '拿到的价格' . $real_price . '元' . PHP_EOL;
|
|
||||||
|
|
||||||
if ($auto) {
|
if ($auto) {
|
||||||
// 获取本月天数
|
// 获取本月天数
|
||||||
$days = now()->daysInMonth;
|
$days = now()->daysInMonth;
|
||||||
|
Loading…
Reference in New Issue
Block a user