Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵增煜
/
tzt-admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
40bad929
authored
Nov 27, 2024
by
lujunyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
药店权限控制
parent
91f96463
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
150 additions
and
92 deletions
+150
-92
app/Admin/Controllers/PharmacistController.php
+66
-41
app/Admin/Controllers/PharmacyController.php
+84
-51
No files found.
app/Admin/Controllers/PharmacistController.php
View file @
40bad929
...
...
@@ -10,7 +10,9 @@
use
Dcat\Admin\Form
;
use
Dcat\Admin\Grid
;
use
Dcat\Admin\Http\Controllers\AdminController
;
use
Dcat\Admin\Layout\Content
;
use
Dcat\Admin\Show
;
use
Dcat\Admin\Widgets\Alert
;
use
Dcat\Admin\Widgets\Tab
;
use
Illuminate\Http\Request
;
use
Jxlwqq\IdValidator\IdValidator
;
...
...
@@ -61,9 +63,14 @@ protected function grid()
return
$tab
;
});
// 药店权限判断和数据过滤
if
(
Admin
::
user
()
->
isRole
(
'pharmacy'
))
{
$grid
->
model
()
->
where
(
'pharmacy_id'
,
Admin
::
user
()
->
pharmacy_id
);
}
$grid
->
model
()
->
orderBy
(
'id'
,
'desc'
);
$grid
->
column
(
'id'
)
->
sortable
();
if
(
!
Admin
::
user
()
->
isRole
(
'pharmacy'
))
{
$grid
->
column
(
'id'
)
->
sortable
();
}
$grid
->
column
(
'status'
)
->
switch
(
''
,
true
);
$grid
->
column
(
'name'
);
$grid
->
column
(
'id_card'
)
->
display
(
function
(
$content
)
{
...
...
@@ -82,26 +89,37 @@ protected function grid()
// $grid->column('created_at');
// $grid->column('updated_at')->sortable();
// 快捷搜索
$grid
->
quickSearch
([
'name'
,
'mobile'
,
'id_card'
])
->
placeholder
(
'请输入[姓名|手机号|身份证号码]'
)
->
width
(
25
);
$grid
->
filter
(
function
(
Grid\Filter
$filter
)
{
$filter
->
panel
();
// 更改为 panel 布局
$filter
->
expand
();
// 默认展开搜索框
$filter
->
like
(
'name'
)
->
width
(
3
);
$filter
->
like
(
'id_card'
)
->
width
(
3
);
$filter
->
like
(
'mobile'
)
->
width
(
3
);
$filter
->
equal
(
'pharmacy_id'
)
->
select
(
PharmacyModel
::
all
()
->
pluck
(
'name'
,
'id'
))
->
width
(
3
);
});
if
(
Admin
::
user
()
->
isRole
(
'pharmacy'
))
{
// 行按钮控制
$grid
->
disableDeleteButton
();
// 禁用删除按钮
$grid
->
disableViewButton
();
// 禁用详情按钮
$grid
->
disableRowSelector
();
// 禁止选中行
// 工具栏按钮控制
$grid
->
disableBatchActions
();
// 禁用批量按钮
$grid
->
disableCreateButton
();
// 禁止创建按钮
}
else
{
// 快捷搜索
$grid
->
quickSearch
([
'name'
,
'mobile'
,
'id_card'
])
->
placeholder
(
'请输入[姓名|手机号|身份证号码]'
)
->
width
(
25
);
$grid
->
filter
(
function
(
Grid\Filter
$filter
)
{
$filter
->
panel
();
// 更改为 panel 布局
$filter
->
expand
();
// 默认展开搜索框
$filter
->
like
(
'name'
)
->
width
(
3
);
$filter
->
like
(
'id_card'
)
->
width
(
3
);
$filter
->
like
(
'mobile'
)
->
width
(
3
);
$filter
->
equal
(
'pharmacy_id'
)
->
select
(
PharmacyModel
::
all
()
->
pluck
(
'name'
,
'id'
))
->
width
(
3
);
});
$grid
->
setActionClass
(
Grid\Displayers\Actions
::
class
);
// 行按钮控制
$grid
->
disableDeleteButton
();
// 禁用删除按钮
$grid
->
disableViewButton
();
// 禁用详情按钮
$grid
->
setActionClass
(
Grid\Displayers\Actions
::
class
);
// 行按钮控制
$grid
->
disableDeleteButton
();
// 禁用删除按钮
$grid
->
disableViewButton
();
// 禁用详情按钮
// 工具栏按钮控制
$grid
->
disableBatchDelete
();
// 禁用批量删除
// 工具栏按钮控制
$grid
->
disableBatchDelete
();
// 禁用批量删除
}
});
}
...
...
@@ -111,27 +129,27 @@ protected function grid()
* @param mixed $id
* @return Show
*/
protected
function
detail
(
$id
)
{
return
Show
::
make
(
$id
,
new
PharmacistRepository
(),
function
(
Show
$show
)
{
$show
->
field
(
'id'
)
->
width
(
4
);
$show
->
field
(
'name'
)
->
width
(
4
);
$show
->
field
(
'id_card'
)
->
width
(
4
);
$show
->
field
(
'license_number'
)
->
width
(
4
);
$show
->
field
(
'mobile'
)
->
width
(
4
);
$show
->
field
(
'practicing_license'
)
->
width
(
4
);
$show
->
field
(
'practicing_license_period'
)
->
width
(
4
);
$show
->
field
(
'physician_license'
)
->
width
(
4
);
$show
->
field
(
'signed_pic'
)
->
width
(
4
);
$show
->
field
(
'status'
)
->
width
(
4
);
$show
->
field
(
'created_at'
)
->
width
(
4
);
$show
->
field
(
'updated_at'
)
->
width
(
4
);
$show
->
panel
()
->
tools
(
function
(
$tools
)
{
$tools
->
disableDelete
();
// 禁止删除按钮
});
});
}
//
protected function detail($id)
//
{
//
return Show::make($id, new PharmacistRepository(), function (Show $show) {
//
$show->field('id')->width(4);
//
$show->field('name')->width(4);
//
$show->field('id_card')->width(4);
//
$show->field('license_number')->width(4);
//
$show->field('mobile')->width(4);
//
$show->field('practicing_license')->width(4);
//
$show->field('practicing_license_period')->width(4);
//
$show->field('physician_license')->width(4);
//
$show->field('signed_pic')->width(4);
//
$show->field('status')->width(4);
//
$show->field('created_at')->width(4);
//
$show->field('updated_at')->width(4);
//
$show->panel()->tools(function ($tools) {
//
$tools->disableDelete(); // 禁止删除按钮
//
});
//
});
//
}
/**
* Make a form builder.
...
...
@@ -141,6 +159,13 @@ protected function detail($id)
protected
function
form
()
{
return
Form
::
make
(
new
PharmacistRepository
(),
function
(
Form
$form
)
{
$pharmacyId
=
$form
->
pharmacy_id
;
if
(
Admin
::
user
()
->
isRole
(
'pharmacy'
)
&&
Admin
::
user
()
->
pharmacy_id
!=
$pharmacyId
)
{
admin_exit
(
Content
::
make
()
->
body
(
Alert
::
make
(
'您无法进行此操作~'
,
'无权操作'
)
->
danger
())
);
}
$form
->
column
(
6
,
function
(
Form
$form
)
{
$form
->
display
(
'id'
);
$form
->
text
(
'name'
)
->
required
()
->
maxLength
(
32
,
'最多输入32个字符'
);
...
...
app/Admin/Controllers/PharmacyController.php
View file @
40bad929
...
...
@@ -12,12 +12,15 @@
use
Box\Spout\Common\Entity\Style\Color
;
use
Box\Spout\Writer\Common\Creator\Style\StyleBuilder
;
use
Box\Spout\Writer\Common\Creator\WriterEntityFactory
;
use
Dcat\Admin\Admin
;
use
Dcat\Admin\Form
;
use
Dcat\Admin\Grid
;
use
Dcat\Admin\Http\Controllers\AdminController
;
use
Dcat\Admin\Layout\Content
;
use
Dcat\Admin\Models\Administrator
;
use
Dcat\Admin\Models\Role
;
use
Dcat\Admin\Show
;
use
Dcat\Admin\Widgets\Alert
;
use
Dcat\EasyExcel\Excel
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Str
;
...
...
@@ -33,10 +36,18 @@ class PharmacyController extends AdminController
protected
function
grid
()
{
return
Grid
::
make
(
new
PharmacyRepository
(
'user'
),
function
(
Grid
$grid
)
{
// 药店权限判断和数据过滤
if
(
Admin
::
user
()
->
isRole
(
'pharmacy'
))
{
$grid
->
model
()
->
where
(
'id'
,
Admin
::
user
()
->
pharmacy_id
);
}
$grid
->
model
()
->
orderBy
(
'id'
,
'desc'
);
$grid
->
column
(
'id'
)
->
sortable
();
$grid
->
column
(
'status'
)
->
switch
(
''
,
true
);
if
(
Admin
::
user
()
->
isRole
(
'pharmacy'
))
{
$grid
->
column
(
'status'
)
->
using
(
PharmacyModel
::
STATUS_MAP
);
}
else
{
$grid
->
column
(
'id'
)
->
sortable
();
$grid
->
column
(
'status'
)
->
switch
(
''
,
true
);
}
$grid
->
column
(
'is_open'
)
->
using
(
PharmacyModel
::
IS_OPEN_MAP
)
->
help
(
'药店控制'
)
->
dot
(
PharmacyModel
::
IS_OPEN_MAP_COLOR
);
$grid
->
column
(
'is_auto'
)
->
using
(
PharmacyModel
::
IS_AUTO_MAP
)
->
dot
(
PharmacyModel
::
IS_AUTO_MAP_COLOR
);
$grid
->
column
(
'name'
);
...
...
@@ -57,36 +68,45 @@ protected function grid()
$grid
->
column
(
'mobile'
);
// $grid->column('lng');
// $grid->column('lat');
$grid
->
column
(
'user.openid'
);
//
$grid->column('user.openid');
$grid
->
column
(
'created_at'
);
$grid
->
column
(
'updated_at'
)
->
sortable
();
// 工具栏普通按钮
$grid
->
tools
(
function
(
$tools
)
{
$tools
->
append
(
new
PharmacyImportAction
());
// 导入药店信息
});
// 快捷搜索
$grid
->
quickSearch
([
'name'
,
'mobile'
])
->
placeholder
(
'请输入[药店名称|管理员手机号]'
)
->
width
(
25
);
if
(
Admin
::
user
()
->
isRole
(
'pharmacy'
))
{
// 行按钮控制
$grid
->
disableDeleteButton
();
// 禁用删除按钮
$grid
->
disableViewButton
();
// 禁用详情按钮
$grid
->
disableRowSelector
();
// 禁止选中行
$grid
->
filter
(
function
(
Grid\Filter
$filter
)
{
$filter
->
panel
();
// 更改为 panel 布局
$filter
->
expand
();
// 默认展开搜索框
// 工具栏按钮控制
$grid
->
disableBatchActions
();
// 禁用批量按钮
$grid
->
disableCreateButton
();
// 禁止创建按钮
}
else
{
// 工具栏普通按钮
$grid
->
tools
(
function
(
$tools
)
{
$tools
->
append
(
new
PharmacyImportAction
());
// 导入药店信息
});
$filter
->
like
(
'name'
)
->
width
(
3
);
$filter
->
like
(
'mobile'
)
->
width
(
3
);
$filter
->
in
(
'status'
,
'平台启用状态'
)
->
checkbox
(
PharmacyModel
::
STATUS_MAP
)
->
width
(
3
);
$filter
->
in
(
'is_open'
,
'开店状态'
)
->
checkbox
(
PharmacyModel
::
IS_OPEN_MAP
)
->
width
(
3
);
$filter
->
in
(
'is_auto'
,
'自动审方'
)
->
checkbox
(
PharmacyModel
::
IS_AUTO_MAP
)
->
width
(
3
);
});
// 快捷搜索
$grid
->
quickSearch
([
'name'
,
'mobile'
])
->
placeholder
(
'请输入[药店名称|管理员手机号]'
)
->
width
(
25
);
$grid
->
filter
(
function
(
Grid\Filter
$filter
)
{
$filter
->
panel
();
// 更改为 panel 布局
$filter
->
expand
();
// 默认展开搜索框
$grid
->
setActionClass
(
Grid\Displayers\Actions
::
class
);
// 行按钮控制
$grid
->
disableDeleteButton
();
// 禁用删除按钮
$grid
->
disableViewButton
();
// 禁用详情按钮
$filter
->
like
(
'name'
)
->
width
(
3
);
$filter
->
like
(
'mobile'
)
->
width
(
3
);
$filter
->
in
(
'status'
,
'平台启用状态'
)
->
checkbox
(
PharmacyModel
::
STATUS_MAP
)
->
width
(
3
);
$filter
->
in
(
'is_open'
,
'开店状态'
)
->
checkbox
(
PharmacyModel
::
IS_OPEN_MAP
)
->
width
(
3
);
$filter
->
in
(
'is_auto'
,
'自动审方'
)
->
checkbox
(
PharmacyModel
::
IS_AUTO_MAP
)
->
width
(
3
);
});
$grid
->
setActionClass
(
Grid\Displayers\Actions
::
class
);
// 行按钮控制
$grid
->
disableDeleteButton
();
// 禁用删除按钮
$grid
->
disableViewButton
();
// 禁用详情按钮
// 工具栏按钮控制
$grid
->
disableBatchDelete
();
// 禁用批量删除
// 工具栏按钮控制
$grid
->
disableBatchActions
();
// 禁用批量操作
}
});
}
...
...
@@ -96,31 +116,31 @@ protected function grid()
* @param mixed $id
* @return Show
*/
protected
function
detail
(
$id
)
{
return
Show
::
make
(
$id
,
new
PharmacyRepository
(),
function
(
Show
$show
)
{
$show
->
field
(
'id'
)
->
width
(
4
);
$show
->
field
(
'name'
)
->
width
(
4
);
$show
->
field
(
'business_license'
)
->
width
(
4
);
$show
->
field
(
'drug_biz_license'
)
->
width
(
4
);
$show
->
field
(
'food_biz_license'
)
->
width
(
4
);
$show
->
field
(
'med_device_biz_license'
)
->
width
(
4
);
$show
->
field
(
'drug_info_service_cert'
)
->
width
(
4
);
$show
->
field
(
'pre_packaged_food'
)
->
width
(
4
);
$show
->
field
(
'area'
)
->
width
(
4
);
$show
->
field
(
'address'
)
->
width
(
4
);
$show
->
field
(
'mobile'
)
->
width
(
4
);
$show
->
field
(
'lng'
)
->
width
(
4
);
$show
->
field
(
'lat'
)
->
width
(
4
);
$show
->
field
(
'status'
)
->
width
(
4
);
$show
->
field
(
'created_at'
)
->
width
(
4
);
$show
->
field
(
'updated_at'
)
->
width
(
4
);
$show
->
panel
()
->
tools
(
function
(
$tools
)
{
$tools
->
disableDelete
();
// 禁止删除按钮
});
});
}
//
protected function detail($id)
//
{
//
return Show::make($id, new PharmacyRepository(), function (Show $show) {
//
$show->field('id')->width(4);
//
$show->field('name')->width(4);
//
$show->field('business_license')->width(4);
//
$show->field('drug_biz_license')->width(4);
//
$show->field('food_biz_license')->width(4);
//
$show->field('med_device_biz_license')->width(4);
//
$show->field('drug_info_service_cert')->width(4);
//
$show->field('pre_packaged_food')->width(4);
//
$show->field('area')->width(4);
//
$show->field('address')->width(4);
//
$show->field('mobile')->width(4);
//
$show->field('lng')->width(4);
//
$show->field('lat')->width(4);
//
$show->field('status')->width(4);
//
$show->field('created_at')->width(4);
//
$show->field('updated_at')->width(4);
//
$show->panel()->tools(function ($tools) {
//
$tools->disableDelete(); // 禁止删除按钮
//
});
//
});
//
}
/**
* Make a form builder.
...
...
@@ -130,6 +150,13 @@ protected function detail($id)
protected
function
form
()
{
return
Form
::
make
(
new
PharmacyRepository
(),
function
(
Form
$form
)
{
$pharmacyId
=
$form
->
getKey
();
if
(
Admin
::
user
()
->
isRole
(
'pharmacy'
)
&&
Admin
::
user
()
->
pharmacy_id
!=
$pharmacyId
)
{
admin_exit
(
Content
::
make
()
->
body
(
Alert
::
make
(
'您无法进行此操作~'
,
'无权操作'
)
->
danger
())
);
}
$form
->
column
(
6
,
function
(
Form
$form
)
{
$form
->
display
(
'id'
);
$form
->
text
(
'name'
)
->
required
()
->
maxLength
(
64
,
'最多输入64个字符'
);
...
...
@@ -144,7 +171,7 @@ protected function form()
$form
->
timeRange
(
'business_start'
,
'business_end'
,
'营业时间'
)
->
required
();
$form
->
map
(
'lat'
,
'lng'
,
'经纬度坐标'
);
// $form->select('user_id')->options(User::all()->pluck('openid', 'id'))->width(6)->help('实际后台操作可以不用关联');
if
(
$form
->
isEditing
())
{
if
(
$form
->
isEditing
()
&&
!
Admin
::
user
()
->
isRole
(
'pharmacy'
)
)
{
$form
->
switch
(
'status'
);
}
$form
->
switch
(
'is_auto'
);
...
...
@@ -161,6 +188,9 @@ protected function form()
$form
->
image
(
'pre_packaged_food'
)
->
accept
(
'jpg,png,jpeg'
)
->
uniqueName
()
->
autoUpload
()
->
retainable
()
->
removable
(
false
);
});
$form
->
saving
(
function
(
Form
$form
)
{
if
(
$form
->
isCreating
()
&&
Admin
::
user
()
->
isRole
(
'pharmacy'
))
{
return
$form
->
response
()
->
error
(
'您无法进行此操作~'
);
}
$status
=
$form
->
status
;
$pharmacyId
=
$form
->
getKey
();
$pharmacistNum
=
PharmacistModel
::
where
(
'status'
,
PharmacyModel
::
STATUS_TRUE
)
->
where
(
'pharmacy_id'
,
$pharmacyId
)
->
count
();
...
...
@@ -171,6 +201,9 @@ protected function form()
if
(
$form
->
mobile
&&
!
preg_match
(
'/^1[3456789]{1}[0-9]{9}$/'
,
$form
->
mobile
))
{
return
$form
->
response
()
->
error
(
'手机号格式错误'
);
}
if
(
Admin
::
user
()
->
isRole
(
'pharmacy'
))
{
$form
->
deleteInput
(
'status'
);
}
});
$form
->
saved
(
function
(
Form
$form
,
$result
)
{
...
...
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