This article illustrates the recursive royalty scheme implemented by PHP. Share to everyone for your reference, specific as follows:
The most recent CRM project uses a recursive royalty scheme, which is analyzed as follows:
The SQL statement is as follows:
CREATE TABLE ' crm_proxy_bonux_rule ' (
' id ' int (one) not NULL auto_increment COMMENT ' Partial commission rule ID ',
' Bouns_rule_ Name ' varchar ' NOT null COMMENT ' rule names, such as the D package 0-20 range ',
' rid ' bigint ' default NULL COMMENT ' is 0, which is the default global setting ',
' Start_rang ' smallint (6) default null COMMENT ' Start range ',
' End_rang ' smallint (6) default null COMMENT ' End Range ',
' Bonus_ Rate ' smallint (6) default null COMMENT ' royalty rate ',
' Bonus_reward ' decimal (8,2) default null COMMENT ' Reward cash ',
' Chain_ A value on the pre ' int (one) default null COMMENT ' list defaults to 0, representing the root node ',
' chain_next ' int (a) default null COMMENT ' list next value ',
' Is_ Standard ' enum (' 0 ', ' 1 ') DEFAULT ' 0 ' COMMENT ' is standard,
PRIMARY KEY (' id ')
) Engine=innodb auto_increment=12 DEFAULT Charset=utf8;
The PHP implementation code is as follows:
Private Function Bouns_recursion ($range, $standard,& $rule _list, $amount) {$price = 1000; $max = $standard [' End_rang '];//maximum $min = $standard [' Start_rang '];//min $bonus _rate = $standard [' Bonus_rate '];//
Dividend rate if ($range < $min) {return false;
} $standard _amount = 0;
$plus = 0; Is the standard first if ($standard [' Is_standard ']==1) {$standard _amount = $price * $min * $bonus _rate/100;//Commission 600 30 0}else{$plus = 1;//second to add} if ($range > $max) {$number = ($max-$min) + $plus;/= travel value 5 4-3 = = 1 $amount = ($price * $number * $bonus _rate/100); For Commission}else{$number = ($range-$min) + $plus;//Business trip value 4 1 $amount = ($price * $number * $bonus _rate/ 100); Commission $amount = $amount + $standard _amount;//800 if ($rule _list[$standard [' Chain_next ']]) && $ran GE > $max) {return $amount + = $this->bouns_recursion ($range, $rule _list[$standard [' Chain_next ']], $rule _list,$
Amount); return $amount;
}
I hope this article will help you with your PHP programming.