Commit 86271534 by 宁成龙

完善自动分配功能

parent 5c0f1a95
......@@ -3,6 +3,7 @@
namespace App\Admin\Controllers;
use App\Admin\Metrics\Examples;
use App\Admin\Service\AutoAssignCustomerService;
use App\Http\Controllers\Controller;
use Dcat\Admin\Http\Controllers\Dashboard;
use Dcat\Admin\Layout\Column;
......@@ -13,6 +14,10 @@ class HomeController extends Controller
{
public function index(Content $content)
{
$assign = AutoAssignCustomerService::getNowAssignInfo();
var_dump($assign);
var_dump(AutoAssignCustomerService::incAssignNumByDepartmentId($assign['department_id'],1));
var_dump(123);die;
return $content
->header('Dashboard')
->description('Description...')
......
......@@ -4,17 +4,18 @@ namespace App\Admin\Service;
use Illuminate\Support\Facades\DB;
class AutoAssignCustomer
class AutoAssignCustomerService
{
public static function getNowAssignInfo()
{
try {
DB::beginTransaction();
$assignInfo = \App\Models\AutoAssignCustomer::getNowAssignInfo();
if (empty($res)) {
if (empty($assignInfo)) {
$assignInfo = \App\Models\AutoAssignCustomer::getInfoByOrderSort();
\App\Models\AutoAssignCustomer::updateAll(['is_now' => \App\Models\AutoAssignCustomer::IS_NOW_NO]);
\App\Models\AutoAssignCustomer::updateById($assignInfo['id'], ['is_now' => \App\Models\AutoAssignCustomer::IS_NOW_YES]);
\App\Models\AutoAssignCustomer::updateById($assignInfo['id'],
['is_now' => \App\Models\AutoAssignCustomer::IS_NOW_YES]);
}
DB::commit();
return $assignInfo;
......@@ -30,33 +31,65 @@ class AutoAssignCustomer
if (empty($assignInfo)) {
return false;
}
$nowNum = $assignInfo['now_num'] + $num;
if ($nowNum > $assignInfo['max_num']) {
if ($assignInfo['is_now'] == \App\Models\AutoAssignCustomer::IS_NOW_NO) {
return false;
}
if ($nowNum == $assignInfo['max_num']) {
$nowNum = $assignInfo['now_num'] + $num;
if ($nowNum > $assignInfo['max_num']) {
$nextAssignInfo = \App\Models\AutoAssignCustomer::getInfoByOrderSort($assignInfo['sort']);
if (empty($nextAssignInfo)) {
$nextAssignInfo = \App\Models\AutoAssignCustomer::getInfoByOrderSort(-999999999);
}
if (empty($nextAssignInfo)) {
return false;
}
\App\Models\AutoAssignCustomer::updateAll(['is_now' => \App\Models\AutoAssignCustomer::IS_NOW_NO]);
\App\Models\AutoAssignCustomer::updateAll([
'is_now' => \App\Models\AutoAssignCustomer::IS_NOW_NO,
"now_num" => 0
]);
\App\Models\AutoAssignCustomer::updateById($nextAssignInfo['id'],
['is_now' => \App\Models\AutoAssignCustomer::IS_NOW_YES]);
}
return \App\Models\AutoAssignCustomer::updateById($assignInfo['id'], ['now_num' => $nowNum]);
}
public static function updateDepartmentNum(){
public static function updateDepartmentNum()
{
//获取自动分配部门
$assignInfo = \App\Models\AutoAssignCustomer::getNowAssignInfo();
if (empty($assignInfo)) {
$assignList = \App\Models\AutoAssignCustomer::getList();
if (empty($assignList)) {
return false;
}
//获取部门人员
foreach ($assignList as $assign) {
$departmentId = $assign['department_id'];
$departmentIds = [];
$departmentIds = self::getChildDepartmentList($departmentId, $departmentIds);
$departmentIds[] = $departmentId;
$departmentIds = array_unique($departmentIds);
//获取该部门下的用户
$userList = \App\Models\Cms\CmsUser::getUserListByDepartmentId($departmentIds);
$updateData = [
'max_num' => count($userList),
];
var_dump($updateData);
\App\Models\AutoAssignCustomer::updateById($assign['id'], $updateData);
}
}
public static function getChildDepartmentList($departmentId, &$departmentIds)
{
// 获取下级部门
$sub_department = \App\Models\Cms\CmsUserDepartmentModel::getDepartmentByParentId($departmentId);
if ($sub_department) {
foreach ($sub_department as $key => $v) {
self::getChildDepartmentList($key, $departmentIds);
}
}
$departmentIds[] = $departmentId;
return $departmentIds;
}
}
......@@ -32,31 +32,38 @@ class AutoAssignCustomer extends Model
return self::insertGetId($data);
}
//获取列表
public static function getList()
{
$res = self::orderBy('sort', 'asc')->get();
return ($res) ? $res->toArray() : [];
}
public static function getNowAssignInfo()
{
$res = self::where('is_now', self::IS_NOW_YES)->get();
$res = self::where('is_now', self::IS_NOW_YES)->first();
return ($res) ? $res->toArray() : [];
}
public static function getInfoByOrderSort($sort = 0)
{
$res = self::where('sort', ">=", $sort)->orderBy("sort", "ASC")->get();
$res = self::where('sort', ">", $sort)->orderBy("sort", "ASC")->first();
return ($res) ? $res->toArray() : [];
}
public static function deleteById($addressId)
{
return self::where('address_id', $addressId)->delete();
return self::where('id', $addressId)->delete();
}
public static function updateById($id, $update)
{
return self::where("address_id", $id)->update($update);
return self::where("id", $id)->update($update);
}
public static function updateAll( $update)
public static function updateAll($update)
{
return self::update($update);
return self::where([])->update($update);
}
public static function updateByUserId($userId, $update)
......@@ -69,6 +76,7 @@ class AutoAssignCustomer extends Model
$res = self::where('id', $id)->first();
return ($res) ? $res->toArray() : [];
}
public static function getInfoByDepartmentId($id)
{
$res = self::where('department_id', $id)->first();
......
......@@ -15,4 +15,11 @@ class CmsUser extends Model
$res = self::where('userId', $userId)->first();
return ($res) ? $res->toArray() : [];
}
//根据部门id获取列表
public static function getUserListByDepartmentId($departmentIds)
{
$res = self::whereIn('department_id', $departmentIds)->get();
return ($res) ? $res->toArray() : [];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment