Browse Source

Fix #130 & 简化switch使用情况

兔姬桑 4 years ago
parent
commit
7bd21336ad

+ 5 - 4
app/Http/Controllers/Controller.php

@@ -107,18 +107,19 @@ class Controller extends BaseController
     // 节点信息
     // 节点信息
     public function getUserNodeInfo(array $server, bool $is_url): ?string
     public function getUserNodeInfo(array $server, bool $is_url): ?string
     {
     {
+        $type = $is_url ? new URLSchemes() : new Text();
         switch ($server['type']) {
         switch ($server['type']) {
             case'shadowsocks':
             case'shadowsocks':
-                $data = $is_url ? URLSchemes::buildShadowsocks($server) : Text::buildShadowsocks($server);
+                $data = $type->buildShadowsocks($server);
                 break;
                 break;
             case 'shadowsocksr':
             case 'shadowsocksr':
-                $data = $is_url ? URLSchemes::buildShadowsocksr($server) : Text::buildShadowsocksr($server);
+                $data = $type->buildShadowsocksr($server);
                 break;
                 break;
             case 'v2ray':
             case 'v2ray':
-                $data = $is_url ? URLSchemes::buildVmess($server) : Text::buildVmess($server);
+                $data = $type->buildVmess($server);
                 break;
                 break;
             case 'trojan':
             case 'trojan':
-                $data = $is_url ? URLSchemes::buildTrojan($server) : Text::buildTrojan($server);
+                $data = $type->buildTrojan($server);
                 break;
                 break;
             default:
             default:
         }
         }

+ 1 - 14
app/Http/Controllers/Gateway/EPay.php

@@ -15,22 +15,9 @@ class EPay extends AbstractPayment
     {
     {
         $payment = $this->creatNewPayment(Auth::id(), $request->input('id'), $request->input('amount'));
         $payment = $this->creatNewPayment(Auth::id(), $request->input('id'), $request->input('amount'));
 
 
-        switch ($request->input('type')) {
-            case 2:
-                $type = 'qqpay';
-                break;
-            case 3:
-                $type = 'wxpay';
-                break;
-            case 1:
-            default:
-                $type = 'alipay';
-                break;
-        }
-
         $data = [
         $data = [
             'pid'          => sysConfig('epay_mch_id'),
             'pid'          => sysConfig('epay_mch_id'),
-            'type'         => $type,
+            'type'         => [1 => 'alipay', 2 => 'qqpay', 3 => 'wxpay'][$request->input('type')] ?? 'alipay',
             'notify_url'   => route('payment.notify', ['method' => 'epay']),
             'notify_url'   => route('payment.notify', ['method' => 'epay']),
             'return_url'   => route('invoice'),
             'return_url'   => route('invoice'),
             'out_trade_no' => $payment->trade_no,
             'out_trade_no' => $payment->trade_no,

+ 5 - 14
app/Models/Marketing.php

@@ -13,19 +13,10 @@ class Marketing extends Model
 
 
     public function getStatusLabelAttribute(): string
     public function getStatusLabelAttribute(): string
     {
     {
-        $status_label = '';
-        switch ($this->attributes['status']) {
-            case -1:
-                $status_label = '失败';
-                break;
-            case 0:
-                $status_label = '待推送';
-                break;
-            case 1:
-                $status_label = '成功';
-                break;
-        }
-
-        return $status_label;
+        return [
+            -1 => '失败',
+            0  => '待推送',
+            1  => '成功',
+        ][$this->attributes['status']] ?? '';
     }
     }
 }
 }

+ 6 - 18
app/Models/Node.php

@@ -178,23 +178,11 @@ class Node extends Model
 
 
     public function getTypeLabelAttribute(): string
     public function getTypeLabelAttribute(): string
     {
     {
-        switch ($this->attributes['type']) {
-            case 1:
-                $type_label = 'ShadowsocksR';
-                break;
-            case 2:
-                $type_label = 'V2Ray';
-                break;
-            case 3:
-                $type_label = 'Trojan';
-                break;
-            case 4:
-                $type_label = 'VNet';
-                break;
-            default:
-                $type_label = 'UnKnown';
-        }
-
-        return $type_label;
+        return [
+            1 => 'ShadowsocksR',
+            2 => 'V2Ray',
+            3 => 'Trojan',
+            4 => 'VNet',
+        ][$this->attributes['type']] ?? 'UnKnown';
     }
     }
 }
 }

+ 11 - 83
app/Models/Order.php

@@ -155,98 +155,26 @@ class Order extends Model
     // 支付渠道
     // 支付渠道
     public function getPayTypeLabelAttribute(): string
     public function getPayTypeLabelAttribute(): string
     {
     {
-        switch ($this->attributes['pay_type']) {
-            case 0:
-                $pay_type_label = trans('common.payment.credit');
-                break;
-            case 1:
-                $pay_type_label = trans('common.payment.alipay');
-                break;
-            case 2:
-                $pay_type_label = 'QQ';
-                break;
-            case 3:
-                $pay_type_label = trans('common.payment.wechat');
-                break;
-            case 4:
-                $pay_type_label = trans('common.payment.crypto');
-                break;
-            case 5:
-                $pay_type_label = 'PayPal';
-                break;
-            case 6:
-                $pay_type_label = 'Stripe';
-                break;
-            default:
-                $pay_type_label = '';
-        }
-
-        return $pay_type_label;
+        return [
+            0 => trans('common.payment.credit'),
+            1 => trans('common.payment.alipay'),
+            2 => 'QQ',
+            3 => trans('common.payment.wechat'),
+            4 => trans('common.payment.crypto'),
+            5 => 'PayPal',
+            6 => 'Stripe',
+        ][$this->attributes['pay_type']] ?? '';
     }
     }
 
 
     // 支付图标
     // 支付图标
     public function getPayTypeIconAttribute(): string
     public function getPayTypeIconAttribute(): string
     {
     {
-        $base_path = '/assets/images/payment/';
-
-        switch ($this->attributes['pay_type']) {
-            case 1:
-                $pay_type_icon = $base_path.'alipay.png';
-                break;
-            case 2:
-                $pay_type_icon = $base_path.'qq.png';
-                break;
-            case 3:
-                $pay_type_icon = $base_path.'wechat.png';
-                break;
-            case 5:
-                $pay_type_icon = $base_path.'paypal.png';
-                break;
-            case 6:
-                $pay_type_icon = $base_path.'stripe.png';
-                break;
-            default:
-                $pay_type_icon = $base_path.'coin.png';
-        }
-
-        return $pay_type_icon;
+        return '/assets/images/payment/'.config('common.payment.icon')[$this->attributes['pay_type']] ?? 'coin.png';
     }
     }
 
 
     // 支付方式
     // 支付方式
     public function getPayWayLabelAttribute(): string
     public function getPayWayLabelAttribute(): string
     {
     {
-        switch ($this->attributes['pay_way']) {
-            case 'credit':
-                $pay_way_label = '余额';
-                break;
-            case 'youzan':
-                $pay_way_label = '有赞云';
-                break;
-            case 'f2fpay':
-                $pay_way_label = '支付宝当面付';
-                break;
-            case 'codepay':
-                $pay_way_label = '码支付';
-                break;
-            case 'payjs':
-                $pay_way_label = 'PayJs';
-                break;
-            case 'bitpayx':
-                $pay_way_label = '麻瓜宝';
-                break;
-            case 'paypal':
-                $pay_way_label = 'PayPal';
-                break;
-            case 'stripe':
-                $pay_way_label = 'Stripe';
-                break;
-            case 'paybeaver':
-                $pay_way_label = '海狸支付';
-                break;
-            default:
-                $pay_way_label = '未知';
-        }
-
-        return $pay_way_label;
+        return config('common.payment.labels')[$this->attributes['pay_way']] ?? '未知';
     }
     }
 }
 }

+ 6 - 17
app/Models/PaymentCallback.php

@@ -13,22 +13,11 @@ class PaymentCallback extends Model
 
 
     public function getStatusLabelAttribute(): string
     public function getStatusLabelAttribute(): string
     {
     {
-        $status_label = '';
-        switch ($this->attributes['status']) {
-            case 'WAIT_BUYER_PAY':
-                $status_label = '等待买家付款';
-                break;
-            case 'WAIT_SELLER_SEND_GOODS':
-                $status_label = '等待卖家发货';
-                break;
-            case 'TRADE_SUCCESS':
-                $status_label = '交易成功';
-                break;
-            case 'PAID':
-                $status_label = '支付完成';
-                break;
-        }
-
-        return $status_label;
+        return [
+            'WAIT_BUYER_PAY'         => '等待买家付款',
+            'WAIT_SELLER_SEND_GOODS' => '等待卖家发货',
+            'TRADE_SUCCESS'          => '交易成功',
+            'PAID'                   => '支付完成',
+        ][$this->attributes['status']] ?? '';
     }
     }
 }
 }

+ 12 - 36
app/Models/Rule.php

@@ -15,46 +15,22 @@ class Rule extends Model
 
 
     public function getTypeLabelAttribute(): string
     public function getTypeLabelAttribute(): string
     {
     {
-        switch ($this->attributes['type']) {
-            case 1:
-                $type_label = '正则表达式';
-                break;
-            case 2:
-                $type_label = '域 名';
-                break;
-            case 3:
-                $type_label = 'I P';
-                break;
-            case 4:
-                $type_label = '协 议';
-                break;
-            default:
-                $type_label = '未 知';
-        }
-
-        return $type_label;
+        return [
+            1 => '正则表达式',
+            2 => '域 名',
+            3 => 'I P',
+            4 => '协 议',
+        ][$this->attributes['type']] ?? '未 知';
     }
     }
 
 
     public function getTypeApiLabelAttribute(): string
     public function getTypeApiLabelAttribute(): string
     {
     {
-        switch ($this->attributes['type']) {
-            case 1:
-                $type_api_label = 'reg';
-                break;
-            case 2:
-                $type_api_label = 'domain';
-                break;
-            case 3:
-                $type_api_label = 'ip';
-                break;
-            case 4:
-                $type_api_label = 'protocol';
-                break;
-            default:
-                $type_api_label = 'unknown';
-        }
-
-        return $type_api_label;
+        return [
+            1 => 'reg',
+            2 => 'domain',
+            3 => 'ip',
+            4 => 'protocol',
+        ][$this->attributes['type']] ?? 'unknown';
     }
     }
 
 
     public function rule_groups()
     public function rule_groups()

+ 9 - 21
app/Providers/SettingServiceProvider.php

@@ -11,11 +11,6 @@ use NotificationChannels\Telegram\TelegramChannel;
 
 
 class SettingServiceProvider extends ServiceProvider
 class SettingServiceProvider extends ServiceProvider
 {
 {
-    /**
-     * Bootstrap services.
-     *
-     * @return void
-     */
     public function boot()
     public function boot()
     {
     {
         $toApp = collect([
         $toApp = collect([
@@ -26,7 +21,6 @@ class SettingServiceProvider extends ServiceProvider
             'hcaptcha_secret'        => 'HCaptcha.secret',
             'hcaptcha_secret'        => 'HCaptcha.secret',
             'hcaptcha_sitekey'       => 'HCaptcha.sitekey',
             'hcaptcha_sitekey'       => 'HCaptcha.sitekey',
         ]);
         ]);
-
         $notifications = collect([
         $notifications = collect([
             'account_expire_notification',
             'account_expire_notification',
             'data_anomaly_notification',
             'data_anomaly_notification',
@@ -40,25 +34,22 @@ class SettingServiceProvider extends ServiceProvider
             'ticket_created_notification',
             'ticket_created_notification',
             'ticket_replied_notification',
             'ticket_replied_notification',
         ]);
         ]);
-
+        $payments = ['is_AliPay', 'is_QQPay', 'is_WeChatPay', 'is_otherPay'];
         $settings = Config::all();
         $settings = Config::all();
-
         $modified = $settings
         $modified = $settings
             ->whereNotIn('name', $toApp->keys()->merge($notifications)) // 设置一般系统选项
             ->whereNotIn('name', $toApp->keys()->merge($notifications)) // 设置一般系统选项
             ->pluck('value', 'name')
             ->pluck('value', 'name')
             ->merge($settings->whereIn('name', $notifications)->pluck('value', 'name')->map(function ($item) {
             ->merge($settings->whereIn('name', $notifications)->pluck('value', 'name')->map(function ($item) {
                 return self::setChannel(json_decode($item, true) ?? []);
                 return self::setChannel(json_decode($item, true) ?? []);
             })) // 设置通知相关选项
             })) // 设置通知相关选项
-            ->merge(collect(['is_onlinePay' => $settings->whereIn('name', ['is_AliPay', 'is_QQPay', 'is_WeChatPay', 'is_otherPay'])->pluck('value')->filter()->isNotEmpty(),
-            ])) // 设置在线支付开关
-            ->sortKeys();
+            ->merge(collect(['is_onlinePay' => $settings->whereIn('name', $payments)->pluck('value')->filter()->isNotEmpty()])) // 设置在线支付开关
+            ->sortKeys()
+            ->toArray();
 
 
         config(['settings' => $modified]); // 设置系统参数
         config(['settings' => $modified]); // 设置系统参数
-
         $settings->whereIn('name', $toApp->keys())->pluck('value', 'name')->each(function ($item, $key) use ($toApp) {
         $settings->whereIn('name', $toApp->keys())->pluck('value', 'name')->each(function ($item, $key) use ($toApp) {
             config([$toApp[$key] => $item]); // 设置PHP软件包相关配置
             config([$toApp[$key] => $item]); // 设置PHP软件包相关配置
         });
         });
-
         collect([
         collect([
             'website_name' => 'app.name',
             'website_name' => 'app.name',
             'website_url'  => 'app.url',
             'website_url'  => 'app.url',
@@ -69,18 +60,15 @@ class SettingServiceProvider extends ServiceProvider
 
 
     private static function setChannel(array $channels)
     private static function setChannel(array $channels)
     {
     {
-        $options = [
+        return collect([
             'telegram'   => TelegramChannel::class,
             'telegram'   => TelegramChannel::class,
             'beary'      => BearyChatChannel::class,
             'beary'      => BearyChatChannel::class,
             'bark'       => BarkChannel::class,
             'bark'       => BarkChannel::class,
             'serverChan' => ServerChanChannel::class,
             'serverChan' => ServerChanChannel::class,
-        ];
-        foreach ($options as $option => $str) {
-            if (($key = array_search($option, $channels, true)) !== false) {
-                $channels[$key] = $str;
+        ])->each(function ($item, $key) use ($channels) {
+            if (array_key_exists($key, $channels)) {
+                $channels[$key] = $item;
             }
             }
-        }
-
-        return $channels;
+        });
     }
     }
 }
 }

+ 28 - 0
config/common.php

@@ -0,0 +1,28 @@
+<?php
+
+return [
+    'payment' => [
+        'labels' => [
+            'bitpayx'   => '麻瓜宝',
+            'codepay'   => '码支付',
+            'credit'    => '余额',
+            'epay'      => '易支付',
+            'f2fpay'    => '支付宝当面付',
+            'paybeaver' => '海狸支付',
+            'payjs'     => 'PayJs',
+            'paypal'    => 'PayPal',
+            'stripe'    => 'Stripe',
+            'youzan'    => '有赞云',
+        ],
+        'icon'   => [
+            0 => 'creditpay.svg',
+            1 => 'alipay.png',
+            2 => 'qq.png',
+            3 => 'wechat.png',
+            4 => 'coin.png',
+            5 => 'paypal.png',
+            6 => 'stripe.png',
+        ],
+
+    ],
+];

+ 3 - 6
resources/views/admin/logs/callback.blade.php

@@ -23,12 +23,9 @@
                     <div class="form-group col-lg-2 col-sm-4">
                     <div class="form-group col-lg-2 col-sm-4">
                         <select class="form-control" name="type" id="type" onChange="Search()">
                         <select class="form-control" name="type" id="type" onChange="Search()">
                             <option value="" hidden>支付方式</option>
                             <option value="" hidden>支付方式</option>
-                            <option value="f2fpay">当面付</option>
-                            <option value="codepay">码支付</option>
-                            <option value="payjs">PayJs</option>
-                            <option value="bitpayx">麻瓜宝</option>
-                            <option value="paypal">PayPal</option>
-                            <option value="epay">易支付</option>
+                            @foreach(config('common.payment.labels') as $key => $value)
+                                <option value="{{$key}}">{{$value}}</option>
+                            @endforeach
                         </select>
                         </select>
                     </div>
                     </div>
                     <div class="form-group col-lg-2 col-sm-4">
                     <div class="form-group col-lg-2 col-sm-4">

+ 3 - 8
resources/views/admin/logs/order.blade.php

@@ -46,14 +46,9 @@
                     <div class="form-group col-lg-2 col-sm-6">
                     <div class="form-group col-lg-2 col-sm-6">
                         <select class="form-control" name="pay_way" id="pay_way" onChange="Search()">
                         <select class="form-control" name="pay_way" id="pay_way" onChange="Search()">
                             <option value="" hidden>支付方式</option>
                             <option value="" hidden>支付方式</option>
-                            <option value="credit">余额</option>
-                            <option value="youzan">有赞云</option>
-                            <option value="f2fpay">当面付</option>
-                            <option value="codepay">码支付</option>
-                            <option value="payjs">PayJs</option>
-                            <option value="bitpayx">麻瓜宝</option>
-                            <option value="paypal">PayPal</option>
-                            <option value="epay">易支付</option>
+                            @foreach(config('common.payment.labels') as $key => $value)
+                                <option value="{{$key}}">{{$value}}</option>
+                            @endforeach
                         </select>
                         </select>
                     </div>
                     </div>
                     <div class="form-group col-lg-2 col-sm-6">
                     <div class="form-group col-lg-2 col-sm-6">