Database schema - custom fields?

I sell leads and buy my clients like this: (Only one type of payment from the following can be charged per client)
Pay Per Lead:
$ __ for the first __ potential customers per month
$ __ for the next __ potential customers per month
$ __ for the next __ potential customers per month
and so on ...

Appointment fee:
$ __ for the first __ potential customers per month
$ __ for the next __ potential customers per month
$ __ for the next __ potential customers per month
and so on ...

Sale Percentage Fee:
__% of the sale price (per sale)

My question is:
What are the best possible solutions for database design in such cases?

What I tried:

+---------+ 
| clients |
+---------+
| id      |
| name    |
+---------+

+---------------+
|     deals     |
+---------------+
| client_id     |
| max_quantity  | 
| cost          |
| unit_type     |
+---------------+

Thus, records for client id1 may look like this:

+-----------+--------------+---------------+-------------+
| client_id | max_quantity | cost_per_unit |  unit_type  |
+-----------+--------------+---------------+-------------+
|         1 |           10 |            10 | lead        |
|         1 |           30 |             5 | lead        |
|         1 |          100 |             2 | lead        |
|         1 |           10 |            35 | appointment |
|         1 |           30 |            20 | appointment |
|         1 |          100 |            10 | appointment |
|         1 |         1000 |             5 | appointment |
|         1 |            0 |            50 | sale        |
+-----------+--------------+---------------+-------------+

Now, the above table means that:
$10will be charged for leadbefore 10leads
$5will be charged for leadbefore 30leads
$2will be charged for leadbefore 100leads

$35will be charged for appointmentbefore 10leads
$20will be charged for appointmentbefore 30leads
$10will be charged for appointmentbefore 100leads $5will be charged for appointmentbefore 1000leads

$50 will charge for sale

x ( , , )

, - . , ! .

P.S. , unit_type , :)

Update

, ?

+4
3

- . unit_type max_quantity sale.

, deals . , ** , : - commission_lead, commission_appointment commission_sale.

** [ ]

, . , , , , .

, :

+---------+ 
| client  |
+---------+
| id      |
| name    |
+---------+

+-----------------+
| commission_lead |
+-----------------+
| client_id       |
| min_quantity    |
| max_quantity    | 
| cost_per_unit   |
+-----------------+

+------------------------+
| commission_appointment |
+------------------------+
| client_id              |
| min_quantity           |
| max_quantity           |
| cost_per_unit          |
+------------------------+

+-----------------+
| commission_sale |
+-----------------+
| client_id       |
| cost_per_unit   |
+-----------------+

client_id = 1:

commission_lead
+-----------+--------------+--------------+---------------+
| client_id | min_quantity | max_quantity | cost_per_unit |
+-----------+--------------+--------------+---------------+
|         1 |            0 |           10 |            10 |
|         1 |           11 |           30 |             5 |
|         1 |           31 |          100 |             2 |
+-----------+--------------+--------------+---------------+

commission_appointment
+-----------+--------------+--------------+---------------+
| client_id | min_quantity | max_quantity | cost_per_unit |
+-----------+--------------+--------------+---------------+
|         1 |            0 |           10 |            35 |
|         1 |           11 |           30 |            20 |
|         1 |           31 |          100 |            10 |
|         1 |          101 |         1000 |             5 |
+-----------+--------------+--------------+---------------+

commission_sale
+-----------+---------------+
| client_id | cost_per_unit |
+-----------+---------------+
|         1 |            50 |
+-----------+---------------+
+4

, (/), select , ,

+-----------+--------------+---------------+---------------+--------------+------------+
| client_id | max_quantity | min_quantity  | cost_per_unit | default_cost | unit_type  |
+-----------+--------------+---------------+---------------+--------------+------------+
|         1 |           10 |            0  |           10  |            0 |        lead|
|         1 |           40 |           10  |            5  |          100 |        lead|
|         1 |          140 |           40  |            2  |          250 |        lead|
|         1 |           10 |            0  |           35  |            0 | appointment|
|         1 |           40 |           10  |           20  |          350 | appointment|
|         1 |          140 |           40  |           10  |          950 | appointment|
|         1 |         1140 |          140  |            5  |         1950 | appointment|
|         1 |            0 |            0  |           50  |            0 |        sale|
+-----------+--------------+---------------+---------------+--------------+------------+

select

select 
   default_cost + ($quantity - min_quantity) * cost_per_unit
from 
   table
where 
   unit_type = $unit_type 
   and (max_quantity >= $quantity or max_quantity = 0)
   and $quantity >= min_quantity 
+2

- , . / , rule_id, , unit_type, varchar, , , , .

, -, . , 5 , . rule_id -, .

, / , , ...

+1

Source: https://habr.com/ru/post/1536853/


All Articles