Example #1
0
        /// <summary>
        /// 获取2两小时内的订单
        /// </summary>
        /// <returns></returns>
        public Domain.Dinner.OrderModel Get_CurrentOrder()
        {
            using (DbRepository entities = new DbRepository())
            {
                var    user   = CookieHelper.GetCurrentWxUser();
                string shopId = CookieHelper.GetCurrentShopId();
                if (user == null)
                {
                    return(null);
                }
                if (!shopId.IsNotNullOrEmpty())
                {
                    return(null);
                }

                var model = new Domain.Dinner.OrderModel();
                //2小时有效订单
                var limitTime = DateTime.Now.AddHours(-2);
                var order     = entities.DinnerOrder.OrderByDescending(x => x.CreatedTime).FirstOrDefault(x => x.OpenId.Equals(user.openid) && x.ShopId.Equals(shopId) && x.CreatedTime > limitTime);

                if (order != null)
                {
                    model.Order   = order;
                    model.Details = entities.OrderDetails.Where(x => x.OrderId.Equals(order.UNID)).ToList();
                    model.Remark  = model.Order.Remark;
                }

                return(model);
            }
        }
Example #2
0
        /// <summary>
        /// 增加订单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public string Add_DinnerOrder(string info)
        {
            if (!info.IsNotNullOrEmpty()
                )
            {
                return("数据为空");
            }
            using (DbRepository entities = new DbRepository())
            {
                var model = info.DeserializeJson <Domain.Dinner.OrderModel>();

                var    user   = CookieHelper.GetCurrentWxUser();
                string shopId = CookieHelper.GetCurrentShopId();
                if (user == null)
                {
                    return("微信授权过期");
                }
                if (!shopId.IsNotNullOrEmpty())
                {
                    return("店铺不存在");
                }
                var addEntity = new DinnerOrder();
                addEntity.UNID    = Guid.NewGuid().ToString("N");
                addEntity.OpenId  = user.openid;
                addEntity.Details = "";

                decimal totalPrice = 0;
                model.Details.ForEach(x => {
                    entities.OrderDetails.Add(new OrderDetails()
                    {
                        UNID     = Guid.NewGuid().ToString("N"),
                        DishId   = x.DishId,
                        DishName = x.DishName,
                        Number   = x.Number,
                        OrderId  = addEntity.UNID,
                        Price    = x.Price,
                    });
                    totalPrice       += (x.Price * x.Number);
                    addEntity.Details = string.Format("{0} {1}X{2}份 ", addEntity.Details, x.DishName, x.Number);
                });
                addEntity.OrderNum    = string.Format("DC{0}-{1}", DateTime.Now.ToString("yyMMddhhmmss"), addEntity.UNID.SubString(4));
                addEntity.TotalPrice  = totalPrice;
                addEntity.CreatedTime = DateTime.Now;
                addEntity.UpdatedTime = DateTime.Now;
                addEntity.State       = (int)DinnerOrderState.Audting;
                addEntity.ShopId      = shopId;
                addEntity.Remark      = model.Remark;

                entities.DinnerOrder.Add(addEntity);
                return(entities.SaveChanges() > 0 ? "" : "保存出错");
            }
        }