public void TestMethod1() { using (var shopDb = TShopDbContxtFactory.MarkShopDb()) { using (var db = TShopDbContxtFactory.MarkFinanceDb()) { BeginRechangeArgsModel args = new BeginRechangeArgsModel(); if (args.ShopFlag == null) { throw new ArgumentNullException("ShopFlag"); } if (!args.ShopOrderId.HasValue) { throw new ArgumentNullException("ShopOrderId"); } var memberId = 113; ShopOrder shopOrder = shopDb.GetSingle <ShopOrder>(args.ShopOrderId.Value); if (shopOrder == null) { throw new Exception("订单不存在"); } ShopPayInfo shopPayInfo = shopDb.Query <ShopPayInfo>() .Where(m => !m.IsDel) .Where(m => m.ShopFlag == args.ShopFlag && m.IsEnable) .FirstOrDefault(); if (shopPayInfo == null) { throw new Exception("当前商铺没有设置好支付信息。"); } PayProxyBase payProxy = FactoryUtil.GetPayProxyFactory().GetProxy(shopPayInfo); var tradeNo = "SP" + DateTime.Now.Ticks + CommonUtil.CreateNoncestr(5); var tradeDate = DateTime.Now.ToString("yyyyMMddHHmmss"); var model = new MemberTradeForRechange() { AddTime = DateTime.Now, MemberId = memberId, Detail = "用户支付" + shopOrder.Payment.Value + "分", OutBank = "", PayChannel = payProxy.PayChannel, Status = MemberTradeForRechangeStatus.未完成, TimeExpire = DateTime.Now, TimeStart = DateTime.Now, Title = "用户支付", TotalFee = shopOrder.Payment.Value, ShopOrderId = args.ShopOrderId.Value, MoneyOffRuleId = shopOrder.MoneyOffRuleId, TradeNo = tradeNo, PayWay = (int)shopPayInfo.PayWay, //ShopType = shopOrder RowVersion = DateTime.Now }; db.AddToMemberTradeForRechange(model); var payInfo = payProxy.GetPayInfo(model, ""); } } }
public APIResult BeginRechange([FromBody] BeginRechangeArgsModel args) { if (args.TotalFee <= 0) { throw new Exception("充值金额需要大于0"); } var memberId = GetMemberId(); var tradeNo = "SP" + DateTime.Now.Ticks + CommonUtil.CreateNoncestr(5); var tradeDate = DateTime.Now.ToString("yyyyMMddHHmmss"); var model = new MemberTradeForRechange() { AddIP = GetIp(), AddTime = DateTime.Now, AddUser = GetUsername(), MemberId = memberId, Detail = "用户充值" + args.TotalFee + "分", OutBank = "", PayChannel = "宝付", Status = MemberTradeForRechangeStatus.未完成, TimeExpire = DateTime.Now, TimeStart = DateTime.Now, Title = "用户充值", TotalFee = args.TotalFee, TradeNo = tradeNo }; db.AddToMemberTradeForRechange(model); db.SaveChanges(); var openId = GetOpenId(); var payInfo = payProxy.GetPayInfo(model, openId, options.DefaultAppId); var obj = Newtonsoft.Json.JsonConvert.DeserializeObject(payInfo); return(Success(new { payInfo = obj, TradeNo = tradeNo })); }
public APIResult BeginRechange([FromBody] BeginRechangeArgsModel args) { //if (args.TotalFee <= 0) throw new Exception("充值金额需要大于0"); if (args.ShopFlag == null) { throw new ArgumentNullException("ShopFlag"); } if (!args.ConglomerationOrderId.HasValue) { throw new ArgumentNullException("ConglomerationOrderId"); } var memberId = GetMemberId(); ConglomerationOrder conglomerationOrder = shopDb.GetSingle <ConglomerationOrder>(args.ConglomerationOrderId.Value); if (conglomerationOrder == null) { throw new Exception("订单不存在"); } ShopPayInfo shopPayInfo = shopDb.Query <ShopPayInfo>() .Where(m => !m.IsDel) .Where(m => m.ShopFlag == args.ShopFlag) .Where(m => m.ShopFlag == args.ShopFlag && m.IsEnable) .FirstOrDefault(); if (shopPayInfo == null) { throw new Exception("当前商铺没有设置好支付信息。"); } if (shopPayInfo.PayWay == PayWay.Wechat) { throw new Exception("拼团功能暂不支持,请联系商户修改支付模式"); } PayProxyBase payProxy = proxyFactory.GetProxy(shopPayInfo); var tradeNo = "SP" + DateTime.Now.Ticks + CommonUtil.CreateNoncestr(5); var tradeDate = DateTime.Now.ToString("yyyyMMddHHmmss"); var model = new MemberTradeForRechange() { AddIP = GetIp(), AddTime = DateTime.Now, AddUser = GetUsername(), MemberId = memberId, Detail = "拼团订单支付" + conglomerationOrder.Payment.Value + "分", OutBank = "", PayChannel = payProxy.PayChannel, Status = MemberTradeForRechangeStatus.未完成, TimeExpire = DateTime.Now, TimeStart = DateTime.Now, Title = "拼团订单支付", TotalFee = conglomerationOrder.Payment.Value, ConglomerationOrderId = args.ConglomerationOrderId.Value, MoneyOffRuleId = 0, TradeNo = tradeNo, OrderType = OrderType.拼团订单, OrderId = args.ConglomerationOrderId.Value, ShopOrderId = 0, PayWay = (int)shopPayInfo.PayWay, ShopId = shopPayInfo.ShopId }; db.AddToMemberTradeForRechange(model); var openId = GetOpenId(); var payInfo = payProxy.GetPayInfo(model, openId); db.SaveChanges(); if (shopPayInfo.PayWay == PayWay.Wechat) { new PayOrRefundUtil <object>(LogDbContext).PayAction("Pay" , BLL.Log.PayOrRefundType.支付, args.ConglomerationOrderId.Value, OrderType.拼团订单, model, payInfo); return(Success(new { payInfo, TradeNo = tradeNo })); } else { PayInfoModel infoModel = new PayInfoModel(); var payinfo = JsonConvert.DeserializeObject <PayInfo>(payInfo.ToString()); infoModel.payInfo = payinfo; new PayOrRefundUtil <object>(LogDbContext).PayAction("Pay" , BLL.Log.PayOrRefundType.支付, args.ConglomerationOrderId.Value, OrderType.拼团订单, model, payInfo); return(Success( infoModel )); } }
public APIResult BeginRecharge([FromBody] BeginRechangeArgsModel args) { try { if (args.ShopFlag == null) { throw new ArgumentNullException("ShopFlag"); } var memberId = GetMemberId(); Shop shop = shopDb.Query <Shop>().FirstOrDefault(m => !m.IsDel && m.Flag == args.ShopFlag); ShopPayInfo shopPayInfo = shopDb.Query <ShopPayInfo>() .Where(m => !m.IsDel) .Where(m => m.ShopFlag == args.ShopFlag && m.IsEnable) .FirstOrDefault(); if (shopPayInfo == null) { throw new Exception("当前商铺没有设置好支付信息。"); } int rechangeAmount, presentedAmount; if (args.RechargeType == RechargeType.固定金额) { if (!args.TopUpId.HasValue) { throw new Exception("TopUpId不能为空"); } var topUpSet = shopDb.Query <ShopTopUpSet>() .FirstOrDefault(m => !m.IsDel && m.Id == args.TopUpId.Value && m.ShopId == shop.Id); if (topUpSet == null) { throw new Exception("该商铺不存在此项充值"); } rechangeAmount = topUpSet.FixationTopUpAmount; presentedAmount = topUpSet.PresentedAmount; } else { if (!args.Amount.HasValue) { throw new Exception("充值金额不能为空"); } rechangeAmount = args.Amount.Value; var customTopUpSet = shopDb.Query <ShopCustomTopUpSet>() .FirstOrDefault(m => !m.IsDel && m.ShopId == shop.Id); if (customTopUpSet == null) { throw new Exception("该商铺不存在此项充值"); } if (args.Amount.Value < customTopUpSet.StartAmount) { throw new Exception("充值金额少于起充金额"); } if (args.Amount.Value > customTopUpSet.MeetAmount) { presentedAmount = (int)((args.Amount.Value - customTopUpSet.MeetAmount) * (customTopUpSet.Additional / 100.00D)); } else { presentedAmount = 0; } } var shopMember = BLL.Servers.ShopMemberServer.GetShopMember(shopDb, shop.Id, memberId); var memberRecharge = new ShopMemberRecharge() { Amount = rechangeAmount, PresentedAmount = presentedAmount, ShopMemberId = shopMember.Id, TransactionTime = DateTime.Now, Status = ShopMemberTransactionStatus.未完成 }; shopDb.Add(memberRecharge); shopDb.SaveChanges(); PayProxyBase payProxy = proxyFactory.GetProxy(shopPayInfo); var tradeNo = "SP" + DateTime.Now.Ticks + CommonUtil.CreateNoncestr(5); var tradeDate = DateTime.Now.ToString("yyyyMMddHHmmss"); var model = new MemberTradeForRechange() { AddIP = GetIp(), AddTime = DateTime.Now, AddUser = GetUsername(), MemberId = memberId, Detail = $"用户支付{rechangeAmount}分", OutBank = "", PayChannel = payProxy.PayChannel, Status = MemberTradeForRechangeStatus.未完成, TimeExpire = DateTime.Now, TimeStart = DateTime.Now, Title = "用户充值", ShopOrderId = memberRecharge.Id, TotalFee = rechangeAmount, TradeNo = tradeNo, PayWay = (int)shopPayInfo.PayWay, RowVersion = DateTime.Now, OrderType = OrderType.充值订单, ConglomerationOrderId = 0, ShopId = shopPayInfo.ShopId }; finaceDb.AddToMemberTradeForRechange(model); var openId = GetOpenId(); var payInfo = payProxy.GetPayInfo(model, openId); finaceDb.SaveChanges(); if (shopPayInfo.PayWay == PayWay.Wechat) { new PayOrRefundUtil <object>(LogDbContext).PayAction("Pay" , BLL.Log.PayOrRefundType.支付, rechangeAmount, OrderType.普通订单, model, payInfo); return(Success(new { payInfo, TradeNo = tradeNo })); } else { var infoModel = new Core.Finance.WechatPay.PayAPIModels.PayInfoModel(); var payinfo = JsonConvert.DeserializeObject <ZRui.Web.Core.Finance.WechatPay.PayAPIModels.PayInfo>(payInfo.ToString()); infoModel.payInfo = payinfo; //new PayOrRefundUtil<object>(LogDbContext).PayAction("Pay" // , BLL.Log.PayOrRefundType.支付, args.ShopOrderId.Value, OrderType.普通订单, model, payInfo); return(Success( infoModel )); } } catch (Exception ex) { //new PayOrRefundUtil<object>(LogDbContext).PayAction("Pay" // , BLL.Log.PayOrRefundType.支付, args.ShopOrderId.Value, OrderType.普通订单, null, null, ex.Message + "【StackTrace】" + ex.StackTrace); throw new Exception(ex.Message); } }
public APIResult BeginRechange([FromBody] BeginRechangeArgsModel args) { try { if (args.ShopFlag == null) { throw new ArgumentNullException("ShopFlag"); } if (!args.ShopOrderId.HasValue) { throw new ArgumentNullException("ShopOrderId"); } var memberId = GetMemberId(); ShopOrder shopOrder = shopDb.GetSingle <ShopOrder>(args.ShopOrderId.Value); if (shopOrder == null) { throw new Exception("订单不存在"); } ShopPayInfo shopPayInfo = shopDb.Query <ShopPayInfo>() .Where(m => !m.IsDel) .Where(m => m.ShopFlag == args.ShopFlag && m.IsEnable) .FirstOrDefault(); if (shopPayInfo == null) { throw new Exception("当前商铺没有设置好支付信息。"); } //排除扫码 自助点餐 var checkThirdResult = CheckThird(shopOrder, shopOrder.ShopId); if (!checkThirdResult.Success) { throw new Exception(checkThirdResult.Message); } PayProxyBase payProxy = proxyFactory.GetProxy(shopPayInfo); var tradeNo = "SP" + DateTime.Now.Ticks + CommonUtil.CreateNoncestr(5); var tradeDate = DateTime.Now.ToString("yyyyMMddHHmmss"); var model = new MemberTradeForRechange() { AddIP = GetIp(), AddTime = DateTime.Now, AddUser = GetUsername(), MemberId = memberId, Detail = "用户支付" + shopOrder.Payment.Value + "分", OutBank = "", PayChannel = payProxy.PayChannel, Status = MemberTradeForRechangeStatus.未完成, TimeExpire = DateTime.Now, TimeStart = DateTime.Now, Title = "用户支付", TotalFee = shopOrder.Payment.Value, ShopOrderId = args.ShopOrderId.Value, MoneyOffRuleId = shopOrder.MoneyOffRuleId, TradeNo = tradeNo, PayWay = (int)shopPayInfo.PayWay, //ShopType = shopOrder RowVersion = DateTime.Now, OrderType = OrderType.普通订单, OrderId = args.ShopOrderId.Value, ConglomerationOrderId = 0, ShopId = shopPayInfo.ShopId }; finaceDb.AddToMemberTradeForRechange(model); // var openId = "oYBBo5PUP3TF37pUNiVvc7j5gJ6k"; //"oYBBo5PUP3TF37pUNiVvc7j5gJ6k";// var openId = GetOpenId(); //"oYBBo5PUP3TF37pUNiVvc7j5gJ6k";// var payInfo = payProxy.GetPayInfo(model, openId); finaceDb.SaveChanges(); if (shopPayInfo.PayWay == PayWay.Wechat) { new PayOrRefundUtil <object>(LogDbContext).PayAction("Pay" , BLL.Log.PayOrRefundType.支付, args.ShopOrderId.Value, OrderType.普通订单, model, payInfo); return(Success(new { payInfo, TradeNo = tradeNo })); } else { PayInfoModel infoModel = new PayInfoModel(); var payinfo = JsonConvert.DeserializeObject <ZRui.Web.Core.Finance.WechatPay.PayAPIModels.PayInfo>(payInfo.ToString()); infoModel.payInfo = payinfo; new PayOrRefundUtil <object>(LogDbContext).PayAction("Pay" , BLL.Log.PayOrRefundType.支付, args.ShopOrderId.Value, OrderType.普通订单, model, payInfo); return(Success( infoModel )); } } catch (Exception ex) { new PayOrRefundUtil <object>(LogDbContext).PayAction("Pay" , BLL.Log.PayOrRefundType.支付, args.ShopOrderId.Value, OrderType.普通订单, null, null, ex.Message + "【StackTrace】" + ex.StackTrace); throw new Exception(ex.Message); } //if (args.TotalFee <= 0) throw new Exception("充值金额需要大于0"); }
public APIResult PayApp([FromBody] BeginRechangeArgsModel args) { ShopOrder shopOrder = shopDb.GetSingle <ShopOrder>(args.ShopOrderId.Value); if (shopOrder == null) { throw new Exception("订单不存在"); } ShopPayInfo shopPayInfo = shopDb.Query <ShopPayInfo>() .Where(m => !m.IsDel) .Where(m => m.ShopFlag == args.ShopFlag && m.IsEnable) .FirstOrDefault(); if (shopPayInfo == null) { throw new Exception("当前商铺没有设置好支付信息。"); } //排除扫码 自助点餐 var checkThirdResult = CheckThird(shopOrder, shopOrder.ShopId); if (!checkThirdResult.Success) { throw new Exception(checkThirdResult.Message); } PayProxyBase payProxy = proxyFactory.GetProxy(shopPayInfo); var tradeNo = "SP" + DateTime.Now.Ticks + CommonUtil.CreateNoncestr(5); var tradeDate = DateTime.Now.ToString("yyyyMMddHHmmss"); var model = new MemberTradeForRechange() { AddIP = GetIp(), AddTime = DateTime.Now, AddUser = GetUsername(), MemberId = 0, Detail = "用户支付" + shopOrder.Payment.Value + "分", OutBank = "", PayChannel = payProxy.PayChannel, Status = MemberTradeForRechangeStatus.未完成, TimeExpire = DateTime.Now, TimeStart = DateTime.Now, Title = "用户支付", TotalFee = shopOrder.Payment.Value, ShopOrderId = args.ShopOrderId.Value, MoneyOffRuleId = shopOrder.MoneyOffRuleId, TradeNo = tradeNo, PayWay = (int)shopPayInfo.PayWay, //ShopType = shopOrder RowVersion = DateTime.Now, OrderType = OrderType.普通订单, OrderId = args.ShopOrderId.Value, ConglomerationOrderId = 0, ShopId = shopPayInfo.ShopId }; finaceDb.AddToMemberTradeForRechange(model); var payInfo = payProxy.GetPayAppInfo(model, "2018"); finaceDb.SaveChanges(); return(Success()); }