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
bd802a79
authored
Nov 15, 2022
by
宁成龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
新增自动分配
parent
a589e910
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
128 additions
and
0 deletions
app/Admin/Service/AutoAssignCustomer.php
app/Models/AutoAssignCustomer.php
app/Admin/Service/AutoAssignCustomer.php
0 → 100644
View file @
bd802a79
<?php
namespace
App\Admin\Service
;
use
Illuminate\Support\Facades\DB
;
class
AutoAssignCustomer
{
public
static
function
getNowAssignInfo
()
{
try
{
DB
::
beginTransaction
();
$assignInfo
=
\App\Models\AutoAssignCustomer
::
getNowAssignInfo
();
if
(
empty
(
$res
))
{
$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
]);
}
DB
::
commit
();
return
$assignInfo
;
}
catch
(
\Throwable
$throwable
)
{
DB
::
rollBack
();
throw
$throwable
;
}
}
public
static
function
incAssignNumByDepartmentId
(
$departmentId
,
$num
=
1
)
{
$assignInfo
=
\App\Models\AutoAssignCustomer
::
getInfoByDepartmentId
(
$departmentId
);
if
(
empty
(
$assignInfo
))
{
return
false
;
}
$nowNum
=
$assignInfo
[
'now_num'
]
+
$num
;
if
(
$nowNum
>
$assignInfo
[
'max_num'
])
{
return
false
;
}
if
(
$nowNum
==
$assignInfo
[
'max_num'
])
{
$nextAssignInfo
=
\App\Models\AutoAssignCustomer
::
getInfoByOrderSort
(
$assignInfo
[
'sort'
]);
if
(
empty
(
$nextAssignInfo
))
{
return
false
;
}
\App\Models\AutoAssignCustomer
::
updateAll
([
'is_now'
=>
\App\Models\AutoAssignCustomer
::
IS_NOW_NO
]);
\App\Models\AutoAssignCustomer
::
updateById
(
$nextAssignInfo
[
'id'
],
[
'is_now'
=>
\App\Models\AutoAssignCustomer
::
IS_NOW_YES
]);
}
return
\App\Models\AutoAssignCustomer
::
updateById
(
$assignInfo
[
'id'
],
[
'now_num'
=>
$nowNum
]);
}
}
app/Models/AutoAssignCustomer.php
0 → 100644
View file @
bd802a79
<?php
namespace
App\Models
;
use
Dcat\Admin\Traits\HasDateTimeFormatter
;
use
Illuminate\Database\Eloquent\Model
;
/**
* @property $id 主键id
* @property $department_id 部门id
* @property $department_name 部门名
* @property $assign_sale_name 分配业务员名
* @property $assign_sale_id 分配业务员id
* @property $sort 排序
* @property $now_num 当前数量
* @property $max_num 分配总数
* @property $is_now 是否为当前分配部门
*/
class
AutoAssignCustomer
extends
Model
{
use
HasDateTimeFormatter
;
public
$timestamps
=
false
;
protected
$table
=
'auto_assign_customer'
;
const
IS_NOW_YES
=
1
;
const
IS_NOW_NO
=
0
;
public
static
function
insertData
(
$data
)
{
return
self
::
insertGetId
(
$data
);
}
public
static
function
getNowAssignInfo
()
{
$res
=
self
::
where
(
'is_now'
,
self
::
IS_NOW_YES
)
->
get
();
return
(
$res
)
?
$res
->
toArray
()
:
[];
}
public
static
function
getInfoByOrderSort
(
$sort
=
0
)
{
$res
=
self
::
where
(
'sort'
,
">="
,
$sort
)
->
orderBy
(
"sort"
,
"ASC"
)
->
get
();
return
(
$res
)
?
$res
->
toArray
()
:
[];
}
public
static
function
deleteById
(
$addressId
)
{
return
self
::
where
(
'address_id'
,
$addressId
)
->
delete
();
}
public
static
function
updateById
(
$id
,
$update
)
{
return
self
::
where
(
"address_id"
,
$id
)
->
update
(
$update
);
}
public
static
function
updateAll
(
$update
)
{
return
self
::
update
(
$update
);
}
public
static
function
updateByUserId
(
$userId
,
$update
)
{
return
self
::
where
(
"user_id"
,
$userId
)
->
update
(
$update
);
}
public
static
function
getInfoById
(
$id
)
{
$res
=
self
::
where
(
'id'
,
$id
)
->
first
();
return
(
$res
)
?
$res
->
toArray
()
:
[];
}
public
static
function
getInfoByDepartmentId
(
$id
)
{
$res
=
self
::
where
(
'department_id'
,
$id
)
->
first
();
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