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
7b884187
authored
Dec 11, 2024
by
lujunyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
用法用量导入
parent
301bc685
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
29 deletions
+47
-29
app/Admin/Controllers/DosageController.php
+26
-0
app/Admin/Extensions/ToolBar/Forms/PharmacyDosageImportForm.php
+19
-29
app/Admin/routes.php
+2
-0
No files found.
app/Admin/Controllers/DosageController.php
View file @
7b884187
...
@@ -4,12 +4,17 @@
...
@@ -4,12 +4,17 @@
use
App\Admin\Extensions\ToolBar\Actions\PharmacyDosageImportAction
;
use
App\Admin\Extensions\ToolBar\Actions\PharmacyDosageImportAction
;
use
App\Admin\Repositories\DosageRepository
;
use
App\Admin\Repositories\DosageRepository
;
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\Admin
;
use
Dcat\Admin\Form
;
use
Dcat\Admin\Form
;
use
Dcat\Admin\Grid
;
use
Dcat\Admin\Grid
;
use
Dcat\Admin\Http\Controllers\AdminController
;
use
Dcat\Admin\Http\Controllers\AdminController
;
use
Dcat\Admin\Layout\Content
;
use
Dcat\Admin\Layout\Content
;
use
Dcat\Admin\Show
;
use
Dcat\Admin\Show
;
use
Dcat\EasyExcel\Excel
;
use
Illuminate\Http\Request
;
// 用法用量
// 用法用量
class
DosageController
extends
AdminController
class
DosageController
extends
AdminController
...
@@ -111,4 +116,25 @@ protected function form()
...
@@ -111,4 +116,25 @@ protected function form()
$form
->
disableViewButton
();
// 去掉跳转详情页按钮
$form
->
disableViewButton
();
// 去掉跳转详情页按钮
});
});
}
}
/**
* 药品导入模板
*
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
*/
public
function
exportDosageTemplate
(
Request
$request
)
{
$sheet1Head
=
[
'用法用量'
,
'显示内容'
];
$sheet1Data
=
[[
'220ug qd 每鼻孔2喷'
,
'220ug qd 每鼻孔2喷'
]];
$sheet1
=
Excel
::
createSheet
(
$sheet1Data
,
'用法用量信息'
,
$sheet1Head
)
->
row
(
function
(
array
$row
)
{
$style
=
(
new
StyleBuilder
)
->
setBackgroundColor
(
Color
::
YELLOW
)
->
build
();
return
WriterEntityFactory
::
createRowFromArray
(
$row
,
$style
);
});
return
Excel
::
export
([
$sheet1
])
->
headings
(
false
)
->
download
(
'用法用量导入模板.xlsx'
);
}
}
}
app/Admin/Extensions/ToolBar/Forms/PharmacyDosageImportForm.php
View file @
7b884187
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
namespace
App\Admin\Extensions\ToolBar\Forms
;
namespace
App\Admin\Extensions\ToolBar\Forms
;
use
App\Models\DrugModel
;
use
App\Models\DosageModel
;
use
Dcat\Admin\Admin
;
use
Dcat\Admin\Http\JsonResponse
;
use
Dcat\Admin\Http\JsonResponse
;
use
Dcat\Admin\Widgets\Form
;
use
Dcat\Admin\Widgets\Form
;
use
Dcat\EasyExcel\Excel
;
use
Dcat\EasyExcel\Excel
;
...
@@ -20,6 +21,10 @@ class PharmacyDosageImportForm extends Form
...
@@ -20,6 +21,10 @@ class PharmacyDosageImportForm extends Form
*/
*/
public
function
handle
(
array
$input
)
:
JsonResponse
public
function
handle
(
array
$input
)
:
JsonResponse
{
{
if
(
!
Admin
::
user
()
->
isRole
(
'pharmacy'
)
||
!
Admin
::
user
()
->
pharmacy_id
)
{
admin_exit
(
Content
::
make
()
->
withError
(
trans
(
'admin.deny'
)));
}
$pharmacyId
=
Admin
::
user
()
->
pharmacy_id
;
// 表单参数
// 表单参数
$file
=
$input
[
'import_file'
];
$file
=
$input
[
'import_file'
];
$filePath
=
storage_path
(
'app/'
.
$file
);
$filePath
=
storage_path
(
'app/'
.
$file
);
...
@@ -28,24 +33,25 @@ public function handle(array $input): JsonResponse
...
@@ -28,24 +33,25 @@ public function handle(array $input): JsonResponse
$chunkSize
=
10
;
$chunkSize
=
10
;
$successNum
=
0
;
$successNum
=
0
;
$failNum
=
0
;
$failNum
=
0
;
Excel
::
import
(
$filePath
)
->
first
()
->
chunk
(
$chunkSize
,
function
(
SheetCollection
$collection
)
use
(
&
$successNum
)
{
Excel
::
import
(
$filePath
)
->
first
()
->
chunk
(
$chunkSize
,
function
(
SheetCollection
$collection
)
use
(
&
$successNum
,
$pharmacyId
)
{
// 此处的数组下标依然是excel表中数据行的行号
// 此处的数组下标依然是excel表中数据行的行号
$rows
=
$collection
->
toArray
();
$rows
=
$collection
->
toArray
();
foreach
(
$rows
as
$row
)
{
foreach
(
$rows
as
$row
)
{
$item
=
array_map
(
function
(
$value
)
{
$item
=
array_map
(
function
(
$value
)
{
return
is_string
(
$value
)
?
trim
(
$value
)
:
$value
;
return
is_string
(
$value
)
?
trim
(
$value
)
:
$value
;
},
$row
);
},
$row
);
$d
rug
Model
=
null
;
$d
osage
Model
=
null
;
if
(
isset
(
$item
[
'
君元ID'
])
&&
$item
[
'君元ID
'
])
{
if
(
isset
(
$item
[
'
用法用量'
])
&&
$item
[
'用法用量
'
])
{
$d
rugModel
=
DrugModel
::
where
(
'product_id'
,
$item
[
'君元ID
'
])
->
first
();
$d
osageModel
=
DosageModel
::
where
(
'dosage_desc'
,
$item
[
'用法用量
'
])
->
first
();
}
}
if
(
!
$d
rug
Model
)
{
if
(
!
$d
osage
Model
)
{
$d
rugModel
=
new
Drug
Model
;
$d
osageModel
=
new
Dosage
Model
;
}
}
$drugModel
->
name
=
$item
[
'通用名'
];
$dosageModel
->
pharmacy_id
=
$pharmacyId
;
$drugModel
->
product_name
=
$item
[
'商品名'
];
$dosageModel
->
dosage_desc
=
$item
[
'用法用量'
];
$dosageModel
->
dosage_show
=
$item
[
'显示内容'
]
??
''
;
if
(
$d
rug
Model
->
save
())
{
if
(
$d
osage
Model
->
save
())
{
$successNum
++
;
$successNum
++
;
}
}
}
}
...
@@ -73,25 +79,9 @@ public function form()
...
@@ -73,25 +79,9 @@ public function form()
->
required
()
->
required
()
->
help
(
"导入要求:<br />
->
help
(
"导入要求:<br />
<span style='color:red;'>
<span style='color:red;'>
1、支持xlsx、csv两种格式<br \>
1、支持xlsx、csv两种格式
2、更新的时候根据本位码唯一更新药品信息
</span>"
);
</span>"
);
$downloadUrl
=
admin_url
(
'drug-template'
);
$downloadUrl
=
admin_url
(
'dosage-template'
);
$this
->
html
(
"<a target='_blank' href='
{
$downloadUrl
}
'>下载药品导入模板</a>"
);
$this
->
html
(
"<a target='_blank' href='
{
$downloadUrl
}
'>下载用法用量导入模板</a>"
);
}
private
static
function
toBool
(
$value
)
{
// 定义一个数组,包含所有需要转换的值及其对应的结果
$mapping
=
[
'是'
=>
1
,
'Y'
=>
1
,
'y'
=>
1
,
'1'
=>
1
,
'否'
=>
0
,
'N'
=>
0
,
'n'
=>
0
,
'0'
=>
0
,
];
// 将输入值转换为小写,以便不区分大小写
$value
=
strtolower
(
$value
);
// 检查值是否存在于映射数组中,如果存在则返回对应的值,否则返回null或自定义的默认值
return
isset
(
$mapping
[
$value
])
?
$mapping
[
$value
]
:
0
;
}
}
}
}
app/Admin/routes.php
View file @
7b884187
...
@@ -68,6 +68,8 @@
...
@@ -68,6 +68,8 @@
$router
->
resource
(
'prescription-print'
,
'PrescriptionPrintController'
);
$router
->
resource
(
'prescription-print'
,
'PrescriptionPrintController'
);
// 用法用量
// 用法用量
$router
->
resource
(
'dosage'
,
'DosageController'
);
$router
->
resource
(
'dosage'
,
'DosageController'
);
// 下载导出模板
$router
->
get
(
'dosage-template'
,
'DosageController@exportDosageTemplate'
);
// 搜索生成处方单
// 搜索生成处方单
$router
->
post
(
'prescription-search'
,
'PrescriptionPrintController@search'
);
$router
->
post
(
'prescription-search'
,
'PrescriptionPrintController@search'
);
// 打印处方单
// 打印处方单
...
...
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