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
6fcd7c9b
authored
Nov 10, 2022
by
宁成龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
完善分配客户
parent
753ab4d3
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
107 additions
and
14 deletions
app/Admin/Actions/User/UserAssignAction.php
app/Admin/Forms/User/AssignUserHandle.php
app/Admin/Service/UserService.php
app/Models/Cms/CmsUser.php
app/Models/User.php
app/Admin/Actions/User/UserAssignAction.php
View file @
6fcd7c9b
...
...
@@ -3,10 +3,13 @@
namespace
App\Admin\Actions\User
;
use
App\Admin\Forms\User\AssignUserHandle
;
use
App\Models\Order
as
OrderModel
;
use
App\Models\User
;
use
Dcat\Admin\Grid
;
use
Dcat\Admin\Grid\BatchAction
;
use
Dcat\Admin\Grid\Tools\AbstractTool
;
use
Dcat\Admin\Widgets\Modal
;
use
Illuminate\Http\Request
;
use
Dcat\Admin\Grid\RowAction
;
...
...
@@ -14,6 +17,7 @@ use Dcat\Admin\Grid\RowAction;
class
UserAssignAction
extends
BatchAction
{
protected
$action
;
protected
$htmlClasses
=
[
'btn btn-primary btn-sm btn-mini'
];
// 注意action的构造方法参数一定要给默认值
public
function
__construct
(
$title
=
null
,
$action
=
1
)
...
...
@@ -25,15 +29,34 @@ class UserAssignAction extends BatchAction
// 确认弹窗信息
public
function
confirm
()
{
return
'您确定要
发布
已选中的文章吗?'
;
return
'您确定要已选中的文章吗?'
;
}
public
function
render
()
{
$form
=
AssignUserHandle
::
make
();
$buttonName
=
trans
(
'user.labels.handle'
);
return
Modal
::
make
()
->
lg
()
->
title
(
$this
->
title
)
->
body
(
$form
->
payload
([]))
->
onLoad
(
$this
->
getModalScript
())
->
button
(
'<button class="btn btn-primary">
<i class="feather icon-check-circle"></i><span class="d-none d-sm-inline" style="margin-left: 5px">'
.
$buttonName
.
'</span>
</button>'
);
}
protected
function
getModalScript
()
{
// 弹窗显示后往隐藏的id表单中写入批量选中的行ID
$warning
=
trans
(
'global.labels.operate_must_select_data'
);
return
<<<JS
var key = {$this->getSelectedKeysScript()}
if (!key.length){
Dcat.swal.error('$warning');
Dcat.reload();
}
$('#id').val(key);
JS;
}
public
function
html
()
{
$class
=
$this
->
getElementClass
();
$this
->
setHtmlAttribute
([
"class"
=>
"
{
$class
}
btn btn-primary btn-sm btn-mini"
,
]);
return
parent
::
html
();
// TODO: Change the autogenerated stub
}
...
...
@@ -46,11 +69,6 @@ class UserAssignAction extends BatchAction
// 获取请求参数
$action
=
$request
->
get
(
'action'
);
foreach
(
Post
::
find
(
$keys
)
as
$post
)
{
$post
->
released
=
$action
;
$post
->
save
();
}
$message
=
$action
?
'文章发布成功'
:
'文章下线成功'
;
return
$this
->
response
()
->
success
(
$message
)
->
refresh
();
...
...
app/Admin/Forms/User/AssignUserHandle.php
0 → 100644
View file @
6fcd7c9b
<?php
namespace
App\Admin\Forms\User
;
use
App\Models\Cms\CmsUser
;
use
App\Models\Inquiry
;
use
App\Models\User
;
use
Dcat\Admin\Contracts\LazyRenderable
;
use
Dcat\Admin\Traits\LazyWidget
;
use
Dcat\Admin\Widgets\Form
;
class
AssignUserHandle
extends
Form
implements
LazyRenderable
{
use
LazyWidget
;
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public
function
handle
(
array
$input
)
{
try
{
$ids
=
explode
(
","
,
$input
[
'id'
]);
// $userList = User::getListByIdArr($ids);
$cmsUser
=
CmsUser
::
getInfoByUserId
(
$input
[
'sale_id'
]);
if
(
!
$cmsUser
)
{
throw
new
\Exception
(
'销售不存在'
);
}
User
::
updateByIdArr
(
$ids
,
[
'sale_id'
=>
$input
[
'sale_id'
],
"sale_name"
=>
$cmsUser
[
'name'
]]);
return
$this
->
response
()
->
success
(
trans
(
'admin.update_succeeded'
))
->
refresh
();
}
catch
(
\Throwable
$throwable
)
{
// var_dump((string)$throwable);
return
$this
->
response
()
->
error
(
trans
(
'admin.update_failed'
));
}
}
/**
* Build a form here.
*/
public
function
form
()
{
$this
->
disableResetButton
();
$this
->
hidden
(
'id'
)
->
attribute
(
'id'
,
'id'
);
$this
->
select
(
'sale_id'
)
->
options
(
CmsUser
::
pluck
(
'name'
,
'userId'
)
->
toArray
())
->
default
(
0
)
->
required
();
}
/**
* The data of the form.
*
* @return array
*/
public
function
default
()
{
return
[
];
}
}
app/Admin/Service/UserService.php
View file @
6fcd7c9b
...
...
@@ -53,8 +53,8 @@ class UserService
public
static
function
userListTool
(
Grid
$grid
)
{
$grid
->
tools
([
new
UserTransferAction
(
"转让销售"
),
new
UserAssignAction
(
"分配销售"
),
new
UserTransferAction
(
"转移销售"
),
]);
}
...
...
app/Models/Cms/CmsUser.php
View file @
6fcd7c9b
...
...
@@ -9,4 +9,10 @@ class CmsUser extends Model
protected
$connection
=
'cms'
;
protected
$table
=
'user_info'
;
public
$timestamps
=
false
;
public
static
function
getInfoByUserId
(
$userId
)
{
$res
=
self
::
where
(
'userId'
,
$userId
)
->
first
();
return
(
$res
)
?
$res
->
toArray
()
:
[];
}
}
app/Models/User.php
View file @
6fcd7c9b
...
...
@@ -48,21 +48,26 @@ class User extends Model
public
static
function
getInfoByUserId
(
$userId
)
{
$res
=
self
::
where
(
'
user_
id'
,
$userId
)
->
first
();
$res
=
self
::
where
(
'id'
,
$userId
)
->
first
();
return
(
$res
)
?
$res
->
toArray
()
:
[];
}
// 批量获取用户信息
public
static
function
getInfoByUserIds
(
$userId
)
{
return
self
::
whereIn
(
'
user_id'
,
$userId
)
->
get
()
->
keyBy
(
'user_
id'
)
->
toArray
();
return
self
::
whereIn
(
'
id'
,
$userId
)
->
get
()
->
keyBy
(
'
id'
)
->
toArray
();
}
public
static
function
getListByIdArr
(
$userIdArr
)
{
$res
=
self
::
wherein
(
'
user_
id'
,
$userIdArr
)
->
get
();
$res
=
self
::
wherein
(
'id'
,
$userIdArr
)
->
get
();
return
(
$res
)
?
$res
->
toArray
()
:
[];
}
public
static
function
updateByIdArr
(
$idArr
,
$update
)
{
return
self
::
whereIn
(
"id"
,
$idArr
)
->
update
(
$update
);
}
}
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