//POST /api/customermanagement/ public IHttpActionResult CreateNewCustomerByModel([FromBody] UpperVendorDto model) { if (_context.UpperVendors.Where(x => x.CustomerCode == model.CustomerCode).Count() != 0) { throw new Exception("Customer Code " + model.CustomerCode + " has been taken. Please try another one."); } var customer = new UpperVendor { CustomerCode = model.CustomerCode, DepartmentCode = model.DepartmentCode, Name = model.Name, FirstAddressLine = model.FirstAddressLine, SecondAddressLine = model.SecondAddressLine, TelNumber = model.TelNumber, EmailAddress = model.EmailAddress, ContactPerson = model.ContactPerson, Status = Status.Active, WarningQuantityLevel = model.WarningQuantityLevel, InboundMinCharge = model.InboundMinCharge, OutboundMinCharge = model.OutboundMinCharge }; _context.UpperVendors.Add(customer); //暂时停止为新客户自动建立收费项目 //var generator = new ChargingItemGenerator(); //generator.GenerateChargingItems(_context, customer); _context.SaveChanges(); var result = _context.UpperVendors.OrderByDescending(x => x.Id).First(); return(Created(Request.RequestUri + "/" + result.Id, Mapper.Map <UpperVendor, UpperVendorDto>(result))); }
//POST /api/customermanagement/?name={name}&customerCode={customerCode}&departmentCode={departmentCode} public IHttpActionResult CreateNewCustomer([FromUri] string name, [FromUri] string customerCode, [FromUri] string departmentCode, [FromUri] string firstAddressLine, [FromUri] string secondAddressLine, [FromUri] string telNumber, [FromUri] string emailAddress, [FromUri] string contactPerson) { if (_context.UpperVendors.Where(x => x.CustomerCode == customerCode).Count() != 0) { throw new Exception("Customer Code " + customerCode + " has been taken. Please try another one."); } var customer = new UpperVendor { CustomerCode = customerCode, DepartmentCode = departmentCode, Name = name, FirstAddressLine = firstAddressLine, SecondAddressLine = secondAddressLine, TelNumber = telNumber, EmailAddress = emailAddress, ContactPerson = contactPerson, Status = Status.Active }; _context.UpperVendors.Add(customer); var generator = new ChargingItemGenerator(); generator.GenerateChargingItems(_context, customer); _context.SaveChanges(); var result = _context.UpperVendors.OrderByDescending(x => x.Id).First(); return(Created(Request.RequestUri + "/" + result.Id, Mapper.Map <UpperVendor, UpperVendorDto>(result))); }
public void UpdateCustomerByModel([FromBody] UpperVendor model) { var customerInDb = _context.UpperVendors.Find(model.Id); customerInDb.FirstAddressLine = model.FirstAddressLine; customerInDb.SecondAddressLine = model.SecondAddressLine; customerInDb.TelNumber = model.TelNumber; customerInDb.EmailAddress = model.EmailAddress; customerInDb.ContactPerson = model.ContactPerson; customerInDb.WarningQuantityLevel = model.WarningQuantityLevel; customerInDb.InboundMinCharge = model.InboundMinCharge; customerInDb.OutboundMinCharge = model.OutboundMinCharge; customerInDb.Name = model.Name; customerInDb.CustomerCode = model.CustomerCode; _context.SaveChanges(); }
public UpperVendor GetCustomer(string reference, string invoiceType) { UpperVendor customer = null; if (invoiceType == FBAInvoiceType.MasterOrder) { customer = _context.FBAMasterOrders .Include(x => x.Customer) .FirstOrDefault(x => x.Container == reference) .Customer; } else if (invoiceType == FBAInvoiceType.ShipOrder) { var customerCode = _context.FBAShipOrders.SingleOrDefault(x => x.ShipOrderNumber == reference).CustomerCode; customer = _context.UpperVendors.SingleOrDefault(x => x.CustomerCode == customerCode); } return(customer); }
public IHttpActionResult CreateNewChargingItem([FromBody] ChargingItemJsonObj obj) { UpperVendor vendorInDb = null; var newItem = new ChargingItem { ChargingType = obj.ChargingType, Name = obj.Name, Rate = obj.Rate, Description = obj.Description, Unit = obj.Unit }; //如果customerId等于0,就通过名字和部门代码来找到customer if (obj.CustomerId == 0) { vendorInDb = _context.UpperVendors .SingleOrDefault(x => x.Name == obj.Vendor && x.DepartmentCode == obj.DepartmentCode); var sameNameItem = _context.ChargingItems .Include(x => x.UpperVendor) .Where(x => x.UpperVendor.Name == obj.Vendor && x.UpperVendor.DepartmentCode == obj.DepartmentCode && x.Name == obj.Name); if (sameNameItem.Count() != 0) { throw new Exception("The name: " + obj.Name + " has already been taken. Please change it and try again."); } newItem.UpperVendor = vendorInDb; _context.ChargingItems.Add(newItem); } else { vendorInDb = _context.UpperVendors.Find(obj.CustomerId); //是否将新加的收费项目应用到所有FBA客户 if (!obj.IsApplyToAll) { var sameNameItem = _context.ChargingItems .Include(x => x.UpperVendor) .Where(x => x.UpperVendor.Name == obj.Vendor && x.UpperVendor.DepartmentCode == obj.DepartmentCode && x.Name == obj.Name); if (sameNameItem.Count() != 0) { throw new Exception("The name: " + obj.Name + " has already been taken. Please change it and try again."); } newItem.UpperVendor = vendorInDb; _context.ChargingItems.Add(newItem); } else { var fbaCustomersInDb = _context.UpperVendors .Include(x => x.ChargingItems) .Where(x => x.DepartmentCode == "FBA"); var itemList = new List <ChargingItem>(); var customerList = fbaCustomersInDb.ToList(); var sameNameItem = _context.ChargingItems .Include(x => x.UpperVendor) .Where(x => x.Name == obj.Name) .ToList(); foreach (var s in sameNameItem) { customerList.Remove(customerList.SingleOrDefault(x => x.CustomerCode == s.UpperVendor.CustomerCode)); } foreach (var c in customerList) { var customerInDb = fbaCustomersInDb.SingleOrDefault(x => x.CustomerCode == c.CustomerCode); itemList.Add(new ChargingItem { ChargingType = obj.ChargingType, Name = obj.Name, Rate = obj.Rate, Description = obj.Description, Unit = obj.Unit, UpperVendor = customerInDb }); } _context.ChargingItems.AddRange(itemList); } } _context.SaveChanges(); var sampleDto = Mapper.Map <ChargingItem, ChargingItemDto>(_context.ChargingItems.OrderByDescending(x => x.Id).First()); return(Created(Request.RequestUri + "/" + sampleDto.Id, sampleDto)); }
public JsonResponse ValidateSign(string appKey, UpperVendor customerInDb, string requestId, string version, string sign) { // 参数验证加密验证 var auth = _context.AuthAppInfos.SingleOrDefault(x => x.AppKey == appKey); if (auth == null) { return(new JsonResponse { Code = 500, ValidationStatus = "Validate failed", Message = "Unregistered app request." }); } var vs = auth.SecretKey.ToUpper() + "&appKey=" + appKey + "&customerCode=" + customerInDb.CustomerCode + "&requestId=" + requestId + "&version=" + version; var md5sign = BitConverter.ToString(MD5.Create().ComputeHash(Encoding.Default.GetBytes(vs))).Replace("-", ""); //var md5sign = BitConverter.ToString(MD5.Create().ComputeHash(Encoding.Default.GetBytes(vs))).Replace("-", "S"); if (md5sign != sign) { return(new JsonResponse { Code = 501, ValidationStatus = "Validate failed", Message = "Invalid sign." }); } // 检查customerCode是否存在,否则返回错误 if (customerInDb == null) { return(new JsonResponse { Code = 501, ValidationStatus = "Validate failed", Message = "Invalid sign." }); } //防止重放攻击和网络延迟等非攻击意向的二次请求,如请求重复则返回错误 if (HttpContext.Current.Cache[requestId] == null) { // 如果没有requestId,则缓存10分钟 HttpContext.Current.Cache.Insert(requestId, requestId, null, DateTime.Now.AddMinutes(10), System.Web.Caching.Cache.NoSlidingExpiration); } else { return(new JsonResponse { Code = 504, ValidationStatus = "Validate failed", Message = "Duplicated request detectived. Request Id: " + requestId + " has already been processed. Please report this request Id: " + requestId + " to CSR of Grand Channel for more support." }); } // 防止重放攻击的二道关卡,如重复则返回错误 var logInDb = _context.OperationLogs.Where(x => x.RequestId == requestId); if (logInDb.Count() != 0) { return(new JsonResponse { Code = 504, ValidationStatus = "Validate failed", Message = "Duplicated request detectived. Request Id: " + requestId + " has already been processed. Please report this request Id: " + requestId + " to CSR of Grand Channel for more support." }); } // 检查version是否支持,否则返回错误 if (version != "V1") { return(new JsonResponse { Code = 505, ValidationStatus = "Validate failed", Message = "Invalid API version." }); } return(new JsonResponse { Code = 200, ValidationStatus = "Validate success", Message = "Successful model validation." }); }
public async Task CreateInboundOrderByAgentRequestV1(UpperVendor customer, string customerCode, FBAInboundOrder order, string requestId) { // 建立主单 var newMasterOrder = new FBAMasterOrder(); newMasterOrder.GrandNumber = "N/A"; newMasterOrder.Agency = order.Agency; newMasterOrder.Container = order.Container; newMasterOrder.CreatedBy = order.Agency; newMasterOrder.SubCustomer = order.Subcustomer; newMasterOrder.StorageType = "SEE INSTRUCTION"; newMasterOrder.Status = FBAStatus.Draft; newMasterOrder.UnloadingType = "DROP-OFF"; newMasterOrder.InboundType = "FCL"; newMasterOrder.Palletizing = "<=80"; newMasterOrder.TotalCBM = order.FBAJobs.Sum(x => x.CBM); newMasterOrder.TotalCtns = order.FBAJobs.Sum(x => x.Quantity); newMasterOrder.OriginalPlts = order.FBAJobs.Sum(x => x.PalletQuantity); newMasterOrder.CustomerCode = customerCode; newMasterOrder.WarehouseLocation = order.WarehouseLocation == "" ? "W0" : order.WarehouseLocation; newMasterOrder.Customer = customer; newMasterOrder.PortOfLoading = order.PortOfLoading; newMasterOrder.ETAPort = order.ETADate; newMasterOrder.ETA = order.ETADate; newMasterOrder.PlaceOfDelivery = order.DeliveryPort; newMasterOrder.Vessel = order.Vessel; newMasterOrder.Carrier = order.Carrier; newMasterOrder.ContainerSize = order.ContainerSize; newMasterOrder.SealNumber = order.SealNumber; newMasterOrder.Comment = "ETL DATE: " + order.ETLDate; newMasterOrder.UpdateLog = "Created by agency via API"; _context.FBAMasterOrders.Add(newMasterOrder); foreach (var j in order.FBAJobs) { var orderDetail = new FBAOrderDetail(); orderDetail.Container = order.Container; orderDetail.GrandNumber = "N/A"; orderDetail.GrossWeight = j.GrossWeight; orderDetail.CBM = j.CBM; orderDetail.Quantity = j.Quantity; orderDetail.ShipmentId = j.ShipmentId; orderDetail.AmzRefId = j.AmzRefId; orderDetail.WarehouseCode = j.WarehouseCode; orderDetail.Remark = "包装:" + j.PackageType + ";产品类型:" + j.ProductType + ";打托数量:" + j.PalletQuantity; orderDetail.FBAMasterOrder = newMasterOrder; _context.FBAOrderDetails.Add(orderDetail); } var instruction = new ChargingItemDetail(); instruction.Description = "To CSR: This inbound order is created by an agency from api. If there is no further customer's instructions below, please contact customer to do a further confirmation."; instruction.HandlingStatus = "N/A"; instruction.Status = FBAStatus.NoNeedForCharging; instruction.IsCharging = false; instruction.IsInstruction = true; instruction.IsOperation = false; instruction.OriginalDescription = instruction.Description; instruction.FBAMasterOrder = newMasterOrder; _context.ChargingItemDetails.Add(instruction); if (order.Instructions != null) { foreach (var i in order.Instructions) { var customerInstruction = new ChargingItemDetail(); customerInstruction.Description = i; customerInstruction.HandlingStatus = "N/A"; customerInstruction.Status = FBAStatus.TBD; customerInstruction.IsCharging = false; customerInstruction.IsInstruction = true; customerInstruction.IsOperation = false; customerInstruction.OriginalDescription = instruction.Description; customerInstruction.FBAMasterOrder = newMasterOrder; _context.ChargingItemDetails.Add(customerInstruction); } } // 添加Request日志 var logger = new Logger(_context, order.Agency); await logger.AddCreatedLogAsync <FBAMasterOrder>(null, Mapper.Map <FBAMasterOrder, FBAMasterOrderDto>(newMasterOrder), "Created by agency from api.", null, OperationLevel.Mediunm); var logInDb = _context.OperationLogs.OrderByDescending(x => x.Id).First(); logInDb.RequestId = requestId; _context.SaveChanges(); }
public async Task <IList <PickingStatus> > CreateShipOrderAsync(FBAOutboundOrder order, UpperVendor customerInDb, string requestId) { var shipOrder = new FBAShipOrder { OrderType = order.OrderType, CustomerCode = customerInDb.CustomerCode, Status = FBAStatus.Draft, CreateBy = "External API", ETS = DateTime.ParseExact(order.ETS, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture), ETSTimeRange = order.EtsTimeRange, Destination = order.Destionation, CreateDate = DateTime.Now, Agency = order.Agency, WarehouseLocation = order.WarehouseLocation == "" ? "W0" : order.WarehouseLocation, ShipOrderNumber = GenerateShipOrderNumber(customerInDb.CustomerCode, order.ShipOrderNumber) }; var logger = new Logger(_context, order.Agency); await logger.AddCreatedLogAsync <FBAShipOrder>(null, Mapper.Map <FBAShipOrder, FBAShipOrderDto>(shipOrder), "Created by agency from api.", null, OperationLevel.Mediunm); var logInDb = _context.OperationLogs.OrderByDescending(x => x.Id).First(); logInDb.RequestId = requestId; var pickingStatusList = new List <PickingStatus>(); var pickDetailCartonList = new List <FBAPickDetailCarton>(); _context.FBAShipOrders.Add(shipOrder); foreach (var p in order.PickingList) { var pickingStatus = new PickingStatus(shipOrder.ShipOrderNumber, p.Container, p.ShipmentId, p.AmzRefId, p.WarehouseCode, p.Quantity, p.PalletQuantity); var inventoryList = _picker.SearchPalletInventory(customerInDb.CustomerCode, p.Container, p.ShipmentId, p.AmzRefId, p.WarehouseCode, order.WarehouseLocation); if (inventoryList.Count() == 0 || inventoryList.First().FBACartonLocations.Count() == 0) { pickingStatus.StatusCode = 3002; pickingStatus.Status = "Failed"; pickingStatus.Message = "Picking failed. No target was found in inventory."; pickingStatusList.Add(pickingStatus); continue; } else if (inventoryList.Count() > 1) { // 执行FIFO pickingStatus.StatusCode = 3001; pickingStatus.Status = "Failed"; pickingStatus.Message = "Picking failed. More than one target found in inventory."; pickingStatusList.Add(pickingStatus); continue; } var pltTarget = inventoryList.First(); var ctnTarget = pltTarget.FBACartonLocations.First(); var quantity = p.Quantity; if (ctnTarget.AvailableCtns < quantity) { pickingStatus.StatusCode = 3003; pickingStatus.Status = "Uncompleted"; pickingStatus.Message = "Picking uncompeleted. Not enough quantity was found in inventory."; pickingStatus.PickedCtns = ctnTarget.AvailableCtns; quantity = ctnTarget.AvailableCtns; } var palletLocationInDb = _context.FBAPalletLocations .Include(x => x.FBAPallet.FBACartonLocations) .Include(x => x.FBAMasterOrder) .Include(x => x.FBAPallet.FBAPalletLocations) .SingleOrDefault(x => x.Id == pltTarget.Id); var pickCartonDtoList = new List <PickCartonDto>(); pickCartonDtoList.Add(new PickCartonDto { Id = ctnTarget.Id, PickQuantity = quantity }); var pickDetail = _picker.CreateFBAPickDetailFromPalletLocation(palletLocationInDb, shipOrder, p.PalletQuantity, p.NewPallet, pickDetailCartonList, pickCartonDtoList, pickingStatus); pickingStatusList.Add(pickingStatus); pickDetail.PickableCtns = p.Quantity; _context.FBAPickDetailCartons.AddRange(pickDetailCartonList); _context.FBAPickDetails.Add(pickDetail); } if (!CheckStatus(pickingStatusList)) { return(pickingStatusList); } _context.SaveChanges(); return(pickingStatusList); }
//当新FBA用户被建立时调用此方法,自动为每个客户添加默认的价格 public void GenerateChargingItems(ApplicationDbContext context, UpperVendor customer) { var chargingItemList = new List <ChargingItem>(); //接收服务 chargingItemList.Add(new ChargingItem { ChargingType = "Receiving", Name = "Uploading with plts FCL/FTL", Unit = "PLT", Rate = 10, Description = "货物接收服务包括接收预报入库*的货物,不包括入库理货。每个托盘货物毛重不得大于660KGS (1455 lb);其他情况另议。", UpperVendor = customer }); chargingItemList.Add(new ChargingItem { ChargingType = "Receiving", Name = "Unloading 20GP", Unit = "CONTAINER", Rate = 0, Description = "货物接收服务包括接收预报入库*的货物,不包括入库理货。", UpperVendor = customer }); chargingItemList.Add(new ChargingItem { ChargingType = "Receiving", Name = " Unloading 40GP", Unit = "CONTAINER", Rate = 350, Description = "货物接收服务包括接收预报入库*的货物,不包括入库理货。", UpperVendor = customer }); chargingItemList.Add(new ChargingItem { ChargingType = "Receiving", Name = " Unloading 40HC", Unit = "CONTAINER", Rate = 350, Description = "货物接收服务包括接收预报入库*的货物,不包括入库理货。", UpperVendor = customer }); chargingItemList.Add(new ChargingItem { ChargingType = "Receiving", Name = " Unloading 45GP", Unit = "CONTAINER", Rate = 0, Description = "货物接收服务包括接收预报入库*的货物,不包括入库理货。", UpperVendor = customer }); chargingItemList.Add(new ChargingItem { ChargingType = "Receiving", Name = "Receiving Doc", Unit = "ORDER", Rate = 0, Description = "收货文件服务包括接收客人提供的装箱清单Packing List、入库单,准备收货单等相关收货文件。", UpperVendor = customer }); //入库理货服务 chargingItemList.Add(new ChargingItem { ChargingType = "Operation", Name = " Sorting Fee", Unit = "CTN", Rate = 0, Description = "入仓理货服务包含按照分货标理货、按照装箱单/入库单清点、存储至库位或上架。适用于货柜/卡车到货的单SKU货品 或 带有分货标的多SKU货品。多SKU货品入仓,分货标必须符合仓库理货标准*,否则加收特殊理货附加费1。", UpperVendor = customer }); chargingItemList.Add(new ChargingItem { ChargingType = "Operation", Name = " Sorting Fee", Unit = "CTN", Rate = 0.5, Description = "需要理货,但分货标*不符合仓库理货标准 或 无分货标的货品额外收取特殊理货附加费1。", UpperVendor = customer }); chargingItemList.Add(new ChargingItem { ChargingType = "Operation", Name = "Sorting Fee", Unit = "CTN", Rate = 0.3, Description = "货品计划入库数量和实际到货数量不符,默认以仓库清点的实际到货数量为准。客户若要求仓库安排重新清点实际到货数量*,则加收特殊理货附加费2(费用计数按实际到货数量)。", UpperVendor = customer }); chargingItemList.Add(new ChargingItem { ChargingType = "Operation", Name = "Sorting Fee", Unit = "CTN", Rate = 0.3, Description = "乱序摆放货物、不同的SKU或者FBA SHIPMENT ID混装在集装箱/车厢中不同的位置会造成卸货理货困难,按实际总数计算,加收特殊理货附加费3。", UpperVendor = customer }); chargingItemList.Add(new ChargingItem { ChargingType = "Operation", Name = " Sorting Fee OVER 1000", Unit = "CTN", Rate = 0.3, Description = "箱数大于1000箱时,超出部分每箱加收箱数超标附加费。", UpperVendor = customer }); chargingItemList.Add(new ChargingItem { ChargingType = "Operation", Name = " Sorting Fee OVER 10 SKU", Unit = "SKU", Rate = 5, Description = "同一票货物入仓有10个以上不同品种需要分货打托,从第10个品种起,每额外品种加收$5.00。", UpperVendor = customer }); chargingItemList.Add(new ChargingItem { ChargingType = "Operation", Name = "Overweight", Unit = "OTHER", Rate = 0.5, Description = "单箱重量大于30KG,超出部分以5KG为单位加收$0.50/5KG。", UpperVendor = customer }); //仓储服务 chargingItemList.Add(new ChargingItem { ChargingType = "Storage", Name = "Storage", Unit = "STORAGE", Rate = 0, Description = "1.适用于到仓前已经向仓库下达发货指令的货物;2.货物必须用托盘装载储存。收货时未打托的货品必须打托才可进入转运货物临时仓储区;3.价格仅适用于标准托盘 *,特殊情况需要提前商议确认", UpperVendor = customer }); //出库操作服务 chargingItemList.Add(new ChargingItem { ChargingType = "Shipping", Name = " Palletizing + Loading ", Unit = "PLT", Rate = 14, Description = "适用于已经打托的货物。服务包括从库位拉货和装车;不包括准备出库文件、打托和卡车运输*。", UpperVendor = customer }); chargingItemList.Add(new ChargingItem { ChargingType = "Shipping", Name = " Loading ", Unit = "PLT", Rate = 4, Description = "适用于已经打托的货物。服务包括从库位拉货和装车;不包括准备出库文件、打托和卡车运输*。 该服务最低收费$20.00/单", UpperVendor = customer }); chargingItemList.Add(new ChargingItem { ChargingType = "Shipping", Name = "Shipping Doc", Unit = "ORDER", Rate = 14, Description = "发货文件服务包括接收客人发货指令/转运单/订单、出具拣货单、系统批量签出、制作提单和向客人发送交货证明POD等。第一单免费。如果客人出具BOL,此服务免费。", UpperVendor = customer }); context.ChargingItems.AddRange(chargingItemList); }