/// <summary> /// 充值 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <string> ChargePay(InsertOrderInput input) { var order = new StoreOrder() { OpenId = input.OpenId, PayType = PayType.PayCharge, OrderNum = Guid.NewGuid().ToString("N"), OrderState = null, PayState = null, Price = input.Price, ProductId = input.ProductId }; var type = await _chargeTypeRepository.FirstOrDefaultAsync(input.ProductId); if (type == null) { throw new UserFriendlyException("充值类型不存在"); } await _storeRepository.InsertAsync(order); JsApiPay jsApiPay = new JsApiPay { Openid = input.OpenId, TotalFee = type.Cost }; jsApiPay.GetUnifiedOrderResult(order.OrderNum, "用户充值", "用户充值"); var param = jsApiPay.GetJsApiParameters(); return(param); }
/// <summary> /// 卡券支付 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <string> CardPay(InsertOrderInput input) { var p = await _productRepository.FirstOrDefaultAsync(c => c.Id == input.ProductId); if (p == null) { throw new UserFriendlyException("该商品不存在"); } var order = new StoreOrder() { OpenId = input.OpenId, PayType = PayType.ActivityPay, OrderNum = Guid.NewGuid().ToString("N"), OrderState = null, PayState = null, Price = p.Price, ProductId = p.ProductId }; await _storeRepository.InsertAsync(order); JsApiPay jsApiPay = new JsApiPay { Openid = input.OpenId, TotalFee = p.Price }; jsApiPay.GetUnifiedOrderResult(order.OrderNum, p.ProductName, p.Description); var param = jsApiPay.GetJsApiParameters(); return(param); }
/// <summary> /// 在线支付 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <string> LinePay(InsertOrderInput input) { var p = await _productRepository.FirstOrDefaultAsync(c => c.Id == input.ProductId); if (p == null) { throw new UserFriendlyException("该商品不存在"); } var order = await _storeRepository.FirstOrDefaultAsync(c => c.OrderNum.Equals(input.Order)); if (order == null) { order = new StoreOrder() { FastCode = input.FastCode, OpenId = input.OpenId, PayType = PayType.LinePay, OrderType = input.OrderType, OrderState = null, OrderNum = input.Order, DeviceNum = input.Device, PayState = null, Price = p.Price, ProductId = p.ProductId }; } else { if (order.PayState.HasValue && order.PayState.Value) { throw new UserFriendlyException("该订单已支付,不可重复付款"); } order.OpenId = input.OpenId; order.Price = p.Price; order.FastCode = input.FastCode; order.OrderType = input.OrderType; order.PayType = PayType.LinePay; } JsApiPay jsApiPay = new JsApiPay { Openid = input.OpenId, TotalFee = p.Price }; var card = await _cardRepository.FirstOrDefaultAsync(c => c.Key == input.Key.Value); //使用优惠券 if (card != null) { order.UseCard = input.Key; var t = p.Price - card.Cost; jsApiPay.TotalFee = t <= 0 ? 0 : t; } await _storeRepository.InsertOrUpdateAsync(order); jsApiPay.GetUnifiedOrderResult(order.OrderNum, p.ProductName, p.Description); var param = jsApiPay.GetJsApiParameters(); return(param); }
public void InsertOrder_InputNotValid_CustomException_CustomExceptionTypeBadRequest() { var orderService = GetOrderService(); var order = new InsertOrderInput() { }; Assert.Throws <CustomException>(() => orderService.InsertOrder(order)); }
/// <summary> /// 在线预支付 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <string> LinePay(InsertOrderInput input) { var order = new Order { OpenId = input.OpenId, OrderType = "购买", PayState = false, Price = input.Price }; JsApiPay jsApiPay = new JsApiPay { Openid = input.OpenId, TotalFee = input.Price }; await _orderRepository.InsertOrUpdateAsync(order); jsApiPay.GetUnifiedOrderResult(order.Id.ToString(), "猿人币购买", "猿人币购买"); var param = jsApiPay.GetJsApiParameters(); return(param); }
public IHttpActionResult InsertOrder([FromBody] InsertOrderInput input) { _orderService.InsertOrder(input); return(Ok()); }
/// <summary> /// 余额支付 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task BalancePay(InsertOrderInput input) { var user = await _userRepository.FirstOrDefaultAsync(c => c.OpenId.Equals(input.OpenId)); if (user == null) { throw new UserFriendlyException("用户信息不存在"); } if (user.Balance < input.Price) { throw new UserFriendlyException("用户余额不足"); } var p = await _productRepository.FirstOrDefaultAsync(c => c.Id == input.ProductId); if (p == null) { throw new UserFriendlyException("该商品不存在"); } var o = await _storeRepository.FirstOrDefaultAsync(c => c.OrderNum.Equals(input.Order)); if (o != null && o.PayState.HasValue && o.PayState.Value) { throw new UserFriendlyException("该订单已存在,请重新下单"); } o = new StoreOrder() { FastCode = input.FastCode, OpenId = input.OpenId, PayType = PayType.BalancePay, OrderType = input.OrderType, OrderState = null, OrderNum = input.Order, DeviceNum = input.Device, PayState = null, Price = p.Price, ProductId = p.ProductId }; await _storeRepository.InsertOrUpdateAsync(o); await CurrentUnitOfWork.SaveChangesAsync(); //使用优惠券 if (input.Key.HasValue) { var card = await _cardRepository.FirstOrDefaultAsync(c => c.Key == input.Key.Value); if (card != null) { var price = p.Price - card.Cost; price = price < 0 ? 0 : price; user.Balance -= price; card.State = true; } } else { user.Balance -= input.Price; } o.PayState = true; //发货 if (o.OrderType == OrderType.Ice) { var result = await PickProductIce(o); Logger.Warn($"出货通知日志:{o.OrderNum}----{result}"); } else { var temp = await PickProductJack(o); Logger.Warn($"出货通知日志:{o.OrderNum}----{temp}"); if (temp.status == "success") { o.OrderState = true; } } }
public void InsertOrder(InsertOrderInput input) { try { if (!input.IsValid()) { throw new CustomException(CustomExceptionTypeEnum.BadRequest, input.GetErrorMessage()); } if (input.PartnerId == PartnerType.PartnerA && input.PaidProducts.Count > 1) { throw new CustomException(CustomExceptionTypeEnum.BadRequest, OrderConstants.PartnerAIncludePaidProduct); } if (input.PartnerId == PartnerType.PartnerA && input.WebSites.Count == 0) { throw new CustomException(CustomExceptionTypeEnum.BadRequest, OrderConstants.PartnerAMissingWebsite); } if (input.PartnerId == PartnerType.PartnerD && input.WebSites.Count > 1) { throw new CustomException(CustomExceptionTypeEnum.BadRequest, OrderConstants.PartnerDIncludeWebsite); } if (input.PartnerId == PartnerType.PartnerD && input.PaidProducts.Count == 0) { throw new CustomException(CustomExceptionTypeEnum.BadRequest, OrderConstants.PartnerDMissingPaidProduct); } if ((input.PartnerId == PartnerType.PartnerB || input.PartnerId == PartnerType.PartnerD) && input.AdditionalOrderInfo != null) { throw new CustomException(CustomExceptionTypeEnum.BadRequest, OrderConstants.PartnerBandDCantHaveAdditionalInfo); } if ((input.PartnerId == PartnerType.PartnerA || input.PartnerId == PartnerType.PartnerC) && input.AdditionalOrderInfo == null) { throw new CustomException(CustomExceptionTypeEnum.BadRequest, OrderConstants.PartnerAandCHaveAdditionalInfo); } var orderEntity = new Order { AdditionalOrderInfo = input.AdditionalOrderInfo, CompanyId = input.CompanyId, CompanyName = input.CompanyName, PartnerId = input.PartnerId, SubmittedBy = input.SubmittedBy, TypeOfOrder = input.TypeOfOrder, Products = new List <Product>() }; foreach (var item in input.PaidProducts) { orderEntity.Products.Add(new PaidSearch { LeadPhoneNumber = item.LeadPhoneNumber, CampaignAddressLine1 = item.CampaignAddressLine1, CampaignName = item.CampaignName, CampaignPostCode = item.CampaignPostCode, Category = item.Category, DestinationURL = item.DestinationURL, Notes = item.Notes, Offer = item.Offer, Radius = item.Radius, SMSPhoneNumber = item.SMSPhoneNumber, UniqueSellingPoint1 = item.UniqueSellingPoint1, UniqueSellingPoint2 = item.UniqueSellingPoint2, UniqueSellingPoint3 = item.UniqueSellingPoint3 }); } foreach (var item in input.WebSites) { orderEntity.Products.Add(new WebSite { Category = item.Category, Notes = item.Notes, TemplateId = item.TemplateId, WebsiteAddressLine1 = item.WebsiteAddressLine1, WebsiteAddressLine2 = item.WebsiteAddressLine2, WebsiteBusinessName = item.WebsiteBusinessName, WebsiteCity = item.WebsiteCity, WebsiteEmail = item.WebsiteEmail, WebsiteMobile = item.WebsiteMobile, WebsitePhone = item.WebsitePhone, WebsitePostCode = item.WebsitePostCode, WebsiteState = item.WebsiteState }); } _unitOfWork.OrderRepository.Insert(orderEntity); _unitOfWork.Save(); } catch (Exception ex) { if (ex is CustomException) { throw ex; } throw new CustomException(CustomExceptionTypeEnum.InternalServerError, "An Error Occurred", ex); } }