京东联盟开发(10)——轮询获取数据

轮循查询数据

判断当前页码是否结束,没有的话获取完当前页数据之后,再跳转到下一页 

    //手动 - 同步商品列表
	public function sync_jingdong($page = 1){
        Vendor('Jd.fangbei_class');
        $jtt = new \class_fangbei();
        $result = $jtt->get_goods_list($page = $page, $num = 100);
        
        //如果超过某个指定值
        if ($page >= $result["total_page"]){
            echo "完成";
        }else{
            // var_dump($result);
            $new = 0;
            $goods = M('jdunion_goods2');
            foreach ($result["data"] as &$item) {
                $new ++;
                $data = array();
                $data['skuid']              = $item['goods_id'];
                $data['couponprice']        = $item['coupon_price'];
                $data['couponlink']         = $item['discount_link'];
                $data['couponstart']        = $item['discount_start'] / 1000;
                $data['couponend']          = $item['discount_end'] / 1000;
                $result = $goods->add($data, array(), true);
            }
            $this->success(date("Y-m-d  H:i:s",time()).' 更新了'.$new.'条记录', U('jdunion/sync_jingdong',array('page'=>$page + 1)));
        }
	}

  

posted @ 2019-07-15 14:18 方倍工作室 阅读(...) 评论(...) 编辑 收藏