stanley-king 8 anos atrás
pai
commit
8c58b592bc

+ 9 - 1
admin/templates/default/mb_special_item.edit.php

@@ -65,7 +65,10 @@
           <option value="keyword">关键字</option>
           <option value="special">专题编号</option>
           <option value="goods">商品编号</option>
-          <option value="url">链接</option>
+          <option value="url">外部链接</option>
+          <option value="brand">品牌</option>
+          <option value="category">分类</option>
+          <option value="innerurl">内置链接</option>
         </select>
         <input id="dialog_item_image_data" type="text" class="txt w200 marginright marginbot vatop"><br />
         <span id="dialog_item_image_desc" class="dialog-image-desc"></span>
@@ -218,6 +221,11 @@
                 desc_array['special'] = '专题编号会跳转到指定的专题,输入框填写专题编号。';
                 desc_array['goods'] = '商品编号会跳转到指定的商品详细页面,输入框填写商品编号。';
                 desc_array['url'] = '链接会跳转到指定链接,输入框填写完整的URL。';
+
+                desc_array['brand'] = '品牌编号会跳转到指定的品牌详细页面,输入框填写品牌编号。';
+                desc_array['category'] = '分类编号会跳转到指定的分类搜索结果页面,输入框填写分类。';
+                desc_array['innerurl'] = '内嵌网页打开,输入框填写完整的URL。';
+
                 desc = desc_array[type];
             }
             $('#dialog_item_image_desc').text(desc);

+ 94 - 0
helper/search_helper.php

@@ -0,0 +1,94 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 2016/10/16
+ * Time: 下午2:24
+ */
+
+function comp_history($left,$right)
+{
+    $t_l = intval($left['add_time']);
+    $t_r = intval($right['add_time']);
+
+    if($t_l > $t_r) {
+        return 1;
+    }
+    elseif($t_l == $t_r)
+    {
+        $c_l = intval($left['count']);
+        $c_r = intval($right['count']);
+
+        if($c_l > $c_r) {
+            return 1;
+        }
+        elseif($c_l == $c_r) {
+            return 0;
+        }
+        else {
+            return -1;
+        }
+    }
+    else {
+        return -1;
+    }
+}
+
+class search_helper
+{
+    private $mContainer;
+
+    public function __construct()
+    {
+        if(array_key_exists('search_history',$_SESSION)) {
+            $histories = $_SESSION['search_history'];
+        } else {
+            $histories = [];
+        }
+
+        $this->mContainer = [];
+        foreach ($histories as $value)
+        {
+            $keyword = $value['keyword'];
+            $this->mContainer[$keyword] = $value;
+        }
+    }
+
+    public function __destruct()
+    {
+        $history = [];
+        foreach ($this->mContainer as $key => $value) {
+            $history[] = $value;
+        }
+        $_SESSION['search_history'] = $history;
+    }
+
+    public function add_word($keyword)
+    {
+        if(empty($keyword)) {
+            return false;
+        }
+
+        if(array_key_exists($keyword,$this->mContainer)) {
+            $this->mContainer[$keyword]['add_time'] = time();
+            $this->mContainer[$keyword]['count'] += 1;
+        } else {
+            $this->mContainer[$keyword]['add_time'] = time();
+            $this->mContainer[$keyword]['count'] = 1;
+            $this->mContainer[$keyword]['keyword'] = $keyword;
+        }
+        uasort($this->mContainer,'comp_history');
+
+        return true;
+    }
+
+    public function get_words()
+    {
+        $result = [];
+        foreach ($this->mContainer as $key => $value) {
+            $result[] = $value['keyword'];
+        }
+        return $result;
+    }
+}

+ 10 - 2
mobile/control/search.php

@@ -5,6 +5,7 @@ defined('InShopNC') or exit('Access Invalid!');
 
 require_once (BASE_ROOT_PATH . '/helper/category_helper.php');
 require_once (BASE_ROOT_PATH . '/helper/goods_helper.php');
+require_once (BASE_ROOT_PATH . '/helper/search_helper.php');
 require_once(BASE_ROOT_PATH . '/helper/search/searcher.php');
 require_once(BASE_ROOT_PATH . '/helper/search/server.php');
 require_once(BASE_ROOT_PATH . '/helper/search/processor.php');
@@ -59,7 +60,7 @@ class searchControl extends mobileHomeControl
         }
     }
 
-    public function get_wordsOp()
+    public function suggest_wordsOp()
     {
         $keyword = $_GET['keyword'];
         if(empty($keyword)) {
@@ -77,9 +78,13 @@ class searchControl extends mobileHomeControl
             return self::outsuccess(array('words' => $result,'mobile_page' => mobile_page($pages)));
         }
     }
+
     public function historyOp()
     {
-
+        $helper = new search_helper();
+        $result = $helper->get_words();
+        $result = $this->separate_page($result,$pages);
+        return self::outsuccess(array('words' => $result,'mobile_page' => mobile_page($pages)));
     }
 
     /**
@@ -94,6 +99,9 @@ class searchControl extends mobileHomeControl
         }
         // 关键字
         if (!empty(trim($_GET['keyword']))) {
+            $word = trim(urldecode($_GET['keyword']));
+            $helper = new search_helper();
+            $helper->add_word($word);
             $condition['goods_name|goods_jingle'] = array('like', '%' . urldecode($_GET['keyword']) . '%');
         }
         // 品牌查询

+ 13 - 0
test/TestSearch.php

@@ -41,4 +41,17 @@ class TestSearch extends PHPUnit_Framework_TestCase
         $result = search\tcp_client::instance()->get_words('眼光影');
     }
 
+    public function testUasort()
+    {
+        $words = [];
+        $words[] = array("add_time" =>  104,"count" => 1);
+        $words[] = array("add_time" =>  100,"count" => 1);
+        $words[] = array("add_time" =>  300,"count" => 1);
+
+        $ret = uasort($words,'comp_time');
+        foreach ($words as $key => $val) {
+            echo $key;
+        }
+    }
+
 }