浏览代码

若干小改动

兔姬桑 3 年之前
父节点
当前提交
0f27a9c5f7

+ 17 - 17
app/Components/IP.php

@@ -35,7 +35,7 @@ class IP
     // 通过api.ip.sb查询IP地址的详细信息
     public static function IPSB($ip)
     {
-        $response = Http::timeout(15)->get('https://api.ip.sb/geoip/'.$ip);
+        $response = Http::withHeaders(['User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'])->timeout(15)->get('https://api.ip.sb/geoip/'.$ip);
 
         if ($response->ok()) {
             return $response->json();
@@ -60,11 +60,11 @@ class IP
             $location = explode('|', $ipInfo['region']);
             if ($location) {
                 return [
-                    'country' => $location[0] ?: '',
+                    'country'  => $location[0] ?: '',
                     'province' => $location[2] ?: '',
-                    'city' => $location[3] ?: '',
-                    'isp' => $location[4] ?: '',
-                    'area' => $location[1] ?: '',
+                    'city'     => $location[3] ?: '',
+                    'isp'      => $location[4] ?: '',
+                    'area'     => $location[1] ?: '',
                 ];
             }
         }
@@ -81,9 +81,9 @@ class IP
                 ->lookup($ip, [Database::CITY_NAME, Database::REGION_NAME, Database::COUNTRY_NAME]);
 
             return [
-                'country' => $location['countryName'],
+                'country'  => $location['countryName'],
                 'province' => $location['regionName'],
-                'city' => $location['cityName'],
+                'city'     => $location['cityName'],
             ];
         } catch (Exception $e) {
             Log::error('【ip2Location】错误信息:'.$e->getMessage());
@@ -99,9 +99,9 @@ class IP
         $location = (new City($filePath))->findMap($ip, 'CN');
 
         return [
-            'country' => $location['country_name'],
+            'country'  => $location['country_name'],
             'province' => $location['region_name'],
-            'city' => $location['city_name'],
+            'city'     => $location['city_name'],
         ];
     }
 
@@ -115,10 +115,10 @@ class IP
             $message = $response->json();
             if ($message['code'] === 0) {
                 return [
-                    'country' => $message['data']['country'] === 'XX' ? '' : $message['data']['country'],
+                    'country'  => $message['data']['country'] === 'XX' ? '' : $message['data']['country'],
                     'province' => $message['data']['region'] === 'XX' ? '' : $message['data']['region'],
-                    'city' => $message['data']['city'] === 'XX' ? '' : $message['data']['city'],
-                    'isp' => $message['data']['isp'] === 'XX' ? '' : $message['data']['isp'],
+                    'city'     => $message['data']['city'] === 'XX' ? '' : $message['data']['city'],
+                    'isp'      => $message['data']['isp'] === 'XX' ? '' : $message['data']['isp'],
                 ];
             }
 
@@ -145,10 +145,10 @@ class IP
             $message = $response->json();
             if ($message['status'] === 0) {
                 return [
-                    'country' => $message['content']['address_detail']['country'],
+                    'country'  => $message['content']['address_detail']['country'],
                     'province' => $message['content']['address_detail']['province'],
-                    'city' => $message['content']['address_detail']['city'],
-                    'area' => $message['address'],
+                    'city'     => $message['content']['address_detail']['city'],
+                    'area'     => $message['address'],
                 ];
             }
 
@@ -168,9 +168,9 @@ class IP
             $location = (new Reader($filePath))->city($ip);
 
             return [
-                'country' => $location->country->names['zh-CN'],
+                'country'  => $location->country->names['zh-CN'],
                 'province' => '',
-                'city' => $location->city->name ?? '',
+                'city'     => $location->city->name ?? '',
             ];
         } catch (AddressNotFoundException $e) {
             Log::error('【GeoIP2】查询失败:'.$ip);

+ 1 - 1
app/Http/Controllers/Api/Client/V1Controller.php

@@ -248,7 +248,7 @@ class V1Controller extends Controller
             // 使用优惠券,减少可使用次数
             if (! empty($coupon)) {
                 if ($coupon->usable_times > 0) {
-                    $coupon->decrement('usable_times', 1);
+                    $coupon->decrement('usable_times');
                 }
 
                 Helpers::addCouponLog('订单支付使用', $coupon->id, $goods_id, $newOrder->id);

+ 1 - 1
app/Http/Controllers/User/SubscribeController.php

@@ -63,7 +63,7 @@ class SubscribeController extends Controller
         }
 
         // 更新访问次数
-        $subscribe->increment('times', 1);
+        $subscribe->increment('times');
 
         // 记录每次请求
         $this->subscribeLog($subscribe->id, IP::getClientIp(), json_encode(['Host' => $request->getHost(), 'User-Agent' => $request->userAgent()]));

+ 36 - 36
app/Http/Requests/Admin/NodeRequest.php

@@ -9,44 +9,44 @@ class NodeRequest extends FormRequest
     public function rules(): array
     {
         return [
-            'is_ddns' => 'required|boolean',
-            'name' => 'required|string',
-            'server' => 'required_if:is_ddns,1|nullable|ends_with:'.implode(',', config('domains')),
-            'ip' => 'required_if:is_ddns,0|nullable',
-            'ipv6' => 'nullable',
-            'push_port' => 'numeric|between:1,65535|different:port',
-            'traffic_rate' => 'required|numeric|min:0',
-            'level' => 'required|numeric|exists:level,level',
-            'rule_group_id' => 'nullable|exists:rule_group,id',
-            'speed_limit' => 'required|numeric|min:0',
-            'client_limit' => 'required|numeric|min:0',
-            'labels' => 'nullable|exists:label,id',
-            'country_code' => 'required|exists:country,code',
-            'description' => 'nullable|string',
-            'sort' => 'required|numeric|between:0,255',
-            'is_udp' => 'required|boolean',
-            'status' => 'required|boolean',
-            'type' => 'required|numeric|between:0,4',
-            'method' => 'required|exists:ss_config,name',
-            'protocol' => 'required_if:type,1,4|exists:ss_config,name',
+            'is_ddns'        => 'required|boolean',
+            'name'           => 'required|string',
+            'server'         => 'required_if:is_ddns,1|nullable|ends_with:'.implode(',', config('domains')),
+            'ip'             => 'required_if:is_ddns,0|nullable',
+            'ipv6'           => 'nullable',
+            'push_port'      => 'numeric|between:1,65535|different:port',
+            'traffic_rate'   => 'required|numeric|min:0',
+            'level'          => 'required|numeric|exists:level,level',
+            'rule_group_id'  => 'nullable|exists:rule_group,id',
+            'speed_limit'    => 'required|numeric|min:0',
+            'client_limit'   => 'required|numeric|min:0',
+            'labels'         => 'nullable|exists:label,id',
+            'country_code'   => 'required|exists:country,code',
+            'description'    => 'nullable|string',
+            'sort'           => 'required|numeric|between:0,255',
+            'is_udp'         => 'required|boolean',
+            'status'         => 'required|boolean',
+            'type'           => 'required|numeric|between:0,4',
+            'method'         => 'required|exists:ss_config,name',
+            'protocol'       => 'required_if:type,1,4|exists:ss_config,name',
             'protocol_param' => 'nullable|string',
-            'obfs' => 'required_if:type,1,4|exists:ss_config,name',
-            'obfs_param' => 'nullable|string',
-            'is_subscribe' => 'required|boolean',
+            'obfs'           => 'required_if:type,1,4|exists:ss_config,name',
+            'obfs_param'     => 'nullable|string',
+            'is_subscribe'   => 'required|boolean',
             'detection_type' => 'required|numeric|between:0,3',
-            'single' => 'required|boolean',
-            'port' => 'required_if:single,1,type,2,type,3|numeric|between:1,65535|different:push_port|nullable',
-            'passwd' => 'exclude_unless:type,1,type,4|required_if:single,1|string|nullable',
-            'v2_alter_id' => 'required_if:type,2|numeric|between:0,65535',
-            'v2_method' => 'required_if:type,2',
-            'v2_net' => 'required_if:type,2',
-            'v2_type' => 'required_if:type,2',
-            'v2_host' => 'string|nullable',
-            'v2_path' => 'string|nullable',
-            'v2_sni' => 'string|nullable',
-            'v2_tls' => 'required_if:type,2|boolean',
-            'tls_provider' => 'json|nullable',
-            'relay_node_id' => 'nullable|exists:node,id',
+            'single'         => 'required|boolean',
+            'port'           => 'required_unless:single,0|numeric|between:1,65535|different:push_port',
+            'passwd'         => 'exclude_unless:type,1,type,4|required_if:single,1|string|nullable',
+            'v2_alter_id'    => 'required_if:type,2|numeric|between:0,65535',
+            'v2_method'      => 'required_if:type,2',
+            'v2_net'         => 'required_if:type,2',
+            'v2_type'        => 'required_if:type,2',
+            'v2_host'        => 'string|nullable',
+            'v2_path'        => 'string|nullable',
+            'v2_sni'         => 'string|nullable',
+            'v2_tls'         => 'required_if:type,2|boolean',
+            'tls_provider'   => 'json|nullable',
+            'relay_node_id'  => 'nullable|exists:node,id',
         ];
     }
 

+ 2 - 1
app/Models/Node.php

@@ -105,7 +105,7 @@ class Node extends Model
 
             if ($data) {
                 self::withoutEvents(function () use ($data) {
-                    $this->update(['geo' => $data['latitude'].','.$data['longitude']]);
+                    $this->update(['geo' => $data['latitude'] ?? null.','.$data['longitude'] ?? null]);
                 });
 
                 return true;
@@ -215,6 +215,7 @@ class Node extends Model
     public function getTypeLabelAttribute(): string
     {
         return [
+            0 => 'Shadowsocks',
             1 => 'ShadowsocksR',
             2 => 'V2Ray',
             3 => 'Trojan',

+ 1 - 1
app/Observers/OrderObserver.php

@@ -54,7 +54,7 @@ class OrderObserver
     // 返回优惠券
     private function returnCoupon(Coupon $coupon): bool
     {
-        if ($coupon && $coupon->type !== 3) {
+        if ($coupon->type !== 3) {
             return $coupon->update(['usable_times' => $coupon->usable_times + 1, 'status' => 0]);
         }
 

+ 1 - 1
resources/lang/en/user.php

@@ -17,7 +17,7 @@ return [
             'expired'           => 'Expired',
             'overused'          => 'You have reach the <code>:data</code> GB hourly data spend limit<br/> Wait <code id="countdown">:min</code> to cool down',
             'traffic_exhausted' => 'OUT OF DATA',
-            'unknown'           => 'UNKNOWN ERROR, please contact admin for reason',
+            'unknown'           => 'UNKNOWN ERROR, Please try to refresh your browser first before contact admin for help',
         ],
     ],
     'status'              => [

+ 1 - 1
resources/lang/zh_CN/user.php

@@ -17,7 +17,7 @@ return [
             'expired'           => '您的账号套餐已过期',
             'overused'          => '本时段使用流量超过 <code>:data</code> GB触发系统限制<br/> <code id="countdown">:min</code> 后解除限制',
             'traffic_exhausted' => '您的账号[流量]消耗殆尽',
-            'unknown'           => '未知原因,请开工单联系管理',
+            'unknown'           => '未知原因,请尝试[刷新]你的浏览器!多次无果后再请开工单联系管理',
         ],
     ],
     'status'              => [