Преглед изворни кода

优化:安装脚本支持填写数据库端口号

Yahoo пре 4 година
родитељ
комит
ef92fa0fbb

+ 8 - 9
app/api/model/User.php

@@ -13,7 +13,10 @@ declare (strict_types=1);
 namespace app\api\model;
 
 use think\facade\Cache;
+use edward\captcha\facade\CaptchaApi;
+use app\api\service\User as UserService;
 use app\common\model\User as UserModel;
+use cores\exception\BaseException;
 
 /**
  * 用户模型类
@@ -36,20 +39,17 @@ class User extends UserModel
 
     /**
      * 获取器:隐藏手机号中间四位
-     * @param $value
-     * @return mixed
+     * @param string $value
+     * @return string
      */
-    public function getMobileAttr($value)
+    public function getMobileAttr(string $value): string
     {
-        if (strlen($value) === 11) {
-            return hide_mobile($value);
-        }
-        return $value;
+        return strlen($value) === 11 ? hide_mobile($value) : $value;
     }
 
     /**
      * 获取用户信息
-     * @param $token
+     * @param string $token
      * @return bool|static
      */
     public static function getUserByToken(string $token)
@@ -62,5 +62,4 @@ class User extends UserModel
         }
         return false;
     }
-
 }

+ 3 - 11
cores/AppService.php

@@ -21,13 +21,6 @@ use think\facade\Request;
  */
 class AppService extends Service
 {
-    /**
-     * 是否记录访问日志
-     * 建议在当前运行时出错或者需要debug时开启
-     * @var bool
-     */
-    private $enabled = false;
-
     // 服务注册
     public function register()
     {
@@ -38,9 +31,8 @@ class AppService extends Service
     public function boot()
     {
         // 记录访问日志
-        if ($this->enabled && !is_debug()) {
-            $log = '';
-            $log .= $this->getVisitor();
+        if (env('access_log') && !is_debug()) {
+            $log = $this->getVisitor();
             $log .= "\r\n" . '[ header ] ' . print_r(Request::header(), true);
             $log .= "" . '[ param ] ' . print_r(Request::param(), true);
             $log .= "\r\n" . '--------------------------------------------------------------------------------------------';
@@ -52,7 +44,7 @@ class AppService extends Service
      * 获取请求路径信息
      * @return string
      */
-    private function getVisitor()
+    private function getVisitor(): string
     {
         $data = [Request::ip(), Request::method(), Request::url(true)];
         return implode(' ', $data);

+ 3 - 2
public/install/index.php

@@ -21,7 +21,7 @@ if (phpversion() < '7.1') {
 set_time_limit(0);
 
 // 设置系统路径
-define('IN_INSTALL', TRUE);
+define('IN_INSTALL', true);
 define('INSTALL_PATH', str_replace('\\', '/', dirname(__FILE__)));
 define('ROOT_PATH', dirname(INSTALL_PATH, 2));
 
@@ -92,7 +92,7 @@ if ($s == 3) {
 
         // 连接证数据库
         try {
-            $dsn = "mysql:host=$dbhost;port=$dbport;charset=utf8";
+            $dsn = "mysql:host={$dbhost};port={$dbport};charset=utf8";
             $pdo = new PDO($dsn, $dbuser, $dbpwd);
             $pdo->query("SET NAMES utf8"); // 设置数据库编码
         } catch (Exception $e) {
@@ -186,6 +186,7 @@ if ($s == 63832) {
     $dbhost = $_GET['dbhost'] ?? '';
     $dbuser = $_GET['dbuser'] ?? '';
     $dbpwd = $_GET['dbpwd'] ?? '';
+    $dbport = $_GET['dbport'] ?? '';
     try {
         $dsn = "mysql:host=$dbhost;charset=utf8";
         $pdo = new PDO($dsn, $dbuser, $dbpwd);

+ 2 - 1
public/install/templates/js/forms.js

@@ -121,13 +121,14 @@ function CheckPwd() {
         data: {
             s: 63832,
             dbhost: $("#dbhost").val(),
+            dbport: $("#dbport").val(),
             dbuser: $("#dbuser").val(),
             dbpwd: $("#dbpwd").val(),
         },
         type: 'get',
         dataType: 'html',
         success: function (data) {
-            if (data == 'true') {
+            if (data === 'true') {
                 $('#cpwdTxt').html('<span class="correct">可用</span>');
                 $('#cpwd').val("true");
             } else {

+ 12 - 2
public/install/templates/step_2.php

@@ -23,12 +23,22 @@
                     <td><input type="text" name="dbhost" id="dbhost" class="input" value="localhost"/>
                         <span class="cnote">数据库服务器地址, 一般为 localhost</span></td>
                 </tr>
+                <tr>
+                    <td width="30%" height="40" align="right">数据库端口号:</td>
+                    <td>
+                        <input type="text" name="dbport" id="dbport" class="input" value="3306"/>
+                        <span class="cnote">数据库端口号, 一般为 3306</span>
+                    </td>
+                </tr>
                 <tr>
                     <td height="40" align="right">数据库名称:</td>
-                    <td><input type="text" name="dbname" id="dbname" class="input" value="yoshop2_db"/></td>
+                    <td>
+                        <input type="text" name="dbname" id="dbname" class="input" value="yoshop2_db"/>
+                        <span class="cnote">数据库的名称,如果没有请先新增</span>
+                    </td>
                 </tr>
                 <tr>
-                    <td height="40" align="right">数据库用户:</td>
+                    <td height="40" align="right">数据库用户名:</td>
                     <td><input type="text" name="dbuser" id="dbuser" class="input" value="root"/></td>
                 </tr>
                 <tr>