Ejemplo n.º 1
0
        /// <summary>
        /// 打印订单商品
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        private List <byte[]> ProductLine(ThirdOrderProduct product, int fontSize = 1)
        {
            var left = product.Name;

            if (!string.IsNullOrEmpty(product.GetDesc()))
            {
                left += "(" + product.GetDesc() + ")";
            }
            var middle = "*" + Convert.ToDouble(product.Quantity);
            var right  = Convert.ToDouble(product.Price * product.Quantity) + "";
            var place  = string.Empty;

            for (int i = 0; i < maxRightLen - middle.Length - right.Length; i++)
            {
                place += " ";
            }
            right = middle + place + right;

            var buffer = PrinterCmdUtils.PrintLineLeftRight(left, right, fontSize: fontSize);

            return(new List <byte[]> {
                buffer
            });
        }
Ejemplo n.º 2
0
        public async Task <ThirdOrder> ElemeSaveAsync(JObject message)
        {
            var shopId  = message["shopId"].Value <long>();
            var eleme   = JObject.Parse(message["message"].Value <string>());
            var orderId = eleme["id"].Value <string>();

            if (await Context.ThirdOrders.CountAsync(a => a.OrderId == orderId) > 0)
            {
                return(null);                                                                       // 如果已存在该订单,则业务终止
            }
            var business = await Context.Businesses.FirstOrDefaultAsync(a => a.Eleme_Poi_Id == shopId);

            if (business == null)
            {
                return(null);
            }

            var phone = eleme["phoneList"]?.FirstOrDefault();
            var geo   = eleme["deliveryGeo"].Value <string>().Split(',');

            var order = new ThirdOrder
            {
                OrderId            = eleme["id"].Value <string>(),
                PoiCode            = eleme["shopId"].ToString(),
                PoiName            = eleme["shopName"].Value <string>(),
                RecipientName      = eleme["consignee"].Value <string>(),
                RecipientAddress   = eleme["address"].Value <string>(),
                RecipientPhone     = phone?.Value <string>(),
                ShippingFee        = eleme["deliverFee"].Value <double>(),
                PackageFee         = eleme["packageFee"].Value <double>(),
                Amount             = eleme["totalPrice"].Value <double>(),
                OriginalAmount     = eleme["originalPrice"].Value <double>(),
                Caution            = eleme["description"].Value <string>(),
                InvoiceTitle       = eleme["invoice"].Value <string>(),
                TaxpayerId         = eleme["taxpayerId"].Value <string>(),
                Ctime              = eleme["createdAt"].Value <DateTime>(),
                DeliveryTime       = eleme["deliverTime"].Value <DateTime?>(),
                Longitude          = Convert.ToDouble(geo[0]),
                Latitude           = Convert.ToDouble(geo[1]),
                DaySeq             = eleme["daySn"].Value <int>(),
                Status             = OrderStatus.Payed,
                OrderSource        = 1,
                BusinessId         = business.ID,
                ThirdOrderProducts = new List <ThirdOrderProduct>()
            };
            // 订单商品
            var detail    = eleme["groups"];
            var cardIndex = 1;

            foreach (var box in detail)
            {
                foreach (var p in box["items"])
                {
                    var product = new ThirdOrderProduct
                    {
                        Code        = p["vfoodId"].ToString(),
                        Name        = p["name"].Value <string>(),
                        SkuId       = p["skuId"].ToString(),
                        Quantity    = p["quantity"].Value <int>(),
                        Price       = p["price"].Value <double>(),
                        Spec        = string.Join(',', p["newSpecs"].Select(a => a["value"].ToString())),
                        Description = string.Join(',', p["attributes"].Select(a => a["value"].ToString())),
                        //Discount = Math.Round(p["price"].Value<double>() / p["shopPrice"].Value<double>(), 2),
                        Discount = 1,
                        CartId   = cardIndex
                    };
                    order.ThirdOrderProducts.Add(product);
                }
                cardIndex++;
            }
            var codes    = order.ThirdOrderProducts.Select(a => a.Code).ToList();       // 饿了么使用商品id匹配
            var mappings = await Context.ThirdProductMappings.Where(a => a.ThirdSource == 1 && a.BusinessId == order.BusinessId && codes.Contains(a.ThirdProductId)).ToListAsync();

            order.ThirdOrderProducts.ForEach(item =>
            {
                var mapping = mappings.FirstOrDefault(a => a.ThirdProductId == item.Code);
                if (mapping == null)
                {
                    return;
                }
                item.ProductId = mapping.ProductId;
            });
            // 活动信息
            var activities = eleme["orderActivities"];

            if (activities.HasValues && activities.Count() > 0)
            {
                order.ThirdOrderActivities = new List <ThirdOrderActivity>();
                foreach (var item in activities)
                {
                    var activity = new ThirdOrderActivity
                    {
                        ActiveId    = item["metaId"].Value <int>(),
                        ReduceFee   = item["amount"].Value <double>(),
                        ThirdCharge = item["elemePart"].Value <double>() + item["familyPart"].Value <double>(),
                        PoiCharge   = item["restaurantPart"].Value <double>(),
                        Remark      = item["name"].Value <string>()
                    };
                    order.ThirdOrderActivities.Add(activity);
                }
            }
            await Context.AddAsync(order);

            await Context.SaveChangesAsync();

            return(order);
        }