将待处理订单分成两队

发布于 2024-11-08 19:02:00 字数 443 浏览 0 评论 0原文

当客户在网站上提交订单时..员工可以在管理后端查看待处理订单(从 m​​ysql 中提取数据),但我希望将待处理订单分成两个团队。

示例

我们收到了 21 个待处理订单。

现有工作人员11人。

团队 1:5 名员工

团队 2:6 名员工

团队 1 可以查看 11 个订单,团队 2 可以查看 10 个订单

有时我每小时可能会收到 100 个订单 - PHP 应该决定将一半的挂单分成两个团队(动态)...

是否应该在订单表上设置 team_id ?例如:tbl_orders.team_id = 2 用户何时提交订单? ..但是如果没有足够的员工登录团队 1 或 2 该怎么办

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷心人i 2024-11-15 19:02:00

你有2种方法。

首先(动态)

首先计算所有未决的:

SELECT COUNT(*) FROM pending;

然后向团队 1 展示上半场:

$half = round($count/2);
SELECT * FROM pending ORDER BY id DESC LIMIT $half;

团队 2 获得:

SELECT * FROM pending ORDER BY id DESC LIMIT $half,$half;

如果您有更多团队,则只需将插入的团队总数除以 2。

第二个选项(固定)

当插入待处理时,您将它们与一个团队相关联。但您必须向表中添加另一个字段。

假设您有一个字段team TINYINT(1) UNSIGNED

当放置下一个待处理时,您检查插入的最后一个团队:

 SELECT team FROM pending ORDER BY id DESC LIMIT 1;

假设您有一个配置,其中存储了您的团队数量:

 $totalTeamsAvailable = 2;

使用您通过查询选择的值:

 $nextTeam = (++$teamFromSql % $TotalTeamsAvailable) + 1;

现在您拥有可以与此相关的悬而未决。当然,您将其添加为

 INSERT INTO pending (data,team) VALUES (,$nextTeam);

第二个解决方案可能会受到竞争条件的影响。 (IE:2个待处理的放置在几乎相同的位置可能与同一个团队相关联,但我相信这根本不会造成伤害)

Addum

要计算最近做过某事的团队,您有两种方法:

  • 您需要一个表<代码>teams 您存储员工上次登录数据的位置。
  • 使用数据存储每个团队已完成的每个操作(例如团队 1 批准并发送待处理订单 #2)(也许您已经有了此表)

此时,可以轻松选择最近进行活动的团队数量。
使用表团队,您只需要执行以下操作:

$teamWithRecentlyActivity = SELECT COUNT(*) FROM teams WHERE lastLogin > (time() - (60*60*24));   
//> This select all teams within 1 day from last login

有了这个数字,您就可以将您需要的所有待处理拆分为:

$pendingPerTeam = round($totalPendings / $teamWithRecentlyActivity);

并在我的第一个解决方案中使用此偏移量

You have 2 ways.

First (dynamic)

First of all you count all the pendings:

SELECT COUNT(*) FROM pending;

Then you show the first half to team 1:

$half = round($count/2);
SELECT * FROM pending ORDER BY id DESC LIMIT $half;

Team 2 gets:

SELECT * FROM pending ORDER BY id DESC LIMIT $half,$half;

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:

 SELECT team FROM pending ORDER BY id DESC LIMIT 1;

Let's say you have a config where is stored your number of teams:

 $totalTeamsAvailable = 2;

With the value that you have select with the query you do:

 $nextTeam = (++$teamFromSql % $TotalTeamsAvailable) + 1;

Now you have the team that can be associated with this pending. Of course you add it with

 INSERT INTO pending (data,team) VALUES (,$nextTeam);

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:

  • You need a table teams where you store the last login data of the staff.
  • Store each actions that each teams have done (for example team 1 approved and sent order pending #2) with a data (maybe you have already this table)

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:

$teamWithRecentlyActivity = SELECT COUNT(*) FROM teams WHERE lastLogin > (time() - (60*60*24));   
//> This select all teams within 1 day from last login

Having this number you can split all the pending you need with:

$pendingPerTeam = round($totalPendings / $teamWithRecentlyActivity);

And use this offset within my first solution

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文