biztalk_standby.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?
  2. /*
  3. * 관리자 입찰대기건을 입찰 승인 처리 하여 비즈톡 예약 발송 테이블에 등록한다
  4. * 실행시간
  5. * 10:50 (전일 14:50:00 ~ 당일 10:49:59까지 수집된 데이터)
  6. * 14:50 (당일 10:50:00 ~ 당일 14:49:59까지 수집된 데이터)
  7. */
  8. include $_SERVER['DOCUMENT_ROOT'].'/common/lib/comm.php';
  9. exit;
  10. ini_set('max_execution_time', 600);
  11. $senderKey = "4856a5e128f9289082c884d066f1df198cbb1165";
  12. $tmpltCode = "standby";
  13. $tmpltCode = "auto_push_30";
  14. $resMethod = "PUSH";
  15. $cur_date = date('Y-m-d H:i:s');
  16. //오전 기준 시간
  17. $standard_time = 11;
  18. $cur_time = date('H');
  19. $is_early = false;
  20. //기준 시간 보다 작으면 오전 발송
  21. if($standard_time > $cur_time) {
  22. $is_early = true;
  23. }
  24. if($_SERVER['REMOTE_ADDR'] == '220.86.25.88') {
  25. // echo "no";
  26. // exit;
  27. }
  28. if($is_early == true) {
  29. $start_date = date('Y-m-d 14:50:00', strtotime(date("Y-m-d"). '-1day'));
  30. $end_date = date('Y-m-d 10:09:59');
  31. $send_date = date('Y-m-d 10:15:00');
  32. }else {
  33. $start_date = date('Y-m-d 10:10:00');
  34. $end_date = date('Y-m-d 14:49:59');
  35. $send_date = date('Y-m-d 14:53:00');
  36. }
  37. //발송대상이 존재 하는지
  38. //지역별 발송 대상자가 존재 하는지
  39. // $sql = "select ds_area
  40. // from sale_master_standby
  41. // where create_date between '".$start_date."' and '".$end_date."'
  42. // and status = '0'
  43. // limit 1
  44. // ";
  45. $area_data = array();
  46. $stand_data = array();
  47. //지역별 발송 대상자가 존재 하는지
  48. $sql = "select cd_standby, ds_area
  49. from sale_master_standby
  50. where create_date between '".$start_date."' and '".$end_date."'
  51. and status = '0'
  52. ";
  53. $res = mysql_query($sql);
  54. while($col = mysql_fetch_array($res)) {
  55. if(empty($col['ds_area'])) {
  56. continue;
  57. }
  58. $area_data[] = $col['ds_area'];
  59. $stand_data[] = $col['cd_standby'];
  60. }
  61. // print_r($stand_data);
  62. // echo $cnt;
  63. // echo $sql;
  64. $area_data1 = array_unique($area_data);
  65. if(count($stand_data) > 0) {
  66. $area_str = implode("|", $area_data1);
  67. $stand_str = implode(",", $stand_data);
  68. //가져온 데이터는 수집 완료로 변경
  69. mysql_query("update sale_master_standby set status = '1' where cd_standby in ($stand_str) ");
  70. $q_sql = "select t2.cd_dealerid, t1.nm_area, t2.ds_type, t1.nm_company,
  71. (case when t2.ds_type = 'D0' then CONCAT_WS('-', t1.nm_hp_01, t1.nm_hp_02, t1.nm_hp_03)
  72. when t2.ds_type = 'D1' then CONCAT_WS('-', t2.nm_hp_01, t2.nm_hp_02, t2.nm_hp_03)
  73. else ''
  74. end ) as nm_hp
  75. , (case when t2.ds_type = 'D0' then t1.nm_name
  76. when t2.ds_type = 'D1' then t2.nm_name
  77. else ''
  78. end ) as nm_name
  79. from
  80. (
  81. SELECT nm_name, cd_dealerid, nm_area, cd_dealer, nm_hp_01, nm_hp_02, nm_hp_03, nm_company
  82. from dealer_master
  83. where ds_delind = 'N'
  84. and ds_status = 'Z0'
  85. ) t1
  86. left JOIN dealer_master as t2 on t1.cd_dealer = t2.cd_dealer_p and ds_delind = 'N'
  87. where t1.nm_area regexp '$area_str'
  88. ";
  89. //지역 포함 딜러 수집
  90. $r = mysql_query($q_sql);
  91. // echo $q_sql;
  92. // exit;
  93. $cnt = mysql_num_rows($r);
  94. if($cnt > 0) {
  95. //발송 마스터 등록
  96. $master_sql = "insert into kakao_biztalk set
  97. status = 0
  98. , senderKey = '".$senderKey."'
  99. , tmpltCode = '".$tmpltCode."'
  100. , resMethod = '".$resMethod."'
  101. , send_date = '".$send_date."'
  102. ";
  103. $master_res = mysql_query($master_sql);
  104. $cd_talk = mysql_insert_id();
  105. //딜러별 메시지 최대 30개 생성
  106. while($dealer = mysql_fetch_array($r)) {
  107. $car_info = "";
  108. $contents_sql = "select contents
  109. from sale_master_standby
  110. where cd_standby in ($stand_str)
  111. and ds_area regexp '".str_replace(',', '|', $dealer[nm_area])."'
  112. limit 30";
  113. // echo $contents_sql;
  114. // exit;
  115. $contents_cnt = 0;
  116. $contents_res = mysql_query($contents_sql);
  117. while($contents_row = mysql_fetch_array($contents_res)) {
  118. // if($contents_cnt%2 == 0) {
  119. // $car_info.= $contents_row['contents'];
  120. // }else {
  121. // $car_info.= ' / '. $contents_row['contents'].'\n';
  122. // }
  123. // $contents_cnt++;
  124. $car_info.= $contents_row['contents'].'\n';
  125. }
  126. // if($contents_cnt%2 == 1) {
  127. // $car_info.= '\n';
  128. // }
  129. $contents = $dealer[nm_company]."님 매물이 업데이트 되었습니다.
  130. $car_info
  131. 유프로 관리페이지에 접속하셔서 차량정보를
  132. 확인하세요!";
  133. //발송 대기 상태로 변경
  134. $recipient_sql = "INSERT INTO kakao_biztalk_recipient ( cd_talk, phone, status, contents)
  135. SELECT '$cd_talk', '$dealer[nm_hp]', '0', '$contents' FROM dual
  136. WHERE not EXISTS
  137. (
  138. SELECT cd_talk, phone, status, contents
  139. FROM kakao_biztalk_recipient
  140. WHERE cd_talk = '$cd_talk'
  141. and phone = '$dealer[nm_hp]'
  142. and status = '0'
  143. and contents = '$contents'
  144. )
  145. ";
  146. mysql_query($recipient_sql);
  147. }
  148. mysql_query("update kakao_biztalk set status = '1' where cd_talk = '".$cd_talk."' ");
  149. }
  150. }
  151. ?>