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
753ab4d3
authored
Nov 10, 2022
by
宁成龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
完善禁用/启用操作
parent
5e446ea2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
23 deletions
app/Admin/Actions/User/UserStatusAction.php
app/Admin/Service/UserService.php
app/Models/User.php
app/Admin/Actions/User/UserStatusAction.php
View file @
753ab4d3
...
...
@@ -3,6 +3,7 @@
namespace
App\Admin\Actions\User
;
use
App\Admin\Service\UserService
;
use
App\Models\Order
as
OrderModel
;
use
App\Models\User
;
use
Dcat\Admin\Grid\BatchAction
;
...
...
@@ -29,7 +30,7 @@ class UserStatusAction extends RowAction
public
function
title
()
{
$buttonName
=
"启用"
;
if
(
$this
->
row
->
status
==
User
::
STATUS_NORMAL
)
{
if
(
$this
->
row
->
status
==
User
::
STATUS_NORMAL
)
{
$buttonName
=
"禁用"
;
}
return
$buttonName
;
...
...
@@ -39,14 +40,14 @@ class UserStatusAction extends RowAction
{
$class
=
$this
->
getElementClass
();
$color
=
"btn btn-primary btn-sm btn-mini"
;
if
(
$this
->
row
->
status
==
User
::
STATUS_NORMAL
)
{
if
(
$this
->
row
->
status
==
User
::
STATUS_NORMAL
)
{
$color
=
"btn btn-danger btn-sm btn-mini"
;
}
// 获取当前行数据ID
$id
=
$this
->
getKey
();
$this
->
setHtmlAttribute
([
'data-id'
=>
$id
,
"class"
=>
"
{
$class
}
{
$color
}
"
,
"class"
=>
"
{
$class
}
{
$color
}
"
,
]);
return
parent
::
html
();
}
...
...
@@ -59,7 +60,7 @@ class UserStatusAction extends RowAction
public
function
confirm
()
{
$buttonName
=
"启用"
;
if
(
$this
->
row
->
status
==
User
::
STATUS_NORMAL
)
{
if
(
$this
->
row
->
status
==
User
::
STATUS_NORMAL
)
{
$buttonName
=
"禁用"
;
}
return
[
"是否确认
{
$buttonName
}
?"
];
...
...
@@ -78,8 +79,13 @@ class UserStatusAction extends RowAction
// 获取 parameters 方法传递的参数
$rowData
=
$request
->
get
(
'rowData'
);
return
$this
->
response
()
->
success
(
'取消成功'
)
->
refresh
();
try
{
UserService
::
updateUserStatus
(
$id
,
$rowData
[
'status'
]
==
User
::
STATUS_NORMAL
?
User
::
STATUS_DISABLE
:
User
::
STATUS_NORMAL
);
}
catch
(
\Throwable
$e
)
{
return
$this
->
response
()
->
error
(
$e
->
getMessage
());
}
return
$this
->
response
()
->
success
(
'操作成功'
)
->
refresh
();
}
/**
...
...
@@ -95,6 +101,4 @@ class UserStatusAction extends RowAction
}
}
app/Admin/Service/UserService.php
View file @
753ab4d3
...
...
@@ -8,12 +8,13 @@ use App\Admin\Actions\User\UserAssignAction;
use
App\Admin\Actions\User\UserStatusAction
;
use
App\Admin\Actions\User\UserTransferAction
;
use
App\Models\Cms\CmsUser
;
use
App\Models\User
;
use
Dcat\Admin\Grid
;
class
UserService
{
public
static
function
userListFilter
(
Grid
$grid
)
{
public
static
function
userListFilter
(
Grid
$grid
)
{
$grid
->
filter
(
function
(
$filter
)
{
$filter
->
expand
(
true
);
$filter
->
whereBetween
(
'create_time'
,
function
(
$q
)
{
...
...
@@ -26,17 +27,18 @@ class UserService
$filter
->
startWith
(
'user_sn'
)
->
width
(
2
);
$filter
->
startWith
(
'name'
)
->
width
(
2
);
$filter
->
equal
(
'status'
)
->
select
(
admin_trans
(
'user.options.status'
))
->
width
(
2
);
$filter
->
equal
(
'sales_id'
,
trans
(
'inquiry.fields.sales_name'
))
->
select
(
CmsUser
::
pluck
(
'name'
,
'userId'
)
->
toArray
())
->
width
(
3
);
$filter
->
equal
(
'sale_id'
,
trans
(
'user.fields.sale_name'
))
->
select
(
CmsUser
::
pluck
(
'name'
,
'userId'
)
->
toArray
())
->
width
(
3
);
$filter
->
equal
(
'reg_source'
)
->
select
(
admin_trans
(
'user.options.reg_source'
))
->
width
(
2
);
});
}
public
static
function
userListListField
(
Grid
$grid
){
public
static
function
userListListField
(
Grid
$grid
)
{
$grid
->
column
(
'company_name'
);
$grid
->
column
(
'user_sn'
)
->
link
(
function
(
$user_sn
)
{
return
admin_url
(
'smc_user/'
.
$user_sn
);
});
return
admin_url
(
'smc_user/'
.
$user_sn
);
});
$grid
->
column
(
'name'
);
$grid
->
column
(
'phone'
);
$grid
->
column
(
'email'
);
...
...
@@ -46,18 +48,18 @@ class UserService
return
$time
?
date
(
'Y-m-d H:i:s'
,
$time
)
:
''
;
})
->
sortable
();;
$grid
->
column
(
'status'
)
->
using
(
admin_trans
(
'user.options.status'
));
}
public
static
function
userListTool
(
Grid
$grid
){
public
static
function
userListTool
(
Grid
$grid
)
{
$grid
->
tools
([
new
UserAssignAction
(
"分配销售"
),
new
UserTransferAction
(
"转移销售"
),
]);
}
public
static
function
userListActions
(
Grid
$grid
)
{
public
static
function
userListActions
(
Grid
$grid
)
{
$grid
->
setActionClass
(
Grid\Displayers\Actions
::
class
);
$grid
->
actions
(
function
(
Grid\Displayers\Actions
$actions
)
{
$actions
->
disableDelete
();
...
...
@@ -71,10 +73,14 @@ class UserService
$id
=
$actions
->
getKey
();
//状态按钮
$actions
->
append
(
new
UserStatusAction
());
});
}
public
static
function
updateUserStatus
(
$id
,
$status
)
{
$update
=
[
"status"
=>
$status
];
User
::
updateById
(
$id
,
$update
);
}
}
app/Models/User.php
View file @
753ab4d3
...
...
@@ -30,9 +30,39 @@ class User extends Model
{
use
HasDateTimeFormatter
;
protected
$table
=
'users'
;
public
$timestamps
=
false
;
const
STATUS_NORMAL
=
1
;
const
STATUS_DISABLE
=
-
1
;
public
static
function
insertData
(
$data
)
{
return
self
::
insertGetId
(
$data
);
}
public
static
function
updateById
(
$id
,
$update
)
{
return
self
::
where
(
"id"
,
$id
)
->
update
(
$update
);
}
public
static
function
getInfoByUserId
(
$userId
)
{
$res
=
self
::
where
(
'user_id'
,
$userId
)
->
first
();
return
(
$res
)
?
$res
->
toArray
()
:
[];
}
// 批量获取用户信息
public
static
function
getInfoByUserIds
(
$userId
)
{
return
self
::
whereIn
(
'user_id'
,
$userId
)
->
get
()
->
keyBy
(
'user_id'
)
->
toArray
();
}
public
static
function
getListByIdArr
(
$userIdArr
)
{
$res
=
self
::
wherein
(
'user_id'
,
$userIdArr
)
->
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