public async Task DsCoupons(IFormFile excelfile) { string sWebRootFolder = _webHostEnvironment.WebRootPath; string sFileName = $"{Guid.NewGuid()}.json"; var path = Path.Combine(sWebRootFolder, sFileName); FileInfo file = new FileInfo(path); using (FileStream fs = new FileStream(file.ToString(), FileMode.Create)) { excelfile.CopyTo(fs); fs.Flush(); } string NotUserInfo = null; string package = System.IO.File.ReadAllText(path, Encoding.Default); List <CouponModel> list = JsonConvert.DeserializeObject <List <CouponModel> >(package); foreach (var item in list) { var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip }; UserInfoModel userInfo = null; using (var httpClient = new HttpClient()) { var requestUri = "https://loosen.microfeel.net/api/user/getList?Name=" + item.Name; var httpResponseMessage = await httpClient.GetAsync(requestUri); var responseConetent = await httpResponseMessage.Content.ReadAsStringAsync(); userInfo = JsonConvert.DeserializeObject <List <UserInfoModel> >(responseConetent).FirstOrDefault(); } if (userInfo == null) { NotUserInfo += item.Name + "无用户信息" + "\n"; continue; } List <Coupon> coupons = null; using (var httpClient = new HttpClient()) { var requestUri = "https://loosen.microfeel.net/api/user/get-coupon?UserId=" + userInfo.Id + "&CouponTypeName=" + item.Type; var httpResponseMessage = await httpClient.GetAsync(requestUri); var responseConetent = await httpResponseMessage.Content.ReadAsStringAsync(); coupons = JsonConvert.DeserializeObject <List <Coupon> >(responseConetent); } if (coupons == null) { NotUserInfo += item.Name + "无卡卷信息" + "\n"; continue; } if (coupons.Count > item.Count) { int useCount = coupons.Count - item.Count; for (int i = 0; i < useCount; i++) { using var httpClient = new HttpClient(); var requestUri = "https://loosen.microfeel.net/api/user/use-coupon?couponId=" + coupons[i].Id; var httpResponseMessage = await httpClient.GetAsync(requestUri); var responseConetent = await httpResponseMessage.Content.ReadAsStringAsync(); httpResponseMessage.EnsureSuccessStatusCode(); if (httpResponseMessage.IsSuccessStatusCode) { NotUserInfo += "消耗:" + coupons[i].CouponTypeName + "\n"; } } } } using StreamWriter txtFile = new StreamWriter(System.IO.File.Create(Path.Combine(sWebRootFolder, "卡卷.txt"))); txtFile.WriteLine(NotUserInfo); }
private static async Task <string> NewMethod(SavingModel item, HttpClientHandler handler, UserInfoModel userInfo, decimal balance) { string NotUserInfo = null; if (balance == item.Price) { NotUserInfo += item.Name + item.Type.ToString() + "信息准确,"; } else if (balance < item.Price) { RechargeInputModel RechargeInput = new RechargeInputModel { Balance = item.Price - balance, ChannelType = ChannelType.数据导入, Money = item.Price - balance, OwnerId = userInfo.Id, SavingSource = SavingSource.平台已有数据导入, SavingType = item.Type }; NotUserInfo += item.Name + "充值" + await PostRecharge(handler, RechargeInput); } else if (balance > item.Price) { WithholdInputModel withhold = new WithholdInputModel { PayPrice = balance - item.Price, PayType = PayType.余额支付, UserId = userInfo.Id }; NotUserInfo += item.Name + "扣款" + await PostWithhold(handler, withhold); } return(NotUserInfo); }
public async Task DSSavings(IFormFile excelfile) { string sWebRootFolder = _webHostEnvironment.WebRootPath; string sFileName = $"{Guid.NewGuid()}.json"; var path = Path.Combine(sWebRootFolder, sFileName); FileInfo file = new FileInfo(path); using (FileStream fs = new FileStream(file.ToString(), FileMode.Create)) { excelfile.CopyTo(fs); fs.Flush(); } string NotUserInfo = null; string package = System.IO.File.ReadAllText(path, Encoding.Default); List <SavingModel> list = JsonConvert.DeserializeObject <List <SavingModel> >(package); foreach (var item in list) { var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip }; UserInfoModel userInfo = null; using (var httpClient = new HttpClient()) { var requestUri = "https://loosen.microfeel.net/api/user/getList?Name=" + item.Name; var httpResponseMessage = await httpClient.GetAsync(requestUri); var responseConetent = await httpResponseMessage.Content.ReadAsStringAsync(); userInfo = JsonConvert.DeserializeObject <List <UserInfoModel> >(responseConetent).FirstOrDefault(); } if (userInfo == null) { NotUserInfo += item.Name + "无用户信息" + "\n"; continue; } //WithholdInputModel withhold = null; switch (item.Type) { case SavingType.通用余额: NotUserInfo += await NewMethod(item, handler, userInfo, userInfo.Balance_Common) + "\n"; break; case SavingType.团教余额: NotUserInfo += await NewMethod(item, handler, userInfo, userInfo.Balance_Group) + "\n"; break; case SavingType.私教余额: NotUserInfo += await NewMethod(item, handler, userInfo, userInfo.Balance_Personal) + "\n"; break; default: break; } } using StreamWriter txtFile = new StreamWriter(System.IO.File.Create(Path.Combine(sWebRootFolder, "余额3月.txt"))); txtFile.WriteLine(NotUserInfo); //return true; }