public async Task <UserRecommendTreeDTO> GetModelTreeByMobileAsync(string mobile) { using (MyDbContext dbc = new MyDbContext()) { var user = await dbc.GetAll <UserEntity>().AsNoTracking().FirstOrDefaultAsync(u => u.Mobile == mobile); if (user == null) { return(null); } return(ToDTO(user, user.MLevelId)); } }
public async Task <PlatformUserDTO> GetModelAsync(long id) { using (MyDbContext dbc = new MyDbContext()) { var user = await dbc.GetAll <PlatformUserEntity>().SingleOrDefaultAsync(p => p.Id == id); if (user == null) { return(null); } return(ToDTO(user)); } }
public async Task <LinkDTO> GetModelByIdAsync(long id) { using (MyDbContext dbc = new MyDbContext()) { LinkEntity entity = await dbc.GetAll <LinkEntity>().SingleOrDefaultAsync(p => p.Id == id); if (entity == null) { return(null); } return(ToDTO(entity)); } }
public async Task <long?> GetIdByDescAsync(string description) { using (MyDbContext dbc = new MyDbContext()) { var type = await dbc.GetAll <JournalTypeEntity>().SingleOrDefaultAsync(j => j.Description == description); if (type == null) { return(null); } return(type.Id); } }
public async Task <BonusDTO> GetModelAsync(long id) { using (MyDbContext dbc = new MyDbContext()) { var entity = await dbc.GetAll <BonusEntity>().AsNoTracking().SingleOrDefaultAsync(a => a.Id == id); if (entity == null) { return(null); } return(ToDTO(entity)); } }
public async Task <SettingDTO> GetModelByNameAsync(string name) { using (MyDbContext dbc = new MyDbContext()) { SettingEntity entity = await dbc.GetAll <SettingEntity>().Include(s => s.SettingType).AsNoTracking().SingleOrDefaultAsync(g => g.Name == name); if (entity == null) { return(null); } return(ToDTO(entity)); } }
public async Task <UserAccountDTO> GetDefaultModelAsync(long userId) { using (MyDbContext dbc = new MyDbContext()) { var entity = await dbc.GetAll <UserAccountEntity>().AsNoTracking().SingleOrDefaultAsync(a => a.UserId == userId); if (entity == null) { return(null); } return(ToDTO(entity)); } }
public async Task <IdNameDTO> GetByNameAsync(string name) { using (MyDbContext dbc = new MyDbContext()) { var entitiy = await dbc.GetAll <IdNameEntity>().AsNoTracking().SingleOrDefaultAsync(i => i.Name == name); if (entitiy == null) { return(null); } return(ToDTO(entitiy)); } }
public async Task <GoodsSecondTypeDTO> GetModelAsync(long id) { using (MyDbContext dbc = new MyDbContext()) { GoodsSecondTypeEntity entity = await dbc.GetAll <GoodsSecondTypeEntity>().AsNoTracking().SingleOrDefaultAsync(g => g.Id == id); if (entity == null) { return(null); } return(ToDTO(entity)); } }
public async Task <UserDTO> GetModelAsync(long id) { using (MyDbContext dbc = new MyDbContext()) { UserEntity entity = await dbc.GetAll <UserEntity>().AsNoTracking().SingleOrDefaultAsync(u => u.Id == id); if (entity == null) { return(null); } return(ToDTO(entity)); } }
public async Task <UserDTO> GetModelByUserCodeAsync(string userCode) { using (MyDbContext dbc = new MyDbContext()) { var user = await dbc.GetAll <UserEntity>().AsNoTracking().Where(u => u.IsNull == false).SingleOrDefaultAsync(u => u.UserCode == userCode); if (user == null) { return(null); } return(ToDTO(user)); } }
public long Add() { using (MyDbContext dbc = new MyDbContext()) { if (dbc.GetAll <StatEntity>().AsNoTracking().Any()) { return(-1); } var typeList = MyEnumHelper.GetEnumList <TypeEnum>(); var itemList = MyEnumHelper.GetEnumList <ItemEnum>(); StatEntity entity; foreach (var type in typeList) { if (type.Id <= 3) { var items = itemList.Where(i => i.Id < 10); foreach (var item in items) { entity = new StatEntity(); entity.ItemId = item.Id; entity.TypeId = type.Id; dbc.Stats.Add(entity); } } if (type.Id == 4) { var items = itemList.Where(i => i.Id >= 10 && i.Id < 20); foreach (var item in items) { entity = new StatEntity(); entity.ItemId = item.Id; entity.TypeId = type.Id; dbc.Stats.Add(entity); } } if (type.Id == 5) { var items = itemList.Where(i => i.Id > 20); foreach (var item in items) { entity = new StatEntity(); entity.ItemId = item.Id; entity.TypeId = type.Id; dbc.Stats.Add(entity); } } } dbc.SaveChanges(); return(1); } }
public async Task <long> ConfirmAsync(long id, long adminId) { using (MyDbContext dbc = new MyDbContext()) { TakeCashEntity takeCash = await dbc.GetAll <TakeCashEntity>().SingleOrDefaultAsync(t => t.Id == id); if (takeCash == null) { return(-1); } UserEntity user = await dbc.GetAll <UserEntity>().SingleOrDefaultAsync(u => u.Id == takeCash.UserId); if (user == null) { return(-2); } if (takeCash.Amount > user.Amount) { return(-3); } user.Amount = user.Amount - takeCash.Amount; takeCash.StateId = (int)TakeCashStateEnum.已结款; takeCash.AdminMobile = (await dbc.GetAll <AdminEntity>().SingleOrDefaultAsync(a => a.Id == adminId)).Mobile; JournalEntity journal = new JournalEntity(); journal.UserId = user.Id; journal.BalanceAmount = user.Amount; journal.OutAmount = takeCash.Amount; journal.Remark = "用户(" + user.Mobile + ")提现"; journal.JournalTypeId = (int)JournalTypeEnum.佣金提现; //journal.OrderCode = order.Code; //journal.GoodsId = order.Id;//来至订单ID journal.CurrencyType = 1;//币种,只有rmb dbc.Journals.Add(journal); await dbc.SaveChangesAsync(); return(takeCash.Id); } }
public async Task <UserDTO> GetModelByMobileAsync(string mobile) { using (MyDbContext dbc = new MyDbContext()) { UserSearchResult result = new UserSearchResult(); var user = await dbc.GetAll <UserEntity>().AsNoTracking().FirstOrDefaultAsync(u => u.Mobile == mobile); if (user == null) { return(null); } return(ToDTO(user)); } }
public async Task <GoodsImgDTO[]> GetModelListAsync(long?goodsId) { using (MyDbContext dbc = new MyDbContext()) { var entities = dbc.GetAll <GoodsImgEntity>().AsNoTracking(); if (goodsId != null) { entities = entities.Where(a => a.GoodsId == goodsId); } var res = await entities.ToListAsync(); return(res.Select(g => ToDTO(g)).ToArray()); } }
public async Task <LinkDTO[]> GetModelListEnableAsync(int?typeId) { using (MyDbContext dbc = new MyDbContext()) { var entities = dbc.GetAll <LinkEntity>().AsNoTracking().Where(p => p.Enabled == 1); if (typeId != null) { entities = entities.Where(e => e.TypeId == typeId); } var idNames = await entities.OrderBy(p => p.Sort).ToListAsync(); return(idNames.Select(p => ToDTO(p)).ToArray()); } }
/// <summary> /// 递归获取线下会员id /// </summary> /// <param name="dbc"></param> /// <param name="id"></param> /// <returns></returns> private async Task <List <long> > GetUserIdsAsync(MyDbContext dbc, long id) { List <long> ids = await dbc.GetAll <UserEntity>().Where(u => u.RecommendId == id).Select(u => u.Id).ToListAsync(); items.AddRange(ids); if (ids.LongCount() > 0) { foreach (long item in ids) { return(await GetUserIdsAsync(dbc, item)); } } return(items); }
public async Task <SettingDTO[]> GetModelListAsync(long[] settingTypeIds) { using (MyDbContext dbc = new MyDbContext()) { var entities = dbc.GetAll <SettingEntity>().Include(s => s.SettingType).AsNoTracking(); if (settingTypeIds.Count() > 0) { entities = entities.Where(a => settingTypeIds.Contains(a.SettingTypeId)); } var settingsResult = await entities.ToListAsync(); return(settingsResult.Select(a => ToDTO(a)).ToArray()); } }
public async Task <UserSearchResult> GetActivateListAsync(int pageIndex, int pageSize) { using (MyDbContext dbc = new MyDbContext()) { UserSearchResult result = new UserSearchResult(); var users = dbc.GetAll <UserEntity>().AsNoTracking().Where(u => u.IsUpgraded == false); result.PageCount = (int)Math.Ceiling((await users.LongCountAsync()) * 1.0f / pageSize); var userResult = await users.OrderByDescending(a => a.CreateTime).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToListAsync(); result.Users = userResult.Select(a => ToDTO(a)).ToArray(); return(result); } }
public bool Del(long id) { using (MyDbContext dbc = new MyDbContext()) { StatEntity entity = dbc.GetAll <StatEntity>().SingleOrDefault(g => g.Id == id); if (entity == null) { return(false); } entity.IsDeleted = true; dbc.SaveChanges(); return(true); } }
public async Task <long> AddAsync(long userId, long payTypeId, decimal amount, string descripton, string partner_trade_no, string payment_no, DateTime payment_time) { using (MyDbContext dbc = new MyDbContext()) { UserEntity user = await dbc.GetAll <UserEntity>().SingleOrDefaultAsync(u => u.Id == userId); if (user == null) { return(-1); } if (user.Amount < amount) { return(-2); } //if(user.Level.Name=="普通会员") //{ // return -4; //} TakeCashEntity entity = new TakeCashEntity(); entity.UserId = userId; entity.PayTypeId = payTypeId; var stateId = await dbc.GetIdAsync <IdNameEntity>(i => i.Name == "已结款"); if (stateId == 0) { return(-3); } entity.StateId = stateId; entity.Amount = amount; entity.Description = descripton; entity.partner_trade_no = partner_trade_no; entity.payment_no = payment_no; entity.payment_time = payment_time; dbc.TakeCashes.Add(entity); user.Amount -= amount; JournalEntity journal = new JournalEntity(); journal.OutAmount = amount; journal.JournalTypeId = 1; journal.Remark = "余额提现"; journal.UserId = userId; journal.BalanceAmount = user.Amount; journal.OrderCode = payment_no; dbc.Journals.Add(journal); await dbc.SaveChangesAsync(); return(entity.Id); } }
public async Task <bool> UpdateAsync(long id, string mobile, string description, string password, long[] permissionIds) { using (MyDbContext dbc = new MyDbContext()) { var entity = await dbc.GetAll <AdminEntity>().SingleOrDefaultAsync(a => a.Id == id); if (entity == null) { return(false); } entity.Mobile = mobile; entity.Description = description; entity.Password = CommonHelper.GetMD5(password + entity.Salt); entity.Permissions.Clear(); var perms = dbc.GetAll <PermissionEntity>().Where(p => permissionIds.Contains(p.Id)); await perms.ForEachAsync(p => entity.Permissions.Add(p)); await dbc.SaveChangesAsync(); return(true); } }
public async Task <long> ValidOrder(long id) { using (MyDbContext dbc = new MyDbContext()) { OrderEntity order = await dbc.GetAll <OrderEntity>().SingleOrDefaultAsync(o => o.Id == id); if (order == null) { return(-1); } UserEntity user = await dbc.GetAll <UserEntity>().SingleOrDefaultAsync(u => u.Id == order.BuyerId); if (user == null) { return(-2); } var orderlists = dbc.GetAll <OrderListEntity>().Where(o => o.OrderId == order.Id).ToList(); foreach (var orderlist in orderlists) { GoodsEntity goods = await dbc.GetAll <GoodsEntity>().SingleOrDefaultAsync(g => g.Id == orderlist.GoodsId); if (goods == null) { continue; } if (!goods.IsPutaway) { return(-4); } if (goods.Inventory < orderlist.Number) { return(-3); } } return(1); } }
public async Task <TakeCashSearchResult> GetModelListAsync(long?stateId, string mobile, DateTime?startTime, DateTime?endTime, int pageIndex, int pageSize) { using (MyDbContext dbc = new MyDbContext()) { TakeCashSearchResult result = new TakeCashSearchResult(); var entities = dbc.GetAll <TakeCashEntity>(); if (stateId != null) { entities = entities.Where(t => t.StateId == stateId); } if (!string.IsNullOrEmpty(mobile)) { entities = entities.Where(t => t.PlatformUser.Mobile.Contains(mobile)); } if (startTime != null) { entities = entities.Where(t => t.CreateTime >= startTime); } if (endTime != null) { entities = entities.Where(a => a.CreateTime.Year <= endTime.Value.Year && a.CreateTime.Month <= endTime.Value.Month && a.CreateTime.Day <= endTime.Value.Day); } long givingIntegralId = dbc.GetAll <IntegralTypeEntity>().SingleOrDefault(i => i.Name == "商家积分").Id; long useIntegralId = dbc.GetAll <IntegralTypeEntity>().SingleOrDefault(i => i.Name == "消费积分").Id; long sId = dbc.GetAll <StateEntity>().SingleOrDefault(s => s.Name == "已转账").Id; result.TotalCount = await entities.LongCountAsync(); result.GivingIntegralCount = await entities.Where(t => t.IntegralTypeId == givingIntegralId && t.StateId == sId).SumAsync(t => t.Integral); result.UseIntegralCount = await entities.Where(t => t.IntegralTypeId == useIntegralId && t.StateId == sId).SumAsync(t => t.Integral); var res = await entities.OrderByDescending(t => t.CreateTime).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToListAsync(); result.TakeCashes = res.Select(t => ToDTO(t)).ToArray(); return(result); } }
public async Task <long> AddAsync(long userId, decimal amount) { using (MyDbContext dbc = new MyDbContext()) { UserEntity user = await dbc.GetAll <UserEntity>().SingleOrDefaultAsync(u => u.Id == userId); if (user == null) { return(-1); } if (user.BonusAmount < amount) { return(-2); } TransferEntity entity = new TransferEntity(); entity.UserId = userId; entity.ChangeType = 1; entity.Amount = amount; dbc.Transfer.Add(entity); user.BonusAmount -= amount; user.Amount += amount; int JournalTypeId = 1; JournalEntity journal = new JournalEntity(); journal.OutAmount = amount; journal.InAmount = 0; journal.JournalTypeId = JournalTypeId; journal.Remark = "A积分转换B积分"; journal.UserId = userId; journal.CurrencyType = 1; journal.BalanceAmount = user.BonusAmount; dbc.Journals.Add(journal); JournalEntity journalInfo = new JournalEntity(); journalInfo.OutAmount = 0; journalInfo.InAmount = amount; journalInfo.JournalTypeId = JournalTypeId; journalInfo.Remark = "A积分转换B积分"; journalInfo.UserId = userId; journalInfo.CurrencyType = 2; journalInfo.BalanceAmount = user.Amount; dbc.Journals.Add(journalInfo); await dbc.SaveChangesAsync(); return(entity.Id); } }
public async Task <long> AddAsync(long userId, long payTypeId, decimal amount, string descripton) { using (MyDbContext dbc = new MyDbContext()) { UserEntity user = await dbc.GetAll <UserEntity>().SingleOrDefaultAsync(u => u.Id == userId); if (user == null) { return(-1); } if (user.Amount < amount) { return(-2); } if (string.IsNullOrEmpty(user.Mobile)) { return(-4); } TakeCashEntity takeCash = new TakeCashEntity(); takeCash.UserId = userId; takeCash.TypeId = payTypeId; var stateId = await dbc.GetIdAsync <IdNameEntity>(i => i.Name == "未结款"); if (stateId == 0) { return(-3); } takeCash.StateId = stateId; takeCash.Amount = amount; takeCash.Description = descripton; dbc.TakeCashes.Add(takeCash); await dbc.SaveChangesAsync(); user.Amount = user.Amount - takeCash.Amount; JournalEntity journal = new JournalEntity(); journal.OutAmount = takeCash.Amount; journal.JournalTypeId = await dbc.GetIdAsync <IdNameEntity>(i => i.Name == "余额提现中"); journal.Remark = "余额提现"; journal.UserId = takeCash.UserId; journal.BalanceAmount = user.Amount; journal.Journal01 = takeCash.Id; dbc.Journals.Add(journal); await dbc.SaveChangesAsync(); return(takeCash.Id); } }
public async Task <bool> FrozenAsync(long id) { using (MyDbContext dbc = new MyDbContext()) { var entity = await dbc.GetAll <AdminEntity>().SingleOrDefaultAsync(a => a.Id == id); if (entity == null) { return(false); } var platformUser = await dbc.GetAll <PlatformUserEntity>().SingleOrDefaultAsync(p => p.Mobile == entity.Mobile); if (platformUser == null) { return(false); } platformUser.IsEnabled = !platformUser.IsEnabled; entity.IsEnabled = !entity.IsEnabled; await dbc.SaveChangesAsync(); return(true); } }
/// <summary> /// /// </summary> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public async Task <CashHallSearchResult> GetListAsync(int accountType, int pageIndex, int pageSize) { using (MyDbContext dbc = new MyDbContext()) { CashHallSearchResult result = new CashHallSearchResult(); var buyEntity = dbc.GetAll <CashBuyEntity>().AsNoTracking() .Where(w => w.StateType == 0 && w.BalanceNum > 0 && w.CurrencyType == accountType) .Select(s => new CashHallDTO { TradeId = s.Id, TradeType = 1, TradeName = "买入积分", Num = s.BalanceNum, Amount = s.Amount, Price = s.Price, CreateTime = s.CreateTime, CurrencyType = s.CurrencyType }); var sellEntity = dbc.GetAll <CashSellEntity>().AsNoTracking() .Where(w => w.StateType == 0 && w.BalanceNum > 0 && w.CurrencyType == accountType) .Select(s => new CashHallDTO { TradeId = s.Id, TradeType = 2, TradeName = "卖出积分", Num = s.BalanceNum, Amount = s.Amount, Price = s.Price, CreateTime = s.CreateTime, CurrencyType = s.CurrencyType }); var list = buyEntity.Union(sellEntity); result.PageCount = (int)Math.Ceiling((await list.LongCountAsync()) * 1.0f / pageSize); var logsResult = await list.OrderByDescending(a => a.CreateTime).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToListAsync(); result.List = logsResult.Select(s => new CashHallDTO { TradeId = s.TradeId, TradeType = s.TradeType, TradeName = s.TradeName, Num = s.Num, Amount = s.Amount, Price = s.Price, CreateTime = s.CreateTime, CurrencyType = s.CurrencyType, CurrencyName = s.CurrencyType.GetEnumName <CurrencyEnums>() }).ToArray(); return(result); } }
public async Task InitializeAsync() { using (MyDbContext dbc = new MyDbContext()) { var dataList = await dbc.GetAll <PermissionEntity>().ToListAsync(); foreach (var item in dataList) { item.Enabled = 0; item.Icon = null; item.Sort = null; } await dbc.SaveChangesAsync(); } }
public async Task <JournalSearchResult> GetMerchantModelListAsync(long?id, long?typeId, string mobile, string code, DateTime?startTime, DateTime?endTime, int pageIndex, int pageSize) { using (MyDbContext dbc = new MyDbContext()) { JournalSearchResult result = new JournalSearchResult(); long useId = dbc.GetAll <JournalTypeEntity>().SingleOrDefault(j => j.Description == "消费").Id; var journals = dbc.GetAll <JournalEntity>(); journals = journals.Where(j => j.PlatformUserId == id || (j.PlatformUserId == id && j.PlatformUserId == j.ToPlatformUserId) || (j.ToPlatformUserId == id && j.ToPlatformUserId == j.FormPlatformUserId)); if (typeId != null) { journals = journals.Where(j => j.JournalTypeId == typeId); } if (!string.IsNullOrEmpty(mobile)) { journals = journals.Where(j => j.ToPlatformUser.Mobile.Contains(mobile) || (j.FormPlatformUser.Mobile.Contains(mobile) && j.JournalTypeId == useId)); } if (!string.IsNullOrEmpty(code)) { journals = journals.Where(j => j.ToPlatformUser.Code.Contains(code) || (j.FormPlatformUser.Code.Contains(code) && j.JournalTypeId == useId)); } if (startTime != null) { journals = journals.Where(j => j.CreateTime >= startTime); } if (endTime != null) { journals = journals.Where(a => a.CreateTime.Year <= endTime.Value.Year && a.CreateTime.Month <= endTime.Value.Month && a.CreateTime.Day <= endTime.Value.Day); } result.TotalCount = await journals.LongCountAsync(); var journalResult = await journals.OrderByDescending(j => j.CreateTime).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToListAsync(); result.Journals = journalResult.Select(j => ToDTO(j)).ToArray(); return(result); } }