|
@@ -13,6 +13,7 @@ class pretreat_tmdata
|
|
private $tm_props;
|
|
private $tm_props;
|
|
private $tm_prop_values;
|
|
private $tm_prop_values;
|
|
private $goods_class;
|
|
private $goods_class;
|
|
|
|
+ private $cls_tree;
|
|
|
|
|
|
public function __construct()
|
|
public function __construct()
|
|
{
|
|
{
|
|
@@ -21,12 +22,13 @@ class pretreat_tmdata
|
|
$this->tm_props = Model('tm_props');
|
|
$this->tm_props = Model('tm_props');
|
|
$this->tm_prop_values = Model('tm_prop_values');
|
|
$this->tm_prop_values = Model('tm_prop_values');
|
|
$this->goods_class = Model('goods_class');
|
|
$this->goods_class = Model('goods_class');
|
|
|
|
+ $this->cls_tree = new class_tree();
|
|
}
|
|
}
|
|
|
|
|
|
- public function proc($create_brand)
|
|
|
|
|
|
+ public function proc()
|
|
{
|
|
{
|
|
- $this->tm_spec->where(array('num_iid > 0'))->delete();
|
|
|
|
- $results = $this->tm_goods->field('body,title,num_iid')->where(array('imported' => 0))->limit(false)->select();
|
|
|
|
|
|
+ $this->tm_spec->where(array('num_iid > 0'))->delete(); //->where(array('imported' => 0))
|
|
|
|
+ $results = $this->tm_goods->field('body,title,num_iid')->limit(false)->select();
|
|
foreach ($results as $result) {
|
|
foreach ($results as $result) {
|
|
$num_iid = $result['num_iid'];
|
|
$num_iid = $result['num_iid'];
|
|
$body = $result['body'];
|
|
$body = $result['body'];
|
|
@@ -43,21 +45,6 @@ class pretreat_tmdata
|
|
$this->parse_tm_pic($item,$picnum);
|
|
$this->parse_tm_pic($item,$picnum);
|
|
$this->tm_goods->where(array('num_iid' => $num_iid))->update(array('picnum' => $picnum));
|
|
$this->tm_goods->where(array('num_iid' => $num_iid))->update(array('picnum' => $picnum));
|
|
}
|
|
}
|
|
- if($create_brand == true) {
|
|
|
|
- $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)
|
|
private function parse_propnames($propnames)
|
|
@@ -128,8 +115,11 @@ class pretreat_tmdata
|
|
return $ret['gc_name'];
|
|
return $ret['gc_name'];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
private function download($url)
|
|
private function download($url)
|
|
{
|
|
{
|
|
|
|
+ static $pngext = array('png');
|
|
|
|
+
|
|
$info = pathinfo($url);
|
|
$info = pathinfo($url);
|
|
$name = md5($url) . '.' . $info['extension'];
|
|
$name = md5($url) . '.' . $info['extension'];
|
|
|
|
|
|
@@ -140,7 +130,26 @@ class pretreat_tmdata
|
|
exec("wget -O $path $pic_url");
|
|
exec("wget -O $path $pic_url");
|
|
}
|
|
}
|
|
|
|
|
|
- if(file_exists($path)) {
|
|
|
|
|
|
+ if(file_exists($path))
|
|
|
|
+ {
|
|
|
|
+ $fh = fopen($path, "rb");
|
|
|
|
+ $head = fread($fh, 8);
|
|
|
|
+ fclose($fh);
|
|
|
|
+
|
|
|
|
+ if(empty($head)) {
|
|
|
|
+ unlink($path);
|
|
|
|
+ Log::record("{$path} file is empty.",Log::ERR);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(!in_array($info['extension'],$pngext))
|
|
|
|
+ {
|
|
|
|
+ $arr = unpack("C4", $head);
|
|
|
|
+ if($arr[1] == 137 && $arr[2] == 80 && $arr[3] == 78 && $arr[4] == 71) {
|
|
|
|
+ Log::record("{$path} is a png file",Log::ERR);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
return true;
|
|
return true;
|
|
} else {
|
|
} else {
|
|
return false;
|
|
return false;
|
|
@@ -180,6 +189,8 @@ class pretreat_tmdata
|
|
{
|
|
{
|
|
if($this->download($pic)) {
|
|
if($this->download($pic)) {
|
|
$arpic[$name] = 1;
|
|
$arpic[$name] = 1;
|
|
|
|
+ } else {
|
|
|
|
+ Log::record("download pic {$pic}.",Log::ERR);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
//$arpic[$name] += 1;
|
|
//$arpic[$name] += 1;
|