| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <?
- /*
- * 관리자 입찰대기건을 입찰 승인 처리 하여 비즈톡 예약 발송 테이블에 등록한다
- * 실행시간
- * 10:50 (전일 14:50:00 ~ 당일 10:49:59까지 수집된 데이터)
- * 14:50 (당일 10:50:00 ~ 당일 14:49:59까지 수집된 데이터)
- */
- include $_SERVER['DOCUMENT_ROOT'].'/common/lib/comm.php';
- exit;
- ini_set('max_execution_time', 600);
- $senderKey = "4856a5e128f9289082c884d066f1df198cbb1165";
- $tmpltCode = "standby";
- $tmpltCode = "auto_push_30";
- $resMethod = "PUSH";
- $cur_date = date('Y-m-d H:i:s');
- //오전 기준 시간
- $standard_time = 11;
- $cur_time = date('H');
- $is_early = false;
- //기준 시간 보다 작으면 오전 발송
- if($standard_time > $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."' ");
- }
- }
- ?>
|