<!--#include virtual = "/common/lib/dbcon.asp" -->
<!--#include virtual = "/common/lib/func.asp" -->
<!--#include virtual = "/common/lib/JSON.asp" -->
<%

'────────────────────────────────────────────────────
' 스룩페이 사용중 20161004
'────────────────────────────────────────────────────

'm_id : 회원ID
'msg : 메세지
'tran_callback : 회신번호
'tran_phone : 수신번호 ex) 0111231234,0171231234

result = "Y"
result_msg = ""


refer_url = Request.ServerVariables("HTTP_REFERER")
If InStr(1,refer_url, ".15449642.com",1)=0 And InStr(1,refer_url, "srook.co.kr",1)=0 Then
	result = "N"
	result_msg = "올바른접속이 아님"
End If


If result="Y" then
	m_id			= InputValue( Request.Form("sms_m_id") )
	msg				= InputValue( Request.Form("sms_msg") )
	tran_callback	= InputValue( Request.form("sms_tran_callback") )
	tran_phone		= InputValue( Request.form("sms_tran_phone") )
	shop_id			= InputValue( Request.form("sub_shop_id") )
	If m_id="" Or msg="" Or tran_callback="" Or tran_phone="" Or shop_id="" Then
		result = "N"
		result_msg = "필수값 없음"
	End If
End If

If result="Y" Then
	t = 0
	tran_phone_arr = Split(tran_phone,",")
	For i = 0 To UBound( tran_phone_arr )
		If Trim(tran_phone_arr(i)) <> "" then
			t=t+1
		End If
	Next

	sql = "select m_g_sms from member where m_id = '" & m_id & "'"
	Set rs = dbcon.execute( sql )
	If rs.bof Or rs.eof Then
		remain_cnt = 0
	Else
		remain_cnt = rs(0)
	End If
	Set rs = Nothing

	If remain_cnt<t Then
		result = "N"
		result_msg = "잔여량 부족"
	End if		
End If


If result="Y" Then

	Rdate = Date()& " " & Hour(now)&":"&Minute(now)
	tran_callback = Replace(tran_callback, "-", "")
	
	z = 0

	tran_phone_arr = Split(tran_phone,",")		
	For i = 0 To UBound( tran_phone_arr )
		If Trim(tran_phone_arr(i)) <> "" then
			tran_phone = Replace(tran_phone_arr(i), "-", "")
			
			sql = "Insert into em_tran(tran_id, tran_phone, tran_callback, tran_status, tran_date, tran_msg, tran_etc1) values ("
			sql = sql & "'"&m_id&"','"&tran_phone&"', '"&tran_callback&"', '1', '"&Rdate&"', '"&msg&"', '"&shop_id&"')"
			Dbcon.Execute sql

			z = z + 1
		End if
	Next

	sql = "update member set M_g_sms = M_g_sms - "&z&" where M_id = '"&m_id&"'"
	Dbcon.Execute sql
	
End if

Dbcon.close
Set Dbcon = Nothing


Set returnData = jsObject()
returnData("result") = result
returnData("result_msg") = result_msg
returnData("cnt") = z
returnData.Flush

%>
