update: add traffic reset method

This commit is contained in:
tokumeikoi 2022-06-08 02:19:19 +08:00
parent b24041cc23
commit 3840df1203
5 changed files with 41 additions and 38 deletions

View File

@ -69,9 +69,12 @@ class ResetTraffic extends Command
// no action
case 2:
break;
// year
// year first day
case 3:
$this->resetByYear($builder);
$this->resetByYearFirstDay($builder);
// year expire day
case 4:
$this->resetByExpireYear($builder);
}
break;
}
@ -90,14 +93,35 @@ class ResetTraffic extends Command
}
case ($resetMethod['method'] === 3): {
$builder = with(clone($this->builder))->whereIn('plan_id', $planIds);
$this->resetByYear($builder);
$this->resetByYearFirstDay($builder);
break;
}
case ($resetMethod['method'] === 4): {
$builder = with(clone($this->builder))->whereIn('plan_id', $planIds);
$this->resetByExpireYear($builder);
break;
}
}
}
}
private function resetByYear($builder):void
private function resetByExpireYear($builder):void
{
$users = [];
foreach ($builder->get() as $item) {
$expireDay = date('m-d', $item->expired_at);
$today = date('m-d');
if ($expireDay === $today) {
array_push($users, $item->id);
}
}
User::whereIn('id', $users)->update([
'u' => 0,
'd' => 0
]);
}
private function resetByYearFirstDay($builder):void
{
if ((string)date('md') === '0101') {
$builder->update([

View File

@ -48,7 +48,7 @@ class ConfigSave extends FormRequest
'register_limit_expire' => 'integer',
// subscribe
'plan_change_enable' => 'in:0,1',
'reset_traffic_method' => 'in:0,1,2,3',
'reset_traffic_method' => 'in:0,1,2,3,4',
'surplus_enable' => 'in:0,1',
'new_order_event_id' => 'in:0,1',
'renew_order_event_id' => 'in:0,1',
@ -60,35 +60,6 @@ class ConfigSave extends FormRequest
'server_log_enable' => 'in:0,1',
'server_v2ray_domain' => '',
'server_v2ray_protocol' => '',
// alipay
'alipay_enable' => 'in:0,1',
'alipay_appid' => 'nullable|integer|min:16',
'alipay_pubkey' => 'max:2048',
'alipay_privkey' => 'max:2048',
// stripe
'stripe_alipay_enable' => 'in:0,1',
'stripe_wepay_enable' => 'in:0,1',
'stripe_card_enable' => 'in:0,1',
'stripe_sk_live' => '',
'stripe_pk_live' => '',
'stripe_webhook_key' => '',
'stripe_currency' => 'in:hkd,usd,sgd,eur,gbp,jpy,cad',
// bitpayx
'bitpayx_name' => '',
'bitpayx_enable' => 'in:0,1',
'bitpayx_appsecret' => '',
// mGate
'mgate_name' => '',
'mgate_enable' => 'in:0,1',
'mgate_url' => 'nullable|url',
'mgate_app_id' => '',
'mgate_app_secret' => '',
// Epay
'epay_name' => '',
'epay_enable' => 'in:0,1',
'epay_url' => 'nullable|url',
'epay_pid' => '',
'epay_key' => '',
// frontend
'frontend_theme' => '',
'frontend_theme_sidebar' => 'in:dark,light',

View File

@ -26,7 +26,7 @@ class PlanSave extends FormRequest
'three_year_price' => 'nullable|integer',
'onetime_price' => 'nullable|integer',
'reset_price' => 'nullable|integer',
'reset_traffic_method' => 'nullable|integer|in:0,1,2,3'
'reset_traffic_method' => 'nullable|integer|in:0,1,2,3,4'
];
}

View File

@ -44,12 +44,20 @@ class UserService
return $lastDay - $today + $day;
}
}
if ((int)config('v2board.reset_traffic_method') === 2 ||
(isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 2))
if ((int)config('v2board.reset_traffic_method') === 3 ||
(isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 3))
{
$nextYear = strtotime(date("Y-01-01", strtotime('+1 year')));
return (int)(($nextYear - time()) / 86400);
}
if ((int)config('v2board.reset_traffic_method') === 4 ||
(isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 4))
{
$md = date('m-d', $user->expired_at);
$nowYear = strtotime(date("Y-{$md}"));
$nextYear = strtotime('+1 year', $nowYear);
return (int)(($nextYear - time()) / 86400);
}
return null;
}

File diff suppressed because one or more lines are too long