Hello to all!

Has anyone encountered the creation of a tariff plan system in their product? I am interested to know how to make the system in such a way that it could rate any indicators)

    1 answer 1

    Here, depending on what you ultimately need:

    Example

    It is necessary to charge the client depending on the amount of resource consumed. There are three tariff plans, which depend on the amount of resources used. We must calculate the "initial" tariff (for example):

    if(res>0 and res<=10) // set tarif 1 elseif(res>10 and res<100) // set tarif 2 elseif(res>=100) // set tarif 3 

    I had one final formula that calculated the final sum that the subscriber had to pay, provided that we still had different services, penalties and bonuses (which were calculated by other formulas, methods ...). Like that:

     endSum = tarif + services + penalty - bonus 

    If you really bother, then in the admin panel you can make a formula editor for tariffs.

    UPD

    With the formula generator, everything is neglected :)

    1) There should be a table of indicators and formulas (we will reduce billing_parameters to BP)

    | id | name | type | note |

    where type is static, interval or dynamic and lead to separate tables

    static

     |id_BP|name|param| a=10 

    interval

     |id_BP|name|min|max|param| a=10 если попало в предел min-max записей на один id_PB может быть несколько 

    dynamic

     |id_BP|type|formula| записей на один id_PB будет несколько 

    type - element or formula

    formula - what the user entered in string form

    A small remark before the second paragraph

    On the field on the input field, the indicator selection menu pops up:

     Name - note Bonus - Бонусы за попугаев 

    when you select the formula, Name gets to us and to the list in order to add all the entered parameters to the database.

    2) I'll go straight to the formulas themselves.

    In the end, we will have several methods - to calculate the intervals and the formula itself.

    We make the dictionary key: value, in order to enter into it the counted parameters. In the dynamic table we have all the simple elements of the formula, we count them and put them in the name: param dictionary, then we take the formula and replay the names of indicators in it for the calculated indicators, we have a ready-made mathematical formula, profit

    • Hello! That's it, the tariff editor is interested) - nolka
    • updated the answer - sonniy
    • Thank you for info, I will study:] - nolka