Kaynağa Gözat

Merge pull request #43 from v2board/dev

1.1.2
tokumeikoi 5 yıl önce
ebeveyn
işleme
c576299a60

+ 5 - 3
app/Console/Commands/CheckOrder.php

@@ -70,9 +70,11 @@ 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);
+        if ($order->type == 3) {
+            $user->expired_at = time();
+        }
+        if ($order->refund_amount) {
+            $user->balance = $user->balance + $order->refund_amount;
         }
         $user->transfer_enable = $plan->transfer_enable * 1073741824;
         $user->enable = 1;

+ 3 - 2
app/Http/Controllers/Admin/ConfigController.php

@@ -29,7 +29,6 @@ class ConfigController extends Controller
                     'app_url' => config('v2board.app_url'),
                     'subscribe_url' => config('v2board.subscribe_url'),
                     'plan_change_enable' => (int)config('v2board.plan_change_enable', 1),
-                    'plan_transfer_hour' => config('v2board.plan_transfer_hour', 12),
                     'try_out_plan_id' => (int)config('v2board.try_out_plan_id', 0),
                     'try_out_hour' => (int)config('v2board.try_out_hour', 1),
                     'email_whitelist_enable' => (int)config('v2board.email_whitelist_enable', 0),
@@ -56,7 +55,9 @@ class ConfigController extends Controller
                     'paytaro_app_secret' => config('v2board.paytaro_app_secret')
                 ],
                 'frontend' => [
-                    'frontend_theme' => config('v2board.frontend_theme', 1),
+                    'frontend_theme_sidebar' => config('v2board.frontend_theme_sidebar', 'light'),
+                    'frontend_theme_header' => config('v2board.frontend_theme_header', 'dark'),
+                    'frontend_theme_color' => config('v2board.frontend_theme_color', 'default'),
                     'frontend_background_url' => config('v2board.frontend_background_url')
                 ],
                 'server' => [

+ 30 - 3
app/Http/Controllers/Server/PoseidonController.php

@@ -13,7 +13,7 @@ use Illuminate\Support\Facades\Cache;
 
 class PoseidonController extends Controller
 {
-    CONST SERVER_CONFIG = '{"api":{"services":["HandlerService","StatsService"],"tag":"api"},"stats":{},"inbound":{"port":443,"protocol":"vmess","settings":{"clients":[]},"streamSettings":{"network":"tcp"},"tag":"proxy"},"inboundDetour":[{"listen":"0.0.0.0","port":23333,"protocol":"dokodemo-door","settings":{"address":"0.0.0.0"},"tag":"api"}],"log":{"loglevel":"debug","access":"access.log","error":"error.log"},"outbound":{"protocol":"freedom","settings":{}},"routing":{"settings":{"rules":[{"inboundTag":["api"],"outboundTag":"api","type":"field"}]},"strategy":"rules"},"policy":{"levels":{"0":{"handshake":4,"connIdle":300,"uplinkOnly":5,"downlinkOnly":30,"statsUserUplink":true,"statsUserDownlink":true}}}}';
+    CONST SERVER_CONFIG = '{"api":{"services":["HandlerService","StatsService"],"tag":"api"},"stats":{},"inbound":{"port":443,"protocol":"vmess","settings":{"clients":[]},"streamSettings":{"network":"tcp"},"tag":"proxy"},"inboundDetour":[{"listen":"0.0.0.0","port":23333,"protocol":"dokodemo-door","settings":{"address":"0.0.0.0"},"tag":"api"}],"log":{"loglevel":"debug","access":"access.log","error":"error.log"},"outbound":{"protocol":"freedom","settings":{}},"outboundDetour":[{"protocol":"blackhole","settings":{},"tag":"block"}],"routing":{"settings":{"rules":[{"inboundTag":["api"],"outboundTag":"api","type":"field"}]},"strategy":"rules"},"policy":{"levels":{"0":{"handshake":4,"connIdle":300,"uplinkOnly":5,"downlinkOnly":30,"statsUserUplink":true,"statsUserDownlink":true}}}}';
 
     // 后端获取用户
     public function user(Request $request)
@@ -40,6 +40,8 @@ class PoseidonController extends Controller
                 'v2ray_alter_id',
                 'v2ray_level'
             ])
+            ->whereRaw('u + d < transfer_enable')
+            ->where('enable', 1)
             ->get();
         $result = [];
         foreach ($users as $user) {
@@ -131,9 +133,34 @@ class PoseidonController extends Controller
                     break;
             }
         }
+
+        if ($server->rules) {
+            $rules = json_decode($server->rules);
+            // domain
+            if (isset($rules->domain)) {
+                $domainObj = new \StdClass();
+                $domainObj->type = 'field';
+                $domainObj->domain = $rules->domain;
+                $domainObj->outboundTag = 'block';
+                array_push($json->routing->settings->rules, $domainObj);
+            }
+            // protocol
+            if (isset($rules->protocol)) {
+                $protocolObj = new \StdClass();
+                $protocolObj->type = 'field';
+                $protocolObj->protocol = $rules->protocol;
+                $protocolObj->outboundTag = 'block';
+                array_push($json->routing->settings->rules, $protocolObj);
+            }
+        }
+
         if ((int)$server->tls) {
-            $json->inbound->streamSettings->security = "tls";
-            $tls = (object)array("certificateFile" => "/home/v2ray.crt", "keyFile" => "/home/v2ray.key");
+            $json->inbound->streamSettings->security = 'tls';
+            $tls = (object)[
+                'certificateFile' => '/home/v2ray.crt',
+                'keyFile' => '/home/v2ray.key'
+            ];
+            $json->inbound->streamSettings->tlsSettings = new \StdClass();
             $json->inbound->streamSettings->tlsSettings->certificates[0] = $tls;
         }
 

+ 33 - 8
app/Http/Controllers/User/OrderController.php

@@ -51,7 +51,6 @@ class OrderController extends Controller
             abort(500, '订单不存在');
         }
         $order['plan'] = Plan::find($order->plan_id);
-        $order['plan_transfer_hour'] = config('v2board.plan_transfer_hour', 12);
         $order['try_out_plan_id'] = (int)config('v2board.try_out_plan_id');
         if (!$order['plan']) {
             abort(500, '订阅不存在');
@@ -72,6 +71,24 @@ class OrderController extends Controller
         return true;
     }
 
+    // surplus value
+    private function getSurplusValue(User $user)
+    {
+        $plan = Plan::find($user->plan_id);
+        $dayPrice = 0;
+        if ($plan->month_price) {
+            $dayPrice = $plan->month_price / 30;
+        } else if ($plan->quarter_price) {
+            $dayPrice = $plan->quarter_price / 91;
+        } else if ($plan->half_year_price) {
+            $dayPrice = $plan->half_year_price / 183;
+        } 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 +139,15 @@ 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->surplus_amount = $this->getSurplusValue($user);
+            if ($order->surplus_amount >= $order->total_amount) {
+                $order->refund_amount = $order->surplus_amount - $order->total_amount;
+                $order->total_amount = 0;
+            } else {
+                $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 {
@@ -155,12 +179,6 @@ class OrderController extends Controller
         // discount complete
         $order->total_amount = $order->total_amount - $order->discount_amount;
         // discount end
-
-        // free process
-        if ($order->total_amount <= 0) {
-            $order->total_amount = 0;
-            $order->status = 1;
-        }
         // invite process
         if ($user->invite_user_id && $order->total_amount > 0) {
             $order->invite_user_id = $user->invite_user_id;
@@ -194,6 +212,13 @@ class OrderController extends Controller
         if (!$order) {
             abort(500, '订单不存在或已支付');
         }
+        // free process
+        if ($order->total_amount <= 0) {
+            $order->total_amount = 0;
+            $order->status = 1;
+            $order->save();
+            exit();
+        }
         switch ($method) {
             // return type => 0: QRCode / 1: URL
             case 0:

+ 3 - 2
app/Http/Requests/Admin/ConfigSave.php

@@ -18,7 +18,6 @@ class ConfigSave extends FormRequest
         'app_description' => '',
         'app_url' => 'url',
         'subscribe_url' => 'url',
-        'plan_transfer_hour' => 'numeric',
         'plan_change_enable' => 'in:0,1',
         'try_out_enable' => 'in:0,1',
         'try_out_plan_id' => 'integer',
@@ -47,7 +46,9 @@ class ConfigSave extends FormRequest
         'paytaro_app_id' => '',
         'paytaro_app_secret' => '',
         // frontend
-        'frontend_theme' => 'in:1,2',
+        'frontend_theme_sidebar' => 'in:dark,light',
+        'frontend_theme_header' => 'in:dark,light',
+        'frontend_theme_color' => 'in:default,darkblue,black',
         'frontend_background_url' => 'nullable|url',
         // tutorial
         'apple_id' => 'email',

+ 1 - 0
app/Http/Routes/PassportRoute.php

@@ -21,6 +21,7 @@ class PassportRoute
             // Comm
             $router->get ('/comm/config', 'Passport\\CommController@config');
             $router->post('/comm/sendEmailVerify', 'Passport\\CommController@sendEmailVerify');
+            $router->post('/comm/pv', 'Passport\\CommController@pv');
         });
     }
 }

+ 1 - 1
config/app.php

@@ -234,5 +234,5 @@ return [
     |--------------------------------------------------------------------------
     */
 
-    'version' => '1.1.1'
+    'version' => '1.1.2'
 ];

+ 6 - 0
database/update.sql

@@ -156,3 +156,9 @@ CREATE TABLE `failed_jobs` (
 
 ALTER TABLE `v2_user`
 ADD `discount` int(11) NULL AFTER `balance`;
+
+ALTER TABLE `v2_order`
+ADD `surplus_amount` int(11) NULL COMMENT '剩余价值' AFTER `discount_amount`;
+
+ALTER TABLE `v2_order`
+ADD `refund_amount` int(11) NULL COMMENT '退款金额' AFTER `surplus_amount`;

Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
public/assets/admin/antd.chunk.css


+ 5 - 3
public/assets/admin/env.example.js

@@ -1,12 +1,14 @@
 window.v2board = {
   // 站点标题
   title: 'V2Board',
-  // 站点描述
-  description: 'V2Board is best',
   // API
   host: '',
   // 主题
-  theme: '1',
+  theme: {
+    sidebar: 'light',
+    header: 'dark',
+    color: 'default'
+  },
   // 背景
   background_url: ''
 }

Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
public/assets/admin/theme/black.css


Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
public/assets/admin/theme/darkblue.css


Dosya farkı çok büyük olduğundan ihmal edildi
+ 1 - 0
public/assets/admin/theme/default.css


Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 6
public/assets/admin/umi.css


Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
public/assets/admin/umi.js


Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
public/assets/user/antd.chunk.css


+ 5 - 1
public/assets/user/env.example.js

@@ -6,7 +6,11 @@ window.v2board = {
   // API
   host: '',
   // 主题
-  theme: '1',
+  theme: {
+    sidebar: 'light',
+    header: 'dark',
+    color: 'default'
+  },
   // 背景
   background_url: ''
 }

Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
public/assets/user/theme/black.css


Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
public/assets/user/theme/darkblue.css


Dosya farkı çok büyük olduğundan ihmal edildi
+ 1 - 0
public/assets/user/theme/default.css


Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 6
public/assets/user/umi.css


Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
public/assets/user/umi.js


+ 5 - 1
resources/views/admin.blade.php

@@ -13,7 +13,11 @@
     <script>
         window.v2board = {
             title: '{{$title}}',
-            theme: '{{$theme}}',
+            theme: {
+                sidebar: '{{$theme_sidebar}}',
+                header: '{{$theme_header}}',
+                color: '{{$theme_color}}',
+            },
             verison: '{{$verison}}',
             background_url: '{{$backgroun_url}}'
         }

+ 5 - 1
resources/views/app.blade.php

@@ -13,7 +13,11 @@
     <script>
         window.v2board = {
             title: '{{$title}}',
-            theme: '{{$theme}}',
+            theme: {
+                sidebar: '{{$theme_sidebar}}',
+                header: '{{$theme_header}}',
+                color: '{{$theme_color}}',
+            },
             verison: '{{$verison}}',
             background_url: '{{$backgroun_url}}',
             description: '{{$description}}'

+ 6 - 2
routes/web.php

@@ -21,7 +21,9 @@ Route::get('/', function (Request $request) {
     }
     return view('app', [
         'title' => config('v2board.app_name', 'V2Board'),
-        'theme' => config('v2board.frontend_theme', 1),
+        'theme_sidebar' => config('v2board.frontend_theme_sidebar', 'light'),
+        'theme_header' => config('v2board.frontend_theme_header', 'dark'),
+        'theme_color' => config('v2board.frontend_theme_color', 'default'),
         'backgroun_url' => config('v2board.frontend_background_url'),
         'verison' => config('app.version'),
         'description' => config('v2board.app_description', 'V2Board is best')
@@ -31,7 +33,9 @@ Route::get('/', function (Request $request) {
 Route::get('/admin', function () {
     return view('admin', [
         'title' => config('v2board.app_name', 'V2Board'),
-        'theme' => config('v2board.frontend_theme', 1),
+        'theme_sidebar' => config('v2board.frontend_theme_sidebar', 'light'),
+        'theme_header' => config('v2board.frontend_theme_header', 'dark'),
+        'theme_color' => config('v2board.frontend_theme_color', 'default'),
         'backgroun_url' => config('v2board.frontend_background_url'),
         'verison' => config('app.version')
     ]);

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor