From 7bd21336ad8671d42990c552334fcd554ca8ae31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=94=E5=A7=AC=E6=A1=91?= Date: Sat, 23 Jan 2021 22:42:41 -0500 Subject: [PATCH] =?UTF-8?q?Fix=20#130=20&=20=E7=AE=80=E5=8C=96switch?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Controller.php | 9 +- app/Http/Controllers/Gateway/EPay.php | 15 +-- app/Models/Marketing.php | 19 +--- app/Models/Node.php | 24 ++--- app/Models/Order.php | 94 +++---------------- app/Models/PaymentCallback.php | 23 ++--- app/Models/Rule.php | 48 +++------- app/Providers/SettingServiceProvider.php | 30 ++---- config/common.php | 28 ++++++ resources/views/admin/logs/callback.blade.php | 9 +- resources/views/admin/logs/order.blade.php | 11 +-- 11 files changed, 89 insertions(+), 221 deletions(-) create mode 100644 config/common.php diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index bc831f6c..5458486d 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -107,18 +107,19 @@ class Controller extends BaseController // 节点信息 public function getUserNodeInfo(array $server, bool $is_url): ?string { + $type = $is_url ? new URLSchemes() : new Text(); switch ($server['type']) { case'shadowsocks': - $data = $is_url ? URLSchemes::buildShadowsocks($server) : Text::buildShadowsocks($server); + $data = $type->buildShadowsocks($server); break; case 'shadowsocksr': - $data = $is_url ? URLSchemes::buildShadowsocksr($server) : Text::buildShadowsocksr($server); + $data = $type->buildShadowsocksr($server); break; case 'v2ray': - $data = $is_url ? URLSchemes::buildVmess($server) : Text::buildVmess($server); + $data = $type->buildVmess($server); break; case 'trojan': - $data = $is_url ? URLSchemes::buildTrojan($server) : Text::buildTrojan($server); + $data = $type->buildTrojan($server); break; default: } diff --git a/app/Http/Controllers/Gateway/EPay.php b/app/Http/Controllers/Gateway/EPay.php index 31ab4118..26d22f8f 100644 --- a/app/Http/Controllers/Gateway/EPay.php +++ b/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')); - switch ($request->input('type')) { - case 2: - $type = 'qqpay'; - break; - case 3: - $type = 'wxpay'; - break; - case 1: - default: - $type = 'alipay'; - break; - } - $data = [ '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']), 'return_url' => route('invoice'), 'out_trade_no' => $payment->trade_no, diff --git a/app/Models/Marketing.php b/app/Models/Marketing.php index 504c40b2..19558f01 100644 --- a/app/Models/Marketing.php +++ b/app/Models/Marketing.php @@ -13,19 +13,10 @@ class Marketing extends Model 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']] ?? ''; } } diff --git a/app/Models/Node.php b/app/Models/Node.php index 2bc203de..a523a359 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -178,23 +178,11 @@ class Node extends Model 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'; } } diff --git a/app/Models/Order.php b/app/Models/Order.php index c1f0b301..857a8b54 100644 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -155,98 +155,26 @@ class Order extends Model // 支付渠道 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 { - $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 { - 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']] ?? '未知'; } } diff --git a/app/Models/PaymentCallback.php b/app/Models/PaymentCallback.php index f6e565d5..04458941 100644 --- a/app/Models/PaymentCallback.php +++ b/app/Models/PaymentCallback.php @@ -13,22 +13,11 @@ class PaymentCallback extends Model 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']] ?? ''; } } diff --git a/app/Models/Rule.php b/app/Models/Rule.php index 1a67a6e2..2ef857ea 100644 --- a/app/Models/Rule.php +++ b/app/Models/Rule.php @@ -15,46 +15,22 @@ class Rule extends Model 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 { - 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() diff --git a/app/Providers/SettingServiceProvider.php b/app/Providers/SettingServiceProvider.php index 93e93ec2..b2ed1468 100644 --- a/app/Providers/SettingServiceProvider.php +++ b/app/Providers/SettingServiceProvider.php @@ -11,11 +11,6 @@ use NotificationChannels\Telegram\TelegramChannel; class SettingServiceProvider extends ServiceProvider { - /** - * Bootstrap services. - * - * @return void - */ public function boot() { $toApp = collect([ @@ -26,7 +21,6 @@ class SettingServiceProvider extends ServiceProvider 'hcaptcha_secret' => 'HCaptcha.secret', 'hcaptcha_sitekey' => 'HCaptcha.sitekey', ]); - $notifications = collect([ 'account_expire_notification', 'data_anomaly_notification', @@ -40,25 +34,22 @@ class SettingServiceProvider extends ServiceProvider 'ticket_created_notification', 'ticket_replied_notification', ]); - + $payments = ['is_AliPay', 'is_QQPay', 'is_WeChatPay', 'is_otherPay']; $settings = Config::all(); - $modified = $settings ->whereNotIn('name', $toApp->keys()->merge($notifications)) // 设置一般系统选项 ->pluck('value', 'name') ->merge($settings->whereIn('name', $notifications)->pluck('value', 'name')->map(function ($item) { 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]); // 设置系统参数 - $settings->whereIn('name', $toApp->keys())->pluck('value', 'name')->each(function ($item, $key) use ($toApp) { config([$toApp[$key] => $item]); // 设置PHP软件包相关配置 }); - collect([ 'website_name' => 'app.name', 'website_url' => 'app.url', @@ -69,18 +60,15 @@ class SettingServiceProvider extends ServiceProvider private static function setChannel(array $channels) { - $options = [ + return collect([ 'telegram' => TelegramChannel::class, 'beary' => BearyChatChannel::class, 'bark' => BarkChannel::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; + }); } } diff --git a/config/common.php b/config/common.php new file mode 100644 index 00000000..35b4f0ce --- /dev/null +++ b/config/common.php @@ -0,0 +1,28 @@ + [ + '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', + ], + + ], +]; diff --git a/resources/views/admin/logs/callback.blade.php b/resources/views/admin/logs/callback.blade.php index 120a7a82..04b0b190 100644 --- a/resources/views/admin/logs/callback.blade.php +++ b/resources/views/admin/logs/callback.blade.php @@ -23,12 +23,9 @@
diff --git a/resources/views/admin/logs/order.blade.php b/resources/views/admin/logs/order.blade.php index 09e98a9d..c027041b 100644 --- a/resources/views/admin/logs/order.blade.php +++ b/resources/views/admin/logs/order.blade.php @@ -46,14 +46,9 @@