改进 返回内容

This commit is contained in:
iVampireSP.com 2023-02-01 00:46:52 +08:00
parent ae32ddedcd
commit 498030fcf7
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132

View File

@ -54,6 +54,11 @@ protected static function boot()
}); });
static::created(function (self $model) { static::created(function (self $model) {
$model->load('module');
// model price 使用 bcmul 保留两位小数
$model->price = bcmul($model->price, 1, 2);
$model->user->notify(new WebNotification($model, 'hosts.created')); $model->user->notify(new WebNotification($model, 'hosts.created'));
}); });
@ -97,13 +102,13 @@ protected static function boot()
// }); // });
static::deleting(function ($model) { static::deleting(function ($model) {
Cache::forget('user_tasks_'.$model->user_id); Cache::forget('user_tasks_' . $model->user_id);
}); });
static::deleted(function ($model) { static::deleted(function ($model) {
broadcast(new Users($model->user_id, 'hosts.deleted', $model)); broadcast(new Users($model->user_id, 'hosts.deleted', $model));
Cache::forget('user_tasks_'.$model->user_id); Cache::forget('user_tasks_' . $model->user_id);
Cache::forget('user_hosts_'.$model->user_id); Cache::forget('user_hosts_' . $model->user_id);
}); });
} }
@ -179,7 +184,7 @@ public function cost(string $amount = null, $auto = true): bool
$real_price = $amount ?? $this->price; $real_price = $amount ?? $this->price;
if (! $amount) { if (!$amount) {
if ($this->managed_price) { if ($this->managed_price) {
$real_price = $this->managed_price; $real_price = $this->managed_price;
} }
@ -190,7 +195,7 @@ public function cost(string $amount = null, $auto = true): bool
if ($user_group->discount !== 100 && $user_group->discount !== null) { if ($user_group->discount !== 100 && $user_group->discount !== null) {
$real_price = bcmul($real_price, bcdiv($user_group->discount, '100', 4), 4); $real_price = bcmul($real_price, bcdiv($user_group->discount, '100', 4), 4);
$append_description = ' (折扣 '.$user_group->discount.'%)'; $append_description = ' (折扣 ' . $user_group->discount . '%)';
} }
} }
@ -218,7 +223,7 @@ public function cost(string $amount = null, $auto = true): bool
$month = now()->month; $month = now()->month;
$month_cache_key = 'user_'.$this->user_id.'_month_'.$month.'_hosts_balances'; $month_cache_key = 'user_' . $this->user_id . '_month_' . $month . '_hosts_balances';
$hosts_balances = Cache::get($month_cache_key, []); $hosts_balances = Cache::get($month_cache_key, []);
// 统计 Host 消耗的 Balance // 统计 Host 消耗的 Balance
@ -272,7 +277,7 @@ public function addLog(string $amount = '0'): bool
$current_month = now()->month; $current_month = now()->month;
$current_year = now()->year; $current_year = now()->year;
$cache_key = 'module_earning_'.$this->module_id; $cache_key = 'module_earning_' . $this->module_id;
// 应支付的提成 // 应支付的提成
$commission = config('billing.commission'); $commission = config('billing.commission');
@ -287,7 +292,7 @@ public function addLog(string $amount = '0'): bool
$earnings = Cache::get($cache_key, []); $earnings = Cache::get($cache_key, []);
if (! isset($earnings[$current_year])) { if (!isset($earnings[$current_year])) {
$earnings[$current_year] = []; $earnings[$current_year] = [];
} }