|
@@ -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);
|
|
|
}
|
|
|
|