AdminPush.php 5.31 KB
<? include $_SERVER["DOCUMENT_ROOT"] . "/common/classes/AdminBase.php" ;?>
<?
/*
 * Admin process
 * add by dev.lee
 * */
if(!class_exists("AdminPush")){
	class AdminPush extends  AdminBase {
		
		function __construct($req) 
		{
			parent::__construct($req);
		}
		
		function sendPushForAnswer()
		{
			$user_fk = $this->req["user_fk"] ;
			$push_msg = "문의에 대한 답변이 달렸습니다." ;
			$push_code = $this->getBulkPushCode();
			
			$sql = "
			INSERT INTO tbl_push_target_bulk(push_code, registration_key, device_type_id, app_type)
			(
				SELECT '{$push_code}', registration_key, device_type_id, app_type
				FROM tbl_user U
				WHERE U.no='{$user_fk}' AND U.status = 'Y' AND U.registration_key != '' AND is_push = 1 AND comm_push = 1
				LIMIT 0, 1
			)
			";
			
			$push_count = $this->update($sql);
			
			// 푸시 전송
			$params = Array(
					"push_code"	=> $push_code,
					"push_msg"	=> $push_msg,
					"push_type"	=> $this->PUSH_TYPE_ADMIN
					);
			
			$this->sendPushBulk($params);
			
			return $this->makeResultJson(1, "전송되었습니다.");
			
		}
		
		function sendPushForBillSend()
		{
			$room_fk = $this->req["room_fk"] ;
			$push_msg = "청구서가 도착했습니다." ;
			$push_code = $this->getBulkPushCode();
			
			$sql="
				SELECT user_fk
				FROM tbl_room
				WHERE no='{$room_fk}'
			";
			$result=$this->getRow($sql);
			$user_fk=$result["user_fk"];
			
			$sql = "
			INSERT INTO tbl_push_target_bulk(push_code, registration_key, device_type_id, app_type)
			(
			SELECT '{$push_code}', registration_key, device_type_id, app_type
			FROM tbl_user U
			WHERE U.no='{$user_fk}' AND U.status = 'Y' AND U.registration_key != '' AND is_push = 1
			LIMIT 0, 1
			)";
				
			$push_count = $this->update($sql);
				
			// 푸시 전송
			$params = Array(
					"push_code"	=> $push_code,
					"push_msg"	=> $push_msg,
					"push_type"	=> $this->PUSH_TYPE_ADMIN
					);
				
			$this->sendPushBulk($params);
				
			return $this->makeResultJson(1, "전송되었습니다.");
		}
		
		function sendPushForChargeSend()
		{
			$building_name = $this->req["building_name"] ;
			$room_name	= $this->req["room_name"];
			$push_msg = "청구서가 도착했습니다." ;
			$push_code = $this->getBulkPushCode();
			$sql="
				SELECT vip_fk
				FROM tbl_building AS `B`
				JOIN tbl_room AS `R` ON `B`.no = `R`.building_fk
				WHERE `R`.name='{$room_name}' AND `B`.name='{$building_name}'
			";
			$result=$this->getRow($sql);
			$vip_fk=$result["vip_fk"];
			
				
			$sql = "
			INSERT INTO tbl_push_target_bulk(push_code, registration_key, device_type_id, app_type)
			(
			SELECT '{$push_code}', registration_key, device_type_id, app_type
			FROM tbl_user U
			WHERE U.no='{$vip_fk}' AND U.status = 'Y' AND U.registration_key != '' AND is_push = 1
			LIMIT 0, 1
			)
			";
				
			$push_count = $this->update($sql);
				
			// 푸시 전송
			$params = Array(
					"push_code"	=> $push_code,
					"push_msg"	=> $push_msg,
					"push_type"	=> $this->PUSH_TYPE_ADMIN
					);
				
			$this->sendPushBulk($params);
				
			return $this->makeResultJson(1, "전송되었습니다.");
				
		}

		function sendAdminPush()
		{
			$push_msg = $this->req["pushMessage"];
			$push_code = $this->getBulkPushCode();
			$push_succeed=0;
			
				$sql = "
					INSERT INTO tbl_push_target_bulk(push_code, registration_key, device_type_id)
					(
						SELECT '{$push_code}', registrationKey, deviceTypeID
						FROM tblUser U
						WHERE U.status = 1 AND U.registrationKey != '' AND push = 1
					)
				";
				$push_count = $this->update($sql);
				
				$sql="SELECT count(*) as rn 
						FROM tblUser U
						WHERE U.status = 1 AND U.registrationKey != '' AND push = 1";
				$result=$this->getRow($sql);
				$push_succeed = $result["rn"];

			
			$push_msg = $this->req["pushMessage"];
			
			// 푸시 전송
			$params = Array(
				"push_code"	=> $push_code,
				"push_msg"	=> $push_msg,
				"push_type"	=> $this->PUSH_TYPE_ADMIN
			);
			
			$this->sendPushBulk($params);
			
			
			return $this->makeResultJson(1, "전송되었습니다.");
		}
		
		// 푸시키 코드 조회
		function getBulkPushCode()
		{
			$microTime = microtime();
			$timeArr = explode(" ", $microTime);
			$code = str_replace(".", "", ($timeArr[1] . ($timeArr[0]*1E8)));
			
			return $code;
		}
		
		
		function getListOfAdminPush()
		{
			//최초 페이지 설정
			$this->initPage();
					
			$sql = "
				SELECT COUNT(*) AS rn
				FROM tbl_push_log
				{$where}
			";
			$this->rownum = $this->getValue($sql, 'rn');
				
			//총 로우수를 획득후 페이지 최종 설정
			$this->setPage($this->rownum);
				
			$sql = "
				SELECT
					*
				FROM tbl_push_log
				ORDER BY no DESC
				LIMIT {$this->startNum}, {$this->endNum} ;
			";
			$result = $this->getArray($sql);
				
			return $result;
		}
		
		function saveAgreement(){
			$type=$this->req["type"];
			$content=$this->req["content"];
			
			if($type == "AG"){
				$filePath = $this->agreeInfoPath;
				$files = fopen($filePath, "w");
				
				fwrite($files, $content);
				fclose($files);
				return $this->makeResultJson(1, "약관이 저장되었습니다");
			}
			else if($type == "PR"){
				$filePath = $this->privacyInfoPath;
				$files = fopen($filePath, "w");
				fwrite($files, $content);
				fclose($files);
				return $this->makeResultJson(1, "개인정보처리방침이 저장되었습니다");
			}
			
			
		}

	} // class end
}
?>