mirror of
https://github.com/v2board/v2board.git
synced 2025-06-13 21:28:27 +08:00
update: more
This commit is contained in:
@ -4,8 +4,10 @@ namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Order;
|
||||
use App\Models\User;
|
||||
use App\Utils\CacheKey;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Matriphe\Larinfo;
|
||||
|
||||
class Test extends Command
|
||||
|
@ -146,11 +146,11 @@ class OrderController extends Controller
|
||||
$orderService = new OrderService($order);
|
||||
$order->user_id = $user->id;
|
||||
$order->plan_id = $plan->id;
|
||||
$order->cycle = $request->input('cycle');
|
||||
$order->period = $request->input('period');
|
||||
$order->trade_no = Helper::guid();
|
||||
$order->total_amount = $request->input('total_amount');
|
||||
|
||||
if ($order->cycle === 'reset_price') {
|
||||
if ($order->period === 'reset_price') {
|
||||
$order->type = 4;
|
||||
} else if ($user->plan_id !== NULL && $order->plan_id !== $user->plan_id) {
|
||||
$order->type = 3;
|
||||
|
@ -22,6 +22,7 @@ class ManageController extends Controller
|
||||
|
||||
public function sort(Request $request)
|
||||
{
|
||||
ini_set('post_max_size', '1m');
|
||||
DB::beginTransaction();
|
||||
foreach ($request->input('sorts') as $k => $v) {
|
||||
switch ($v['key']) {
|
||||
|
@ -79,20 +79,20 @@ class OrderController extends Controller
|
||||
}
|
||||
|
||||
if ((!$plan->show && !$plan->renew) || (!$plan->show && $user->plan_id !== $plan->id)) {
|
||||
if ($request->input('cycle') !== 'reset_price') {
|
||||
if ($request->input('period') !== 'reset_price') {
|
||||
abort(500, __('This subscription has been sold out, please choose another subscription'));
|
||||
}
|
||||
}
|
||||
|
||||
if (!$plan->renew && $user->plan_id == $plan->id && $request->input('cycle') !== 'reset_price') {
|
||||
if (!$plan->renew && $user->plan_id == $plan->id && $request->input('period') !== 'reset_price') {
|
||||
abort(500, __('This subscription cannot be renewed, please change to another subscription'));
|
||||
}
|
||||
|
||||
if ($plan[$request->input('cycle')] === NULL) {
|
||||
abort(500, __('This payment cycle cannot be purchased, please choose another cycle'));
|
||||
if ($plan[$request->input('period')] === NULL) {
|
||||
abort(500, __('This payment period cannot be purchased, please choose another period'));
|
||||
}
|
||||
|
||||
if ($request->input('cycle') === 'reset_price') {
|
||||
if ($request->input('period') === 'reset_price') {
|
||||
if ($user->expired_at <= time() || !$user->plan_id) {
|
||||
abort(500, __('Subscription has expired or no active subscription, unable to purchase Data Reset Package'));
|
||||
}
|
||||
@ -107,9 +107,9 @@ class OrderController extends Controller
|
||||
$orderService = new OrderService($order);
|
||||
$order->user_id = $request->session()->get('id');
|
||||
$order->plan_id = $plan->id;
|
||||
$order->cycle = $request->input('cycle');
|
||||
$order->period = $request->input('period');
|
||||
$order->trade_no = Helper::generateOrderNo();
|
||||
$order->total_amount = $plan[$request->input('cycle')];
|
||||
$order->total_amount = $plan[$request->input('period')];
|
||||
|
||||
if ($request->input('coupon_code')) {
|
||||
$couponService = new CouponService($request->input('coupon_code'));
|
||||
|
@ -17,7 +17,7 @@ class OrderAssign extends FormRequest
|
||||
'plan_id' => 'required',
|
||||
'email' => 'required',
|
||||
'total_amount' => 'required',
|
||||
'cycle' => 'required|in:month_price,quarter_price,half_year_price,year_price,two_year_price,three_year_price,onetime_price,reset_price'
|
||||
'period' => 'required|in:month_price,quarter_price,half_year_price,year_price,two_year_price,three_year_price,onetime_price,reset_price'
|
||||
];
|
||||
}
|
||||
|
||||
@ -27,8 +27,8 @@ class OrderAssign extends FormRequest
|
||||
'plan_id.required' => '订阅不能为空',
|
||||
'email.required' => '邮箱不能为空',
|
||||
'total_amount.required' => '支付金额不能为空',
|
||||
'cycle.required' => '订阅周期不能为空',
|
||||
'cycle.in' => '订阅周期格式有误'
|
||||
'period.required' => '订阅周期不能为空',
|
||||
'period.in' => '订阅周期格式有误'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ class OrderSave extends FormRequest
|
||||
{
|
||||
return [
|
||||
'plan_id' => 'required',
|
||||
'cycle' => 'required|in:month_price,quarter_price,half_year_price,year_price,two_year_price,three_year_price,onetime_price,reset_price'
|
||||
'period' => 'required|in:month_price,quarter_price,half_year_price,year_price,two_year_price,three_year_price,onetime_price,reset_price'
|
||||
];
|
||||
}
|
||||
|
||||
@ -23,8 +23,8 @@ class OrderSave extends FormRequest
|
||||
{
|
||||
return [
|
||||
'plan_id.required' => __('Plan ID cannot be empty'),
|
||||
'cycle.required' => __('Plan cycle cannot be empty'),
|
||||
'cycle.in' => __('Wrong plan cycle')
|
||||
'period.required' => __('Plan period cannot be empty'),
|
||||
'period.in' => __('Wrong plan period')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ class OrderService
|
||||
abort(500, '开通失败');
|
||||
}
|
||||
}
|
||||
switch ((string)$order->cycle) {
|
||||
switch ((string)$order->period) {
|
||||
case 'onetime_price':
|
||||
$this->buyByOneTime($plan);
|
||||
break;
|
||||
@ -54,7 +54,7 @@ class OrderService
|
||||
$this->buyByResetTraffic();
|
||||
break;
|
||||
default:
|
||||
$this->buyByCycle($order, $plan);
|
||||
$this->buyByPeriod($order, $plan);
|
||||
}
|
||||
|
||||
switch ((int)$order->type) {
|
||||
@ -86,7 +86,7 @@ class OrderService
|
||||
public function setOrderType(User $user)
|
||||
{
|
||||
$order = $this->order;
|
||||
if ($order->cycle === 'reset_price') {
|
||||
if ($order->period === 'reset_price') {
|
||||
$order->type = 4;
|
||||
} else if ($user->plan_id !== NULL && $order->plan_id !== $user->plan_id && ($user->expired_at > time() || $user->expired_at === NULL)) {
|
||||
if (!(int)config('v2board.plan_change_enable', 1)) abort(500, '目前不允许更改订阅,请联系客服或提交工单操作');
|
||||
@ -156,7 +156,7 @@ class OrderService
|
||||
if ($user->expired_at === NULL) {
|
||||
$this->getSurplusValueByOneTime($user, $order);
|
||||
} else {
|
||||
$this->getSurplusValueByCycle($user, $order);
|
||||
$this->getSurplusValueByPeriod($user, $order);
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,23 +170,23 @@ class OrderService
|
||||
}
|
||||
$notUsedTraffic = $plan->transfer_enable - (($user->u + $user->d) / 1073741824);
|
||||
$result = $trafficUnitPrice * $notUsedTraffic;
|
||||
$orderModel = Order::where('user_id', $user->id)->where('cycle', '!=', 'reset_price')->where('status', 3);
|
||||
$orderModel = Order::where('user_id', $user->id)->where('period', '!=', 'reset_price')->where('status', 3);
|
||||
$order->surplus_amount = $result > 0 ? $result : 0;
|
||||
$order->surplus_order_ids = array_column($orderModel->get()->toArray(), 'id');
|
||||
}
|
||||
|
||||
private function orderIsUsed(Order $order):bool
|
||||
{
|
||||
$month = self::STR_TO_TIME[$order->cycle];
|
||||
$month = self::STR_TO_TIME[$order->period];
|
||||
$orderExpireDay = strtotime('+' . $month . ' month', $order->created_at);
|
||||
if ($orderExpireDay < time()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private function getSurplusValueByCycle(User $user, Order $order)
|
||||
private function getSurplusValueByPeriod(User $user, Order $order)
|
||||
{
|
||||
$orderModel = Order::where('user_id', $user->id)
|
||||
->where('cycle', '!=', 'reset_price')
|
||||
->where('period', '!=', 'reset_price')
|
||||
->where('status', 3);
|
||||
$orders = $orderModel->get();
|
||||
$orderSurplusMonth = 0;
|
||||
@ -194,9 +194,9 @@ class OrderService
|
||||
$userSurplusMonth = ($user->expired_at - time()) / 2678400;
|
||||
foreach ($orders as $k => $item) {
|
||||
// 兼容历史余留问题
|
||||
if ($item->cycle === 'onetime_price') continue;
|
||||
if ($item->period === 'onetime_price') continue;
|
||||
if ($this->orderIsUsed($item)) continue;
|
||||
$orderSurplusMonth = $orderSurplusMonth + self::STR_TO_TIME[$item->cycle];
|
||||
$orderSurplusMonth = $orderSurplusMonth + self::STR_TO_TIME[$item->period];
|
||||
$orderSurplusAmount = $orderSurplusAmount + ($item['total_amount'] + $item['balance_amount'] + $item['surplus_amount'] - $item['refund_amount']);
|
||||
}
|
||||
if (!$orderSurplusMonth || !$orderSurplusAmount) return;
|
||||
@ -252,7 +252,7 @@ class OrderService
|
||||
$this->user->d = 0;
|
||||
}
|
||||
|
||||
private function buyByCycle(Order $order, Plan $plan)
|
||||
private function buyByPeriod(Order $order, Plan $plan)
|
||||
{
|
||||
// change plan process
|
||||
if ((int)$order->type === 3) {
|
||||
@ -265,7 +265,7 @@ class OrderService
|
||||
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);
|
||||
$this->user->expired_at = $this->getTime($order->period, $this->user->expired_at);
|
||||
}
|
||||
|
||||
private function buyByOneTime(Plan $plan)
|
||||
|
Reference in New Issue
Block a user