|
@@ -8,6 +8,7 @@
|
|
|
|
|
|
require_once(BASE_DATA_PATH . '/model/goods.model.php');
|
|
|
|
|
|
+
|
|
|
class product_importer
|
|
|
{
|
|
|
private $tm_goods;
|
|
@@ -31,9 +32,6 @@ class product_importer
|
|
|
private $cls_tree;
|
|
|
private $down_path;
|
|
|
|
|
|
- const store_name = "熊猫美妆";
|
|
|
- const store_id = 6;
|
|
|
-
|
|
|
public function __construct()
|
|
|
{
|
|
|
$this->tm_goods = Model('tm_goods');
|
|
@@ -285,8 +283,9 @@ class product_importer
|
|
|
|
|
|
$general['num_iid'] = $num_iid;
|
|
|
$general['tm_shop'] = $shop_id;
|
|
|
- $general['store_id'] = self::store_id;
|
|
|
- $general['store_name'] = self::store_name;
|
|
|
+ $general['store_id'] = fetch_config::store_id;
|
|
|
+ $general['store_name'] = fetch_config::store_name;
|
|
|
+
|
|
|
$general['goods_name'] = not_null($item['title']);
|
|
|
$general['goods_mobile_name'] = not_null($item['title']);
|
|
|
$general['goods_jingle'] = not_null($item['sell_point']);
|
|
@@ -318,17 +317,52 @@ class product_importer
|
|
|
|
|
|
private function upload_imges(&$imges,$storeid)
|
|
|
{
|
|
|
- foreach($imges as &$img) {
|
|
|
+ foreach($imges as &$img)
|
|
|
+ {
|
|
|
+ static $pngext = array('png','jpg','jpeg');
|
|
|
+
|
|
|
$url = $img['url'];
|
|
|
$info = pathinfo($url);
|
|
|
$src_name = $this->down_path . '/' . md5($url) . '.' . $info['extension'];
|
|
|
- if(!file_exists($src_name) || filesize($src_name) == 0) continue;
|
|
|
+
|
|
|
+ if(empty($info['extension'])) continue;
|
|
|
+
|
|
|
+ $err = true;
|
|
|
+ if(file_exists($src_name))
|
|
|
+ {
|
|
|
+ $fh = fopen($src_name, "rb");
|
|
|
+ $head = fread($fh, 8);
|
|
|
+ fclose($fh);
|
|
|
+
|
|
|
+ $err = false;
|
|
|
+ if(empty($head)) {
|
|
|
+ unlink($src_name);
|
|
|
+ Log::record("{$src_name} file is empty.",Log::ERR);
|
|
|
+ $err = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(in_array($info['extension'],$pngext))
|
|
|
+ {
|
|
|
+ $arr = unpack("C4", $head);
|
|
|
+ if($arr[1] == 137 && $arr[2] == 80) {
|
|
|
+ Log::record("{$src_name} is a png file.",Log::ERR);
|
|
|
+ $err = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if($err) {
|
|
|
+ Log::record("{$src_name} file is error.",Log::ERR);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
$upctl = new upload_control();
|
|
|
$upctl->set_store($storeid);
|
|
|
$up_name = $upctl->upload_img($src_name);
|
|
|
$img['upname'] = $up_name;
|
|
|
$img['file'] = $src_name;
|
|
|
}
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
private function add_attr($gd_id,$gdcommon_id,$gc_id,$type_id,$goods_attr)
|
|
@@ -371,8 +405,6 @@ class product_importer
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
private function import_item($item,$desc,$num_iid,$shop_id,&$nsku)
|
|
|
{
|
|
|
$cid = $item['cid'];
|
|
@@ -409,11 +441,11 @@ class product_importer
|
|
|
|
|
|
$prop_imgs = $item['prop_imgs']['prop_img'];
|
|
|
if(!empty($prop_imgs)) {
|
|
|
- $this->upload_imges($prop_imgs,self::store_id);
|
|
|
+ $this->upload_imges($prop_imgs,fetch_config::store_id);
|
|
|
}
|
|
|
|
|
|
$imgs = $this->reset_imgs($item['item_imgs']['item_img']);
|
|
|
- $this->upload_imges($imgs,self::store_id);
|
|
|
+ $this->upload_imges($imgs,fetch_config::store_id);
|
|
|
|
|
|
if(empty($prop_imgs))
|
|
|
{
|
|
@@ -434,7 +466,7 @@ class product_importer
|
|
|
}
|
|
|
|
|
|
$this->mod_goods_images->insert(array('goods_commonid' => $common_id,
|
|
|
- 'store_id' => self::store_id,'goods_image' => $upname,'goods_image_sort' => $pos,'is_default' => $default,'filesig' => $file_sig));
|
|
|
+ 'store_id' => fetch_config::store_id,'goods_image' => $upname,'goods_image_sort' => $pos,'is_default' => $default,'filesig' => $file_sig));
|
|
|
}
|
|
|
}
|
|
|
else
|
|
@@ -453,7 +485,7 @@ class product_importer
|
|
|
|
|
|
$color_id = $this->goods_colorid($cid,$pimg['properties']);
|
|
|
$this->mod_goods_images->insert(array('goods_commonid' => $common_id,'color_id' => $color_id,
|
|
|
- 'store_id' => self::store_id,'goods_image' => $pupname,'goods_image_sort' => $pos,'is_default' => $default,'filesig' => $file_sig));
|
|
|
+ 'store_id' => fetch_config::store_id,'goods_image' => $pupname,'goods_image_sort' => $pos,'is_default' => $default,'filesig' => $file_sig));
|
|
|
$main_pic = $pupname;
|
|
|
|
|
|
$default = 0;
|
|
@@ -467,7 +499,7 @@ class product_importer
|
|
|
$file_sig = md5_file($img['file']);
|
|
|
}
|
|
|
$this->mod_goods_images->insert(array('goods_commonid' => $common_id,'color_id' => $color_id,
|
|
|
- 'store_id' => self::store_id,'goods_image' => $upname,'goods_image_sort' => $pos + 1,'is_default' => $default,'filesig' => $file_sig));
|
|
|
+ 'store_id' => fetch_config::store_id,'goods_image' => $upname,'goods_image_sort' => $pos + 1,'is_default' => $default,'filesig' => $file_sig));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -523,19 +555,31 @@ class product_importer
|
|
|
return $common_id;
|
|
|
}
|
|
|
|
|
|
-// public function proc()
|
|
|
-// {
|
|
|
-// $bodys = $this->tm_goods->field('num_iid,shop_id,body,description')->where(array('imported' => 0))->limit(false)->order('num_iid')->select();
|
|
|
-//
|
|
|
-// $items = $this->get_tmgoods($bodys);
|
|
|
-// foreach($items as $item) {
|
|
|
-// print "handle num_iid=" . $item['num_iid'] . " start.\r\n";
|
|
|
-// $this->import_item($item['body'],$item['desc'],$item['num_iid'],$item['shop_id']);
|
|
|
-//
|
|
|
-// $this->tm_goods->where(array('num_iid' => $item['num_iid']))->update(array('imported' => 1));
|
|
|
-// print "handle num_iid=" . $item['num_iid'] . " end. \r\n";
|
|
|
-// }
|
|
|
-// }
|
|
|
+ public function proc()
|
|
|
+ {
|
|
|
+ $condition = array('num_iid' => 13898341378);
|
|
|
+ //$condition = array('imported' => 0);
|
|
|
+ $bodys = $this->tm_goods->field('num_iid,shop_id,body,description')->where($condition)->limit(false)->order('num_iid')->select();
|
|
|
+
|
|
|
+ $items = $this->get_tmgoods($bodys);
|
|
|
+ foreach($items as $item) {
|
|
|
+ print "handle num_iid=" . $item['num_iid'] . " start.\r\n";
|
|
|
+ $this->import_item($item['body'],$item['desc'],$item['num_iid'],$item['shop_id']);
|
|
|
+
|
|
|
+ $this->tm_goods->where(array('num_iid' => $item['num_iid']))->update(array('imported' => 1));
|
|
|
+ print "handle num_iid=" . $item['num_iid'] . " end. \r\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function goods_exist($num_iid)
|
|
|
+ {
|
|
|
+ $items = $this->mod_goods->where(array('num_iid' => $num_iid))->select();
|
|
|
+ if(!empty($items) && count($items) > 0) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
public function proc_shop()
|
|
|
{
|
|
@@ -549,7 +593,8 @@ class product_importer
|
|
|
Log::endl(Log::DEBUG);
|
|
|
Log::record("begin shop_id={$shopid} spu count= {$count}",Log::DEBUG);
|
|
|
|
|
|
- $bodys = $this->tm_goods->field('num_iid,cid,shop_id,body,description,picnum')->where(array('imported' => 0,'shop_id' => $shopid))->limit(false)->order('num_iid')->select();
|
|
|
+ $con = array('imported' => 0,'shop_id' => $shopid);
|
|
|
+ $bodys = $this->tm_goods->field('num_iid,cid,shop_id,body,description,picnum')->where($con)->limit(false)->order('num_iid')->select();
|
|
|
|
|
|
$items = $this->get_tmgoods($bodys);
|
|
|
foreach($items as $item)
|
|
@@ -560,17 +605,19 @@ class product_importer
|
|
|
Log::endl(Log::DEBUG);
|
|
|
Log::record("handle num_iid={$num_iid} start.\r\n",Log::DEBUG);
|
|
|
|
|
|
- echo "begin shop_id={$shopid} spu count= {$count} \r\n";
|
|
|
+ if($this->goods_exist($num_iid)) {
|
|
|
+ Log::record("handle num_iid={$item['num_iid']} has existed.",Log::DEBUG);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
$cid = $item['cid'];
|
|
|
if(is_excids($cid)) {
|
|
|
--$count;
|
|
|
+ Log::record("handle num_iid={$item['num_iid']} cid is exclude.",Log::DEBUG);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- echo __FUNCTION__ . " 1 \r\n";
|
|
|
$commonid =$this->import_item($item['body'],$item['desc'],$num_iid,$item['shop_id'],$nsku);
|
|
|
- echo __FUNCTION__ . " 2 \r\n";
|
|
|
if($commonid)
|
|
|
{
|
|
|
if($this->check($num_iid,$nsku,$picnum,$commonid) == false) {
|
|
@@ -578,6 +625,9 @@ class product_importer
|
|
|
$this->mod_goods_common->where(array('goods_commonid' => $commonid))->delete();
|
|
|
$this->mod_goods_images->where(array('goods_commonid' => $commonid))->delete();
|
|
|
$this->mod_goods->where(array('goods_commonid' => $commonid))->delete();
|
|
|
+ $this->mod_goods->where(array('num_iid' => $num_iid))->delete();
|
|
|
+ $this->mod_goods_common->where(array('num_iid' => $num_iid))->delete();
|
|
|
+
|
|
|
Log::record("shopid = {$shopid} and num_iid = {$num_iid} nsku = {$nsku} cannot be imported.",Log::ERR);
|
|
|
} else {
|
|
|
$this->tm_goods->where(array('num_iid' => $item['num_iid']))->update(array('imported' => 1,'commonid' => $commonid));
|
|
@@ -590,8 +640,6 @@ class product_importer
|
|
|
}
|
|
|
|
|
|
Log::record("handle num_iid={$item['num_iid']} end.",Log::DEBUG);
|
|
|
-
|
|
|
- echo "handle num_iid={$item['num_iid']} end.";
|
|
|
}
|
|
|
|
|
|
Log::record("end shop_id = {$shopid} Error= {$count}",Log::DEBUG);
|