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
248cf850
authored
Nov 20, 2024
by
赵增煜
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://git.imohe.com/zhaozengyu/tzt-admin
parents
8a44edf3
a9160242
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
29 deletions
+40
-29
app/Admin/Extensions/ToolBar/Forms/DrugImportForm.php
+40
-29
No files found.
app/Admin/Extensions/ToolBar/Forms/DrugImportForm.php
View file @
248cf850
...
...
@@ -2,48 +2,59 @@
namespace
App\Admin\Extensions\ToolBar\Forms
;
use
App\Models\DrugModel
;
use
Dcat\Admin\Http\JsonResponse
;
use
Dcat\Admin\Widgets\Form
;
use
Dcat\EasyExcel\Excel
;
use
Dcat\EasyExcel\Support\SheetCollection
;
use
Exception
;
class
DrugImportForm
extends
Form
{
const
IS_MAP
=
[
'Y'
=>
1
,
'N'
=>
0
,
];
/**
* 处理表单提交逻辑.
*/
public
function
handle
(
array
$input
)
:
JsonResponse
{
// 表单参数
// $file = $input['import_file'];
// $remark = $input['remark'] ?? '';
// $filePath = storage_path('uploads/'.$file);
// try {
// $rows = Excel::import($filePath)->first()->toArray();
// $context = '';
// foreach ($rows as $row) {
// $orderId = $row['订单号'] ?? '';
// $deliveryCode = $row['快递公司'] ?? '';
// $deliveryNo = $row['快递单号'] ?? '';
// if (! $orderId || ! $deliveryCode || ! $deliveryNo) {
// continue;
// }
// $rowData = trim($orderId).','.trim($deliveryNo).','.trim($deliveryCode);
// $context .= $rowData."\n"; // 拼接数据并加上换行符
// }
// $context = rtrim($context, "\n");
// $deliveryImport = new ShopDeliveryImport();
// $deliveryImport->context = $context;
// $deliveryImport->remark = $remark;
// if ($deliveryImport->save()) {
// $id = $deliveryImport->id;
// ShopService::deliveryImportNotice($id);
// }
// $return = $this->response()->success('导入成功')->refresh();
// } catch (Exception $e) {
// $return = $this->response()->error('导入失败:'.$e->getMessage());
// }
$file
=
$input
[
'import_file'
];
$filePath
=
storage_path
(
'app/'
.
$file
);
try
{
// 每100行数据为一批数据进行读取
$chunkSize
=
10
;
$successNum
=
0
;
$failNum
=
0
;
Excel
::
import
(
$filePath
)
->
first
()
->
chunk
(
$chunkSize
,
function
(
SheetCollection
$collection
)
use
(
$successNum
)
{
// 此处的数组下标依然是excel表中数据行的行号
$rows
=
$collection
->
toArray
();
foreach
(
$rows
as
$row
)
{
$drugModel
=
new
DrugModel
;
$drugModel
->
name
=
$row
[
'药品名称'
];
$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
;
if
(
$drugModel
->
save
())
{
$successNum
++
;
}
}
});
$return
=
$this
->
response
()
->
success
(
"导入成功
{
$successNum
}
条"
)
->
refresh
();
unlink
(
$filePath
);
}
catch
(
Exception
$e
)
{
$return
=
$this
->
response
()
->
error
(
"导入失败
{
$failNum
}
条:"
.
$e
->
getMessage
());
}
return
$return
;
}
...
...
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