public static void GetEmailByAPI(AccountType account, DateTime beginDate, DateTime endDate, ISession NSession) { ApiContext context = AppSettingHelper.GetGenericApiContext("US"); context.ApiCredential.eBayToken = account.ApiToken; GetMemberMessagesCall apicall = new GetMemberMessagesCall(context); apicall.DetailLevelList.Add(DetailLevelCodeType.ReturnAll); TimeFilter fltr = new TimeFilter(); fltr.TimeFrom = beginDate; fltr.TimeTo = endDate; MemberMessageExchangeTypeCollection messages; int i = 1; do { apicall.Pagination = new eBay.Service.Core.Soap.PaginationType(); apicall.Pagination.PageNumber = i; apicall.Pagination.EntriesPerPage = 100; messages = apicall.GetMemberMessages(fltr, MessageTypeCodeType.All, MessageStatusTypeCodeType.Unanswered); for (int k = 0; k < messages.Count; k++) { MemberMessageExchangeType mmet = messages[k]; EbayMessageType email = new EbayMessageType(); email.Body = mmet.Question.Body; email.CreationDate = mmet.CreationDate; email.MessageId = mmet.Question.MessageID; email.MessageStatus = "未回复"; email.MessageType = MessageType(mmet.Question.MessageType.ToString()); email.SenderEmail = mmet.Question.SenderEmail; email.SenderID = mmet.Question.SenderID; email.Subject = mmet.Question.Subject; if (mmet.Item != null) { email.ItemId = mmet.Item.ItemID; email.Title = mmet.Item.Title; } email.Shop = mmet.Question.RecipientID[0]; email.CreateOn = DateTime.Now; email.ReplayOn = Convert.ToDateTime("2000-01-01"); if (HasExist(email.MessageId, NSession)) { } else { NSession.Save(email); NSession.Flush(); } } i++; } while (messages != null && messages.Count == 100); }
public static List<ResultInfo> ImportByAmount(AccountType account, string fileName, ISession NSession) { List<ResultInfo> results = new List<ResultInfo>(); foreach (DataRow dr in GetDataTable(fileName).Rows) { if (dr.Table.Columns.Count == 3) NSession.CreateQuery("update OrderType set Amount=:p1,OrderFees=:p3 where OrderExNo=:p2").SetDouble("p1", Utilities.ToDouble(dr[1].ToString())).SetDouble("p3", Utilities.ToDouble(dr[2].ToString())).SetString("p2", dr[0].ToString()).ExecuteUpdate(); } return results; }
public static string RefreshToken(AccountType account) { Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add("grant_type", "refresh_token"); dic.Add("client_id", Config.AliAppKey); dic.Add("client_secret", Config.AliAppSecret); dic.Add("refresh_token", account.ApiToken); dic.Add("_aop_signature", SMTConfig.Sign(SMTConfig.UrlRefreshToken, dic)); string c = PostWebRequest(SMTConfig.IP + SMTConfig.UrlRefreshToken + "/" + Config.AliAppKey, SMTConfig.GetParamUrl(dic)); JToken token = (JToken)Newtonsoft.Json.JsonConvert.DeserializeObject(c); return token["access_token"].ToString().Replace("\"", ""); }
public JsonResult Create(AccountType obj) { try { if (IsCreateOk(obj.AccountName, obj.Platform)) return Json(new { errorMsg = "此账号已存在!" }); if (obj.Platform == "SMT") { if (!string.IsNullOrEmpty(obj.ApiToken) && obj.ApiToken.Trim().Length > 0) obj.ApiToken = AliUtil.GetToken(obj.ApiToken.Trim()); } NSession.SaveOrUpdate(obj); NSession.Flush(); } catch (Exception ee) { return Json(new { IsSuccess = false, ErrorMsg = "出错了" }); } return Json(new { IsSuccess = true }); }
public static List<ResultInfo> APIBySMT(AccountType account, DateTime st, DateTime et, ISession NSession) { List<ResultInfo> results = new List<ResultInfo>(); string token = AliUtil.RefreshToken(account); List<CountryType> countryTypes = NSession.CreateQuery("from CountryType").List<CountryType>().ToList(); AliOrderListType aliOrderList = null; int page = 1; do { try { aliOrderList = AliUtil.findOrderListQuery(token, page); if (aliOrderList.totalItem != 0) { foreach (var o in aliOrderList.orderList) { bool isExist = IsExist(o.orderId.ToString(), NSession); if (!isExist) { AliOrderType ot = AliUtil.findOrderById(token, o.orderId.ToString()); OrderType order = new OrderType { IsMerger = 0, Enabled = 1, IsOutOfStock = 0, IsRepeat = 0, IsSplit = 0, Status = OrderStatusEnum.待处理.ToString(), IsPrint = 0, CreateOn = DateTime.Now, ScanningOn = DateTime.Now }; order.OrderNo = Utilities.GetOrderNo(NSession); order.CurrencyCode = ot.orderAmount.currencyCode; order.OrderExNo = ot.id.ToString(); order.Amount = ot.orderAmount.amount; order.LogisticMode = o.productList[0].logisticsServiceName; CountryType country = countryTypes.Find( p => p.CountryCode.ToUpper() == ot.receiptAddress.country.ToUpper()); if (country != null) { order.Country = country.ECountry; } else { order.Country = ot.receiptAddress.country; } order.BuyerName = ot.buyerInfo.firstName + " " + ot.buyerInfo.lastName; order.BuyerEmail = ot.buyerInfo.email; foreach (ProductList p in o.productList) { order.BuyerMemo += p.memo; } OrderMsgType[] msgTypes = AliUtil.findOrderMsgByOrderId(token, order.OrderExNo); foreach (OrderMsgType orderMsgType in msgTypes) { order.BuyerMemo += "<br/>" + orderMsgType.senderName + " " + GetAliDate(orderMsgType.gmtCreate).ToString("yyyy-MM-dd HH:mm:ss") + ":" + orderMsgType.content + ""; } if (!string.IsNullOrEmpty(order.BuyerMemo)) order.IsLiu = 1; order.TId = ""; order.OrderFees = 0; order.OrderCurrencyCode = ""; order.Account = account.AccountName; order.GenerateOn = GetAliDate(ot.gmtPaySuccess); order.Platform = PlatformEnum.SMT.ToString(); order.AddressId = CreateAddress(ot.receiptAddress.contactPerson, ot.receiptAddress.detailAddress + " " + ot.receiptAddress.address2, ot.receiptAddress.city, ot.receiptAddress.province, country == null ? ot.receiptAddress.country : country.ECountry, country == null ? ot.receiptAddress.country : country.CountryCode, ot.receiptAddress.phoneCountry + " " + ot.receiptAddress.phoneArea + " " + ot.receiptAddress.phoneNumber, ot.receiptAddress.mobileNo, ot.buyerInfo.email, ot.receiptAddress.zip, 0, NSession); NSession.Save(order); NSession.Flush(); foreach (ChildOrderList item in ot.childOrderList) { string remark = ""; if (item.productAttributes.Length > 0) { SkuListType skuList = JsonConvert.DeserializeObject<SkuListType>( item.productAttributes.Replace("\\", "")); foreach (SkuType skuType in skuList.sku) { remark += skuType.pName + ":" + skuType.pValue; } } CreateOrderPruduct(item.productId.ToString(), item.skuCode, item.productCount, item.productName, remark, item.initOrderAmt.amount, "", order.Id, order.OrderNo, NSession); } NSession.Clear(); NSession.Update(order); NSession.Flush(); results.Add(GetResult(order.OrderExNo, "", "导入成功")); } else { results.Add(GetResult(o.orderId.ToString(), "该订单已存在", "导入失败")); } } page++; } } catch (Exception) { token = AliUtil.RefreshToken(account); continue; } } while (aliOrderList.totalItem > (page - 1) * 50); return results; }
public string DeleteStock(AccountType obj) { try { object ject = NSession.Delete(" from EbayType where Account='" + obj.AccountName + "'"); NSession.Flush(); return "删除该账号库存信息成功"; } catch (Exception e) { return "删除该账号库存信息出错"; } }
public ActionResult Edit(AccountType obj) { try { //EBayUtil.GetMyeBaySelling(obj); if (!IsOk(obj.Id, obj.AccountName, obj.Platform)) return Json(new { errorMsg = "此账号已存在!" }); NSession.Update(obj); NSession.Flush(); } catch (Exception ee) { return Json(new { IsSuccess = false, ErrorMsg = "出错了" }); } return Json(new { IsSuccess = true }); }
public static void GetMyeBaySelling(AccountType sa, ISession NSession) { if (sa == null) return; ApiContext context = EBayUtil.GetGenericApiContext("US"); context.ApiCredential.eBayToken = sa.ApiToken; GetMyeBaySellingCall apicall = new GetMyeBaySellingCall(context); apicall.ActiveList = new ItemListCustomizationType(); int i = 1; DeleteALL(sa.AccountName, NSession); do { apicall.ActiveList.Pagination = new PaginationType(); apicall.ActiveList.Pagination.EntriesPerPage = 200; apicall.ActiveList.Pagination.PageNumber = i; apicall.GetMyeBaySelling(); if (apicall.ActiveListReturn != null && apicall.ActiveListReturn.ItemArray != null && apicall.ActiveListReturn.ItemArray.Count > 0) { foreach (ItemType actitem in apicall.ActiveListReturn.ItemArray) { try { if (actitem.SellingStatus != null) { EbayType ei = new EbayType(); ei.ItemId = actitem.ItemID; ei.ItemTitle = actitem.Title; ei.Price = actitem.SellingStatus.CurrentPrice.Value.ToString(); ei.Currency = actitem.SellingStatus.CurrentPrice.currencyID.ToString(); ei.StartNum = actitem.Quantity; ei.NowNum = actitem.QuantityAvailable; ei.ProductUrl = actitem.ListingDetails.ViewItemURL; if (actitem.PictureDetails != null && actitem.PictureDetails.GalleryURL != null) { ei.PicUrl = actitem.PictureDetails.GalleryURL; } ei.StartTime = actitem.ListingDetails.StartTime; ei.Account = sa.AccountName; ei.Status = "销售中"; ei.SKU = ""; if (actitem.SKU != null) { ei.SKU = actitem.SKU; if (ei.NowNum == 0) { ei.Status = "卖完"; } NSession.Clear(); ei.CreateOn = DateTime.Now; NSession.Save(ei); NSession.Flush(); } else { if (actitem.Variations != null) { foreach (VariationType v in actitem.Variations.Variation) { NSession.Clear(); ei.SKU = v.SKU; ei.StartNum = v.Quantity; ei.NowNum = v.Quantity - v.SellingStatus.QuantitySold; ei.Status = "销售中"; if (ei.NowNum == 0) { ei.Status = "卖完"; } ei.ItemTitle = v.VariationTitle; ei.CreateOn = DateTime.Now; NSession.Save(ei); NSession.Flush(); } } else { ei.SKU = ""; if (ei.NowNum == 0) { ei.Status = "卖完"; } NSession.Clear(); ei.CreateOn = DateTime.Now; NSession.Save(ei); NSession.Flush(); } } } } catch (Exception) { continue; } } i++; if (i > apicall.ActiveListReturn.PaginationResult.TotalNumberOfPages) { break; } } } while (apicall.ActiveListReturn != null && apicall.ActiveListReturn.ItemArray != null && apicall.ActiveListReturn.ItemArray.Count == 200); }
public AccountType GetTokenByAccount(string account) { AccountType accountname = new AccountType(); IList<AccountType> ac = NSession.CreateQuery("from AccountType where AccountName ='" + account + "' and ApiToken <>''").List<AccountType>(); foreach (var item in ac) { accountname = item; } return accountname; }
public static void APIByEbayFee(AccountType account, DateTime st, DateTime et, ISession NSession) { List<ResultInfo> results = new List<ResultInfo>(); ApiContext context = AppSettingHelper.GetGenericApiContext("US"); context.ApiCredential.eBayToken = account.ApiToken; eBay.Service.Call.GetOrdersCall apicall = new eBay.Service.Call.GetOrdersCall(context); apicall.IncludeFinalValueFee = true; apicall.DetailLevelList.Add(eBay.Service.Core.Soap.DetailLevelCodeType.ReturnAll); eBay.Service.Core.Soap.OrderTypeCollection m = null; int i = 1; do { apicall.Pagination = new eBay.Service.Core.Soap.PaginationType(); apicall.Pagination.PageNumber = i; apicall.Pagination.EntriesPerPage = 50; apicall.OrderRole = eBay.Service.Core.Soap.TradingRoleCodeType.Seller; apicall.OrderStatus = eBay.Service.Core.Soap.OrderStatusCodeType.Completed; apicall.CreateTimeFrom = st; apicall.CreateTimeTo = et; apicall.Execute(); m = apicall.OrderList; for (int k = 0; k < m.Count; k++) { eBay.Service.Core.Soap.OrderType ot = m[k]; IList<OrderType> orders = NSession.CreateQuery("from OrderType where OrderExNo='" + m[k].OrderID + "'").List<OrderType>(); if (orders.Count > 0) { OrderType order = orders[0]; order.OrderFees = ot.ExternalTransaction[0].FeeOrCreditAmount.Value; order.OrderCurrencyCode = ot.ExternalTransaction[0].FeeOrCreditAmount.currencyID.ToString(); foreach (TransactionType item in ot.TransactionArray) { order.OrderCurrencyCode2 = item.FinalValueFee.currencyID.ToString(); order.OrderFees2 += item.FinalValueFee.Value; } NSession.Update(order); NSession.Flush(); } } i++; } while (apicall.HasMoreOrders); }
public static List<ResultInfo> APIByEbay(AccountType account, DateTime st, DateTime et, ISession NSession) { List<ResultInfo> results = new List<ResultInfo>(); ApiContext context = AppSettingHelper.GetGenericApiContext("US"); context.ApiCredential.eBayToken = account.ApiToken; eBay.Service.Call.GetOrdersCall apicall = new eBay.Service.Call.GetOrdersCall(context); apicall.IncludeFinalValueFee = true; apicall.DetailLevelList.Add(eBay.Service.Core.Soap.DetailLevelCodeType.ReturnAll); eBay.Service.Core.Soap.OrderTypeCollection m = null; int i = 1; do { apicall.Pagination = new eBay.Service.Core.Soap.PaginationType(); apicall.Pagination.PageNumber = i; apicall.Pagination.EntriesPerPage = 50; apicall.OrderRole = eBay.Service.Core.Soap.TradingRoleCodeType.Seller; apicall.OrderStatus = eBay.Service.Core.Soap.OrderStatusCodeType.Completed; apicall.ModTimeFrom = st; apicall.ModTimeTo = et; apicall.Execute(); m = apicall.OrderList; for (int k = 0; k < m.Count; k++) { eBay.Service.Core.Soap.OrderType ot = m[k]; if (ot.OrderStatus == eBay.Service.Core.Soap.OrderStatusCodeType.Authenticated || ot.OrderStatus == eBay.Service.Core.Soap.OrderStatusCodeType.CustomCode || ot.OrderStatus == eBay.Service.Core.Soap.OrderStatusCodeType.Default || ot.OrderStatus == eBay.Service.Core.Soap.OrderStatusCodeType.Inactive || ot.OrderStatus == eBay.Service.Core.Soap.OrderStatusCodeType.InProcess) { //去除别的订单状态 continue; } if (ot.PaidTime == DateTime.MinValue || ot.ShippedTime != DateTime.MinValue) { continue; } //查看是不是在订单系统里面存在 bool isExist = IsExist(ot.OrderID, NSession); if (!isExist) { OrderType order = new OrderType { IsMerger = 0, Enabled = 1, IsOutOfStock = 0, IsRepeat = 0, IsSplit = 0, Status = OrderStatusEnum.待处理.ToString(), IsPrint = 0, CreateOn = DateTime.Now, ScanningOn = DateTime.Now }; order.OrderNo = Utilities.GetOrderNo(NSession); order.CurrencyCode = ot.AmountPaid.currencyID.ToString(); order.OrderExNo = ot.OrderID; order.Amount = ot.AmountPaid.Value; order.Country = ot.ShippingAddress.CountryName; order.BuyerName = ot.BuyerUserID; order.BuyerEmail = ot.TransactionArray[0].Buyer.Email; order.BuyerMemo = ot.BuyerCheckoutMessage; order.TId = ot.ExternalTransaction[0].ExternalTransactionID; order.OrderFees = ot.ExternalTransaction[0].FeeOrCreditAmount.Value; order.OrderCurrencyCode = ot.ExternalTransaction[0].FeeOrCreditAmount.currencyID.ToString(); order.Account = account.AccountName; order.GenerateOn = ot.PaidTime; order.Platform = PlatformEnum.Ebay.ToString(); order.AddressId = CreateAddress(ot.ShippingAddress.Name, (string.IsNullOrEmpty(ot.ShippingAddress.Street) ? "" : ot.ShippingAddress.Street) + (string.IsNullOrEmpty(ot.ShippingAddress.Street1) ? "" : ot.ShippingAddress.Street1) + (string.IsNullOrEmpty(ot.ShippingAddress.Street2) ? "" : ot.ShippingAddress.Street2), ot.ShippingAddress.CityName, ot.ShippingAddress.StateOrProvince, ot.ShippingAddress.CountryName, ot.ShippingAddress.Country.ToString(), ot.ShippingAddress.Phone, ot.ShippingAddress.Phone, ot.TransactionArray[0].Buyer.Email, ot.ShippingAddress.PostalCode, 0, NSession); NSession.Save(order); NSession.Flush(); foreach (TransactionType item in ot.TransactionArray) { string sku = ""; if (item.Variation != null) { sku = item.Variation.SKU; } else { sku = item.Item.SKU; } order.OrderCurrencyCode2 = item.FinalValueFee.currencyID.ToString(); order.OrderFees2 += item.FinalValueFee.Value; CreateOrderPruduct(item.Item.ItemID, sku, item.QuantityPurchased, item.Item.Title, "", 0, "http://thumbs.ebaystatic.com/pict/" + item.Item.ItemID + "6464_1.jpg", order.Id, order.OrderNo, NSession); } NSession.Clear(); NSession.Update(order); NSession.Flush(); results.Add(GetResult(order.OrderExNo, "", "导入成功")); } else { results.Add(GetResult(ot.OrderID, "该订单已存在", "导入失败")); } } i++; } while (apicall.HasMoreOrders); return results; }
public static void Upload(AccountType account, ISession NSession) { ApiContext context = AppSettingHelper.GetGenericApiContext("US"); context.ApiCredential.eBayToken = account.ApiToken; AddMemberMessageRTQCall addMsgApicall = new AddMemberMessageRTQCall(context); ReviseMyMessagesCall revMsgApicall = new ReviseMyMessagesCall(context); IList<EbayMessageReType> list = NSession.CreateQuery("from EbayMessageReType where IsUpload<>'1'").List<EbayMessageReType>(); if (list.Count != 0) { foreach (var item in list) { MemberMessageType mm = new MemberMessageType(); mm.SenderID = item.SenderID; mm.SenderEmail = item.SenderEmail; mm.MessageID = item.EbayId; mm.Body = item.BodyRe; mm.ParentMessageID = item.EbayId; addMsgApicall.AddMemberMessageRTQ(item.ItemId, mm); revMsgApicall.ReviseMyMessages(true, false, new StringCollection(new string[] { mm.MessageID })); item.IsUpload = 1; } } }
public static List<ResultInfo> ImportBySMT(AccountType account, string fileName, ISession NSession) { List<ResultInfo> results = new List<ResultInfo>(); foreach (DataRow dr in GetDataTable(fileName).Rows) { string OrderExNo = dr["订单号"].ToString(); string o = dr["订单状态"].ToString(); if (o != "等待您发货") { results.Add(GetResult(OrderExNo, "订单已经发货", "导入失败")); continue; } bool isExist = IsExist(OrderExNo, NSession); if (!isExist) { OrderType order = new OrderType { IsMerger = 0, Enabled = 1, IsOutOfStock = 0, IsRepeat = 0, IsSplit = 0, Status = OrderStatusEnum.待处理.ToString(), IsPrint = 0, CreateOn = DateTime.Now, ScanningOn = DateTime.Now }; try { order.OrderNo = Utilities.GetOrderNo(NSession); order.CurrencyCode = "USD"; order.OrderExNo = OrderExNo; order.Amount = Utilities.ToDouble(dr["订单金额"].ToString()); order.BuyerMemo = dr["订单备注"].ToString(); order.Country = dr["收货国家"].ToString(); order.BuyerName = dr["买家名称"].ToString(); order.BuyerEmail = dr["买家邮箱"].ToString(); order.TId = ""; order.Account = account.AccountName; order.GenerateOn = Convert.ToDateTime(dr["付款时间"]); order.Platform = PlatformEnum.SMT.ToString(); //舍弃原来的客户表 //下面地址 order.AddressId = CreateAddress(dr["收货人名称"].ToString(), dr["地址"].ToString(), dr["城市"].ToString(), dr["州/省"].ToString(), dr["收货国家"].ToString(), dr["收货国家"].ToString(), dr["联系电话"].ToString(), dr["手机"].ToString(), dr["买家邮箱"].ToString(), dr["邮编"].ToString(), 0, NSession); NSession.Save(order); NSession.Flush(); // //添加产品 // string info = dr["产品信息_(双击单元格展开所有产品信息!)"].ToString(); string[] cels = info.Split(new char[] { '【' }, StringSplitOptions.RemoveEmptyEntries); if (cels.Length == 0) { results.Add(GetResult(OrderExNo, "没有产品信息", "导入失败")); continue;//物品信息出错 } for (int i = 0; i < cels.Length; i++) { string Str = cels[i]; System.Text.RegularExpressions.Regex r2 = new System.Text.RegularExpressions.Regex(@"】(?<title>.*)\n", System.Text.RegularExpressions.RegexOptions.None); System.Text.RegularExpressions.Regex r4 = new System.Text.RegularExpressions.Regex(@"\(产品属性:(?<ppp>.*)\n", System.Text.RegularExpressions.RegexOptions.None); System.Text.RegularExpressions.Regex r5 = new System.Text.RegularExpressions.Regex(@"\(产品数量:(?<quantity>\d+)", System.Text.RegularExpressions.RegexOptions.None); System.Text.RegularExpressions.Regex r3 = new System.Text.RegularExpressions.Regex(@"\(商家编码:(?<sku>.*)\)", System.Text.RegularExpressions.RegexOptions.None); //System.Text.RegularExpressions.Regex r6 = new System.Text.RegularExpressions.Regex(@"\(物流等级&买家选择物流:(?<wuliu>.+)\)", System.Text.RegularExpressions.RegexOptions.None); System.Text.RegularExpressions.Match mc2 = r2.Match(Str); System.Text.RegularExpressions.Match mc3 = r3.Match(Str); System.Text.RegularExpressions.Match mc4 = r4.Match(Str); System.Text.RegularExpressions.Match mc5 = r5.Match(Str); order.LogisticMode = dr["买家选择物流"].ToString(); if (order.LogisticMode.IndexOf("\n") != -1) { order.LogisticMode = order.LogisticMode.Substring(0, order.LogisticMode.IndexOf("\n")); } NSession.Update(order); NSession.Flush(); CreateOrderPruduct(mc3.Groups["sku"].Value, Utilities.ToInt(mc5.Groups["quantity"].Value.Trim(')').Trim()), mc2.Groups["title"].Value, mc4.Groups["ppp"].Value.Replace("(产品属性: ", "").Replace(")", ""), 0, "", order.Id, order.OrderNo, NSession); } } catch (Exception ex) { Console.WriteLine(ex.Message); } results.Add(GetResult(OrderExNo, "", "导入成功")); LoggerUtil.GetOrderRecord(order, "订单导入", "导入成功", NSession); } else { results.Add(GetResult(OrderExNo, "订单已存在", "导入失败")); } } return results; }
public static List<ResultInfo> APIByAmazon(AccountType account, DateTime st, DateTime et, ISession NSession) { List<ResultInfo> results = new List<ResultInfo>(); return results; }
public static List<ResultInfo> ImportByAmazon(AccountType account, string fileName, ISession NSession) { List<ResultInfo> results = new List<ResultInfo>(); CsvReader csv = new CsvReader(fileName, Encoding.Default); List<Dictionary<string, string>> lsitss = csv.ReadAllData(); Dictionary<string, int> listOrder = new Dictionary<string, int>(); foreach (Dictionary<string, string> item in lsitss) { if (item.Count < 10)//判断列数 continue; string OrderExNo = item["order-id"]; if (listOrder.ContainsKey(OrderExNo)) { CreateOrderPruduct(item["sku"], Utilities.ToInt(item["quantity-purchased"]), item["sku"], "", 0, "", listOrder[OrderExNo], OrderExNo, NSession); continue; } bool isExist = IsExist(OrderExNo, NSession); if (!isExist) { OrderType order = new OrderType { IsMerger = 0, Enabled = 1, IsOutOfStock = 0, IsRepeat = 0, IsSplit = 0, Status = OrderStatusEnum.待处理.ToString(), IsPrint = 0, CreateOn = DateTime.Now, ScanningOn = DateTime.Now }; order.OrderNo = Utilities.GetOrderNo(NSession); try { order.CurrencyCode = item["currency"].ToUpper().Trim(); } catch (Exception) { order.CurrencyCode = "USD"; } order.OrderExNo = item["order-id"]; //order.Amount =Utilities.ToDouble(dr["订单金额"]); //order.BuyerMemo = dr["订单备注"].ToString(); order.Country = item["ship-country"]; order.BuyerName = item["buyer-name"]; order.BuyerEmail = item["buyer-email"]; order.TId = ""; order.Account = account.AccountName; order.GenerateOn = Convert.ToDateTime(item["payments-date"]); order.Platform = PlatformEnum.Amazon.ToString(); order.AddressId = CreateAddress(item["recipient-name"], item["ship-address-1"] + item["ship-address-2"] + item["ship-address-3"], item["ship-city"], item["ship-state"], item["ship-country"], item["ship-country"], item["buyer-phone-number"], item["buyer-phone-number"], item["buyer-email"], item["ship-postal-code"], 0, NSession); NSession.Save(order); NSession.Flush(); CreateOrderPruduct(item["sku"], Utilities.ToInt(item["quantity-purchased"]), item["sku"], "", 0, "", order.Id, order.OrderNo, NSession); results.Add(GetResult(OrderExNo, "", "导入成功")); listOrder.Add(OrderExNo, order.Id); LoggerUtil.GetOrderRecord(order, "订单导入", "导入成功", NSession); } else { results.Add(GetResult(OrderExNo, "订单已存在", "导入失败")); } } return results; }
public static List<ResultInfo> APIByB2C(AccountType account, DateTime st, DateTime et, ISession NSession) { List<ResultInfo> results = new List<ResultInfo>(); string s = DownHtml("http://www.gamesalor.com/GetOrdersHandler.ashx?startTime=" + st.ToShortDateString() + "&endTime=" + et.ToShortDateString() + "", System.Text.Encoding.UTF8); System.Collections.Generic.List<Order> orders = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.List<Order>>(s); foreach (Order foo in orders) { try { bool isExist = IsExist(foo.GoodsDataWare.ItemNumber, NSession); if (!isExist) { OrderType order = new OrderType { Enabled = 1, IsMerger = 0, IsOutOfStock = 0, IsRepeat = 0, IsSplit = 0, Status = OrderStatusEnum.待处理.ToString(), IsPrint = 0, CreateOn = DateTime.Now, ScanningOn = DateTime.Now }; order.OrderNo = Utilities.GetOrderNo(NSession); order.CurrencyCode = foo.GoodsDataWare.McCurrency; order.OrderExNo = foo.GoodsDataWare.ItemNumber; order.Amount = Utilities.ToDouble(foo.GoodsDataWare.McGross.ToString()); order.BuyerMemo = "客户付款账户" + foo.GoodsDataWare.Business + " " + foo.GoodsDataWare.Memo; order.Country = foo.GoodsDataWare.AddressCountry; order.BuyerName = foo.GoodsDataWare.FirstName + " " + foo.GoodsDataWare.LastName; order.BuyerEmail = foo.GoodsDataWare.PayerEmail; order.TId = foo.GoodsDataWare.TxnId; order.Account = account.AccountName; order.GenerateOn = foo.GoodsDataWare.PaymentDate; order.Platform = PlatformEnum.DH.ToString(); order.LogisticMode = foo.GoodsDataWare.EMS; order.AddressId = CreateAddress(foo.GoodsDataWare.AddressName, foo.GoodsDataWare.AddressStreet, foo.GoodsDataWare.AddressCity, foo.GoodsDataWare.AddressState, foo.GoodsDataWare.AddressCountry, foo.GoodsDataWare.AddressCountryCode, foo.GoodsDataWare.ContactPhone, foo.GoodsDataWare.ContactPhone, foo.GoodsDataWare.PayerEmail, foo.GoodsDataWare.AddressZip, 0, NSession); NSession.Save(order); NSession.Flush(); foreach (GoodsDataOrder item in foo.GoodsDataOrderList) { CreateOrderPruduct(item.ItemID, item.Quantity, item.ItemID, "", 0, item.Url, order.Id, order.OrderNo, NSession); } results.Add(GetResult(order.OrderExNo, "", "导入成功")); } else { results.Add(GetResult(foo.GoodsDataWare.ItemNumber, "该订单已存在", "导入失败")); } } catch (Exception ex) { Console.WriteLine(ex.Message); throw ex; } } return results; }
public static List<ResultInfo> ImportByB2C(AccountType account, string fileName, ISession NSession) { List<ResultInfo> results = new List<ResultInfo>(); foreach (DataRow item in OrderHelper.GetDataTable(fileName).Rows) { try { string OrderExNo = item["订单编号"].ToString(); bool isExist = IsExist(OrderExNo, NSession); if (!isExist) { OrderType order = new OrderType { IsMerger = 0, Enabled = 1, IsOutOfStock = 0, IsRepeat = 0, IsSplit = 0, Status = OrderStatusEnum.待处理.ToString(), IsPrint = 0, CreateOn = DateTime.Now, ScanningOn = DateTime.Now }; order.OrderNo = Utilities.GetOrderNo(NSession); order.OrderExNo = OrderExNo; order.Amount = Utilities.ToDouble(item["金额"].ToString()); order.Country = item["国家"].ToString(); order.BuyerName = item["用户名"].ToString(); order.CurrencyCode = "USD"; order.Account = account.AccountName; order.GenerateOn = DateTime.Now; order.Platform = PlatformEnum.DH.ToString(); order.AddressId = CreateAddress(item["收件人"].ToString(), item["街道"].ToString(), item["城市"].ToString(), item["省"].ToString(), item["国家"].ToString(), item["国家"].ToString(), item["电话"].ToString(), item["电话"].ToString(), item["邮箱"].ToString(), item["邮编"].ToString(), 0, NSession); NSession.Save(order); NSession.Flush(); CreateOrderPruduct(item["商品"].ToString(), item["商品"].ToString(), Utilities.ToInt(item["数量"].ToString()), "", "", 0, item["属性"].ToString(), order.Id, order.OrderNo, NSession); results.Add(GetResult(OrderExNo, "", "导入成功")); LoggerUtil.GetOrderRecord(order, "订单导入", "导入成功", NSession); } } catch (Exception ex) { Console.WriteLine(ex.Message); throw ex; } } return results; }
public static List<ResultInfo> ImportByGmarket(AccountType account, string fileName, ISession NSession) { List<ResultInfo> results = new List<ResultInfo>(); CsvReader csv = new CsvReader(fileName, Encoding.Default); List<Dictionary<string, string>> lsitss = csv.ReadAllData(); Dictionary<string, int> listOrder = new Dictionary<string, int>(); foreach (Dictionary<string, string> item in lsitss) { try { if (item.Count < 10)//判断列数 continue; string OrderExNo = item["Cart no."]; double price = Convert.ToDouble(item["Settle Price"].Replace(",", "")); if (listOrder.ContainsKey(OrderExNo)) { CreateOrderPruduct(item["Item code"], item["Option Code"], Utilities.ToInt(item["Qty."]), item["Item"], item["Options"], 0, "", listOrder[OrderExNo], OrderExNo, NSession); NSession.CreateSQLQuery("update orders set Amount=Amount+" + price + " where Id=" + listOrder[OrderExNo]).UniqueResult(); continue; } bool isExist = IsExist(OrderExNo, NSession, account.AccountName); if (!isExist) { OrderType order = new OrderType { IsMerger = 0, Enabled = 1, IsOutOfStock = 0, IsRepeat = 0, IsSplit = 0, Status = OrderStatusEnum.待处理.ToString(), IsPrint = 0, CreateOn = DateTime.Now, ScanningOn = DateTime.Now }; order.OrderNo = Utilities.GetOrderNo(NSession); order.CurrencyCode = item["Currency"]; order.OrderExNo = OrderExNo; order.Amount = Utilities.ToDouble(item["Settle Price"]); order.BuyerMemo = item["Memo to Seller"]; order.Country = item["Nation"]; order.BuyerName = item["Customer"]; order.BuyerEmail = ""; order.TId = item["Order no."]; order.Account = account.AccountName; order.GenerateOn = Convert.ToDateTime(item["Payment Complete"]); order.Platform = PlatformEnum.Gmarket.ToString(); order.BuyerMemo = item["Memo to Seller"] + item["Options"]; order.AddressId = CreateAddress(item["Recipient"], item["Address"], "", "", item["Nation"], item["Nation"], item["Recipient Phone number"], item["Recipient mobile Phone number"], "", item["Postal code"], 0, NSession); NSession.Save(order); NSession.Flush(); CreateOrderPruduct(item["Item code"], item["Option Code"], Utilities.ToInt(item["Qty."]), item["Item"], item["Options"], 0, "", order.Id, order.OrderNo, NSession); results.Add(GetResult(OrderExNo, "", "导入成功")); listOrder.Add(OrderExNo, order.Id); LoggerUtil.GetOrderRecord(order, "订单导入", "导入成功", NSession); } else { results.Add(GetResult(OrderExNo, "订单已存在", "导入失败")); } } catch (Exception ex) { Console.WriteLine(ex.Message); throw ex; } } return results; }