1
This commit is contained in:
28
app/index/config/lang.php
Normal file
28
app/index/config/lang.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 多语言设置
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
use app\LangService;
|
||||
use enums\LangEnum;
|
||||
|
||||
return [
|
||||
// 默认语言
|
||||
'default_lang' => LangEnum::EN->value,
|
||||
// 允许的语言列表
|
||||
'allow_lang_list' => LangService::getAllowLang(),
|
||||
// 多语言自动侦测变量名
|
||||
'detect_var' => 'lang',
|
||||
// 是否使用Cookie记录
|
||||
'use_cookie' => false,
|
||||
// 多语言cookie变量
|
||||
'cookie_var' => 'lang',
|
||||
// 多语言header变量
|
||||
'header_var' => 'lang',
|
||||
// 扩展语言包
|
||||
'extend_list' => LangService::getLangExtend(),
|
||||
// Accept-Language转义为对应语言包名称
|
||||
'accept_language' => LangService::getAcceptLang(),
|
||||
// 是否支持语言分组
|
||||
'allow_group' => true,
|
||||
];
|
||||
64
app/index/controller/Index.php
Normal file
64
app/index/controller/Index.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use app\admin\model\BlackIp;
|
||||
use app\admin\model\MallOrder;
|
||||
use app\BaseController;
|
||||
use Kaadon\Uuid\Uuids;
|
||||
use think\Exception;
|
||||
use think\facade\Env;
|
||||
use think\response\Redirect;
|
||||
|
||||
class Index extends BaseController
|
||||
{
|
||||
/**
|
||||
* @throws \think\Exception
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if ($this->request->isPost()){
|
||||
$param = $this->request->post();
|
||||
$ip = $this->request->ip();
|
||||
$black = BlackIp::where('ip',$ip)->find();
|
||||
if (!empty($black)){
|
||||
throw new Exception();
|
||||
exit();
|
||||
return error('您的IP已被禁止充值,如有疑问请联系管理员');
|
||||
}
|
||||
$rid = Uuids::getUuid4();
|
||||
$data = [
|
||||
'money'=>$param['amount'],
|
||||
'rid'=>$rid,
|
||||
'start_time'=>time(),
|
||||
'end_time'=>time()+180,
|
||||
'ip'=> $ip,
|
||||
];
|
||||
(new MallOrder())->save($data);
|
||||
return redirect('index/index/reloads?rid='.$rid);
|
||||
}else{
|
||||
return view();
|
||||
}
|
||||
}
|
||||
public function reloads()
|
||||
{
|
||||
return view();
|
||||
}
|
||||
public function status()
|
||||
{
|
||||
$rid = $this->request->param('rid');
|
||||
$data = MallOrder::where('rid',$rid)->find();
|
||||
if (empty($data))
|
||||
return error();
|
||||
$status = match ($data['status']) {
|
||||
1 => 'yellow',
|
||||
2 => 'red',
|
||||
default => 'blue',
|
||||
};
|
||||
return success([
|
||||
'status'=>$status,
|
||||
'color'=>$status,
|
||||
'url'=>$data['url']
|
||||
]);
|
||||
}
|
||||
}
|
||||
224
app/index/controller/Install.php
Normal file
224
app/index/controller/Install.php
Normal file
@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use app\BaseController;
|
||||
use app\common\traits\JumpTrait;
|
||||
use think\facade\Db;
|
||||
use think\Request;
|
||||
|
||||
class Install extends BaseController
|
||||
{
|
||||
|
||||
use JumpTrait;
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$isInstall = false;
|
||||
$installPath = config_path() . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR;
|
||||
$errorInfo = null;
|
||||
if (is_file($installPath . 'lock' . DIRECTORY_SEPARATOR . 'install.lock')) {
|
||||
// 如果你已经成功安装了后台系统 并且不想再次出现安装界面,可以把下面跳转注释取消
|
||||
// $this->redirect('/');
|
||||
$isInstall = true;
|
||||
$errorInfo = '已安装系统,如需重新安装请删除文件:/config/install/lock/install.lock,或者删除 /install 路由';
|
||||
}elseif (version_compare(phpversion(), '8.1.0', '<')) {
|
||||
$errorInfo = 'PHP版本不能小于8.1.0';
|
||||
}elseif (!extension_loaded("pdo_mysql")) {
|
||||
$errorInfo = '当前未开启pdo_mysql,无法进行安装';
|
||||
}
|
||||
if (!is_file(root_path() . '.env')) {
|
||||
$errorInfo = '.env 文件不存在,请先配置 .env 文件';
|
||||
}
|
||||
if (!$request->isAjax()) {
|
||||
$envInfo = [
|
||||
'DB_HOST' => $isInstall ? '' : env('DB_HOST', '127.0.0.1'),
|
||||
'DB_NAME' => $isInstall ? '' : env('DB_NAME', 'easyadmin8'),
|
||||
'DB_USER' => $isInstall ? '' : env('DB_USER', 'root'),
|
||||
'DB_PASS' => $isInstall ? '' : env('DB_PASS', 'root'),
|
||||
'DB_PORT' => $isInstall ? '' : env('DB_PORT', 3306),
|
||||
'DB_PREFIX' => $isInstall ? '' : env('DB_PREFIX', 'ea8_'),
|
||||
];
|
||||
$currentHost = '://';
|
||||
$result = compact('errorInfo', 'currentHost', 'isInstall', 'envInfo');
|
||||
return view('index@install/index', $result);
|
||||
}
|
||||
if ($errorInfo) $this->error($errorInfo);
|
||||
$charset = 'utf8mb4';
|
||||
$post = $request->post();
|
||||
$cover = $post['cover'] == 1;
|
||||
$database = $post['database'];
|
||||
$hostname = $post['hostname'];
|
||||
$hostport = $post['hostport'];
|
||||
$dbUsername = $post['db_username'];
|
||||
$dbPassword = $post['db_password'];
|
||||
$prefix = $post['prefix'];
|
||||
$adminUrl = $post['admin_url'];
|
||||
$username = $post['username'];
|
||||
$password = $post['password'];
|
||||
// 参数验证
|
||||
$validateError = null;
|
||||
// 判断是否有特殊字符
|
||||
$check = preg_match('/[0-9a-zA-Z]+$/', $adminUrl, $matches);
|
||||
if (!$check) {
|
||||
$validateError = '后台地址不能含有特殊字符, 只能包含字母或数字。';
|
||||
$this->error($validateError);
|
||||
}
|
||||
if (strlen($adminUrl) < 2) {
|
||||
$validateError = '后台的地址不能小于2位数';
|
||||
}elseif (strlen($password) < 5) {
|
||||
$validateError = '管理员密码不能小于5位数';
|
||||
}elseif (strlen($username) < 4) {
|
||||
$validateError = '管理员账号不能小于4位数';
|
||||
}
|
||||
if (!empty($validateError)) $this->error($validateError);
|
||||
$config = [
|
||||
"driver" => 'mysql',
|
||||
"host" => $hostname,
|
||||
"database" => $database,
|
||||
"port" => $hostport,
|
||||
"username" => $dbUsername,
|
||||
"password" => $dbPassword,
|
||||
"prefix" => $prefix,
|
||||
"charset" => $charset,
|
||||
];
|
||||
// 检测数据库连接
|
||||
$this->checkConnect($config);
|
||||
// 检测数据库是否存在
|
||||
if (!$cover && $this->checkDatabase($database)) $this->error('数据库已存在,请选择覆盖安装或者修改数据库名');
|
||||
// 创建数据库
|
||||
$this->createDatabase($database, $config);
|
||||
// 导入sql语句等等
|
||||
$config = array_merge($config, ['database' => $database]);
|
||||
$this->install($username, $password, $config, $adminUrl);
|
||||
$this->success('系统安装成功,正在跳转登录页面');
|
||||
}
|
||||
|
||||
protected function install(string $username, string $password, array $config): ?bool
|
||||
{
|
||||
$installPath = config_path() . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR;
|
||||
$sqlPath = file_get_contents($installPath . 'sql' . DIRECTORY_SEPARATOR . 'install.sql');
|
||||
$sqlArray = $this->parseSql($sqlPath, $config['prefix'], 'ea_');
|
||||
$dsn = $this->pdoDsn($config, true);
|
||||
try {
|
||||
$pdo = new \PDO($dsn, $config['username'] ?? 'root', $config['password'] ?? '');
|
||||
foreach ($sqlArray as $sql) {
|
||||
$pdo->query($sql);
|
||||
}
|
||||
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
|
||||
$tableName = 'system_admin';
|
||||
$update = [
|
||||
'username' => $username,
|
||||
'head_img' => '/static/admin/images/head.jpg',
|
||||
'password' => $hashedPassword,
|
||||
'create_time' => time(),
|
||||
'update_time' => time()
|
||||
];
|
||||
foreach ($update as $_k => $_up) {
|
||||
$pdo->query("UPDATE {$config['prefix']}{$tableName} SET {$_k} = '{$_up}' WHERE id = 1");
|
||||
}
|
||||
// 处理安装文件
|
||||
!is_dir($installPath) && @mkdir($installPath);
|
||||
!is_dir($installPath . 'lock' . DIRECTORY_SEPARATOR) && @mkdir($installPath . 'lock' . DIRECTORY_SEPARATOR);
|
||||
@file_put_contents($installPath . 'lock' . DIRECTORY_SEPARATOR . 'install.lock', date('Y-m-d H:i:s'));
|
||||
}catch (\Exception|\PDOException|\Throwable $e) {
|
||||
$this->error("系统安装失败:" . $e->getMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function parseSql($sql = '', $to = '', $from = ''): array
|
||||
{
|
||||
list($pure_sql, $comment) = [[], false];
|
||||
$sql = explode("\n", trim(str_replace(["\r\n", "\r"], "\n", $sql)));
|
||||
foreach ($sql as $key => $line) {
|
||||
if ($line == '') {
|
||||
continue;
|
||||
}
|
||||
if (preg_match("/^(#|--)/", $line)) {
|
||||
continue;
|
||||
}
|
||||
if (preg_match("/^\/\*(.*?)\*\//", $line)) {
|
||||
continue;
|
||||
}
|
||||
if (str_starts_with($line, '/*')) {
|
||||
$comment = true;
|
||||
continue;
|
||||
}
|
||||
if (str_ends_with($line, '*/')) {
|
||||
$comment = false;
|
||||
continue;
|
||||
}
|
||||
if ($comment) {
|
||||
continue;
|
||||
}
|
||||
if ($from != '') {
|
||||
$line = str_replace('`' . $from, '`' . $to, $line);
|
||||
}
|
||||
if ($line == 'BEGIN;' || $line == 'COMMIT;') {
|
||||
continue;
|
||||
}
|
||||
$pure_sql[] = $line;
|
||||
}
|
||||
//$pure_sql = implode($pure_sql, "\n");
|
||||
$pure_sql = implode("\n", $pure_sql);
|
||||
return explode(";\n", $pure_sql);
|
||||
}
|
||||
|
||||
protected function createDatabase($database, $config): bool
|
||||
{
|
||||
$dsn = $this->pdoDsn($config);
|
||||
try {
|
||||
$pdo = new \PDO($dsn, $config['username'] ?? 'root', $config['password'] ?? '');
|
||||
$pdo->query("CREATE DATABASE IF NOT EXISTS `{$database}` DEFAULT CHARACTER SET {$config['charset']} COLLATE=utf8mb4_general_ci");
|
||||
}catch (\PDOException $e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function checkDatabase($database): bool
|
||||
{
|
||||
try {
|
||||
$check = Db::query("SELECT * FROM information_schema.schemata WHERE schema_name='{$database}'");
|
||||
}catch (\Throwable $exception) {
|
||||
$check = false;
|
||||
}
|
||||
if (empty($check)) {
|
||||
return false;
|
||||
}else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkConnect(array $config): ?bool
|
||||
{
|
||||
$dsn = $this->pdoDsn($config);
|
||||
try {
|
||||
$pdo = new \PDO($dsn, $config['username'] ?? 'root', $config['password'] ?? '');
|
||||
$res = $pdo->query('select VERSION()');
|
||||
$_version = $res->fetch()[0] ?? 0;
|
||||
if (version_compare($_version, '5.7.0', '<')) {
|
||||
$this->error('mysql版本最低要求 5.7.x');
|
||||
}
|
||||
}catch (\PDOException $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @param bool $needDatabase
|
||||
* @return string
|
||||
*/
|
||||
protected function pdoDsn(array $config, bool $needDatabase = false): string
|
||||
{
|
||||
$host = $config['host'] ?? '127.0.0.1';
|
||||
$database = $config['database'] ?? '';
|
||||
$port = $config['port'] ?? '3306';
|
||||
$charset = $config['charset'] ?? 'utf8mb4';
|
||||
if ($needDatabase) return "mysql:host=$host;port=$port;dbname=$database;charset=$charset";
|
||||
return "mysql:host=$host;port=$port;charset=$charset";
|
||||
}
|
||||
}
|
||||
207
app/index/view/index/index.html
Normal file
207
app/index/view/index/index.html
Normal file
@ -0,0 +1,207 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>移动端收银台</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background: #007bff;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.cashier-container {
|
||||
background: white;
|
||||
border-radius: 20px;
|
||||
padding: 30px;
|
||||
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
.header {
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
color: #333;
|
||||
font-size: 24px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.header p {
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.form-group input,
|
||||
.form-group textarea {
|
||||
width: 100%;
|
||||
padding: 15px;
|
||||
border: 2px solid #e1e5e9;
|
||||
border-radius: 10px;
|
||||
font-size: 16px;
|
||||
transition: border-color 0.3s;
|
||||
}
|
||||
|
||||
.form-group input:focus,
|
||||
.form-group textarea:focus {
|
||||
outline: none;
|
||||
border-color: #007bff;
|
||||
}
|
||||
|
||||
.amount-input {
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
padding-left: 45px;
|
||||
}
|
||||
|
||||
.amount-input-container {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.currency-icon {
|
||||
position: absolute;
|
||||
left: 15px;
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
color: #007bff;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.blinking-cursor {
|
||||
position: absolute;
|
||||
left: 35px;
|
||||
font-size: 20px;
|
||||
color: #007bff;
|
||||
animation: blink 1s infinite;
|
||||
}
|
||||
|
||||
@keyframes blink {
|
||||
0%, 50% {
|
||||
opacity: 1;
|
||||
}
|
||||
51%, 100% {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.payment-method {
|
||||
background: #f8f9fa;
|
||||
border-radius: 10px;
|
||||
padding: 15px;
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.qq-icon {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
background: #12b7f5;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.pay-button {
|
||||
width: 100%;
|
||||
background: #007bff;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 18px;
|
||||
border-radius: 15px;
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
|
||||
.pay-button:hover {
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.pay-button:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
color: #e74c3c;
|
||||
font-size: 14px;
|
||||
margin-top: 5px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.amount-range {
|
||||
color: #666;
|
||||
font-size: 12px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
textarea {
|
||||
resize: vertical;
|
||||
min-height: 80px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="cashier-container">
|
||||
<div class="header">
|
||||
<h1>收银台</h1>
|
||||
<p>安全快捷的移动支付</p>
|
||||
</div>
|
||||
|
||||
<form method="post" action="/">
|
||||
<div class="form-group">
|
||||
<label for="amount">支付金额 (元)</label>
|
||||
<div class="amount-input-container">
|
||||
<span class="currency-icon">¥</span>
|
||||
<input type="number" id="amount" name="amount" class="amount-input"
|
||||
placeholder="请输入金额" min="{:sysConfig('site','site_mix')}" max="{:sysConfig('site','site_max')}" step="1" required>
|
||||
</div>
|
||||
<div class="amount-range">支付范围:¥{:sysConfig('site','site_mix')} - ¥{:sysConfig('site','site_max')}</div>
|
||||
<div class="error-message" id="amountError">请输入{:sysConfig('site','site_mix')}-{:sysConfig('site','site_max')}元之间的金额</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="pay-button" id="payButton">
|
||||
发起支付
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
80
app/index/view/index/reloads.html
Normal file
80
app/index/view/index/reloads.html
Normal file
@ -0,0 +1,80 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>获取支付状态</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<style>
|
||||
.loading {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="bg-gray-50 min-h-screen flex flex-col items-center justify-center">
|
||||
|
||||
<div class="w-11/12 max-w-md bg-white rounded-xl shadow p-5 text-center space-y-3">
|
||||
<!-- 蓝色提示 -->
|
||||
<div id="msg-blue" class="bg-blue-100 text-blue-800 py-2 rounded">
|
||||
若取码失败,可以尝试重新发起支付
|
||||
</div>
|
||||
|
||||
<!-- 黄色提示 -->
|
||||
<div id="msg-yellow" class="bg-yellow-100 text-yellow-800 py-2 rounded">
|
||||
正在努力匹配订单中,已等待时间 <span id="waitTime">0</span> 秒
|
||||
</div>
|
||||
|
||||
<!-- 红色提示 -->
|
||||
<div id="msg-red" class="bg-red-100 text-red-800 py-2 rounded">
|
||||
系统正在通过安全验证,取码时间较长,请您耐心等待,最长需要 <span id="maxTime">180</span> 秒。
|
||||
</div>
|
||||
|
||||
<div class="flex justify-center pt-3">
|
||||
<svg class="loading w-6 h-6 text-gray-400" fill="none" stroke="currentColor" stroke-width="2"
|
||||
viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round"
|
||||
d="M12 4v4m0 8v4m8-8h4M4 12H0m16.95 7.05l2.83 2.83M4.22 4.22l2.83 2.83m0 10.9l-2.83 2.83M19.78 4.22l-2.83 2.83" />
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let wait = 0;
|
||||
const waitSpan = document.getElementById("waitTime");
|
||||
const maxTime = document.getElementById("maxTime");
|
||||
|
||||
function updateWaitTime() {
|
||||
wait++;
|
||||
waitSpan.textContent = wait;
|
||||
}
|
||||
|
||||
// 每秒计时
|
||||
setInterval(updateWaitTime, 1000);
|
||||
|
||||
// 每3秒请求一次后端接口
|
||||
setInterval(async () => {
|
||||
try {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const rid = urlParams.get('rid');
|
||||
const res = await fetch('/index/index/status?rid='+rid); // 后端返回 {status: "blue"|"yellow"|"red"|"success", payUrl: "xxx"}
|
||||
let data = await res.json();
|
||||
data = data.data;
|
||||
// 根据status切换显示状态
|
||||
// document.getElementById("msg-blue").style.display = data.status === "blue" ? "block" : "none";
|
||||
// document.getElementById("msg-yellow").style.display = data.status === "yellow" ? "block" : "none";
|
||||
// document.getElementById("msg-red").style.display = data.status === "red" ? "block" : "none";
|
||||
|
||||
// 若status为success,则跳转支付链接
|
||||
if (data.url !== null && data.url !== undefined && data.url !== "") {
|
||||
window.location.href = data.url;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("请求失败", e);
|
||||
}
|
||||
}, 3000);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user