Home>

Recently, a recursive commission scheme has been used in the crm project.analyse as below:

The sql statement is as follows:

create table `crm_proxy_bonux_rule` (
`id` int (11) not null auto_increment comment" Excess part is deducted from rule id ",`bouns_rule_name` varchar (20) not null comment" rule name,"D package 0-20 range",`rid` bigint (20) default null comment" is 0, which is the default global setting ",`start_rang` smallint (6) default null comment" starting range ", `end_rang` smallint (6) default null comment" End range ",`bonus_rate` smallint (6) default null comment" commission rate ",`bonus_reward` decimal (8,2) default null comment" bonus cash ",`chain_pre` int (11) default null comment" The default value of a linked list is 0, which means the root node ",`chain_next` int (11) default null comment" Next value in the list ",`is_standard` enum (" 0 "," 1 ") default" 0 "comment" Is it a standard ",primary key (`id`)
) engine=innodb auto_increment=12 default charset=utf8;

PHP implementation code is as follows:

private function bouns_recursion ($range, $standard,&$rule_list, $amount) {
   $price=1000;
   $max=$standard ["end_rang"];//The maximum value
   $min=$standard ["start_rang"];//Minimum value
   $bonus_rate=$standard ["bonus_rate"];//Dividend rate
   if ($range<$min) {
      return false;
   }
   $standard_amount=0;
   $plus=0;
   //whether it is the standard first
   if ($standard ["is_standard"] == 1) {
       $standard_amount=$price * $min * $bonus_rate/100;//ask for a commission of 600 300
    } else {
      $plus=1;//Second accumulation
   }
   if ($range>$max) {
     $number=($max-$min) + $plus;//Calculate the difference 5 4-3 == 1
     $amount=($price * $number * $bonus_rate/100);//Find a commission of 200
   } else {
      $number=($range-$min) + $plus;//Calculate the difference 4 1
      $amount=($price * $number * $bonus_rate/100);//ask for a commission
  }
   $amount=$amount + $standard_amount;//800
   if (! empty ($rule_list [$standard ["chain_next"]])&&$range>$max) {
      return $amount +=$this->bouns_recursion ($range, $rule_list [$standard ["chain_next"]], $rule_list, $amount);
  }
  return $amount;
}
php
  • Previous PHP uses redis to implement statistical caching mysql pressure method
  • Next Memory management in IOS