Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
liexin_supplier
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
daec97eb
authored
Mar 14, 2023
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
供应商导出功能,简易版
parent
447f0a75
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
84 additions
and
5 deletions
app/Http/Controllers/Api/SupplierApiController.php
app/Http/Services/SupplierService.php
app/Http/function.php
resources/views/script/SupplierListScript.blade.php
resources/views/web/SupplierList.blade.php
app/Http/Controllers/Api/SupplierApiController.php
View file @
daec97eb
...
@@ -723,4 +723,13 @@ class SupplierApiController extends Controller
...
@@ -723,4 +723,13 @@ class SupplierApiController extends Controller
$this
->
response
(
-
1
,
'没有全部采购员离职的供应商'
);
$this
->
response
(
-
1
,
'没有全部采购员离职的供应商'
);
}
}
//导出供应商
public
function
exportSupplier
(
$request
)
{
$params
=
$request
->
input
(
'params'
);
$params
=
json_decode
(
$params
,
true
);
(
new
SupplierService
())
->
exportSupplier
(
$params
);
exit
;
}
}
}
app/Http/Services/SupplierService.php
View file @
daec97eb
...
@@ -27,11 +27,16 @@ class SupplierService
...
@@ -27,11 +27,16 @@ class SupplierService
$filter
=
new
SupplierFilter
();
$filter
=
new
SupplierFilter
();
$query
=
$filter
->
listFilter
(
$map
,
$query
);
$query
=
$filter
->
listFilter
(
$map
,
$query
);
$limit
=
array_get
(
$map
,
'limit'
,
10
);
$limit
=
array_get
(
$map
,
'limit'
,
10
);
$list
=
$query
->
paginate
(
$limit
)
->
toArray
();
if
(
!
empty
(
$map
[
'is_export'
]))
{
$transformer
=
new
SupplierTransformer
();
$list
=
$query
->
get
()
->
toArray
();
$list
[
'data'
]
=
$transformer
->
transformList
(
$list
[
'data'
]);
}
else
{
//这里还要单独去处理采购员是否离职的显示,考虑到性能,所以再单独搞个方法出来了
$list
=
$query
->
paginate
(
$limit
)
->
toArray
();
$list
[
'data'
]
=
$transformer
->
transformResignChannelUser
(
$list
[
'data'
]);
$transformer
=
new
SupplierTransformer
();
$list
[
'data'
]
=
$transformer
->
transformList
(
$list
[
'data'
]);
//这里还要单独去处理采购员是否离职的显示,考虑到性能,所以再单独搞个方法出来了
$list
[
'data'
]
=
$transformer
->
transformResignChannelUser
(
$list
[
'data'
]);
}
return
$list
;
return
$list
;
}
}
...
@@ -686,4 +691,30 @@ class SupplierService
...
@@ -686,4 +691,30 @@ class SupplierService
return
(
bool
)
$list
[
'total'
];
return
(
bool
)
$list
[
'total'
];
}
}
//导出供应商
public
function
exportSupplier
(
$params
)
{
$params
[
'is_export'
]
=
1
;
$list
=
$this
->
getSupplierList
(
$params
);
foreach
(
$list
as
&
$supplier
)
{
$supplier
[
'channel_username'
]
=
(
new
SupplierTransformer
())
->
getChannelUserNames
(
$supplier
[
'channel_uid'
]);
}
unset
(
$supplier
);
$csvData
=
[];
foreach
(
$list
as
$supplier
)
{
$item
=
[
$supplier
[
'supplier_code'
],
$supplier
[
'supplier_name'
],
$supplier
[
'channel_username'
],
];
$csvData
[]
=
$item
;
}
$header
=
[
'供应商编码'
,
'供应商名称'
,
'采购员'
,
];
exportCsv
(
$csvData
,
'导出供应商列表'
,
$header
);
}
}
}
\ No newline at end of file
app/Http/function.php
View file @
daec97eb
...
@@ -253,3 +253,28 @@ function isDateTime($dateTime){
...
@@ -253,3 +253,28 @@ function isDateTime($dateTime){
return
$ret
!==
FALSE
&&
$ret
!=
-
1
;
return
$ret
!==
FALSE
&&
$ret
!=
-
1
;
}
}
function
fputcsv2
(
$handle
,
array
$fields
,
$delimiter
=
","
,
$enclosure
=
'"'
,
$escape_char
=
"
\\
"
)
{
foreach
(
$fields
as
$k
=>
$v
)
{
$fields
[
$k
]
=
iconv
(
"UTF-8"
,
"GB2312//IGNORE"
,
$v
);
// 这里将UTF-8转为GB2312编码
}
fputcsv
(
$handle
,
$fields
,
$delimiter
,
$enclosure
,
$escape_char
);
}
//导出csv
function
exportCsv
(
$data
,
$filename
,
$column
)
{
header
(
'Content-Description: File Transfer'
);
header
(
'Content-Type: application/vnd.ms-excel'
);
header
(
'Content-Disposition: attachment; filename="'
.
$filename
.
'.csv"'
);
header
(
'Expires: 0'
);
header
(
'Cache-Control: must-revalidate'
);
header
(
'Pragma: public'
);
$file
=
fopen
(
'php://output'
,
'w'
);
fputcsv2
(
$file
,
$column
);
foreach
(
$data
as
$row
)
{
fputcsv2
(
$file
,
$row
);
}
exit
();
}
resources/views/script/SupplierListScript.blade.php
View file @
daec97eb
...
@@ -675,8 +675,18 @@
...
@@ -675,8 +675,18 @@
});
});
}
}
let
formValue
=
{};
$
(
'#export_supplier'
).
click
(
function
()
{
initCondition
.
source_type
=
whereCondition
.
source_type
;
whereCondition
=
$
.
extend
(
false
,
initCondition
,
formValue
);
whereCondition
=
JSON
.
stringify
(
whereCondition
);
window
.
open
(
'/api/supplier/exportSupplier?params='
+
whereCondition
,
'_blank'
);
});
//点击查询按钮
//点击查询按钮
form
.
on
(
'submit(load)'
,
function
(
data
)
{
form
.
on
(
'submit(load)'
,
function
(
data
)
{
formValue
=
data
.
field
;
//罗盘选项会跳回全部
//罗盘选项会跳回全部
clearTypeFilter
();
clearTypeFilter
();
$
(
'#total'
).
attr
(
'class'
,
'main_filter layui-badge layui-bg-green'
);
$
(
'#total'
).
attr
(
'class'
,
'main_filter layui-badge layui-bg-green'
);
...
...
resources/views/web/SupplierList.blade.php
View file @
daec97eb
...
@@ -65,6 +65,9 @@
...
@@ -65,6 +65,9 @@
@if(checkPerm('BatchAllocateYunxinChannelUser'))
@if(checkPerm('BatchAllocateYunxinChannelUser'))
<button type="
button
" class="
layui
-
btn
layui
-
btn
-
sm
" id="
batch_allocate_yunxin_channel_user
">设置SKU采购</button>
<button type="
button
" class="
layui
-
btn
layui
-
btn
-
sm
" id="
batch_allocate_yunxin_channel_user
">设置SKU采购</button>
@endif
@endif
@if(checkPerm('ExportSupplier'))
<button type="
button
" class="
layui
-
btn
layui
-
btn
-
sm
" id="
export_supplier
">导出供应商</button>
@endif
</div>
</div>
<button type="
button
" id="
refreshWindow
" style="
display
:
none
">刷新页面</button>
<button type="
button
" id="
refreshWindow
" style="
display
:
none
">刷新页面</button>
<table class="
layui
-
table
" id="
list
" lay-filter="
list
"></table>
<table class="
layui
-
table
" id="
list
" lay-filter="
list
"></table>
...
...
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