Exemple #1
0
        public async Task RecordLog(Log.LogProgram program, Log.LogLevel level, string message, string detail = null)
        {
            Log log = new Log {
                Program = program,
                Level   = level,
                Message = message,
                Detail  = detail
            };

            ctx.Logs.Add(log);
            await ctx.SaveChangesAsync();
        }
Exemple #2
0
        private async Task changeCustomerPoints(Dine dine)
        {
            // 用户总平台消费金额
            var  yummyonlineCtx = new YummyOnlineContext();
            User user           = await yummyonlineCtx.Users.FirstOrDefaultAsync(p => p.Id == dine.UserId);

            if (user == null)
            {
                return;
            }
            user.Price += dine.Price;
            await yummyonlineCtx.SaveChangesAsync();

            Customer customer = await ctx.Customers.FirstOrDefaultAsync(p => p.Id == dine.UserId);

            // 如果用户不存在或者是匿名用户
            if (customer == null || await new UserManager().IsInRoleAsync(dine.UserId, Role.Nemo))
            {
                return;
            }
            // 如果使用的积分支付
            DinePaidDetail pointsPaidDetail = await ctx.DinePaidDetails.FirstOrDefaultAsync(p => p.Dine.Id == dine.Id && p.PayKind.Type == PayKindType.Points);

            if (pointsPaidDetail != null)
            {
                HotelConfig config = await ctx.HotelConfigs.FirstOrDefaultAsync();

                customer.Points -= Convert.ToInt32((double)pointsPaidDetail.Price / config.PointsRatio);
            }
            // 用户点过的菜品增加积分
            List <DineMenu> dineMenus = await ctx.DineMenus.Include(p => p.Menu.MenuPrice).Where(p => p.Dine.Id == dine.Id).ToListAsync();

            dineMenus?.ForEach(m => {
                customer.Points += m.Menu.MenuPrice.Points * m.Count;
            });
        }