123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace App\Service;
- use App\Exports\ExportOrder;
- use App\Exports\MyExport;
- use App\Model\Area;
- use App\Model\BasicMaterial;
- use App\Model\BasicRollFilm;
- use App\Model\BasicType;
- use App\Model\CarDepart;
- use App\Model\CarFiles;
- use App\Model\CarType;
- use App\Model\Company;
- use App\Model\Construction;
- use App\Model\ConstructionInfo;
- use App\Model\ConstructionOrder;
- use App\Model\ConstructionOrderImg;
- use App\Model\ConstructionOrderSub;
- use App\Model\ConstructionProductInfo;
- use App\Model\Employee;
- use App\Model\FoursShop;
- use App\Model\InOutRecord;
- use App\Model\Inventory;
- use App\Model\InventorySub;
- use App\Model\Material;
- use App\Model\MaterialCharge;
- use App\Model\MaterialChargeSub;
- use App\Model\MaterialOrder;
- use App\Model\MaterialOrderApply;
- use App\Model\MaterialOrderIn;
- use App\Model\MaterialOrderSend;
- use App\Model\MaterialOrderSendSub;
- use App\Model\MaterialReturn;
- use App\Model\MaterialReturnSub;
- use App\Model\PaymentReceipt;
- use App\Model\PaymentReceiptInfo;
- use App\Model\PurchaseOrder;
- use App\Model\PurchaseOrderInfo;
- use App\Model\RollFilm;
- use App\Model\RollFilmCombine;
- use App\Model\RollFilmCompany;
- use App\Model\RollFilmInventory;
- use App\Model\SalesOrder;
- use App\Model\SalesOrderOtherFee;
- use App\Model\SalesOrderProductInfo;
- use App\Model\Storehouse;
- use App\Model\Supplier;
- use App\Model\Transfer;
- use App\Model\TransferSub;
- use Illuminate\Support\Facades\DB;
- use Maatwebsite\Excel\Facades\Excel;
- class ExportFileService extends Service
- {
- //导出文件
- const type_one = 1;
- const type_two = 2;
- const type_three = 3;
- const type_four = 4;
- const type_five = 5;
- const type_six = 6;
- const type_seven = 7;
- //导出文件方法
- protected static $fuc = [
- self::type_one => 'kqList',
- self::type_two => '',
- self::type_three => '',
- self::type_four => '',
- self::type_five => '',
- ];
- protected static $fuc_name = [
- self::type_one => '考勤',
- self::type_two => '',
- self::type_three => '',
- self::type_four => '',
- self::type_five => '',
- ];
- public static $filename = "";
- public function exportAll($data,$user){
- if(empty($data['id'])) return [false,'请选择导出数据'];
- if(empty($data['type']) || ! isset(self::$fuc[$data['type']])) return [false,'导出文件类型错误或者不存在'];
- self::$filename = self::$fuc_name[$data['type']] ?? "";
- //不超时
- ini_set('max_execution_time', 0);
- //内存设置
- ini_set('memory_limit', -1);
- $function = self::$fuc[$data['type']];
- $return = $this->$function($data);
- return [true, $return];
- }
- public function kqList($ergs){
- $id = $ergs['id'];
- // 导出数据
- $return = [];
- DB::table('kq_list')
- ->whereIn('id', $id)
- ->select('id','order_number','model_type','sales_order_type','sign_time','plat_order','plat_type','product_total','other_fee','discount_fee','contract_fee','crt_time','crt_id','state','invoice_state','pay_way')
- ->orderBy('id','desc')
- ->chunk(500,function ($data) use(&$return){
- $data = Collect($data)->map(function ($object) {
- return (array)$object;
- })->toArray();
- $list['data'] = $data;
- });
- $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;
- }
- }
|