From 5c0b4dc627027acd89f6c580063039e296ac90a1 Mon Sep 17 00:00:00 2001 From: ycc Date: Mon, 19 Apr 2021 11:27:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E7=BA=BF=E4=BF=A1=E6=81=AF=E6=8E=A8?= =?UTF-8?q?=E8=8D=90=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/controllers/information.php | 93 ++- application/models/information_model.php | 23 +- .../models/recommends_and_tips_model.php | 61 ++ .../third_party/recommend/views/bind_info.php | 30 +- application/views/mobile_first/ah-next.php | 112 +++ application/views/mobile_first/ah-pc.php | 647 ++++++++---------- 6 files changed, 584 insertions(+), 382 deletions(-) create mode 100644 application/models/recommends_and_tips_model.php create mode 100644 application/views/mobile_first/ah-next.php diff --git a/application/controllers/information.php b/application/controllers/information.php index d4527b2c..bf110899 100644 --- a/application/controllers/information.php +++ b/application/controllers/information.php @@ -21,8 +21,10 @@ class Information extends CI_Controller $this->load->model('InfoMetas_model'); $this->load->model('Infoauthors_model'); $this->load->model('InfoSMS_model'); + $this->load->model('recommends_and_tips_model'); $this->load->library('Amplib'); //加载AMP处理类 $this->load->library('html_optimize_lib'); //加载HTML优化类 + } public function index() @@ -585,6 +587,7 @@ class Information extends CI_Controller default: } + //替换模板中的标签 $template = str_replace('', $information->ic_seo_title, $template); $template = str_replace('', $information->ic_seo_description, $template); @@ -720,11 +723,17 @@ class Information extends CI_Controller $template = str_replace('', $template_H1, $template); + //推荐信息或者产品 + //信息推荐 暂时不用,未来用广告系统替代 + $template_recommand = $this->recommand_information($information); + $template = str_replace('', $this->load->view($template_path . '-next', array('recommands'=>$template_recommand), TRUE), $template); + //广告,改叫tips,防止被插件屏蔽 + if(!empty($template_recommand['Tips Right'])) { + $template = str_replace('', "
".$template_recommand['Tips Right']."
", $template); + } + //非产品页面 if (empty(get_meta($information->ic_id, 'meta_product_code'))) { - //信息推荐 暂时不用,未来用广告系统替代 - //$template_NEXT = $this->call_mobile_template_NEXT($template_path, $information->is_id); - //$template = str_replace('', $template_NEXT, $template); $addthis_widget = $this->load->view($template_path . '-add-this', false, true); $template = str_replace('', $addthis_widget, $template); } else { @@ -1059,6 +1068,83 @@ class Information extends CI_Controller return ''; } + //根据推荐规则进行查询 + function recommand_information_rule($information, $root_information, $recommand, &$exclude_ids) + { + $data = array(); + switch ($recommand->ir_rule) { + case 'rule_same_node_keyword'://同节点关键词 + $keywords = explode(',', $recommand->ir_keyword); + $data = $this->Information_model->search_by_words_2($root_information->is_path, $keywords, $exclude_ids); + break; + case 'rule_same_url_keyword'://同URL关键词 + $keywords = explode(',', $recommand->ir_keyword); + $url = trim($information->ic_url); + $url = substr($url, 0, strpos($url, '/', 1) + 1); + $data = $this->Information_model->search_by_words($url, $keywords, $exclude_ids); + break; + case 'rule_same_node_random'://同节点随机 + $data = $this->Information_model->random(1, $root_information->is_id, $exclude_ids); + break; + case 'rule_this_node_random'://指定节点下随机 + $data = $this->Information_model->random(1, $recommand->ir_pointer_is_id, $exclude_ids); + break; + case 'rule_range_random'://范围内随机,同读取备用节点 + break; + case 'rule_show_tips'://显示广告 + $data = $this->recommends_and_tips_model->tips_detail($recommand->ir_pointer_it_id); + return array($recommand->ir_name => $data); + break; + case 'rule_no_show'://不显示 + return array($recommand->ir_name => false); + break; + default: //'rule_parent'://继承上级规则则留空,程序会循环一遍分组的规则 + ; + } + //读取备用节点 + if (empty($data) && !empty($recommand->ir_urls)) {//查不到信息并且备选urls不为空,则随机选一条 + $url_array = explode("\n", $recommand->ir_urls); + $data = $this->Information_model->Detail($url_array[rand(0, count($url_array) - 1)]); + } + if (!empty($data)) { + $exclude_ids[] = $data->is_id; + } + //读取附加移动端图片 + $data->mobile_photo=get_meta($data->ic_id, 'meta_addon_picture_mobile'); + return array($recommand->ir_name => $data); + } + + //获取当前信息所有的推荐信息和广告内容 + function recommand_information($information) + { + $data = array(); + $group_detail = $this->Information_model->get_detail_by_path($information->is_path, 0); //信息所属分组,根据分组进行不同推荐 + $group_recommands = $this->recommends_and_tips_model->recommends_list($group_detail->is_id);//节点下所有的推荐规则 + $root_detail = $this->Information_model->get_detail_by_path($information->is_path, 1); //信息所属分类,获取信息顶级节点内容 + $root_recommands = $this->recommends_and_tips_model->recommends_list($root_detail->is_id);//节点下所有的推荐规则 + + $exclude_ids = array($information->is_id);//需要排除的is_id,防止通过页面显示相同内容,默认排除本身,每个推荐内容都需要排除已经推荐过的 + + foreach ($root_recommands as $item) { + $result = $this->recommand_information_rule($information, $root_detail, $item, $exclude_ids); + if (!empty($result)) { + $data += $result; + } + } + + + foreach ($group_recommands as $item) { + if (empty($data[$item->ir_name])) { + $result = $this->recommand_information_rule($information, $root_detail, $item, $exclude_ids); + if (!empty($result)) { + $data += $result; + } + } + } + //print_r($data); + return $data; + } + function call_mobile_template_NEXT($template_path, $is_id) { $data['detail'] = $this->Information_model->Detail($is_id); @@ -1169,6 +1255,7 @@ class Information extends CI_Controller return $this->load->view($template_path . '-next', $data, TRUE); } + //更新静态文件 //不用参数提交的原因是可能url带有特殊字符,CI会报错 public function update_cache($static_html_url = false, $delete_only = false) diff --git a/application/models/information_model.php b/application/models/information_model.php index 51cd3268..523f6bb3 100644 --- a/application/models/information_model.php +++ b/application/models/information_model.php @@ -65,15 +65,30 @@ class Information_model extends CI_Model { } //根据关键词来搜索内容 - function search_by_words($url,array $words,$self_is_id){ + function search_by_words($url,array $words,$exclude_ids){ $this->init(); $this->topNum = 1; $sql_keyword=' AND ( 1=1 '; foreach ($words as $item) { - $sql_keyword .=" AND ic_title like '%". $this->HT->escape_like_str($item) ."%' "; + $sql_keyword .=" AND ic_title like '%". $this->HT->escape_like_str(trim($item)) ."%' "; } $sql_keyword.=' ) '; - $this->search =" AND ic_url LIKE '$url%' ". $sql_keyword.' AND is_id<>'.$self_is_id; + $this->search =" AND ic_status=1 AND ic_url LIKE '$url%' ". $sql_keyword.' AND is_id NOT IN('.implode(',',$exclude_ids).',0)'; + $this->orderBy = " ORDER BY is1.is_level ASC, is1.is_sort ASC,ic_datetime DESC "; + return $this->GetList(); + } + + //在当前节点下搜索关键词 + function search_by_words_2($path,array $words,$exclude_ids){ + $this->init(); + $this->topNum = 1; + $sql_keyword=' AND ( 1=1 '; + foreach ($words as $item) { + $sql_keyword .=" AND ic_title like '%". $this->HT->escape_like_str(trim($item)) ."%' "; + } + $sql_keyword.=' ) '; + $this->path = " AND is1.is_path LIKE '$path%' "; + $this->search =' AND ic_status=1 AND is_id NOT IN('.implode(',',$exclude_ids).',0)'; $this->orderBy = " ORDER BY is1.is_level ASC, is1.is_sort ASC,ic_datetime DESC "; return $this->GetList(); } @@ -84,7 +99,7 @@ class Information_model extends CI_Model { $this->topNum = $topnum; $this->search = " AND is_parent_id =". $this->HT->escape($is_parent_id); $exclude_ids_string=implode(',',$exclude_ids); - $this->search .= " AND is_id NOT in ($exclude_ids_string,0)"; + $this->search .= " AND ic_status=1 AND is_id NOT in ($exclude_ids_string,0)"; $this->orderBy = " ORDER BY NewID() "; return $this->GetList(); } diff --git a/application/models/recommends_and_tips_model.php b/application/models/recommends_and_tips_model.php new file mode 100644 index 00000000..6a02f0eb --- /dev/null +++ b/application/models/recommends_and_tips_model.php @@ -0,0 +1,61 @@ +HT = $this->load->database('HT', TRUE); + } + + + public function recommends_list($is_id) + { + $sql = " SELECT + ir.ir_id + ,ir.ir_is_id + ,ir.ir_keyword + ,ir.ir_name + ,ir.ir_pointer_is_id + ,ir.ir_pointer_it_id + ,ir.ir_rule + ,ir.ir_urls + ,ir.ir_datetime + ,ir.ir_sitecode + from infoRecommends ir + where 1=1 + AND ir.ir_sitecode=? + AND ir.ir_is_id=? + "; + $query = $this->HT->query($sql, array($this->config->item('site_code'), $is_id)); + //print_r($this->INFO->queries); + return $query->result(); + } + + public function tips_detail($it_id) + { + $sql = " SELECT TOP 1 + it.it_id + ,it.it_title + ,it.it_expires + ,it.it_content + ,it.it_sitecode + ,it.it_datetime + from infoTips it + where 1=1 + AND it.it_sitecode=? + AND it.it_id=? + AND it.it_expires<=getdate() + "; + $query = $this->HT->query($sql, array($this->config->item('site_code'), $it_id)); + //print_r($this->INFO->queries); + if ($query->num_rows() > 0) { + $row = $query->row(); + return $row; + } else { + return FALSE; + } + } + +} \ No newline at end of file diff --git a/application/third_party/recommend/views/bind_info.php b/application/third_party/recommend/views/bind_info.php index 49798700..89692788 100644 --- a/application/third_party/recommend/views/bind_info.php +++ b/application/third_party/recommend/views/bind_info.php @@ -8,42 +8,42 @@
- +
- +
-
-
-
-
- +
- +
diff --git a/application/views/mobile_first/ah-next.php b/application/views/mobile_first/ah-next.php new file mode 100644 index 00000000..3dd24a89 --- /dev/null +++ b/application/views/mobile_first/ah-next.php @@ -0,0 +1,112 @@ +
+ +

Visit Vietnam with Asia Highlights

+

Asia Highlights welcomes the chance to help you design your perfect trip to Vietnam. + Check out the following links to learn more about our tours and get a head start on planning your + hassle-free vacation today!

+ + +
+ <?php echo $recommands['Tour A']->ic_title; ?> + +
+ + + +
+ <?php echo $recommands['Tour B']->ic_title; ?> + +
+ + + +
+ <?php echo $recommands['Tour C']->ic_title; ?> + +
+ + + +
+ <?php echo $recommands['Tour D']->ic_title; ?> + +
+ + + + +

Related Articles

+ + + + + + + + + + + + + + + + + +
diff --git a/application/views/mobile_first/ah-pc.php b/application/views/mobile_first/ah-pc.php index 122344b5..fb2276cc 100644 --- a/application/views/mobile_first/ah-pc.php +++ b/application/views/mobile_first/ah-pc.php @@ -1,361 +1,288 @@ - - - - - - - <!--@TITLE@--> - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - -
- -
- -
- -
-
- Myanmar Novices -
- - - -
- - - - - -
- - We are here to help you...
Start planning your tailor-made Asia tour with 1-1 - help from our travel advisors. - - Create My Trip - -
-
- -
-
- -
- -
-
About Us
-
At Asia Highlights, we create your kind of journey — your dates, your destinations, at your pace. Not just any journey, but the unique trip with the exceptional experiences you're looking for — whether it's a family vacation, a honeymoon, or your annual break. more - ... -
- - Rated - 4.8 out of 5 | Excellent -
-
- - -
- -
- - -
- -
Featured on
- Medias - -
- - -
- - -
-
-
- - - - - - - - - - - + + + + + + + <!--@TITLE@--> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+ + + + + + + +
+ + + + + +
+ + We are here to help you...
Start planning your tailor-made Asia tour with 1-1 + help from our travel advisors. + + Create My Trip + +
+
+ +
+
+ +
+ +
+
About Us
+
At Asia Highlights, we create your kind of journey — your dates, your destinations, at your pace. Not just any journey, but the unique trip with the exceptional experiences you're looking for — whether it's a family vacation, a honeymoon, or your annual break. more + ... +
+ + Rated + 4.8 out of 5 | Excellent +
+
+ + +
+ +
+ + +
+ +
Featured on
+ Medias + +
+ + +
+ + +
+
+
+ + + + + + + + + + + \ No newline at end of file