diff --git a/application/third_party/tripadvisor_spider/config/config.php b/application/third_party/tripadvisor_spider/config/config.php index 022d61f8..3b452f64 100644 --- a/application/third_party/tripadvisor_spider/config/config.php +++ b/application/third_party/tripadvisor_spider/config/config.php @@ -18,10 +18,10 @@ $config['tripadvisor_website'] = array( 'Zhangjiajie' => 'http://www.tripadvisor.com/Attraction_Review-g494933-d8077695-Reviews{PAGENUM}China_Highlights_Zhangjiajie_Day_Tour-Zhangjiajie_Hunan.html', 'HongKong' => 'https://www.tripadvisor.com/Attraction_Review-g294217-d10243951-Reviews{PAGENUM}China_Highlights_Hong_Kong-Hong_Kong.html', 'Panda' => 'https://www.tripadvisor.com/Attraction_Review-g297463-d11489225-Reviews{PAGENUM}China_Highlights-Chengdu_Sichuan.html', - 'tp_Beijing' => 'https://www.tripadvisor.com/Attraction_Review-g294212-d4006739-Reviews-The_Trippest_Mini_Group_Tours-Beijing.html', - 'tp_Xian' => 'https://www.tripadvisor.com/Attraction_Review-g298557-d10999897-Reviews-Xi_an_Trippest_Mini_Group_Tours-Xi_an_Shaanxi.html', - 'tp_Shanghai' => 'https://www.tripadvisor.com/Attraction_Review-g308272-d6222868-Reviews-Shanghai_Trippest_Mini_Group_Tours-Shanghai.html', - 'tp_Guilin' => 'https://www.tripadvisor.com/Attraction_Review-g298556-d14121459-Reviews-Trippest_Mini_Group_Tours-Guilin_Guangxi.html' + 'tp_Beijing' => 'https://www.tripadvisor.com/Attraction_Review-g294212-d4006739-Reviews{PAGENUM}-The_Trippest_Mini_Group_Tours-Beijing.html', + 'tp_Xian' => 'https://www.tripadvisor.com/Attraction_Review-g298557-d10999897-Reviews{PAGENUM}-Xi_an_Trippest_Mini_Group_Tours-Xi_an_Shaanxi.html', + 'tp_Shanghai' => 'https://www.tripadvisor.com/Attraction_Review-g308272-d6222868-Reviews{PAGENUM}-Shanghai_Trippest_Mini_Group_Tours-Shanghai.html', + 'tp_Guilin' => 'https://www.tripadvisor.com/Attraction_Review-g298556-d14121459-Reviews{PAGENUM}-Trippest_Mini_Group_Tours-Guilin_Guangxi.html' ); diff --git a/application/third_party/tripadvisor_spider/controllers/index.php b/application/third_party/tripadvisor_spider/controllers/index.php index 6b7e266f..2b8124b6 100644 --- a/application/third_party/tripadvisor_spider/controllers/index.php +++ b/application/third_party/tripadvisor_spider/controllers/index.php @@ -267,24 +267,40 @@ class Index extends CI_Controller { } } - public function get_destination_reviews($destination = null){ + public function get_destination_reviews($destination = null,$pagenum = null){ + set_time_limit(0); $ta_website = $this->config->item('tripadvisor_website'); //根据传入的目的地简码获取TA的相应评论列表 if(isset($ta_website[$destination])){ $url = $ta_website[$destination]; + if($pagenum != ''){ + $url = str_replace('{PAGENUM}','-or'.$pagenum,$url); + }else{ + $url = str_replace('{PAGENUM}','',$url); + } //根据url获取页面内容 $content = GET_HTTP($url); - //进行页面解析 $html_object = str_get_html($content); - - //获取第一页列表上的url - foreach ($html_object->find('.reviewSelector .quote a') as $a_info){ - $url = 'https://www.tripadvisor.com'.$a_info->href; - + $return = new stdClass(); + $return->urls = array(); + //获取每个页面上的url + foreach ($html_object->find('.reviewSelector .quote a') as $reviews_url){ + array_push($return->urls,'https://www.tripadvisor.com'.$reviews_url->href); } + print_r(json_encode($return)); + } + } + + //查看抓取到的所有信息 + public function get_all_reviews($destination){ + if($destination != ''){ + $all_reviews = $this->Tripadvisor_Review_model->get_all_reviews($destination); + $return = array(); + $return['list'] = $all_reviews; + print_r(json_encode($return)); } } @@ -294,8 +310,8 @@ class Index extends CI_Controller { $destination = $this->input->get_post('destination'); $html_num = $this->input->get_post('html_num'); - //$url = 'https://www.tripadvisor.com/ShowUserReviews-g294212-d4006739-r666168101-The_Trippest_Mini_Group_Tours-Beijing.html'; - $destination = 'tp_Beijing'; + //$url = 'https://www.tripadvisor.com/ShowUserReviews-g308272-d6222868-r599123490-Shanghai_Trippest_Mini_Group_Tours-Shanghai.html'; + //$destination = 'tp_Beijing'; if($url != ''){ $content = GET_HTTP($url); @@ -307,15 +323,28 @@ class Index extends CI_Controller { //提取局部,不做整个页面的寻找元素,提升效率 $meta_inner = $html_object->find('.meta_inner'); + $detail_data->user_loc = ''; + $detail_data->pic = array(); foreach($meta_inner as $detail_info){ //记录该条记录的id $detail_data->html_id = $html_num; + //获取评论者帐号 foreach($detail_info->find('.info_text') as $review_name){ $detail_data->review_name = $review_name->first_child()->innertext; } + //获取评论者帐号 + foreach($detail_info->find('.info_text .userLoc strong') as $user_loc){ + $detail_data->user_loc = $user_loc->innertext; + } + + //抓取评论时间 + foreach($detail_info->find('.ratingDate') as $ratingDate){ + $detail_data->rating_date = date('Y-m-d',strtotime($ratingDate->title)); + } + //获取评论者ID foreach($detail_info->find('.reviewSelector') as $review_id){ $detail_data->review_id = str_replace('review_','',$review_id->id); @@ -337,13 +366,21 @@ class Index extends CI_Controller { $detail_data->content = $content->innertext; } - //获取评论时间 - foreach($detail_info->find('.prw_reviews_stay_date_hsx') as $review_date){ - $detail_data->review_date = str_replace('Date of experience: ','',$review_date->innertext); + //获取体验时间 + foreach($detail_info->find('.prw_reviews_stay_date_hsx') as $experience_date){ + $detail_data->experience_date = date('Y-m-d',strtotime(str_replace('Date of experience: ','',$experience_date->innertext))); + } + + //抓取图片 + foreach($detail_info->find('.imgWrap .noscript') as $imgWrap){ + $imgWrap->src = str_replace('photo-l','photo-s',$imgWrap->src); + array_push($detail_data->pic,$imgWrap->src); } } //拿到数据后进行入库 + $this->Tripadvisor_Review_model->add_reviews($detail_data); + print_r(json_encode($detail_data)); } } diff --git a/application/third_party/tripadvisor_spider/models/Tripadvisor_Review_model.php b/application/third_party/tripadvisor_spider/models/Tripadvisor_Review_model.php index 25414fc7..d2f8cf21 100644 --- a/application/third_party/tripadvisor_spider/models/Tripadvisor_Review_model.php +++ b/application/third_party/tripadvisor_spider/models/Tripadvisor_Review_model.php @@ -161,5 +161,39 @@ class Tripadvisor_Review_model extends CI_Model { $result = $query->result(); return $result; } + + public function add_reviews($detail_data){ + $sql = " + IF NOT EXISTS( + select tr_review_id from Ta_Reviews where tr_review_id = ? + ) + insert into Ta_Reviews + ( + tr_destination, + tr_review_id, + tr_review_title, + tr_content, + tr_member_name, + tr_member_loc, + tr_member_starts, + tr_review_date, + tr_visited_date, + tr_review_pics, + tr_gri_no, + tr_tgi_sn, + tr_datetime + )values( + ?,?,?,?,?,?,?,?,?,?,?,?,GETDATE() + ) + "; + $query = $this->INFO->query($sql, array($detail_data->review_id,$detail_data->destination,$detail_data->review_id,$detail_data->title,$detail_data->content,$detail_data->review_name,$detail_data->user_loc,$detail_data->star_nums,$detail_data->rating_date,$detail_data->experience_date,json_encode($detail_data->pic),'','')); + //$result = $query->result(); + } + + public function get_all_reviews($destination){ + $sql = 'select * from Ta_Reviews where tr_destination = ? order by tr_review_date desc'; + $query = $this->INFO->query($sql,array($destination)); + return $query->result(); + } } diff --git a/application/third_party/tripadvisor_spider/views/third_party_input.php b/application/third_party/tripadvisor_spider/views/third_party_input.php index 0643046e..eb84da06 100644 --- a/application/third_party/tripadvisor_spider/views/third_party_input.php +++ b/application/third_party/tripadvisor_spider/views/third_party_input.php @@ -10,9 +10,15 @@ +
  • + 列表抓取 +
  • excel导入
  • +
  • + 数据预览 +
  • @@ -30,17 +36,21 @@

    +

    +

    -

    +

    +

    +
    @@ -57,6 +67,50 @@
    + +
    +
    +
    + +
    +
    + +
    + +
    +
    + +
    +
    +
    + +
    + +
    +
    + +
    +
    + @@ -70,6 +124,7 @@ $(function(){ //获取填写的url var ta_url = $('#ta_url').val(); var stars = ''; + var pic_htm = ''; if(ta_url == ''){ alert('请填写需要采集的TA地址'); }else{ @@ -80,8 +135,14 @@ $(function(){ var data = $.parseJSON(json); console.log(data); $('.ta_content').html(data.content); - $('.review_date').html('Date of experience: '+data.review_date); + $('.experience_date').html('Date of experience: '+data.experience_date); $('.review_name').html(data.review_name); + $('.user_loc').html(data.user_loc); + $('.rating_date').html('Reviewed:'+data.rating_date); + for(var i=0;i

    '; + } + $('.review_pic').html(pic_htm); $('.ta_title').html(''+data.title+''); if(data.star_nums){ for(var i=0;i

    '+jsondata.list[y].tr_member_loc+'

    '; + for(var i=0;i

    Reviewed: '+jsondata.list[y].tr_review_date+'

    '+jsondata.list[y].tr_content+'

    '; + html += '

    '; + + if($.parseJSON(jsondata.list[y].tr_review_pics).length > 0){ + for(var j=0;j<$.parseJSON(jsondata.list[y].tr_review_pics).length;j++){ + html += '

    '; + } + } + + html += '

    Date of experience: '+jsondata.list[y].tr_visited_date+'


    '; + } + html += '

    total nums : '+jsondata.list.length+'

    ' + $('#list_view_content').html(html); + } + }); + } + }); }); \ No newline at end of file diff --git a/webht/controllers/onlineoffice.php b/webht/controllers/onlineoffice.php new file mode 100644 index 00000000..0d8b9d97 --- /dev/null +++ b/webht/controllers/onlineoffice.php @@ -0,0 +1,95 @@ +output->enable_profiler(TRUE); + $this->permission->is_admin(true); + $this->load->model('Navigation_model'); + $this->load->model('Operator_model'); + $this->admin_data=$this->session->userdata('admin_chtcdn'); + $this->uid=$this->admin_data['OPI_SN']; + } + + public function index() + { + $data['mid']=$this->uid; + $this->load->view('n-header', $data); + $user_data=$this->Operator_model->get_webhtuser_by_id($this->admin_data['whu_uid']); + $data['whu_ip']=$user_data->whu_ip; + $data['whu_mac']=$user_data->whu_mac; + $this->load->view('onlineoffice/wakeup',$data); + $this->load->view('n-footer'); + } + + + public function wakeonlan($ip,$mac,$port=7){ + //需要在system32目录下放置wolcmd.exe来启动 + $mac=str_replace(':','',$mac); + $last_line = system("wolcmd $mac $ip 255.255.255.0 7", $retval); + echo $last_line; + + return true; + + $addr_byte = explode(':', $mac); + $hw_addr = ''; + for ($i=0; $i <6; $i++){ + $hw_addr .= chr(hexdec($addr_byte[$i])); + } + $msg = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255); + for ($i = 1; $i <= 16; $i++) { + $msg .= $hw_addr; +} + $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); + if ($socket == false) { + echo "create socket failed!\n"; + echo "error:'".socket_last_error($socket)."' - " . socket_strerror(socket_last_error($socket)); + return FALSE; + } else { + $opt_ret = socket_set_option($socket,SOL_SOCKET, SO_BROADCAST, TRUE); + if($opt_ret <0) { + echo "setsockopt() failed, error: " . strerror($opt_ret) . "\n"; + return FALSE; + } + + if(socket_sendto($socket, $msg, strlen($msg), 0, $ip, $port)) { + echo "唤醒数据包发送成功!"; + socket_close($socket); + return TRUE; + } else { + echo "唤醒数据包发送失败!"; + return FALSE; + } + } + } + + //检查端口是否打开,用来判断电脑是否启动成功 + public function ping($ip,$port=3389) { + $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); + socket_set_nonblock($sock); + @socket_connect($sock,$ip, $port); + socket_set_block($sock); + //返回值说明:2关闭,1打开,0超时 + switch(socket_select($r = array($sock), $w = array($sock), $f = array($sock), 5)){ + case 0: + echo '努力启动中...'; + break; + case 1: + echo '电脑启动成功!'; + break; + case 2: + echo '电脑启动成功,远程端口未打开,联系YCC开启权限'; + break; + } + } + + +} \ No newline at end of file diff --git a/webht/models/operator_model.php b/webht/models/operator_model.php index 720d19f0..0a71edca 100644 --- a/webht/models/operator_model.php +++ b/webht/models/operator_model.php @@ -161,6 +161,29 @@ class Operator_model extends CI_Model } return $result; } + + public function get_webhtuser_by_id($whu_uid){ + $sql=" + SELECT TOP 1 wu.whu_uid, + wu.whu_uname, + wu.whu_email, + wu.whu_ip, + wu.whu_mac, + wu.whu_status, + wu.whu_isadmin, + wu.department + FROM webht_user wu + WHERE wu.whu_uid = ? + "; + $query = $this->HT->query($sql,array($whu_uid)); + if ($query->num_rows() > 0) + { + $row = $query->row(); + return $row; + }else{ + return false; + } + } public function get_webhtuser_by_name($whu_uname,$filed='whu_uid',$flag=false) { @@ -178,6 +201,7 @@ class Operator_model extends CI_Model $result=$result[0]->$filed; } } + //print_r($this->HT->queries); return $result; } @@ -188,7 +212,8 @@ class Operator_model extends CI_Model { return false; } - + //echo $OPI_Name; + $sql = "SELECT TOP $top oi.OPI_SN, \n" . " oi.OPI_Name, \n" . " oi.OPI_Email,OPI_MoveTelephone,OPI_Telephone, \n" diff --git a/webht/third_party/partners/controllers/index.php b/webht/third_party/partners/controllers/index.php index abf5a129..2e1b1d00 100644 --- a/webht/third_party/partners/controllers/index.php +++ b/webht/third_party/partners/controllers/index.php @@ -53,7 +53,11 @@ class Index extends CI_Controller $data['status']=$status; $data['list']=$this->Partners_model->get_orders($user,$status,$date1,$date2,$COLI_ID); //if ($COLI_ID!==false) { - $this->load->view('index/order_search',$data); + $grouptpl='index/order_search'; + if ($this->session->userdata('isapp')) { + $grouptpl='index/group_app'; + } + $this->load->view($grouptpl,$data); return; //} @@ -62,6 +66,7 @@ class Index extends CI_Controller $this->load->view('index/group'); $this->load->view('footer'); } + //地接与导游信息 public function guideinfo($GRI_SN='') { @@ -93,7 +98,11 @@ class Index extends CI_Controller $data=array(); $this->load->model('Mailinfo_model'); $data['mailinfo']=$this->Mailinfo_model->get_mail_info($COLI_ID); - $this->load->view('index/mailinfo', $data); + $tpl='index/mailinfo'; + if ($this->session->userdata('isapp')) { + $tpl='index/mailinfo_app'; + } + $this->load->view($tpl, $data); } //来往邮件正文内容 public function mail_detail($MAI_SN) @@ -102,7 +111,11 @@ class Index extends CI_Controller $this->load->model('Mailinfo_model'); $data['maildetail']=$this->Mailinfo_model->mail_detail($MAI_SN); $data['mailattach']=$this->Mailinfo_model->mail_attach($MAI_SN); - $this->load->view('index/maildetail', $data); + $tpl='index/maildetail'; + if ($this->session->userdata('isapp')) { + $tpl='index/maildetail_app'; + } + $this->load->view($tpl, $data); } } diff --git a/webht/third_party/partners/models/mailinfo_model.php b/webht/third_party/partners/models/mailinfo_model.php index ca8596c2..9dab7897 100644 --- a/webht/third_party/partners/models/mailinfo_model.php +++ b/webht/third_party/partners/models/mailinfo_model.php @@ -17,6 +17,7 @@ class Mailinfo_model extends CI_Model { { $sql="SELECT MAI_SN, MAI_SendDate, + MOI_ReadState, MAI_COLI_SN, MAI_From, MAI_To, diff --git a/webht/third_party/partners/models/partners_model.php b/webht/third_party/partners/models/partners_model.php index 3cad3b63..7ac8a80f 100644 --- a/webht/third_party/partners/models/partners_model.php +++ b/webht/third_party/partners/models/partners_model.php @@ -90,7 +90,8 @@ class Partners_model extends CI_Model { } $ApplyDate_sql=''; if ($date1) { - $ApplyDate_sql=" AND COLI_ApplyDate Between '$date1' AND '$date2' "; + //$ApplyDate_sql=" AND COLI_ApplyDate Between '$date1' AND '$date2' "; + $ApplyDate_sql=" AND COLI_OrderStartDate Between '$date1' AND '$date2' ORDER BY COLI_OrderStartDate ASC"; }elseif(!$date1 && $status==5) { $default_date=date("Y-m-d",strtotime("-15 day")); $ApplyDate_sql=" AND COLI_OrderStartDate>'$default_date' ORDER BY COLI_OrderStartDate ASC"; diff --git a/webht/third_party/partners/views/index/group_app.php b/webht/third_party/partners/views/index/group_app.php new file mode 100644 index 00000000..f0346a7e --- /dev/null +++ b/webht/third_party/partners/views/index/group_app.php @@ -0,0 +1,42 @@ + $g) { ?> +
    +
    +
    +

    订单号: COLI_ID; ?>

    +

    订单类型:COLI_OrderType;?>

    +

    报价名称:PTI_Name;?>

    +

    订单人数:COLI_PersonNum;?>

    +

    预订天数:COLI_Days;?>,出发日期是COLI_OrderStartDate;?>

    +

    订单来源于COLI_OrderSource;?>,提交日期是COLI_ApplyDate;?>

    +
    +
    +
    + 客人信息 + 团信息 + 地接导游 + 来往邮件 + SFI_FileName)){ ?> + 确认信 + +
    +
    +
    + + + + + \ No newline at end of file diff --git a/webht/third_party/partners/views/index/maildetail_app.php b/webht/third_party/partners/views/index/maildetail_app.php new file mode 100644 index 00000000..71766d46 --- /dev/null +++ b/webht/third_party/partners/views/index/maildetail_app.php @@ -0,0 +1,26 @@ + + + + + + + 邮件正文 + + + + + + + +
    +

    MAI_Subject; ?>

    +

    发送时间: MAI_SendDate; ?>

    + MAI_BlobContent; ?> +
    + + \ No newline at end of file diff --git a/webht/third_party/partners/views/index/mailinfo.php b/webht/third_party/partners/views/index/mailinfo.php index 84fc9b2b..33c701a4 100644 --- a/webht/third_party/partners/views/index/mailinfo.php +++ b/webht/third_party/partners/views/index/mailinfo.php @@ -12,7 +12,7 @@
    -

    MAI_From); ?> MAI_SendDate; ?>

    +

    MAI_Direction==2 && $v->MOI_ReadState==0)echo ''; ?>MAI_From); ?> MAI_SendDate; ?>

    MAI_Subject; ?>

    diff --git a/webht/third_party/partners/views/index/mailinfo_app.php b/webht/third_party/partners/views/index/mailinfo_app.php new file mode 100644 index 00000000..50f316fe --- /dev/null +++ b/webht/third_party/partners/views/index/mailinfo_app.php @@ -0,0 +1,27 @@ + + + + + + + 来往邮件 + + + + + + + + + + + \ No newline at end of file diff --git a/webht/third_party/pay/controllers/iPayLinksService.php b/webht/third_party/pay/controllers/iPayLinksService.php index 1231650d..b5f5085e 100644 --- a/webht/third_party/pay/controllers/iPayLinksService.php +++ b/webht/third_party/pay/controllers/iPayLinksService.php @@ -602,7 +602,9 @@ class IPayLinksService extends CI_Controller $parent_dealId = $parent_payment->dealId; $parent_note = $this->Note_model->note($parent_dealId); // APP 组的退款查不到原始收款记录 - if (empty($parent_note) && true === $this->IPayLinks_model->if_APP_order($parent_order) ) { + $pure_orderid = strstr($parent_order,"_",true); + $pure_orderid = $pure_orderid===false ? $parent_order : $pure_orderid; + if (empty($parent_note) && true === $this->IPayLinks_model->if_APP_order($pure_orderid) ) { $parent_note = $parent_payment; // 补充字段 $parent_note->IPL_orderId = $parent_order . '_B'; diff --git a/webht/third_party/pay/models/note_model.php b/webht/third_party/pay/models/note_model.php index 8f5fc052..21ecf0a0 100644 --- a/webht/third_party/pay/models/note_model.php +++ b/webht/third_party/pay/models/note_model.php @@ -218,7 +218,13 @@ class Note_model extends CI_Model { 1=1 $this->date -- AND (IPL_noticeTime BETWEEN '2018-07-27 00:00:00' AND '2018-07-27 23:59:59' or IPL_sent<>'send') - or ((ISNULL(gaib.GAI_SN, 0)+ISNULL(gai.GAI_SN, 0))=0 and IPL_payType='pay' AND (IPL_sent<>'closeRecord') and COLI.COLI_ID is null) + or ( + ( + (ISNULL(gaib.GAI_SN, 0)+ISNULL(gai.GAI_SN, 0))=0 and COLI.COLI_ID is null + and IPL_sent not in ('send','closeRecord') + ) + or ISNULL(IPL_sent,'') in ('sendfail','unsend','') + ) ) order by isRecord asc,ipl.IPL_sent desc,IPL_sn desc"; $query = $this->INFO->query($sql); diff --git a/webht/third_party/paypal/controllers/index.php b/webht/third_party/paypal/controllers/index.php index b4dfbc2c..33718108 100644 --- a/webht/third_party/paypal/controllers/index.php +++ b/webht/third_party/paypal/controllers/index.php @@ -611,6 +611,73 @@ class Index extends CI_Controller { return ; } + /*! + * [paypal_webhook description] + * @author LYT + * @date 2019-05-23 + * PAYMENT.SALE.COMPLETED 没有付款人信息 + * * resource.id=txn_id + * * invoice_number=invoice_number + */ + public function paypal_webhook() + { + $raw_post = file_get_contents('php://input'); + if (empty($raw_post)) { + return; + } + $post_data = json_decode($raw_post); + if ($post_data->event_type != 'PAYMENT.SALE.COMPLETED') { + log_message('error',"paypal_webhook" . var_export($raw_post, 1)); + return; + } + $pn_txn_id = $post_data->resource->id; + + $pn_invoice = $post_data->resource->invoice_number; + + $pn_mc_gross = $post_data->resource->amount->total; + + // $pn_item_name = $this->input->post('item_name'); + // if (empty($pn_item_name)) { + // $pn_item_name = $this->input->post('item_name1'); //APP用SDK支付的话会是item_name1 + // empty($pn_item_name) ? $pn_item_name = '' : false; + // } + + // $pn_item_number = $this->input->post('item_number'); + // if (empty($pn_item_number)) { + // $pn_item_number = $this->input->post('item_number1'); //APP用SDK支付的话会是item_number1 + // empty($pn_item_number) ? $pn_item_number = '' : false; + // } + + $pn_mc_currency = $post_data->resource->amount->currency; + $pn_payment_status = $post_data->resource->state; + $pn_payment_date = $post_data->resource->update_time; + // $pn_payer = $post_data->resource->amount->currency; + // $pn_payer_email = $post_data->resource->amount->currency; + $pn_memo = $raw_post; + if (!empty($pn_txn_id)) { + //把PDT时间转成GMT时间 + $pn_payment_date = gmdate('Y-m-d H:i:s', strtotime($pn_payment_date)); + $this->Note_model->save_paypal_note( + $pn_txn_id, + $pn_invoice, + "", + $pn_mc_gross, + "", + "", + $pn_mc_currency, + $pn_payment_status, + "", + "", + $pn_payment_date, + $pn_memo); + log_message('error','paypal-webhook-succeed ' . $pn_txn_id . ' # ' . $pn_invoice); + // echo 'ok'; + } else { + // echo 'no'; + } + return; + } + //解析出订单号 public function analysis_orderid($note_invoice_string) { $data = array(); @@ -718,13 +785,13 @@ class Index extends CI_Controller { */ //找到没有发送的记录 - public function send_note($pn_txn_id = false, $old_ssje=NULL) { + public function send_note($pn_txn_id = false, $old_ssje=NULL, $pn_sn=NULL) { $data = array(); $handpick = empty($pn_txn_id) ? false : TRUE; //优先处理指定的交易号,用于修正交易号直接发送通知 if (!empty($pn_txn_id)) { - $data['unsend_list'] = array($this->Note_model->note($pn_txn_id)); + $data['unsend_list'] = array($this->Note_model->note($pn_txn_id, $pn_sn)); } //找到处理过的的记录 @@ -749,15 +816,27 @@ class Index extends CI_Controller { if (empty($pn_txn_id)) { echo ++$show_index . ' ' . $item->pn_txn_id . '
    '; } + + // webhook的跳过 + $webhook_memo = json_decode($item->pn_memo); + $is_webhook = false; + if (isset($webhook_memo->id) && substr($webhook_memo->id, 0, 2)==="WH") { + $is_webhook = true; + } + if (true === $is_webhook) { + $this->Note_model->update_send($item->pn_txn_id, 'send', $item->pn_sn); + continue; + } + //退款状态默认为已经处理,陆燕在退款前手动通知外联了,系统跳过处理 - if ($item->pn_payment_status == 'Refunded') { + if (strtolower($item->pn_payment_status) == 'refunded') { $this->send_refund($item, $handpick, $old_ssje); // $this->Note_model->update_send($item->pn_txn_id, 'send'); continue; } //只处理完成状态,其他状态由陆燕处理 - if ($item->pn_payment_status !== 'Completed') { + if (strtolower($item->pn_payment_status) !== 'completed') { $this->Note_model->update_send($item->pn_txn_id, 'sendfail'); continue; } @@ -785,7 +864,7 @@ class Index extends CI_Controller { } $orderid_info = json_decode($orderid_info); // 仅自动程序发送提醒 false == $handpick && - if ($item->pn_payment_status === 'Completed' + if (strtolower($item->pn_payment_status) === 'completed' && $orderid_info->ordertype == 'A' && strpos($get_order_no, 'China Train Booking') !== false) { // APP 组的China Train Booking-开头的订单号 // 发送邮件提醒外联核对收款金额, 不写入收款记录 @@ -893,9 +972,8 @@ class Index extends CI_Controller { continue; } - //添加邮件发送记录 - if ($item->pn_send !== 'send') { + if ($item->pn_send !== 'send' && false===$is_webhook) { //给外联发送通知邮件 $fromName = !empty($item->pn_payer) ? $item->pn_payer : ''; $fromEmail = !empty($item->pn_payer_email) ? $item->pn_payer_email : ''; @@ -909,6 +987,8 @@ class Index extends CI_Controller { $this->Paypal_model->save_automail($fromName, $fromEmail, $toName, $toEmail, $subject, $body, $M_RelatedInfo, $M_State, $M_AddTime, 'paypal note'); //添加邮件发送记录 end + $this->Note_model->update_send($item->pn_txn_id, 'send'); + } else { $this->Note_model->update_send($item->pn_txn_id, 'send'); } } @@ -1236,7 +1316,7 @@ class Index extends CI_Controller { $amount = $this->input->post("set_amount"); $last_record = $this->input->post("date_history"); if (empty($amount)) { - $export_list = $this->Note_model->date_range($from_date, $to_date, $currency); + $export_list = $this->Note_model->date_range($from_date, $to_date, $currency, null, false); } else { $allmost_day = intval(ceil($amount/10000)); if ( ! in_array($currency, array('CNY','USD'))) { @@ -1302,7 +1382,7 @@ class Index extends CI_Controller { public function target_amount_recursive($currency, $target_amount, $now_amount, $from_date,$days=10,$list=array(), $last_sn=null, $last_flag=null) { $to_date = date('Y-m-d', strtotime("+$days days", strtotime($from_date))); - $former_list = $this->Note_model->date_range($from_date, $to_date, $currency, $last_sn); + $former_list = $this->Note_model->date_range($from_date, $to_date, $currency, $last_sn, false); $list_index = 0; $last_sn = $last_sn===null ? 0 : $last_sn; $last_flag = $last_flag===null ? null : $last_flag; diff --git a/webht/third_party/paypal/models/note_model.php b/webht/third_party/paypal/models/note_model.php index 0cd9ecd4..ac914479 100644 --- a/webht/third_party/paypal/models/note_model.php +++ b/webht/third_party/paypal/models/note_model.php @@ -24,7 +24,8 @@ class Note_model extends CI_Model { $this->search = false; $this->pn_payment_status = false; $this->pn_txn_id = false; - $this->orderby = ' ORDER BY pn.pn_sn DESC '; + // $this->orderby = ' ORDER BY pn.pn_sn DESC '; + $this->orderby = ' ORDER BY pn_datetime desc,pn_payer desc '; //$this->pn_payment_status=' AND pn_payment_status= '; } @@ -45,7 +46,7 @@ class Note_model extends CI_Model { public function search_date($date) { $this->init(); - $search_sql = " AND (pn.pn_datetime BETWEEN '$date 00:00:00' AND '$date 23:59:59' OR pn_send not in ('send','closeRecord')) "; + $search_sql = " AND (pn.pn_datetime BETWEEN '$date 00:00:00' AND '$date 23:59:59' OR isnull(pn_send,'') in ('sendfail','unsend','')) "; $this->search = $search_sql; $this->orderby=" ORDER BY CASE pn.pn_send WHEN 'sendfail' THEN 1 ELSE 2 END ,pn.pn_sn DESC "; return $this->get_list(); @@ -134,12 +135,13 @@ class Note_model extends CI_Model { } } - public function update_send($pn_txn_id, $pn_send) { + public function update_send($pn_txn_id, $pn_send, $pn_sn=NULL) { $sql = " UPDATE paypal_note SET pn_send = ? WHERE pn_txn_id = ? - "; + "; + $sql .= ($pn_sn===NULL) ? "" : " and pn_sn=$pn_sn "; return $this->HT->query($sql, array($pn_send, $pn_txn_id)); } @@ -153,7 +155,7 @@ class Note_model extends CI_Model { return $this->HT->query($sql, array($pn_invoice, $pn_txn_id)); } - public function date_range($from, $to, $currency=NULL, $pn_sn=NULL) + public function date_range($from, $to, $currency=NULL, $pn_sn=NULL, $includeWH=true) { $this->init(); $search_sql = " AND pn_payment_status in ('Completed','Refunded') "; @@ -164,6 +166,9 @@ class Note_model extends CI_Model { if ( ! empty($pn_sn)) { $search_sql .= " AND pn_sn >= $pn_sn "; } + if (true !== $includeWH) { + $search_sql .= " AND isnull(pn_payer,'')<>'' and ISNULL(pn_payer_email,'')<>'' "; + } $this->search = $search_sql; $this->orderby = " order by pn.pn_sn asc"; return $this->get_list(); diff --git a/webht/third_party/paypal/views/note_list.php b/webht/third_party/paypal/views/note_list.php index 4dcfcb2d..c40e675e 100644 --- a/webht/third_party/paypal/views/note_list.php +++ b/webht/third_party/paypal/views/note_list.php @@ -213,7 +213,7 @@ echo "
    - +