Skip to content

Commit

Permalink
Fix #763
Browse files Browse the repository at this point in the history
  • Loading branch information
sampoyigi committed May 31, 2021
1 parent 0f01d89 commit 6744e2b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
4 changes: 1 addition & 3 deletions app/admin/controllers/StaffGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ public function __construct()
AdminMenu::setContext('staffs', 'users');
}

public function index()
public function formAfterSave()
{
Staff_groups_model::syncAutoAssignStatus();

$this->asExtension('ListController')->index();
}
}
2 changes: 2 additions & 0 deletions app/admin/models/Assignable_logs_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public function scopeApplyRoundRobinScope($query)
->select('assignee_id')
->selectRaw('MAX(created_at) as assign_value')
->whereIn('status_id', setting('processing_order_status', []))
->whereNotNull('assignee_id')
->groupBy('assignee_id')
->orderBy('assign_value', 'asc');
}
Expand All @@ -135,6 +136,7 @@ public function scopeApplyLoadBalancedScope($query, $limit)
->select('assignee_id')
->selectRaw('COUNT(assignee_id)/'.DB::getPdo()->quote($limit).' as assign_value')
->whereIn('status_id', setting('processing_order_status', []))
->whereNotNull('assignee_id')
->groupBy('assignee_id')
->orderBy('assign_value', 'desc')
->havingRaw('assign_value < 1');
Expand Down
10 changes: 3 additions & 7 deletions app/admin/models/Staff_groups_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Admin\Models;

use Carbon\Carbon;
use Model;

/**
Expand Down Expand Up @@ -101,19 +100,16 @@ public function findAvailableAssignee()
{
$query = $this->assignable_logs()->newQuery();

$useLoadBalance = ($this->auto_assign_mode == self::AUTO_ASSIGN_LOAD_BALANCED);
$useLoadBalance = $this->auto_assign_mode == self::AUTO_ASSIGN_LOAD_BALANCED;

$useLoadBalance
? $query->applyLoadBalancedScope($this->auto_assign_limit)
: $query->applyRoundRobinScope();

$logs = $query->pluck('assign_value', 'assignee_id');

$assignees = $this->listAssignees()->map(function (Staffs_model $model) use ($useLoadBalance, $logs) {
$assignValue = $useLoadBalance ?
0 : Carbon::now()->addYear()->toDateTimeString();

$model->assign_value = $logs[$model->getKey()] ?? $assignValue;
$assignees = $this->listAssignees()->map(function (Staffs_model $model) use ($logs) {
$model->assign_value = $logs[$model->getKey()] ?? 0;

return $model;
});
Expand Down

0 comments on commit 6744e2b

Please sign in to comment.