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
6cbd7e3e
authored
Apr 29, 2021
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
数据导出
parent
1abb4c8c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
2 deletions
app/Http/Services/DataService.php
app/Http/routes.php
app/Http/Services/DataService.php
View file @
6cbd7e3e
...
...
@@ -25,4 +25,53 @@ class DataService
}
}
}
//导出不合理的采购员的供应商
public
function
exportNotValidChannelUid
()
{
$supplierModel
=
new
SupplierChannelModel
();
$list
=
$supplierModel
->
where
(
'is_type'
,
0
)
->
whereRaw
(
'length(channel_uid) > 5'
)
->
get
();
$result
=
[];
foreach
(
$list
as
$key
=>
$item
)
{
$channelUid
=
explode
(
','
,
$item
[
'channel_uid'
]);
$adminService
=
new
AdminUserService
();
$names
=
[];
foreach
(
$channelUid
as
$codeId
)
{
$user
=
$adminService
->
getAdminUserInfoByCodeId
(
$codeId
);
$name
=
array_get
(
$user
,
'name'
);
$names
[]
=
$name
;
}
$names
=
implode
(
'|'
,
$names
);
$result
[]
=
[
'name'
=>
$item
[
'supplier_name'
],
'value'
=>
$names
];
}
// 需要导出的内容
// 文件名,这里都要将utf-8编码转为gbk,要不可能出现乱码现象
$filename
=
$this
->
utfToGbk
(
'导出csv文件.csv'
);
// 拼接文件信息,这里注意两点
// 1、字段与字段之间用逗号分隔开
// 2、行与行之间需要换行符
$fileData
=
$this
->
utfToGbk
(
'姓名, 采购'
)
.
"
\n
"
;
foreach
(
$result
as
$value
)
{
$temp
=
$value
[
'name'
]
.
','
.
$value
[
'value'
];
$fileData
.=
$this
->
utfToGbk
(
$temp
)
.
"
\n
"
;
}
// 头信息设置
header
(
"Content-type:text/csv"
);
header
(
"Content-Disposition:attachment;filename="
.
$filename
);
header
(
'Cache-Control:must-revalidate,post-check=0,pre-check=0'
);
header
(
'Expires:0'
);
header
(
'Pragma:public'
);
echo
$fileData
;
exit
;
}
function
utfToGbk
(
$data
)
{
return
iconv
(
'utf-8'
,
'GBK'
,
$data
);
}
}
\ No newline at end of file
app/Http/routes.php
View file @
6cbd7e3e
...
...
@@ -39,4 +39,8 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () {
Route
::
match
([
'get'
,
'post'
],
'/api/log/{key}'
,
'LogApiController@Entrance'
);
Route
::
match
([
'get'
,
'post'
],
'/api/supplier_receipt/{key}'
,
'SupplierReceiptApiController@Entrance'
);
Route
::
match
([
'get'
,
'post'
],
'/api/supplier_sync_log/{key}'
,
'SupplierSyncLogApiController@Entrance'
);
});
\ No newline at end of file
});
Route
::
match
([
'get'
,
'post'
],
'/test'
,
function
()
{
$service
=
new
\App\Http\Services\DataService
();
$service
->
exportNotValidChannelUid
();
});
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