A recursive royalty scheme instance _php technique for PHP implementation

Source: Internet
Author: User
Tags php programming

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.