public function index() { $p = I('p', 1, 'intval'); $cid = I('cid', '', 'intval'); $top = $this->_get_top(); $req = $top->load_api('FtxiaJuCatsGetRequest'); $req->setFields('cid,name'); $resp = $top->execute($req); $cats = object_to_array($resp->cats); $this->assign('cats', $cats); $ltop = $this->_get_top(); $req = $ltop->load_api('FtxiaJuListsGetRequest'); $req->setPage($p); $req->setCid($cid); $req->setTime(date("y-m-d-h", time())); $resp = $ltop->execute($req); $jus = object_to_array($resp->lists); $count = $jus['totalPage']; $html = Newiconv("GBK", "UTF-8", urldecode($jus['html'])); $html = str_replace("data-ks-lazyload", "src", $html); $html = str_replace("&id=", "&tm=", $html); $html = str_replace("http://detail.ju.taobao.com/home.htm?item_id=", "?m=jump&a=index&iid=", $html); $html = str_replace("&tm=", "&from=open.ftxia.com", $html); $pager = $this->_pager($count, '1'); $this->assign('page', $pager->kshow()); $this->assign('html', $html); $this->assign('cid', $cid); $this->assign('nav_curr', 'ju'); $this->_config_seo(array('title' => ' 汇聚最划算的团购商品 - ')); $this->display(); }
public function index() { $act_sign_id = I('act_sign_id', 'intval'); $ltop = $this->_get_top(); $req = $ltop->load_api('FtxiaJuBrandItemsGetRequest'); $req->setSid($act_sign_id); $req->setTime(date("y-m-d-h", time())); $resp = $ltop->execute($req); $jus = object_to_array($resp->items); $html = Newiconv("GBK", "UTF-8", urldecode($jus['html'])); $html = str_replace("data-ks-lazyload", "src", $html); $this->assign('html', $html); $this->assign('nav_curr', 'ju'); $this->_config_seo(array('title' => ' 汇聚最划算的团购商品 - ' . C('ftx_site_name'))); $this->display(); }
public function taobao_collect($date, $p) { M('robots')->where(array('id' => $date['id']))->save(array('last_page' => $p, 'last_time' => time())); $s = ($p - 1) * 44; $q = ''; $tp = F('tp'); if ($p > 1) { if ($p > $tp) { $this->ajaxReturn(0, '已经采集完成' . $tp . '页!请返回,谢谢'); } } if ($p == 1) { $totalcoll = 0; } else { $totalcoll = F('totalcoll'); } if ($date['tb_cid']) { $q .= '&cat=' . $date['tb_cid']; } if ($date['keyword']) { $q .= '&q=' . $date['keyword']; } if ($date['shop_type'] == 'B') { $q .= '&tab=mall'; } else { $q .= '&tab=all'; } if ($date['start_coupon_rate'] && $date['end_coupon_rate'] && $date['start_coupon_rate'] < $date['end_coupon_rate']) { $q .= '&zk_rate=%5B' . $date['start_coupon_rate'] . '%2C' . $date['end_coupon_rate'] . '%5D'; } if ($date['start_price'] && $date['end_price'] && $date['start_price'] < $date['end_price']) { //$q.='&start_price='.$date['start_price'].'&end_price='.$date['end_price']; $q .= '&filter=reserve_price%5B' . $date['start_price'] . '%2C' . $date['end_price'] . '%5D'; } if ($date['sort']) { $sorts = explode("|", $date['sort']); if ($sorts[0] == 'volume') { $sorts[0] = 'sale'; } $q .= '&sort=' . $sorts[0] . '-' . $sorts[1]; } $url = 'http://s.taobao.com/search?commend=all' . $q . '&style=grid&atype=b&limitPromotion=true&filterFineness=2&fs=1&discount_index=1&s=' . $s . '&zk_type=0#J_FilterTabBar'; $ftxia_https = new ftxia_https(); $ftxia_https->fetch($url); $content = $ftxia_https->results; if (!$content) { $content = file_get_contents($url); } $content = Newiconv("GBK", "UTF-8", $content); $ck = get_word($content, '<li class="home"><a href="http:\\/\\/www.taobao.com\\/">', '<\\/a><\\/li>'); $pre = L('pre'); $totalnum = get_word($content, L($pre . 'total_start'), L($pre . 'total_end')); if (strpos($totalnum, L($pre . 'wang'))) { $totalnum = get_word($content, L($pre . 'total_start'), L($pre . 'total_ends')); $totalnum = $totalnum * 10000; } $tp = intval($totalnum / 40) + 1; F('tp', $tp); if (preg_match_all(L($pre . 'listitem'), $content, $matchitem)) { for ($i = 0; $i < count($matchitem[0]); $i++) { $pi = ($p - 1) * 40 + $i; $msg = '折扣不满足。不采集'; $item = $matchitem[1][$i]; $titlebar = get_word($item, L($pre . 'titlebar_start'), L($pre . 'titlebar_end')); $title = get_word($titlebar, L($pre . 'title_start'), L($pre . 'title_end')); $img = get_word($item, L($pre . 'img_start'), L($pre . 'img_end')); if (!$img) { $img = get_word($item, L($pre . 'imgs_start'), L($pre . 'imgs_end')); if (!$img) { $img = get_word($item, L($pre . 'imgss_start'), L($pre . 'imgss_end')); } } $iid = get_word($item, L($pre . 'iid_start'), L($pre . 'iid_end')); $price = get_word($item, L($pre . 'price_start'), L($pre . 'price_end')); if (!$price) { $pricebar = get_word($item, L($pre . 'pricesssbar_start'), L($pre . 'pricesssbar_end')); $price = get_word($pricebar, L($pre . 'pricesss_start'), L($pre . 'pricesss_end')); } $zkprice = get_word($item, L($pre . 'zkprice_start'), L($pre . 'zkprice_end')); if (!$zkprice) { $zkprice = get_word($item, L($pre . 'zkprices_start'), L($pre . 'zkprices_end')); } if (!$price) { $price = $zkprice; } $volume = get_word($item, L($pre . 'volume_start'), L($pre . 'volume_end')); $nickbar = get_word($item, L($pre . 'nickbar_start'), L($pre . 'nickbar_end')); $nick = get_word($nickbar, L($pre . 'nick_start'), L($pre . 'nick_end')); $ems = get_word($item, L($pre . 'ems_start'), L($pre . 'ems_end')); if (!$ems) { $ems = get_word($item, L($pre . 'emss_start'), L($pre . 'emss_end')); } if ($ems) { if (strpos($ems, L($pre . 'emsor'))) { $ems = '1'; } else { $ems = '0'; } } else { $ems = L('def_ems'); } if (!$volume) { $volume = 0; } $zekou = get_word($item, L($pre . 'zekou_start'), L($pre . 'zekou_end')); if (!$zekou) { $zekou = get_word($item, L($pre . 'zekous_start'), L($pre . 'zekous_end')); if (!$zekou) { $zekou = L('def_coupon_rate'); } } $coupon_add_time = C('ftx_coupon_add_time'); if ($coupon_add_time) { $times = (int) (time() + $coupon_add_time * 3600); } else { $times = (int) (time() + 72 * 86400); } if (strpos($item, 'tmall.com')) { $itemarray['shop_type'] = 'B'; } else { $itemarray['shop_type'] = 'C'; } $itemarray['title'] = $title; $itemarray['pic_url'] = $img; $itemarray['num_iid'] = $iid; $itemarray['price'] = $price; $itemarray['coupon_price'] = $zkprice; $itemarray['volume'] = $volume; $itemarray['nick'] = $nick; $itemarray['ems'] = $ems; $itemarray['cate_id'] = $date['cate_id']; $itemarray['coupon_rate'] = $zekou * 1000; $itemarray['coupon_end_time'] = $times; $itemarray['coupon_start_time'] = time(); if ($title && $img && $iid && $nick) { $result['item_list'][] = $itemarray; } } } else { $result['msg'] = '采集结束!请返回2'; } $taobaoke_item_list = $result['item_list']; $taobaoke_item_list && F('taobaoke_item_list', $taobaoke_item_list); $coll = 0; $thiscount = 0; foreach ($taobaoke_item_list as $key => $val) { $res = $this->_ajax_tb_publish_insert($val); if ($res > 0) { $coll++; $totalcoll++; } $thiscount++; } F('totalcoll', $totalcoll); $result_data['p'] = $p; $result_data['msg'] = $msg; $result_data['coll'] = $coll; $result_data['totalcoll'] = $totalcoll; $result_data['totalnum'] = $totalnum; $result_data['thiscount'] = $thiscount; return $result_data; }
public function taobao_collect($date, $p) { M('robots')->where(array('id' => $date['id']))->save(array('last_page' => $p, 'last_time' => time())); $s = ($p - 1) * 44; $q = ''; $tp = 100; //F('tp');//35732 if ($p > 1) { if ($p > $tp) { $this->ajaxReturn(0, '已经采集完成' . $tp . '页!请返回,谢谢'); } } if ($p == 1) { $totalcoll = 0; } else { $totalcoll = F('totalcoll'); } if ($date['tb_cid']) { $q .= '&cat=' . $date['tb_cid']; } if ($date['keyword']) { $q .= '&q=' . $date['keyword']; } if ($date['shop_type'] == 'B') { $q .= '&tab=mall&isprepay=1'; } else { $q .= '&tab=all&apassall=1'; } if ($date['start_price'] && $date['end_price'] && $date['start_price'] < $date['end_price']) { $q .= '&filter=reserve_price%5B' . $date['start_price'] . '%2C' . $date['end_price'] . '%5D'; } if ($date['sort']) { $sorts = explode('|', $date['sort']); if ($sorts[0] == 'volume') { $sorts[0] = 'sale'; } $q .= '&sort=' . $sorts[0] . '-' . $sorts[1]; } $url = 'http://s.taobao.com/search?' . $q . '&style=grid&fs=0&cps=yes&initiative_id=staobaoz_20140606&promote=0&s=' . $s . '#J_relative'; $ftxia_https = new ftxia_https(); $ftxia_https->fetch($url); $content = $ftxia_https->results; if (!$content) { $content = file_get_contents($url); } $content = Newiconv("GBK", "UTF-8", $content); $ck = get_word($content, '<li class="home"><a href="http:\\/\\/www.taobao.com\\/">', '<\\/a><\\/li>'); $pre = L('pre'); $totalnum = get_word($content, L($pre . 'total_start'), L($pre . 'total_end')); $tp = intval($totalnum / 44) + 1; if (preg_match_all(L($pre . "listitem"), $content, $matchitem)) { //44 $mtmp = array(); for ($i = 0; $i < count($matchitem[0]); $i++) { $pi = ($p - 1) * 44 + $i; $msg = '折扣不满足。不采集'; $item = $matchitem[1][$i]; $titlebar = get_word($item, L($pre . 'titlebar_start'), L($pre . 'titlebar_end')); $title = get_word($titlebar, L($pre . 'title_start'), L($pre . 'title_end')); $img = get_word($item, L($pre . 'img_start'), L($pre . 'img_end')); if (!$img) { $img = get_word($item, L($pre . 'imgs_start'), L($pre . 'imgs_end')); if (!$img) { $img = get_word($item, L($pre . 'imgss_start'), L($pre . 'imgss_end')); } } $iid = get_word($item, L($pre . 'iid_start'), L($pre . 'iid_end')); $price = get_word($item, L($pre . 'price_start'), L($pre . 'price_end')); if (!$price) { $price = get_word($item, L($pre . 'prices_start'), L($pre . 'prices_end')); } if (!$price) { $price = get_word($item, L($pre . 'pricess_start'), L($pre . 'pricess_end')); } if (!$price) { $pricebar = get_word($item, L($pre . 'pricesssbar_start'), L($pre . 'pricesssbar_end')); $price = get_word($pricebar, L($pre . 'pricesss_start'), L($pre . 'pricesss_end')); } $zkprice = get_word($item, L($pre . 'zkprice_start'), L($pre . 'zkprice_end')); if (!$price) { $price = $zkprice; } $volume = get_word($item, L($pre . 'volume_start'), L($pre . 'volume_end')); $hits = get_word($item, L($pre . 'hits_start'), L($pre . 'hits_end')); $nick = get_word($item, L($pre . 'nick_start'), L($pre . 'nick_end')); $nick = urldecode($nick); $ems = get_word($item, L($pre . 'ems_start'), L($pre . 'ems_end')); if (!$ems) { $ems = get_word($item, L($pre . 'emss_start'), L($pre . 'emss_end')); } if ($ems) { if ($pre == 'hk_') { if (strpos($ems, '免運費')) { $ems = '1'; } else { $ems = '0'; } } else { if (strpos($ems, '免运费')) { $ems = '1'; } else { $ems = '0'; } } } else { $ems = '1'; } if (!$volume) { $volume = 0; } $zekou = round($zkprice / $price * 10, 1); $coupon_add_time = C('ftx_coupon_add_time'); if ($coupon_add_time) { $times = (int) (time() + $coupon_add_time * 3600); } else { $times = (int) (time() + 72 * 86400); } if (strpos($item, 'tmall.com')) { $itemarray['shop_type'] = 'B'; } else { $itemarray['shop_type'] = 'C'; } $volume = trim($volume); $volume = str_ireplace('人付款', '', $volume); $price = trim($price); $price = str_ireplace('<i>¥</i>', '', $price); $tag_list = d("items")->get_tags_by_title($title); $tags = implode(" ", $tag_list); $zkprice = trim($zkprice); $zkprice = str_ireplace('<i>¥</i>', '', $zkprice); $itemarray['title'] = $title; $itemarray['intro'] = '强烈推荐:' . $title . ',优惠活动折扣价格:' . $zkprice . '元,已成交:' . $volume . '笔。'; $itemarray['pic_url'] = $img; $itemarray['num_iid'] = $iid; $itemarray['hits'] = $hits; $itemarray['price'] = $price; $itemarray['likes'] = rand(99, 9999); $itemarray['coupon_price'] = $zkprice; $itemarray['volume'] = $volume; $itemarray['nick'] = $nick; $itemarray['tags'] = $tags; $itemarray['ems'] = $ems; $itemarray['cate_id'] = $date['cate_id']; $itemarray['coupon_rate'] = $zekou * 1000; $itemarray['coupon_end_time'] = $times; $itemarray['coupon_start_time'] = time(); if ($title && $img && $iid) { $result['item_list'][] = $itemarray; } //exit(print_r($itemarray)); } } else { $result['msg'] = '采集结束!请返回2'; } $taobaoke_item_list = $result['item_list']; $taobaoke_item_list && F('taobaoke_item_list', $taobaoke_item_list); $coll = 0; $thiscount = 0; foreach ($taobaoke_item_list as $key => $val) { $res = $this->_ajax_tb_publish_insert($val); if ($res > 0) { $coll++; $totalcoll++; } $thiscount++; } F('totalcoll', $totalcoll); $result_data['p'] = $p; $result_data['msg'] = $msg; $result_data['coll'] = $coll; $result_data['totalcoll'] = $totalcoll; $result_data['totalnum'] = $totalnum; $result_data['thiscount'] = $thiscount; return $result_data; }