public void EleUpdateStock(string userId, string shopNo, IEnumerable <dynamic> data) { var service = new EleFoodApiService(); var shop = _eleShopService.Get(userId, shopNo); if (shop is null) { return; } var total = data.Count(); var size = 50; var pageCount = (total + size - 1) / size; var msg = ""; for (var i = 0; i < pageCount; i++) { var dd = data.Skip(i * size).Take(size); var dic = new Dictionary <long, int>(); foreach (var item in dd) { var stock = 0; if (ToolsCommon.IsPositiveNumber(item["Stock"].ToString())) { stock = (int)item["Stock"]; } dic.Add(long.Parse(item["ProdCode"].ToString().Split(';')[1]), stock); } var result = service.BatchUpdateStock(shop.AccessToken, dic); } }
public FoodMapController() { _serviceFood = new EleFoodApiService(); _prodList = Bak365Service.GetProdList(); }
public EleFoodService() { _shopService = new EleShopService(); _foodApiService = new EleFoodApiService(); }
//售卖状态,1表下架,0表上架 private async Task EleUpDown(string userId, string shopNo, IEnumerable <StockModel> models) { var service = new EleFoodApiService(); var shop = _eleShopService.Get(userId, shopNo); if (shop == null) { return; } //通过接口查询门店商品,然后转化成 Id对应ProdNo var res = service.QueryItemByPage(shop.AccessToken, shop.ShopId); if (res.error != null) { return; } var oItems = JsonConvert.DeserializeObject <List <OItem> >(res.result.ToString()); var idNos = ( from oItem in oItems from spec in oItem.specs select new { Id = oItem.id, specId = spec.specId, ProdNo = spec.extendCode }) .ToList(); //匹配对应的SpecId var data = from a in models join b in idNos on a.ProdNo equals b.ProdNo select new StockModel { ProdId = b.Id, SpecId = b.specId, ProdNo = b.ProdNo, CurrentStock = a.CurrentStock, EleMarkStock = a.EleMarkStock }; var size = 50; //分批次提交 //上架 提交商品Id { var upData = data.Where(x => x.CurrentStock > x.EleMarkStock).Select(x => x.ProdId); if (!upData.Any()) { return; } var loop = (upData.Count() + size - 1) / size; for (var i = 0; i < loop; i++) { var response = service.BatchListItems(shop.AccessToken, upData.Skip(i * size).Take(size).ToList()); } } //下架 提交商品Id { var downData = data.Where(x => x.CurrentStock <= x.EleMarkStock).Select(x => x.ProdId); if (!downData.Any()) { return; } var loop = (downData.Count() + size - 1) / size; for (var i = 0; i < loop; i++) { var response = service.BatchDelistItems(shop.AccessToken, downData.Skip(i * size).Take(size).ToList()); } } //上架时更新库存 提交商品规格Id { var upData = data.Where(x => x.CurrentStock > x.EleMarkStock); if (!upData.Any()) { return; } var loop = (upData.Count() + size - 1) / size; for (var i = 0; i < loop; i++) { var dic = upData.Skip(i * size).Take(size).ToDictionary(x => x.SpecId, x => ToolsCommon.IsPositiveNumber(x.CurrentStock.ToString()) ? (int)x.CurrentStock : 0); var response = service.BatchUpdateStock(shop.AccessToken, dic); } } }