소스 검색

解决分类父级查询

stanley-king 8 년 전
부모
커밋
b693df3490
5개의 변경된 파일89개의 추가작업 그리고 31개의 파일을 삭제
  1. 5 5
      centra_srv.php
  2. 55 12
      helper/search/searcher.php
  3. 17 0
      helper/search/util.php
  4. 1 2
      mobile/control/member_buy.php
  5. 11 12
      mobile/control/search.php

+ 5 - 5
centra_srv.php

@@ -64,12 +64,12 @@ function remote_addr()
 }
 
 $listen_fd = stream_socket_server (remote_addr(), $errno, $errstr);
-//search_work($listen_fd);
+search_work($listen_fd);
 
-$count = 1;
-while ($count-- > 0) {
-    fork_subprocess($count,$listen_fd);
-}
+//$count = 1;
+//while ($count-- > 0) {
+//    fork_subprocess($count,$listen_fd);
+//}
 
 
 

+ 55 - 12
helper/search/searcher.php

@@ -60,16 +60,16 @@ class brand_dict extends words
 
 class category_dict extends words
 {
-    private $gc_hot;    //一个GC对应一个HotID
-    private $hot_tree;  //HOT的父子关系
+    private $mGcHot;   //一个GC对应一个HotID
+    private $mHoTree;  //HOT的父子关系
 
     private $mHotBrand;
     private $mHotCommon;
 
     public function __construct() {
         parent::__construct();
-        $this->gc_hot   = new one_one();
-        $this->hot_tree = new array_tree();
+        $this->mGcHot   = new one_one();
+        $this->mHoTree = new array_tree();
         $this->mHotBrand = new one_multi();
         $this->mHotCommon = new one_multi();
 
@@ -81,7 +81,7 @@ class category_dict extends words
         foreach ($cats as $item)
         {
             $hot_id = intval($item['hot_id']);
-            $this->hot_tree->add($hot_id,0);
+            $this->mHoTree->add($hot_id,0);
 
             $name = $item['name'];
             $this->parase($name,$hot_id);
@@ -89,7 +89,7 @@ class category_dict extends words
             foreach($item['subitem'] as $sub_item) {
                 $subhot_id = intval($sub_item['hot_id']);
 
-                $this->hot_tree->add($subhot_id,$hot_id);
+                $this->mHoTree->add($subhot_id,$hot_id);
 
                 $cids = category_helper::instance()->cids($subhot_id);
                 $this->add_gc_hot($cids,$subhot_id);
@@ -99,12 +99,55 @@ class category_dict extends words
             }
         }
     }
-    public function brands($hotid) {
-        return $this->mHotBrand->get($hotid);
+    public function brands($hotid)
+    {
+        if($this->mHoTree->is_parent($hotid) == false) {
+            return $this->mHotBrand->get($hotid);
+        }
+        else
+        {
+            $sub_hots = $this->mHoTree->subs($hotid);
+
+            $pos = 0;
+            $brands = [];
+            foreach ($sub_hots as $hot)
+            {
+                if($pos == 0) {
+                    $brands = $this->mHotBrand->get($hot);
+                } else {
+                    $tmp = $this->mHotBrand->get($hot);
+                    $brands = algorithm::set_union($brands,$tmp);
+                }
+                $pos++;
+            }
+            return $brands;
+        }
     }
-    public function commons($hotid) {
-        return $this->mHotCommon->get($hotid);
+    public function commons($hotid)
+    {
+        if($this->mHoTree->is_parent($hotid) == false) {
+            return $this->mHotCommon->get($hotid);
+        }
+        else
+        {
+            $sub_hots = $this->mHoTree->subs($hotid);
+
+            $pos = 0;
+            $cids = [];
+            foreach ($sub_hots as $hot)
+            {
+                if($pos == 0) {
+                    $cids = $this->mHotCommon->get($hot);
+                } else {
+                    $tmp = $this->mHotCommon->get($hot);
+                    $cids = algorithm::set_union($cids,$tmp);
+                }
+                $pos++;
+            }
+            return $cids;
+        }
     }
+
     public function add_hot($hotid,$brand,$common)
     {
         $this->mHotBrand->add($hotid,$brand);
@@ -112,14 +155,14 @@ class category_dict extends words
     }
 
     public function hotid($gc_id) {
-        return $this->gc_hot->get($gc_id);
+        return $this->mGcHot->get($gc_id);
     }
 
     private function add_gc_hot($gc_ids,$hot_id)
     {
         foreach ($gc_ids as $cid) {
             $cid = intval($cid);
-            $this->gc_hot->add($cid,$hot_id);
+            $this->mGcHot->add($cid,$hot_id);
         }
     }
 }

+ 17 - 0
helper/search/util.php

@@ -207,4 +207,21 @@ class array_tree
             algorithm::array_insert($values,$pos,$val);
         }
     }
+
+    public function is_parent($hot)
+    {
+        if (array_key_exists($hot, $this->mTree) == false) {
+            return false;
+        }
+
+        return (count($this->mTree[$hot]['subids']) > 0);
+    }
+    public function subs($hot)
+    {
+        if (array_key_exists($hot, $this->mTree) == false) {
+            return array();
+        }
+
+        return $this->mTree[$hot]['subids'];
+    }
 }

+ 1 - 2
mobile/control/member_buy.php

@@ -18,6 +18,7 @@ require_once (BASE_ROOT_PATH . '/helper/pay_helper.php');
 
 class member_buyControl extends mbMemberControl
 {
+
     public function __construct() {
         parent::__construct();
     }
@@ -86,8 +87,6 @@ class member_buyControl extends mbMemberControl
 
             $out_put = pay_helper::pay($pay_sn,$payment,$usebonus,$err);
             if($out_put == false) {
-//                $out_put['payment'] = $payment;
-//                $out_put['pay_sn'] = $pay_sn;
                 return self::outerr($err['code'],$err['msg']);
             } else {
                 $out_put['payment'] = $payment;

+ 11 - 12
mobile/control/search.php

@@ -76,11 +76,11 @@ class searchControl extends mobileHomeControl
 
         if(empty($result))
         {
-            self::outsuccess(array('special_list' => array(),
-                'summary'  => array(),
-                'groupbuy' => array(),
-                'limitime' => array(),
-                'bundling' => array(),
+            return self::outsuccess(array('special_list' => null,
+                'summary'  => null,
+                'groupbuy' => null,
+                'limitime' => null,
+                'bundling' => null,
                 'mobile_page' => mobile_page(0)));
         }
 
@@ -95,12 +95,11 @@ class searchControl extends mobileHomeControl
 
         if(empty($goods_list))
         {
-            $goods_ids = array();
-            self::outsuccess(array('special_list' => $goods_ids,
-                'summary'  => array(),
-                'groupbuy' => array(),
-                'limitime' => array(),
-                'bundling' => array(),
+            return self::outsuccess(array('special_list' => null,
+                'summary'  => null,
+                'groupbuy' => null,
+                'limitime' => null,
+                'bundling' => null,
                 'mobile_page' => mobile_page($page_count)));
         }
         else
@@ -138,7 +137,7 @@ class searchControl extends mobileHomeControl
             $helper = new goods_helper();
             $ret = $helper->get_summaryex($goods_list,$related_goods);
 
-            self::outsuccess(array('special_list' => $blocks,
+            return self::outsuccess(array('special_list' => $blocks,
                 'summary'  => $ret['summary'],
                 'groupbuy' => $ret['groupbuy'],
                 'limitime' => $ret['limitime'],