예제 #1
0
        public IActionResult SetProductStock(SeckillPo seckillPo)
        {
            // 1、查询秒杀库存
            Seckill seckill = SeckillService.GetSeckillByProductId(seckillPo.ProductId);

            // 2、判断秒杀库存是否完成
            if (seckill.SeckillStock <= 0)
            {
                throw new BizException("秒杀库存完了");
            }

            // 3、扣减秒杀库存
            seckill.SeckillStock = seckill.SeckillStock - seckillPo.ProductCount;

            // 4、更新秒杀库存
            SeckillService.Update(seckill);
            return(Ok("更新库存成功"));
        }
예제 #2
0
        public IActionResult SetProductStock(SeckillPo seckillPo)
        {
            //1.查询秒杀库存
            Seckill seckill = _seckillService.GetSeckillByProductId(seckillPo.ProductId);

            //2.判断秒杀库存是否完成
            if (seckill.SeckillStock <= 0)
            {
                throw new BizException("秒杀库存完了");
            }
            if (seckill.SeckillStock <= seckillPo.ProductCount)
            {
                throw new BizException($"秒杀库存不足{seckillPo.ProductCount}个");
            }
            //3.扣减库存
            seckill.SeckillStock -= seckillPo.ProductCount;
            //4.更新秒杀库存
            _seckillService.Update(seckill);
            return(Ok("更新库存成功"));
        }
예제 #3
0
        public IActionResult PutProductStock(SeckillPo seckillPo)
        {
            // 1、查询秒杀库存
            Seckill seckill = SeckillService.GetSeckillByProductId(seckillPo.ProductId);

            // 2、判断秒杀库存是否完成
            if (seckill.SeckillStock <= 0)
            {
                throw new BizException("秒杀库存完了");
            }

            // 3、扣减秒杀库存
            seckill.SeckillStock = seckill.SeckillStock - seckillPo.ProductCount;

            // 4、更新秒杀库存
            SeckillService.Update(seckill);

            // 5、seckill 转换成为Dto对象seckill
            // SeckillDto seckillDto = AutoMapperHelper.AutoMapTo<SeckillDto>(seckill);
            return(Ok("更新库存成功"));
        }