stanley-king 9 роки тому
батько
коміт
37355b5082

+ 0 - 2
core/lrlz.php

@@ -83,8 +83,6 @@ if ($config['gzip'] == 1 && function_exists('ob_gzhandler') && $_GET['inajax'] !
 	ob_start();
 }
 
-
-
 if(function_exists('spl_autoload_register')) {
 	spl_autoload_register(array('Base', 'autoload'));
 } else {

+ 76 - 10
crontab/crawl/category.php

@@ -8,15 +8,15 @@
 
 class category
 {
-    private $model_cats;
-    private $model_class;
-    private $topcats = NULL;
+    private $tm_cats;
+    private $goods_class;
+    private $tm_goods;
 
-    public function __construct($topcats)
+    public function __construct()
     {
-        $this->model_cats = Model('item_cats');
-        $this->model_class = Model('goods_class');
-        $this->topcats = $topcats;
+        $this->tm_cats = Model('tm_cats');
+        $this->goods_class = Model('goods_class');
+        $this->tm_goods = Model('tm_goods');
     }
 
     private function insert($catdatas)
@@ -32,7 +32,7 @@ class category
             $item['gc_sort'] = $val['sort_order'];
             $item['gc_virtual'] = 0;
 
-            $this->model_class->insert($item);
+            $this->goods_class->insert($item);
             $cids[] = (int)$val['cid'];
         }
 
@@ -44,19 +44,85 @@ class category
         if(empty($pcids)) return;
 
         foreach ($pcids as $pcid) {
-            $datas = $this->model_cats->field('*')->limit(false)->where(array('parent_cid'=> $pcid))->select();
+            $datas = $this->tm_cats->field('*')->limit(false)->where(array('parent_cid'=> $pcid))->select();
             $cids = $this->insert($datas);
 
             $this->insert_all($cids);
         }
     }
 
+    private function get_cids()
+    {
+        $items = $this->tm_goods->group('cid')->field('cid')->limit(false)->select();
+
+        $cids = array();
+        foreach($items as $val) {
+            array_push($cids,$val['cid']);
+        }
+        return $cids;
+    }
     public function proc()
     {
+        $cids = $this->get_cids();
+        foreach($cids as $cid) {
+            $this->import_leaf($cid);
+        }
+    }
+
+    private function get_goods_cidinfo($cid)
+    {
+        $items = $this->goods_class->field('*')->where(array('gc_id' => $cid))->limit(false)->select();
+
+        if(empty($items)) {
+            echo("gc_id = $cid cannot get info from goods_class.\r\n");
+            return NULL;
+        } else {
+            return $items[0];
+        }
+    }
+
+    private function get_tm_cidinfo($cid)
+    {
+        $items = $this->tm_cats->field('*')->where(array('cid' => $cid))->limit(false)->select();
+
+        if(empty($items)) {
+            echo "cid = $cid cannot get info from tm_cats.\r\n";
+            return NULL;
+        } else {
+            return $items[0];
+        }
+    }
+
+    private function import_leaf($cid)
+    {
+        if($cid == 0 || !empty($this->get_goods_cidinfo($cid))) {
+            return;
+        }
+        else
+        {
+            $val = $this->get_tm_cidinfo($cid);
+
+            $item['gc_id'] = $val['cid'];
+            $item['gc_name'] = $val['name'];
+            $item['gc_parent_id'] = $val['parent_cid'];
+            $item['commis_rate'] = 0;
+            $item['gc_sort'] = $val['sort_order'];
+            $item['gc_virtual'] = 0;
+
+            $id = $this->goods_class->insert($item);
+            if($id == false) {
+                echo "insert cid = $cid error.";
+            }
+            $this->import_leaf($item['gc_parent_id']);
+        }
+    }
+
+    public function procex()
+    {
         if(empty($this->topcats)) return;
 
         foreach ($this->topcats as $cid) {
-            $datas = $this->model_cats->field('*')->limit(false)->where(array('cid'=>$cid,'parent_cid'=> 0))->select();
+            $datas = $this->tm_cats->field('*')->limit(false)->where(array('cid'=>$cid,'parent_cid'=> 0))->select();
             $this->insert($datas);
         }
 

+ 2 - 2
crontab/crawl/class_tree.php

@@ -9,6 +9,7 @@
 class class_tree
 {
     private $group_class;
+    private $file_obj;
 
     public function __construct()
     {
@@ -68,7 +69,7 @@ class class_tree
      * @param array $condition 检索条件
      * @return array 数组类型的返回结果
      */
-    private function load_all()
+    public function load_all()
     {
         $mod_cats = Model('goods_class');
         $class_list = $mod_cats->field('*')->order('gc_parent_id asc,gc_sort asc,gc_id asc')->limit(false)->select();
@@ -103,5 +104,4 @@ class class_tree
         $this->write_deep($group_class,$group_class[0]['child'],1);
         return $group_class;
     }
-
 }

+ 7 - 7
crontab/crawl/fetch_goods.php

@@ -21,24 +21,24 @@ require_once (BASE_CRONTAB_PATH . '/crawl/upload_file.php');
 require_once (BASE_CRONTAB_PATH . '/crawl/upload_control.php');
 require_once (BASE_CORE_PATH . '/framework/libraries/uploadfile.php');
 
-
 date_default_timezone_set('Asia/Shanghai');
 
 
-//$cat = new category(array(1801,50010788,50023282));
+//$cat = new category();
 //$cat->proc();
 
 $tmreq = new tmrequest();
 $tmreq->proc();
 
-get_tmdata();
 $treater = new pretreat_tmdata();
 $treater->proc();
 
-//$spec = new spec_attr();
-//$spec->proc();
 
-//$importer = new product_importer();
-//$importer->proc();
+
+$spec = new spec_attr();
+$spec->proc();
+
+$importer = new product_importer();
+$importer->proc();
 
 

+ 15 - 1
crontab/crawl/pretreat_tmdata.php

@@ -30,9 +30,23 @@ class pretreat_tmdata
             $body = $result['body'];
             $response = json_decode($body, true);
             $item = $response['item_seller_get_response']['item'];
-            //$this->parse_tm_product($item);
+            $this->parse_tm_product($item);
             $this->parse_tm_pic($item);
         }
+        $this->create_brand();
+    }
+
+    private function create_brand()
+    {
+        $barnds = $this->tm_prop_values->field('name,cid')->where(array('pid' => 20000))->group('vid')->select();
+
+        $mod_brand = Model('brand');
+        foreach($barnds as $val) {
+            $name = $val['name'];
+            $cid = $val['cid'];
+            $ret = $mod_brand->insert(array('brand_name' => $name,'brand_class' => $cid));
+        }
+
     }
 
     private function parse_propnames($propnames)

+ 2 - 0
crontab/crawl/product_importer.php

@@ -284,8 +284,10 @@ class product_importer
         $general['store_id'] = self::store_id;
         $general['store_name'] = self::store_name;
         $general['goods_name'] = $item['title'];
+        $general['goods_mobile_name'] = $item['title'];
         $general['goods_jingle'] = empty($item['sell_point']) ? '' : $item['sell_point'];
         $general['goods_price'] = $item['price'];
+        $general['goods_marketprice'] = $item['price'];
         $general['goods_image'] = $item['pic_url'];
         $general['goods_state'] = 1;
         $general['goods_verify'] = 1;

+ 2 - 2
crontab/crawl/spec_attr.php

@@ -245,10 +245,10 @@ class spec_attr
             {
                 $rid = $this->tm_tvid_attrvid->insert(array('attr_vid' =>$attr_vid,'tcid' => $cid,'tpid' => $pid,'tvid' => $vid));
                 if(empty($rid)) {
-                    throw new Exception('insert tm_tvid_attrvid error');
+                    //throw new Exception('insert tm_tvid_attrvid error');
                 }
             } else {
-                throw(new Exception("cannot add attribute value."));
+                //throw(new Exception("cannot add attribute value."));
             }
         }
     }