Common.php 12.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
<? include $_SERVER["DOCUMENT_ROOT"] . '/common/classes/comm/HomeFrm.php'; ?>
<?php

if (! class_exists("Common"))
{

	class Common extends HomeFrm
	{

		function __construct($req)
		{
			parent::__construct($req);
		}
		
		//resultJson 생성
		function makeResultJson($returnCode, $returnMessage, $entity = "", $addData = Array())
		{
			
			//기본 json데이터 생성
			$resultJson = Array(
				"callApi" => $this->callApi,
				"returnCode" => $returnCode,
				"returnMessage" => $returnMessage,
				"entity" => $entity
			);
			
			//추가 데이터 추가
			if (is_array($addData))
			{
				foreach ($addData as $key => $value)
				{
					$resultJson[$key] = $value;
				}
			}
			
			return json_encode($resultJson);
		}

		/**
		 * *************************************************************************
		 * 제 목 : 이미지 파일 사이즈 구하기
		 * 함수명 : fileUpload
		 * 작성일 : 2013-07-22
		 * 작성자 : dev.Na
		 * 설 명 :
		 * 수 정 :
		 * '**************************************************************************
		 */
		function inFn_Common_getImageSize($imgUrl)
		{
			$imgUrl = $this->fileSavePath . "/" . $imgUrl;
			
			$imgExtension = Array(
				'GIF',
				'JPG',
				'PNG',
				'PSD',
				'BMP'
			);
			
			if (in_array(strtoupper($this->getFileExtension($imgUrl)), $imgExtension))
			{
				$sizeInfo = getimagesize($imgUrl);
				$file_width = $sizeInfo[0];
				$file_height = $sizeInfo[1];
			}
			else
			{
				$file_width = "0";
				$file_height = "0";
			}
			
			$retArr = Array(
				"file_name" => str_replace($this->fileSavePath, "", $imgUrl),
				"file_width" => $file_width,
				"file_height" => $file_height
			);
			
			return $retArr;
		}
		
		// 파일명중 확장자를 분리해준다.
		function inFn_Common_getFileExtension($imgUrl)
		{
			$Tmp = explode(".", $imgUrl);
			
			return $Tmp[count($Tmp) - 1];
		}
		
		// 파일 저장
		function inFn_Common_fileSave($Files)
		{
			$result = Array();
			$Upload = new UploadUtil();
			
			foreach ($Files as $key => $File)
			{
				$uploadResult = $Upload->uploadOneFile($File, $this->fileSavePath, "", true, false, true);
				$result[$key] = $uploadResult["fileInfo"];
				
				if ($uploadResult["returnCode"] == "1")
				{
					// 파일 디비에 저장할 데이터 셋팅
					$fileOriginName = $result[$key]["name"];
					$filePath = $result[$key]["saveURL"];
					$fileSize = $result[$key]["size"];
					$fileType = $result[$key]["type"];
					$fileExtension = $result[$key]["extension"];
					$imgWidth = 0;
					$imgHeight = 0;
					
					//이미지일 경우
					if (strpos($result[$key]["type"], "image") !== false)
					{
						// 이미지 사이즈 조회 후 디비 저장 데이터에 추가
						$imgSizeData = $this->inFn_Common_getImageSize($result[$key]["saveURL"]);
						$imgWidth = $imgSizeData["file_width"];
						$imgHeight = $imgSizeData["file_height"];
						
						// 이미지 리사이징
						$image = new SimpleImage();
						$assoc = array(
							$this->fileSavePath_720 . "/",
							$this->fileSavePath_640 . "/",
							$this->fileSavePath_480 . "/",
							$this->fileSavePath_320 . "/",
							$this->fileSavePath_100 . "/"
						);
						
						$image->check($assoc);
						
						$image->processing($uploadResult["fileInfo"]["savePath"] . "/", $this->fileSavePath_720 . "/", 720, $uploadResult["fileInfo"]['re_name']);
						$image->processing($uploadResult["fileInfo"]["savePath"] . "/", $this->fileSavePath_640 . "/", 640, $uploadResult["fileInfo"]['re_name']);
						$image->processing($uploadResult["fileInfo"]["savePath"] . "/", $this->fileSavePath_480 . "/", 480, $uploadResult["fileInfo"]['re_name']);
						$image->processing($uploadResult["fileInfo"]["savePath"] . "/", $this->fileSavePath_320 . "/", 320, $uploadResult["fileInfo"]['re_name']);
						$image->processing($uploadResult["fileInfo"]["savePath"] . "/", $this->fileSavePath_100 . "/", 100, $uploadResult["fileInfo"]['re_name']);
					}
				}
			}
			
			return $result;
		}
		
		// 엑셀 데이터 추출
		function inFnExcelDataToArr($uploadExcelFile, $isReadTitle = false)
		{
			$arrRow = Array();
			$Upload = new UploadUtil();
			$uploadResult = $Upload->uploadOneFile($uploadExcelFile, $this->excelSavePath, "", true, false, true);
			
			if ($uploadResult["returnCode"] != "1")
				return $arrRow;
			
			$excelData = $uploadResult["fileInfo"];
			if (strcmp($excelData['re_name'], ""))
			{
				$excelFile = $this->excelSavePath . "/" . $excelData['saveURL'];
				
				$exReaderObj = new Spreadsheet_Excel_Reader();
				$exReaderObj->setOutputEncoding("UTF-8");
				$exReaderObj->read($excelFile);
				
				error_reporting(E_ALL ^ E_NOTICE);
				
				$seq = $exReaderObj->sheets[0]['numRows'];
				
				for ($i = (($isReadTitle) ? 1 : 2); $i <= $seq; $i ++)
				{
					// safe array
					

					if ($exReaderObj->sheets[0]['cells'][$i][1] != "" && $exReaderObj->sheets[0]['numCols'] > 0)
					{
						$arrData = Array();
						
						for ($j = 1; $j <= $exReaderObj->sheets[0]['numCols']; $j ++)
						{
							
							$input = $exReaderObj->sheets[0]['cells'][$i][$j];
							
							$input = ($input == null) ? "" : $input;
							
							array_push($arrData, $input);
						}
						
						array_push($arrRow, $arrData);
					}
				}
			}
			
			return $arrRow;
		}

		/**
		 * 회원 사용가능 포인트 조회
		 * 
		 * @return string
		 */
		function inFn_Common_getUserPointBalance($no)
		{
			
			$sql = "
                SELECT IFNULL(SUM(CASE trans_type WHEN 'I' THEN amt ELSE (amt*-1) END ), 0) AS balanceAmt
				FROM tbl_point_trans
				WHERE user_fk = '{$no}'
			";
			
			$balanceAmt = $this->getValue($sql, "balanceAmt");
			
			return $balanceAmt;
		}
		
		/**
		 * 등록 차감 함수
		 * @param $trans_type
		 * @param $no
		 * @param $amt
		 * @param $shop_fk
		 * @param $pay_type
		 * @return boolean
		 */
		function inFn_Common_savePointTrans($trans_type, $user_fk, $amt, $group_fk, $shop_fk = 0, $pay_type = "", $pay_amt = "0")
		{
			$sql = "
				INSERT INTO tbl_point_trans
				(
					user_fk, group_fk, shop_fk, trans_type, amt, pay_type, pay_amt, reg_dt, reg_date
				)
				VALUES
				(
					'{$user_fk}', '{$group_fk}', '{$shop_fk}', '{$trans_type}', '{$amt}', '{$pay_type}', '{$pay_amt}', NOW(), CURDATE()
				)
			";	
			$result = $this->update($sql);
				
			return ($result > 0);
		}
		
		
		
		/***************************************************************************
		*	제  목 : 주소로 좌표 뽑기 / reverseGeocode
		*	작성일 : 2013-11-04
		*	작성자 : dev.Na
		*	설  명 : 
		*   리  턴 : String
		*   
		****************************************************************************/
		function reverseGeocode($address)
		{
			$latitude	= 0;
			$longitude	= 0;

			$addresParam = urlencode($address);
			$url = "http://maps.googleapis.com/maps/api/geocode/json?address=$addresParam&sensor=false&language=ko";
			//$url = "https://maps.googleapis.com/maps/api/geocode/json?key=AIzaSyDoTwPl7kcLmuMqz5ljXgNJqvYJgmUS2ps&address=$addresParam&sensor=true&language=ko";
			//https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY
			
			if($address){
				$ch = curl_init();
				curl_setopt($ch, CURLOPT_URL, $url);
				curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-Language:ko"));
				curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);	
				curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
				curl_setopt($ch, CURLOPT_SSLVERSION,4); 
				curl_setopt($ch, CURLOPT_HEADER, 0);			
				curl_setopt($ch, CURLOPT_TIMEOUT, 30); 
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
				$resultJson = curl_exec($ch);
				curl_close($ch);
				
				//echo $resultJson;
				$resultArr = json_decode($resultJson, true);
				
				if($resultArr["status"] == "OK")
				{
					$lat = $resultArr["results"][0]["geometry"]["location"]["lat"];
					$lng = $resultArr["results"][0]["geometry"]["location"]["lng"];
	
					$latitude = floor($lat*1E6);
					$longitude = floor($lng*1E6);
				}
			}
			$retArr = Array(
				"latitude"	=> $latitude,
				"longitude"	=> $longitude
			);

			return $retArr;
		}
		/***************************************************************************
		 *	제  목 : 주소로 좌표 뽑기 / reverseGeocode2
		 *	작성일 : 2013-11-04
		 *	작성자 : dev.Na
		 *	설  명 : Daum
		 *  리  턴 : String
		 *
		 ****************************************************************************/
		function reverseGeocode2($address)
		{
			$latitude	= 0;
			$longitude	= 0;
			$addresParam = urlencode($address);
			$apikey = "29ba15a34edd4ee5ad304b1f7c7cd26c";
			//$address = str_replace(" ", "%20", $address);
			$url = "https://apis.daum.net/local/geo/addr2coord?apikey=$apikey&q=$addresParam&output=json";
			//echo $url . "<br/>";
			if($address){
				$ch = curl_init();
				curl_setopt($ch, CURLOPT_URL, $url);
				curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-Language:ko"));
				curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
				curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
				curl_setopt($ch, CURLOPT_SSLVERSION,4);
				curl_setopt($ch, CURLOPT_HEADER, 0);
				curl_setopt($ch, CURLOPT_TIMEOUT, 30);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
				$resultJson = curl_exec($ch);
				$curl_errno = curl_errno($ch);
				$curl_error = curl_error($ch);			
				curl_close($ch);
				/*
				echo "=====================================<br/>";
				echo "RESULT : " . $resultJson . "<br/>";
				echo "ERROR CODE : " . $curl_errno . "<br/>";
				echo "ERROROR MSG : " . $curl_error . "<br/>";
				echo "=====================================<br/>";
				*/
				echo $resultJson;
				$resultArr = json_decode($resultJson, true);
				$result = $resultArr["channel"]; 
				
				if($result["result"] == "1")
				{
					
					$lat = $result["item"][0]["lat"];
					$lng = $result["item"][0]["lng"];
					
					$latitude = floor($lat*1E6);
					$longitude = floor($lng*1E6);
				}
			}
			$retArr = Array(
					"latitude"	=> $latitude,
					"longitude"	=> $longitude
			);
		
			return $retArr;
		}
		
		
		
		
		
		function sendPushBulk($params)
		{
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, "{$this->con_domain}/feed/sendBulkPush.php");
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
			curl_setopt($ch, CURLOPT_POST, true);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
			$result = curl_exec($ch);
			
			if(curl_error($ch)){
				echo 'error:' . curl_error($ch);
			}
	
			curl_close($ch);
		}
		
		
		/** 
		 * sendSms($sendStr)
		 * add by Dev.Na 2013-01-09
		 * @param $sendStr - 발송할 문구
		 *
		 * @param $phone - 전화번호
		 * */
		function sendSMS($sendStr, $resPhone, $reqPhone){
				
			$sms_id		= "groupby" ;
			$sms_passwd	= "rtgvcdf$%" ;
			$sms_type	= "L" ;
			$sms_to		= $resPhone ;
			$sms_from	= $reqPhone ;
			$sms_date	= "0" ;
			$sms_msg	= $sendStr ;
		
			if($resPhone == "" && $resPhone == "")
			{
// 				$logData = "Api : sendSMS // reqPhone : {$reqPhone} //resPhone : {$resPhone} // 발송실패";
// 				LogUtil::writeFileLog($this->logPath, $logData);
				return false;
			}
				
			$sms = new EmmaSMS();
		
			$sms->login($sms_id, $sms_passwd);
			
			$ret = $sms->send($sms_to, $sms_from, $sms_msg, $sms_date, $sms_type);
			
			if($ret)
			{
				$smsInfo	= json_encode($ret);
				$retunrVal	= true;
				$returnMsg	= "Success";
			}
			else
			{
				$smsInfo	= "";
				$retunrVal	= false;
				$returnMsg	= $sms->errMsg;
			}
		
// 			$logData = "Api : sendSMS // reqPhone : {$reqPhone} //resPhone : {$resPhone} // 메세지 : {$sendStr} // 발송여부 : {$returnMsg} // 잔여정보 : {$smsInfo}";
// 			LogUtil::writeFileLog($this->logPath, $logData);
		
			return $retunrVal;
		}
		
		function feedSimpleLog($logData)
		{
			$today = date("Ymd", time()); ;
		
		
			$fileDirectory = $this->logPath;
		
		
			if(is_dir ($fileDirectory)!=true){
				mkdir($fileDirectory);
			}
		
			if(is_dir($fileDirectory.$today)!=true){
				mkdir($fileDirectory.$today);
			}
		
			$fileName = $today.".txt";
		
			$fPath = $fileDirectory.$today."/".$fileName;
		
			$fp = fopen($fPath,"a+");
		
			//파일에 쓰는부분 .
		
			fwrite($fp,"LogStart Date : ".$today. " // " . $logData . "\n");
			fwrite($fp,"============================================================================\n");
		
		
			//파일 쓰기 끝 닫기
		
			fclose($fp);
		}
		
		
		
	}
}
?>