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
11e33f43
authored
Nov 20, 2024
by
lujunyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
导出导入模板
parent
6303c69f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
124 additions
and
75 deletions
+124
-75
app/Admin/Controllers/DrugController.php
+32
-0
app/Admin/Extensions/ToolBar/Actions/DrugImportAction.php
+21
-0
app/Admin/Extensions/ToolBar/Forms/DrugImportForm.php
+69
-0
app/Admin/Extensions/ToolBar/Forms/Shop/DeliveryImportForm.php
+0
-75
app/Admin/routes.php
+2
-0
No files found.
app/Admin/Controllers/DrugController.php
View file @
11e33f43
...
@@ -2,14 +2,20 @@
...
@@ -2,14 +2,20 @@
namespace
App\Admin\Controllers
;
namespace
App\Admin\Controllers
;
use
App\Admin\Extensions\ToolBar\Actions\DrugImportAction
;
use
App\Admin\Repositories\DrugRepository
;
use
App\Admin\Repositories\DrugRepository
;
use
App\Models\DrugModel
;
use
App\Models\DrugModel
;
use
App\Models\DrugTagModel
;
use
App\Models\DrugTagModel
;
use
App\Models\DrugUnitModel
;
use
App\Models\DrugUnitModel
;
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\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\Show
;
use
Dcat\Admin\Show
;
use
Dcat\EasyExcel\Excel
;
use
Illuminate\Http\Request
;
// 药品池
// 药品池
class
DrugController
extends
AdminController
class
DrugController
extends
AdminController
...
@@ -43,6 +49,11 @@ protected function grid()
...
@@ -43,6 +49,11 @@ protected function grid()
// $grid->column('created_at');
// $grid->column('created_at');
// $grid->column('updated_at')->sortable();
// $grid->column('updated_at')->sortable();
// 工具栏普通按钮
$grid
->
tools
(
function
(
$tools
)
{
$tools
->
append
(
new
DrugImportAction
());
// 导入发货信息
});
// 快捷搜索
// 快捷搜索
$grid
->
quickSearch
([
'name'
,
'code'
,
'factory'
])
->
placeholder
(
'请输入[药品名称/药品简码/生产厂家]'
)
->
width
(
25
);
$grid
->
quickSearch
([
'name'
,
'code'
,
'factory'
])
->
placeholder
(
'请输入[药品名称/药品简码/生产厂家]'
)
->
width
(
25
);
...
@@ -134,4 +145,25 @@ protected function form()
...
@@ -134,4 +145,25 @@ protected function form()
$form
->
disableDeleteButton
();
// 去掉删除按钮
$form
->
disableDeleteButton
();
// 去掉删除按钮
});
});
}
}
/**
* 药品导入模板
*
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
*/
public
function
exportDrugTemplate
(
Request
$request
)
{
$sheet1Head
=
[
'药品名称'
,
'本位码'
,
'单位'
,
'规格'
,
'剂型'
,
'生产厂家'
,
'批准文号'
,
'是否处方药'
,
'是否医保药品'
,
'君元ID'
];
$sheet1Data
=
[[
'加味天麻胶囊'
,
'86903692001013'
,
'粒'
,
'36s'
,
'每粒装0.25g'
,
'葵花药业集团(佳木斯)有限公司'
,
'国药准字Z23020970'
,
'是'
,
'是'
,
'8000'
]];
$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/Actions/DrugImportAction.php
0 → 100644
View file @
11e33f43
<?php
namespace
App\Admin\Extensions\ToolBar\Actions
;
use
App\Admin\Extensions\ToolBar\Forms\DrugImportForm
;
use
Dcat\Admin\Grid\Tools\AbstractTool
;
use
Dcat\Admin\Widgets\Modal
;
class
DrugImportAction
extends
AbstractTool
{
public
$title
=
'导入药品'
;
public
function
html
()
:
Modal
{
return
Modal
::
make
()
->
lg
()
->
title
(
$this
->
title
)
->
body
(
new
DrugImportForm
())
->
button
(
"<button class='btn btn-success'><i class='feather icon-upload'></i>
{
$this
->
title
}
</button>"
);
}
}
app/Admin/Extensions/ToolBar/Forms/DrugImportForm.php
0 → 100644
View file @
11e33f43
<?php
namespace
App\Admin\Extensions\ToolBar\Forms
;
use
Dcat\Admin\Http\JsonResponse
;
use
Dcat\Admin\Widgets\Form
;
use
Dcat\EasyExcel\Excel
;
use
Exception
;
class
DrugImportForm
extends
Form
{
/**
* 处理表单提交逻辑.
*/
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());
// }
return
$return
;
}
/**
* 构造表单.
*/
public
function
form
()
{
$this
->
file
(
'import_file'
,
'文件'
)
->
disk
(
'local'
)
->
accept
(
'xls,xlsx,csv'
)
->
autoUpload
()
->
uniqueName
()
->
required
()
->
help
(
"导入要求:<br />
<span style='color:red;'>
1、支持xls、xlsx、csv三种格式
</span>"
);
$downloadUrl
=
admin_url
(
'drug-template'
);
$this
->
html
(
"<a target='_blank' href='
{
$downloadUrl
}
'>下载药品导入模板</a>"
);
}
}
app/Admin/Extensions/ToolBar/Forms/Shop/DeliveryImportForm.php
deleted
100644 → 0
View file @
6303c69f
<?php
namespace
App\Admin\Extensions\ToolBar\Forms\Shop
;
use
App\Models\Shop\ShopDeliveryImport
;
use
App\Service\Shop\ShopService
;
use
Dcat\Admin\Http\JsonResponse
;
use
Dcat\Admin\Widgets\Form
;
use
Dcat\EasyExcel\Excel
;
use
Exception
;
class
DeliveryImportForm
extends
Form
{
/**
* 处理表单提交逻辑.
*/
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
());
}
return
$return
;
}
/**
* 构造表单.
*/
public
function
form
()
{
$this
->
text
(
'remark'
,
'发货备注'
)
->
placeholder
(
'方便自己区分'
);
$this
->
file
(
'import_file'
,
'文件'
)
->
disk
(
'admin'
)
->
accept
(
'xls,xlsx,csv'
)
->
autoUpload
()
->
uniqueName
()
->
required
()
->
help
(
"导入要求:<br />
<span style='color:red;'>
1、支持xls、xlsx、csv三种格式!<br />
2、表头必须包含【订单号,快递公司,快递单号】这三列,列的顺序无所谓,多余列会自动过滤!<br />
3、“快递公司”填写发货模板第二个sheet中的“快递公司编码”<br />
4、发货信息必须在第一个sheet!
</span>"
);
$downloadUrl
=
admin_url
(
'shop-delivery-template-url'
);
$this
->
html
(
"<a target='_blank' href='
{
$downloadUrl
}
'>下载发货模板文件</a>"
);
}
}
app/Admin/routes.php
View file @
11e33f43
...
@@ -19,6 +19,8 @@
...
@@ -19,6 +19,8 @@
$router
->
resource
(
'diagnosi'
,
'DiagnosiController'
);
$router
->
resource
(
'diagnosi'
,
'DiagnosiController'
);
// 药品-药品
// 药品-药品
$router
->
resource
(
'drug'
,
'DrugController'
);
$router
->
resource
(
'drug'
,
'DrugController'
);
// 下载导出模板
$router
->
get
(
'drug-template'
,
'DrugController@exportDrugTemplate'
);
// 药品-标签
// 药品-标签
$router
->
resource
(
'drug-tag'
,
'DrugTagController'
);
$router
->
resource
(
'drug-tag'
,
'DrugTagController'
);
// 药品-单位
// 药品-单位
...
...
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