<?php

namespace Home\Controller;

use Think\Controller;

class ArchivesController extends ComController
{
    //现场档案
    public function addArchives(){
        $Data = I('');
        if (!isset($Data['account_number']) || !isset($Data['rheological_change']) || !isset($Data['power_capacity'])
            || !isset($Data['site_id'])|| !isset($Data['route_id'])|| !isset($Data['supervision_department_id'])
            || !isset($Data['cable_hole'])|| !isset($Data['damage'])|| !isset($Data['water_leakage'])
            || !isset($Data['annihilator_insufficient_configuration'])|| !isset($Data['annihilator_overdue'])|| !isset($Data['pile_up_sundries'])
            || !isset($Data['serious_ash_deposition'])|| !isset($Data['around_environment_humid'])|| !isset($Data['around_pile_up_sundries'])
            || !isset($Data['no_electrician'])|| !isset($Data['electrician_lack'])|| !isset($Data['overdue_electrician_certificate'])
            || !isset($Data['electric_test_overdue'])|| !isset($Data['blanket_insufficient_configuration'])
            || !isset($Data['ground_wire'])|| !isset($Data['analog_screen'])) {
            $res['msg'] = '操作失败，缺少重要参数';
            $res['flag'] = false;
            echo json_encode($res);
            exit();
        }

        if (!empty($Data['door_baffle_describe'])){
            $data['door_baffle_describe'] = $Data['door_baffle_describe'];
        }
        if (!empty($Data['charged_display_describe'])){
            $data['charged_display_describe'] = $Data['charged_display_describe'];
        }
        if (!empty($Data['lighting_describe'])){
            $data['lighting_describe'] = $Data['lighting_describe'];
        }

        if (!empty($Data['door_baffle_picture'])){
            $data['door_baffle_picture'] = $Data['door_baffle_picture'];
        }
        if (!empty($Data['charged_display_picture'])){
            $data['charged_display_picture'] = $Data['charged_display_picture'];
        }
        if (!empty($Data['lighting_picture'])){
            $data['lighting_picture'] = $Data['lighting_picture'];
        }

        if (!empty($Data['cable_hole_describe'])){
            $data['cable_hole_describe'] = $Data['cable_hole_describe'];
        }
//        unset($Data['cable_hole_describe']);
        if (!empty($Data['cable_hole_picture'])){
            $data['cable_hole_picture'] = $Data['cable_hole_picture'];
        }
//        unset($Data['cable_hole_picture']);
        if (!empty($Data['damage_describe'])){
            $data['damage_describe'] = $Data['damage_describe'];
        }
//        unset($Data['damage_describe']);
        if (!empty($Data['damage_picture'])){
            $data['damage_picture'] = $Data['damage_picture'];
        }
//        unset($Data['damage_picture']);
        if (!empty($Data['water_leakage_describe'])){
            $data['water_leakage_describe'] = $Data['water_leakage_describe'];
        }
//        unset($Data['water_leakage_describe']);
        if (!empty($Data['water_leakage_picture'])){
            $data['water_leakage_picture'] = $Data['water_leakage_picture'];
        }
//        unset($Data['water_leakage_picture']);
        if (!empty($Data['annihilator_insufficient_configuration_describe'])){
            $data['annihilator_insufficient_configuration_describe'] = $Data['annihilator_insufficient_configuration_describe'];
        }
//        unset($Data['annihilator_insufficient_configuration_describe']);
        if (!empty($Data['annihilator_insufficient_configuration_picture'])){
            $data['annihilator_insufficient_configuration_picture'] = $Data['annihilator_insufficient_configuration_picture'];
        }
//        unset($Data['annihilator_insufficient_configuration_picture']);
        if (!empty($Data['annihilator_overdue_describe'])){
            $data['annihilator_overdue_describe'] = $Data['annihilator_overdue_describe'];
        }
//        unset($Data['annihilator_overdue_describe']);
        if (!empty($Data['annihilator_overdue_picture'])){
            $data['annihilator_overdue_picture'] = $Data['annihilator_overdue_picture'];
        }
//        unset($Data['annihilator_overdue_picture']);
        if (!empty($Data['pile_up_sundries_describe'])){
            $data['pile_up_sundries_describe'] = $Data['pile_up_sundries_describe'];
        }
//        unset($Data['pile_up_sundries_describe']);
        if (!empty($Data['pile_up_sundries_picture'])){
            $data['pile_up_sundries_picture'] = $Data['pile_up_sundries_picture'];
        }
//        unset($Data['pile_up_sundries_picture']);
        if (!empty($Data['serious_ash_deposition_describe'])){
            $data['serious_ash_deposition_describe'] = $Data['serious_ash_deposition_describe'];
        }
//        unset($Data['serious_ash_deposition_describe']);
        if (!empty($Data['serious_ash_deposition_picture'])){
            $data['serious_ash_deposition_picture'] = $Data['serious_ash_deposition_picture'];
        }
//        unset($Data['serious_ash_deposition_picture']);
        if (!empty($Data['around_environment_humid_describe'])){
            $data['around_environment_humid_describe'] = $Data['around_environment_humid_describe'];
        }
//        unset($Data['around_environment_humid_describe']);
        if (!empty($Data['around_environment_humid_picture'])){
            $data['around_environment_humid_picture'] = $Data['around_environment_humid_picture'];
        }
//        unset($Data['around_environment_humid_picture']);
        if (!empty($Data['around_pile_up_sundries_describe'])){
            $data['around_pile_up_sundries_describe'] = $Data['around_pile_up_sundries_describe'];
        }
//        unset($Data['around_pile_up_sundries_describe']);
        if (!empty($Data['around_pile_up_sundries_picture'])){
            $data['around_pile_up_sundries_picture'] = $Data['around_pile_up_sundries_picture'];
        }
//        unset($Data['around_pile_up_sundries_picture']);
        if (!empty($Data['no_electrician_describe'])){
            $data['no_electrician_describe'] = $Data['no_electrician_describe'];
        }
//        unset($Data['no_electrician_describe']);
        if (!empty($Data['no_electrician_picture'])){
            $data['no_electrician_picture'] = $Data['no_electrician_picture'];
        }
//        unset($Data['no_electrician_picture']);
        if (!empty($Data['electrician_lack_describe'])){
            $data['electrician_lack_describe'] = $Data['electrician_lack_describe'];
        }
//        unset($Data['electrician_lack_describe']);
        if (!empty($Data['electrician_lack_picture'])){
            $data['electrician_lack_picture'] = $Data['electrician_lack_picture'];
        }
//        unset($Data['electrician_lack_picture']);
        if (!empty($Data['overdue_electrician_certificate_describe'])){
            $data['overdue_electrician_certificate_describe'] = $Data['overdue_electrician_certificate_describe'];
        }
//        unset($Data['overdue_electrician_certificate_describe']);
        if (!empty($Data['overdue_electrician_certificate_picture'])){
            $data['overdue_electrician_certificate_picture'] = $Data['overdue_electrician_certificate_picture'];
        }
//        unset($Data['overdue_electrician_certificate_picture']);
        if (!empty($Data['blanket_insufficient_configuration_describe'])){
            $data['blanket_insufficient_configuration_describe'] = $Data['blanket_insufficient_configuration_describe'];
        }
//        unset($Data['blanket_insufficient_configuration_describe']);
        if (!empty($Data['blanket_insufficient_configuration_picture'])){
            $data['blanket_insufficient_configuration_picture'] = $Data['blanket_insufficient_configuration_picture'];
        }
//        unset($Data['blanket_insufficient_configuration_picture']);
        if (!empty($Data['ground_wire_describe'])){
            $data['ground_wire_describe'] = $Data['ground_wire_describe'];
        }
//        unset($Data['ground_wire_describe']);
        if (!empty($Data['ground_wire_picture'])){
            $data['ground_wire_picture'] = $Data['ground_wire_picture'];
        }
//        unset($Data['ground_wire_picture']);
        if (!empty($Data['analog_screen_describe'])){
            $data['analog_screen_describe'] = $Data['analog_screen_describe'];
        }
//        unset($Data['analog_screen_describe']);
        if (!empty($Data['analog_screen_picture'])){
            $data['analog_screen_picture'] = $Data['analog_screen_picture'];
        }

//        unset($Data['analog_screen_picture']);
        $data_R=M()->query("select * from sitedtl where site_id = ".$Data['site_id']);
        if (!empty($data_R)){
            $res['msg'] = '操作失败，该站点已有现场档案';
            $res['flag'] = false;
            echo json_encode($res);
            exit();
        }
        $Data['creator']=$_SESSION['phone'];
        $Data['create_time']=date('Y-m-d H:i:s', time());
        $R = M("sitedtl")->add($Data);
        if ($R) {
            $where['sitedtl_id']=$R;
            $Res=M("site_archives")->where($where)->select();
            if (!empty($Res)){
                $R1 = M("site_archives")->where($where)->save($data);
            }else{
                $data['sitedtl_id'] = $R;
                $R1 = M("site_archives")->add($data);
            }

            if ($R1){
                $res['msg'] = '操作成功';
                $res['flag'] = true;
                echo json_encode($res);
            }else{
                $res['msg'] = '操作失败';
                $res['flag'] = false;
                echo json_encode($res);
            }
        } else {
            $res['msg'] = '操作失败';
            $res['flag'] = false;
            echo json_encode($res);
        }
    }

    public function setArchives(){
        $Data = I('');

        if ($_SESSION['permissionLabel'] !=1&&$_SESSION['permissionLabel'] !=2&&$_SESSION['permissionLabel'] !=4){
            $res['msg'] = '权限不足，无法进行操作';
            $res['flag'] = false;
            echo json_encode($res);
            exit();
        }

        if (!isset($Data['id'])) {
            $res['msg'] = '操作失败，缺少重要参数';
            $res['flag'] = false;
            echo json_encode($res);
            exit();
        }
        $where['id'] = $Data['id'];
        $where1['sitedtl_id'] = $Data['id'];
        if (isset($Data['door_baffle'])&&$Data['door_baffle']!='null'){
            $data['door_baffle'] = $Data['door_baffle'];
        }
        if (isset($Data['high_voltage_cabinet'])&&$Data['high_voltage_cabinet']!='null'){
            $data['high_voltage_cabinet'] = $Data['high_voltage_cabinet'];
        }
        if (isset($Data['charged_display'])&&$Data['charged_display']!='null'){
            $data['charged_display'] = $Data['charged_display'];
        }
        if (isset($Data['lighting'])&&$Data['lighting']!='null'){
            $data['lighting'] = $Data['lighting'];
        }
        if ($Data['door_baffle_describe']!='null'&&isset($Data['analog_screen_picture'])){
            $data1['door_baffle_describe'] = $Data['door_baffle_describe'];
        }
        if ($Data['charged_display_describe']!='null'&&isset($Data['analog_screen_picture'])){
            $data1['charged_display_describe'] = $Data['charged_display_describe'];
        }
        if ($Data['lighting_describe']!='null'&&isset($Data['analog_screen_picture'])){
            $data1['lighting_describe'] = $Data['lighting_describe'];
        }
        if ($Data['door_baffle_picture']!='null'&&isset($Data['analog_screen_picture'])){
            $data1['door_baffle_picture'] = $Data['door_baffle_picture'];
        }
        if ($Data['charged_display_picture']!='null'&&isset($Data['analog_screen_picture'])){
            $data1['charged_display_picture'] = $Data['charged_display_picture'];
        }
        if ($Data['lighting_picture']!='null'&&isset($Data['analog_screen_picture'])){
            $data1['lighting_picture'] = $Data['lighting_picture'];
        }

        if (isset($Data['rheological_change'])&&$Data['rheological_change']!='null'){
            $data['rheological_change'] = $Data['rheological_change'];
        }
        if (isset($Data['power_capacity'])&&$Data['power_capacity']!='null'){
            $data['power_capacity'] = $Data['power_capacity'];
        }
        if (isset($Data['route_id'])&&$Data['route_id']!='null'){
            $data['route_id'] = $Data['route_id'];
        }
        if (isset($Data['supervision_department_id'])&&$Data['supervision_department_id']!='null'){
            $data['supervision_department_id'] = $Data['supervision_department_id'];
        }
        if (isset($Data['cable_hole'])&&$Data['cable_hole']!='null'){
            $data['cable_hole'] = $Data['cable_hole'];
        }
        if (isset($Data['damage'])&&$Data['damage']!='null'){
            $data['damage'] = $Data['damage'];
        }
        if (isset($Data['water_leakage'])&&$Data['water_leakage']!='null'){
            $data['water_leakage'] = $Data['water_leakage'];
        }
        if (isset($Data['annihilator_insufficient_configuration'])&&$Data['annihilator_insufficient_configuration']!='null'){
            $data['annihilator_insufficient_configuration'] = $Data['annihilator_insufficient_configuration'];
        }
        if (isset($Data['annihilator_overdue'])&&$Data['annihilator_overdue']!='null'){
            $data['annihilator_overdue'] = $Data['annihilator_overdue'];
        }
        if (isset($Data['pile_up_sundries'])&&$Data['pile_up_sundries']!='null'){
            $data['pile_up_sundries'] = $Data['pile_up_sundries'];
        }
        if (isset($Data['serious_ash_deposition'])&&$Data['serious_ash_deposition']!='null'){
            $data['serious_ash_deposition'] = $Data['serious_ash_deposition'];
        }
        if (isset($Data['around_environment_humid'])&&$Data['around_environment_humid']!='null'){
            $data['around_environment_humid'] = $Data['around_environment_humid'];
        }
        if (isset($Data['around_pile_up_sundries'])&&$Data['around_pile_up_sundries']!='null'){
            $data['around_pile_up_sundries'] = $Data['around_pile_up_sundries'];
        }
        if (isset($Data['no_electrician'])&&$Data['no_electrician']!='null'){
            $data['no_electrician'] = $Data['no_electrician'];
        }
        if (isset($Data['electrician_lack'])&&$Data['electrician_lack']!='null'){
            $data['electrician_lack'] = $Data['electrician_lack'];
        }
        if (isset($Data['overdue_electrician_certificate'])&&$Data['overdue_electrician_certificate']!='null'){
            $data['overdue_electrician_certificate'] = $Data['overdue_electrician_certificate'];
        }
        if (isset($Data['electric_test_overdue'])&&$Data['electric_test_overdue']!='null'){
            $data['electric_test_overdue'] = $Data['electric_test_overdue'];
        }
        if (isset($Data['blanket_insufficient_configuration'])&&$Data['blanket_insufficient_configuration']!='null'){
            $data['blanket_insufficient_configuration'] = $Data['blanket_insufficient_configuration'];
        }
        if (isset($Data['ground_wire'])&&$Data['ground_wire']!='null'){
            $data['ground_wire'] = $Data['ground_wire'];
        }
        if (isset($Data['analog_screen'])&&$Data['analog_screen']!='null'){
            $data['analog_screen'] = $Data['analog_screen'];
        }
        $data['creator']=$_SESSION['phone'];
        $data['create_time']=date('Y-m-d H:i:s', time());

        if (isset($Data['cable_hole_describe'])&&$Data['cable_hole_describe']!='null'){
            $data1['cable_hole_describe'] = $Data['cable_hole_describe'];
        }
        if (isset($Data['cable_hole_picture'])&&$Data['cable_hole_picture']!='null'){
            $data1['cable_hole_picture'] = $Data['cable_hole_picture'];
        }
        if (isset($Data['damage_describe'])&&$Data['damage_describe']!='null'){
            $data1['damage_describe'] = $Data['damage_describe'];
        }
        if (isset($Data['damage_picture'])&&$Data['damage_picture']!='null'){
            $data1['damage_picture'] = $Data['damage_picture'];
        }
        if (isset($Data['water_leakage_describe'])&&$Data['water_leakage_describe']!='null'){
            $data1['water_leakage_describe'] = $Data['water_leakage_describe'];
        }
        if (isset($Data['water_leakage_picture'])&&$Data['water_leakage_picture']!='null'){
            $data1['water_leakage_picture'] = $Data['water_leakage_picture'];
        }
        if (isset($Data['annihilator_insufficient_configuration_describe'])&&$Data['annihilator_insufficient_configuration_describe']!='null'){
            $data1['annihilator_insufficient_configuration_describe'] = $Data['annihilator_insufficient_configuration_describe'];
        }
        if (isset($Data['annihilator_insufficient_configuration_picture'])&&$Data['annihilator_insufficient_configuration_picture']!='null'){
            $data1['annihilator_insufficient_configuration_picture'] = $Data['annihilator_insufficient_configuration_picture'];
        }
        if (isset($Data['annihilator_overdue_describe'])&&$Data['annihilator_overdue_describe']!='null'){
            $data1['annihilator_overdue_describe'] = $Data['annihilator_overdue_describe'];
        }
        if (isset($Data['annihilator_overdue_picture'])&&$Data['annihilator_overdue_picture']!='null'){
            $data1['annihilator_overdue_picture'] = $Data['annihilator_overdue_picture'];
        }
        if (isset($Data['pile_up_sundries_describe'])&&$Data['pile_up_sundries_describe']!='null'){
            $data1['pile_up_sundries_describe'] = $Data['pile_up_sundries_describe'];
        }
        if (isset($Data['pile_up_sundries_picture'])&&$Data['pile_up_sundries_picture']!='null'){
            $data1['pile_up_sundries_picture'] = $Data['pile_up_sundries_picture'];
        }
        if (isset($Data['serious_ash_deposition_describe'])&&$Data['serious_ash_deposition_describe']!='null'){
            $data1['serious_ash_deposition_describe'] = $Data['serious_ash_deposition_describe'];
        }
        if (isset($Data['serious_ash_deposition_picture'])&&$Data['serious_ash_deposition_picture']!='null'){
            $data1['serious_ash_deposition_picture'] = $Data['serious_ash_deposition_picture'];
        }
        if (isset($Data['around_environment_humid_describe'])&&$Data['around_environment_humid_describe']!='null'){
            $data1['around_environment_humid_describe'] = $Data['around_environment_humid_describe'];
        }
        if (isset($Data['around_environment_humid_picture'])&&$Data['around_environment_humid_picture']!='null'){
            $data1['around_environment_humid_picture'] = $Data['around_environment_humid_picture'];
        }
        if (isset($Data['around_pile_up_sundries_describe'])&&$Data['around_pile_up_sundries_describe']!='null'){
            $data1['around_pile_up_sundries_describe'] = $Data['around_pile_up_sundries_describe'];
        }
        if (isset($Data['around_pile_up_sundries_picture'])&&$Data['around_pile_up_sundries_picture']!='null'){
            $data1['around_pile_up_sundries_picture'] = $Data['around_pile_up_sundries_picture'];
        }
        if (isset($Data['no_electrician_describe'])&&$Data['no_electrician_describe']!='null'){
            $data1['no_electrician_describe'] = $Data['no_electrician_describe'];
        }
        if (isset($Data['no_electrician_picture'])&&$Data['no_electrician_picture']!='null'){
            $data1['no_electrician_picture'] = $Data['no_electrician_picture'];
        }
        if (isset($Data['electrician_lack_describe'])&&$Data['electrician_lack_describe']!='null'){
            $data1['electrician_lack_describe'] = $Data['electrician_lack_describe'];
        }
        if (isset($Data['electrician_lack_picture'])&&$Data['electrician_lack_picture']!='null'){
            $data1['electrician_lack_picture'] = $Data['electrician_lack_picture'];
        }
        if (isset($Data['overdue_electrician_certificate_describe'])&&$Data['overdue_electrician_certificate_describe']!='null'){
            $data1['overdue_electrician_certificate_describe'] = $Data['overdue_electrician_certificate_describe'];
        }
        if (isset($Data['overdue_electrician_certificate_picture'])&&$Data['overdue_electrician_certificate_picture']!='null'){
            $data1['overdue_electrician_certificate_picture'] = $Data['overdue_electrician_certificate_picture'];
        }
        if (isset($Data['blanket_insufficient_configuration_describe'])&&$Data['blanket_insufficient_configuration_describe']!='null'){
            $data1['blanket_insufficient_configuration_describe'] = $Data['blanket_insufficient_configuration_describe'];
        }
        if (isset($Data['blanket_insufficient_configuration_picture'])&&$Data['blanket_insufficient_configuration_picture']!='null'){
            $data1['blanket_insufficient_configuration_picture'] = $Data['blanket_insufficient_configuration_picture'];
        }
        if (isset($Data['ground_wire_describe'])&&$Data['ground_wire_describe']!='null'){
            $data1['ground_wire_describe'] = $Data['ground_wire_describe'];
        }
        if (isset($Data['ground_wire_picture'])&&$Data['ground_wire_picture']!='null'){
            $data1['ground_wire_picture'] = $Data['ground_wire_picture'];
        }
        if (isset($Data['analog_screen_describe'])&&$Data['analog_screen_describe']!='null'){
            $data1['analog_screen_describe'] = $Data['analog_screen_describe'];
        }
        if (isset($Data['analog_screen_picture'])&&$Data['analog_screen_picture']!='null'){
            $data1['analog_screen_picture'] = $Data['analog_screen_picture'];
        }

        $R = M("sitedtl")->where($where)->save($data);

        $Res=M("site_archives")->where($where1)->select();
        if (!empty($Res)){
            $R1 = M("site_archives")->where($where1)->save($data1);
        }else{
            $data1['sitedtl_id'] = $Data['id'];
            $R1 = M("site_archives")->add($data1);
        }

        if ($R||$R1) {
            $res['msg'] = '操作成功';
            $res['flag'] = true;
            echo json_encode($res);
        } else {
            $res['msg'] = '操作失败';
            $res['flag'] = false;
            echo json_encode($res);
        }

    }

    public function setSiteArchives(){
        $Data = I('');
        if (!isset($Data['id'])) {
            $res['msg'] = '操作失败，缺少重要参数';
            $res['flag'] = false;
            echo json_encode($res);
            exit();
        }
        $where['sitedtl_id'] = $Data['id'];

        if (!empty($Data['door_baffle_describe'])){
            $data['door_baffle_describe'] = $Data['door_baffle_describe'];
        }
        if (!empty($Data['charged_display_describe'])){
            $data['charged_display_describe'] = $Data['charged_display_describe'];
        }
        if (!empty($Data['lighting_describe'])){
            $data['lighting_describe'] = $Data['lighting_describe'];
        }
        if (!empty($Data['door_baffle_picture'])){
            $data['door_baffle_picture'] = $Data['door_baffle_picture'];
        }
        if (!empty($Data['charged_display_picture'])){
            $data['charged_display_picture'] = $Data['charged_display_picture'];
        }
        if (!empty($Data['lighting_picture'])){
            $data['lighting_picture'] = $Data['lighting_picture'];
        }

        if (!empty($Data['cable_hole_describe'])){
            $data['cable_hole_describe'] = $Data['cable_hole_describe'];
        }
        if (!empty($Data['cable_hole_picture'])){
            $data['cable_hole_picture'] = $Data['cable_hole_picture'];
        }
        if (!empty($Data['damage_describe'])){
            $data['damage_describe'] = $Data['damage_describe'];
        }
        if (!empty($Data['damage_picture'])){
            $data['damage_picture'] = $Data['damage_picture'];
        }
        if (!empty($Data['water_leakage_describe'])){
            $data['water_leakage_describe'] = $Data['water_leakage_describe'];
        }
        if (!empty($Data['water_leakage_picture'])){
            $data['water_leakage_picture'] = $Data['water_leakage_picture'];
        }
        if (!empty($Data['annihilator_insufficient_configuration_describe'])){
            $data['annihilator_insufficient_configuration_describe'] = $Data['annihilator_insufficient_configuration_describe'];
        }
        if (!empty($Data['annihilator_insufficient_configuration_picture'])){
            $data['annihilator_insufficient_configuration_picture'] = $Data['annihilator_insufficient_configuration_picture'];
        }
        if (!empty($Data['annihilator_overdue_describe'])){
            $data['annihilator_overdue_describe'] = $Data['annihilator_overdue_describe'];
        }
        if (!empty($Data['annihilator_overdue_picture'])){
            $data['annihilator_overdue_picture'] = $Data['annihilator_overdue_picture'];
        }
        if (!empty($Data['pile_up_sundries_describe'])){
            $data['pile_up_sundries_describe'] = $Data['pile_up_sundries_describe'];
        }
        if (!empty($Data['pile_up_sundries_picture'])){
            $data['pile_up_sundries_picture'] = $Data['pile_up_sundries_picture'];
        }
        if (!empty($Data['serious_ash_deposition_describe'])){
            $data['serious_ash_deposition_describe'] = $Data['serious_ash_deposition_describe'];
        }
        if (!empty($Data['serious_ash_deposition_picture'])){
            $data['serious_ash_deposition_picture'] = $Data['serious_ash_deposition_picture'];
        }
        if (!empty($Data['around_environment_humid_describe'])){
            $data['around_environment_humid_describe'] = $Data['around_environment_humid_describe'];
        }
        if (!empty($Data['around_environment_humid_picture'])){
            $data['around_environment_humid_picture'] = $Data['around_environment_humid_picture'];
        }
        if (!empty($Data['around_pile_up_sundries_describe'])){
            $data['around_pile_up_sundries_describe'] = $Data['around_pile_up_sundries_describe'];
        }
        if (!empty($Data['around_pile_up_sundries_picture'])){
            $data['around_pile_up_sundries_picture'] = $Data['around_pile_up_sundries_picture'];
        }
        if (!empty($Data['no_electrician_describe'])){
            $data['no_electrician_describe'] = $Data['no_electrician_describe'];
        }
        if (!empty($Data['no_electrician_picture'])){
            $data['no_electrician_picture'] = $Data['no_electrician_picture'];
        }
        if (!empty($Data['electrician_lack_describe'])){
            $data['electrician_lack_describe'] = $Data['electrician_lack_describe'];
        }
        if (!empty($Data['electrician_lack_picture'])){
            $data['electrician_lack_picture'] = $Data['electrician_lack_picture'];
        }
        if (!empty($Data['overdue_electrician_certificate_describe'])){
            $data['overdue_electrician_certificate_describe'] = $Data['overdue_electrician_certificate_describe'];
        }
        if (!empty($Data['overdue_electrician_certificate_picture'])){
            $data['overdue_electrician_certificate_picture'] = $Data['overdue_electrician_certificate_picture'];
        }
        if (!empty($Data['blanket_insufficient_configuration_describe'])){
            $data['blanket_insufficient_configuration_describe'] = $Data['blanket_insufficient_configuration_describe'];
        }
        if (!empty($Data['blanket_insufficient_configuration_picture'])){
            $data['blanket_insufficient_configuration_picture'] = $Data['blanket_insufficient_configuration_picture'];
        }
        if (!empty($Data['ground_wire_describe'])){
            $data['ground_wire_describe'] = $Data['ground_wire_describe'];
        }
        if (!empty($Data['ground_wire_picture'])){
            $data['ground_wire_picture'] = $Data['ground_wire_picture'];
        }
        if (!empty($Data['analog_screen_describe'])){
            $data['analog_screen_describe'] = $Data['analog_screen_describe'];
        }
        if (!empty($Data['analog_screen_picture'])){
            $data['analog_screen_picture'] = $Data['analog_screen_picture'];
        }

        $Res=M("site_archives")->where($where)->select();
        if (!empty($Res)){
            $R = M("site_archives")->where($where)->save($data);
        }else{
            $data['sitedtl_id'] = $Data['id'];
            $R = M("site_archives")->add($data);
        }
        if ($R) {
            $res['msg'] = '操作成功';
            $res['flag'] = true;
            echo json_encode($res);
        } else {
            $res['msg'] = '操作失败';
            $res['flag'] = false;
            echo json_encode($res);
        }

    }

    public function  getArchivesList(){
        $Data = I('');
        if (!isset($_SESSION['phone'])) {
            $res['msg'] = '请重新进入公众号';
            $res['flag'] = false;
            echo json_encode($res);
            exit();
        }

        $where="";
        if (!empty($Data['id'])) {
            $where .= " and b.id = ".$Data['id'];
        }

        if (!empty($Data['site_id'])) {
            $where .= " and b.site_id = ".$Data['site_id'];
        }

        if (!empty($Data['supervision_name'])) {
            $where .= " and d.supervision_name = ".$Data['supervision_name'];
        }

        if (!empty($Data['site_name'])) {
            $where .= " and e.site_name like '%".$Data['site_name']."%' ";
        }

        if (!empty($Data['route_name'])) {
            $where .= " and c.route_name like '%".$Data['route_name']."%' ";
        }

        if(!empty($Data['currentPage'])&&!empty($Data['size'])){
            $start_number = ($Data['currentPage']-1)*$Data['size'];
            $limit = " limit ".$start_number.",".$Data['size'];
        }

        $a=M()->query("select count(*) as sl
                        from personnel as a join sitedtl as b on a.site_id=b.site_id join route as c on b.route_id=c.id 
                        join supervision as d on b.supervision_department_id=d.id join site as e on b.site_id=e.id  
                        LEFT JOIN site_archives AS s ON b.id=s.sitedtl_id where a.personnel_phone='".$_SESSION['phone']."'".$where." order by b.id desc");

        $R=M()->query("select b.*,c.route_name,c.supervision_id,d.supervision_name,d.phone,e.site_name,s.sitedtl_id,
                        s.cable_hole_describe,s.cable_hole_picture,s.damage_describe,s.damage_picture,
                        s.water_leakage_describe,s.water_leakage_picture,s.annihilator_insufficient_configuration_describe,
                        s.annihilator_insufficient_configuration_picture,s.annihilator_overdue_describe,
                        s.annihilator_overdue_picture,s.pile_up_sundries_describe,s.pile_up_sundries_picture,
                        s.serious_ash_deposition_describe,s.serious_ash_deposition_picture,s.around_environment_humid_describe,
                        s.around_environment_humid_picture,s.around_pile_up_sundries_describe,s.around_pile_up_sundries_picture,
                        s.no_electrician_describe,s.no_electrician_picture,s.electrician_lack_describe,s.electrician_lack_picture,
                        s.overdue_electrician_certificate_describe,s.overdue_electrician_certificate_picture,
                        s.blanket_insufficient_configuration_describe,s.blanket_insufficient_configuration_picture,
                        s.ground_wire_describe,s.ground_wire_picture,s.analog_screen_describe,s.analog_screen_picture,
                        s.door_baffle_describe,s.charged_display_describe,s.lighting_describe,s.door_baffle_picture,
                        s.charged_display_picture,s.lighting_picture 
                        from personnel as a join sitedtl as b on a.site_id=b.site_id join route as c on b.route_id=c.id 
                        join supervision as d on b.supervision_department_id=d.id join site as e on b.site_id=e.id  
                        LEFT JOIN site_archives AS s ON b.id=s.sitedtl_id where a.personnel_phone='".$_SESSION['phone']."'".$where." order by b.id desc ".$limit);


        if (!empty($R[0]['electric_test_overdue'])&&!empty($Data['id'])){
            $time2 = strtotime($R[0]['electric_test_overdue']) - strtotime(date('Y-m-d H:i:s',time()))/(60*60*24);
            if ($time2>0){
                $R[0]['electric_test_overdue_bz']=$time2;
            }else{
                $R[0]['electric_test_overdue_bz']=0;
            }
        }

        $res['msg'] = '操作成功';
        $res['flag'] = true;
        $res['data'] = $R;
        $res['total'] = $a[0]['sl'];
        $res['currentPage'] = $Data['currentPage'];
        $res['size'] = $Data['size'];
        echo json_encode($res);
    }


    public function  getArchivesList1(){
        $Data = I('');
        if (!isset($_SESSION['phone'])) {
            $res['msg'] = '请重新进入公众号';
            $res['flag'] = false;
            echo json_encode($res);
            exit();
        }

        $where="";
        if (!empty($Data['id'])) {
            $where .= " and b.id = ".$Data['id'];
        }
        if (!empty($Data['site_id'])) {
            $where .= " and b.site_id = ".$Data['site_id'];
        }

        $R=M()->query("select b.*,c.route_name,c.supervision_id,d.supervision_name,d.phone,e.site_name,s.sitedtl_id,
                        s.cable_hole_describe,s.cable_hole_picture,s.damage_describe,s.damage_picture,
                        s.water_leakage_describe,s.water_leakage_picture,s.annihilator_insufficient_configuration_describe,
                        s.annihilator_insufficient_configuration_picture,s.annihilator_overdue_describe,
                        s.annihilator_overdue_picture,s.pile_up_sundries_describe,s.pile_up_sundries_picture,
                        s.serious_ash_deposition_describe,s.serious_ash_deposition_picture,s.around_environment_humid_describe,
                        s.around_environment_humid_picture,s.around_pile_up_sundries_describe,s.around_pile_up_sundries_picture,
                        s.no_electrician_describe,s.no_electrician_picture,s.electrician_lack_describe,s.electrician_lack_picture,
                        s.overdue_electrician_certificate_describe,s.overdue_electrician_certificate_picture,
                        s.blanket_insufficient_configuration_describe,s.blanket_insufficient_configuration_picture,
                        s.ground_wire_describe,s.ground_wire_picture,s.analog_screen_describe,s.analog_screen_picture,
                        s.door_baffle_describe,s.charged_display_describe,s.lighting_describe,s.door_baffle_picture,
                        s.charged_display_picture,s.lighting_picture   
                        from personnel as a join sitedtl as b on a.site_id=b.site_id join route as c on b.route_id=c.id 
                        join supervision as d on b.supervision_department_id=d.id join site as e on b.site_id=e.id  
                        LEFT JOIN site_archives AS s ON b.id=s.sitedtl_id where a.personnel_phone='".$_SESSION['phone']."'".$where." order by b.id desc");


        if (!empty($R[0]['electric_test_overdue'])&&strtotime($R[0]['electric_test_overdue']) > strtotime(date('Y-m-d',time()))){
            $time2 = (strtotime($R[0]['electric_test_overdue']) - strtotime(date('Y-m-d',time())))/(60*60*24);
            if ($time2>0){
                $R[0]['electric_test_overdue_bz']=$time2;
            }else{
                $R[0]['electric_test_overdue_bz']=0;
            }
        }else{
            $R[0]['electric_test_overdue_bz']=0;
        }


        if ($R[0]['cable_hole']==1){
            $arr1['name']='电缆孔洞';
            $arr1['where']=$R[0]['cable_hole'];
            $arr1['describe']=$R[0]['cable_hole_describe'];
            $arr1['picture']=$R[0]['cable_hole_picture'];
            $R[0]['problem_one'][]=$arr1;
            $R[0]['problem_two']=array();
        }else{
            $arr1['name']='电缆孔洞';
            $arr1['where']=$R[0]['cable_hole'];
            $arr1['describe']=$R[0]['cable_hole_describe'];
            $arr1['picture']=$R[0]['cable_hole_picture'];
            $R[0]['problem_one']=array();
            $R[0]['problem_two'][]=$arr1;
        }
        if ($R[0]['damage']==1){
            $arr2['name']='门窗墙壁破损';
            $arr2['where']=$R[0]['damage'];
            $arr2['describe']=$R[0]['damage_describe'];
            $arr2['picture']=$R[0]['damage_picture'];
            $R[0]['problem_one'][]=$arr2;
        }else{
            $arr2['name']='门窗墙壁破损';
            $arr2['where']=$R[0]['damage'];
            $arr2['describe']=$R[0]['damage_describe'];
            $arr2['picture']=$R[0]['damage_picture'];
            $R[0]['problem_two'][]=$arr2;
        }
        if ($R[0]['water_leakage']==1){
            $arr3['name']='屋顶、墙壁渗漏水';
            $arr3['where']=$R[0]['water_leakage'];
            $arr3['describe']=$R[0]['water_leakage_describe'];
            $arr3['picture']=$R[0]['water_leakage_picture'];
            $R[0]['problem_one'][]=$arr3;
        }else{
            $arr3['name']='屋顶、墙壁渗漏水';
            $arr3['where']=$R[0]['water_leakage'];
            $arr3['describe']=$R[0]['water_leakage_describe'];
            $arr3['picture']=$R[0]['water_leakage_picture'];
            $R[0]['problem_two'][]=$arr3;
        }
        if ($R[0]['annihilator_insufficient_configuration']==1){
            $arr4['name']='灭火器配置不足';
            $arr4['where']=$R[0]['annihilator_insufficient_configuration'];
            $arr4['describe']=$R[0]['annihilator_insufficient_configuration_describe'];
            $arr4['picture']=$R[0]['annihilator_insufficient_configuration_picture'];
            $R[0]['problem_one'][]=$arr4;
        }else{
            $arr4['name']='灭火器配置不足';
            $arr4['where']=$R[0]['annihilator_insufficient_configuration'];
            $arr4['describe']=$R[0]['annihilator_insufficient_configuration_describe'];
            $arr4['picture']=$R[0]['annihilator_insufficient_configuration_picture'];
            $R[0]['problem_two'][]=$arr4;
        }
        if ($R[0]['annihilator_overdue']==1){
            $arr5['name']='灭火器超期';
            $arr5['where']=$R[0]['annihilator_overdue'];
            $arr5['describe']=$R[0]['annihilator_overdue_describe'];
            $arr5['picture']=$R[0]['annihilator_overdue_picture'];
            $R[0]['problem_one'][]=$arr5;
        }else{
            $arr5['name']='灭火器超期';
            $arr5['where']=$R[0]['annihilator_overdue'];
            $arr5['describe']=$R[0]['annihilator_overdue_describe'];
            $arr5['picture']=$R[0]['annihilator_overdue_picture'];
            $R[0]['problem_two'][]=$arr5;
        }
        if ($R[0]['pile_up_sundries']==1){
            $arr6['name']='堆放杂物';
            $arr6['where']=$R[0]['pile_up_sundries'];
            $arr6['describe']=$R[0]['pile_up_sundries_describe'];
            $arr6['picture']=$R[0]['pile_up_sundries_picture'];
            $R[0]['problem_one'][]=$arr6;
        }else{
            $arr6['name']='堆放杂物';
            $arr6['where']=$R[0]['pile_up_sundries'];
            $arr6['describe']=$R[0]['pile_up_sundries_describe'];
            $arr6['picture']=$R[0]['pile_up_sundries_picture'];
            $R[0]['problem_two'][]=$arr6;
        }
        if ($R[0]['serious_ash_deposition']==1){
            $arr7['name']='积灰严重';
            $arr7['where']=$R[0]['serious_ash_deposition'];
            $arr7['describe']=$R[0]['serious_ash_deposition_describe'];
            $arr7['picture']=$R[0]['serious_ash_deposition_picture'];
            $R[0]['problem_one'][]=$arr7;
        }else{
            $arr7['name']='积灰严重';
            $arr7['where']=$R[0]['serious_ash_deposition'];
            $arr7['describe']=$R[0]['serious_ash_deposition_describe'];
            $arr7['picture']=$R[0]['serious_ash_deposition_picture'];
            $R[0]['problem_two'][]=$arr7;
        }
        if ($R[0]['around_environment_humid']==1){
            $arr8['name']='配电房周围环境潮湿';
            $arr8['where']=$R[0]['around_environment_humid'];
            $arr8['describe']=$R[0]['around_environment_humid_describe'];
            $arr8['picture']=$R[0]['around_environment_humid_picture'];
            $R[0]['problem_one'][]=$arr8;
        }else{
            $arr8['name']='配电房周围环境潮湿';
            $arr8['where']=$R[0]['around_environment_humid'];
            $arr8['describe']=$R[0]['around_environment_humid_describe'];
            $arr8['picture']=$R[0]['around_environment_humid_picture'];
            $R[0]['problem_two'][]=$arr8;
        }
        if ($R[0]['around_pile_up_sundries']==1){
            $arr9['name']='配电房周围堆放杂物';
            $arr9['where']=$R[0]['around_pile_up_sundries'];
            $arr9['describe']=$R[0]['around_pile_up_sundries_describe'];
            $arr9['picture']=$R[0]['around_pile_up_sundries_picture'];
            $R[0]['problem_one'][]=$arr9;
        }else{
            $arr9['name']='配电房周围堆放杂物';
            $arr9['where']=$R[0]['around_pile_up_sundries'];
            $arr9['describe']=$R[0]['around_pile_up_sundries_describe'];
            $arr9['picture']=$R[0]['around_pile_up_sundries_picture'];
            $R[0]['problem_two'][]=$arr9;
        }
        if ($R[0]['no_electrician']==1){
            $arr10['name']='无电工';
            $arr10['where']=$R[0]['no_electrician'];
            $arr10['describe']=$R[0]['no_electrician_describe'];
            $arr10['picture']=$R[0]['no_electrician_picture'];
            $R[0]['problem_one'][]=$arr10;
        }else{
            $arr10['name']='无电工';
            $arr10['where']=$R[0]['no_electrician'];
            $arr10['describe']=$R[0]['no_electrician_describe'];
            $arr10['picture']=$R[0]['no_electrician_picture'];
            $R[0]['problem_two'][]=$arr10;
        }
        if ($R[0]['electrician_lack']==1){
            $arr11['name']='电工人数配置不足';
            $arr11['where']=$R[0]['electrician_lack'];
            $arr11['describe']=$R[0]['electrician_lack_describe'];
            $arr11['picture']=$R[0]['electrician_lack_picture'];
            $R[0]['problem_one'][]=$arr11;
        }else{
            $arr11['name']='电工人数配置不足';
            $arr11['where']=$R[0]['electrician_lack'];
            $arr11['describe']=$R[0]['electrician_lack_describe'];
            $arr11['picture']=$R[0]['electrician_lack_picture'];
            $R[0]['problem_two'][]=$arr11;
        }
        if ($R[0]['overdue_electrician_certificate']==1){
            $arr12['name']='电工证超期';
            $arr12['where']=$R[0]['overdue_electrician_certificate'];
            $arr12['describe']=$R[0]['overdue_electrician_certificate_describe'];
            $arr12['picture']=$R[0]['overdue_electrician_certificate_picture'];
            $R[0]['problem_one'][]=$arr12;
        }else{
            $arr12['name']='电工证超期';
            $arr12['where']=$R[0]['overdue_electrician_certificate'];
            $arr12['describe']=$R[0]['overdue_electrician_certificate_describe'];
            $arr12['picture']=$R[0]['overdue_electrician_certificate_picture'];
            $R[0]['problem_two'][]=$arr12;
        }
        if ($R[0]['blanket_insufficient_configuration']==1){
            $arr13['name']='绝缘毯配置不足';
            $arr13['where']=$R[0]['blanket_insufficient_configuration'];
            $arr13['describe']=$R[0]['blanket_insufficient_configuration_describe'];
            $arr13['picture']=$R[0]['blanket_insufficient_configuration_picture'];
            $R[0]['problem_one'][]=$arr13;
        }else{
            $arr13['name']='绝缘毯配置不足';
            $arr13['where']=$R[0]['blanket_insufficient_configuration'];
            $arr13['describe']=$R[0]['blanket_insufficient_configuration_describe'];
            $arr13['bpicture']=$R[0]['blanket_insufficient_configuration_picture'];
            $R[0]['problem_two'][]=$arr13;
        }
        if ($R[0]['ground_wire']==1){
            $arr14['name']='接地线与存放位置';
            $arr14['where']=$R[0]['ground_wire'];
            $arr14['describe']=$R[0]['ground_wire_describe'];
            $arr14['picture']=$R[0]['ground_wire_picture'];
            $R[0]['problem_one'][]=$arr14;
        }else{
            $arr14['name']='接地线与存放位置';
            $arr14['where']=$R[0]['ground_wire'];
            $arr14['describe']=$R[0]['ground_wire_describe'];
            $arr14['picture']=$R[0]['ground_wire_picture'];
            $R[0]['problem_two'][]=$arr14;
        }
        if ($R[0]['analog_screen']==1){
            $arr15['name']='模拟屏';
            $arr15['where']=$R[0]['analog_screen'];
            $arr15['describe']=$R[0]['analog_screen_describe'];
            $arr15['picture']=$R[0]['analog_screen_picture'];
            $R[0]['problem_one'][]=$arr15;
        }else{
            $arr15['name']='模拟屏';
            $arr15['where']=$R[0]['analog_screen'];
            $arr15['describe']=$R[0]['analog_screen_describe'];
            $arr15['picture']=$R[0]['analog_screen_picture'];
            $R[0]['problem_two'][]=$arr15;
        }

        if ($R[0]['door_baffle']==1){
            $arr15['name']='门挡板';
            $arr15['where']=$R[0]['door_baffle'];
            $arr15['describe']=$R[0]['door_baffle_describe'];
            $arr15['picture']=$R[0]['door_baffle_picture'];
            $R[0]['problem_one'][]=$arr15;
        }else{
            $arr15['name']='门挡板';
            $arr15['where']=$R[0]['door_baffle'];
            $arr15['describe']=$R[0]['door_baffle_describe'];
            $arr15['picture']=$R[0]['door_baffle_picture'];
            $R[0]['problem_two'][]=$arr15;
        }

        if ($R[0]['charged_display']==1){
            $arr15['name']='带电显示器损坏';
            $arr15['where']=$R[0]['charged_display'];
            $arr15['describe']=$R[0]['charged_display_describe'];
            $arr15['picture']=$R[0]['charged_display_picture'];
            $R[0]['problem_one'][]=$arr15;
        }else{
            $arr15['name']='带电显示器损坏';
            $arr15['where']=$R[0]['charged_display'];
            $arr15['describe']=$R[0]['charged_display_describe'];
            $arr15['picture']=$R[0]['charged_display_picture'];
            $R[0]['problem_two'][]=$arr15;
        }

        if ($R[0]['lighting']==1){
            $arr15['name']='缺失照明';
            $arr15['where']=$R[0]['lighting'];
            $arr15['describe']=$R[0]['lighting_describe'];
            $arr15['picture']=$R[0]['lighting_picture'];
            $R[0]['problem_one'][]=$arr15;
        }else{
            $arr15['name']='缺失照明';
            $arr15['where']=$R[0]['lighting'];
            $arr15['describe']=$R[0]['lighting_describe'];
            $arr15['picture']=$R[0]['lighting_picture'];
            $R[0]['problem_two'][]=$arr15;
        }

        unset($R[0]['cable_hole_describe']);
        unset($R[0]['cable_hole_picture']);
        unset($R[0]['damage_describe']);
        unset($R[0]['damage_picture']);
        unset($R[0]['water_leakage_describe']);
        unset($R[0]['water_leakage_picture']);
        unset($R[0]['annihilator_insufficient_configuration_describe']);
        unset($R[0]['annihilator_insufficient_configuration_picture']);
        unset($R[0]['annihilator_overdue_describe']);
        unset($R[0]['annihilator_overdue_picture']);
        unset($R[0]['pile_up_sundries_describe']);
        unset($R[0]['pile_up_sundries_picture']);
        unset($R[0]['serious_ash_deposition_describe']);
        unset($R[0]['serious_ash_deposition_picture']);
        unset($R[0]['around_environment_humid_describe']);
        unset($R[0]['around_environment_humid_picture']);
        unset($R[0]['around_pile_up_sundries_describe']);
        unset($R[0]['around_pile_up_sundries_picture']);
        unset($R[0]['no_electrician_describe']);
        unset($R[0]['no_electrician_picture']);
        unset($R[0]['electrician_lack_describe']);
        unset($R[0]['electrician_lack_picture']);
        unset($R[0]['overdue_electrician_certificate_describe']);
        unset($R[0]['overdue_electrician_certificate_picture']);
        unset($R[0]['blanket_insufficient_configuration_describe']);
        unset($R[0]['blanket_insufficient_configuration_picture']);
        unset($R[0]['ground_wire_describe']);
        unset($R[0]['ground_wire_picture']);
        unset($R[0]['analog_screen_describe']);
        unset($R[0]['analog_screen_picture']);
        unset($R[0]['cable_hole']);
        unset($R[0]['damage']);
        unset($R[0]['water_leakage']);
        unset($R[0]['annihilator_insufficient_configuration']);
        unset($R[0]['annihilator_overdue']);
        unset($R[0]['pile_up_sundries']);
        unset($R[0]['serious_ash_deposition']);
        unset($R[0]['around_environment_humid']);
        unset($R[0]['around_pile_up_sundries']);
        unset($R[0]['no_electrician']);
        unset($R[0]['electrician_lack']);
        unset($R[0]['overdue_electrician_certificate']);
        unset($R[0]['blanket_insufficient_configuration']);
        unset($R[0]['ground_wire']);
        unset($R[0]['analog_screen']);


        $res['msg'] = '操作成功';
        $res['flag'] = true;
        $res['data'] = $R;
        echo json_encode($res);
    }


    public function getRoutrBox(){
        $R=M()->query("select * from route where enable=1 order by id desc");
        $res['msg'] = '操作成功';
        $res['flag'] = true;
        $res['data'] = $R;
        echo json_encode($res);
    }
    public function getsupervisionBox(){
        $R=M()->query("select * from supervision order by id desc");
        $res['msg'] = '操作成功';
        $res['flag'] = true;
        $res['data'] = $R;
        echo json_encode($res);
    }
}