PHP教程

PHP自定义导出

本文主要是介绍PHP自定义导出,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 field参数是逗号隔开传过来的

$params   = request()->param();
		$info = array('name'=>'*姓名','card_no'=>'*身份证号','company'=>'*单位','duties'=>'*职务','guest_source'=>'*嘉宾来源','guests_type'=>'嘉宾类型','sex'=>'*性别(男/女)','nation'=>'*民族(汉族)','phone'=>'*联系电话','is_driver'=>'*是否自驾','public_transport'=>'*公共交通工具','train_number'=>'*抵达车次/航班','train_time'=>'*抵达时间(年-月-日 时:分:秒)','is_station'=>'*是否接站(是/否)','station_address'=>'*接站地点','special_request'=>'特殊要求','invite_soucre'=>'邀请来源','is_check_status'=>'*签到状态','check_address'=>'签到地点','check_mode'=>'签到方式','hotel_name'=>'住宿酒店','type'=>'房间类型','room_number'=>'房间号','observation_group'=>'观摩组','vehicle_number'=>'观摩分车','restaurant_name'=>'用餐场地','table'=>'用餐桌号','username'=>'一对一接待员','remarks'=>'备注');
		$field = \explode(',',$params['field']);
		foreach($field as $key => $value){
			$res[$key+1] = $info[$value];
		}
		$header = ['序号']+$res;
		$data = ReceiptGuestModel::receiptGuestExport($params);
		
		foreach($data as $key => $value){
			switch ($value['sex'])
			{
				case 1:
					$data[$key]['sex'] = '男';
					break;
				case 2:
					$data[$key]['send_mode'] = '女';
					break;
			}
			switch ($value['is_driver'])
			{
				case 1:
					$data[$key]['is_driver'] = '是';
					break;
				case 2:
					$data[$key]['is_driver'] = '否';
					break;
			}
			switch ($value['is_station'])
			{
				case 1:
					$data[$key]['is_station'] = '是';
					break;
				case 2:
					$data[$key]['is_station'] = '否';
					break;
			}
			switch ($value['is_check_status'])
			{
				case 1:
					$data[$key]['is_check_status'] = '已签到';
					break;
				case 2:
					$data[$key]['is_check_status'] = '未签到';
					break;
			}
			switch ($value['check_mode'])
			{
				case 0:
					$data[$key]['check_mode'] = '';
					break;
				case 1:
					$data[$key]['check_mode'] = '手机号';
					break;
				case 2:
					$data[$key]['check_mode'] = '二维码';
					break;
				case 3:
					$data[$key]['check_mode'] = '后台';
					break;
				case 4:
					$data[$key]['check_mode'] = '闸机';
					break;
			}
		}
		foreach($data as $key => $value){
			$record = [];
			$record['xuhao'] = $key+1;
			foreach($field as $k => $v){
				$record[$v] = $value[$v];
			}
			$body[] = $record;
		}

这篇关于PHP自定义导出的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!