/// <summary> /// 获取众筹列表 /// </summary> /// <param name="appName">app名称</param> /// <param name="cfState">众筹状态(-1,不限)</param> /// <param name="pageIndex">页码</param> /// <param name="pageSize">每页数量</param> public GetCrowdfundingsDTO GetCrowdfundingsExt(string appName, int cfState, int pageIndex, int pageSize) { GetCrowdfundingsDTO getCrowdfundingsDTO = new GetCrowdfundingsDTO(); if (pageIndex < 1 || pageSize < 1) { return(null); } try { var querys = (from query in Crowdfunding.ObjectSet() join cnt in CrowdfundingCount.ObjectSet() on query.Id equals cnt.CrowdfundingId where (string.IsNullOrEmpty(appName) ? true : (query.AppName.Contains(appName))) && (cfState == -1 ? true : (cfState == query.State)) select new CrowdfundingFullDTO { Id = query.Id, AppId = query.AppId, AppName = query.AppName, CurrentShareCount = cnt.CurrentShareCount, Description = query.Description, DividendPercent = query.DividendPercent, PerShareMoney = query.PerShareMoney, ShareCount = query.ShareCount, Slogan = query.Slogan, StartTime = query.StartTime, State = query.State, SubTime = query.SubTime, TotalDividend = (decimal)cnt.TotalDividend / 1000 } ).OrderByDescending(q => q.SubTime); var list = querys.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList(); if (list != null && list.Count > 0) { getCrowdfundingsDTO.List = list; getCrowdfundingsDTO.Total = querys.Count(); } else { getCrowdfundingsDTO.Total = 0; } return(getCrowdfundingsDTO); } catch (Exception ex) { LogHelper.Error(string.Format("获取众筹列表服务异常。appName:{0},cfState:{1},pageIndex:{2},pageSize:{3}", appName, cfState, pageIndex, pageSize), ex); return(null); } }
/// <summary> /// 添加众筹 /// </summary> /// <param name="crowdfundingDTO">众筹实体</param> public ResultDTO AddCrowdfundingExt(Jinher.AMP.BTP.Deploy.CrowdfundingDTO crowdfundingDTO) { if (crowdfundingDTO == null) { return new ResultDTO { ResultCode = 2, Message = "入参不能为空" } } ; if (crowdfundingDTO.AppId == Guid.Empty) { return new ResultDTO { ResultCode = 2, Message = "请正确填写应用" } } ; var dividendPercent = crowdfundingDTO.DividendPercent * crowdfundingDTO.ShareCount; if (dividendPercent > CustomConfig.CrowdfundingConfig.MaxDividend) { return new ResultDTO { ResultCode = 2, Message = "您的订单成交额已不足抵扣分红,请重新设置!" } } ; if (crowdfundingDTO.StartTime < DateTime.Now) { return(new ResultDTO { ResultCode = 2, Message = "众筹开始时间必须大于当前时间!" }); } string message = "Success"; try { var tmp = Crowdfunding.ObjectSet().FirstOrDefault(c => c.AppId == crowdfundingDTO.AppId); if (tmp != null) { return new ResultDTO { ResultCode = 3, Message = "该应用已经参加众筹活动,不能重复添加" } } ; Dictionary <Guid, string> list = APPSV.GetAppNameListByIds(new List <Guid> { crowdfundingDTO.AppId }); if (list == null || !list.Any() || !list.ContainsKey(crowdfundingDTO.AppId) || list[crowdfundingDTO.AppId] != crowdfundingDTO.AppName.Trim()) { return new ResultDTO { ResultCode = 2, Message = "应用Id与名称不符" } } ; ContextSession contextSession = ContextFactory.CurrentThreadContext; //保存众筹 Crowdfunding entity = Crowdfunding.CreateCrowdfunding(); entity.AppName = crowdfundingDTO.AppName; entity.AppId = crowdfundingDTO.AppId; entity.PerShareMoney = crowdfundingDTO.PerShareMoney; entity.DividendPercent = crowdfundingDTO.DividendPercent; entity.ShareCount = crowdfundingDTO.ShareCount; entity.StartTime = crowdfundingDTO.StartTime; entity.State = 0; entity.Slogan = crowdfundingDTO.Slogan; entity.Description = crowdfundingDTO.Description; contextSession.SaveObject(entity); //保存众筹计数表 CrowdfundingCount cnt = CrowdfundingCount.CreateCrowdfundingCount(); cnt.AppId = entity.AppId; cnt.CrowdfundingId = entity.Id; cnt.ShareCount = entity.ShareCount; contextSession.SaveObject(cnt); contextSession.SaveChanges(); if (dividendPercent > CustomConfig.CrowdfundingConfig.WarnDividend) { message = string.Format("您的分红支出已超{0:P0},请注意收支平衡!", CustomConfig.CrowdfundingConfig.WarnDividend); } CrowdfundingMessageDTO Message = new CrowdfundingMessageDTO(); Message.Now = DateTime.Now; Message.StartTime = entity.StartTime; Message.State = -1; AddMessage addMessage = new AddMessage(); addMessage.SendMessage(entity.Id, entity.AppId, entity.StartTime, Message); } catch (Exception ex) { LogHelper.Error(string.Format("添加众筹服务异常。crowdfundingDTO:{0}", crowdfundingDTO), ex); return(new ResultDTO { ResultCode = 1, Message = "Error" }); } return(new ResultDTO { ResultCode = 0, Message = message }); }