示例#1
0
 public bool UpdateSrorage(DYGoods gd, string token)
 {
     try
     {
         Auth     auth     = new Token(token); // Auth auth = new Sign("app_id", "app_secret");
         YZClient yzClient = new DefaultYZClient(auth);
         Dictionary <string, object> dict = new System.Collections.Generic.Dictionary <string, object>();
         dict.Add("item_id", gd.ItemID);
         dict.Add("quantity", gd.Qty);
         dict.Add("type", 0);
         dict.Add("sku_id", gd.ItemSku);
         var result = yzClient.Invoke("youzan.item.quantity.update", "3.0.0", "POST", dict, null);
         var model  = CommonHelper.DeJson <UpdateSrorageResponse>(result);
         if (model.response != null)
         {
             return(model.response.is_success);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
     return(false);
 }
示例#2
0
        //获取待上传的数据
        //获取后上传
        public void GetUpdateList(ItemsItem item)
        {
            countUpdate++;
            List <DYGoods> listUpdateData = new List <DYGoods>();
            //获取有赞商店里商品的明细类别 如大小 L M 号的sku编码
            var skuRoot     = shopService.GetSku_Root(item.item_id, token);
            var itemDetails = skuRoot.response.item.skus;

            foreach (var itemDetail in itemDetails)
            {
                //编码处理
                string itemNo = string.Empty;
                int    index  = itemDetail.item_no.LastIndexOf("|");
                itemNo = index != -1 ? itemDetail.item_no.Substring(index + 1, itemDetail.item_no.Length - index - 1) : itemDetail.item_no;
                //获取erp系统中的库存明细
                var erpStorages    = storeService.GetSrorage(listStockCk, itemNo);
                var erpStoragesHas = erpStorages.Where(e => Convert.ToInt32(e.EndQty) > 0).ToList();
                //计算库存量
                int qty = 0;
                foreach (var storage in erpStoragesHas)
                {
                    int index1 = listStockCk.FindIndex(e => e == storage.StorageID);
                    if (index1 >= 0)
                    {
                        double a = Convert.ToDouble(storage.EndQty) * Convert.ToDouble(listStockPer[index1]);
                        if (a >= 1)
                        {
                            qty += Convert.ToInt32(Math.Floor(a));
                        }
                    }
                }

                if (erpStorages.Count > 0)
                {
                    var goods = new DYGoods {
                        ItemID = item.item_id, Qty = qty, ItemSku = itemDetail.sku_id.ToString()
                    };
                    if (goods.Qty != itemDetail.quantity)
                    {
                        log.Debug("ERP同步库存至有赞 :" + goods.ItemSku + "库存数量" + qty + " ============");
                        shopService.UpdateSrorage(goods, token);
                    }
                }



                //if (goods.Qty == itemDetail.quantity)
                //{
                //    log.Debug("erp库存与有赞库存相同不需要同步 :" + goods.GoodNo + "库存数量" + goods.Qty + DateTime.Now);
                //}
            }

            //if (listUpdateData.Count == 0)
            //{
            //    log.Error("erp系统中没有有赞商城的数据 itemId:" + item.item_id);
            //}
            //else
            //{
            //    //同步数据
            //    foreach (var data in listUpdateData)
            //    {
            //        if (data.Qty != item.quantity)
            //        {
            //            // log.Debug("准备开始同步 :" + CommonHelper.ToJson(data));
            //            shopService.UpdateSrorage(data, token);
            //            // log.Debug("同步成功 :" + CommonHelper.ToJson(data));
            //        }
            //        //else
            //        //{
            //        //    //log.Debug("库存数目与有赞商店相同不需要同步:" + CommonHelper.ToJson(data));
            //        //}
            //    }
            //}
            // log.Debug("有赞已经库存同步了:" + countUpdate+"条数据");
        }