예제 #1
0
        public async Task GetAndUpdate(BbItemDetail itemDetail)
        {
            countUpdate++;
            //List<BbGood> listGood = new List<BbGood>();
            foreach (var item in itemDetail.Sku)
            {
                string itemNo = string.Empty;
                int    index  = item.Outer_Id.LastIndexOf("|");
                itemNo = index != -1 ? item.Outer_Id.Substring(index + 1, item.Outer_Id.Length - index - 1): item.Outer_Id;
                //获取erp系统中的库存明细
                // var erpStorages = storeService.GetSrorage(listStockCk, itemNo);
                var erpStorages = storeService.GetBbSrorage(listStockCk, itemNo);
                //var erpStoragesHas = erpStorages.Where(e => Convert.ToInt32(e.EndQty) > 0).ToList();
                //计算库存量
                int qty = 0;

                if (erpStorages.Count > 0)
                {
                    foreach (var storage in erpStorages)
                    {
                        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 (qty == item.Num)
                        //{
                        //    log.Debug("erp库存与贝店库存相同不需要同步 :" + goods.Outer_Id +"库存数量"+qty + " =====" + DateTime.Now);
                        //}
                    }
                }
                //if (erpStorages.Count > 0)
                //{
                BbGood goods = new BbGood
                {
                    Iid      = itemDetail.Iid,
                    Sku_Id   = item.Id.ToString(),
                    Outer_Id = item.Outer_Id,
                    Qty      = qty.ToString()
                };
                if (qty != item.Num)
                {
                    await shopService.UpdateItemQty(goods);

                    log.Debug("ERP同步库存至贝店 :" + goods.Outer_Id + "库存数量" + qty + " ============");
                }
                //}
            }

            //log.Debug("贝店已经库存同步了:" + countUpdate + "条数据");
        }
예제 #2
0
파일: BbShopService.cs 프로젝트: zxswola/ZH
        public async Task <bool> UpdateItemQty(BbGood good)
        {
            try
            {
                string method = "beibei.outer.item.qty.update";
                using (HttpClient hc = new HttpClient())
                {
                    Dictionary <string, string> dict = new Dictionary <string, string>();
                    dict.Add("method", method);
                    dict.Add("app_id", appId);
                    dict.Add("secret", secret);
                    dict.Add("session", session);
                    dict.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    dict.Add("version", "1.0");
                    dict.Add("iid", good.Iid);
                    dict.Add("sku_id", good.Sku_Id);
                    dict.Add("outer_id", good.Outer_Id);
                    dict.Add("qty", good.Qty);
                    string sing = CommonHelper.BbOpera(dict, secret);
                    dict.Add("sign", sing);
                    FormUrlEncodedContent content = new FormUrlEncodedContent(dict);
                    HttpResponseMessage   msg     = await hc.PostAsync(gateway, content);

                    string res = await msg.Content.ReadAsStringAsync();

                    var resQty = CommonHelper.DeJson <BbQtyUpdateResponse>(res);
                    if (resQty != null)
                    {
                        log.Debug("id" + resQty.Data.Iid + "qty" + resQty.Data.Sale_Qty + "    " + resQty.Success);
                        return(resQty.Success);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return(false);
        }