Commit 6cbd7e3e by mushishixian

数据导出

parent 1abb4c8c
...@@ -25,4 +25,53 @@ class DataService ...@@ -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
...@@ -40,3 +40,7 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () { ...@@ -40,3 +40,7 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () {
Route::match(['get', 'post'], '/api/supplier_receipt/{key}', 'SupplierReceiptApiController@Entrance'); Route::match(['get', 'post'], '/api/supplier_receipt/{key}', 'SupplierReceiptApiController@Entrance');
Route::match(['get', 'post'], '/api/supplier_sync_log/{key}', 'SupplierSyncLogApiController@Entrance'); Route::match(['get', 'post'], '/api/supplier_sync_log/{key}', 'SupplierSyncLogApiController@Entrance');
}); });
Route::match(['get', 'post'], '/test', function () {
$service = new \App\Http\Services\DataService();
$service->exportNotValidChannelUid();
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment