친구톡 요금 계산 js cnrk
@297e46ce88b871d81df8e4d4a55236ed3292394f
+++ src/main/webapp/js/kakao/ft/ftPriceClclt.js
... | ... | @@ -0,0 +1,315 @@ |
| 1 | +/** | |
| 2 | + * | |
| 3 | + * @author : 우영두 | |
| 4 | + * @fileName : ftPriceClclt.js | |
| 5 | + * @date : 2024.01.12 | |
| 6 | + * @description : 친구톡 및 대체문자 금액 연산.js | |
| 7 | + * =========================================================== | |
| 8 | + * DATE AUTHOR NOTE | |
| 9 | + * ----------------------------------------------------------- * | |
| 10 | + * 2024.01.12 우영두 최초 생성 | |
| 11 | + * | |
| 12 | + * | |
| 13 | + * | |
| 14 | + */ | |
| 15 | + | |
| 16 | + | |
| 17 | +/** | |
| 18 | + * | |
| 19 | + * @param {*} totRows 수신자 수 | |
| 20 | + * @description 금액 계산 function | |
| 21 | + * 대체 문자 X | |
| 22 | + * 카카오 금액 * 수신자 수 계산 | |
| 23 | + */ | |
| 24 | +function totalFtPriceSum(totRows){ | |
| 25 | + | |
| 26 | + var collNumCnt = parseInt(totRows); //받는사람 건수 | |
| 27 | + var price = $("#kakaoFtPrice").val(); //개별 건수 금액 | |
| 28 | + var totalPrice = 0; //전체 금액 | |
| 29 | + var totalStr = "0"; //전체 합계 금액 | |
| 30 | + var userMoney = $('#hdUserMoney').text(); //헤더 영역 보유 금액 불러오기 | |
| 31 | + | |
| 32 | + if(!userMoney > 0){ | |
| 33 | + | |
| 34 | + userMoney = 0; | |
| 35 | + | |
| 36 | + } | |
| 37 | + //헤더 영역 보유 금액 콤마 문자 제거 | |
| 38 | + if(userMoney != ''){ | |
| 39 | + | |
| 40 | + userMoney = userMoney.replaceAll("," , ""); | |
| 41 | + | |
| 42 | + } | |
| 43 | + | |
| 44 | + totalPrice = price * collNumCnt; | |
| 45 | + | |
| 46 | + // 소수점 첫째자리 까지 표시 | |
| 47 | + totalPrice = totalPrice.toFixed(1); | |
| 48 | + | |
| 49 | + if(totalPrice > 0){ | |
| 50 | + | |
| 51 | + //totalStr = totalPrice.toFixed(2); | |
| 52 | + totalStr = totalPrice; | |
| 53 | + | |
| 54 | + } | |
| 55 | + | |
| 56 | + //개별 문자 단가 파라미터에 입력 | |
| 57 | + $('#eachPrice').val(numberWithCommas(price)); | |
| 58 | + | |
| 59 | + //결제금액 합계 파라이터에 입력 | |
| 60 | + $('#totPrice').val(numberWithCommas(totalStr)); | |
| 61 | + | |
| 62 | + //결제금액 합계 화면에 표시 | |
| 63 | + $('#totalPriceTxt').text(numberWithCommas(totalStr)); | |
| 64 | + | |
| 65 | + $('#repPriceTxt').hide(); | |
| 66 | + | |
| 67 | + return totalStr; | |
| 68 | + | |
| 69 | +} | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | +/* | |
| 74 | + * ====================================================================================================================== | |
| 75 | + * | |
| 76 | + * */ | |
| 77 | + | |
| 78 | +//카카오 mms sms 단가 셋팅 | |
| 79 | +var KAKAO_FT_PRICE = ''; | |
| 80 | +var SHORT_PRICE = ''; | |
| 81 | +var LONG_PRICE = ''; | |
| 82 | + | |
| 83 | +/*$(document).ready(function(){ | |
| 84 | + | |
| 85 | + // 카카오 mms sms 단가 셋팅 | |
| 86 | + KAKAO_FT_PRICE = $('#kakaoFtPrice').val(); | |
| 87 | + SHORT_PRICE = $('#shortPrice').val(); | |
| 88 | + LONG_PRICE = $('#longPrice').val(); | |
| 89 | + | |
| 90 | + ///////////////////////////////////////// Mutation Observer | |
| 91 | + // 감시 대상 node 선택 | |
| 92 | + // 변수X 수신자 목록 | |
| 93 | + let target01 = document.getElementById('wrap01_body'); | |
| 94 | + // 변수O 수신자 목록 | |
| 95 | + let target02 = document.getElementById('wrap02'); | |
| 96 | + // 대체 문자 단문 장문 텍스트 노드 | |
| 97 | + let target03 = document.getElementById('afterDeny'); | |
| 98 | + | |
| 99 | + // 감시자의 설정 | |
| 100 | + let option = { | |
| 101 | + subtree : true // 대상 노드의 자식 요소뿐만 아니라 후손 요소의 변화까지 감지 | |
| 102 | + , childList : true // 대상 노드의 자식 요소(텍스트 포함)의 변화 감지 | |
| 103 | + , attributes : true // 해당 노드의 attribute 속성 | |
| 104 | + | |
| 105 | + // , characterData: true // 대상 노드의 데이터 변화 감지 | |
| 106 | + }; | |
| 107 | + | |
| 108 | + | |
| 109 | + // wrap01 감시자 인스턴스 만들기 | |
| 110 | + let observer_wrap01 = new MutationObserver((mutations) => { | |
| 111 | + // 노드가 변경 됐을 때의 작업 | |
| 112 | + fn_priceClclt(); | |
| 113 | + }); | |
| 114 | + | |
| 115 | + // wrap02 감시자 인스턴스 만들기 | |
| 116 | + let observer_wrap02 = new MutationObserver((mutations) => { | |
| 117 | + // 노드가 변경 됐을 때의 작업 | |
| 118 | + fn_priceClclt(); | |
| 119 | + }); | |
| 120 | + | |
| 121 | + // wrap03 감시자 인스턴스 만들기 | |
| 122 | + let observer_wrap03 = new MutationObserver((mutations) => { | |
| 123 | + // 노드가 변경 됐을 때의 작업 | |
| 124 | + fn_priceClclt(); | |
| 125 | + }); | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + // 대상 노드에 감시자 전달 | |
| 131 | + observer_wrap01.observe(target01, option); | |
| 132 | + observer_wrap02.observe(target02, option); | |
| 133 | + observer_wrap03.observe(target03, option); | |
| 134 | + | |
| 135 | + ///////////////////////////////////////// //Mutation Observer | |
| 136 | + | |
| 137 | +});*/ | |
| 138 | + | |
| 139 | +/** | |
| 140 | + * @description 금액 계산 function | |
| 141 | + */ | |
| 142 | +function fn_priceClclt(){ | |
| 143 | + | |
| 144 | + // 미리보기 텍스트 | |
| 145 | + var templateHtml = $('#smsTxtArea').val(); | |
| 146 | + // var templateHtml = $('.template_text').html(); | |
| 147 | + | |
| 148 | + // 수신 번호 개수 | |
| 149 | + var phoneSu = $('.phoneArea').length; | |
| 150 | + // 대체문자 있는지 확인 | |
| 151 | + var isSendFailChecked = $("#send_fail_check").is(":checked"); | |
| 152 | + // 치환문자 여부 확인 | |
| 153 | + var txtReplYn = $('#txtReplYn').val() | |
| 154 | + // 대체문자 하위에 장문 / 단문 select | |
| 155 | + var msgTypeText = $('.msg_com').text().trim(); | |
| 156 | + | |
| 157 | + if(typeof templateHtml == 'undefined') return false; | |
| 158 | + else if(isSendFailChecked && txtReplYn=='Y') fn_sendFailCheckedAndTxtRepl_Y(templateHtml, msgTypeText, phoneSu); // 대체문자 체크 & 치환문자 Y | |
| 159 | + else if(isSendFailChecked && txtReplYn=='N') fn_sendFailCheckedAndTxtRepl_N(msgTypeText, phoneSu); // 대체문자 체크 & 치환문자 N | |
| 160 | + else fn_sendFailUnChecked(phoneSu); | |
| 161 | + | |
| 162 | +} | |
| 163 | + | |
| 164 | +/** | |
| 165 | + * | |
| 166 | + * @param {*} phoneSu 수신자 수 | |
| 167 | + * @description 금액 계산 function | |
| 168 | + * 대체 문자 X | |
| 169 | + * 카카오 금액 * 수신자 수 계산 | |
| 170 | + */ | |
| 171 | +function fn_sendFailUnChecked(phoneSu){ | |
| 172 | + | |
| 173 | + // 카카오 금액 * 수신자 수 | |
| 174 | + // fn_writePriceText() 첫 파라미터가 null이면 카카오 전송으로 인식 | |
| 175 | + fn_writePriceText('', phoneSu); | |
| 176 | + // $('#totalPriceTxt').text((KAKAO_AT_PRICE * phoneSu).toFixed(1)); | |
| 177 | + fn_priceText('알림톡', phoneSu); | |
| 178 | +} | |
| 179 | + | |
| 180 | +/** | |
| 181 | + * | |
| 182 | + * @param {*} templateHtml 템플릿html | |
| 183 | + * @param {*} msgTypeText 발송 타입 | |
| 184 | + * @param {*} phoneSu 수신자 수 | |
| 185 | + * @description 금액 계산 function | |
| 186 | + * 대체 문자 O | |
| 187 | + * 치환 문자 O | |
| 188 | + */ | |
| 189 | +function fn_sendFailCheckedAndTxtRepl_Y(templateHtml, msgTypeText, phoneSu){ | |
| 190 | + | |
| 191 | + // 대체문자 하위에 html 그대로의 byte 계산이 단문일 경우에만 치환 후 장문이 있는지 확인 | |
| 192 | + if(msgTypeText == '단문'){ | |
| 193 | + msgTypeText = fn_transHtml(msgTypeText, templateHtml); | |
| 194 | + } | |
| 195 | + | |
| 196 | + fn_writePriceText(msgTypeText, phoneSu); | |
| 197 | + fn_priceText(msgTypeText, phoneSu); | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | +} | |
| 202 | + | |
| 203 | +/** | |
| 204 | + * | |
| 205 | + * @param {*} msgTypeText 발송 타입 | |
| 206 | + * @param {*} phoneSu 수신자 수 | |
| 207 | + * @description 금액 계산 function | |
| 208 | + * 대체 문자 O | |
| 209 | + * 치환 문자 X | |
| 210 | + */ | |
| 211 | +function fn_sendFailCheckedAndTxtRepl_N(msgTypeText, phoneSu){ | |
| 212 | + | |
| 213 | + fn_priceText(msgTypeText, phoneSu); | |
| 214 | + fn_writePriceText(msgTypeText, phoneSu); | |
| 215 | +} | |
| 216 | + | |
| 217 | + | |
| 218 | +/** | |
| 219 | + * | |
| 220 | + * @param {*} msgTypeText 발송 타입 | |
| 221 | + * @param {*} phoneSu 수신자 수 | |
| 222 | + * @returns | |
| 223 | + * @description 발송 금액 계산 / 노출 | |
| 224 | + */ | |
| 225 | +function fn_priceText(msgTypeText, phoneSu){ | |
| 226 | + | |
| 227 | + // $("#repPriceTxt").is(":visible") => 발송 금액 show hide 여부 | |
| 228 | + if(phoneSu === 0){ | |
| 229 | + | |
| 230 | + $('#repPriceTxt').empty(); | |
| 231 | + $('#repPriceTxt').hide(); | |
| 232 | + return false; | |
| 233 | + } | |
| 234 | + // 텍스트 초기화 | |
| 235 | + $('#repPriceTxt').show(); | |
| 236 | + $('#repPriceTxt').empty(); | |
| 237 | + | |
| 238 | + var priceText = '$SENDTYPE$ :<strong>$SU$</strong>건'; | |
| 239 | + priceText = priceText.replace('$SENDTYPE$', msgTypeText).replace('$SU$', phoneSu); | |
| 240 | + | |
| 241 | + $('#repPriceTxt').append(priceText); | |
| 242 | +} | |
| 243 | + | |
| 244 | +/** | |
| 245 | + * @description 발송금액 라인 text / 금액 초기화 | |
| 246 | + */ | |
| 247 | +function priceInit(){ | |
| 248 | + if($("#repPriceTxt").is(":visible")){ | |
| 249 | + $('#repPriceTxt').empty(); | |
| 250 | + $('#repPriceTxt').hide(); | |
| 251 | + } | |
| 252 | + $('#totalPriceTxt').text(0.0); | |
| 253 | + | |
| 254 | +} | |
| 255 | + | |
| 256 | +/** | |
| 257 | + * | |
| 258 | + * @param {*} msgTypeText 발송 타입 | |
| 259 | + * @param {*} phoneSu 수신자 수 | |
| 260 | + * @description 발송 금액 '발송타입:00건' 노출 | |
| 261 | + */ | |
| 262 | +function fn_writePriceText(msgTypeText, phoneSu){ | |
| 263 | + | |
| 264 | + var price; | |
| 265 | + msgTypeText = msgTypeText.trim(); | |
| 266 | + if(msgTypeText == '단문') price = SHORT_PRICE * phoneSu; | |
| 267 | + else if(msgTypeText == '장문') price = LONG_PRICE * phoneSu; | |
| 268 | + else price = KAKAO_AT_PRICE * phoneSu; // 카카오 | |
| 269 | + | |
| 270 | + $('#totalPriceTxt').text((price).toFixed(1)); | |
| 271 | +} | |
| 272 | + | |
| 273 | + | |
| 274 | +/** | |
| 275 | + * | |
| 276 | + * @param {*} msgTypeText 발송 타입 : 단문 | |
| 277 | + * @param {*} templateHtml 템플릿 html | |
| 278 | + * @returns msgTypeText : 단문 or 장문 | |
| 279 | + * @description 치환 데이터 있는 경우 단문일 경우만 호출 | |
| 280 | + * 치환 후 장문 데이터일경우 'returns 장문'으로 끝남 | |
| 281 | + */ | |
| 282 | +function fn_transHtml(msgTypeText, templateHtml){ | |
| 283 | + | |
| 284 | + // 템플릿 | |
| 285 | + templateHtml = templateHtml.trim().replace(/(<br>|<br\/>|<br \/>)/g, '\n'); | |
| 286 | + // 치환 부분 '#{내용}'만 추출 | |
| 287 | + var varList = $("#excelTemplateContent").val().match(/#\{([^}]+)\}/g); | |
| 288 | + // 템플릿을 반복할때마다 담는 temp 선언 | |
| 289 | + var tempTemplateHtml; | |
| 290 | + // 치환 데이터 담는 변수 선언 | |
| 291 | + var replaceStr; | |
| 292 | + | |
| 293 | + // excelBody 부분 반복 시작 | |
| 294 | + $('.excelBody').each(function(i, t){ | |
| 295 | + tempTemplateHtml = templateHtml; | |
| 296 | + | |
| 297 | + $(this).find('.transData').each(function(index, item){ | |
| 298 | + // console.log('item text :: ', $(item).text().trim()); | |
| 299 | + replaceStr = $(item).text().trim(); | |
| 300 | + tempTemplateHtml = tempTemplateHtml.replace(varList[index], replaceStr); | |
| 301 | + }); | |
| 302 | + // 치환 후 byte 계산 | |
| 303 | + // 장문이면 break; | |
| 304 | + if(90 < conByteLeng(tempTemplateHtml)) | |
| 305 | + { | |
| 306 | + msgTypeText = '장문'; | |
| 307 | + return false; | |
| 308 | + } | |
| 309 | + }); | |
| 310 | + | |
| 311 | + | |
| 312 | + return msgTypeText; | |
| 313 | +} | |
| 314 | + | |
| 315 | + (No newline at end of file) |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?