/// <summary> /// 备注 分销商 /// </summary> /// <param name="id"></param> /// <param name="remarks"></param> /// <returns></returns> public ResultDTO RemarkDistributorExt(Guid id, string remarks) { ContextSession contextSession = ContextFactory.CurrentThreadContext; var now = DateTime.Now; var apply = Distributor.ObjectSet().FirstOrDefault(t => t.Id == id); if (apply == null) { return new ResultDTO <DistributionApply> { isSuccess = false, ResultCode = 0, Message = "没有找到ID='" + id + "'的数据!", Data = null } } ; apply.Remarks = remarks; apply.ModifiedOn = now; apply.EntityState = EntityState.Modified; contextSession.SaveChanges(); return(new ResultDTO { isSuccess = true, ResultCode = 1 }); }
/// <summary> /// 分销商列表信息 /// </summary> /// <param name="manaDTO"></param> /// <returns></returns> public ManageDTO ManageInfoExt(ManageVM manaDTO) { ManageDTO result = new ManageDTO(); if (manaDTO == null) { return(result); } if (manaDTO.Ynos == 1 && manaDTO.ParentId != Guid.Empty) { var parent = Distributor.ObjectSet().FirstOrDefault(c => c.Id == manaDTO.ParentId); if (parent != null) { var tuple = CBCSV.GetUserNameAndCode(parent.UserId); result.ParentName = tuple.Item1; result.ParentCode = tuple.Item2; } } var resultData = DSSBP.Instance.ManageInfo(manaDTO); if (resultData != null && resultData.Data != null) { result.Count = resultData.Data.Count; result.Manager = resultData.Data.Manager; } LogHelper.Info( string.Format("DistributeBP.ManageInfoExt(AppId='{0}',ParentId='{1}'),返回:Count={2},Manager.Count={3}。", manaDTO.AppId, manaDTO.ParentId, result.Count, result.Manager.Count)); return(result); }
/// <summary> /// 同步正式环境历史数据使用 勿调用 /// </summary> /// <returns></returns> private ResultDTO SaveMicroshopExt() { var result = new ResultDTO { isSuccess = false }; var query = from d in Distributor.ObjectSet() select d; foreach (var distributor in query) { var isE = Microshop.ObjectSet().FirstOrDefault(t => t.Key == distributor.Id); if (isE != null && isE.QRCodeUrl == "") { var id = Guid.NewGuid(); MicroshopTypeVO mv = new MicroshopTypeVO() { Value = 1 }; var url = BTP.Common.CustomConfig.BtpDomain + string.Format("/Distribute/MicroshopIndex?appid={0}µshopId={1}&distributorId={2}", distributor.EsAppId, id, distributor.Id) + "&type=tuwen&source=share&SrcType=34&isshowsharebenefitbtn=1"; List <Guid> users = new List <Guid> { distributor.UserId }; var user = CBCSV.Instance.GetUserInfoWithAccountList(users)[0]; var logo = user.HeadIcon; var userName = user.Name; var qRCodeUrl = CreateQrCode(logo, url); var ms = new Microshop { Id = id, SubTime = DateTime.Now, ModifiedOn = DateTime.Now, AppId = distributor.EsAppId, UserId = distributor.UserId, Logo = logo, Name = userName + "的小店", Url = url, Type = mv, Key = distributor.Id, QRCodeUrl = qRCodeUrl, EntityState = EntityState.Added }; ContextFactory.CurrentThreadContext.SaveObject(ms); } } int msCount = ContextFactory.CurrentThreadContext.SaveChanges(); if (msCount > 0) { result.isSuccess = true; result.Message = "添加成功"; } else { result.Message = "添加失败"; } return(result); }
/// <summary> /// 查询 分销商 /// </summary> /// <param name="appId"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <param name="rowCount"></param> /// <returns></returns> public List <DistributorDTO> GetDistributorsExt(Guid appId, int pageSize, int pageIndex, out int rowCount) { var query = Distributor.ObjectSet().Where(x => x.EsAppId == appId); rowCount = query.Count(); var queryOrdered = query.OrderByDescending(x => x.SubTime); var entities = queryOrdered.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); return(entities.Select(x => x.ToEntityData()).ToList()); }
private Guid GetDistributorGrandFatherId(Guid fatherId) { if (fatherId.Equals(Guid.Empty)) { return(Guid.Empty); } return((from d2 in Distributor.ObjectSet() where d2.Id == fatherId join d1 in Distributor.ObjectSet() on d2.ParentId equals d1.Id select d1.Id).FirstOrDefault()); }
/// <summary> ///更新分销商的用户信息。 /// </summary> /// <param name="uinfo">用户信息</param> /// <returns>操作结果</returns> public ResultDTO UpdateDistributorUserInfoExt(UserSDTO uinfo) { ResultDTO result = new ResultDTO(); try { if (uinfo == null) { result.ResultCode = 1; result.Message = "参数错误,参数不能为空!"; return(result); } if (uinfo.UserId == Guid.Empty) { result.ResultCode = 2; result.Message = "参数错误,参数UserId不能为空!"; return(result); } var distrQuery = (from d in Distributor.ObjectSet() where d.UserId == uinfo.UserId select d).ToList(); if (distrQuery.Any()) { result.ResultCode = 0; result.Message = "未找到当前用户相关分销商!"; return(result); } foreach (Distributor d in distrQuery) { d.UserName = uinfo.UserName; d.UserCode = uinfo.LoginAccount; d.PicturePath = uinfo.PicUrl; } ContextFactory.CurrentThreadContext.SaveChanges(); } catch (Exception ex) { string errMsg = string.Format("UpdateDistributorUserInfoExt异常,异常信息:{0}", ex); LogHelper.Error(errMsg); result.ResultCode = -1; result.Message = "服务异常,请稍后重试!"; } return(result); }
/// <summary> /// 判断用户是否为三级分销商 /// </summary> /// <param name="cuinfo"></param> /// <returns></returns> public ResultDTO CheckDistributorUserInfoExt(UserSDTO cuinfo) { ResultDTO result = new ResultDTO(); try { if (cuinfo == null) { result.ResultCode = 1; result.Message = "参数不能为空!"; return(result); } if (cuinfo.UserId == Guid.Empty) { result.ResultCode = 2; result.Message = "用户ID不能为空!"; return(result); } bool capp = Jinher.AMP.BTP.TPS.BACBP.CheckAppDistribute(cuinfo.AppId); if (capp) { var cdistor = Distributor.ObjectSet().Where(c => c.UserId == cuinfo.UserId && c.EsAppId == cuinfo.AppId).ToList(); if (cdistor.Count > 0) { result.ResultCode = 0; result.Message = "该用户是三级分销商"; return(result); } result.ResultCode = 3; result.Message = "该用户不是三级分销商"; return(result); } result.ResultCode = 4; result.Message = "该应用未选用三级分销功能"; return(result); } catch (Exception ex) { string errMsg = string.Format("UpdateDistributorUserInfoExt异常,异常信息:{0}", ex); LogHelper.Error(errMsg); result.ResultCode = -1; result.Message = "服务异常,请稍后重试!"; } return(result); }
/// <summary> /// 获取分销商们的备注信息 /// </summary> /// <param name="distributorList"></param> /// <returns></returns> public Dictionary <Guid, string> GetDistributorsRemarksExt(List <Guid> distributorList) { var result = new Dictionary <Guid, string>(); if (distributorList.Any()) { var distributorIds = string.Join(",", distributorList.Select(x => "Guid'" + x + "'").ToArray()); var distributors = Distributor.ObjectSet() .Where("it.Id in {" + distributorIds + "}") .Select(x => new { Id = x.Id, Remarks = x.Remarks }) .ToList(); distributors.ForEach(x => result.Add(x.Id, x.Remarks)); } return(result); }
private List <AuditRet4Wx> GetAuditRet4WxsWhenPass(DistributionApply apply, Distributor l3Distributor, string microShopUrl, out int appDistributorCount) { if (apply.State == DistributeApplyStateEnum.Audit && (l3Distributor == null || string.IsNullOrEmpty(microShopUrl))) { throw new Exception("通过审核时,参数distributor,l3MircoShopId不能为空!"); } var result = new List <AuditRet4Wx>(); var appId = apply.RuleId;//Apply的RuleId是DistributionRule的Id,而它就是AppId switch (apply.State.EnumValue) { case DistributeApplyStateEnum.Audit: var threeLevels = (from d3 in Distributor.ObjectSet() where d3.Id == l3Distributor.Id select d3 ).Union(from d2 in Distributor.ObjectSet() where d2.Id == l3Distributor.ParentId select d2 ).Union(from d2 in Distributor.ObjectSet() where d2.Id == l3Distributor.ParentId join d1 in Distributor.ObjectSet() on d2.ParentId equals d1.Id select d1) .ToList(); threeLevels.ForEach(x => result.Add(new AuditRet4Wx(x.UserId, x.UserName, x.UserCode, x.Level))); var l3 = result.OrderByDescending(x => x.Level).FirstOrDefault(); if (l3 != null) { l3.SetMicroShopUrl(microShopUrl); } break; case DistributeApplyStateEnum.AuditRefuse: result.Add(new AuditRet4Wx(apply.UserId, apply.UserName, apply.UserCode, apply.RefuseReason)); break; } appDistributorCount = Distributor.ObjectSet().Count(x => x.EsAppId == appId); return(result); }
/// <summary> /// 分销商数量和层级 /// </summary> /// <returns></returns> public ManageNumDTO ManageNcExt(ManageVM search) { ManageNumDTO manageNumDTO = new ManageNumDTO(); if (search == null || search.AppId == Guid.Empty) { return(manageNumDTO); } var query = Distributor.ObjectSet().Where(c => c.EsAppId == search.AppId); if (query.Any()) { manageNumDTO.Count = query.Count(); manageNumDTO.MaxLevel = query.Max(c => c.Level); } else { manageNumDTO.Count = 0; manageNumDTO.MaxLevel = 0; } return(manageNumDTO); }
/// <summary> /// 获取分销商信息 /// </summary> /// <param name="distributorUserRelationDTO"></param> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.DistributorInfoDTO GetDistributorInfoExt(Jinher.AMP.BTP.Deploy.CustomDTO.DistributorUserRelationDTO distributorUserRelationDTO) { if (distributorUserRelationDTO == null) { return(null); } if (distributorUserRelationDTO.UserId == Guid.Empty || distributorUserRelationDTO.EsAppId == Guid.Empty) { return(null); } var distributor = (from dis in Distributor.ObjectSet() where dis.UserId == distributorUserRelationDTO.UserId && dis.EsAppId == distributorUserRelationDTO.EsAppId select dis).FirstOrDefault(); if (distributor == null) { return(null); } Jinher.AMP.BTP.Deploy.CustomDTO.DistributorInfoDTO result = new DistributorInfoDTO() { Id = distributor.Id, UserName = distributor.UserName, UserCode = distributor.UserCode, SubTime = distributor.SubTime, ModifiedOn = distributor.ModifiedOn, EsAppId = distributor.EsAppId, ParentId = distributor.ParentId, Level = distributor.Level, Key = distributor.Key, UserId = distributor.UserId, UserSubTime = distributor.UserSubTime, PicturePath = distributor.PicturePath, }; return(result); }
/// <summary> /// 获取一个分销商 /// </summary> /// <param name="appId"></param> /// <param name="userId"></param> /// <returns></returns> public DistributorDTO GetDistributorByExt(Guid appId, Guid userId) { var entity = Distributor.ObjectSet().FirstOrDefault(x => x.EsAppId == appId && x.UserId == userId); return(entity == null ? null : entity.ToEntityData()); }
private Tuple <Distributor, Microshop> PassAuditing_DistributorAndMicroshop(DistributionApply apply) { ContextSession contextSession = ContextFactory.CurrentThreadContext; var now = DateTime.Now; var appId = apply.RuleId;//Apply的RuleId是DistributionRule的Id,而它就是AppId var newDistributorId = Guid.NewGuid(); var level = apply.ParentId.Equals(Guid.Empty) ? 1 : Distributor.ObjectSet().First(x => x.Id == apply.ParentId).Level + 1; var parentDistributorIds = new List <Guid> { GetDistributorGrandFatherId(apply.ParentId), apply.ParentId, newDistributorId }.Where(x => !x.Equals(Guid.Empty)) .Select(x => x.ToString()).ToArray(); var distributorKey = string.Join(",", parentDistributorIds); var remarks = ""; var distributor = new Distributor { Id = newDistributorId, UserId = apply.UserId, UserName = apply.UserName, UserCode = apply.UserCode, SubTime = now, ModifiedOn = now, EsAppId = appId, ParentId = apply.ParentId, Level = level, Key = distributorKey, UserSubTime = apply.SubTime, PicturePath = apply.PicturePath, Remarks = remarks, EntityState = EntityState.Added }; contextSession.SaveObject(distributor); var logo = ""; var userInfo = CBCSV.Instance.GetUserInfoWithAccountList(new List <Guid> { apply.UserId }); if (userInfo != null && userInfo.Count > 0) { logo = userInfo[0].HeadIcon; } else { LogHelper.Error(string.Format("调用CBCSV.Instance.GetUserInfoWithAccountList({0}),没有返回有效值值!", apply.UserId)); } var qrCodeUrl = "";//暂时为空,后续通过update动作赋值 var newMicroshopId = Guid.NewGuid(); var microshopType = MicroshopTypeEnum.Distribution; var microshopUrl = CreateMicroShopUrl(appId, newMicroshopId, distributor.Id); var microshop = new Microshop { Id = newMicroshopId, SubTime = now, ModifiedOn = now, AppId = appId, UserId = apply.UserId, Logo = logo, QRCodeUrl = qrCodeUrl, Name = string.Format("{0}的小店", apply.UserName), Url = microshopUrl, Type = microshopType, Key = distributor.Id, EntityState = EntityState.Added }; contextSession.SaveObject(microshop); contextSession.SaveChanges(); return(new Tuple <Distributor, Microshop>(distributor, microshop)); }
/// <summary> /// 获取分销商的所有身份设置 /// </summary> /// <param name="distributorList"></param> /// <returns></returns> public List <DistributorsHasIdentityResultDTO> GetDistributorsIdentitysExt(List <Guid> distributorList) { var result = new List <DistributorsHasIdentityResultDTO>(); var distributorIds = string.Join(",", distributorList.Select(x => "Guid'" + x + "'").ToArray()); if (distributorIds.Any()) { var distributorObjectSet = Distributor.ObjectSet() .Where("it.Id in {" + distributorIds + "}"); var stateAudit = (int)DistributeApplyStateEnum.Audit; var applyList = (from distributor in distributorObjectSet join apply in DistributionApply.ObjectSet() on new { UserId = distributor.UserId, AppId = distributor.EsAppId } equals new { UserId = apply.UserId, AppId = apply.RuleId } where apply.State.Value == stateAudit select new { DistributorId = distributor.Id, ApplyId = apply.Id, PicturePath = apply.PicturePath }) .Distinct() .ToList(); if (applyList.Any()) { var applyIds = string.Join(",", applyList.Select(x => x.ApplyId).Select(x => "Guid'" + x + "'").ToArray()); var identitysList = DistributionIdentity.ObjectSet().Where("it.ApplyId in {" + applyIds + "}").ToList(); Func <Guid, Guid> getApplyFunc = (distributorId) => { var first = applyList.FirstOrDefault(x => x.DistributorId == distributorId); return(first == null ? Guid.Empty : first.ApplyId); }; Func <Guid, string> getPicturePathFunc = (distributorId) => { var first = applyList.FirstOrDefault(x => x.DistributorId == distributorId); return(first == null ? "" : first.PicturePath); }; Func <Guid, bool> hasIdentityFunc = (applyId) => { var identitys = identitysList.Where(x => x.ApplyId == applyId); return(identitys.Any()); }; Func <Guid, List <DistributionIdentityDTO> > getIdentitysFunc = (applyId) => { var identitys = identitysList.Where(x => x.ApplyId == applyId); return(identitys.Select(x => x.ToEntityData()).ToList()); }; distributorList.ForEach(x => result.Add(new DistributorsHasIdentityResultDTO { DistributorId = x, ApplyId = getApplyFunc(x), PicturePath = getPicturePathFunc(x), HasIdentity = hasIdentityFunc(getApplyFunc(x)), Identitys = getIdentitysFunc(getApplyFunc(x)) })); } } return(result); }
/// <summary> /// 保存分销商关系 /// </summary> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <Guid> SaveDistributorRelationExt(Jinher.AMP.BTP.Deploy.CustomDTO.DistributorUserRelationDTO distribDto) { Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <Guid> result = new Deploy.CustomDTO.ResultDTO <Guid>(); try { if (distribDto == null) { result.ResultCode = 1; result.Message = "参数错误,参数不能为空!"; return(result); } if (distribDto.UserId == Guid.Empty || distribDto.EsAppId == Guid.Empty) { result.ResultCode = 1; result.Message = "参数错误,参数不能为空!"; return(result); } if (!Jinher.AMP.BTP.TPS.BACBP.CheckAppDistribute(distribDto.EsAppId)) { result.ResultCode = 3; result.Message = "抱歉,暂不支持该功能"; return(result); } Distributor disParent = null; //DistributorId为空,当前用户将成为馆的直接分销商(一级分销商). if (distribDto.DistributorId == Guid.Empty) { disParent = new Distributor(); disParent.Id = Guid.Empty; disParent.Level = 0; disParent.Key = ""; } else { disParent = (from dis in Distributor.ObjectSet() where dis.Id == distribDto.DistributorId select dis).FirstOrDefault(); if (disParent == null) { result.ResultCode = 2; result.Message = "分销商信息未找到!"; return(result); } if (disParent.EsAppId != distribDto.EsAppId) { result.ResultCode = 4; result.Message = "请求错误,请检查后重试~"; return(result); } } Guid disQuery = (from dis in Distributor.ObjectSet() where dis.EsAppId == distribDto.EsAppId && dis.UserId == distribDto.UserId select dis.Id).FirstOrDefault(); if (disQuery != null && disQuery != Guid.Empty) { result.Data = disQuery; result.ResultCode = 0; result.Message = "用户已存在分销关系!"; return(result); } var uniDto = Jinher.AMP.BTP.TPS.CBCSV.GetUserNameAndCode(distribDto.UserId); ContextSession contextSession = ContextFactory.CurrentThreadContext; Distributor distributor = Distributor.CreateDistributor(); distributor.Id = Guid.NewGuid(); distributor.UserName = uniDto.Item1; distributor.UserCode = uniDto.Item2; distributor.SubTime = DateTime.Now; distributor.ModifiedOn = DateTime.Now; distributor.EsAppId = distribDto.EsAppId; distributor.ParentId = disParent.Id; distributor.Level = disParent.Level + 1; distributor.Key = (disParent.Key + "." + distributor.Id).Trim('.'); distributor.UserId = distribDto.UserId; distributor.UserSubTime = DateTime.Now; distributor.PicturePath = ""; distributor.EntityState = System.Data.EntityState.Added; contextSession.SaveObject(distributor); //DistributorProfits distributorProfits = new DistributorProfits(); //distributorProfits.Id = distributor.Id; //distributorProfits.UserName = distributor.UserName; //distributorProfits.UserCode = distributor.UserCode; //distributorProfits.SubTime = DateTime.Now; //distributorProfits.ModifiedOn = DateTime.Now; //distributorProfits.OrderAmount = 0; //distributorProfits.CommissionAmount = 0; //distributorProfits.CommmissionUnPay = 0; //distributorProfits.UnderlingCount = 0; //distributorProfits.SubUnderlingCount = 0; //distributorProfits.EntityState = System.Data.EntityState.Added; //contextSession.SaveObject(distributorProfits); contextSession.SaveChanges(); result.Data = distributor.Id; } catch (Exception ex) { string errMsg = string.Format("SaveDistributorRelationExt异常,异常信息:{0}", ex); LogHelper.Error(errMsg); } return(result); }