public Tuple <BookingBuyOutput, ServiceResult> Buy(BookingBuyInput buyInput) { // 安验证,Order BookingId // order.price =总价/数量 // pay表记录 #region 验证 if (buyInput.UserId <= 0) { return(Tuple.Create(new BookingBuyOutput(), ServiceResult.FailedWithMessage("会员不存在"))); } if (buyInput.Count < 1) { return(Tuple.Create(new BookingBuyOutput(), ServiceResult.FailedWithMessage("至少要有一名参与者"))); } if (buyInput.Price != buyInput.TotalPrice / buyInput.Count) { return(Tuple.Create(new BookingBuyOutput(), ServiceResult.FailedWithMessage("价格计算有误"))); } //if (buyInput.BookingId.IsNullOrEmpty()) { // return Tuple.Create(new BookingBuyOutput(), ServiceResult.FailedWithMessage("订单为空")); //} //var checkModel = Resolve<IBookingSignupOrderService>() // .GetSingle(u => u.BookingId == buyInput.BookingId.ToObjectId()); //if (checkModel != null) { // return Tuple.Create(new BookingBuyOutput(), ServiceResult.FailedWithMessage("该订单已存在,请勿重复提交")); //} #endregion 验证 var user = Resolve <IUserService>().GetSingle(buyInput.UserId); var model = AutoMapping.SetValue <BookingSignupOrder>(buyInput); #region 手机验证 model.Contacts = buyInput.Contacts.Deserialize <BookingSignupOrderContact>(); var i = 0; foreach (var item in model.Contacts) { i++; if (item.Name.IsNullOrEmpty()) { return(Tuple.Create(new BookingBuyOutput(), ServiceResult.FailedWithMessage($"第{i}名参与者名字不能为空"))); } if (item.Mobile.IsNullOrEmpty()) { return(Tuple.Create(new BookingBuyOutput(), ServiceResult.FailedWithMessage($"第{i}名参与者手机号不能为空"))); } if (!RegexHelper.CheckMobile(item.Mobile)) { return(Tuple.Create(new BookingBuyOutput(), ServiceResult.FailedWithMessage($"第{i}名参与者手机号不正确"))); } } #endregion 手机验证 model.IsPay = false; model.BookingId = buyInput.BookingId.ToObjectId(); if (Resolve <IBookingSignupOrderService>().Add(model)) { var payExtension = new PayExtension { TradeNo = model.Id.ToString(), Body = "您正在企牛牛商城上消费,请认真核对账单信息", UserName = user.GetUserName(), AfterSuccess = new BaseServiceMethod { Method = "AfterPaySuccess", ServiceName = typeof(IBookingSignupService).Name, Parameter = model.Id }, BuyerCount = 0, GroupOverId = 0, ReturnUrl = $"/pages/index?path=successful_registration&id={model.Id.ToString()}" //NotifyUrl = //不知道什么支付方式 //RedirectUrl = $"/pages/index?path=successful_registration&id={model.Id}", }; payExtension.RedirectUrl = $"/pages/index?path=successful_registration&id={model.Id.ToString()}"; var pay = new Pay { Status = PayStatus.WaiPay, Type = CheckoutType.Customer, Amount = buyInput.TotalPrice, UserId = user.Id }; try { var bookingSignup = Resolve <IBookingSignupService>().GetSingle(u => u.Id == model.BookingId); // Resolve<ITradeService>().Add(trade); pay.EntityId = $"[\"{model.Id.ToString()}\"]"; payExtension.TradeNo = model.Id.ToString(); pay.Extensions = payExtension.ToJsons(); Resolve <IPayService>().Add(pay); } catch (Exception ex) { return(Tuple.Create(new BookingBuyOutput(), ServiceResult.FailedWithMessage("订单记录失败"))); } var outPut = new BookingBuyOutput { PayId = pay.Id, PayAmount = buyInput.TotalPrice, OrderId = model.Id }; return(Tuple.Create(outPut, ServiceResult.Success)); } return(Tuple.Create(new BookingBuyOutput(), ServiceResult.FailedWithMessage("订单记录失败"))); }
/// <summary> /// 根据订单和用户生成支付记录 /// 生成的支付记录没有,支付方式,支付方式有前端返回来 /// </summary> /// <param name="singlePayInput">The order.</param> public Tuple <ServiceResult, Pay> AddSinglePay(SinglePayInput singlePayInput) { var webSite = Resolve <IAutoConfigService>().GetValue <WebSiteConfig>(); var pay = new Pay { EntityId = singlePayInput.Orders.Select(r => r.Id).ToJson(), Status = PayStatus.WaiPay, Type = singlePayInput.CheckoutType, Amount = singlePayInput.Orders.Sum(r => r.PaymentAmount), UserId = singlePayInput.User.Id }; // 是否为管理员代付 if (singlePayInput.IsAdminPay) { pay.PayType = PayType.AdminPay; } if (singlePayInput.Type == CheckoutType.Customer) { pay.Type = singlePayInput.Type; } var payExtension = new PayExtension { TradeNo = singlePayInput.Orders.FirstOrDefault() .Serial, // 使用第一个订单作为交易号 // Subject = order.OrderExtension?.Product?.Name, // 支付标题为商品名称 TotalAmount = singlePayInput.Orders.Sum(r => r.PaymentAmount), Body = $"您正在{webSite.WebSiteName}商城上购买商品,请认真核对订单信息", // ProductCode = order.OrderExtension?.Product?.Bn, UserName = singlePayInput.User.GetUserName(), IsFromOrder = singlePayInput.IsFromOrder }; if (singlePayInput.IsGroupBuy) { //是否为拼团购买 payExtension.IsGroupBuy = true; payExtension.BuyerCount = singlePayInput.BuyerCount; } if (singlePayInput.ExcecuteSqlList != null) { payExtension.ExcecuteSqlList = singlePayInput.ExcecuteSqlList; } if (singlePayInput.AfterSuccess != null) { payExtension.AfterSuccess = singlePayInput.AfterSuccess; } if (singlePayInput.OrderUser != null) { payExtension.OrderUser = singlePayInput.OrderUser; } payExtension.RedirectUrl = singlePayInput.RedirectUrl; if (Convert.ToInt16(singlePayInput.TriggerType) > 0) { payExtension.TriggerType = singlePayInput.TriggerType; } if (!singlePayInput.EntityId.IsNullOrEmpty()) { pay.EntityId = singlePayInput.EntityId; } IList <KeyValuePair <Guid, decimal> > acmountPay = new List <KeyValuePair <Guid, decimal> >(); if (singlePayInput.ReduceMoneys != null && singlePayInput.ReduceMoneys.Count > 0) { payExtension.Note = "扣除"; singlePayInput.ReduceMoneys.Foreach(r => { payExtension.Note += " " + r.Name + r.MaxPayPrice; acmountPay.Add(new KeyValuePair <Guid, decimal>(r.MoneyId, r.MaxPayPrice)); }); } pay.AccountPay = acmountPay.ToJson(); if (!singlePayInput.RedirectUrl.IsNullOrEmpty()) { payExtension.RedirectUrl = singlePayInput.RedirectUrl; } pay.Extensions = payExtension.ToJson(); if (Resolve <IPayService>().Add(pay)) { return(Tuple.Create(ServiceResult.Success, pay)); } return(Tuple.Create(ServiceResult.FailedWithMessage("支付订单创建失败"), new Pay())); }