Commit daec97eb by 杨树贤

供应商导出功能,简易版

parent 447f0a75
......@@ -723,4 +723,13 @@ class SupplierApiController extends Controller
$this->response(-1, '没有全部采购员离职的供应商');
}
//导出供应商
public function exportSupplier($request)
{
$params = $request->input('params');
$params = json_decode($params, true);
(new SupplierService())->exportSupplier($params);
exit;
}
}
......@@ -27,11 +27,16 @@ class SupplierService
$filter = new SupplierFilter();
$query = $filter->listFilter($map, $query);
$limit = array_get($map, 'limit', 10);
if (!empty($map['is_export'])) {
$list = $query->get()->toArray();
} else {
$list = $query->paginate($limit)->toArray();
$transformer = new SupplierTransformer();
$list['data'] = $transformer->transformList($list['data']);
//这里还要单独去处理采购员是否离职的显示,考虑到性能,所以再单独搞个方法出来了
$list['data'] = $transformer->transformResignChannelUser($list['data']);
}
return $list;
}
......@@ -686,4 +691,30 @@ class SupplierService
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
......@@ -253,3 +253,28 @@ function isDateTime($dateTime){
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();
}
......@@ -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) {
formValue = data.field;
//罗盘选项会跳回全部
clearTypeFilter();
$('#total').attr('class', 'main_filter layui-badge layui-bg-green');
......
......@@ -65,6 +65,9 @@
@if(checkPerm('BatchAllocateYunxinChannelUser'))
<button type="button" class="layui-btn layui-btn-sm" id="batch_allocate_yunxin_channel_user">设置SKU采购</button>
@endif
@if(checkPerm('ExportSupplier'))
<button type="button" class="layui-btn layui-btn-sm" id="export_supplier">导出供应商</button>
@endif
</div>
<button type="button" id="refreshWindow" style="display: none">刷新页面</button>
<table class="layui-table" id="list" lay-filter="list"></table>
......
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