みんなJingdongモールドッキングマイクロエンジンVOPドッキングJingdongはコモディティ、コモディティ同期アドレス、在庫、価格、およびラックダウン。Jingdongは、顧客の商品の背景グラフィカルインタフェースのドッキングプロセスをjdvop作成するために、AJAXを使用して、3つの層+ +マイクロエンジンモールみんな

今日、突然、我々は約5,000品目を同期する必要があり、動作することを学んだので、私は、バックグラウンド更新ページを記述する必要性を感じました

まず、図の効果 

単一商品としてアップデートや新製品のアップデート

 

 

 

すべての商品効果を更新し、次のとおりです。

 

 

 

 

 

ポップポップを使用して層の上に、ポップには、これは非常に良好であると言っているん

 

 いくつかの単語の男は、直接バーコードの上に、言いました

もちろん、それはヘッダーヘッダーでlayer.jsを導入することです

 

 

 

 

 次のjsの前部があります

<script>
    var num=0;
    var total=0;
    $("#updateAll").click(function(){
        if (num==0) {
            layer.msg('启动更新,获取商品总数中请等待', {time: 5000, icon:1});
            var url = ";
            var data = {type: 'getTotal'};
            $.ajax({
                type: 'get',
                async: true,
                url: url,
                data: data,
                dataType: "json",
                timeout: 90000,
                success: function (dates) {
                    if (dates.error == 0) {
                        num=num+20;
                        total = dates.total;
                        layer.msg('成功获取总商品数'+total+' 个 准备更新', {time: 6000, icon:1});
                        layer.msg('正在更新0/'+total+'个商品 请耐心等待', {time: 40000, icon:1});
                        $("#updateAll").click();
                    } else {
                        layer.alert('获取商品池数量失败')
                    }
                }
            })
        }else{
                var url = ";
                var data = {type: 'updateAll',num:num};
                $.ajax({
                    type: 'get',
                    async: true,
                    url: url,
                    data: data,
                    dataType: "json",
                    timeout: 90000,
                    success: function (dates) {
                        if (dates.error == 0&&dates.status==0) {
                            //提示层
                            layer.msg('正在更新第 '+num+'/'+total +' 请耐心等待', {time: 40000, icon:1});
                            num=num+20;
                            $("#updateAll").click();
                        } else {
                            if (dates.status == 1){
                                layer.alert('更新完成,本次共更新'+total+'个商品,请刷新页面。如遇更新不完整,请单独更新,或者重新更新');
                                num=0;
                                total=0;
                            }else {
                                layer.confirm('更新第' + num + '个区间商品失败,错误信息'+dates.errorMsg+'是否跳过该区间?', {
                                    btn: ['跳过', '取消'] //按钮
                                }, function () {
                                    num+=num+20;
                                    $("#updateAll").click();
                                }, function () {
                                    layer.msg('您选择了取消');
                                });
                            }
                        }
                    }
                })

            }
    });
    $("#update").click(
        function(){
            if (num==0) {
                layer.msg('启动更新,获取商品总数中请等待', {time: 5000, icon:1});
                var url = "http://amuying1.mynatapp.cc/web/index.php?c=site&a=entry&m=ewei_shopv2&do=web&r=goods.vopUpdateAll";
                var data = {type: 'getTotal',style:'update'};
                $.ajax({
                    type: 'get',
                    async: true,
                    url: url,
                    data: data,
                    dataType: "json",
                    timeout: 90000,
                    success: function (dates) {
                        if (dates.error == 0) {
                            num=num+20;
                            total = dates.total;
                            layer.msg('成功获取总商品数'+total+' 个 准备更新', {time: 6000, icon:1});
                            layer.msg('正在更新0/'+total+'个商品 请耐心等待', {time: 40000, icon:1});
                            $("#update").click();
                        } else {
                            layer.alert('获取商品池数量失败')
                        }
                    }
                })
            }else{
                var url = "http://amuying1.mynatapp.cc/web/index.php?c=site&a=entry&m=ewei_shopv2&do=web&r=goods.vopUpdateAll";
                var data = {type: 'update',num:num};
                $.ajax({
                    type: 'get',
                    async: true,
                    url: url,
                    data: data,
                    dataType: "json",
                    timeout: 90000,
                    success: function (dates) {
                        if (dates.error == 0&&dates.status==0) {
                            //提示层
                            layer.msg('正在更新第 '+num+'/'+total +' 请耐心等待', {time: 40000, icon:1});
                            num=num+20;
                            $("#update").click();
                        } else {
                            if (dates.status == 1){
                                layer.alert('更新完成,本次共更新'+total+'个商品,请刷新页面。如遇更新不完整,请单独更新,或者重新更新');
                                num=0;
                                total=0;
                            }else {
                                layer.confirm('更新第' + num + '个区间商品失败,错误信息'+dates.errorMsg+'是否跳过该区间?', {
                                    btn: ['跳过', '取消'] //按钮
                                }, function () {
                                    num+=num+20;
                                    $("#update").click();
                                }, function () {
                                    layer.msg('您选择了取消');
                                });
                            }
                        }
                    }
                })

            }
        }

    )
</script>

后端代码:

 /**
     * 更新全部商品,有就update  没有就 insert
     *
     */
    public function vopUpdateAll(){
        global $_GPC;
        if ($_GPC['type']=='getTotal'){
            // 获取部分全部商品数
            include_once EWEI_SHOPV2_PATH . 'jdvop/goods/controller/Index.php';
            $res=new \jdvop_goods\Index();
            if ($_GPC['style']=='update'){
                $result= $res->getAllSku(2);
            }else{
                $result= $res->getAllSku();
            }
            if ($result['error']!=0){
                echo json_encode(array('error'=>1,'errorMsg'=>$result['errorMsg'],'status'=>0));
                die;
            }else{
                echo json_encode(array('error'=>0,'total'=>$result['total'],'status'=>0));
                die;
            }
        }else if ($_GPC['type']=='updateAll'){
            // 更新商品 每次更新二十个
            if (isset($_GPC['num'])&&$_GPC['num']>=20){
                $psize=20;
                $pindex=$_GPC['num']-20;
                $getSku=pdo_fetchall('select sku from '.tablename('ewei_shop_jdvop_goods')." order by id asc  limit $pindex".','."$psize");
                if ($getSku){
                    // 获取部分全部商品数
                    include_once EWEI_SHOPV2_PATH . 'jdvop/goods/controller/Index.php';
                    $res=new \jdvop_goods\Index();
                   $result= $res->getDetail(1,$getSku);
                   if ($result==true){
                       echo json_encode(array('error'=>0,'status'=>0));
                       die;
                   }else{
                       echo json_encode(array('error'=>1,'status'=>0,'errorMsg'=>'获取商品信息错误,请重试'));
                       die;
                   }
                }else{
                    echo json_encode(array('error'=>0,'status'=>1));
                    die;
                }
            }
        }else if($_GPC['type']=='update'){
            // 更新商品 每次更新二十个
            if (isset($_GPC['num'])&&$_GPC['num']>=20){
                $psize=20;
                $pindex=$_GPC['num']-20;
                $getSku=pdo_fetchall('select sku from '.tablename('ewei_shop_jdvop_goods')." where status=0 order by id asc  limit $pindex".','."$psize");
                if ($getSku){
                    // 获取部分全部商品数
                    include_once EWEI_SHOPV2_PATH . 'jdvop/goods/controller/Index.php';
                    $res=new \jdvop_goods\Index();
                    $result= $res->getDetail(1,$getSku);
                    if ($result==true){
                        echo json_encode(array('error'=>0,'status'=>0));
                        die;
                    }else{
                        echo json_encode(array('error'=>1,'status'=>0,'errorMsg'=>'获取商品信息错误,请重试'));
                        die;
                    }
                }else{
                    echo json_encode(array('error'=>0,'status'=>1));
                    die;
                }
            }

        }

    }

    /**
     * 更新单个商品
     */
    public function vopUpdate(){
        global $_GPC;
        global $_W;
        if (empty($_GPC['id'])){
            show_json(0,'ID 非法');
        }else{
           $check= pdo_fetch('select jdsku from '.tablename('ewei_shop_goods')." where id=:id and uniacid=:uniacid",array(':id'=>$_GPC['id'],':uniacid'=>$_W['uniacid']));
          if ($check){
              // 获取部分全部商品数
              include_once EWEI_SHOPV2_PATH . 'jdvop/goods/controller/Index.php';
              $res=new \jdvop_goods\Index();
              $result= $res->getDetail(2,$check);
              if ($result==true){
                  show_json(1, array('url' => referer()));
              }else{
                  show_json(0,'更新失败'.$result['errorMsg']);
              }
          }else{
              show_json(0,'ID 非法');
          }
        }

    }

采用的是面向切面编程(oop) 里面具体的逻辑 控制器,不在赘述。 

おすすめ

転載: www.cnblogs.com/tongcharge/p/11497897.html