Exemple #1
0
        public static void SetFinish(this MemberTradeForRechange rechange, PrintDbContext printDbContext, ShopDbContext shopDb, DbContext db, WechatTemplateSendOptions options, ThirdConfig toptions, ILogger _logger)
        {
            if (rechange.ShopOrderId != 0)
            {
                if (rechange.OrderType == OrderType.充值订单)
                {
                    SetShopMemberRechangeFinish(rechange, shopDb);
                }
                else
                {
                    SetShopOrderFinish(printDbContext, shopDb, rechange, options, toptions, _logger);
                }
            }
            if (rechange.ConglomerationOrderId != 0)
            {
                _logger.LogInformation("进入回调,拼团订单");

                try
                {
                    SetConglomerationOrderFinish(printDbContext, shopDb, rechange, options, _logger);
                }
                catch (Exception e)
                {
                    _logger.LogInformation($"回调错误,错误信息:{ e}");

                    throw;
                }
            }
        }
Exemple #2
0
        public static void SetFinish(this MemberTradeForRechange rechange, DbContext db, SwiftpassPayResponseHandler result)
        {
            if (result.TradeState != "NOTPAY")
            {
                if (rechange.Status == MemberTradeForRechangeStatus.未完成)
                {
                    if (rechange.TotalFee != result.TotalFee)
                    {
                        throw new Exception("指定的金额不对应");
                    }
                    rechange.OutBank          = result.Xml;
                    rechange.MechanismTradeNo = result.TransactionId;
                    switch (result.TradeState)
                    {
                    case "SUCCESS":
                        db.SetMemberTradeForRechangeSuccess(rechange);
                        break;

                    case "CLOSED":
                        rechange.Status = MemberTradeForRechangeStatus.取消;
                        break;

                    default:
                        db.SetMemberTradeForRechangeFail(rechange, result.TradeState);
                        break;
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// 开始计算积分(通过支付记录)
        /// </summary>
        /// <param name="db"></param>
        /// <param name="memberTradeForRechange"></param>
        /// <param name="_logger"></param>
        /// <returns></returns>
        public static async Task <bool> GetIntegralStartAsync(ShopDbContext db, MemberTradeForRechange memberTradeForRechange, ILogger _logger)
        {
            try
            {
                var sourceType = SourceType.拼团订单;

                if (memberTradeForRechange.OrderType != OrderType.拼团订单)
                {
                    var order = await db.ShopOrders.FindAsync(memberTradeForRechange.OrderId);

                    if (order.IsTakeOut)
                    {
                        sourceType = SourceType.外卖订单;
                    }
                    if (order.ShopPartId.HasValue)
                    {
                        sourceType = SourceType.扫码点餐订单;
                    }
                    if (order.ShopOrderSelfHelpId.HasValue)
                    {
                        sourceType = SourceType.自助点餐订单;
                    }
                }
                return(await GetOrderIntegral(db, memberTradeForRechange.OrderId, sourceType, _logger));
            }
            catch (Exception e)
            {
                _logger.LogError($"开始计算积分GetIntegralStartAsync 错误信息:{e}");
                return(await Task.FromResult(true));
            }
        }
Exemple #4
0
        /// <summary>
        /// 回调成功更新集合
        /// </summary>
        /// <param name="rechange"></param>
        public static void NotifyOkRemoveList(MemberTradeForRechange rechange, ShopDbContext shopdb, ILogger _logger)
        {
            if (rechange.ConglomerationOrderId.HasValue && rechange.ConglomerationOrderId.Value != 0)
            {
                _logger.LogInformation($"==========回调成功更新集合方法NotifyOkRemoveList开始============");
                _logger.LogInformation($"rechange.ConglomerationOrderId.HasValue:{rechange.ConglomerationOrderId.HasValue}=rechange.ConglomerationOrderId.Value:{rechange.ConglomerationOrderId.Value}");
                var orderId = rechange.ConglomerationOrderId.Value;
                var order   = shopdb.ConglomerationOrder.Find(orderId);
                _logger.LogInformation($"orderID:{order.Id}");

                var ConglomerationSetUp = shopdb.ConglomerationSetUp.Find(order.ConglomerationSetUpId);
                _logger.LogInformation($"ConglomerationSetUpId:{ConglomerationSetUp.Id}");

                if (ConglomerationSetUp.Status == ConglomerationSetUpStatus.已经成团)
                {
                    SetupIdAndMemberId.Remove(ConglomerationSetUp.Id);
                    _logger.LogInformation($"移除拼团拼团ID:{ConglomerationSetUp.Id}");
                }
                else
                {
                    var list = GetSetupIdAndMemberId(ConglomerationSetUp.Id, _logger);
                    _logger.LogInformation($"listCount:{list.Count}");
                    list.RemoveAll(m => m.MmeberId.Equals(order.MemberId));
                    _logger.LogInformation($"移除拼团拼团集合项order.MemberId:{order.MemberId}");
                }
                _logger.LogInformation($"==========回调成功更新集合方法NotifyOkRemoveList结束============");
            }
        }
Exemple #5
0
 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, "");
         }
     }
 }
Exemple #6
0
        /// <summary>
        /// 设置充值完成
        /// </summary>
        /// <param name="rechange"></param>
        /// <param name="shopDb"></param>
        private static void SetShopMemberRechangeFinish(MemberTradeForRechange rechange, ShopDbContext shopDb)
        {
            var memberTransaction = shopDb.GetSingle <ShopMemberRecharge>(rechange.ShopOrderId.Value);

            if (memberTransaction == null)
            {
                return;
            }
            memberTransaction.Status = ShopMemberTransactionStatus.已完成;
            int increaseAmount = memberTransaction.Amount + memberTransaction.PresentedAmount;
            var shopMember     = shopDb.Query <ShopMember>()
                                 .Where(m => !m.IsDel && m.ShopId == rechange.ShopId && m.MemberId == rechange.MemberId)
                                 .FirstOrDefault();

            shopMember.Balance += increaseAmount;
            shopDb.SaveChanges();
        }
Exemple #7
0
        public string GetPayInfo(MemberTradeForRechange rechange, string sub_openid, string sub_appid)
        {
            var requestHandler = new SwiftpassPayRequestHandler(swifpasskey);

            requestHandler.setParameter("out_trade_no", rechange.TradeNo);                                       //商户订单号
            requestHandler.setParameter("body", rechange.Detail);                                                //商品描述
            requestHandler.setParameter("attach", "");                                                           //附加信息
            requestHandler.setParameter("total_fee", rechange.TotalFee.ToString());                              //总金额
            requestHandler.setParameter("mch_create_ip", rechange.AddIP);                                        //终端IP
            requestHandler.setParameter("time_start", rechange.AddTime.ToString("yyyyMMddHHmmss"));              //订单生成时间
            requestHandler.setParameter("time_expire", rechange.AddTime.AddHours(1).ToString("yyyyMMddHHmmss")); //订单超时时间
            requestHandler.setParameter("service", "pay.weixin.jspay");                                          //接口类型:pay.weixin.jspay
            requestHandler.setParameter("mch_id", payinfo.MchId);                                                //必填项,商户号,由平台分配
            requestHandler.setParameter("version", options.Version);                                             //接口版本号
            requestHandler.setParameter("notify_url", options.NotifyUrl);
            //通知地址,必填项,接收平台通知的URL,需给绝对路径,255字符内;此URL要保证外网能访问
            requestHandler.setParameter("nonce_str", Common.CommonUtil.CreateNoncestr(16)); //随机字符串,必填项,不长于 32 位
            requestHandler.setParameter("charset", "UTF-8");                                //字符集
            requestHandler.setParameter("sign_type", "RSA_1_256");                          //签名方式
            requestHandler.setParameter("is_raw", "0");                                     //原生JS值
            requestHandler.setParameter("is_minipg", "1");                                  //表示小程序支付
            requestHandler.setParameter("device_info", "");                                 //终端设备号
            requestHandler.setParameter("sub_appid", sub_appid);
            requestHandler.setParameter("sub_openid", sub_openid);                          //测试账号不传值,此处默认给空值。正式账号必须传openid值,获取openid值指导文档地址:http://www.cnblogs.com/txw1958/p/weixin76-user-info.html
            requestHandler.setParameter("callback_url", "https://www.swiftpass.cn");        //前台地址  交易完成后跳转的 URL,需给绝对路径,255字 符 内 格 式如:http://wap.tenpay.com/callback.asp
            requestHandler.setParameter("goods_tag", "");                                   //商品标记
            requestHandler.CreateSign();                                                    //创建签名

            string data   = toXml(requestHandler.getAllParameters());                       //生成XML报文
            var    result = Post(swifpasskey.ReqUrl, data);

            //Hashtable param = requestHandler.getAllParameters();
            if (result.isTenpaySign())
            {
                if (result.Status != 0 || result.ResultCode != 0)
                {
                    throw new Exception($"错误代码:{result.Status},错误信息:{result.Message}");
                }

                return(result.PayInfo);
            }
            else
            {
                throw new Exception($"状态:{result.Status},信息:{result.Message}");
            }
        }
Exemple #8
0
        static void SetShopOrderFinish(PrintDbContext printDbContext, ShopDbContext db,
                                       MemberTradeForRechange memberTradeForRechange, WechatTemplateSendOptions options, ThirdConfig toptions, ILogger _logger)
        {
            if (!memberTradeForRechange.ShopOrderId.HasValue)
            {
                throw new Exception("memberTradeForRechange.ShopOrderId is null");
            }
            var shopOrder = db.ShopOrders.FirstOrDefault(p => p.Id == memberTradeForRechange.ShopOrderId.Value);

            shopOrder.PayWay = "微信支付";
            memberTradeForRechange.Status = MemberTradeForRechangeStatus.成功;
            db.SaveChanges();
            OrderFinish(printDbContext, db, options, toptions, shopOrder, _logger);
            var shopName = db.Query <Shop>()
                           .Where(m => m.Id == shopOrder.ShopId)
                           .Select(m => m.Name)
                           .FirstOrDefault();

            AfterOrderPlacing(printDbContext, db, toptions, shopOrder, shopName, options, _logger);
        }
Exemple #9
0
        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
            }));
        }
Exemple #10
0
        public override PayResponseBaseHandler GetPayResult(MemberTradeForRechange rechange)
        {
            var requestHandler = new SwiftpassPayRequestHandler(swifpasskey);

            requestHandler.setParameter("out_trade_no", rechange.TradeNo);                  //商户订单号

            requestHandler.setParameter("transaction_id", rechange.MechanismTradeNo);       //平台订单号
            requestHandler.setParameter("service", "unified.trade.query");                  //接口 unified.trade.query
            requestHandler.setParameter("mch_id", payinfo.MchId);                           //必填项,商户号,由平台分配
            requestHandler.setParameter("version", options.Version);                        //接口版本号
            requestHandler.setParameter("sign_type", "RSA_1_256");                          //签名方式

            requestHandler.setParameter("nonce_str", Common.CommonUtil.CreateNoncestr(16)); //随机字符串,必填项,不长于 32 位
            requestHandler.CreateSign();                                                    //创建签名
            //_logger.LogInformation("GetPayResult result 签名成功");

            string data = toXml(requestHandler.getAllParameters());//生成XML报文

            //_logger.LogInformation("GetPayResult result 生成XML报文:" + data);

            var result = Post(swifpasskey.ReqUrl, data);

            //Hashtable param = requestHandler.getAllParameters();
            //if (result.isTenpaySign())
            //{
            if (result.Status != 0 || result.ResultCode != 0)
            {
                throw new Exception($"错误代码2:{result.ErrCode},错误信息2:{result.ErrMsg}");
            }

            return(result);

            //}
            //else
            //{
            throw new Exception($"错误代码1:{result.Status},错误信息1:{result.Message}");
            //}
        }
Exemple #11
0
        public static void SetFinish(this MemberTradeForRechange rechange, PrintDbContext printDbContext, ThirdConfig toptions, ShopDbContext shopDb, DbContext db, WechatTemplateSendOptions options, PayResponseBaseHandler result, ILogger _logger)
        {
            if (result.TradeState != "NOTPAY")
            {
                if (rechange.Status == MemberTradeForRechangeStatus.未完成)
                {
                    if (rechange.TotalFee != result.TotalFee)
                    {
                        throw new Exception("指定的金额不对应");
                    }
                    rechange.OutBank          = result.Xml;
                    rechange.MechanismTradeNo = result.TransactionId;
                    switch (result.TradeState)
                    {
                    case "SUCCESS":
                        db.SetMemberTradeForRechangeSuccess(rechange);
                        if (rechange.OrderType == OrderType.充值订单)
                        {
                            SetShopMemberRechangeFinish(rechange, shopDb);
                        }
                        else
                        {
                            SetShopOrderFinish(printDbContext, shopDb, rechange, options, toptions, _logger);
                        }
                        break;

                    case "CLOSED":
                        rechange.Status = MemberTradeForRechangeStatus.取消;
                        break;

                    default:
                        db.SetMemberTradeForRechangeFail(rechange, result.TradeState);
                        break;
                    }
                }
            }
        }
Exemple #12
0
 /// <summary>
 /// 获取支付信息
 /// </summary>
 /// <param name="rechange"></param>
 /// <param name="sub_openid"></param>
 /// <param name="sub_appid"></param>
 /// <returns></returns>
 public abstract object GetPayInfo(MemberTradeForRechange rechange, string sub_openid);
Exemple #13
0
 /// <summary>
 /// 获取支付结果
 /// </summary>
 /// <param name="rechange"></param>
 /// <returns></returns>
 public abstract PayResponseBaseHandler GetPayResult(MemberTradeForRechange rechange);
Exemple #14
0
        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
                           ));
            }
        }
Exemple #15
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());
        }
Exemple #16
0
        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);
            }
        }
Exemple #17
0
        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");
        }
Exemple #18
0
 public abstract string GetPayAppInfo(MemberTradeForRechange rechange, string appid);
Exemple #19
0
        /// <summary>
        /// 设置拼团订单支付完成
        /// </summary>
        /// <param name="printDbContext"></param>
        /// <param name="shopDb"></param>
        /// <param name="rechange"></param>
        /// <param name="options"></param>
        /// <param name="logger"></param>
        static void SetConglomerationOrderFinish(PrintDbContext printDbContext, ShopDbContext db, MemberTradeForRechange memberTradeForRechange, WechatTemplateSendOptions options, ILogger _logger)
        {
            var model = db.ConglomerationOrder.Find(memberTradeForRechange.ConglomerationOrderId);

            if (model.PayTime.HasValue)
            {
                return;
            }
            model.PayTime = DateTime.Now;
            model.Status  = ShopOrderStatus.已支付;
            model.PayWay  = "微信支付";
            db.SaveChanges();
            model.Payment = (int)memberTradeForRechange.TotalFee;
            var shopName = db.Query <Shop>()
                           .Where(m => m.Id == model.ShopId)
                           .Select(m => m.Name)
                           .FirstOrDefault();

            AfterConglomerationOrderPlacing(printDbContext, db, model, shopName, options, _logger);

            memberTradeForRechange.Status = MemberTradeForRechangeStatus.成功;

            db.SaveChanges();
        }