wang jun 2 gadi atpakaļ
vecāks
revīzija
08386e6fea

+ 19 - 1
application/app/controller/Webuser.php

@@ -14,7 +14,7 @@ use think\Controller;
 class Webuser extends BaseController
 {
     /**
-     * 管理员登陆
+     * 管理员登陆 短信登陆
      *
      * @return void
      * @author wj
@@ -49,4 +49,22 @@ class Webuser extends BaseController
             return backjson2(200, 'success', $result['data']);
         }
     }
+    /**
+     * 管理员密码登陆
+     *
+     * @return void
+     * @author wj
+     * @date 2022-08-18
+     */
+    public function loginbypwd()
+    {
+        $param = request()->param();
+        $l_w = new webuserlogic();
+        $result = $l_w->loginbypwd($param);
+        if (1 != $result['status']) {
+            return backjson2(0, $result['msg']);
+        } else {
+            return backjson2(200, 'success', $result['data']);
+        }
+    }
 }

+ 71 - 0
application/app/logic/webuserlogic.php

@@ -28,6 +28,10 @@ class webuserlogic extends baselogic
             'sendsms' => [
                 ['name' => 'telno', 'title' => '手机号', 'require' => true, 'type' => 'numeric'],
             ],
+            'loginbypwd' => [
+                ['name' => 'account', 'title' => '账号', 'require' => true],
+                ['name' => 'passwd', 'title' => '密码', 'require' => true],
+            ],
         ];
         return $list;
     }
@@ -144,5 +148,72 @@ class webuserlogic extends baselogic
         $result = $s_tc->sendsms($array);
         return $result;
     }
+    /**
+     * 通过验证码登陆
+     *
+     * @param  [type] $arr
+     * @return void
+     * @author wj
+     * @date 2022-08-18
+     */
+    public function loginbypwd($arr)
+    {
+        $result = $this->checkparam(__FUNCTION__, $arr);
+        if (1 != $result['status']) {
+            return $result;
+        }
+        $data = $result['data'];
+        $account = $data['account'];
+        $passwd = $data['passwd'];
+        //验证用户
+        $m_w = new webusermodel();
+        //手机号作为账户号
+        $winfo = $m_w->getinfobytelno($account);
+        if (empty($winfo)) {
+            return backarr(0, "无用户数据");
+        }
+        $wid = $winfo['id'];
+        $telno = $winfo['telno'];
+        $pwd = $winfo['userpwd'];
+        if (empty($pwd)) {
+            //密码为空设为默认
+            $pwd = $this->getpwd("000000");
+            $row = $m_w->setpwd($wid, $pwd);
+            if (empty($row)) {
+                return backarr(0, "密码修改失败");
+            }
+        }
+        //验证密码
+        if (!password_verify($passwd, $pwd)) {
+            return backarr(0, "密码错误");
+        }
+        //重置token
+        $row = $m_w->settoken($wid, $telno);
+        if (empty($row)) {
+            return backarr(0, "用户token修改失败");
+        }
+        $winfo = $m_w->getinfobyid($wid, ['token']);
+        return backarr(1, "用户登录成功", $winfo);
+    }
+    /**
+     * 获取加密后的密码
+     *
+     * @param  string $salt
+     * @return void
+     * @author wj
+     * @date 2022-08-20
+     */
+    public function getpwd($pwd = "")
+    {
+        $defaultpwd = "000000";
+        if (empty($pwd) || !is_string($pwd)) {
+            $pwd = $defaultpwd;
+        }
+        $options = [
+            'cost' => 12, //递归层数
+        ];
+        $pwd = password_hash($pwd, PASSWORD_DEFAULT, $options);
+        return $pwd;
+    }
 
 }

+ 16 - 0
application/common/model/webusermodel.php

@@ -132,4 +132,20 @@ class webusermodel extends Model
         $row = $this->where($where)->update($updateData);
         return $row ? $row : false;
     }
+    /**
+     * 设置用户密码
+     *
+     * @param  [type] $wid
+     * @param  [type] $telno
+     * @return void
+     * @author wj
+     * @date 2022-08-20
+     */
+    public function setpwd($wid, $pwd)
+    {
+        $where = ['id' => $wid];
+        $updateData = ['userpwd' => $pwd];
+        $row = $this->where($where)->update($updateData);
+        return $row ? $row : false;
+    }
 }