示例#1
0
        private async Task <bool> HandleAsync(OrderPayed e)
        {
            Console.WriteLine($"Order paid: Order Id = {e._orderId}, Bank = {e._bank}");

            using (var db = GetOrderDb())
            {
                try
                {
                    var order = await db.Orders.FirstOrDefaultAsync(o => o.OrderId == e._orderId);

                    if (order == null)
                    {
                        throw new KeyNotFoundException($"Order with ID {e._orderId} not found");
                    }

                    order.AddStateChange(OrderState.PAYMENTCOMPLETE);

                    await db.SaveChangesAsync();
                }
                catch (DbUpdateException)
                {
                    Console.WriteLine($"Skipped paying order with order id {e._orderId}.");
                }
            }

            return(true);
        }
示例#2
0
        public async Task <IActionResult> PostAsync(string orderId, [FromBody] string bank)
        {
            OrderPayed e = new OrderPayed(Guid.NewGuid(), orderId, bank);

            await _messagePublisher.PublishMessageAsync(MessageTypes.OrderPayed, e, "");

            return(Ok());
        }
示例#3
0
        public void Handle(OrderPayed e)
        {
            Order order = this.repository.GetById(e.OrderId);

            if (order.Cancelled)
            {
                this.billingSystem.NotifyAccounting(e.OrderId, "RequestRefund");
            }
        }
示例#4
0
        public IActionResult OrderNotify(OrderPayed model)
        {
            if (model == null || model.order_id == 0)
            {
                return(Content("{\"data\":\"model not find\"}"));
            }

            //model.detail = WebUtility.UrlDecode(model.detail);
            ////构建日志参数
            //var meiTOrderLog=new MeiTOrderLog
            //{
            //    OrderId = model.order_id,
            //    OrderContext = WebUtility.UrlDecode(JsonConvert.SerializeObject(model)),
            //    CreateTime = DateTime.Now
            //};
            //_meiTOrderLogService.Add(meiTOrderLog);
            //var orderInfoExist = _meiTOrderInfoService.GetMeiTOrderInfo(model.order_id);
            ////防止美团的重复推送
            //if (orderInfoExist == null)
            //{
            //    //将订单存储在数据库
            //    var orderInfo = new MeiTOrderInfo
            //    {
            //        ShopId = model.app_poi_code,
            //        ShopName = WebUtility.UrlDecode(model.wm_poi_name),
            //        OrderId = model.order_id,
            //        Consignee = WebUtility.UrlDecode(model.recipient_name),
            //        Phone = model.recipient_phone,
            //        Address = WebUtility.UrlDecode(model.recipient_address),
            //        DeliverFee = model.shipping_fee,
            //        Income = model.total,
            //        OriginalPrice = model.original_price,
            //        DaySeq = model.day_seq.ToString(),
            //        PackageBagMoney = model.package_bag_money,
            //        DinnersNumber = model.dinners_number,
            //        TotalPrice = model.original_price-model.shipping_fee
            //    };

            //    if (model.delivery_time != 0)
            //    {
            //        orderInfo.DeliverTime = CommonHelper.GenericTimeStamp(model.delivery_time);
            //    }
            //    orderInfo.Description = WebUtility.UrlDecode(model.caution);
            //    //orderInfo.Status = model.status;
            //    orderInfo.Status = 2;
            //    orderInfo.CreatedAt = CommonHelper.GenericTimeStamp(model.ctime);
            //    _meiTOrderInfoService.Add(orderInfo);

            //    var products = JsonConvert.DeserializeObject<List<OrderProduct>>(model.detail);

            //    if (products != null && products.Count > 0)
            //    {
            //        foreach (var orderProduct in products)
            //        {
            //            var mtProduct = new MeiTOrderProduct
            //            {
            //                OrderId = model.order_id,
            //                ProductId = orderProduct.app_food_code,
            //                Price = orderProduct.price,
            //                Quantity = orderProduct.quantity,
            //                Total = orderProduct.price * orderProduct.quantity,
            //                Attributes = orderProduct.unit,
            //                NewSpecs = orderProduct.spec,
            //                ProductName = orderProduct.food_name,
            //                //ShopPrice = orderProduct.price,
            //                BoxNum = orderProduct.box_num,
            //                BoxPrice = orderProduct.box_price,
            //                CartId = orderProduct.cart_id,
            //                FoodProperty = orderProduct.food_property
            //            };
            //            _meiTOrderProductService.Add(mtProduct);
            //        }
            //    }

            //}
            return(Content("{\"data\":\"ok\"}"));
        }
示例#5
0
        public IActionResult OrderConfirmTest(OrderPayed model)
        {
            if (model == null || model.order_id == 0)
            {
                return(Content("{\"data\":\"model not find\"}"));
            }

            model.detail = WebUtility.UrlDecode(model.detail);
            //构建日志参数
            var meiTOrderLog = new MeiTOrderLog
            {
                OrderId               = model.order_id,
                OrderContext          = "confrim_" + WebUtility.UrlDecode(JsonConvert.SerializeObject(model)),
                OrderPoiReceiveDetail = model.poi_receive_detail,
                OrderExtras           = model.extras,
                CreateTime            = DateTime.Now
            };

            _meiTOrderLogService.Add(meiTOrderLog);
            var orderInfoExist = _meiTOrderInfoService.GetMeiTOrderInfo(model.order_id);

            //防止美团的重复推送
            if (orderInfoExist == null)
            {
                //将订单存储在数据库
                var orderInfo = new MeiTOrderInfo
                {
                    ShopId          = model.app_poi_code,
                    ShopName        = WebUtility.UrlDecode(model.wm_poi_name),
                    OrderId         = model.order_id,
                    Consignee       = WebUtility.UrlDecode(model.recipient_name),
                    Phone           = model.recipient_phone,
                    Address         = WebUtility.UrlDecode(model.recipient_address),
                    DeliverFee      = model.shipping_fee,
                    Income          = model.total,
                    OriginalPrice   = model.original_price,
                    DaySeq          = model.day_seq.ToString(),
                    PackageBagMoney = model.package_bag_money,
                    DinnersNumber   = model.dinners_number,
                    TotalPrice      = model.original_price - model.shipping_fee,
                    CreateTime      = DateTime.Now
                };
                //获取商家实收
                var shopReceive = JsonConvert.DeserializeObject <PoiReceivedDetail>(model.poi_receive_detail);
                orderInfo.WmPoiReceive = Math.Round((decimal)shopReceive.wmPoiReceiveCent / 100, 2);
                if (orderInfo.DinnersNumber > 10 || orderInfo.DinnersNumber == 0)
                {
                    orderInfo.DinnersNumber = 1;
                }

                if (model.delivery_time != 0)
                {
                    orderInfo.DeliverTime = CommonHelper.GenericTimeStamp(model.delivery_time);
                }

                orderInfo.Description = WebUtility.UrlDecode(model.caution);
                orderInfo.Status      = 2;
                orderInfo.CreatedAt   = CommonHelper.GenericTimeStamp(model.ctime);
                _meiTOrderInfoService.Add(orderInfo);

                var products = JsonConvert.DeserializeObject <List <OrderProduct> >(model.detail);

                if (products != null && products.Count > 0)
                {
                    foreach (var orderProduct in products)
                    {
                        var mtProduct = new MeiTOrderProduct
                        {
                            OrderId     = model.order_id,
                            ProductId   = orderProduct.app_food_code,
                            Price       = orderProduct.price,
                            Quantity    = orderProduct.quantity,
                            Total       = orderProduct.price * orderProduct.quantity,
                            Attributes  = orderProduct.unit,
                            NewSpecs    = orderProduct.spec,
                            ProductName = orderProduct.food_name,
                            //ShopPrice = orderProduct.price,
                            BoxNum       = orderProduct.box_num,
                            BoxPrice     = orderProduct.box_price,
                            CartId       = orderProduct.cart_id,
                            FoodProperty = orderProduct.food_property
                        };
                        _meiTOrderProductService.Add(mtProduct);
                    }
                }
            }

            return(Content("{\"data\":\"ok\"}"));
        }
示例#6
0
 private void HandleEvent(OrderPayed @event)
 {
     this.IsPayed  = true;
     this.IsClosed = true;
 }
示例#7
0
        public async void HandleToZp(OrderPayed model, List <OrderProduct> products)
        {
            var configInfo = _meiTConfigService.GetMeiTConfigByShopId(model.app_poi_code);

            if (configInfo != null && !string.IsNullOrEmpty(configInfo.Zp_ShopId))
            {
                //获取当前门店的菜品
                var cpList = _meiTProductInfoService.ListProductInfo(model.app_poi_code);
                if (cpList == null || cpList.Count == 0)
                {
                    return;
                }

                var insertData = new MeiTOrder_ZpOrder
                {
                    OrderId     = model.order_id,
                    CQ_KT_DC_TH = "自结美团",
                    Bas_text    = "自结外卖",
                    People      = model.dinners_number,
                    Cope        = model.total,
                    TotalPrice  = model.original_price - model.shipping_fee,
                    Ptdjh       = "#" + model.day_seq + "美团外卖",
                    door_id     = configInfo.Zp_ShopId,
                    door_name   = configInfo.Zp_ShopName,
                    WM_PT       = "MT",
                };
                if (model.delivery_time != 0)
                {
                    insertData.DeliverTime = CommonHelper.GenericTimeStamp(model.delivery_time);
                }

                if (products != null && products.Count > 0)
                {
                    var zpCp = "";
                    foreach (var orderProduct in products)
                    {
                        var cpInfo = cpList.FirstOrDefault(p => p.ProductName == orderProduct.food_name);
                        if (cpInfo == null || string.IsNullOrEmpty(cpInfo.Zp_ProductId))
                        {
                            continue;
                        }
                        else
                        {
                            zpCp += "<" + cpInfo.Zp_ProductId + "^" + orderProduct.quantity + "^" +
                                    orderProduct.food_property
                                    + '^' + orderProduct.price.ToString("0.00") + ">";
                        }
                    }
                    //计算餐盒费
                    var boxPrice = products.Sum(p => p.box_num * p.box_price);
                    zpCp += "<990103^" + boxPrice + "^^1.00>";
                    insertData.Eat_BM_CP     = zpCp;
                    insertData.Eat_allremark = ZpOrderRemark(model.day_seq, WebUtility.UrlDecode(model.caution));
                }

                try
                {
                    //将结果插入数据库
                    await _Conn.InsertAsync(insertData);
                }
                catch
                {
                    //直接抛掉错误
                    throw;
                }
            }
        }