|
@@ -72,6 +72,7 @@ class product_importer
|
|
$product['desc'] = $body['description'];
|
|
$product['desc'] = $body['description'];
|
|
$product['num_iid'] = $body['num_iid'];
|
|
$product['num_iid'] = $body['num_iid'];
|
|
$product['shop_id'] = $body['shop_id'];
|
|
$product['shop_id'] = $body['shop_id'];
|
|
|
|
+ $product['picnum'] = $body['picnum'];
|
|
|
|
|
|
array_push($result,$product);
|
|
array_push($result,$product);
|
|
}
|
|
}
|
|
@@ -326,6 +327,7 @@ class product_importer
|
|
$upctl->set_store($storeid);
|
|
$upctl->set_store($storeid);
|
|
$up_name = $upctl->upload_img($src_name);
|
|
$up_name = $upctl->upload_img($src_name);
|
|
$img['upname'] = $up_name;
|
|
$img['upname'] = $up_name;
|
|
|
|
+ $img['file'] = $src_name;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -426,8 +428,13 @@ class product_importer
|
|
$default = 0;
|
|
$default = 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ $file_sig = '';
|
|
|
|
+ if(isset($img['file'])) {
|
|
|
|
+ $file_sig = md5_file($img['file']);
|
|
|
|
+ }
|
|
|
|
+
|
|
$this->mod_goods_images->insert(array('goods_commonid' => $common_id,
|
|
$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));
|
|
|
|
|
|
+ 'store_id' => self::store_id,'goods_image' => $upname,'goods_image_sort' => $pos,'is_default' => $default,'filesig' => $file_sig));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -437,9 +444,16 @@ class product_importer
|
|
$default = 1;
|
|
$default = 1;
|
|
$pos = 0;
|
|
$pos = 0;
|
|
$pupname = $pimg['upname'];
|
|
$pupname = $pimg['upname'];
|
|
|
|
+ if(empty($pupname)) continue;
|
|
|
|
+
|
|
|
|
+ $file_sig = '';
|
|
|
|
+ if(isset($img['file'])) {
|
|
|
|
+ $file_sig = md5_file($img['file']);
|
|
|
|
+ }
|
|
|
|
+
|
|
$color_id = $this->goods_colorid($cid,$pimg['properties']);
|
|
$color_id = $this->goods_colorid($cid,$pimg['properties']);
|
|
$this->mod_goods_images->insert(array('goods_commonid' => $common_id,'color_id' => $color_id,
|
|
$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));
|
|
|
|
|
|
+ 'store_id' => self::store_id,'goods_image' => $pupname,'goods_image_sort' => $pos,'is_default' => $default,'filesig' => $file_sig));
|
|
$main_pic = $pupname;
|
|
$main_pic = $pupname;
|
|
|
|
|
|
$default = 0;
|
|
$default = 0;
|
|
@@ -447,9 +461,13 @@ class product_importer
|
|
{
|
|
{
|
|
$upname = $img['upname'];
|
|
$upname = $img['upname'];
|
|
if(empty($upname)) continue;
|
|
if(empty($upname)) continue;
|
|
- //$color_id = $this->goods_colorid($cid);
|
|
|
|
|
|
+
|
|
|
|
+ $file_sig = '';
|
|
|
|
+ if(isset($img['file'])) {
|
|
|
|
+ $file_sig = md5_file($img['file']);
|
|
|
|
+ }
|
|
$this->mod_goods_images->insert(array('goods_commonid' => $common_id,'color_id' => $color_id,
|
|
$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));
|
|
|
|
|
|
+ 'store_id' => self::store_id,'goods_image' => $upname,'goods_image_sort' => $pos + 1,'is_default' => $default,'filesig' => $file_sig));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -501,26 +519,27 @@ class product_importer
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
- 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";
|
|
|
|
- }
|
|
|
|
|
|
+ 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_shop()
|
|
public function proc_shop()
|
|
{
|
|
{
|
|
- //SELECT shop_id,count(*) FROM 33hao.lrlz_tm_goods group by shop_id;
|
|
|
|
-
|
|
|
|
|
|
+ ob_implicit_flush(1);
|
|
$shopes = $this->tm_goods->field('shop_id,count(*) as n')->group('shop_id')->limit(false)->select();
|
|
$shopes = $this->tm_goods->field('shop_id,count(*) as n')->group('shop_id')->limit(false)->select();
|
|
|
|
|
|
foreach($shopes as $shop)
|
|
foreach($shopes as $shop)
|
|
@@ -528,42 +547,80 @@ class product_importer
|
|
$shopid = $shop['shop_id'];
|
|
$shopid = $shop['shop_id'];
|
|
$count = $shop['n'];
|
|
$count = $shop['n'];
|
|
|
|
|
|
- $bodys = $this->tm_goods->field('num_iid,cid,shop_id,body,description')->where(array('imported' => 0,'shop_id' => $shopid))->limit(false)->order('num_iid')->select();
|
|
|
|
|
|
+ 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();
|
|
|
|
|
|
$items = $this->get_tmgoods($bodys);
|
|
$items = $this->get_tmgoods($bodys);
|
|
- foreach($items as $item) {
|
|
|
|
- print "handle num_iid=" . $item['num_iid'] . " start.\r\n";
|
|
|
|
|
|
+ foreach($items as $item)
|
|
|
|
+ {
|
|
|
|
+ $num_iid = $item['num_iid'];
|
|
|
|
+ $picnum = $item['picnum'];
|
|
|
|
|
|
- $cid = $item['cid'];
|
|
|
|
- if(is_excids($cid)) continue;
|
|
|
|
|
|
+ Log::endl(Log::DEBUG);
|
|
|
|
+ Log::record("handle num_iid={$num_iid} start.\r\n",Log::DEBUG);
|
|
|
|
|
|
- $this->import_item($item['body'],$item['desc'],$item['num_iid'],$item['shop_id'],$nsku);
|
|
|
|
- $this->tm_goods->where(array('num_iid' => $item['num_iid']))->update(array('imported' => 1));
|
|
|
|
- print "handle num_iid=" . $item['num_iid'] . " end. \r\n";
|
|
|
|
|
|
+ echo "begin shop_id={$shopid} spu count= {$count} \r\n";
|
|
|
|
+ flush();
|
|
|
|
|
|
- $num_iid = $item['num_iid'];
|
|
|
|
|
|
|
|
- if($this->check_count($num_iid,$nsku) == false) {
|
|
|
|
- Log::record("shopid = {$shopid} and num_iid = {$num_iid} nsku = {$nsku} cannot be imported.");
|
|
|
|
|
|
+ $cid = $item['cid'];
|
|
|
|
+ if(is_excids($cid)) {
|
|
|
|
+ --$count;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $commonid =$this->import_item($item['body'],$item['desc'],$num_iid,$item['shop_id'],$nsku);
|
|
|
|
+ if($commonid)
|
|
|
|
+ {
|
|
|
|
+ if($this->check($num_iid,$nsku,$picnum,$commonid) == false) {
|
|
|
|
+ $this->mod_goods_attr_index->where(array('goods_commonid' => $commonid))->delete();
|
|
|
|
+ $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();
|
|
|
|
+ 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));
|
|
|
|
+ --$count;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ Log::record("goods_commonid is error num_iid={$item['num_iid']}.",Log::DEBUG);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Log::record("handle num_iid={$item['num_iid']} end.",Log::DEBUG);
|
|
|
|
+
|
|
|
|
+ echo "handle num_iid={$item['num_iid']} end.";
|
|
|
|
+ flush();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ Log::record("end shop_id = {$shopid} Error= {$count}",Log::DEBUG);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private function check_count($num_iid,$nsku)
|
|
|
|
|
|
+ private function check($num_iid,$nsku,$picnum,$commonid)
|
|
{
|
|
{
|
|
|
|
+ $ret = true;
|
|
$ncommon = $this->mod_goods_common->where(array('num_iid' => $num_iid))->count();
|
|
$ncommon = $this->mod_goods_common->where(array('num_iid' => $num_iid))->count();
|
|
if($ncommon != 1) {
|
|
if($ncommon != 1) {
|
|
Log::record("goods_common table's data is not equal 1 where num_iid = {$num_iid}",Log::ERR);
|
|
Log::record("goods_common table's data is not equal 1 where num_iid = {$num_iid}",Log::ERR);
|
|
- return false;
|
|
|
|
|
|
+ if($ret) $ret = false;
|
|
}
|
|
}
|
|
|
|
|
|
$ngoods = $this->mod_goods->where(array('num_iid' => $num_iid))->count();
|
|
$ngoods = $this->mod_goods->where(array('num_iid' => $num_iid))->count();
|
|
|
|
|
|
if($ngoods != $nsku) {
|
|
if($ngoods != $nsku) {
|
|
Log::record("goods table's data is not equal {$nsku} where num_iid = {$num_iid}",Log::ERR);
|
|
Log::record("goods table's data is not equal {$nsku} where num_iid = {$num_iid}",Log::ERR);
|
|
- return false;
|
|
|
|
|
|
+ if($ret) $ret = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $npics = $this->mod_goods_images->where(array('goods_commonid' => $commonid))->count();
|
|
|
|
+ if($npics < $picnum) {
|
|
|
|
+ Log::record("imageerror: goods image import error where goods_commonid = {$commonid} picnum={$picnum} npics={$npics}",Log::ERR);
|
|
|
|
+ if($ret) $ret = false;
|
|
}
|
|
}
|
|
- return true;
|
|
|
|
|
|
+ return $ret;
|
|
}
|
|
}
|
|
}
|
|
}
|