Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
semour
/
semour_admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
86271534
authored
Nov 17, 2022
by
宁成龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
完善自动分配功能
parent
5c0f1a95
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
17 deletions
app/Admin/Controllers/HomeController.php
app/Admin/Service/AutoAssignCustomer.php → app/Admin/Service/AutoAssignCustomerService.php
app/Models/AutoAssignCustomer.php
app/Models/Cms/CmsUser.php
app/Admin/Controllers/HomeController.php
View file @
86271534
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
App\Admin\Controllers
;
namespace
App\Admin\Controllers
;
use
App\Admin\Metrics\Examples
;
use
App\Admin\Metrics\Examples
;
use
App\Admin\Service\AutoAssignCustomerService
;
use
App\Http\Controllers\Controller
;
use
App\Http\Controllers\Controller
;
use
Dcat\Admin\Http\Controllers\Dashboard
;
use
Dcat\Admin\Http\Controllers\Dashboard
;
use
Dcat\Admin\Layout\Column
;
use
Dcat\Admin\Layout\Column
;
...
@@ -13,6 +14,10 @@ class HomeController extends Controller
...
@@ -13,6 +14,10 @@ class HomeController extends Controller
{
{
public
function
index
(
Content
$content
)
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
return
$content
->
header
(
'Dashboard'
)
->
header
(
'Dashboard'
)
->
description
(
'Description...'
)
->
description
(
'Description...'
)
...
...
app/Admin/Service/AutoAssignCustomer.php
→
app/Admin/Service/AutoAssignCustomer
Service
.php
View file @
86271534
...
@@ -4,17 +4,18 @@ namespace App\Admin\Service;
...
@@ -4,17 +4,18 @@ namespace App\Admin\Service;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\DB
;
class
AutoAssignCustomer
class
AutoAssignCustomer
Service
{
{
public
static
function
getNowAssignInfo
()
public
static
function
getNowAssignInfo
()
{
{
try
{
try
{
DB
::
beginTransaction
();
DB
::
beginTransaction
();
$assignInfo
=
\App\Models\AutoAssignCustomer
::
getNowAssignInfo
();
$assignInfo
=
\App\Models\AutoAssignCustomer
::
getNowAssignInfo
();
if
(
empty
(
$
res
))
{
if
(
empty
(
$
assignInfo
))
{
$assignInfo
=
\App\Models\AutoAssignCustomer
::
getInfoByOrderSort
();
$assignInfo
=
\App\Models\AutoAssignCustomer
::
getInfoByOrderSort
();
\App\Models\AutoAssignCustomer
::
updateAll
([
'is_now'
=>
\App\Models\AutoAssignCustomer
::
IS_NOW_NO
]);
\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
();
DB
::
commit
();
return
$assignInfo
;
return
$assignInfo
;
...
@@ -30,33 +31,65 @@ class AutoAssignCustomer
...
@@ -30,33 +31,65 @@ class AutoAssignCustomer
if
(
empty
(
$assignInfo
))
{
if
(
empty
(
$assignInfo
))
{
return
false
;
return
false
;
}
}
$nowNum
=
$assignInfo
[
'now_num'
]
+
$num
;
if
(
$assignInfo
[
'is_now'
]
==
\App\Models\AutoAssignCustomer
::
IS_NOW_NO
)
{
if
(
$nowNum
>
$assignInfo
[
'max_num'
])
{
return
false
;
return
false
;
}
}
if
(
$nowNum
==
$assignInfo
[
'max_num'
])
{
$nowNum
=
$assignInfo
[
'now_num'
]
+
$num
;
if
(
$nowNum
>
$assignInfo
[
'max_num'
])
{
$nextAssignInfo
=
\App\Models\AutoAssignCustomer
::
getInfoByOrderSort
(
$assignInfo
[
'sort'
]);
$nextAssignInfo
=
\App\Models\AutoAssignCustomer
::
getInfoByOrderSort
(
$assignInfo
[
'sort'
]);
if
(
empty
(
$nextAssignInfo
))
{
if
(
empty
(
$nextAssignInfo
))
{
$nextAssignInfo
=
\App\Models\AutoAssignCustomer
::
getInfoByOrderSort
(
-
999999999
);
}
if
(
empty
(
$nextAssignInfo
))
{
return
false
;
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'
],
\App\Models\AutoAssignCustomer
::
updateById
(
$nextAssignInfo
[
'id'
],
[
'is_now'
=>
\App\Models\AutoAssignCustomer
::
IS_NOW_YES
]);
[
'is_now'
=>
\App\Models\AutoAssignCustomer
::
IS_NOW_YES
]);
}
}
return
\App\Models\AutoAssignCustomer
::
updateById
(
$assignInfo
[
'id'
],
[
'now_num'
=>
$nowNum
]);
return
\App\Models\AutoAssignCustomer
::
updateById
(
$assignInfo
[
'id'
],
[
'now_num'
=>
$nowNum
]);
}
}
public
static
function
updateDepartmentNum
(){
public
static
function
updateDepartmentNum
()
{
//获取自动分配部门
//获取自动分配部门
$assign
Info
=
\App\Models\AutoAssignCustomer
::
getNowAssignInfo
();
$assign
List
=
\App\Models\AutoAssignCustomer
::
getList
();
if
(
empty
(
$assign
Info
))
{
if
(
empty
(
$assign
List
))
{
return
false
;
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
;
}
}
}
app/Models/AutoAssignCustomer.php
View file @
86271534
...
@@ -32,31 +32,38 @@ class AutoAssignCustomer extends Model
...
@@ -32,31 +32,38 @@ class AutoAssignCustomer extends Model
return
self
::
insertGetId
(
$data
);
return
self
::
insertGetId
(
$data
);
}
}
//获取列表
public
static
function
getList
()
{
$res
=
self
::
orderBy
(
'sort'
,
'asc'
)
->
get
();
return
(
$res
)
?
$res
->
toArray
()
:
[];
}
public
static
function
getNowAssignInfo
()
public
static
function
getNowAssignInfo
()
{
{
$res
=
self
::
where
(
'is_now'
,
self
::
IS_NOW_YES
)
->
ge
t
();
$res
=
self
::
where
(
'is_now'
,
self
::
IS_NOW_YES
)
->
firs
t
();
return
(
$res
)
?
$res
->
toArray
()
:
[];
return
(
$res
)
?
$res
->
toArray
()
:
[];
}
}
public
static
function
getInfoByOrderSort
(
$sort
=
0
)
public
static
function
getInfoByOrderSort
(
$sort
=
0
)
{
{
$res
=
self
::
where
(
'sort'
,
">
="
,
$sort
)
->
orderBy
(
"sort"
,
"ASC"
)
->
ge
t
();
$res
=
self
::
where
(
'sort'
,
">
"
,
$sort
)
->
orderBy
(
"sort"
,
"ASC"
)
->
firs
t
();
return
(
$res
)
?
$res
->
toArray
()
:
[];
return
(
$res
)
?
$res
->
toArray
()
:
[];
}
}
public
static
function
deleteById
(
$addressId
)
public
static
function
deleteById
(
$addressId
)
{
{
return
self
::
where
(
'
address_
id'
,
$addressId
)
->
delete
();
return
self
::
where
(
'id'
,
$addressId
)
->
delete
();
}
}
public
static
function
updateById
(
$id
,
$update
)
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
)
public
static
function
updateByUserId
(
$userId
,
$update
)
...
@@ -69,6 +76,7 @@ class AutoAssignCustomer extends Model
...
@@ -69,6 +76,7 @@ class AutoAssignCustomer extends Model
$res
=
self
::
where
(
'id'
,
$id
)
->
first
();
$res
=
self
::
where
(
'id'
,
$id
)
->
first
();
return
(
$res
)
?
$res
->
toArray
()
:
[];
return
(
$res
)
?
$res
->
toArray
()
:
[];
}
}
public
static
function
getInfoByDepartmentId
(
$id
)
public
static
function
getInfoByDepartmentId
(
$id
)
{
{
$res
=
self
::
where
(
'department_id'
,
$id
)
->
first
();
$res
=
self
::
where
(
'department_id'
,
$id
)
->
first
();
...
...
app/Models/Cms/CmsUser.php
View file @
86271534
...
@@ -15,4 +15,11 @@ class CmsUser extends Model
...
@@ -15,4 +15,11 @@ class CmsUser extends Model
$res
=
self
::
where
(
'userId'
,
$userId
)
->
first
();
$res
=
self
::
where
(
'userId'
,
$userId
)
->
first
();
return
(
$res
)
?
$res
->
toArray
()
:
[];
return
(
$res
)
?
$res
->
toArray
()
:
[];
}
}
//根据部门id获取列表
public
static
function
getUserListByDepartmentId
(
$departmentIds
)
{
$res
=
self
::
whereIn
(
'department_id'
,
$departmentIds
)
->
get
();
return
(
$res
)
?
$res
->
toArray
()
:
[];
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment