goods.services.php 文件添加采集函数,利用天猫精品库API采集商品
//add by wangtongphp QQ1006440989 通过天猫精品库API采集商品 public function infinityCollect($q,$cat,$start,$sort,$brand,$post_fee,$start_price,$end_price,$aution_tag) { setTimeLimit(3600); global $_FANWE; include_once FANWE_ROOT.'sdks/taobao/TopClient.php'; include_once FANWE_ROOT.'sdks/taobao/request/TmallItemsDiscountSearchRequest.php'; Cache::getInstance()->loadCache('business'); $client = new TopClient; $client->appkey = trim($_FANWE['cache']['business']['taobao']['app_key']); $client->secretKey = trim($_FANWE['cache']['business']['taobao']['app_secret']); $req = new TmallItemsDiscountSearchRequest; $req->setQ("%E8%80%90%E5%85%8B"); $req->setCat("2"); $req->setStart(0); $req->setSort("sort=s"); $req->setBrand(20531); $req->setPostFee(-1); $req->setStartPrice("100"); $req->setEndPrice("500"); $req->setAuctionTag(3458); $resp = $client->execute($req); $result = array('status'=>0,'count'=>0,'max_page'=>0); var_dump($resp); if(isset($resp->taobaoke_items) && isset($resp->taobaoke_items->taobaoke_item)) { $max_page = ceil(((int)$resp->total_results) / 40); $list = (array)$resp->taobaoke_items; $list = $list['taobaoke_item']; foreach($list as $item) { usleep(10); $item = (array)$item; $item['num_iid'] = (float)$item['num_iid']; $item['keyid'] = 'taobao_'.$item['num_iid']; $bln = (int)FDB::resultFirst('SELECT COUNT(id) FROM '.FDB::table('goods')." WHERE keyid='".$item['keyid']."'"); if($bln) continue; $bln = (int)FDB::resultFirst('SELECT COUNT(id) FROM '.FDB::table('goods_disable')." WHERE keyid='".$item['keyid']."'"); if($bln) continue; $item['nick'] = addslashes($item['nick']); //add by wangtongphp 如果不是天猫店铺,过滤掉;旗舰店、专卖店、专营店留下; if(!(mb_stripos($item['nick'],'旗舰店'))) { continue; } $item['title'] = addslashes(strip_tags($item['title'])); //add by wangtongphp 如果是男的,过滤; if(mb_stripos($item['title'],'男')) { continue; } $item['price'] = (float)$item['price']; $item['click_url'] = addslashes($item['click_url']); $item['shop_click_url'] = addslashes($item['shop_click_url']); $item['pic_url'] = addslashes($item['pic_url']); $item['item_location'] = addslashes($item['item_location']); $item['volume'] = (int)$item['volume']; $item['commission_rate'] = (float)$item['commission_rate'] / 100; $item['commission'] = (float)$item['commission']; $item['commission_num'] = (int)$item['commission_num']; $item['commission_volume'] = (float)$item['commission_volume']; FDB::insert('taobao_collect',$item,false,true); } $result['status'] = 1; $result['count'] = count($list); $result['max_page'] = $max_page; } return $result; }