Exemplo n.º 1
0
        public APIResult GetShopOpenStatus([FromBody] IdArgsModel args)
        {
            var flag = ShopCallingQueue.GetShopOpenStatusFlag(args.Id);
            var v    = db.GetSettingValue <bool>(flag);

            return(Success(v));
        }
Exemplo n.º 2
0
        public async System.Threading.Tasks.Task <APIResult> SetShopOpenStatus([FromBody] SetShopOpenStatusArgsModel args)
        {
            var flag = ShopCallingQueue.GetShopOpenStatusFlag(args.Id);

            db.SetSettingValue(flag, args.IsOpen.ToString());
            await db.SaveChangesAsync();

            return(Success());
        }
Exemplo n.º 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));
        }