$cur_time) { $is_early = true; } if($_SERVER['REMOTE_ADDR'] == '220.86.25.88') { // echo "no"; // exit; } if($is_early == true) { $start_date = date('Y-m-d 14:50:00', strtotime(date("Y-m-d"). '-1day')); $end_date = date('Y-m-d 10:09:59'); $send_date = date('Y-m-d 10:15:00'); }else { $start_date = date('Y-m-d 10:10:00'); $end_date = date('Y-m-d 14:49:59'); $send_date = date('Y-m-d 14:53:00'); } //발송대상이 존재 하는지 //지역별 발송 대상자가 존재 하는지 // $sql = "select ds_area // from sale_master_standby // where create_date between '".$start_date."' and '".$end_date."' // and status = '0' // limit 1 // "; $area_data = array(); $stand_data = array(); //지역별 발송 대상자가 존재 하는지 $sql = "select cd_standby, ds_area from sale_master_standby where create_date between '".$start_date."' and '".$end_date."' and status = '0' "; $res = mysql_query($sql); while($col = mysql_fetch_array($res)) { if(empty($col['ds_area'])) { continue; } $area_data[] = $col['ds_area']; $stand_data[] = $col['cd_standby']; } // print_r($stand_data); // echo $cnt; // echo $sql; $area_data1 = array_unique($area_data); if(count($stand_data) > 0) { $area_str = implode("|", $area_data1); $stand_str = implode(",", $stand_data); //가져온 데이터는 수집 완료로 변경 mysql_query("update sale_master_standby set status = '1' where cd_standby in ($stand_str) "); $q_sql = "select t2.cd_dealerid, t1.nm_area, t2.ds_type, t1.nm_company, (case when t2.ds_type = 'D0' then CONCAT_WS('-', t1.nm_hp_01, t1.nm_hp_02, t1.nm_hp_03) when t2.ds_type = 'D1' then CONCAT_WS('-', t2.nm_hp_01, t2.nm_hp_02, t2.nm_hp_03) else '' end ) as nm_hp , (case when t2.ds_type = 'D0' then t1.nm_name when t2.ds_type = 'D1' then t2.nm_name else '' end ) as nm_name from ( SELECT nm_name, cd_dealerid, nm_area, cd_dealer, nm_hp_01, nm_hp_02, nm_hp_03, nm_company from dealer_master where ds_delind = 'N' and ds_status = 'Z0' ) t1 left JOIN dealer_master as t2 on t1.cd_dealer = t2.cd_dealer_p and ds_delind = 'N' where t1.nm_area regexp '$area_str' "; //지역 포함 딜러 수집 $r = mysql_query($q_sql); // echo $q_sql; // exit; $cnt = mysql_num_rows($r); if($cnt > 0) { //발송 마스터 등록 $master_sql = "insert into kakao_biztalk set status = 0 , senderKey = '".$senderKey."' , tmpltCode = '".$tmpltCode."' , resMethod = '".$resMethod."' , send_date = '".$send_date."' "; $master_res = mysql_query($master_sql); $cd_talk = mysql_insert_id(); //딜러별 메시지 최대 30개 생성 while($dealer = mysql_fetch_array($r)) { $car_info = ""; $contents_sql = "select contents from sale_master_standby where cd_standby in ($stand_str) and ds_area regexp '".str_replace(',', '|', $dealer[nm_area])."' limit 30"; // echo $contents_sql; // exit; $contents_cnt = 0; $contents_res = mysql_query($contents_sql); while($contents_row = mysql_fetch_array($contents_res)) { // if($contents_cnt%2 == 0) { // $car_info.= $contents_row['contents']; // }else { // $car_info.= ' / '. $contents_row['contents'].'\n'; // } // $contents_cnt++; $car_info.= $contents_row['contents'].'\n'; } // if($contents_cnt%2 == 1) { // $car_info.= '\n'; // } $contents = $dealer[nm_company]."님 매물이 업데이트 되었습니다. $car_info 유프로 관리페이지에 접속하셔서 차량정보를 확인하세요!"; //발송 대기 상태로 변경 $recipient_sql = "INSERT INTO kakao_biztalk_recipient ( cd_talk, phone, status, contents) SELECT '$cd_talk', '$dealer[nm_hp]', '0', '$contents' FROM dual WHERE not EXISTS ( SELECT cd_talk, phone, status, contents FROM kakao_biztalk_recipient WHERE cd_talk = '$cd_talk' and phone = '$dealer[nm_hp]' and status = '0' and contents = '$contents' ) "; mysql_query($recipient_sql); } mysql_query("update kakao_biztalk set status = '1' where cd_talk = '".$cd_talk."' "); } } ?>