我试图理解该Excel公式的逻辑,尤其是带有“ x”的行的含义。有人可以帮我伪逻辑或提取数学公式吗?
Excel公式(部分):
IF(INDEX(TurboCheck,pLookupIndex)="T",
IF(J4<INDEX(BaseMiles,pLookupIndex),(INDEX(BaseMiles,pLookupIndex)-J4)*-T_Under_Base,
IF(J4>INDEX(Max_Mileage,pLookupIndex),"x",(J4-INDEX(BaseMiles,pLookupIndex))*T_Over_Base)
),
IF(J4<INDEX(BaseMiles,pLookupIndex),(INDEX(BaseMiles,pLookupIndex)-J4)*-NT_Under_Base,
IF(J4>INDEX(Max_Mileage,pLookupIndex),"x",(J4-INDEX(BaseMiles,J8))*NT_Over_Base)
)
)
尝试将其构建为(PHP)逻辑:
J4 = $mileage
INDEX(BaseMiles,pLookupIndex) = $BaseMiles
T_Under_Base = $T_Under_Base
T_Over_Base = $T_Over_Base
NT_Under_Base = $NT_Under_Base
NT_Over_Base = $NT_Over_Base
INDEX(Max_Mileage,pLookupIndex) = $MaxMiles
INDEX(TurboCheck,pLookupIndex) = $is_turbo
IF($is_turbo) {
if ($mileage<$BaseMiles) {
$calc = (($BaseMiles - $mileage) * (-1 * $T_Under_Base));
if ($mileage > $MaxMiles) {
$calc = (($mileage - $BaseMiles)*$T_Over_Base)
}
}
else if ($mileage < $BaseMiles)
$calc = (($mileage - $BaseMiles) * (-1 * $NT_Under_Base));
if ($mileage > $BaseMiles) {
$calc = (($mileage - $BaseMiles) * $NT_Over_Base);
}
}
}
显然这是不对的,但我想展示我到目前为止的情况。
更新:我将此作为一种可行的方法,但尚未完全验证,但想感谢大家的帮助!
/**
* Calculate Adjustment - adapted from excel sheet formula:
*
* IF(
* IF(INDEX(TurboCheck,pLookupIndex)="T",
* IF(J4<INDEX(BaseMiles,pLookupIndex),(INDEX(BaseMiles,pLookupIndex)-J4)*-T_Under_Base,
* IF(J4>INDEX(Max_Mileage,pLookupIndex),"x",(J4-INDEX(BaseMiles,pLookupIndex))*T_Over_Base),
* IF(J4<INDEX(BaseMiles,pLookupIndex),(INDEX(BaseMiles,pLookupIndex)-J4)*-NT_Under_Base,
* IF(J4>INDEX(Max_Mileage,pLookupIndex),"x",(J4-INDEX(BaseMiles,pLookupIndex))*NT_Over_Base))
* )
* < (-Max_RV_Adj*J3),-Max_RV_Adj*J3,
* IF(INDEX(TurboCheck,pLookupIndex)="T",
* IF(J4<INDEX(BaseMiles,pLookupIndex),(INDEX(BaseMiles,pLookupIndex)-J4)*-T_Under_Base,
* IF(J4>INDEX(Max_Mileage,pLookupIndex),"x",(J4-INDEX(BaseMiles,pLookupIndex))*T_Over_Base)),
* IF(J4<INDEX(BaseMiles,pLookupIndex),(INDEX(BaseMiles,pLookupIndex)-J4)*-NT_Under_Base,
* IF(J4>INDEX(Max_Mileage,pLookupIndex),"x",(J4-INDEX(BaseMiles,J8))*NT_Over_Base)))
* )
*
* @param $filters
* @return array
*/
private function calcAdjustment($filters)
{
$mileage = $filters['mileage'];
$BaseMiles = $filters['base'];
$MaxMiles = $filters['max_mi'];
$Max_RV_Adj_Pct = (!empty($this->lease_defaults['max_rv_adj'])) ? $this->lease_defaults['max_rv_adj'] : 10; //percentage //
$BaseRV = $filters['base_residual_value'];
$adjust = null;
if ($mileage < $MaxMiles) {
if ($filters['is_turbo']) {
$Under_Base = $filters['under_base']['turbo'];
$Over_Base = $filters['over_base']['turbo'];
} else {
$Under_Base = $filters['under_base']['base'];
$Over_Base = $filters['over_base']['base'];
}
if ($mileage < $BaseMiles) {
$adjust = (($BaseMiles - $mileage) * (-1 * $Under_Base));
} else {
$adjust = (($mileage - $BaseMiles) * $Over_Base);
}
if ($adjust < (-$Max_RV_Adj_Pct * $BaseRV)) {
$adjust = (($mileage - $adjust) * $Over_Base); // can be negative value
}
}
if ($adjust != null) {
$ret = array("valid" => true, "adjust" => $adjust);
} else {
$ret = array("valid" => true, "adjust" => null);
}
return $ret;
}
答案 0 :(得分:3)
if ($is_turbo == 'T') {
if ($mileage < $BaseMiles) {
return (($BaseMiles - $mileage) * (-1 * $T_Under_Base));
} else {
if ($mileage > $MaxMiles) {
return 'x';
} else {
return (($mileage - $BaseMiles)*$T_Over_Base);
}
}
} else {
if ($mileage < $BaseMiles) {
return ($BaseMiles - $mileage) * (-1 * $NT_Under_Base);
} else {
if ($mileage > $MaxMiles) {
return 'x';
} else {
return ($mileage - $BaseMiles) * $NT_Over_Base;
}
}
}
假设J8
是pLookupIndex
。