Fix #130 & 简化switch使用情况

This commit is contained in:
兔姬桑
2021-01-23 22:42:41 -05:00
parent 152b8f65be
commit 7bd21336ad
11 changed files with 89 additions and 221 deletions

View File

@@ -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:
}

View File

@@ -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,

View File

@@ -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']] ?? '';
}
}

View File

@@ -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';
}
}

View File

@@ -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']] ?? '未知';
}
}

View File

@@ -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']] ?? '';
}
}

View File

@@ -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()

View File

@@ -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;
});
}
}

28
config/common.php Normal file
View File

@@ -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',
],
],
];

View File

@@ -23,12 +23,9 @@
<div class="form-group col-lg-2 col-sm-4">
<select class="form-control" name="type" id="type" onChange="Search()">
<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>
</div>
<div class="form-group col-lg-2 col-sm-4">

View File

@@ -46,14 +46,9 @@
<div class="form-group col-lg-2 col-sm-6">
<select class="form-control" name="pay_way" id="pay_way" onChange="Search()">
<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>
</div>
<div class="form-group col-lg-2 col-sm-6">