diff --git a/app/controller/IndexController.php b/app/controller/IndexController.php index 7bee3a4..1bcb6ab 100644 --- a/app/controller/IndexController.php +++ b/app/controller/IndexController.php @@ -22,17 +22,7 @@ class IndexController } public function test() { - $info = request()->post(); - $action = isset($info['action']) ? $info['action'] : ''; - if ($action === 'mpay') { - $data = json_decode($info['data'], true); - $config = \think\facade\Config::load("payconfig/{$data['pid']}_{$data['aid']}", 'payconfig'); - $payclient_path = "\\payclient\\{$config['pay']['payclass']}"; - $Payclient = new $payclient_path($info, $config); - $res = $Payclient->notify(); - return $res; - } else { - return 202; - } + + return app()->getBasePath(); } } diff --git a/app/controller/InstallController.php b/app/controller/InstallController.php new file mode 100644 index 0000000..391a6e0 --- /dev/null +++ b/app/controller/InstallController.php @@ -0,0 +1,196 @@ +checkLock()) { + return redirect('User/login'); + }; + return View::fetch(); + } + + public function install(Request $request) + { + // 检查是否已经安装过 + if ($this->checkLock()) { + return backMsg(1, '已经安装'); + }; + // 获取表单提交的数据库配置信息 + $dbConfig = $request->post(); + + // 保存数据库配置信息到配置文件 + $this->saveDbConfig($dbConfig); + + // 连接数据库并建表 + $is_succ_tb = $this->createTables(); + + // 初始化数据记录 + $is_succ_data = $this->initData($dbConfig); + + // 安装检测 + if (!$is_succ_tb) { + return json(backMsg(1, '数据表创建失败')); + } + if (!$is_succ_data) { + return json(backMsg(1, '数据初始化失败')); + } + // 安装成功,写入安装锁文件 + $this->setLock(); + return json(backMsg(0, '安装成功')); + } + + private function saveDbConfig($dbConfig) + { + $envPath = app()->getRootPath() . '.env'; + $envContent = <<execute("DROP TABLE IF EXISTS `mpay_order`;"); + $db->execute($sql); + + // 创建pay_account表的 SQL 语句 + $sql = "CREATE TABLE `mpay_pay_account` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '收款平台ID', + `pid` int(11) NOT NULL DEFAULT '0' COMMENT '用户ID', + `platform` varchar(255) NOT NULL DEFAULT '' COMMENT '收款平台', + `account` varchar(255) NOT NULL DEFAULT '' COMMENT '账号', + `password` varchar(255) NOT NULL DEFAULT '' COMMENT '密码', + `state` tinyint(4) NOT NULL DEFAULT '1' COMMENT '启用', + `pattern` tinyint(4) NOT NULL DEFAULT '1' COMMENT '账号监听模式', + `params` varchar(255) NOT NULL DEFAULT '' COMMENT '自定义查询', + `delete_time` timestamp NULL DEFAULT NULL COMMENT '软删除', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;"; + + // 执行 SQL 语句创建表 + $db->execute("DROP TABLE IF EXISTS `mpay_pay_account`;"); + $db->execute($sql); + + // 创建pay_channel表的 SQL 语句 + $sql = "CREATE TABLE `mpay_pay_channel` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '渠道ID', + `account_id` int(11) NOT NULL DEFAULT '0' COMMENT '收款平台ID', + `channel` varchar(255) NOT NULL DEFAULT '' COMMENT '收款通道', + `type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '保存类型', + `qrcode` varchar(255) NOT NULL DEFAULT '' COMMENT '二维码', + `last_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最近使用', + `state` tinyint(4) NOT NULL DEFAULT '1' COMMENT '启用', + `delete_time` timestamp NULL DEFAULT NULL COMMENT '软删除', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;"; + + // 执行 SQL 语句创建表 + $db->execute("DROP TABLE IF EXISTS `mpay_pay_channel`;"); + $db->execute($sql); + + // 创建user表的 SQL 语句 + $sql = "CREATE TABLE `mpay_user` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `pid` int(11) NOT NULL DEFAULT '0' COMMENT '商户ID', + `secret_key` varchar(255) CHARACTER SET utf8mb4 NOT NULL DEFAULT '' COMMENT '商户秘钥', + `nickname` varchar(255) CHARACTER SET utf8mb4 NOT NULL DEFAULT '' COMMENT '用户昵称', + `username` varchar(255) CHARACTER SET utf8mb4 NOT NULL DEFAULT '' COMMENT '账号', + `password` varchar(255) CHARACTER SET utf8mb4 NOT NULL DEFAULT '' COMMENT '密码', + `state` tinyint(4) NOT NULL DEFAULT '1' COMMENT '启用状态 0:禁用 1:启用', + `role` tinyint(4) NOT NULL DEFAULT '0' COMMENT '用户角色 0:普通用户 1:管理员', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `delete_time` timestamp NULL DEFAULT NULL COMMENT '软删除', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;"; + + // 执行 SQL 语句创建表 + $db->execute("DROP TABLE IF EXISTS `mpay_user`;"); + $db->execute($sql); + return true; + } + + private function initData($dbConfig) + { + // 连接数据库 + $db = Db::connect(); + $info = [ + 'secret_key' => md5(1000 . time() . mt_rand()), + 'nickname' => $dbConfig['nickname'], + 'username' => $dbConfig['username'], + 'password' => password_hash($dbConfig['password'], PASSWORD_DEFAULT), + ]; + // 初始化数据的 SQL 语句 + $sql = "INSERT INTO `mpay_user` (`id`, `pid`, `secret_key`, `nickname`, `username`, `password`, `state`, `role`) VALUES (1, 1000, :secret_key, :nickname, :username, :password, 1, 1);"; + + // 执行 SQL 语句插入初始数据 + $is_succ = $db->execute($sql, $info); + if (!$is_succ) { + return false; + } + return true; + } + private function checkLock() + { + $path = runtime_path() . 'install.lock'; + return file_exists($path); + } + private function setLock() + { + $path = runtime_path() . 'install.lock'; + file_put_contents($path, time()); + } +} diff --git a/app/controller/UserController.php b/app/controller/UserController.php index 59be72f..fc9a3da 100644 --- a/app/controller/UserController.php +++ b/app/controller/UserController.php @@ -32,7 +32,7 @@ class UserController extends BaseController // 修改用户 public function setUser() { - $userinfo = User::find(\session('userid'))->toArray(); + $userinfo = User::find(session('userid'))->toArray(); View::assign($userinfo); return View::fetch(); } diff --git a/app/controller/api/UserController.php b/app/controller/api/UserController.php index 085fc6c..4696d2a 100644 --- a/app/controller/api/UserController.php +++ b/app/controller/api/UserController.php @@ -22,7 +22,7 @@ class UserController extends BaseController Session::set('nickname', $userinfo['data']->nickname); Session::set('userrole', $userinfo['data']->role); Session::set('islogin', true); - return json(\backMsg(0, 'ok')); + return json(backMsg(0, 'ok')); } else { return json($userinfo); } @@ -30,26 +30,42 @@ class UserController extends BaseController public function logout() { Session::clear(); - return json(\backMsg(0, '注销成功')); + return json(backMsg(0, '注销成功')); } public function editUser() { - $userid = \session('userid'); + $userid = session('userid'); $info = $this->request->post(); $res = User::update($info, ['id' => $userid]); if (!$res) { - return json(\backMsg(1, '修改失败')); + return json(backMsg(1, '修改失败')); + } + return json(backMsg(0, '重置成功')); + } + public function changePassword() + { + $userid = session('userid'); + $user_info = User::find($userid); + $post_info = $this->request->post(); + if (password_verify($post_info['old_password'], $user_info->password)) { + $new_password = password_hash($post_info['new_password'], PASSWORD_DEFAULT); + $res = User::update(['password' => $new_password], ['id' => $userid]); + if (!$res) { + return json(backMsg(1, '修改失败')); + } + return json(backMsg(0, '修改成功')); + } else { + return json(backMsg(1, '原密码错误')); } - return json(\backMsg(0, '重置成功')); } public function resetKey() { - $userid = \session('userid'); + $userid = session('userid'); $res = User::update(['secret_key' => $this->generateKey()], ['id' => $userid]); if (!$res) { - return json(\backMsg(1, '重置失败')); + return json(backMsg(1, '重置失败')); } - return json(\backMsg(0, '重置成功')); + return json(backMsg(0, '重置成功')); } private function checkUser(array $login_info): array { @@ -57,16 +73,16 @@ class UserController extends BaseController $password = $login_info['password']; $userinfo = User::where('username', $username)->find(); if ($userinfo) { - if ($password === $userinfo->password) { + if (password_verify($password, $userinfo->password)) { return ['code' => 0, 'data' => $userinfo]; } else { - return \backMsg(1, '登陆密码错误'); + return backMsg(1, '登陆密码错误'); } } else { - return \backMsg(2, '用户不存在'); + return backMsg(2, '用户不存在'); } } - private function generateKey() + private function generateKey(bool $strong = true) { $bytes = openssl_random_pseudo_bytes(16, $strong); if ($strong) { diff --git a/config/extendconfig/payplugin.php b/config/extendconfig/payplugin.php index 873f7ed..b7ce271 100644 --- a/config/extendconfig/payplugin.php +++ b/config/extendconfig/payplugin.php @@ -59,7 +59,7 @@ return array ( 'price' => '49.00', 'describe' => '数字门店', 'website' => 'https://store.zhihuijingyingba.com/', - 'state' => 1, + 'state' => 0, 'query' => array ( 'pageNo' => 1, @@ -79,7 +79,7 @@ return array ( 'price' => '59.00', 'describe' => '为商户和消费者提供安全、便捷、高效的支付产品与服务助力商户提升运营效率,实现数字化运营', 'website' => 'https://xym.ysepay.com/', - 'state' => 1, + 'state' => 0, 'query' => array ( 'storeNo' => '', @@ -102,7 +102,7 @@ return array ( 'price' => '49.00', 'describe' => '码钱商管平台', 'website' => 'https://m.hkrt.cn/', - 'state' => 1, + 'state' => 0, 'query' => array ( 'terminalType' => '', diff --git a/view/Install/index.html b/view/Install/index.html new file mode 100644 index 0000000..1ca1804 --- /dev/null +++ b/view/Install/index.html @@ -0,0 +1,135 @@ + + + + + + 程序安装 + + + + + + +
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+
+
+
+ + + + + + + \ No newline at end of file diff --git a/view/user/set_user.html b/view/user/set_user.html index bcabf75..8b7ebe3 100644 --- a/view/user/set_user.html +++ b/view/user/set_user.html @@ -16,14 +16,6 @@
-
- -
-
- -
-
-
@@ -35,13 +27,18 @@
- +
-
+
- +
+ ******** + +
@@ -60,24 +57,51 @@
- + - \ No newline at end of file