AdminPush.php 5.76 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["push_msg"];
			$group_no = $this->req["group_no"];
			$push_target_type = $this->req["push_target_type"];
			$push_code = $this->getBulkPushCode();
			$push_succeed=0;
			
			if($push_target_type == "1"){
				$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.status = 'Y' AND U.registration_key != '' AND is_push = 1
					)
				";
				$push_count = $this->update($sql);
				
				$sql="SELECT count(*) as rn 
						FROM tbl_user U
						WHERE U.status = 'Y' AND U.registration_key != '' AND is_push = 1";
				$result=$this->getRow($sql);
				$push_succeed = $result["rn"];
			}
			else
			{
				$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.group_fk = '{$group_no}' AND U.status = 'Y' AND U.registration_key != '' AND is_push = 1
					)
				";
				$push_count = $this->update($sql);
				$sql="SELECT count(*) as rn
						FROM tbl_user U
						WHERE U.status = 'Y' AND U.registration_key != '' AND is_push = 1";
				$result=$this->getRow($sql);
				$push_succeed = $result["rn"];
			}
			
			$sql = "
				INSERT INTO tbl_push_log(push_target_type, group_fk, push_msg, push_count, push_dt)
				VALUES('{$push_target_type}', '{$group_no}', '{$push_msg}', '{$push_succeed}', NOW())
			";
			$this->update($sql);
			$push_msg = $this->req["push_msg"];
			$group_no = $this->req["group_no"];
			$push_target_type = $this->req["push_target_type"];
			
			// 푸시 전송
			$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;
		}

	} // class end
}
?>