Переглянути джерело

chore: improve code quality

Cat 2 роки тому
батько
коміт
31def93017

+ 5 - 4
src/Controllers/UserController.php

@@ -154,9 +154,9 @@ final class UserController extends BaseController
 
         if ($codeq->type === 10002) {
             if (\time() > strtotime($user->expire_in)) {
-                $user->expire_in = date('Y-m-d H:i:s', \time() + $codeq->number * 86400);
+                $user->expire_in = date('Y-m-d H:i:s', \time() + (int) $codeq->number * 86400);
             } else {
-                $user->expire_in = date('Y-m-d H:i:s', strtotime($user->expire_in) + $codeq->number * 86400);
+                $user->expire_in = date('Y-m-d H:i:s', strtotime($user->expire_in) + (int) $codeq->number * 86400);
             }
             $user->save();
         }
@@ -166,7 +166,7 @@ final class UserController extends BaseController
                 $user->class_expire = date('Y-m-d H:i:s', \time());
                 $user->save();
             }
-            $user->class_expire = date('Y-m-d H:i:s', strtotime($user->class_expire) + $codeq->number * 86400);
+            $user->class_expire = date('Y-m-d H:i:s', strtotime($user->class_expire) + (int) $codeq->number * 86400);
             $user->class = $codeq->type;
             $user->save();
         }
@@ -413,7 +413,8 @@ final class UserController extends BaseController
             }
         }
 
-        array_multisort(array_column($results, 'node_name'), SORT_ASC, $results);
+        $node_names = array_column($results, 'node_name');
+        array_multisort($node_names, SORT_ASC, $results);
 
         return $this->view()
             ->assign('results', $results)

+ 3 - 3
src/Models/Bought.php

@@ -55,7 +55,7 @@ final class Bought extends Model
      */
     public function datetime(): string
     {
-        return date('Y-m-d H:i:s', $this->datetime);
+        return date('Y-m-d H:i:s', (int) $this->datetime);
     }
 
     /**
@@ -138,7 +138,7 @@ final class Bought extends Model
             $resetIndex = 1 + (int) ((\time() - $this->datetime - $day) / ($shop->reset() * $day));
             $restTime = $resetIndex * $shop->reset() * $day + $this->datetime;
             $time = \time() + ($day * 86400);
-            return ! $unix ? date('Y-m-d', strtotime('+1 day', strtotime(date('Y-m-d', $restTime)))) : $time;
+            return ! $unix ? date('Y-m-d', strtotime('+1 day', strtotime(date('Y-m-d', (int) $restTime)))) : $time;
         }
         return ! $unix ? '-' : 0;
     }
@@ -151,7 +151,7 @@ final class Bought extends Model
         $shop = $this->shop();
         if ($shop->useLoop()) {
             $time = $this->datetime + ($shop->resetExp() * 86400);
-            return ! $unix ? date('Y-m-d H:i:s', $time) : $time;
+            return ! $unix ? date('Y-m-d H:i:s', (int) $time) : $time;
         }
         return ! $unix ? '-' : 0;
     }

+ 5 - 5
src/Models/Shop.php

@@ -161,22 +161,22 @@ final class Shop extends Model
                     break;
                 case 'expire':
                     if (\time() > strtotime($user->expire_in)) {
-                        $user->expire_in = date('Y-m-d H:i:s', \time() + $value * 86400);
+                        $user->expire_in = date('Y-m-d H:i:s', \time() + (int) $value * 86400);
                     } else {
-                        $user->expire_in = date('Y-m-d H:i:s', strtotime($user->expire_in) + $value * 86400);
+                        $user->expire_in = date('Y-m-d H:i:s', strtotime($user->expire_in) + (int) $value * 86400);
                     }
                     break;
                 case 'class':
                     if ($_ENV['enable_bought_extend'] === true) {
                         if ($user->class === $value) {
-                            $user->class_expire = date('Y-m-d H:i:s', strtotime($user->class_expire) + $this->content['class_expire'] * 86400);
+                            $user->class_expire = date('Y-m-d H:i:s', strtotime($user->class_expire) + (int) $this->content['class_expire'] * 86400);
                         } else {
-                            $user->class_expire = date('Y-m-d H:i:s', \time() + $this->content['class_expire'] * 86400);
+                            $user->class_expire = date('Y-m-d H:i:s', \time() + (int) $this->content['class_expire'] * 86400);
                         }
                         $user->class = $value;
                     } else {
                         $user->class = $value;
-                        $user->class_expire = date('Y-m-d H:i:s', \time() + $this->content['class_expire'] * 86400);
+                        $user->class_expire = date('Y-m-d H:i:s', \time() + (int) $this->content['class_expire'] * 86400);
                         break;
                     }
                     // no break

+ 1 - 1
src/Models/User.php

@@ -211,7 +211,7 @@ final class User extends Model
         }
         $percent = ($this->u + $this->d) / $this->transfer_enable;
         $percent = round($percent, 2);
-        return $percent * 100;
+        return (int) $percent * 100;
     }
 
     /*

+ 0 - 2
src/Services/Captcha.php

@@ -15,12 +15,10 @@ final class Captcha
                 return [
                     'turnstile_sitekey' => Setting::obtain('turnstile_sitekey'),
                 ];
-                break;
             case 'geetest':
                 return [
                     'geetest_id' => Setting::obtain('geetest_id'),
                 ];
-                break;
         }
 
         return [];

+ 0 - 37
src/Services/Config.php

@@ -9,38 +9,10 @@ use App\Models\Setting;
 // Config is singleton instance store all config
 final class Config
 {
-    private static $instnace = null;
-    private $kv = [];
     private function __construct()
     {
     }
 
-    public static function getConfigInstance(): Config
-    {
-        if (! isset(self::$instnace)) {
-            self::$instnace = new static();
-
-            $settings = Setting::all();
-
-            foreach ($settings as $setting) {
-                self::$instnace->kv[$setting->item] = $setting->value;
-            }
-        }
-
-        return self::$instnace;
-    }
-
-    public static function getConf($key): mixed
-    {
-        return self::getConfigInstance()->getConfigCache($key);
-    }
-
-    // TODO: remove
-    public static function get($key)
-    {
-        return $_ENV[$key];
-    }
-
     public static function getPublicConfig()
     {
         $public_configs = Setting::getPublicConfig();
@@ -200,13 +172,4 @@ final class Config
                 ];
         }
     }
-
-    private function getConfigCache($key): mixed
-    {
-        if (isset($kv[$key])) {
-            return $kv[$key];
-        }
-
-        return null;
-    }
 }

+ 4 - 2
src/Services/Gateway/AopF2F.php

@@ -52,7 +52,7 @@ final class AopF2F extends AbstractPayment
 
         $gateway = $this->createGateway();
 
-        /** @var AopTradePreCreateRequest $request */
+        /** @var \Omnipay\Alipay\Requests\AopTradePreCreateRequest $request */
         $request = $gateway->purchase();
         $request->setBizContent([
             'subject' => $pl->tradeno,
@@ -77,7 +77,7 @@ final class AopF2F extends AbstractPayment
     public function notify($request, $response, $args): ResponseInterface
     {
         $gateway = $this->createGateway();
-        /** @var AopCompletePurchaseRequest $aliRequest */
+        /** @var \Omnipay\Alipay\Requests\AopCompletePurchaseRequest $aliRequest */
         $aliRequest = $gateway->completePurchase();
         $aliRequest->setParams($_POST);
 
@@ -92,6 +92,8 @@ final class AopF2F extends AbstractPayment
         } catch (Exception $e) {
             return $response->write('fail');
         }
+
+        return $response->write('unknown');
     }
 
     public static function getPurchaseHTML(): string

+ 4 - 5
src/Services/Gateway/Epay.php

@@ -13,7 +13,6 @@ namespace App\Services\Gateway;
 use App\Models\Paylist;
 use App\Models\Setting;
 use App\Services\Auth;
-use App\Services\Config;
 use App\Services\Gateway\Epay\EpayNotify;
 use App\Services\Gateway\Epay\EpaySubmit;
 use App\Services\View;
@@ -55,7 +54,7 @@ final class Epay extends AbstractPayment
         $type = $request->getParam('type');
         $price = $request->getParam('price');
         if ($price <= 0) {
-            return \json_encode(['errcode' => -1, 'errmsg' => '非法的金额.']);
+            return $response->withJson(['errcode' => -1, 'errmsg' => '非法的金额.']);
         }
         $user = Auth::getUser();
         $pl = new Paylist();
@@ -71,12 +70,12 @@ final class Epay extends AbstractPayment
             'pid' => trim($this->epay['partner']),
             'type' => $type,
             'out_trade_no' => $pl->tradeno,
-            'notify_url' => Config::get('baseUrl') . '/payment/notify/epay',
-            'return_url' => Config::get('baseUrl') . '/user/payment/return/epay',
+            'notify_url' => $_ENV['baseUrl'] . '/payment/notify/epay',
+            'return_url' => $_ENV['baseUrl'] . '/user/payment/return/epay',
             'name' => $pl->tradeno,
             #"name" =>  $user->mobile . "" . $price . "",
             'money' => $price,
-            'sitename' => Config::get('appName'),
+            'sitename' => $_ENV['appName'],
         ];
         $alipaySubmit = new EpaySubmit($this->epay);
         $html_text = $alipaySubmit->buildRequestForm($data);

+ 3 - 7
src/Services/Gateway/Epay/EpayNotify.php

@@ -6,7 +6,8 @@ namespace App\Services\Gateway\Epay;
 
 final class EpayNotify
 {
-    public $alipay_config;
+    private $alipay_config;
+    private $http_verify_url;
 
     public function __construct($alipay_config)
     {
@@ -70,14 +71,9 @@ final class EpayNotify
 
     public function getResponse($notify_id)
     {
-        $transport = strtolower(trim($this->alipay_config['transport']));
         $partner = trim($this->alipay_config['partner']);
         $veryfy_url = '';
-        if ($transport === 'https') {
-            $veryfy_url = $this->https_verify_url;
-        } else {
-            $veryfy_url = $this->http_verify_url;
-        }
+        $veryfy_url = $this->http_verify_url;
         $veryfy_url .= 'partner=' . $partner . '&notify_id=' . $notify_id;
         return EpayTool::getHttpResponseGET($veryfy_url, $this->alipay_config['cacert']);
     }

+ 1 - 0
src/Services/Gateway/Epay/EpaySubmit.php

@@ -7,6 +7,7 @@ namespace App\Services\Gateway\Epay;
 final class EpaySubmit
 {
     private $alipay_config;
+    private $alipay_gateway_new;
 
     public function __construct($alipay_config)
     {

+ 1 - 1
src/Services/Gateway/Epay/EpayTool.php

@@ -143,7 +143,7 @@ final class EpayTool
     {
         $output = '';
         if (! isset($_input_charset)) {
-            $_input_charset = $_input_charset;
+            $_input_charset = $_output_charset;
         }
         if ($_input_charset === $_output_charset || $input === null) {
             $output = $input;

+ 5 - 12
src/Services/Gateway/PAYJS.php

@@ -16,11 +16,7 @@ final class PAYJS extends AbstractPayment
 {
     private $appSecret;
     private $gatewayUri;
-    /**
-     * 签名初始化
-     *
-     * @param merKey    签名密钥
-     */
+
     public function __construct()
     {
         $this->appSecret = Setting::obtain('payjs_key');
@@ -50,11 +46,7 @@ final class PAYJS extends AbstractPayment
         ksort($data);
         return http_build_query($data);
     }
-    /**
-     * @name    生成签名
-     *
-     * @param sourceData
-     */
+
     public function sign($data): string
     {
         return strtoupper(md5(urldecode($data) . '&key=' . $this->appSecret));
@@ -95,7 +87,7 @@ final class PAYJS extends AbstractPayment
     {
         $price = $request->getParam('price');
         if ($price <= 0) {
-            return \json_encode(['code' => -1, 'errmsg' => '非法的金额.']);
+            return $response->withJson(['code' => -1, 'errmsg' => '非法的金额.']);
         }
         $user = Auth::getUser();
         $pl = new Paylist();
@@ -197,7 +189,8 @@ final class PAYJS extends AbstractPayment
                 $success = 0;
             }
         }
-        return View::getSmarty()->assign('money', $money)->assign('success', $success)->fetch('gateway/payjs_success.tpl');
+
+        return $response->write(View::getSmarty()->assign('money', $money)->assign('success', $success)->fetch('gateway/payjs_success.tpl'));
     }
 
     public function getStatus($request, $response, $args): ResponseInterface

+ 2 - 0
src/Services/Gateway/THeadPaySDK.php

@@ -6,6 +6,8 @@ namespace App\Services\Gateway;
 
 final class THeadPaySDK
 {
+    private $config;
+
     public function __construct($config)
     {
         $this->config = $config;

+ 1 - 0
src/Services/Mail/SendGrid.php

@@ -12,6 +12,7 @@ final class SendGrid extends Base
     private $sg;
     private $sender;
     private $name;
+    private $email;
 
     public function __construct()
     {