update: order process event

This commit is contained in:
tokumeikoi 2021-07-01 22:04:22 +09:00
parent b174403a2a
commit 9db5de09f2
5 changed files with 55 additions and 29 deletions

View File

@ -72,8 +72,10 @@ class ConfigController extends Controller
'subscribe' => [
'plan_change_enable' => (int)config('v2board.plan_change_enable', 1),
'reset_traffic_method' => (int)config('v2board.reset_traffic_method', 0),
'renew_reset_traffic_enable' => (int)config('v2board.renew_reset_traffic_enable', 0),
'surplus_enable' => (int)config('v2board.surplus_enable', 1)
'surplus_enable' => (int)config('v2board.surplus_enable', 1),
'new_order_event_id' => (int)config('v2board.new_order_event_id', 0),
'renew_order_event_id' => (int)config('v2board.renew_order_event_id', 0),
'change_order_event_id' => (int)config('v2board.change_order_event_id', 0),
],
'pay' => [
// alipay

View File

@ -45,8 +45,10 @@ class ConfigSave extends FormRequest
// subscribe
'plan_change_enable' => 'in:0,1',
'reset_traffic_method' => 'in:0,1',
'renew_reset_traffic_enable' => 'in:0,1',
'surplus_enable' => 'in:0,1',
'new_order_event_id' => 'in:0,1',
'renew_order_event_id' => 'in:0,1',
'change_order_event_id' => 'in:0,1',
// server
'server_token' => 'nullable|min:16',
'server_license' => 'nullable',

View File

@ -14,7 +14,7 @@ class UserFetch extends FormRequest
public function rules()
{
return [
'filter.*.key' => 'required|in:id,email,transfer_enable,d,expired_at,uuid,token,invite_by_email,invite_user_id,plan_id,banned',
'filter.*.key' => 'required|in:id,email,transfer_enable,d,expired_at,uuid,token,invite_by_email,invite_user_id,plan_id,banned,remarks',
'filter.*.condition' => 'required|in:>,<,=,>=,<=,模糊,!=',
'filter.*.value' => 'required'
];

View File

@ -18,6 +18,7 @@ class OrderService
'three_year_price' => 36
];
public $order;
public $user;
public function __construct(Order $order)
{
@ -27,11 +28,11 @@ class OrderService
public function open()
{
$order = $this->order;
$user = User::find($order->user_id);
$this->user = User::find($order->user_id);
$plan = Plan::find($order->plan_id);
if ($order->refund_amount) {
$user->balance = $user->balance + $order->refund_amount;
$this->user->balance = $this->user->balance + $order->refund_amount;
}
DB::beginTransaction();
if ($order->surplus_order_ids) {
@ -46,18 +47,28 @@ class OrderService
}
switch ((string)$order->cycle) {
case 'onetime_price':
$this->buyByOneTime($user, $plan);
$this->buyByOneTime($plan);
break;
case 'reset_price':
$this->buyByResetTraffic($user);
$this->buyByResetTraffic();
break;
default:
$this->buyByCycle($order, $user, $plan);
$this->buyByCycle($order, $plan);
}
if ((int)config('v2board.renew_reset_traffic_enable', 0)) $this->buyByResetTraffic($user);
switch ((int)$order->type) {
case 1:
$this->openEvent(config('v2board.new_order_event_id', 0));
break;
case 2:
$this->openEvent(config('v2board.renew_order_event_id', 0));
break;
case 3:
$this->openEvent(config('v2board.change_order_event_id', 0));
break;
}
if (!$user->save()) {
if (!$this->user->save()) {
DB::rollBack();
abort(500, '开通失败');
}
@ -220,35 +231,35 @@ class OrderService
}
private function buyByResetTraffic(User $user)
private function buyByResetTraffic()
{
$user->u = 0;
$user->d = 0;
$this->user->u = 0;
$this->user->d = 0;
}
private function buyByCycle(Order $order, User $user, Plan $plan)
private function buyByCycle(Order $order, Plan $plan)
{
// change plan process
if ((int)$order->type === 3) {
$user->expired_at = time();
$this->user->expired_at = time();
}
$user->transfer_enable = $plan->transfer_enable * 1073741824;
$this->user->transfer_enable = $plan->transfer_enable * 1073741824;
// 从一次性转换到循环
if ($user->expired_at === NULL) $this->buyByResetTraffic($user);
if ($this->user->expired_at === NULL) $this->buyByResetTraffic();
// 新购
if ($order->type === 1) $this->buyByResetTraffic($user);
$user->plan_id = $plan->id;
$user->group_id = $plan->group_id;
$user->expired_at = $this->getTime($order->cycle, $user->expired_at);
if ($order->type === 1) $this->buyByResetTraffic();
$this->user->plan_id = $plan->id;
$this->user->group_id = $plan->group_id;
$this->user->expired_at = $this->getTime($order->cycle, $this->user->expired_at);
}
private function buyByOneTime(User $user, Plan $plan)
private function buyByOneTime(Plan $plan)
{
$this->buyByResetTraffic($user);
$user->transfer_enable = $plan->transfer_enable * 1073741824;
$user->plan_id = $plan->id;
$user->group_id = $plan->group_id;
$user->expired_at = NULL;
$this->buyByResetTraffic();
$this->user->transfer_enable = $plan->transfer_enable * 1073741824;
$this->user->plan_id = $plan->id;
$this->user->group_id = $plan->group_id;
$this->user->expired_at = NULL;
}
private function getTime($str, $timestamp)
@ -271,4 +282,15 @@ class OrderService
return strtotime('+36 month', $timestamp);
}
}
private function openEvent($eventId)
{
switch ((int) $eventId) {
case 0:
break;
case 1:
$this->buyByResetTraffic();
break;
}
}
}

File diff suppressed because one or more lines are too long