文件
mashangyoujiu/_ai_archive/scripts/simple_test.php

112 行
3.4 KiB
PHP

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
// 简化的权限测试
// 启动session
session_start();
echo "=== 简化权限测试 ===\n";
// 1. 手动设置用户session(模拟登录成功后的状态)
echo "1. 设置用户Session\n";
$user = array(
'id' => '1',
'pid' => '0',
'name' => '收银系统',
'avatar_id' => '0',
'user_type' => '1',
'login_name' => '13888888888',
'system_user_id' => '1',
'jurisdiction_group_id' => '1',
'is_touch' => 1,
'avatar' => '',
'user_name' => '合伙人',
'end_time' => '',
'login_type' => 1
);
// 设置jurisdiction_user session
$_SESSION['jurisdiction_user'] = $user;
echo "已设置 jurisdiction_user session\n";
// 设置合伙人相关session
$_SESSION['admin_userinfo'] = array('id' => $user['system_user_id']);
echo "已设置合伙人相关session\n";
echo "Session设置完成\n\n";
// 2. 包含ThinkPHP框架
echo "2. 加载ThinkPHP框架\n";
define('APP_PATH', './Application/');
define('RUNTIME_PATH', './Runtime/');
// 设置POST数据
$_POST['store_name'] = '测试门店名称';
$_POST['store_address'] = '测试门店地址';
$_POST['store_phone'] = '13800138000';
echo "POST数据已设置\n\n";
// 3. 检查session状态
echo "3. 检查Session状态\n";
echo "jurisdiction_user: " . (isset($_SESSION['jurisdiction_user']) ? 'EXISTS' : 'NOT SET') . "\n";
if (isset($_SESSION['jurisdiction_user'])) {
echo "用户ID: " . $_SESSION['jurisdiction_user']['id'] . "\n";
echo "用户类型: " . $_SESSION['jurisdiction_user']['user_type'] . "\n";
echo "登录类型: " . $_SESSION['jurisdiction_user']['login_type'] . "\n";
}
echo "\n";
// 4. 测试权限验证逻辑(模拟BaseController的_initialize方法)
echo "4. 测试权限验证逻辑\n";
$jurisdiction_user = isset($_SESSION['jurisdiction_user']) ? $_SESSION['jurisdiction_user'] : null;
if (!$jurisdiction_user) {
echo "权限验证失败: 您无权操作1\n";
} else {
echo "权限验证通过\n";
echo "用户信息: " . $jurisdiction_user['name'] . " (" . $jurisdiction_user['user_name'] . ")\n";
// 5. 模拟storeSet方法的逻辑
echo "\n5. 模拟storeSet方法\n";
// 检查是否为POST请求
if ($_SERVER['REQUEST_METHOD'] === 'POST' || !empty($_POST)) {
echo "检测到POST请求\n";
// 获取参数
$store_name = isset($_POST['store_name']) ? $_POST['store_name'] : '';
$store_address = isset($_POST['store_address']) ? $_POST['store_address'] : '';
$store_phone = isset($_POST['store_phone']) ? $_POST['store_phone'] : '';
echo "门店名称: " . $store_name . "\n";
echo "门店地址: " . $store_address . "\n";
echo "门店电话: " . $store_phone . "\n";
// 模拟业务逻辑处理
$param = array(
'store_name' => $store_name,
'store_address' => $store_address,
'store_phone' => $store_phone,
'merchant_id' => 1, // 模拟merchant_id
'store_id' => 1, // 模拟store_id
'operator_id' => $jurisdiction_user['id'],
'source' => 0,
'type' => 4
);
echo "处理参数: \n";
print_r($param);
echo "\n模拟调用Store->storeXcxSet()方法\n";
echo "返回结果: {\"status\":1,\"msg\":\"设置成功\"}\n";
} else {
echo "非POST请求,无法处理\n";
}
}
echo "\n=== 测试完成 ===\n";
?>