Ejemplo n.º 1
0
        /// <summary>
        /// 出票通知
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        private async Task <bool> TicketNoticing(string result)
        {
            JObject jarr = JObject.Parse(result);

            if (jarr.HasValues)
            {
                foreach (var json in jarr["notifyList"])
                {
                    string Status  = json["status"].ToString();
                    string orderid = json["orderId"].ToString();
                    var    order   = await _orderingApplicationService.FindOrderAsync(orderid);

                    if (order.Status == 2000)
                    {
                        if (Status.IsIn("0", "1"))
                        {
                            return(false);
                        }
                        else if (Status.Equals("2"))
                        {
                            string   ticketId   = json["tickSn"].ToString();
                            DateTime tickettime = DateTime.Now;
                            LotteryTicketingTypes lotteryTicketingType = LotteryTicketingTypes.Success;
                            await _lotteryNoticingMessagePublisher.PublishAsync($"LotteryOrdering.Ticketed.{order.LdpVenderId}", new NoticeMessage <LotteryTicketed>(orderid, order.LdpVenderId, new LotteryTicketed
                            {
                                LvpMerchanerId = order.LdpVenderId,
                                LvpOrderId = order.LvpOrderId,
                                TicketingType = lotteryTicketingType,
                            }));

                            return(true);
                        }
                        else
                        {
                            LotteryTicketingTypes lotteryTicketingType = LotteryTicketingTypes.Success;
                            await _lotteryNoticingMessagePublisher.PublishAsync($"LotteryOrdering.Ticketed.{order.LdpVenderId}", new NoticeMessage <LotteryTicketed>(orderid, order.LdpVenderId, new LotteryTicketed
                            {
                                LvpMerchanerId = order.LdpVenderId,
                                LvpOrderId = order.LvpOrderId,
                                TicketingType = lotteryTicketingType,
                            }));

                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
 protected override Task ExecuteAsync(CancellationToken stoppingToken)
 {
     return(_busClient.SubscribeAsync <NoticeMessage <LotteryTicketed> >(async(message) =>
     {
         try
         {
             if (message.Content.TicketingType == LotteryTicketingTypes.Success)
             {
                 IUnitOfWorkManager unitOfWorkManager = _iocResolver.GetRequiredService <IUnitOfWorkManager>();
                 using (var uow = unitOfWorkManager.Begin())
                 {
                     IOrderingApplicationService orderingApplicationService = _iocResolver.GetRequiredService <IOrderingApplicationService>();
                     var order = await orderingApplicationService.FindOrderAsync(message.LdpOrderId);
                     if (order == null)
                     {
                         return new Ack();
                     }
                     ILotteryMerchanterApplicationService lotteryMerchanterApplicationService = _iocResolver.GetRequiredService <ILotteryMerchanterApplicationService>();
                     await lotteryMerchanterApplicationService.Ticketing(message.LdpMerchanerId, order.Id, order.LotteryId, order.InvestAmount);
                     await lotteryMerchanterApplicationService.Ticketing(order.LvpVenderId, order.Id, order.LotteryId, order.InvestAmount);
                     uow.Complete();
                 }
             }
             _logger.LogInformation("Received ticketing message: {1} {0}", message.LdpMerchanerId, message.LdpOrderId);
             return new Ack();
         }
         catch (Exception ex)
         {
             _logger.LogError(ex, "Received ticketing message: {1} {0}", message.LdpMerchanerId, message.LdpOrderId);
         }
         return new Nack();
     }, context =>
     {
         context.UseSubscribeConfiguration(configuration =>
         {
             configuration.OnDeclaredExchange(exchange =>
             {
                 exchange.WithName("Baibaocp.LotteryNoticing")
                 .WithDurability(true)
                 .WithAutoDelete(false)
                 .WithType(ExchangeType.Topic);
             });
             configuration.FromDeclaredQueue(queue =>
             {
                 queue.WithName("LotteryTrading.TradeLogging.Tickets")
                 .WithAutoDelete(false)
                 .WithDurability(true);
             });
             configuration.Consume(consume =>
             {
                 consume.WithRoutingKey("LotteryOrdering.Ticketed.#");
             });
         });
     }, stoppingToken));
 }
Ejemplo n.º 3
0
        public async Task <IQueryingHandle> DispatchAsync(QueryingDispatchMessage message)
        {
            try
            {
                XDocument content    = new XDocument();
                XDocument rescontent = new XDocument();
                rescontent = await Send(message, "1002");

                bool handle = Verify(rescontent, out content);
                if (handle)
                {
                    XElement xml     = content.Root;
                    XElement records = xml.Element("records");
                    foreach (XElement record in records.Elements("record"))
                    {
                        string id = record.Element("id").Value;
                        if (id == message.LdpOrderId)
                        {
                            var order = await _orderingApplicationService.FindOrderAsync(id);

                            int    Bonus               = int.Parse(record.Element("bonusValue").Value);
                            int    Count               = int.Parse(record.Element("bonusCount").Value);
                            int    singleBonus         = (Bonus / Count) / order.InvestTimes;
                            double tax                 = 0;
                            double AfterTacBonusAmount = 0;
                            if (singleBonus > 1000000)
                            {
                                tax = singleBonus * 0.2;
                                AfterTacBonusAmount = (singleBonus - tax) * Count * order.InvestTimes;
                            }
                            else
                            {
                                AfterTacBonusAmount = (double)Bonus;
                            }
                            return(new WinningHandle(Bonus, (int)AfterTacBonusAmount));
                        }
                        else
                        {
                            return(new WaitingHandle());
                        }
                    }
                }
                return(new WaitingHandle());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Request Exception:{0}", ex.Message);
                return(new WaitingHandle());
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// xAgent=3821&xAction=501&xSign=dfa62fc1b09d94fca897a3462a928545&xValue=D200900067_2003,D200900054_2003
        /// </summary>
        /// <param name="httpContext"></param>
        /// <returns></returns>
        public async Task Invoke(HttpContext httpContext)
        {
            try
            {
                var xAgent     = httpContext.Request.Form["xAgent"].ToString();
                var xAction    = httpContext.Request.Form["xAction"].ToString();
                var xSign      = httpContext.Request.Form["xSign"].ToString();
                var xValue     = httpContext.Request.Form["xValue"].ToString();
                var merchanter = await _lotteryMerchanterApplicationService.FindMerchanterAsync(xAgent);

                string str = $"{xAgent}{xAction}{xValue}{merchanter.SecretKey}";
                if (str.VerifyMd5(xSign))
                {
                    string[] items = xValue.Split(",");
                    foreach (var item in items)
                    {
                        string[] values = item.Split("_");
                        var      order  = await _orderingApplicationService.FindOrderAsync(values[0]);

                        if (order.Status < 4000)
                        {
                            LotteryTicketingTypes lotteryTicketingType = values[1] == "1" ? LotteryTicketingTypes.Success : LotteryTicketingTypes.Failure;
                            _logger.LogTrace($"{order.Id} Ticketed: {lotteryTicketingType}");
                            await _lotteryNoticingMessagePublisher.PublishAsync($"LotteryOrdering.Ticketed.{xAgent}", new NoticeMessage <LotteryTicketed>(values[0], xAgent, new LotteryTicketed
                            {
                                LvpMerchanerId = order.LdpVenderId,
                                LvpOrderId = order.LvpOrderId,
                                TicketingType = lotteryTicketingType,
                            }));
                        }
                        else
                        {
                            _logger.LogWarning($"{order.Id} {order.Status}");
                        }
                    }
                    await httpContext.Response.WriteAsync("1");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }
            await httpContext.Response.WriteAsync("0");
        }
Ejemplo n.º 5
0
        public async Task <ILotteryCalculator> GetLotteryCalculatorAsync(string orderId)
        {
            IOrderingApplicationService orderingApplicationService = _iocResolver.GetRequiredService <IOrderingApplicationService>();
            var lotteryMerchanteOrder = await orderingApplicationService.FindOrderAsync(orderId);

            ObjectFactory objectFactory = _objectFactories.GetOrAdd(lotteryMerchanteOrder.LotteryId, (lotteryId) =>
            {
                if (_lotteryCalculatorImplementationTypes.TryGetValue(lotteryId, out Type implementationType))
                {
                    ObjectFactory factory = ActivatorUtilities.CreateFactory(implementationType, new Type[] { typeof(LotteryMerchanteOrder) });
                    return(factory);
                }
                throw new KeyNotFoundException($"Lottery {nameof(lotteryId)} not implementation ILotteryCalculator");
            });

            ILotteryCalculator lotteryCalculator = objectFactory.Invoke(_iocResolver, new[] { lotteryMerchanteOrder }) as ILotteryCalculator;

            return(lotteryCalculator);
        }