视图的sql语句
(SELECT `danger_task`.`id`,`danger_task`.`uid`,`danger_task`.`uid_subs`,`danger_task`.`period`,`danger_task`.`equipment_id`,`danger_task`.`danger_id`,`danger_task`.`is_other`,`danger_task`.`infos`,`danger_task`.`status`,`danger_task`.`edit_info`,`danger_task`.`end_at`,`danger_task`.`created_at`,`danger_task`.`updated_at`,`danger_task`.`deleted_at`,`danger_task`.`is_transfering`,`danger_task`.`complete_task_id`,`danger_task`.`is_timeout_remind`,`danger_task`.`redundancy` as user_id,`danger_task`.`redundancy` as danger_main_id,`danger_task`.`redundancy` as danger_level,`danger_task`.`redundancy` as danger_cates_id,`danger_task`.`redundancy` as danger_cates_subs_id,`danger_task`.`redundancy` as report_time,`danger_task`.`redundancy` as deadline,`danger_task`.`redundancy` as add_type,`danger_task`.`redundancy` as government_id,`danger_task`.`redundancy` as government_user_id,`danger_task`.`redundancy` as branch_id,`danger_task`.`redundancy` as responsible_user_id,`danger_task`.`redundancy` as measures,`danger_task`.`redundancy` as end_time,`danger_task`.`redundancy` as suggestions,`danger_task`.`redundancy` as funds,`danger_task`.`redundancy` as finish_time,`danger_task`.`redundancy` as measures_desc,`danger_task`.`redundancy` as check_type,`danger_task`.`redundancy` as check_user,`danger_task`.`redundancy` as danger_main_rectifications_id,`danger_task`.`redundancy` as accepter_id,`danger_task`.`redundancy` as remark
FROM `danger_task`)
UNION
(SELECT `danger_main_checks`.`id`,`danger_main_checks`.`user_id`,`danger_main_checks`.`danger_main_id`,`danger_main_checks`.`danger_level`,`danger_main_checks`.`danger_cates_id`,`danger_main_checks`.`danger_cates_subs_id`,`danger_main_checks`.`status`,`danger_main_checks`.`report_time`,`danger_main_checks`.`created_at`,`danger_main_checks`.`updated_at`,`danger_main_checks`.`deleted_at`,`danger_main_checks`.`is_transfering`,`danger_main_checks`.`is_timeout_remind`,`danger_main_checks`.`deadline`,`danger_main_checks`.`add_type`,`danger_main_checks`.`government_id`,`danger_main_checks`.`government_user_id`,`danger_main_checks`.`redundancy` as uid,`danger_main_checks`.`redundancy` as uid_subs,`danger_main_checks`.`redundancy` as period,`danger_main_checks`.`redundancy` as equipment_id,`danger_main_checks`.`redundancy` as danger_id,`danger_main_checks`.`redundancy` as is_other,`danger_main_checks`.`redundancy` as infos,`danger_main_checks`.`redundancy` as edit_info,`danger_main_checks`.`redundancy` as end_at,`danger_main_checks`.`redundancy` as complete_task_id,`danger_main_checks`.`redundancy` as branch_id,`danger_main_checks`.`redundancy` as responsible_user_id,`danger_main_checks`.`redundancy` as measures,`danger_main_checks`.`redundancy` as end_time,`danger_main_checks`.`redundancy` as suggestions,`danger_main_checks`.`redundancy` as funds,`danger_main_checks`.`redundancy` as finish_time,`danger_main_checks`.`redundancy` as measures_desc,`danger_main_checks`.`redundancy` as check_type,`danger_main_checks`.`redundancy` as check_user,`danger_main_checks`.`redundancy` as danger_main_rectifications_id,`danger_main_checks`.`redundancy` as accepter_id,`danger_main_checks`.`redundancy` as remark
FROM `danger_main_checks`)
UNION
(SELECT `danger_main_rectifications`.`id`,`danger_main_rectifications`.`danger_main_id`,`danger_main_rectifications`.`branch_id`,`danger_main_rectifications`.`responsible_user_id`,`danger_main_rectifications`.`measures`,`danger_main_rectifications`.`end_time`,`danger_main_rectifications`.`suggestions`,`danger_main_rectifications`.`funds`,`danger_main_rectifications`.`finish_time`,`danger_main_rectifications`.`measures_desc`,`danger_main_rectifications`.`infos`,`danger_main_rectifications`.`status`,`danger_main_rectifications`.`created_at`,`danger_main_rectifications`.`updated_at`,`danger_main_rectifications`.`deleted_at`,`danger_main_rectifications`.`is_transfering`,`danger_main_rectifications`.`is_timeout_remind`,`danger_main_rectifications`.`check_type`,`danger_main_rectifications`.`check_user`,`danger_main_rectifications`.`redundancy` as uid,`danger_main_rectifications`.`redundancy` as uid_subs,`danger_main_rectifications`.`redundancy` as period,`danger_main_rectifications`.`redundancy` as equipment_id,`danger_main_rectifications`.`redundancy` as danger_id,`danger_main_rectifications`.`redundancy` as is_other,`danger_main_rectifications`.`redundancy` as edit_info,`danger_main_rectifications`.`redundancy` as end_at,`danger_main_rectifications`.`redundancy` as complete_task_id,`danger_main_rectifications`.`redundancy` as user_id,`danger_main_rectifications`.`redundancy` as danger_level,`danger_main_rectifications`.`redundancy` as danger_cates_id,`danger_main_rectifications`.`redundancy` as danger_cates_subs_id,`danger_main_rectifications`.`redundancy` as report_time,`danger_main_rectifications`.`redundancy` as deadline,`danger_main_rectifications`.`redundancy` as add_type,`danger_main_rectifications`.`redundancy` as government_id,`danger_main_rectifications`.`redundancy` as government_user_id,`danger_main_rectifications`.`redundancy` as danger_main_rectifications_id,`danger_main_rectifications`.`redundancy` as accepter_id,`danger_main_rectifications`.`redundancy` as remark
FROM `danger_main_rectifications`)
UNION
(SELECT `danger_main_rectification_checks`.`id`,`danger_main_rectification_checks`.`danger_main_id`,`danger_main_rectification_checks`.`danger_main_rectifications_id`,`danger_main_rectification_checks`.`accepter_id`,`danger_main_rectification_checks`.`status`,`danger_main_rectification_checks`.`end_time`,`danger_main_rectification_checks`.`remark`,`danger_main_rectification_checks`.`created_at`,`danger_main_rectification_checks`.`updated_at`,`danger_main_rectification_checks`.`deleted_at`,`danger_main_rectification_checks`.`is_transfering`,`danger_main_rectification_checks`.`is_timeout_remind`,`danger_main_rectification_checks`.`deadline`,`danger_main_rectification_checks`.`redundancy` as uid,`danger_main_rectification_checks`.`redundancy` as uid_subs,`danger_main_rectification_checks`.`redundancy` as period,`danger_main_rectification_checks`.`redundancy` as equipment_id,`danger_main_rectification_checks`.`redundancy` as danger_id,`danger_main_rectification_checks`.`redundancy` as is_other,`danger_main_rectification_checks`.`redundancy` as infos,`danger_main_rectification_checks`.`redundancy` as edit_info,`danger_main_rectification_checks`.`redundancy` as end_at,`danger_main_rectification_checks`.`redundancy` as complete_task_id,`danger_main_rectification_checks`.`redundancy` as user_id,`danger_main_rectification_checks`.`redundancy` as danger_level,`danger_main_rectification_checks`.`redundancy` as danger_cates_id,`danger_main_rectification_checks`.`redundancy` as danger_cates_subs_id,`danger_main_rectification_checks`.`redundancy` as report_time,`danger_main_rectification_checks`.`redundancy` as add_type,`danger_main_rectification_checks`.`redundancy` as government_id,`danger_main_rectification_checks`.`redundancy` as government_user_id,`danger_main_rectification_checks`.`redundancy` as branch_id,`danger_main_rectification_checks`.`redundancy` as responsible_user_id,`danger_main_rectification_checks`.`redundancy` as measures,`danger_main_rectification_checks`.`redundancy` as suggestions,`danger_main_rectification_checks`.`redundancy` as funds,`danger_main_rectification_checks`.`redundancy` as finish_time,`danger_main_rectification_checks`.`redundancy` as measures_desc,`danger_main_rectification_checks`.`redundancy` as check_type,`danger_main_rectification_checks`.`redundancy` as check_user
FROM `danger_main_rectification_checks`);
下面是php代码
$arr1 = ['id','uid','uid_subs','period','equipment_id','danger_id','is_other','infos','status','edit_info','end_at','created_at','updated_at','deleted_at','is_transfering','complete_task_id','is_timeout_remind'];
$arr2 = ['id','user_id','danger_main_id','danger_level','danger_cates_id','danger_cates_subs_id','status','report_time','created_at','updated_at','deleted_at','is_transfering','is_timeout_remind','deadline','add_type','government_id','government_user_id'];
$arr3 = ['id','danger_main_id','branch_id','responsible_user_id','measures','end_time','suggestions','funds','finish_time','measures_desc','infos','status','created_at','updated_at','deleted_at','is_transfering','is_timeout_remind','check_type','check_user'];
$arr4 = ['id','danger_main_id','danger_main_rectifications_id','accepter_id','status','end_time','remark','created_at','updated_at','deleted_at','is_transfering','is_timeout_remind','deadline'];
$bingji = array_unique(array_merge($arr1,$arr2,$arr3,$arr4));
$chaji1 = array_diff($bingji,$arr1);
$chaji2 = array_diff($bingji,$arr2);
$chaji3 = array_diff($bingji,$arr3);
$chaji4 = array_diff($bingji,$arr4);
$str1 = '';
foreach ($arr1 as $item) {
$str1 .= "`danger_task`.`$item`,";
}
foreach ($chaji1 as $item) {
$str1 .= "`danger_task`.`redundancy` as $item,";
}
$str2 = '';
foreach ($arr2 as $item) {
$str2 .= "`danger_main_checks`.`$item`,";
}
foreach ($chaji2 as $item) {
$str2 .= "`danger_main_checks`.`redundancy` as $item,";
}
$str3 = '';
foreach ($arr3 as $item) {
$str3 .= "`danger_main_rectifications`.`$item`,";
}
foreach ($chaji3 as $item) {
$str3 .= "`danger_main_rectifications`.`redundancy` as $item,";
}
$str4 = '';
foreach ($arr4 as $item) {
$str4 .= "`danger_main_rectification_checks`.`$item`,";
}
foreach ($chaji4 as $item) {
$str4 .= "`danger_main_rectification_checks`.`redundancy` as $item,";
}
return compact('str1','str2','str3','str4');