update order change process

This commit is contained in:
Tokumeikoi 2020-02-17 01:00:12 +08:00
parent 76c50e01bf
commit 15cd13c26c
2 changed files with 7 additions and 6 deletions

View File

@ -72,15 +72,16 @@ class OrderController extends Controller
return true;
}
private function getDiffPrice(User $user)
// surplus value
private function getSurplusValue(User $user)
{
$plan = Plan::find($user->plan_id);
if ($plan->month_price) {
$dayPrice = $plan->month_price / 30;
} else if ($plan->quarter_price) {
$dayPrice = $plan->quarter_price / 62;
$dayPrice = $plan->quarter_price / 91;
} else if ($plan->half_year_price) {
$dayPrice = $plan->half_year_price / 182.5;
$dayPrice = $plan->half_year_price / 183;
} else if ($plan->year_price) {
$dayPrice = $plan->year_price / 365;
}
@ -140,8 +141,8 @@ class OrderController extends Controller
if ($user->expired_at > time() && $order->plan_id !== $user->plan_id) {
if (!(int)config('v2board.plan_change_enable', 1)) abort(500, '目前不允许更改订阅,请联系管理员');
$order->type = 3;
$order->diff_amount = $this->getDiffPrice($user);
$order->total_amount = $order->total_amount + $order->diff_amount;
$order->surplus_amount = $this->getSurplusValue($user);
$order->total_amount = $order->total_amount - $order->surplus_amount;
} else if ($user->expired_at > time() && $order->plan_id == $user->plan_id) {
$order->type = 2;
} else {

View File

@ -158,4 +158,4 @@ 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`;
ADD `surplus_amount` int(11) NULL COMMENT '剩余价值' AFTER `discount_amount`;