<?
// 社会用户注册2【机构】
require_once ("../user_include.inc");

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

//获取参数
$openId = ParamUtil::getRequestString("openId");
$unionId = ParamUtil::getRequestString("unionId");

//$openId = $_POST['openId'];
//$unionId = $_POST['unionId'];

ErrorLogger::doOutput("Compass...ajax_social_user_register2.php....openId=" . $openId, 0);
ErrorLogger::doOutput("Compass...ajax_social_user_register2.php....unionId=" . $unionId, 0);

//参数验证
if(empty($openId) || empty($unionId)) {
	$result["message"] = "参数错误！";
	responseNG($result);
}

//判断用户是否已经存在
$param = array();
$param['openid'] = $openId;
$param['unionid'] = $unionId;
$param['delete_flg'] = false;
$userList = UserMst::getList($param,'id','desc', 0, 1);
if(empty($userList)) {
	$result["message"] = "用户不存在！";
	responseOK($result);
}

//用户数据插入
$userMst = $userList[0];
$userMst->role = 6; //社会用户[机构]

//处理上传图片
$aliHandler = new AliUploadHandler();
if(!empty($_FILES['legalPersonImgage1']['tmp_name'])){
  $upload_file = FileUploadUtil::getScalarFile(@$_FILES['legalPersonImgage1']);
  $tmp_file_name = date("Ymd") . "_" . trim(basename($upload_file->name));//保存的名字自定义，这里如果图片的名字原来的是aa.jp，保存成20200220_aa.jpg
  
  $url = $aliHandler->uploadImg($tmp_file_name, $upload_file->tmp_name);
  ErrorLogger::doOutput($url);
  //这里的url就是http://compass-dev.oss-cn-beijing.aliyuncs.com/20200220_aa.jpg
  $userMst->legal_person_imgage1 = $url;
}
if(!empty($_FILES['legalPersonImgage2']['tmp_name'])){
  $upload_file = FileUploadUtil::getScalarFile(@$_FILES['legalPersonImgage2']);
  $tmp_file_name = date("Ymd") . "_" . trim(basename($upload_file->name));//保存的名字自定义，这里如果图片的名字原来的是aa.jp，保存成20200220_aa.jpg
  
  $url = $aliHandler->uploadImg($tmp_file_name, $upload_file->tmp_name);
  ErrorLogger::doOutput($url);
  //这里的url就是http://compass-dev.oss-cn-beijing.aliyuncs.com/20200220_aa.jpg
  $userMst->legal_person_imgage2 = $url;
}
if(!empty($_FILES['licensenImgage']['tmp_name'])){
  $upload_file = FileUploadUtil::getScalarFile(@$_FILES['licensenImgage']);
  $tmp_file_name = date("Ymd") . "_" . trim(basename($upload_file->name));//保存的名字自定义，这里如果图片的名字原来的是aa.jp，保存成20200220_aa.jpg
  
  $url = $aliHandler->uploadImg($tmp_file_name, $upload_file->tmp_name);
  ErrorLogger::doOutput($url);
  //这里的url就是http://compass-dev.oss-cn-beijing.aliyuncs.com/20200220_aa.jpg
  $userMst->licensen_imgage = $url;
}
if(!empty($_FILES['otherImgage']['tmp_name'])){
  $upload_file = FileUploadUtil::getScalarFile(@$_FILES['otherImgage']);
  $tmp_file_name = date("Ymd") . "_" . trim(basename($upload_file->name));//保存的名字自定义，这里如果图片的名字原来的是aa.jp，保存成20200220_aa.jpg

  $url = $aliHandler->uploadImg($tmp_file_name, $upload_file->tmp_name);
  ErrorLogger::doOutput($url);
  //这里的url就是http://compass-dev.oss-cn-beijing.aliyuncs.com/20200220_aa.jpg
  $userMst->other_imgage = $url;
}

$userMst->save();

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

$result["message"] = "注册成功！";
responseOK($result);

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

?>