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
a80e8524
authored
May 14, 2021
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
导出数据
parent
c483e6a1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
4 deletions
app/Http/Services/DataService.php
app/Http/routes.php
app/Http/Services/DataService.php
View file @
a80e8524
...
@@ -4,8 +4,10 @@
...
@@ -4,8 +4,10 @@
namespace
App\Http\Services
;
namespace
App\Http\Services
;
//后台用户相关信息服务
//后台用户相关信息服务
use
App\Http\Transformers\SupplierTransformer
;
use
App\Model\BrandModel
;
use
App\Model\BrandModel
;
use
App\Model\IntracodeModel
;
use
App\Model\IntracodeModel
;
use
App\Model\RedisModel
;
use
App\Model\SupplierChannelModel
;
use
App\Model\SupplierChannelModel
;
use
App\Model\SupplierContactModel
;
use
App\Model\SupplierContactModel
;
use
App\Model\UserInfoModel
;
use
App\Model\UserInfoModel
;
...
@@ -185,9 +187,91 @@ class DataService
...
@@ -185,9 +187,91 @@ class DataService
// return iconv('utf-8', 'GBK', $data);
// return iconv('utf-8', 'GBK', $data);
// }
// }
public
function
test
()
//供应商导出给业务整理,还要带有是否有上架sku数量的标识
public
function
exportSuppliers
()
{
{
$model
=
new
BrandModel
();
$model
=
new
SupplierChannelModel
();
dd
(
DB
::
connection
(
'spu'
)
->
table
(
'brand'
)
->
count
());
$suppliers
=
$model
->
where
(
'is_type'
,
0
)
->
get
();
if
(
empty
(
$suppliers
))
{
return
'供应商空'
;
}
$redis
=
new
RedisModel
();
foreach
(
$suppliers
as
$supplier
)
{
if
(
$redis
->
hget
(
'supplier_data_service'
,
$supplier
[
'supplier_id'
]))
{
continue
;
}
var_dump
(
$supplier
[
'supplier_id'
]);
//先判断是否有sku
$url
=
env
(
'ES_SKU_URL'
,
''
);
$map
[
'canal/condition'
]
=
$supplier
[
'supplier_code'
];
$return
=
curl
(
$url
,
$map
,
1
);
$data
=
json_decode
(
$return
,
true
);
if
(
!
empty
(
$data
[
'data'
][
'total'
]))
{
$total
=
$data
[
'data'
][
'total'
];
}
else
{
$redis
->
hset
(
'supplier_data_service'
,
$supplier
[
'supplier_id'
],
'1'
);
continue
;
}
$service
=
new
AdminUserService
();
$intracodeModel
=
new
IntracodeModel
();
$userCodes
=
$intracodeModel
->
getSampleEncode
();
$channelUids
=
explode
(
','
,
$supplier
[
'channel_uid'
]);
$channelUids
=
array_filter
(
$channelUids
,
function
(
$codeId
)
{
return
!
empty
(
$codeId
);
});
$channelNames
=
array_map
(
function
(
$codeId
)
use
(
$userCodes
)
{
return
array_get
(
$userCodes
,
$codeId
,
''
);
},
$channelUids
);
$channelNames
=
implode
(
'|'
,
$channelNames
);
$userInfo
=
$service
->
getAdminUserInfoByCodeId
(
$supplier
[
'purchase_uid'
]);
$purchaseName
=
$userInfo
[
'name'
]
?:
''
;
$redis
->
hset
(
'supplier_data_service'
,
$supplier
[
'supplier_id'
],
json_encode
([
$supplier
[
'supplier_code'
],
'"'
.
$supplier
[
'supplier_name'
]
.
'"'
,
$channelNames
,
$purchaseName
,
!
empty
(
$supplier
[
'create_time'
])
?
'"'
.
date
(
'Y-m-d H:i:s'
,
$supplier
[
'create_time'
])
.
'"'
:
''
,
$total
]));
}
}
function
export
()
{
$redis
=
new
RedisModel
();
$exportData
=
$redis
->
hgetall
(
'supplier_data_service'
);
$exportData
=
array_filter
(
$exportData
,
function
(
$data
)
{
return
$data
!=
1
;
});
$exportData
=
array_map
(
function
(
$data
)
{
return
json_decode
(
$data
);
},
$exportData
);
// 文件名,这里都要将utf-8编码转为gbk,要不可能出现乱码现象
$filename
=
$this
->
utfToGbk
(
'导出csv文件.csv'
);
// 拼接文件信息,这里注意两点
// 1、字段与字段之间用逗号分隔开
// 2、行与行之间需要换行符
$fileData
=
$this
->
utfToGbk
(
'供应商编码,供应商名称,采购员名称,渠道开发员,创建时间,sku数量'
)
.
"
\n
"
;
foreach
(
$exportData
as
$value
)
{
$temp
=
$value
[
0
]
.
','
.
$value
[
1
]
.
','
.
$value
[
2
]
.
','
.
$value
[
3
]
.
','
.
$value
[
4
]
.
','
.
$value
[
5
];
$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 @
a80e8524
...
@@ -44,7 +44,8 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () {
...
@@ -44,7 +44,8 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () {
});
});
Route
::
match
([
'get'
,
'post'
],
'/test'
,
function
()
{
Route
::
match
([
'get'
,
'post'
],
'/test'
,
function
()
{
$service
=
new
\App\Http\Services\DataService
();
$service
=
new
\App\Http\Services\DataService
();
$service
->
test
();
$service
->
exportSuppliers
();
// $service->export();
// $service->repairData(10);
// $service->repairData(10);
// $service->completeContact(10);
// $service->completeContact(10);
});
});
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