示例#1
0
 function get($cate_id = 0)
 {
     global $_G;
     $req = new ItemcatsGetRequest();
     //$req->setFields("cid,parent_cid,name,is_parent");
     $req->setFields("cid,name");
     $req->setParentCid($cate_id);
     $resp = $_G['TOP']->execute($req);
     top_check_error($resp, 1);
     return $this->parse($resp->item_cats->item_cat);
 }
示例#2
0
 function getCats($parentid)
 {
     $c = new TopClient();
     $c->appkey = APPKEY;
     $c->secretKey = SECRETKEY;
     $req = new ItemcatsGetRequest();
     $req->setFields("cid,parent_cid,name,is_parent");
     //50011740 男鞋
     //16 女装/女士精品
     //50006842 箱包皮具/热销女包/男包
     //50012029 运动鞋new
     //30 男装
     $req->setParentCid($parentid);
     return $c->execute($req);
 }
示例#3
0
 public function collectCates()
 {
     setTimeLimit(3600);
     $ccate = FDB::fetchFirst('SELECT * FROM ' . FDB::table('goods_cate_collect') . ' LIMIT 0,1');
     if (!$ccate) {
         return false;
     }
     FDB::query('DELETE FROM ' . FDB::table('goods_cate_collect') . " WHERE id = '{$ccate['id']}'");
     global $_FANWE;
     include_once FANWE_ROOT . 'sdks/taobao/TopClient.php';
     include_once FANWE_ROOT . 'sdks/taobao/request/ItemcatsGetRequest.php';
     Cache::getInstance()->loadCache('business');
     $sort_file = FANWE_ROOT . '/public/records/cate.sort.php';
     $sort = (int) @file_get_contents($sort_file);
     $client = new TopClient();
     $client->appkey = trim($_FANWE['cache']['business']['taobao']['app_key']);
     $client->secretKey = trim($_FANWE['cache']['business']['taobao']['app_secret']);
     $req = new ItemcatsGetRequest();
     $req->setFields("cid,parent_cid,name,is_parent");
     $req->setParentCid($ccate['cid']);
     $resp = $client->execute($req);
     if (isset($resp->item_cats) && isset($resp->item_cats->item_cat)) {
         foreach ($resp->item_cats->item_cat as $item) {
             $item = (array) $item;
             $cate = array();
             $cate['type'] = 'taobao';
             $cate['id'] = $item['cid'];
             $cate['pid'] = $item['parent_cid'] == 0 ? '' : $item['parent_cid'];
             $cate['name'] = $item['name'];
             $cate['pids'] = empty($ccate['pids']) ? $cate['pid'] : $ccate['pids'] . ',' . $cate['pid'];
             $cate['sort'] = ++$sort;
             FDB::insert('goods_cates', $cate, false, true);
             if ($item['is_parent'] == 'true') {
                 FDB::insert('goods_cate_collect', array('id' => 'NULL', 'cid' => $item['cid'], 'pids' => $cate['pids']));
             }
         }
         @file_put_contents($sort_file, $sort);
     }
     return true;
 }
示例#4
0
 /**
  * 获取商品类目
  *
  * @param int $parent_id
  * @return array
  */
 public function getItemCates($parent_id)
 {
     require_once 'Request/ItemcatsGetRequest.php';
     $req = new ItemcatsGetRequest();
     $req->setFields("cid,parent_cid,name,is_parent");
     $req->setParentCid($parent_id);
     $resp = $this->_topClient->execute($req);
     return is_array($resp) && isset($resp['item_cats']['item_cat']) ? $resp['item_cats']['item_cat'] : array();
 }
示例#5
0
function xt_taobao_item_cats($parentCid = 0, $cids = array())
{
    $app = xt_taobao_is_ready();
    if (!$app) {
        return new WP_Error('系统错误', '尚未配置淘宝开放平台!');
    }
    include_once XT_PLUGIN_DIR . '/xt-core/sdks/taobao/RequestCheckUtil.php';
    include_once XT_PLUGIN_DIR . '/xt-core/sdks/taobao/TopClient.php';
    include_once XT_PLUGIN_DIR . '/xt-core/sdks/taobao/request/ItemcatsGetRequest.php';
    $client = new TopClient();
    $client->format = 'json';
    $client->appkey = $app['appKey'];
    $client->secretKey = $app['appSecret'];
    $req = new ItemcatsGetRequest();
    $req->setFields("cid,parent_cid,name,is_parent,status,sort_order");
    if (!empty($cids) && $parentCid === 0) {
        $req->setCids(implode(',', array_map("absint", $cids)));
    } else {
        $req->setParentCid(absint($parentCid));
    }
    $resp = $client->execute($req);
    if (isset($resp->sub_code)) {
        return new WP_Error($resp->sub_code > 0 ? $resp->sub_code : '500', $resp->sub_msg);
    } elseif (isset($resp->code)) {
        return new WP_Error($resp->code > 0 ? $resp->code : '500', $resp->msg);
    }
    if (isset($resp->item_cats) && isset($resp->item_cats->item_cat)) {
        return $resp->item_cats->item_cat;
    }
    return array();
}