When the customers submit the orders on the website.. staffs can view the pending orders (pull data from mysql) on the admin backend but I want the pending orders to split into two team.
Example
We have received 21 pending orders.
There are 11 staffs.
Team 1: 5 staffs
Team 2: 6 staffs
Team 1 can view 11 orders and Team 2 can view 10
Sometime I might get 100 orders every hour – PHP should determine to split half of the pending orders into two teams (dynamically)…
Should the team_id set on the order table? Eg: tbl_orders.team_id = 2 when users submit the orders? .. but what if not enough staffs logged in team 1 or 2
You have 2 ways.
First (dynamic)
First of all you count all the pendings:
Then you show the first half to team 1:
Team 2 gets:
If you have more team you just need to divide for the total number of teams insted by 2.
Second option (fixed)
When pending are inserted you associate them with a team. But you have to add another field to your table.
Let’s say you have a field
team TINYINT(1) UNSIGNED.When the next pending is placed you check the last team inserted with this:
Let’s say you have a config where is stored your number of teams:
With the value that you have select with the query you do:
Now you have the team that can be associated with this pending. Of course you add it with
This second solution may suffer of race condition. (IE: 2 pending placed at nearly the same istant may be associated with the same team, but I believe this will not hurt at all )
Addedum
To count the team that recently have done something you have 2 ways:
teamswhere you store the last login data of the staff.At this point it’s easy to select the number of team with a recently activity.
Using the table team you just need to do a:
Having this number you can split all the pending you need with:
And use this offset within my first solution