Ejemplo n.º 1
0
        public async Task CancelOrderAsync(int orderId, CancellationToken cancellationToken = default)
        {
            var order = await _db.Orders
                        .Include(o => o.Audits)
                        .Include(o => o.OrderedBy)
                        .SingleAsync(o => o.Id == orderId, cancellationToken);

            if (order.Audits.Any(a => a.Type == AuditType.Received))
            {
                throw new InvalidOperationException("Can not cancel an order with received funds. Please refund it instead.");
            }

            var audit = new OrderAudit
            {
                OrderId                  = orderId,
                PaymentProvider          = string.Empty,
                PaymentProviderReference = string.Empty,
                Type        = AuditType.Cancelled,
                When        = DateTimeOffset.Now,
                AmountCents = 0,
            };

            _db.OrderAudits.Add(audit);

            await _db.SaveChangesAsync(cancellationToken);

            // TODO: Send cancellation email.
            //await _emailService.SendOrderCancelledAsync(order, cancellationToken);
        }
Ejemplo n.º 2
0
        public async Task RefundFundsForOrderAsync(int orderId, int amountCents, string paymentProvider, string paymentReference, DateTimeOffset when, CancellationToken cancellationToken = default)
        {
            var order = await _db.Orders
                        .Include(o => o.Audits)
                        .Include(o => o.OrderedBy)
                        .Include(o => o.TicketsPurchased)
                        .ThenInclude(t => t.TicketType)
                        .SingleAsync(o => o.Id == orderId, cancellationToken);

            if (order.Audits.Any(a => a.PaymentProvider == paymentProvider && a.PaymentProviderReference == paymentReference && a.Type == AuditType.Refunded))
            {
                _logger.LogError($"Refund for order {orderId} has already been applied for {paymentProvider}: {paymentReference}");
            }
            else
            {
                var audit = new OrderAudit
                {
                    OrderId                  = orderId,
                    PaymentProvider          = paymentProvider,
                    PaymentProviderReference = paymentReference,
                    Type        = AuditType.Refunded,
                    When        = when,
                    AmountCents = -amountCents,
                };
                // Recalculate amount paid
                order.AmountPaidCents = order.Audits.Sum(a => a.AmountCents) + audit.AmountCents;

                _db.OrderAudits.Add(audit);

                await _db.SaveChangesAsync(cancellationToken);
            }

            await _emailService.SendPaymentRefundedAsync(order, cancellationToken);
        }
Ejemplo n.º 3
0
        private static KokiDB.OrderAudit  audits(UserInfo u, Order o)
        {
            OrderAudit newau = new OrderAudit {
                AdminID = u.UserID, AuditDate = DateTime.Now, OrderID = o.OrderID,
            }; o.OrderAudits.Add(newau);

            return(newau);
        }
Ejemplo n.º 4
0
 public OrderAuditViewModel(OrderAudit audit)
 {
     Id                       = audit.Id;
     Type                     = audit.Type.ToString();
     AmountCents              = audit.AmountCents;
     When                     = audit.When;
     PaymentProvider          = audit.PaymentProvider;
     PaymentProviderReference = audit.PaymentProviderReference;
     OrderId                  = audit.OrderId;
 }
Ejemplo n.º 5
0
        public async Task AddReceivedFundsForOrderAsync(int orderId, int amountCents, string paymentProvider, string paymentReference, DateTimeOffset when, bool allowDuplicates = false, CancellationToken cancellationToken = default)
        {
            var order = await _db.Orders
                        .Include(o => o.Audits)
                        .Include(o => o.OrderedBy)
                        .Include(o => o.TicketsPurchased)
                        .ThenInclude(t => t.TicketType)
                        .SingleAsync(o => o.Id == orderId, cancellationToken);

            if (!allowDuplicates && order.Audits.Any(a => a.PaymentProvider == paymentProvider && a.PaymentProviderReference == paymentReference && a.Type == AuditType.Received))
            {
                // What about back transfers?
                _logger.LogError($"Received funds for order {orderId} has already been applied for {paymentProvider}: {paymentReference}");
            }
            else if (order.IsCancelled)
            {
                _logger.LogError($"Received funds for order {orderId} has already been cancelled.");
            }
            else
            {
                var audit = new OrderAudit
                {
                    OrderId                  = orderId,
                    PaymentProvider          = paymentProvider,
                    PaymentProviderReference = paymentReference,
                    Type        = AuditType.Received,
                    When        = when,
                    AmountCents = amountCents,
                };

                // Recalculate amount paid
                order.AmountPaidCents = order.Audits.Sum(a => a.AmountCents) + audit.AmountCents;

                await _db.OrderAudits.AddAsync(audit, cancellationToken);

                await _db.SaveChangesAsync(cancellationToken);
            }

            if (order.AmountPaidCents >= order.TotalAmountCents)
            {
                await _emailService.SendOrderPaidAsync(order, cancellationToken);
            }
            else
            {
                await _emailService.SendPaymentReceivedAsync(order, cancellationToken);
            }
        }
        private void OrderAudit_Click(object sender, RoutedEventArgs e)
        {
            OrderAudit or = new OrderAudit(Forms.Order.OrderAudit.OrderAuditType.OrderAudit);

            or.Show();
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> OrderAudit(Input_OrderAuditAdd model, [FromServices] ContextString dbContext)
        {
            QianMuResult _Result = new QianMuResult();


            //参数转换
            Stream stream = HttpContext.Request.Body;

            byte[] buffer = new byte[HttpContext.Request.ContentLength.Value];
            stream.Read(buffer, 0, buffer.Length);
            string inputStr = Encoding.UTF8.GetString(buffer);

            model = (Input_OrderAuditAdd)Newtonsoft.Json.JsonConvert.DeserializeObject(inputStr, model.GetType());
            if (string.IsNullOrEmpty(model.MallCode))
            {
                //检测用户登录情况
                var uol = Method.GetLoginUserName(dbContext, this.HttpContext);
                if (string.IsNullOrEmpty(uol.UserName))
                {
                    _Result.Code = "401";
                    _Result.Msg  = "请登陆后再进行操作";
                    _Result.Data = "";
                    return(Json(_Result));
                }
                else
                {
                    model.MallCode = uol.MallCode;
                }
            }
            if (string.IsNullOrEmpty(model.OrderAuditCode))
            {
                _Result.Code = "510";
                _Result.Msg  = "请输入订单审核编码";
                _Result.Data = "";
                return(Json(_Result));
            }
            var orderAudit = await dbContext.OrderAudit.Where(i => i.Code == model.OrderAuditCode).FirstOrDefaultAsync();

            if (orderAudit == null)
            {
                _Result.Code = "510";
                _Result.Msg  = "订单审核编码输入有误";
                _Result.Data = "";
                return(Json(_Result));
            }

            if (string.IsNullOrEmpty(model.OrderCode))
            {
                _Result.Code = "510";
                _Result.Msg  = "请输入订单编码";
                _Result.Data = "";
                return(Json(_Result));
            }
            if (model.AuditStatus == 2 && string.IsNullOrEmpty(model.AuditOpinion))
            {
                _Result.Code = "510";
                _Result.Msg  = "请输入拒绝理由";
                _Result.Data = "";
                return(Json(_Result));
            }
            int resultData = 0;

            if (model.AuditStatus == 2)
            {
                orderAudit.AuditStatus  = model.AuditStatus;
                orderAudit.AuditOpinion = model.AuditOpinion;
                orderAudit.UpdateTime   = DateTime.Now;
                dbContext.OrderAudit.Update(orderAudit);
                if (model.AuditType == 1)
                {
                    var schedule = await dbContext.ScheduleOrder.Where(i => i.Code == model.OrderCode).FirstOrDefaultAsync();

                    schedule.Status     = 3;
                    schedule.UpdateTime = DateTime.Now;
                    dbContext.ScheduleOrder.Update(schedule);
                    WeChatNotice.SendNoticeBySchedule(schedule, dbContext);
                }
                else
                {
                    var order = await dbContext.ProgramOrder.Where(i => i.Code == model.OrderCode).FirstOrDefaultAsync();

                    order.Status     = 3;
                    order.UpdateTime = DateTime.Now;
                    dbContext.ProgramOrder.Update(order);
                    WeChatNotice.SendNoticeByProgram(order, dbContext);
                }
            }
            else
            {
                orderAudit.AuditStatus = model.AuditStatus;
                orderAudit.UpdateTime  = DateTime.Now;
                dbContext.OrderAudit.Update(orderAudit);
                var nextAudit = await dbContext.AuditProcess.Where(i => i.ModuleType == model.AuditType && i.MallCode == model.MallCode && i.Order == (orderAudit.AuditOrder + 1)).FirstOrDefaultAsync();

                if (nextAudit == null)
                {
                    if (model.AuditType == 1)
                    {
                        var schedule = await dbContext.ScheduleOrder.Where(i => i.Code == model.OrderCode).FirstOrDefaultAsync();

                        schedule.Status     = 2;
                        schedule.UpdateTime = DateTime.Now;
                        dbContext.ScheduleOrder.Update(schedule);
                        WeChatNotice.SendNoticeBySchedule(schedule, dbContext);
                    }
                    else
                    {
                        var order = await dbContext.ProgramOrder.Where(i => i.Code == model.OrderCode).FirstOrDefaultAsync();

                        order.Status     = 2;
                        order.UpdateTime = DateTime.Now;
                        dbContext.ProgramOrder.Update(order);
                        WeChatNotice.SendNoticeByProgram(order, dbContext);
                    }
                    resultData = 1;
                }
                else
                {
                    var orderAuditNext = new OrderAudit();
                    orderAuditNext.AddTime      = DateTime.Now;
                    orderAuditNext.AuditOpinion = "";
                    orderAuditNext.AuditOrder   = orderAudit.AuditOrder + 1;
                    orderAuditNext.AuditStatus  = 0;
                    orderAuditNext.Code         = Guid.NewGuid().ToString();
                    orderAuditNext.OperUser     = nextAudit.OperUser;
                    orderAuditNext.OrderCode    = model.OrderCode;
                    orderAuditNext.UpdateTime   = DateTime.Now;
                    dbContext.OrderAudit.Add(orderAuditNext);
                }
            }

            if (await dbContext.SaveChangesAsync() > 0)
            {
                _Result.Code = "200";
                _Result.Msg  = "审核成功";
                _Result.Data = resultData;
            }
            return(Json(_Result));
        }
        private void ViewOrder_Click(object sender, RoutedEventArgs e)
        {
            OrderAudit or = new OrderAudit(OrderAudit.OrderAuditType.ViewOrder);

            or.Show();
        }