mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 09:39:10 +08:00
update order change process
This commit is contained in:
parent
2e18b1b108
commit
cab7cc9d19
@ -70,10 +70,6 @@ class CheckOrder extends Command
|
||||
{
|
||||
$plan = Plan::find($order->plan_id);
|
||||
// change plan process
|
||||
if ((int)$order->type === 3 && (int)config('v2board.try_out_plan_id') !== (int)$user->plan_id) {
|
||||
$transferEnableDifference = $plan->transfer_enable - ($user->transfer_enable / 1073741824);
|
||||
$user->expired_at = $user->expired_at - ($transferEnableDifference * config('v2board.plan_transfer_hour', 12) * 3600);
|
||||
}
|
||||
$user->transfer_enable = $plan->transfer_enable * 1073741824;
|
||||
$user->enable = 1;
|
||||
$user->u = 0;
|
||||
|
@ -72,6 +72,21 @@ class OrderController extends Controller
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getDiffPrice(User $user, Plan $plan)
|
||||
{
|
||||
if ($plan->month_price) {
|
||||
$dayPrice = $plan->month_price / 30;
|
||||
} else if ($plan->quarter_price) {
|
||||
$dayPrice = $plan->quarter_price / 62;
|
||||
} else if ($plan->half_year_price) {
|
||||
$dayPrice = $plan->half_year_price / 182.5;
|
||||
} else if ($plan->year_price) {
|
||||
$dayPrice = $plan->year_price / 365;
|
||||
}
|
||||
$remainingDay = ($user->expired_at - time()) / 86400;
|
||||
return $remainingDay * $dayPrice;
|
||||
}
|
||||
|
||||
public function save(OrderSave $request)
|
||||
{
|
||||
if ($this->isNotCompleteOrderByUserId($request->session()->get('id'))) {
|
||||
@ -122,8 +137,10 @@ class OrderController extends Controller
|
||||
$order->total_amount = $plan[$request->input('cycle')];
|
||||
// renew and change subscribe process
|
||||
if ($user->expired_at > time() && $order->plan_id !== $user->plan_id) {
|
||||
$order->type = 3;
|
||||
if (!(int)config('v2board.plan_change_enable', 1)) abort(500, '目前不允许更改订阅,请联系管理员');
|
||||
$order->type = 3;
|
||||
$order->diff_amount = $this->getDiffPrice($user, $plan);
|
||||
$order->total_amount = $order->diff_amount;
|
||||
} else if ($user->expired_at > time() && $order->plan_id == $user->plan_id) {
|
||||
$order->type = 2;
|
||||
} else {
|
||||
|
@ -156,3 +156,6 @@ CREATE TABLE `failed_jobs` (
|
||||
|
||||
ALTER TABLE `v2_user`
|
||||
ADD `discount` int(11) NULL AFTER `balance`;
|
||||
|
||||
ALTER TABLE `v2_order`
|
||||
ADD `diff_amount` int(11) NULL COMMENT '差价' AFTER `discount_amount`;
|
||||
|
Loading…
Reference in New Issue
Block a user