コード例 #1
0
        public APIResult Add([FromBody] AddArgsModel args)
        {
            if (!args.ShopId.HasValue)
            {
                throw new ArgumentNullException("ShopId");
            }
            CheckShopActor(args.ShopId.Value, ShopActorType.超级管理员);

            //获取并验证店铺是否存在
            var shop = db.GetSingle <Shop>(args.ShopId.Value);

            if (shop == null)
            {
                throw new Exception("指定的商铺不存在");
            }

            //这里只是添加一个库存纪录,库存的参数在编辑处修改
            var model = new ShopCallingQueueProduct()
            {
                Shop   = shop,
                Status = ShopCallingQueueProductStatus.正常,
                Title  = args.Title,
                Name   = args.Name,
                Detail = args.Detail
            };

            db.Add <ShopCallingQueueProduct>(model);
            db.SaveChanges();

            return(Success());
        }
コード例 #2
0
        public APIResult Add([FromBody] AddArgsModel args)
        {
            //获取并验证店铺是否存在
            var shop = db.GetSingle <Shop>(args.ShopId);

            if (shop == null)
            {
                throw new Exception("指定的商铺不存在");
            }

            //这里只是添加一个库存纪录,库存的参数在编辑处修改
            var model = new ShopCallingQueueProduct()
            {
                Shop   = shop,
                Status = ShopCallingQueueProductStatus.正常,
                Title  = args.Title,
                Detail = args.Detail
            };

            db.Add <ShopCallingQueueProduct>(model);
            db.SaveChanges();

            return(Success());
        }
コード例 #3
0
        public APIResult Add([FromBody] AddArgsModel args)
        {
            //需要判定是否已经开放叫号
            var flag   = ShopCallingQueue.GetShopOpenStatusFlag(args.ShopId);
            var isOpen = db.GetSettingValue <bool>(flag);

            if (!isOpen)
            {
                throw new Exception("还未开放叫号,请等待");
            }

            ShopCallingQueueProduct product = null;

            if (args.ProductId.HasValue)
            {
                product = db.Query <ShopCallingQueueProduct>()
                          .Where(m => !m.IsDel)
                          .Where(m => m.Status == ShopCallingQueueProductStatus.正常)
                          .Where(m => m.Id == args.ProductId && m.ShopId == args.ShopId)
                          .FirstOrDefault();

                if (product == null)
                {
                    throw new Exception("指定的人数设定不存在或者未开放");
                }
                args.Title = product.Title;
            }

            var memberId = GetMemberId();
            var isExit   = db.Query <ShopCallingQueue>()
                           .Where(m => !m.IsDel)
                           .Where(m => m.MemberId == memberId)
                           .Where(m => m.ShopId == args.ShopId)
                           .Where(m => !m.IsUsed)
                           .Where(m => m.Status != ShopCallingQueueStatus.取消)
                           .Where(m => m.Status != ShopCallingQueueStatus.确认失败)
                           .Where(m => DateTime.Now.Date.Equals(m.AddTime.Date))
                           .Count() > 0;

            if (isExit)
            {
                throw new Exception("你已经在排队中,如果想重新排队,需要先取消");
            }

            var startTime = DateTime.Today;
            var endTime   = startTime.AddDays(1);

            var model = new ShopCallingQueue()
            {
                AddTime       = DateTime.Now,
                CanShareTable = args.CanShareTable,
                MemberId      = memberId,
                ProductId     = args.ProductId,
                ShopId        = args.ShopId,
                Title         = args.Title,
                Status        = product == null ? ShopCallingQueueStatus.待确认 : ShopCallingQueueStatus.确认成功
            };

            lock (lockAddObject)
            {//锁定,用于保证每次生成的QueueNumber都是唯一的
                var count = db.Query <ShopCallingQueue>()
                            .Where(m => m.AddTime >= startTime && m.AddTime < endTime)
                            .Count();
                count++; //增加1,否则开始是从0开始
                model.QueueIndex  = count;
                model.QueueNumber = count;

                db.AddTo <ShopCallingQueue>(model);
                db.SaveChanges();
            }
            return(Success(model));
        }