<?php

// 2.家校/家园平台学校信息同步接口
require_once ("../user_include.inc");

ErrorLogger::doOutput("Compass...synchronize_school_dat.php....Start.", 0);

//获取参数
$schoolNo = ParamUtil::getRequestString("schoolNo");
$originalSource = ParamUtil::getRequestNumber("originalSource", 0);
$title = ParamUtil::getRequestString("title");
$province = ParamUtil::getRequestString("province");
$city = ParamUtil::getRequestString("city");
$district = ParamUtil::getRequestString("district");
$street = ParamUtil::getRequestString("street");

//参数检查
if(empty($schoolNo) || empty($originalSource) || empty($title)) {
	responseNG("参数错误！");
}

//originalSource为1或者2
if($originalSource <> 1 && $originalSource <> 2 && $originalSource <> 3) {
	responseNG("参数错误！");
}

//判断学校是否已经存在
$param = array();
$param['school_no'] = $schoolNo;
$param['original_source'] = $originalSource;
$param['delete_flg'] = false;
$schoolList = SchoolMst::getList($param,'id','desc', 0, 1);
if(empty($schoolList)) {
	$schoolMst = new SchoolMst();
	$schoolMst->school_no = $schoolNo;
	$schoolMst->original_source = $originalSource;
	$schoolMst->title = $title;
	$schoolMst->school_type = $originalSource;//此处跟originalSource一样
	$schoolMst->province = $province;
	$schoolMst->city = $city;
	$schoolMst->district = $district;
	$schoolMst->street = $street;
	$schoolMst->save();
} else {
	$schoolMst = $schoolList[0];
	$schoolMst->title = $title;
	$schoolMst->school_type = $originalSource;//此处跟originalSource一样
	$schoolMst->province = $province;
	$schoolMst->city = $city;
	$schoolMst->district = $district;
	$schoolMst->street = $street;
	$schoolMst->save();
}

ErrorLogger::doOutput("Compass...synchronize_school_dat.php....End.", 0);

responseOK("更新成功！");

function responseNG($message) {
	$result = array("status"=>"NG", "message"=>$message);
	print json_encode($result);
	exit;
}
function responseOK($message) {
	$result = array("status"=>"OK", "message"=>$message);
	print json_encode($result);
	exit;
}
?>