Ejemplo n.º 1
0
        public ActionResult PayNotify(int tenantId)
        {
            Action <NotifyResult> successAction = result =>
            {
                var resultLog = JsonConvert.SerializeObject(result);
                using (var context = new AppDbContext())
                {
                    var order = context.Order_Infos.FirstOrDefault(o => o.Code == result.OutTradeNo);
                    if (null != order)
                    {
                        //修改订单状态
                        order.State        = EnumOrderStatus.Overhang;
                        order.ThirdPayType = EnumThirdPayType.WX;
                        order.PaymentOn    = DateTime.Now;
                        order.UpdateTime   = DateTime.Now;
                        //需要更新订单对应的商品的已成交数
                        var lst_details = db.Order_Details.Where(p => p.OrderID == order.Id).ToList();
                        foreach (Order_Detail detail in lst_details)
                        {
                            Product_Info product = db.Product_Infos.FirstOrDefault(
                                p => p.Id == detail.ProductID);
                            product.SellCount = product.SellCount + detail.Quantity;
                        }
                        context.SaveChanges();
                        //记录支付日志
                        using (var payLogDo = new PayLogDO(order.TenantId, order.OpenId, order.ClientIpAddress, context))
                        {
                            payLogDo.AddOrderLog(order.Id, order.TotalPrice, paymentInterfaceLog: resultLog);
                        }
                    }
                    else
                    {
                        logger.Log(LoggerLevels.Error, "Order information does not exist!OrderId:" + result.OutTradeNo);
                    }
                }
                //此处编写成功处理逻辑
                logger.Log(LoggerLevels.Debug, "Success: JSON:" + resultLog);
            };
            Action <NotifyResult> failAction = result =>
            {
                //此处编写失败处理逻辑
                var failLog = JsonConvert.SerializeObject(result);
                logger.Log(LoggerLevels.Error, "Fail: JSON:" + failLog);
                using (var context = new AppDbContext())
                {
                    var order = context.Order_Infos.FirstOrDefault(o => o.Code == result.OutTradeNo);
                    //记录支付日志
                    using (var payLogDo = new PayLogDO(order.TenantId, order.OpenId, order.ClientIpAddress, context))
                    {
                        payLogDo.AddOrderLog(order.Id, order.TotalPrice, paymentInterfaceLog: failLog, errorLog: failLog);
                    }
                }
            };

            return
                (Content(WeChatApisContext.Current.TenPayV3Api.NotifyAndReurnResult(Request.InputStream, successAction,
                                                                                    failAction)));
        }
Ejemplo n.º 2
0
        public IHttpActionResult DoRecharge(dynamic model)
        {
            decimal amount = model.Amount; //Convert.ToDecimal(model.Amout);

            log.Log(LoggerLevels.Debug,
                    "进入API[DoRecharge]amount:" + amount + ", model:" + JsonConvert.SerializeObject(model));

            if (amount <= 0)
            {
                return(BadRequest("充值金额必须大于0!"));
            }
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context

            //记录充值日志
            using (var payLogDo = new PayLogDO(TenantId, WeiChatApplicationContext.Current.WeiChatUser.OpenId, context != null ? context.GetClientIpAddress() : null, db))
            {
                payLogDo.AddRechargeLog(amount, paymentInterfaceLog: null);
            }
            return(Ok());
        }