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
Hide 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 @@
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...'
)
...
...
app/Admin/Service/AutoAssignCustomer.php
→
app/Admin/Service/AutoAssignCustomer
Service
.php
View file @
86271534
...
...
@@ -4,17 +4,18 @@ namespace App\Admin\Service;
use
Illuminate\Support\Facades\DB
;
class
AutoAssignCustomer
class
AutoAssignCustomer
Service
{
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
()
{
//获取自动分配部门
$assign
Info
=
\App\Models\AutoAssignCustomer
::
getNowAssignInfo
();
if
(
empty
(
$assign
Info
))
{
$assign
List
=
\App\Models\AutoAssignCustomer
::
getList
();
if
(
empty
(
$assign
List
))
{
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
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
)
->
ge
t
();
$res
=
self
::
where
(
'is_now'
,
self
::
IS_NOW_YES
)
->
firs
t
();
return
(
$res
)
?
$res
->
toArray
()
:
[];
}
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
()
:
[];
}
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
();
...
...
app/Models/Cms/CmsUser.php
View file @
86271534
...
...
@@ -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
()
:
[];
}
}
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