コード例 #1
0
        /// <summary>
        /// 制作饮品回调
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public ResponseData <string> MakeCallBack(MakeDrinkReq req)
        {
            var result = new ResponseData <string> {
                Code    = "0",
                Data    = "成功",
                Message = "成功",
                Success = true
            };
            var context   = new CoffeeOrderContext();
            var materials = JsonConvert.SerializeObject(req.Drink.Materials);
            var ordDetail = context.BM_COFFEE_DETAIL.Where(o => o.ORDER_ID == req.OrderId && o.COFFEE_TYPE == req.Drink.Value && o.MATERIALS == materials).FirstOrDefault();

            ordDetail.ISSUED += req.Drink.Number;
            context.SaveChanges();
            //判断是否已出完咖啡
            var ordDetailList = context.BM_COFFEE_DETAIL.Where(o => o.ORDER_ID == req.OrderId).ToList();

            if (ordDetailList.Sum(o => o.QUANTITY) == ordDetailList.Sum(o => o.ISSUED))
            {
                FinishCallBack(req.OrderId);
            }
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// 创建订单
        /// </summary>
        /// <param name="ord"></param>
        /// <returns></returns>
        public OrderGroupResult CreateOrder(CoffeeOrder ord)
        {
            if (ord == null)
            {
                throw new ArgumentNullException("order");
            }
            var    s             = new OrderManager();
            string orderDescribe = "";
            //验证产品单价
            var list       = ObjectXmlSerializer.LoadFromXml <List <CoffeeInit> >(System.Web.HttpContext.Current.Server.MapPath("~/cache/Coffee.xml"));
            var ordDetails = ord.DrinkList.GroupBy(o => o.Value).Select(o => (new Drink()
            {
                Name = o.Min(item => item.Name),
                Value = o.Key,
                Number = o.Sum(item => item.Number),
                Price = o.Sum(item => item.Number * item.Price),
                Materials = null
            }));

            foreach (var item in ordDetails)
            {
                if (item.Price != list[0].DrinkList.Find(o => o.Value == item.Value).Price *item.Number)
                {
                    throw new Exception("产品单价有误!");
                }
                orderDescribe  = orderDescribe == "" ? orderDescribe : orderDescribe + "@#";
                orderDescribe += String.Format("名称:{0}@#金额:{1}元@#数量:{2}", item.Name, item.Price, item.Number);
            }
            //验证订单金额金额
            if (ord.TotalAmount != ord.DrinkList.Sum(o => o.Price * o.Number) + ord.Fee)
            {
                throw new Exception("订单金额有误!");
            }
            var orderinfo = new OrderInfo
            {
                memberId      = ord.MemberId,
                message       = "",
                orderAmount   = ord.Amount.ToString(CultureInfo.InvariantCulture),
                orderDescribe = orderDescribe,
                orderFrom     = ord.OrderFrom.ToString(),
                orderType     = OrderType.ToString(),
                storeId       = this.GetStoreInfo().StoreId,
                storeName     = this.GetStoreInfo().StoreName,
                totalAmount   = (ord.TotalAmount).ToString(CultureInfo.InvariantCulture),
                orderEtm      = ord.OrderETMID,
                deleiveryFee  = ord.Fee,
                memberName    = ord.MemberName
            };
            var mresult = s.CreateOrder(orderinfo);

            Logger.Write(Log.Log_Type.Info, string.Format("主订单创建成功,order={0}", JsonConvert.SerializeObject(mresult)));
            var context = new CoffeeOrderContext();

            for (int i = 0; i < ord.DrinkList.Count; i++)
            {
                var item         = ord.DrinkList[i];
                var coffeeDetail = new BM_COFFEE_DETAIL()
                {
                    ORDER_ID        = mresult.dataMap.orderId,
                    ID              = mresult.dataMap.orderId + i.ToString(),
                    ADD_FEE         = 0,
                    AMOUNT          = item.Number * item.Price,
                    CAPACITY        = item.Capacity,
                    COFFEE_TYPE     = item.Value,
                    COFFEE_TYPENAME = item.Name,
                    CREATE_DATE     = DateTime.Now,
                    PRICE           = item.Price,
                    DESCRIPTION     = "",
                    QUANTITY        = item.Number,
                    TOTAL           = item.Number * item.Price,
                    MATERIALS       = JsonConvert.SerializeObject(item.Materials),
                    ISSUED          = 0
                };
                Logger.Write(Log.Log_Type.Info, string.Format("订单详情,Detail={0}", JsonConvert.SerializeObject(coffeeDetail)));
                context.BM_COFFEE_DETAIL.Add(coffeeDetail);
            }
            context.SaveChanges();
            OrderGroupResult result = new OrderGroupResult();

            result.GroupId = mresult.dataMap.orderId;
            result.Items   = new List <OrderItemResult>();
            result.Items.Add(new OrderItemResult()
            {
                Amount    = ord.TotalAmount,
                ItemName  = orderinfo.orderDescribe,
                OrderId   = mresult.dataMap.orderId,
                Qty       = ord.Quantity,
                StoreId   = orderinfo.storeId,
                StoreName = orderinfo.storeName
            });
            result.TotalAmount = ord.TotalAmount;
            return(result);
        }