业绩累计大计算存在问题
大公司业务场景
业绩结算呈现阶梯状
销售业绩大于 | 销售业绩小于 | 提成比例 | |
0 | 1000 | 5% | |
1000 | 100000 | 15% | |
100000 | 1000000 | 20% | |
1000000 | 10000000 | 30% |
多次查询缺点
在基于 Web 与 SQL Server 的应用系统中,Web 应用与 SQL Server 数据库之间的 “握手” 操作,即建立连接的过程,对系统性能有着显著影响。随着握手次数的增多,系统延迟呈现增大的趋势。这一现象主要源于以下几方面原因:
- 连接开销:每次握手都需要在 Web 服务器与 SQL Server 之间进行一系列复杂的网络交互,包括 TCP 三次握手建立网络连接,以及后续的数据库连接认证等操作。这些操作不仅消耗网络带宽资源,还会占用服务器的 CPU 和内存等计算资源。随着握手次数增加,资源消耗不断累积,导致系统整体性能下降,延迟增大。
- 资源竞争:Web 应用可能同时处理多个用户请求,每个请求都可能需要与 SQL Server 进行握手连接。这就导致在高并发场景下,多个连接请求同时竞争数据库服务器的资源,如连接池中的连接数量有限,过多的握手请求可能导致连接池耗尽,新的请求只能等待资源释放,从而增加了请求的响应延迟。
- 连接管理成本:频繁的握手意味着频繁的连接创建与销毁。数据库服务器需要对这些连接进行管理,包括分配和回收资源、维护连接状态等。这增加了数据库服务器的管理负担,进一步影响系统性能,使得处理新请求的速度变慢,延迟加大。
传统难点
每个职员,每种规则不一样,代码又不能想SQL一样快速多条件检索,因此未来之窗自研发了类似SQL得调用规则
强大的查询表达能力
- 灵活的条件筛选:SQL 允许使用
WHERE
子句定义各种复杂条件来筛选数据
数据二维数组多条件查询+缓存seseion
function 东方仙盟_阶梯数据查询_业绩提成公式($全数据,$会员,$业绩类型,$业绩金额){
return array_filter($全数据, function ($subArray) use ($aValue, $会员, $业绩金额) {
return isset($subArray['业绩到'], $subArray['提成'], $subArray['会员'], $subArray['业绩到']) &&
$subArray['业绩到'] < 300 &&
$subArray['提成'] === $业绩类型 &&
$subArray['会员'] === $会员 &&
});
}
调用案例
function filterArray($twoDArray, $aValue, $cValue, $eValue)
{
return array_filter($twoDArray, function ($subArray) use ($aValue, $cValue, $eValue) {
return isset($subArray['end'], $subArray['a'], $subArray['c'], $subArray['e']) &&
$subArray['end'] < 300 &&
$subArray['a'] === $aValue &&
$subArray['c'] === $cValue &&
$subArray['e'] === $eValue;
});
}
// 示例用法
$twoDArray = [
['end' => 200, 'a' => 1, 'c' => '0000', 'e' => 'test1', 'other' => 'data1'],
['end' => 400, 'a' => 1, 'c' => '0000', 'e' => 'test2', 'other' => 'data2'],
['end' => 150, 'a' => 1, 'c' => '0000', 'e' => 'test1', 'other' => 'data3'],
['end' => 250, 'a' => 2, 'c' => '0000', 'e' => 'test1', 'other' => 'data4'],
['end' => 280, 'a' => 1, 'c' => '1111', 'e' => 'test1', 'other' => 'data5']
];
$result = filterArray($twoDArray, 1, '0000', 'test1');
print_r($result);
在上述代码中,定义了一个名为 filterArray 的函数,该函数接受四个参数:
$twoDArray:要进行筛选的二维数组。
$aValue:用于匹配子数组中 a 键对应的值。
$cValue:用于匹配子数组中 c 键对应的值。
$eValue:用于匹配子数组中 e 键对应的值。
函数内部使用 array_filter 结合匿名函数进行筛选,匿名函数通过 use 关键字引入外部的 $aValue、$cValue 和 $eValue 变量,并在子数组同时满足存在 end、a、c、e 键,且 end 小于 300,a 等于 $aValue,c 等于 $cValue,e 等于 $eValue 这些条件时,保留该子数组到结果数组中。最后通过示例调用函数并输出结果。
这里只是抛砖引玉,实际要按照业务要求适当调整。
SELECT
em.职员ID,
em.职员名称,
ISNULL((SELECT SUM(ec.提成明细)
FROM 提成表明细ec
WHERE ec.EmployeeID = em.职员ID AND ec.AchieveType = 1 {$条件混合} ), 0) AS 绩效_item,
ISNULL((SELECT SUM(ec.提成明细)
FROM 提成表明细ec
WHERE ec.EmployeeID = em.职员ID AND ec.AchieveType = 2 {$条件混合} ), 0) AS 绩效_inv,
ISNULL((SELECT SUM(ec.提成明细)
FROM 提成表明细ec
WHERE ec.EmployeeID = em.职员ID AND ec.AchieveType = 3 {$条件混合} ), 0) AS 绩效_card,
ISNULL((SELECT SUM(ec.提成明细)
FROM 提成表明细ec
WHERE ec.EmployeeID = em.职员ID AND ec.AchieveType = 4 {$条件混合} ), 0) AS 绩效_count,
ISNULL((SELECT SUM(ec.提成明细)
FROM 提成表明细ec
WHERE ec.EmployeeID = em.职员ID AND ec.AchieveType = 5 {$条件混合} ), 0) AS 绩效_recharge
,ISNULL((SELECT SUM(ec.提成明细)
FROM 提成表明细ec
WHERE ec.EmployeeID = em.职员ID AND ec.AchieveType = 1 and CardLevel ='' and 轮牌= 0 {$条件混合} ), 0) AS 绩效_item_nocardno轮牌
,ISNULL((SELECT SUM(ec.提成明细)
FROM 提成表明细ec
WHERE ec.EmployeeID = em.职员ID AND ec.AchieveType = 1 and CardLevel ='' and 轮牌= 1 {$条件混合} ), 0) AS 绩效_item_nocard轮牌
,ISNULL((SELECT SUM(ec.提成明细)
FROM 提成表明细ec
WHERE ec.EmployeeID = em.职员ID AND ec.AchieveType = 1 and CardLevel <>'' and 轮牌= 0 {$条件混合} ), 0) AS 绩效_item_cardno轮牌
,ISNULL((SELECT SUM(ec.提成明细)
FROM 提成表明细ec
WHERE ec.EmployeeID = em.职员ID AND ec.AchieveType = 1 and CardLevel <>'' and 轮牌= 1 {$条件混合} ), 0) AS 绩效_item_card轮牌
, ISNULL((SELECT SUM(ec.提成明细)
FROM 提成表明细ec
WHERE ec.EmployeeID = em.职员ID AND ec.AchieveType = 2 and CardLevel <>'' {$条件混合} ), 0) AS 绩效_inv_card
, ISNULL((SELECT SUM(ec.提成明细)
FROM 提成表明细ec
WHERE ec.EmployeeID = em.职员ID AND ec.AchieveType = 2 and CardLevel ='' {$条件混合} ), 0) AS 绩效_inv_nocard
FROM
职员 em where State=1".$query_分店;