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
7c68f97a
authored
Nov 20, 2024
by
lujunyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
导入
parent
6d1f9aca
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
16 deletions
+29
-16
app/Admin/Extensions/ToolBar/Forms/DrugImportForm.php
+29
-16
No files found.
app/Admin/Extensions/ToolBar/Forms/DrugImportForm.php
View file @
7c68f97a
...
...
@@ -11,11 +11,6 @@
class
DrugImportForm
extends
Form
{
const
IS_MAP
=
[
'Y'
=>
1
,
'N'
=>
0
,
];
/**
* 处理表单提交逻辑.
*/
...
...
@@ -33,18 +28,21 @@ public function handle(array $input): JsonResponse
// 此处的数组下标依然是excel表中数据行的行号
$rows
=
$collection
->
toArray
();
foreach
(
$rows
as
$row
)
{
$drugModel
=
new
DrugModel
;
$drugModel
->
name
=
$row
[
'药品名称'
];
$item
=
array_map
(
function
(
$value
)
{
return
is_string
(
$value
)
?
trim
(
$value
)
:
$value
;
},
$row
);
$drugModel
=
DrugModel
::
where
(
'product_id'
,
$item
[
'君元ID'
])
->
first
();
$drugModel
->
name
=
$item
[
'药品名称'
];
$drugModel
->
code
=
''
;
$drugModel
->
standard_code
=
$
row
[
'本位码'
];
$drugModel
->
unit
=
$
row
[
'单位'
];
$drugModel
->
spec
=
$
row
[
'规格'
];
$drugModel
->
dosage_form
=
$
row
[
'剂型'
];
$drugModel
->
factory
=
$
row
[
'生产厂家'
];
$drugModel
->
approval_no
=
$
row
[
'批准文号'
];
$drugModel
->
is_rx
=
self
::
IS_MAP
[
$row
[
'是否处方药'
]]
;
$drugModel
->
is_si
=
self
::
IS_MAP
[
$row
[
'是否医保药品'
]]
;
$drugModel
->
product_id
=
$
row
[
'君元ID'
]
??
0
;
$drugModel
->
standard_code
=
$
item
[
'本位码'
];
$drugModel
->
unit
=
$
item
[
'单位'
];
$drugModel
->
spec
=
$
item
[
'规格'
];
$drugModel
->
dosage_form
=
$
item
[
'剂型'
];
$drugModel
->
factory
=
$
item
[
'生产厂家'
];
$drugModel
->
approval_no
=
$
item
[
'批准文号'
];
$drugModel
->
is_rx
=
self
::
toBool
(
$item
[
'是否处方药'
])
;
$drugModel
->
is_si
=
self
::
toBool
(
$item
[
'是否医保药品'
])
;
$drugModel
->
product_id
=
$
item
[
'君元ID'
]
??
0
;
if
(
$drugModel
->
save
())
{
$successNum
++
;
}
...
...
@@ -77,4 +75,19 @@ public function form()
$downloadUrl
=
admin_url
(
'drug-template'
);
$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
;
}
}
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