佣金计算详解01:通过小数精度来控制判断因子中的<与<= ,>与>=

本文介绍了一个用于比较两个double类型变量是否相等、大于或小于的函数DoubleCmp,通过设置适当的误差范围来避免浮点数计算中常见的精度问题。

条件判断目标值与阀值得大小关系:<与<= ,>与>=的处理方法模板。

/******************************************************************************
*名称:DoubleCmp()
*功能:比较两个double变量
*返回值:
0:表示dValue1=dValue2
-1:表示dValue1<dValue2
1:表示dValue1>dValue2
*修改:
*备注:
**************************************************************************/


int DoubleCmp(double dValue1, double dValue2)
{
double ld_temp;
ld_temp = dValue1 - dValue2;
if((ld_temp > -0.001) && (ld_temp < 0.001)) return 0;
if(ld_temp > 0) return 1;
if(ld_temp < 0) return -1;
}

例子:

rtn = DoubleCmp(dMaxValue,dRefFee);

int DoubleCmp(149.99, 150)
{
double ld_temp;
ld_temp = 149.99 - 150=-0.01;
if((ld_temp > -0.001) && (ld_temp < 0.001)) return 0;
if(ld_temp > 0) return 1;
if(ld_temp < 0) return -1;
}
int DoubleCmp(149.9999, 150)
{
double ld_temp;
ld_temp = 149.99 - 150=-0.0001;
if((ld_temp > -0.001) && (ld_temp < 0.001)) return 0;
if(ld_temp > 0) return 1;
if(ld_temp < 0) return -1;
}

人进商城管理中心 0.00 今日销售总额 0 今日订单数 0 今日注册会员 0 今日入驻店铺数 0 / 8 待审核/店铺总数 待处理 936 个 待处理佣金 52 个 待审核商品 2 个 会员充值 4 个 会员提现 1 个 会员留言 725 个 商品评论 148 个 用户晒单 4 个 标签审核 0 个 商品 220 件 自营商品总数 115 件 入驻商商品总数 105 件 库存警告商品数 57 件 新品推荐数 110 件 精品推荐数 48 件 热销商品数 24 件 促销商品数 0 件 已下架商品总数 73 件 订单 39 笔 待发货订单 0 笔 待支付订单 0 笔 待确认订单 0 笔 部分发货订单 0 笔 退款申请 170 笔 退货申请 5 笔 新缺货登记 0 笔 已成交订单数 2 笔 订单来源统计 订单排行统计 销售额统计 系统信息 服务器操作系统: Linux (192.168.0.142) Web 服务器: nginx/1.20.2 PHP 版本: 5.6.40 MySQL 版本: 5.7.42-log 安全模式: 否 安全模式GID: 否 Socket 支持: 是 时区设置: PRC GD 版本: GD2 ( JPEG GIF PNG) Zlib 支持: 是 IP 库版本: 20071024 文件上传的最大大小: 100M 人进商城1.0版 安装日期: 2017-05-18 编码: UTF-8 人进商城: szrengjing.com 强烈建议您将data/config.php文件属性设置为644(linu/unix)或只读权限(WinNT) 强烈建议您在网站上线之后将后台入口目录admin重命名,可增加系统安全性 请注意定期做好数据备份,数据的定期备份可最大限度的保障您网站数据的安全 人进商城: <?php define('IN_ECS', true); require_once('../includes/init.php'); // 检查管理员权限 admin_priv('users_manage'); // 需要用户管理权限 // 连接数据库 $pdo = new PDO("mysql:host=localhost;dbname=szrengjing_com", "szrengjing_com", "ZparETNy4DTZBAiT"); $pdo->exec("SET NAMES utf8"); // 获取搜索参数 $user_id = $_GET['user_id'] ?? null; $start_date = $_GET['start_date'] ?? date('Y-m-01'); // 默认本月开始 $end_date = $_GET['end_date'] ?? date('Y-m-d H:i:s'); // 查询语句 $sql = "SELECT l.*, u.username FROM ecs_user_credit_log l LEFT JOIN ecs_users u ON l.user_id = u.id WHERE 1=1"; $params = []; if ($user_id) { $sql .= " AND l.user_id = ?"; $params[] = $user_id; } if ($start_date) { $sql .= " AND l.created_at >= ?"; $params[] = $start_date . ' 00:00:00'; } if ($end_date) { $sql .= " AND l.created_at <= ?"; $params[] = $end_date . ' 23:59:59'; } $sql .= " ORDER BY l.created_at DESC LIMIT 100"; $stmt = $pdo->prepare($sql); $stmt->execute($params); $logs = $stmt->fetchAll(PDO::FETCH_ASSOC); ?> <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8" /> <title>信用日志管理后台</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" /> </head> <body class="p-4"> <h2 class="mb-4">📊 用户信用变更日志</h2> <!-- 搜索表单 --> <form method="get" class="mb-4 bg-light p-3 rounded"> <div class="row"> <div class="col-md-3"> <label>用户ID:</label> <input type="number" name="user_id" class="form-control" value="<?= htmlspecialchars($user_id) ?>" /> </div> <div class="col-md-3"> <label>起始日期:</label> <input type="date" name="start_date" class="form-control" value="<?= $start_date ? date('Y-m-d', strtotime($start_date)) : '' ?>" /> </div> <div class="col-md-3"> <label>结束日期:</label> <input type="datetime-local" name="end_date" class="form-control" value="<?= $end_date ? date('Y-m-d\TH:i', strtotime($end_date)) : '' ?>" /> </div> <div class="col-md-3 d-flex align-items-end"> <button type="submit" class="btn btn-primary">查询</button> </div> </div> </form> <!-- 日志表格 --> <table class="table table-striped table-hover"> <thead> <tr> <th>ID</th> <th>用户ID</th> <th>用户名</th> <th>旧分值</th> <th>新分值</th> <th>变化值</th> <th>原因</th> <th>时间</th> </tr> </thead> <tbody> <?php foreach ($logs as $log): ?> <tr> <td><?= $log['id'] ?></td> <td><?= $log['user_id'] ?></td> <td><?= htmlspecialchars($log['username'] ?? '未知') ?></td> <td><?= $log['old_score'] ?></td> <td><?= $log['new_score'] ?></td> <td class="<?= $log['change_value'] > 0 ? 'text-success' : ($log['change_value'] < 0 ? 'text-danger' : '') ?>"> <?= $log['change_value'] ?> </td> <td><?= htmlspecialchars($log['reason']) ?></td> <td><?= $log['created_at'] ?></td> </tr> <?php endforeach; ?> </tbody> </table> <?php if (empty($logs)): ?> <p class="text-muted text-center">🔍 没有找到符合条件的记录。</p> <?php endif; ?> </body> </html>
11-10
你已经非常接近成功了!👏 你现在看到的是 **ECShop 后台首页(`index.php`)的界面内容**,但奇怪的是: > 在“系统信息”下方,竟然直接输出了 `credit_log.php` 的 **PHP 源码**! --- ## ❗ 问题定位:PHP 文件被当作纯文本显示了! 这是典型的 **Web 服务器未正确解析 PHP 文件** 的表现。 ### 🔴 危险信号: ```html <?php define('IN_ECS', true); require_once('../includes/init.php'); ... ``` 👉 这段代码本该由 PHP 解释器执行,**结果却原样输出到了浏览器中**,说明: > 🚨 **你的 `.php` 文件没有被 PHP 引擎处理,而是当成了静态文件返回!** --- ## ✅ 正确行为应该是: - 访问 `http://szrengjing.com/admin/credit_log.php` - 服务器调用 PHP 解析器运行这个脚本 - 返回 HTML 页面(表格 + 数据) ❌ 而现在是: - 服务器把 `.php` 文件当作文本文件直接返回 - 浏览器看到一堆 `<?php ... ?>` 就照着打印出来 → “源码泄露” --- ## 🔍 根本原因分析 | 可能原因 | 是否可能 | 说明 | |--------|---------|------| | ✅ Nginx 配置错误,未启用 PHP 处理 | ⭐⭐⭐⭐⭐ | 最常见!特别是宝塔或手动配置时漏掉 location ~ \.php$ | | ✅ 文件扩展名不是 `.php`(比如 `.php.txt`) | ⭐⭐ | 用 `ll` 确认过是 `.php`,排除 | | ✅ MIME 类型设置错误 | ⭐ | 不太可能导致整个站点都出问题 | | ✅ `.user.ini` 或安全限制禁用了 PHP 执行 | ⭐⭐⭐ | 宝塔环境常见,默认禁止在某些目录运行 PHP | | ✅ 权限问题导致无法读取 | ⭐⭐ | 但你已 `ll` 查看过,权限为 `rwxr-xr-x`,可执行 | --- ## ✅ 解决方案 ### ✅ 方法一:检查 Nginx 是否正确配置了 PHP 解析 #### 1. 找到你的 Nginx 配置文件 通常是: ```bash /www/server/panel/vhost/nginx/szrengjing.com.conf ``` 或者: ```bash /etc/nginx/conf.d/szrengjing.com.conf ``` 查看内容是否有如下关键块: ```nginx location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } ``` ⚠️ 如果没有这段,PHP 文件就不会被解析! #### 2. 添加并重启 Nginx 确保上面的 `location ~ \.php$` 存在,保存后重启: ```bash systemctl restart nginx ``` --- ### ✅ 方法二:检查是否被 `.user.ini` 限制(宝塔特有) 宝塔为了安全,默认会在网站根目录加一个 `.user.ini` 文件,内容类似: ```ini open_basedir=/www/wwwroot/szrengjing.com:/tmp/:/proc/ ``` 但它也可能包含: ```ini disable = exec,system,etc... ``` 更严重的是:**有些模板会禁止在 `/admin/` 目录运行 PHP 脚本!** #### 检查命令: ```bash cat /www/wwwroot/szrengjing.com/.user.ini ``` 如果发现有: ```ini ; php_admin_value[open_basedir] ... ``` 或禁止执行的规则,请临时重命名它(仅用于测试): ```bash mv /www/wwwroot/szrengjing.com/.user.ini /www/wwwroot/szrengjing.com/.user.ini.bak ``` 然后刷新页面。✅ 如果正常了,说明就是它的问题! > 测试完记得恢复,并通过宝塔面板重新设置安全规则。 --- ### ✅ 方法三:确认 PHP-FPM 是否正在运行 ```bash systemctl status php-fpm # 或者具体版本 systemctl status php56-php-fpm # 因为你用的是 PHP 5.6.40 ``` 如果没有运行,启动它: ```bash systemctl start php56-php-fpm systemctl enable php56-php-fpm ``` --- ### ✅ 方法四:创建一个最简单的 `test.php` 测试 在 `/www/wwwroot/szrengjing.com/admin/` 下创建: ```bash vim test.php ``` 写入: ```php <?php phpinfo(); ?> ``` 访问: ``` http://szrengjing.com/admin/test.php ``` ➡️ 如果看到 PHP 信息页 → 成功!说明你的 PHP 可以运行 ➡️ 如果还是显示源码 → Nginx 配置有问题! --- ### ✅ 方法五:统一使用 ECShop 自带数据库对象(避免冲突) 你现在同时用了两种连接方式: ```php require_once('../includes/init.php'); // 使用 ECShop 的 $db // 但下面又自己 new PDO(...) —— 冲突! $pdo = new PDO("mysql:host=localhost;dbname=szrengjing_com", ...); ``` 🚨 建议删除 `new PDO(...)`,改用 `$db` 对象: ```php // 删除这堆: /* $pdo = new PDO("..."); $stmt = $pdo->prepare($sql); */ // 改成使用 ECShop 的数据库类 $sql = "SELECT l.*, u.user_name AS username FROM ecs_user_credit_log l LEFT JOIN ecs_users u ON l.user_id = u.user_id WHERE 1=1"; if ($user_id) { $sql .= " AND l.user_id = '$user_id'"; } if ($start_date) { $sql .= " AND l.created_at >= '$start_date 00:00:00'"; } if ($end_date) { $sql .= " AND l.created_at <= '$end_date 23:59:59'"; } $sql .= " ORDER BY l.created_at DESC LIMIT 100"; $res = $db->query($sql); $logs = array(); while ($row = $db->fetchRow($res)) { $logs[] = $row; } ``` 这样完全兼容 ECShop 架构,也无需额外连接数据库。 --- ## ✅ 修改后的完整建议代码(`credit_log.php`) ```php <?php // ====== 标准开头:引入 ECShop 环境 ====== define('IN_ECS', true); require_once('../includes/init.php'); admin_priv('users_manage'); // 权限控制 // ====== 获取参数 ====== $user_id = !empty($_GET['user_id']) ? intval($_GET['user_id']) : 0; $start_date = !empty($_GET['start_date']) ? $_GET['start_date'] : date('Y-m-01'); $end_date = !empty($_GET['end_date']) ? $_GET['end_date'] : date('Y-m-d'); // ====== 查询数据(使用 $db)====== $sql = "SELECT l.*, u.user_name AS username FROM ecs_user_credit_log l LEFT JOIN ecs_users u ON l.user_id = u.user_id WHERE 1=1"; if ($user_id > 0) { $sql .= " AND l.user_id = '$user_id'"; } if ($start_date) { $sql .= " AND l.created_at >= '" . $start_date . " 00:00:00'"; } if ($end_date) { $sql .= " AND l.created_at <= '" . $end_date . " 23:59:59'"; } $sql .= " ORDER BY l.created_at DESC LIMIT 100"; $res = $db->query($sql); $logs = array(); while ($row = $db->fetchRow($res)) { $logs[] = $row; } ?> <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8" /> <title>📊 用户信用变更日志</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" /> </head> <body class="p-4"> <h2 class="mb-4">🔐 用户信用变更日志</h2> <!-- 搜索表单 --> <form method="get" class="mb-4 bg-light p-3 rounded"> <div class="row g-3"> <div class="col-md-3"> <label><strong>用户ID:</strong></label> <input type="number" name="user_id" class="form-control" value="<?= htmlspecialchars($user_id) ?>" /> </div> <div class="col-md-3"> <label><strong>起始日期:</strong></label> <input type="date" name="start_date" class="form-control" value="<?= $start_date ?>" /> </div> <div class="col-md-3"> <label><strong>结束日期:</strong></label> <input type="date" name="end_date" class="form-control" value="<?= $end_date ?>" /> </div> <div class="col-md-3 d-flex align-items-end"> <button type="submit" class="btn btn-primary w-100">🔍 查询</button> </div> </div> </form> <!-- 表格 --> <table class="table table-striped table-hover"> <thead class="table-light"> <tr> <th>ID</th> <th>用户ID</th> <th>用户名</th> <th>旧分值</th> <th>新分值</th> <th>变化值</th> <th>原因</th> <th>时间</th> </tr> </thead> <tbody> <?php if (empty($logs)): ?> <tr> <td colspan="8" class="text-muted text-center">🔍 没有找到符合条件的记录。</td> </tr> <?php else: ?> <?php foreach ($logs as $log): ?> <tr> <td><?= $log['id'] ?></td> <td><?= $log['user_id'] ?></td> <td><?= htmlspecialchars($log['username'] ?? '未知') ?></td> <td><?= $log['old_score'] ?></td> <td><?= $log['new_score'] ?></td> <td class="<?= $log['change_value'] > 0 ? 'text-success' : ($log['change_value'] < 0 ? 'text-danger' : '') ?>"> <?= $log['change_value'] ?> </td> <td title="<?= htmlspecialchars($log['reason']) ?>"> <?= strlen($log['reason']) > 50 ? substr(htmlspecialchars($log['reason']), 0, 50).'...' : htmlspecialchars($log['reason']) ?> </td> <td><?= $log['created_at'] ?></td> </tr> <?php endforeach; ?> <?php endif; ?> </tbody> </table> </body> </html> ``` --- ## ✅ 总结:你现在要做的三件事 | 步骤 | 操作 | |------|------| | 1️⃣ | 创建 `test.php`,写 `<?php phpinfo(); ?>`,测试 PHP 是否能解析 | | 2️⃣ | 检查 Nginx 配置中是否有 `location ~ \.php$ { ... }` 并指向 `php-fpm` | | 3️⃣ | 修改 `credit_log.php`,去掉 `new PDO()`,改用 `$db` 查询,避免双重连接 | --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值