|
@@ -73,6 +73,7 @@ class ExportFileService extends Service
|
|
|
const type_seven = 7;
|
|
|
const type_eight = 8;
|
|
|
const type_nine = 9;
|
|
|
+ const type_ten = 10;
|
|
|
|
|
|
//导出文件方法
|
|
|
protected static $fuc = [
|
|
@@ -85,6 +86,7 @@ class ExportFileService extends Service
|
|
|
self::type_seven => 'seven',
|
|
|
self::type_eight => 'eight',
|
|
|
self::type_nine => 'nine',
|
|
|
+ self::type_ten => 'ten',
|
|
|
];
|
|
|
|
|
|
protected static $fuc_name = [
|
|
@@ -97,6 +99,7 @@ class ExportFileService extends Service
|
|
|
self::type_seven => '发货单',
|
|
|
self::type_eight => '进销存报表',
|
|
|
self::type_nine => '虚拟采购单',
|
|
|
+ self::type_ten => '客户',
|
|
|
];
|
|
|
|
|
|
public static $filename = "";
|
|
@@ -1302,10 +1305,83 @@ class ExportFileService extends Service
|
|
|
return $this->saveExportData($return,$header);
|
|
|
}
|
|
|
|
|
|
+ public function ten($ergs,$user){
|
|
|
+ $id = $ergs['id'];
|
|
|
+
|
|
|
+ // 导出数据
|
|
|
+ $return = [];
|
|
|
+
|
|
|
+ DB::table('customer')
|
|
|
+ ->whereIn('id', $id)
|
|
|
+ ->select('title','id','model_type','customer_intention','customer_from','customer_type','car_type','consulting_product','intention_product','progress_stage','address1','address2','crt_id','crt_time','mark','importance','company','company_short_name','depart_id','state_type','customer_state','pond_state','top_depart_id','fp_time','fp_top_depart_id')
|
|
|
+ ->orderBy('id','desc')
|
|
|
+ ->chunk(200,function ($data) use(&$return,$user){
|
|
|
+ $data = Collect($data)->map(function ($object) {
|
|
|
+ return (array)$object;
|
|
|
+ })->toArray();
|
|
|
+ $list['data'] = $data;
|
|
|
+
|
|
|
+ //订单数据
|
|
|
+ $service = new CustomerService();
|
|
|
+ $list = $service->fillData($list,$user);
|
|
|
+
|
|
|
+ foreach ($list['data'] as $value){
|
|
|
+ $fz = $value['fz'];
|
|
|
+ if(is_array($value['fz'])) $fz = implode(',',$value['fz']);
|
|
|
+
|
|
|
+ $return[] = [
|
|
|
+ 'type' => Customer::dk2[$value['model_type']] ?? "",
|
|
|
+ 'title' => $value['title'] ?? "",
|
|
|
+ 'customer_detail2' => $value['customer_detail2'] ?? "",
|
|
|
+ 'fz' => $fz,
|
|
|
+ 'customer_intention_title' => $value['customer_intention_title'] ?? "",
|
|
|
+ 'customer_from_title' => $value['customer_from_title'] ?? "",
|
|
|
+ 'customer_type_title' => $value['customer_type_title'] ?? "",
|
|
|
+ 'intention_product_title' => $value['intention_product_title'] ?? "",
|
|
|
+ 'consulting_product' => $value['consulting_product'] ?? "",
|
|
|
+ 'car_type_title' => $value['car_type_title'] ?? "",
|
|
|
+ 'progress_stage_title' => $value['progress_stage_title'] ?? "",
|
|
|
+ 'address' => $value['address'] ?? "",
|
|
|
+ 'mark' => $value['mark'] ?? "",
|
|
|
+ 'crt_time' => $value['crt_time'] ?? "",
|
|
|
+ 'crt_name' => $value['crt_name'] ?? "",
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 释放不再需要的变量
|
|
|
+ unset($data, $list);
|
|
|
+ gc_collect_cycles();
|
|
|
+ });
|
|
|
+
|
|
|
+ $header = ['客户模板','客户名称','联系方式','负责人','客户意向度','客户来源','客户类别','意向产品','咨询产品','车型','进展阶段','地址','特殊备注','创建时间','创建人'];
|
|
|
+
|
|
|
+ return $this->saveExportData($return,$header);
|
|
|
+ }
|
|
|
+
|
|
|
public function saveExportData($data, $headers, $type = 'default',$file_name = ''){
|
|
|
if(empty($file_name)) $file_name = self::$filename . "_". date("Y-m-d") . "_". rand(1000,9999);
|
|
|
$filename = $file_name . '.' . 'xlsx';
|
|
|
$bool = Excel::store(new ExportOrder($data,$type,$headers),"/public/export/{$filename}", null, 'Xlsx', []);
|
|
|
return $filename;
|
|
|
}
|
|
|
+
|
|
|
+ public function saveExportData2($data, $headers, $type = 'default', $file_name = '') {
|
|
|
+ if (empty($file_name)) {
|
|
|
+ $file_name = self::$filename . "_" . date("Y-m-d") . "_" . rand(1000, 9999);
|
|
|
+ }
|
|
|
+ $filename = $file_name . '.xlsx';
|
|
|
+
|
|
|
+ // 使用流式写入
|
|
|
+ $writer = new \Maatwebsite\Excel\Writers\LaravelExcelWriter();
|
|
|
+ $writer->download($filename, function ($excel) use ($data, $headers) {
|
|
|
+ $excel->setTitle('Export Data');
|
|
|
+ $excel->setCreator('Your Name')->setCompany('Your Company');
|
|
|
+ $excel->sheet('Sheet1', function ($sheet) use ($data, $headers) {
|
|
|
+ $sheet->fromArray($data, null, 'A1', true, false);
|
|
|
+ $sheet->prependRow(1, $headers);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ return $filename;
|
|
|
+ }
|
|
|
}
|