浏览代码

Add 套餐添加限速功能

BobCoderS9 4 年之前
父节点
当前提交
6f37cb6b0f

+ 0 - 1
app/Http/Controllers/Admin/ShopController.php

@@ -109,7 +109,6 @@ class ShopController extends Controller
                 return $path;
                 return $path;
             }
             }
         }
         }
-
         try {
         try {
             $data['is_hot'] = array_key_exists('is_hot', $data) ? 1 : 0;
             $data['is_hot'] = array_key_exists('is_hot', $data) ? 1 : 0;
             $data['status'] = array_key_exists('status', $data) ? 1 : 0;
             $data['status'] = array_key_exists('status', $data) ? 1 : 0;

+ 7 - 1
app/Http/Controllers/Api/WebApi/TrojanController.php

@@ -27,10 +27,16 @@ class TrojanController extends BaseController
     public function getUserList(Node $node): JsonResponse
     public function getUserList(Node $node): JsonResponse
     {
     {
         foreach ($node->users() as $user) {
         foreach ($node->users() as $user) {
+            $order = $user->orders()->activePlan()->first(); // 取出用户正在使用的套餐
+            if ($order) {
+                $speed_limit = $order->goods->getRawOriginal('speed_limit');
+            } else {
+                $speed_limit = $user->getRawOriginal('speed_limit');
+            }
             $data[] = [
             $data[] = [
                 'uid' => $user->id,
                 'uid' => $user->id,
                 'password' => $user->passwd,
                 'password' => $user->passwd,
-                'speed_limit' => $user->getRawOriginal('speed_limit'),
+                'speed_limit' => $speed_limit,
             ];
             ];
         }
         }
 
 

+ 7 - 1
app/Http/Controllers/Api/WebApi/V2RayController.php

@@ -44,10 +44,16 @@ class V2RayController extends BaseController
     public function getUserList(Node $node): JsonResponse
     public function getUserList(Node $node): JsonResponse
     {
     {
         foreach ($node->users() as $user) {
         foreach ($node->users() as $user) {
+            $order = $user->orders()->activePlan()->first(); // 取出用户正在使用的套餐
+            if ($order) {
+                $speed_limit = $order->goods->getRawOriginal('speed_limit');
+            } else {
+                $speed_limit = $user->getRawOriginal('speed_limit');
+            }
             $data[] = [
             $data[] = [
                 'uid' => $user->id,
                 'uid' => $user->id,
                 'vmess_uid' => $user->vmess_id,
                 'vmess_uid' => $user->vmess_id,
-                'speed_limit' => $user->getRawOriginal('speed_limit'),
+                'speed_limit' => $speed_limit,
             ];
             ];
         }
         }
 
 

+ 7 - 1
app/Http/Controllers/Api/WebApi/VNetController.php

@@ -32,6 +32,12 @@ class VNetController extends BaseController
     public function getUserList(Node $node): JsonResponse
     public function getUserList(Node $node): JsonResponse
     {
     {
         foreach ($node->users() as $user) {
         foreach ($node->users() as $user) {
+            $order = $user->orders()->activePlan()->first(); // 取出用户正在使用的套餐
+            if ($order) {
+                $speed_limit = $order->goods->getRawOriginal('speed_limit');
+            } else {
+                $speed_limit = $user->getRawOriginal('speed_limit');
+            }
             $data[] = [
             $data[] = [
                 'uid' => $user->id,
                 'uid' => $user->id,
                 'port' => $user->port,
                 'port' => $user->port,
@@ -40,7 +46,7 @@ class VNetController extends BaseController
                 'protocol' => $user->protocol,
                 'protocol' => $user->protocol,
                 'obfs' => $user->obfs,
                 'obfs' => $user->obfs,
                 'obfs_param' => $node->obfs_param,
                 'obfs_param' => $node->obfs_param,
-                'speed_limit' => $user->getRawOriginal('speed_limit'),
+                'speed_limit' => $speed_limit,
                 'enable' => $user->enable,
                 'enable' => $user->enable,
             ];
             ];
         }
         }

+ 1 - 0
app/Http/Requests/Admin/ShopStoreRequest.php

@@ -19,6 +19,7 @@ class ShopStoreRequest extends FormRequest
             'traffic_unit' => 'numeric|nullable',
             'traffic_unit' => 'numeric|nullable',
             'invite_num' => 'numeric',
             'invite_num' => 'numeric',
             'limit_num' => 'numeric',
             'limit_num' => 'numeric',
+            'speed_limit' => 'numeric',
             'days' => 'required|numeric',
             'days' => 'required|numeric',
             'is_hot' => 'nullable|string',
             'is_hot' => 'nullable|string',
             'status' => 'nullable|string',
             'status' => 'nullable|string',

+ 1 - 0
app/Http/Requests/Admin/ShopUpdateRequest.php

@@ -19,6 +19,7 @@ class ShopUpdateRequest extends FormRequest
             'is_hot' => 'nullable|string',
             'is_hot' => 'nullable|string',
             'status' => 'nullable|string',
             'status' => 'nullable|string',
             'sort' => 'numeric',
             'sort' => 'numeric',
+            'speed_limit' => 'numeric',
             'color' => 'nullable|string',
             'color' => 'nullable|string',
             'logo' => 'nullable|image',
             'logo' => 'nullable|image',
             'description' => 'nullable|string',
             'description' => 'nullable|string',

+ 10 - 0
app/Models/Goods.php

@@ -45,4 +45,14 @@ class Goods extends Model
     {
     {
         return flowAutoShow($this->attributes['traffic'] * MB);
         return flowAutoShow($this->attributes['traffic'] * MB);
     }
     }
+
+    public function getSpeedLimitAttribute($value)
+    {
+        return $value / Mbps;
+    }
+
+    public function setSpeedLimitAttribute($value)
+    {
+        return $this->attributes['speed_limit'] = $value * Mbps;
+    }
 }
 }

+ 32 - 0
database/migrations/2021_07_23_151321_append_speed_limit_goods_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AppendSpeedLimitGoodsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('goods', function (Blueprint $table) {
+            $table->bigInteger('speed_limit')->unsigned()->default(0)->comment('商品限速')->after('limit_num');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('goods', function (Blueprint $table) {
+            $table->dropColumn(['speed_limit']);
+        });
+    }
+}

+ 12 - 2
resources/views/admin/shop/info.blade.php

@@ -73,6 +73,14 @@
                                     <span class="input-group-text">元</span>
                                     <span class="input-group-text">元</span>
                                 </div>
                                 </div>
                             </div>
                             </div>
+                            <div class="form-group row package-renew">
+                                <label class="col-md-2 col-form-label" for="speed_limit">用户限速</label>
+                                <div class="col-md-4 input-group">
+                                    <input type="number" style="width: 30%" class="form-control" name="speed_limit" id="speed_limit" value="0"/>
+                                    <span class="input-group-text"> Mbps</span>
+                                    <span class="text-help">为 0 时不限速 </span>
+                                </div>
+                            </div>
                             <div class="form-group row package-renew">
                             <div class="form-group row package-renew">
                                 <label class="col-md-2 col-form-label" for="period">重置周期</label>
                                 <label class="col-md-2 col-form-label" for="period">重置周期</label>
                                 <div class="col-md-4 input-group">
                                 <div class="col-md-4 input-group">
@@ -116,6 +124,8 @@
                                     <span class="text-help"> 到期后会自动从总流量扣减对应的流量 </span>
                                     <span class="text-help"> 到期后会自动从总流量扣减对应的流量 </span>
                                 </div>
                                 </div>
                             </div>
                             </div>
+                        </div>
+                        <div class="col-lg-6 col-md-12">
                             <div class="form-group row">
                             <div class="form-group row">
                                 <label class="col-md-2 col-form-label" for="is_hot">热销</label>
                                 <label class="col-md-2 col-form-label" for="is_hot">热销</label>
                                 <div class="col-md-10">
                                 <div class="col-md-10">
@@ -130,8 +140,6 @@
                                            data-on-text="上架" data-off-text="下架" data-size="small">
                                            data-on-text="上架" data-off-text="下架" data-size="small">
                                 </div>
                                 </div>
                             </div>
                             </div>
-                        </div>
-                        <div class="col-lg-6 col-md-12">
                             <div class="form-group row">
                             <div class="form-group row">
                                 <label class="col-md-2 col-form-label" for="sort">排序</label>
                                 <label class="col-md-2 col-form-label" for="sort">排序</label>
                                 <div class="col-md-4">
                                 <div class="col-md-4">
@@ -197,6 +205,7 @@
             $('#level').selectpicker('val', '{{$good->level}}');
             $('#level').selectpicker('val', '{{$good->level}}');
             @if ($good->type == 2)
             @if ($good->type == 2)
             $('#renew').val('{{$good->renew}}');
             $('#renew').val('{{$good->renew}}');
+            $('#speed_limit').val('{{$good->speed_limit}}');
             $('#period').val('{{$good->period}}');
             $('#period').val('{{$good->period}}');
             $('#days').val('{{$good->days}}').attr('disabled', true);
             $('#days').val('{{$good->days}}').attr('disabled', true);
             @endif
             @endif
@@ -239,6 +248,7 @@
             $('#level').selectpicker('val', '{{old('level')}}');
             $('#level').selectpicker('val', '{{old('level')}}');
             @if (old('type') == 2)
             @if (old('type') == 2)
             $('#renew').val('{{old('renew',0)}}');
             $('#renew').val('{{old('renew',0)}}');
+            $('#speed_limit').val('{{old('speed_limit',0)}}');
             $('#period').val('{{old('period',0)}}');
             $('#period').val('{{old('period',0)}}');
             $('#days').val('{{old('days',0)}}');
             $('#days').val('{{old('days',0)}}');
             @endif
             @endif

+ 2 - 0
resources/views/user/buy.blade.php

@@ -23,6 +23,8 @@
                                 <strong>{{$goods->type === 1? $dataPlusDays:$goods->days}} {{trans('validation.attributes.day')}}</strong>
                                 <strong>{{$goods->type === 1? $dataPlusDays:$goods->days}} {{trans('validation.attributes.day')}}</strong>
                                 <br>
                                 <br>
                                 <strong>{{$goods->traffic_label}}</strong> {{trans('user.attribute.data')}}
                                 <strong>{{$goods->traffic_label}}</strong> {{trans('user.attribute.data')}}
+                                <br>
+                                {{trans('user.account.speed_limit')}}<strong>{{$goods->speed_limit}} MB</strong>
                             </td>
                             </td>
                             <td class="text-middle"> ¥{{$goods->price}} </td>
                             <td class="text-middle"> ¥{{$goods->price}} </td>
                             <td class="text-middle"> x 1</td>
                             <td class="text-middle"> x 1</td>

+ 4 - 1
resources/views/user/services.blade.php

@@ -73,9 +73,12 @@
                                         </div>
                                         </div>
                                         <ul class="pricing-features">
                                         <ul class="pricing-features">
                                             <li>
                                             <li>
-                                                <strong>{{$goods->traffic_label}}</strong>{{trans('user.attribute.data')}}
+                                                <strong>{{$goods->traffic_label}} </strong>{{trans('user.attribute.data')}}
                                                 {!!$goods->type === 1? ' <code>'.$dataPlusDays.'</code> '.trans('validation.attributes.day'):'/'.trans('validation.attributes.month')!!}
                                                 {!!$goods->type === 1? ' <code>'.$dataPlusDays.'</code> '.trans('validation.attributes.day'):'/'.trans('validation.attributes.month')!!}
                                             </li>
                                             </li>
+                                            <li>
+                                                {{trans('user.account.speed_limit')}}<strong> {{ $goods->speed_limit > 0 ? $goods->speed_limit.' MB' : '不限速' }} </strong>
+                                            </li>
                                             {!!$goods->info!!}
                                             {!!$goods->info!!}
                                         </ul>
                                         </ul>
                                         <div class="pricing-footer text-center bg-blue-grey-100">
                                         <div class="pricing-footer text-center bg-blue-grey-100">