/// <summary> /// 给盈科同步指定商城数据 /// </summary> /// <returns></returns> public void GetMallAppsForJobExt(Guid esAppId) { LogHelper.Info(string.Format("MallApplyBP.GetMallAppsForJobExt入参:esAppId={0}", esAppId)); if (esAppId == Guid.Empty) { return; } Task.Factory.StartNew(() => { MallApply.ObjectSet().Where(_ => _.EsAppId == esAppId) .ToList().ForEach(Item => { try { var mqjson = JsonConvert.SerializeObject(Item.ToEntityData()); if (TPS.YJBJMQSV.SendToMq("bj_bw_mallapply", JsonConvert.ToString(mqjson))) { LogHelper.Info("MallApplyBP.GetMallAppsForJobExt成功!"); } else { LogHelper.Info("MallApplyBP.GetMallAppsForJobExt失败!"); } } catch (Exception ex) { LogHelper.Info(string.Format("MallApplyBP.GetMallAppsForJobExt失败:{0}", ex)); LogHelper.Info(string.Format("MallApplyBP.GetMallAppsForJobExt失败:{0}", ex.Message)); } }); }); }
/// <summary> /// 查询商城信息 /// </summary> /// <param name="appId"></param> /// <returns></returns> public System.Collections.Generic.List <Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.MallApplyDTO> GetMallApplyListExt(System.Guid EsAppid) { try { var mallapplylist = MallApply.ObjectSet().AsQueryable(); if (!string.IsNullOrWhiteSpace(EsAppid.ToString()) && (!EsAppid.ToString().Contains("00000000-0000-0000-0000-000000000000"))) { mallapplylist = mallapplylist.Where(p => p.EsAppId == EsAppid && (p.State.Value == 2 || p.State.Value == 4)).AsQueryable(); } List <Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.MallApplyDTO> result = (from c in mallapplylist select new Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.MallApplyDTO { AppId = c.AppId, AppName = c.AppName }).ToList(); //易捷北京特殊处理 if (EsAppid == new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6")) { Deploy.CustomDTO.MallApply.MallApplyDTO YiJie = new Deploy.CustomDTO.MallApply.MallApplyDTO() { AppId = new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6"), AppName = "易捷北京" }; result.Add(YiJie); } return(result); } catch (Exception ex) { Jinher.JAP.Common.Loging.LogHelper.Error(string.Format("查询商城信息GetMallApplyListExt。异常信息"), ex); return(null); } }
/// <summary> /// 根据id获取商品佣金实体 /// </summary> /// <param name="search">查询类</param> /// <returns>结果</returns> public Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.CommodityCommissionDTO GetCommodityCommissionExt(Guid id) { Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.CommodityCommissionDTO model = new Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.CommodityCommissionDTO(); var commodityCommission = CommodityCommission.ObjectSet().FirstOrDefault(p => p.Id == id); if (commodityCommission != null) { var mallapplyid = MallApply.ObjectSet().FirstOrDefault(p => p.Id == commodityCommission.MallApplyId); if (mallapplyid != null) { model.AppId = mallapplyid.AppId; } model.Id = commodityCommission.Id; model.MallApplyId = commodityCommission.MallApplyId; model.ModifiedOn = commodityCommission.ModifiedOn; model.SubTime = commodityCommission.SubTime; model.EffectiveTime = commodityCommission.EffectiveTime; model.Commission = commodityCommission.Commission; model.UserId = commodityCommission.UserId; model.IsDel = commodityCommission.IsDel; model.CategoryId = commodityCommission.CategoryId; model.CommodityId = commodityCommission.CommodityId; model.CommodityName = commodityCommission.CommodityName; } return(model); }
/// <summary> /// 担保交易(金币)支付,生成结算单 /// </summary> public static SettleAccounts CreateSettleAccount(ContextSession contextSession, CommodityOrder commodityOrder) { // 未加入场馆的不生成结算单 if (!commodityOrder.EsAppId.HasValue) { return(null); } if (!CheckPayType(commodityOrder)) { return(null); } var parSources = PaySource.GetPaymentByTradeType(0); if (commodityOrder.Payment != 0) { LogHelper.Warn("担保交易(金币)支付,生成结算单失败,该订单:[" + commodityOrder.Id + "]非金币支付。"); return(null); } // 查询场馆信息 var mall = MallApply.ObjectSet().Where(m => m.AppId == commodityOrder.AppId && m.EsAppId == commodityOrder.EsAppId && (m.State.Value == 2 || m.State.Value == 4)).FirstOrDefault(); if (mall == null) { LogHelper.Info("生成结算项失败,商城中未找到该APP,订单ID:" + commodityOrder.Id); return(null); } return(CreateSettleAccount(contextSession, commodityOrder, mall)); }
/// <summary> /// 获取商城下入住的APP /// </summary> /// <returns></returns> public System.Collections.Generic.List <AppInfoDTO> GetMallAppsExt(Guid esAppId) { return(MallApply.ObjectSet() .Where(_ => _.EsAppId == esAppId && _.State.Value == (int)MallApplyEnum.TG) .Select(_ => new AppInfoDTO { Id = _.AppId, Name = _.AppName }) .ToList()); }
public static string ImportMallApp(Guid appId) { if (appId == Guid.Empty) { return("APPID为空"); } var appInfo = new APPSVFacade().GetAppOwnerInfo(appId); // 获取场馆下所有APP var apps = Jinher.AMP.BTP.TPS.ZPHSV.Instance.GetPavilionApp(new ZPH.Deploy.CustomDTO.QueryPavilionAppParam() { Id = appId, pageIndex = 1, pageSize = int.MaxValue }).Data; if (apps.Count == 0) { return("场馆下无APP"); } var pavilionInfo = Jinher.AMP.BTP.TPS.ZPHSV.Instance.GetAppPavilionInfo(new ZPH.Deploy.CustomDTO.QueryAppPavilionParam { id = appId }); ContextSession contextSession = ContextFactory.CurrentThreadContext; foreach (var app in apps) { var existCount = MallApply.ObjectSet().Where(m => m.AppId == app.appId && m.EsAppId == appId).Count(); if (existCount == 0) { MallApply entity = new MallApply(); entity.Id = Guid.NewGuid(); entity.EsAppId = appId; entity.EsAppName = pavilionInfo.pavilionName; entity.AppId = app.appId; entity.AppName = app.appName; entity.SubTime = DateTime.Now; entity.ModifiedOn = DateTime.Now; entity.UserId = appInfo.OwnerId; entity.State = new ApplyStateVO { Value = 2 }; entity.Type = 1; entity.EntityState = EntityState.Added; contextSession.SaveObject(entity); } } try { contextSession.SaveChanges(); } catch (Exception ex) { return(ex.Message); } return("ok"); }
/// <summary> /// 获取自动调价设置数据 /// </summary> /// <param name="searchDto"></param> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.CommodityPriceFloatList <CommodityPriceFloatListDto> > GetDataListExt(System.Guid appId) { try { var query = CommodityPriceFloat.ObjectSet().Where(_ => !_.IsDel && _.EsAppId == appId); var count = query.Count(); var data = query.OrderByDescending(q => q.SubTime).Select(_ => new CommodityPriceFloatListDto { Id = _.Id, EsAppId = _.EsAppId, AppIds = _.AppIds, FloatPrice = _.FloatPrice }).ToList(); var malls = MallApply.GetTGQuery(appId).Select(_ => new { _.AppId, _.AppName }).ToList(); data.ForEach(_ => { if (!string.IsNullOrEmpty(_.AppIds)) { List <string> appNames = new List <string>(); foreach (var dAppId in _.AppIds.Split(',')) { var mall = malls.Find(m => m.AppId == new Guid(dAppId)); if (mall != null) { appNames.Add(mall.AppName); } } _.AppNames = string.Join("、", appNames); } else { _.AppNames = "未指定店铺"; } }); return(new ResultDTO <CommodityPriceFloatList <CommodityPriceFloatListDto> > { isSuccess = true, Data = new CommodityPriceFloatList <CommodityPriceFloatListDto> { List = data, Count = count } }); } catch (Exception ex) { LogHelper.Error("CommodityPriceFloatBP.GetDataListExt 异常", ex); return(new ResultDTO <CommodityPriceFloatList <CommodityPriceFloatListDto> > { isSuccess = false, Message = ex.Message }); } }
/// <summary> /// 查询商城信息 /// </summary> /// <param name="search">查询类</param> /// <returns>结果</returns> public List <Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.MallApplyDTO> GetMallApplyInfoListExt(Guid appId) { var mallapplylist = MallApply.ObjectSet().ToList(); if (!string.IsNullOrWhiteSpace(appId.ToString()) && (!appId.ToString().Contains("00000000-0000-0000-0000-000000000000"))) { mallapplylist = mallapplylist.Where(p => p.EsAppId == appId).ToList(); } var baseCommissionlist = BaseCommission.ObjectSet().ToList(); List <Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.MallApplyDTO> searchlist = new List <Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.MallApplyDTO>(); if (mallapplylist.Count() > 0) { foreach (var item in mallapplylist) { Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.MallApplyDTO model = new Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.MallApplyDTO(); model.Id = item.Id; model.SubTime = item.SubTime; model.ModifiedOn = item.ModifiedOn; model.AppId = item.AppId; model.EsAppId = item.EsAppId; model.AppName = item.AppName; model.EsAppName = item.EsAppName; model.ApplyContent = item.ApplyContent; int State = Convert.ToInt32(item.State.Value); #region 获取基础佣金比例 var baseCommission = baseCommissionlist.Where(p => p.MallApplyId == item.Id).OrderByDescending(p => p.SubTime).FirstOrDefault(); if (baseCommission != null) { model.Commission = baseCommission.Commission; } #endregion model.State = State; model.StateShow = (State == 0 ? new EnumHelper().GetDescription(MallApplyEnum.RZSQ) : State == 1 ? new EnumHelper().GetDescription(MallApplyEnum.QXRZ) : State == 2 ? new EnumHelper().GetDescription(MallApplyEnum.TG) : State == 3 ? new EnumHelper().GetDescription(MallApplyEnum.BTG) : State == 4 ? new EnumHelper().GetDescription(MallApplyEnum.GQ) : State == 5 ? new EnumHelper().GetDescription(MallApplyEnum.QXRZQR) : ""); model.Type = item.Type; searchlist.Add(model); } //当State的状态为5时不显示 searchlist = searchlist.Where(p => p.State < 5).ToList(); } return(searchlist); }
/// <summary> /// 获取易捷北京商家信息 /// </summary> /// <param name="appIds">商家Id列表</param> /// <returns>商家信息</returns> public System.Collections.Generic.List <Jinher.AMP.BTP.Deploy.CustomDTO.SellerInfoDTO> GetYJSellerInfoesExt(System.Collections.Generic.List <System.Guid> appIds) { if (appIds.Count == 0) { return(new System.Collections.Generic.List <Jinher.AMP.BTP.Deploy.CustomDTO.SellerInfoDTO>()); } var ids = appIds.Distinct(); var mallApplies = MallApply.ObjectSet().Where(m => m.EsAppId == YJB.Deploy.CustomDTO.YJBConsts.YJAppId && ids.Contains(m.AppId)).ToList() .Select(m => new Jinher.AMP.BTP.Deploy.CustomDTO.SellerInfoDTO { AppId = m.AppId, AppName = m.AppName, EsAppId = m.EsAppId, EsAppName = m.EsAppName, Type = m.GetTypeString() }).ToList(); return(mallApplies); }
/// <summary> /// 保存商城信息 /// </summary> /// <returns></returns> public ResultDTO SaveMallApplyExt(Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.MallApplyDTO model) { MallApply entity = new MallApply(); try { ContextSession contextSession = ContextFactory.CurrentThreadContext; entity.Id = model.Id; entity.SubTime = model.SubTime; entity.ModifiedOn = model.ModifiedOn; entity.AppId = model.AppId; entity.CrcAppId = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(model.AppId); entity.AppName = model.AppName; entity.EsAppId = model.EsAppId; entity.EsAppName = model.EsAppName; entity.UserId = model.UserId; entity.ApplyContent = model.ApplyContent; entity.State = new ApplyStateVO { Value = model.State }; entity.Type = model.Type ?? 1; entity.EntityState = EntityState.Added; contextSession.SaveObject(entity); contextSession.SaveChanges(); // 同步Supplier表 var supplier = Supplier.ObjectSet().Where(_ => _.EsAppId == entity.EsAppId && _.AppId == entity.AppId && !_.IsDel).FirstOrDefault(); if (supplier != null) { if (supplier.SupplierType != entity.Type) { supplier.SupplierType = entity.Type; supplier.EntityState = System.Data.EntityState.Modified; contextSession.SaveObject(supplier); } } } catch (Exception ex) { LogHelper.Error(string.Format("商家信息保存异常。MallApply:{0}", ex.Message)); return(new ResultDTO { ResultCode = 1, Message = ex.Message, isSuccess = false }); } return(new ResultDTO { ResultCode = 0, Message = "提交成功", isSuccess = true }); }
/// <summary> /// 获取第三方电商信息 /// </summary> /// <param name="appId"></param> /// <returns></returns> public static ThirdECommerceDTO GetThirdECommerce(Guid appId) { var thirdECommerceId = MallApply.ObjectSet().Where(p => p.EsAppId == CustomConfig.YJAppId && p.AppId == appId && p.ThirdECommerceId.HasValue).Select(p => p.ThirdECommerceId.Value).FirstOrDefault(); if (thirdECommerceId != Guid.Empty) { var thirdECommerce = ThirdECommerce.ObjectSet() .Where(p => p.Id == thirdECommerceId && p.Type == (int)ThirdECommerceTypeEnum.ByBiaoZhunJieKou) .FirstOrDefault(); if (thirdECommerce != null) { return(thirdECommerce.ToEntityData()); } } return(null); }
/// <summary> /// 易捷北京自营商品申请开电子发票 /// </summary> /// <returns></returns> public static bool IsZshInvoice(CommodityOrder commodityOrder) { bool isZshInvoice = false; Guid esAppId = new Guid(CustomConfig.InvoiceAppId); //易捷北京的自营或者门店自营 MallApply mallApply = MallApply.ObjectSet().FirstOrDefault(t => t.EsAppId == esAppId && t.AppId == commodityOrder.AppId && (t.Type == 0 || t.Type == 2)); if (mallApply != null) { var invoice = Invoice.ObjectSet().FirstOrDefault(t => t.CommodityOrderId == commodityOrder.Id); if (invoice != null && invoice.Category == 2) { isZshInvoice = true; } } return(isZshInvoice); }
/// <summary> /// 查询佣金信息 /// </summary> /// <param name="search">查询类</param> /// <returns>结果</returns> public List <Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.BaseCommissionDTO> GetBaseCommissionListExt(Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.BaseCommissionDTO search) { var BaseCommissionlist = BaseCommission.ObjectSet().Where(p => p.IsDel == true).ToList(); if (!string.IsNullOrWhiteSpace(search.MallApplyId.ToString()) && (!search.MallApplyId.ToString().Contains("00000000-0000-0000-0000-000000000000"))) { BaseCommissionlist = BaseCommissionlist.Where(p => p.MallApplyId == search.MallApplyId).ToList(); } if (!string.IsNullOrWhiteSpace(search.UserId.ToString()) && (!search.UserId.ToString().Contains("00000000-0000-0000-0000-000000000000"))) { BaseCommissionlist = BaseCommissionlist.Where(p => p.UserId == search.UserId).ToList(); } var mallapplylist = MallApply.ObjectSet().ToList(); List <Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.BaseCommissionDTO> searchlist = new List <Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.BaseCommissionDTO>(); if (BaseCommissionlist.Count() > 0) { foreach (var item in BaseCommissionlist) { CBC.Deploy.CustomDTO.UserBasicInfoDTO commodityuser = CBCSV.Instance.GetUserBasicInfoNew(item.UserId); var mallapply = mallapplylist.FirstOrDefault(p => p.Id == item.MallApplyId); Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.BaseCommissionDTO model = new Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.BaseCommissionDTO(); model.Id = item.Id; model.SubTime = item.SubTime; model.ModifiedOn = item.ModifiedOn; if (mallapply != null) { model.EsAppName = mallapply.EsAppName; } if (commodityuser != null) { model.UserName = commodityuser.Name; } model.AppName = item.AppName; model.Commission = item.Commission; model.EffectiveTime = item.EffectiveTime; model.MallApplyId = item.MallApplyId; model.UserId = item.UserId; model.IsDel = item.IsDel; searchlist.Add(model); } } return(searchlist); }
/// <summary> /// 导入自营商家未设置结算价时的结算订单 /// </summary> public static void ImportNotSettleOrder() { LogHelper.Info("SettleAccountHelper.ImportNotSettleOrder 开始导入未设置结算价的订单"); try { ContextSession contextSession = ContextFactory.CurrentThreadContext; // 查询商城下APP var mallQuery = MallApply.ObjectSet().Where(m => m.Type == 0 && (m.State.Value == 2 || m.State.Value == 4)); var startDate = new DateTime(2017, 9, 1); var hadAddOrderQuery = SettleAccountsDetails.ObjectSet().AsQueryable(); foreach (var mall in mallQuery.ToList()) { var orderQuery = CommodityOrder.ObjectSet().Where(o => o.AppId == mall.AppId && o.EsAppId == mall.EsAppId && o.PaymentTime > startDate && o.Payment != 0); var orders = orderQuery.Join(CommodityOrderService.ObjectSet() .Where(s => (s.State == 3 || s.State == 7 || s.State == 15)), o => o.Id, s => s.Id, (o, s) => new { s.State, o }) .Where(so => !hadAddOrderQuery.Where(h => h.EsAppId == mall.EsAppId && h.AppId == mall.AppId && h.OrderId == so.o.Id) .Any(h => h.Id == so.o.Id)) .ToList(); if (orders.Count > 0) { // 生成结算项 foreach (var so in orders) { SettleAccountHelper.CreateSettleAccountDetails(contextSession, so.o, mall, so.State); } } } contextSession.SaveChanges(); } catch (Exception ex) { LogHelper.Error(string.Format("SettleAccountHelper.ImportNotSettleOrder 异常", ex)); } LogHelper.Info("SettleAccountHelper.ImportNotSettleOrder 结束导入未设置结算价的订单"); ImportNotSettleGoldOrder(); }
/// <summary> /// 根据id获取商城实体信息 /// </summary> /// <param name="search">查询类</param> /// <returns>结果</returns> public Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.MallApplyDTO GetMallApplyExt(Guid id) { Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.MallApplyDTO model = new Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.MallApplyDTO(); var mallApply = MallApply.ObjectSet().FirstOrDefault(p => p.Id == id); if (mallApply != null) { model.Id = mallApply.Id; model.SubTime = mallApply.SubTime; model.ModifiedOn = mallApply.ModifiedOn; model.AppId = mallApply.AppId; model.EsAppId = mallApply.EsAppId; model.AppName = mallApply.AppName; model.EsAppName = mallApply.EsAppName; model.ApplyContent = mallApply.ApplyContent; int State = Convert.ToInt32(mallApply.State.Value); #region 获取基础佣金比例 var baseCommission = BaseCommission.ObjectSet().FirstOrDefault(p => p.MallApplyId == mallApply.Id); if (baseCommission != null) { model.Commission = baseCommission.Commission; } #endregion model.State = State; model.StateShow = (State == 0 ? new EnumHelper().GetDescription(MallApplyEnum.RZSQ) : State == 1 ? new EnumHelper().GetDescription(MallApplyEnum.QXRZ) : State == 2 ? new EnumHelper().GetDescription(MallApplyEnum.TG) : State == 3 ? new EnumHelper().GetDescription(MallApplyEnum.BTG) : State == 4 ? new EnumHelper().GetDescription(MallApplyEnum.GQ) : State == 5 ? new EnumHelper().GetDescription(MallApplyEnum.QXRZQR) : ""); model.Type = mallApply.Type; model.TypeString = mallApply.GetTypeString(); } return(model); }
/// <summary> /// 验证是否存在入驻商家 /// </summary> /// <returns></returns> public ResultDTO IsHaveMallApplyExt(Guid esAppId, Guid appId) { ResultDTO resultDto = new ResultDTO() { isSuccess = false }; try { var mallApply = MallApply.ObjectSet().FirstOrDefault(t => t.EsAppId == esAppId && t.AppId == appId); if (mallApply != null) { resultDto.isSuccess = true; } } catch (Exception ex) { LogHelper.Error(string.Format("获取入驻商家信息异常。MallApply.IsHaveMallApplyExt:{0}", ex.Message)); } return(resultDto); }
/// <summary> /// 获取App入驻类型 /// </summary> /// <param name="esAppId"></param> /// <returns></returns> public List <MallTypeDTO> GetMallTypeListByEsAppId(Guid esAppId) { var key = "MallType:EAI:" + esAppId.ToString(); //var data = GlobalCacheWrapper.GetDataCache(key, Consts.CacheSetting) as List<MallTypeDTO>; var data = RedisHelper.Get <List <MallTypeDTO> >(key); if (data == null) { data = MallApply.GetTGQuery(esAppId).Select(_ => new MallTypeDTO { Id = _.AppId, Type = _.Type }).ToList(); //GlobalCacheWrapper.AddCache(key, apps, TimeSpan.FromMinutes(30), CacheTypeEnum.redis, Consts.CacheSetting); RedisHelper.Set(key, data, TimeSpan.FromMinutes(30)); LogHelper.Info("GetMallTypeListByEsAppId from DB......"); } else { //LogHelper.Debug("GetMallTypeListByEsAppId from Cache......"); } return(data); }
/// <summary> /// 获取店铺(商家)对应的第三方电商类型 /// </summary> /// <param name="appId"></param> /// <returns></returns> public static ThirdECommerceTypeEnum GetAppThirdECommerceType(Guid appId) { if (appId == Guid.Empty) { return(ThirdECommerceTypeEnum.NotThirdECommerce); } if (CustomConfig.JdAppIdList.Contains(appId)) { return(ThirdECommerceTypeEnum.JingDongDaKeHu); } else if (CustomConfig.YxAppIdList.Contains(appId)) { return(ThirdECommerceTypeEnum.WangYiYanXuan); } else if (CustomConfig.SnAppIdList.Contains(appId)) { return(ThirdECommerceTypeEnum.SuNingYiGou); } else if (CustomConfig.FZAppIdList.Contains(appId)) { return(ThirdECommerceTypeEnum.FangZheng); } else if (CustomConfig.YPKAppIdList.Contains(appId)) { return(ThirdECommerceTypeEnum.YiPaiKe); } else { var thirdECommerceId = MallApply.ObjectSet().Where(p => p.EsAppId == CustomConfig.YJAppId && p.AppId == appId && p.ThirdECommerceId.HasValue).Select(p => p.ThirdECommerceId.Value).FirstOrDefault(); if (thirdECommerceId != Guid.Empty) { if (ThirdECommerce.ObjectSet().Any(p => p.Id == thirdECommerceId && p.Type == (int)ThirdECommerceTypeEnum.ByBiaoZhunJieKou)) { return(ThirdECommerceTypeEnum.ByBiaoZhunJieKou); } } return(ThirdECommerceTypeEnum.NotThirdECommerce); } }
/// <summary> /// 根据id获取基础佣金实体 /// </summary> /// <param name="search">查询类</param> /// <returns>结果</returns> public Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.BaseCommissionDTO GetBaseCommissionExt(Guid id, Guid mallApplyId) { Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.BaseCommissionDTO model = new Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.BaseCommissionDTO(); BaseCommission baseCommission = null; if (!string.IsNullOrWhiteSpace(id.ToString()) && (!id.ToString().Contains("00000000-0000-0000-0000-000000000000"))) { baseCommission = BaseCommission.ObjectSet().OrderByDescending(p => p.SubTime).FirstOrDefault(p => p.Id == id); } if (!string.IsNullOrWhiteSpace(mallApplyId.ToString()) && (!mallApplyId.ToString().Contains("00000000-0000-0000-0000-000000000000"))) { baseCommission = BaseCommission.ObjectSet().OrderByDescending(p => p.SubTime).FirstOrDefault(p => p.MallApplyId == mallApplyId); } if (baseCommission != null) { CBC.Deploy.CustomDTO.UserBasicInfoDTO commodityuser = CBCSV.Instance.GetUserBasicInfoNew(baseCommission.UserId); var mallapplyid = MallApply.ObjectSet().FirstOrDefault(p => p.Id == baseCommission.MallApplyId); if (mallapplyid != null) { model.AppId = mallapplyid.AppId; model.EsAppName = model.AppName; } if (commodityuser != null) { model.UserName = commodityuser.Name; } model.Id = baseCommission.Id; model.MallApplyId = baseCommission.MallApplyId; model.ModifiedOn = baseCommission.ModifiedOn; model.SubTime = baseCommission.SubTime; model.EffectiveTime = baseCommission.EffectiveTime; model.Commission = baseCommission.Commission; model.UserId = baseCommission.UserId; model.IsDel = baseCommission.IsDel; model.AppName = baseCommission.AppName; } return(model); }
/// <summary> /// 添加供用商 /// </summary> /// <param name="searchDto"></param> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO AddSupplierExt(SupplierUpdateDTO dto) { if (dto.AppIds == null || dto.AppIds.Count == 0) { return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { isSuccess = false, Message = "参数错误" }); } ContextSession contextSession = ContextFactory.CurrentThreadContext; var supplierMain = SupplierMain.CreateSupplierMain(); Dictionary <Guid, string> appNames = new Dictionary <Guid, string>(); foreach (var appId in dto.AppIds) { var supplier = Supplier.CreateSupplier(); supplier.EsAppId = dto.EsAppId; supplier.AppId = appId; var appName = Jinher.AMP.BTP.TPS.APPSV.GetAppName(appId); if (appName == "") { appName = MallApply.ObjectSet().Where(_ => _.EsAppId == supplier.EsAppId && _.AppId == supplier.AppId).Select(_ => _.AppName).FirstOrDefault(); } appNames.Add(appId, appName); supplier.AppName = appName; supplier.SubId = dto.SubId; supplier.SupplierName = dto.SupplierName; supplier.SupplierCode = dto.SupplierCode; supplier.SupplierType = dto.SupplierType; supplier.ShipperType = dto.ShipperType; supplier.IsDel = false; supplier.SupplierMainId = supplierMain.Id; contextSession.SaveObject(supplier); // 同步MallApply表 var mallApply = MallApply.ObjectSet().Where(_ => _.EsAppId == supplier.EsAppId && _.AppId == supplier.AppId /*&& _.State.Value == (int)Jinher.AMP.BTP.Deploy.Enum.MallApplyEnum.TG*/).FirstOrDefault(); if (mallApply != null) { if (mallApply.AppName != supplier.AppName || mallApply.Type != supplier.SupplierType) { mallApply.Type = supplier.SupplierType; mallApply.AppName = supplier.AppName; mallApply.EntityState = System.Data.EntityState.Modified; contextSession.SaveObject(mallApply); } } } supplierMain.EsAppId = dto.EsAppId; supplierMain.AppIds = string.Join(",", dto.AppIds); supplierMain.AppNames = string.Join(",", appNames.Values); supplierMain.SubId = dto.SubId; supplierMain.SupplierName = dto.SupplierName; supplierMain.SupplierCode = dto.SupplierCode; supplierMain.SupplierType = dto.SupplierType; supplierMain.ShipperType = dto.ShipperType; supplierMain.IsDel = false; contextSession.SaveObject(supplierMain); try { contextSession.SaveChanges(); } catch (Exception ex) { LogHelper.Error("Supplier.AddSupplierExt 异常", ex); return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { isSuccess = false, Message = ex.Message }); } return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { isSuccess = true }); }
/// <summary> /// 获取易捷北京下所有店铺信息 /// </summary> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <System.Collections.Generic.List <Jinher.AMP.BTP.Deploy.CustomDTO.YJBJAppInfo> > GetYJAppInfoExt(int pageIndex) { LogHelper.Debug("进入客服服务,获取易捷北京下所有店铺信息:请求时间:" + DateTime.Now); ResultDTO <List <YJBJAppInfo> > Result = new ResultDTO <List <YJBJAppInfo> > { isSuccess = false, Message = "获取失败" }; try { int pageSize = 100; var YJAppInfo = MallApply.ObjectSet().Where(p => p.EsAppId == Jinher.AMP.YJB.Deploy.CustomDTO.YJBConsts.YJAppId).OrderBy(o => o.SubTime).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); if (!YJAppInfo.Any()) { Result.Message = "未获取到任何数据"; return(Result); } List <YJBJAppInfo> YJAppList = new List <YJBJAppInfo>(); foreach (var item in YJAppInfo) { YJBJAppInfo AppInfo = new YJBJAppInfo(); AppInfo.appId = item.AppId; AppInfo.AppName = item.AppName; if (item.State.Value == 2) { AppInfo.state = 0; } else { AppInfo.state = 1; } if (item.Type == 0) { AppInfo.type = "自营他配"; } else if (item.Type == 1) { AppInfo.type = "第三方"; } else if (item.Type == 2) { AppInfo.type = "自营自配自采"; } else if (item.Type == 3) { AppInfo.type = "自营自配统采"; } else { AppInfo.type = "未知类型"; } YJAppList.Add(AppInfo); } Result.Data = YJAppList; Result.isSuccess = true; Result.Message = "获取成功"; } catch (Exception ex) { Result.Message = "获取异常"; LogHelper.Error("CustomSV.GetAppSceneContentExt。根据appId获取商家的移动坐席数据:", ex); } return(Result); }
/// <summary> /// 导入自营商家未设置结算价时的金币支付订单 /// </summary> public static void ImportNotSettleGoldOrder() { LogHelper.Info("SettleAccountHelper.ImportNotSettleGoldOrder 开始导入未设置结算价的金币支付订单"); try { ContextSession contextSession = ContextFactory.CurrentThreadContext; // 查询商城下APP var mallQuery = MallApply.ObjectSet().Where(m => m.Type == 0 && (m.State.Value == 2 || m.State.Value == 4)); //var startDate = new DateTime(2017, 9, 1); var hadAddOrderQuery = SettleAccountsDetails.ObjectSet().AsQueryable(); ContextDTO contextDTO = AuthorizeHelper.CoinInitAuthorizeInfo(); // 生成结算项 List <object> saveList = new List <object>(); foreach (var mall in mallQuery.ToList()) { var orderQuery = CommodityOrder.ObjectSet().Where(o => o.AppId == mall.AppId && o.EsAppId == mall.EsAppId && o.PaymentTime > mall.SubTime && o.Payment == 0); var orders = orderQuery.Join(CommodityOrderService.ObjectSet() .Where(s => (s.State == 15)), o => o.Id, s => s.Id, (o, s) => o) .Where(o => !hadAddOrderQuery.Where(h => h.EsAppId == mall.EsAppId && h.AppId == mall.AppId && h.OrderId == o.Id) .Any(h => h.Id == o.Id)) .ToList(); if (orders.Count > 0) { foreach (var o in orders) { LogHelper.Info("ImportNotSettleGoldOrder,导入自营商家未设置结算价时的金币支付订单,开始生成结算单,OrderId:" + o.Id); var sa = SettleAccountHelper.CreateSettleAccount(contextSession, o, mall); if (sa != null) { Jinher.AMP.App.Deploy.CustomDTO.AppIdOwnerIdTypeDTO applicationDTO = APPSV.Instance.GetAppOwnerInfo(o.AppId, contextDTO); // 打款 var confirmDto = OrderSV.BuildConfirmPayDTOAfterSales(contextSession, o, out saveList, applicationDTO, isSaveObject: false); LogHelper.Info("导入自营商家未设置结算价时的金币支付订单,开始打款,OrderId:" + o.Id + "ConfirmPayDTO: " + JsonHelper.JsonSerializer(confirmDto)); var goldPayResult = Jinher.AMP.BTP.TPS.FSPSV.Instance.ConfirmPay(confirmDto); if (goldPayResult.Code != 0) { // 打款失败 sa.IsPaySuccess = false; LogHelper.Info("导入自营商家未设置结算价时的金币支付订单,结束打款,失败,OrderId:" + o.Id); var errorInfo = JsonHelper.JsonSerializer(goldPayResult); LogHelper.Error("OrderSV.CreateSettleAccount 生成结算单,打款异常,OrderId: " + o.Id + " ReturnInfoDTO: " + errorInfo); SettleAccountsException exception = new SettleAccountsException(); exception.Id = sa.Id; exception.OrderId = o.Id; exception.OrderCode = o.Code; exception.OrderRealPrice = o.RealPrice; exception.ClearingPrice = sa.SellerAmount; exception.ExceptionInfo = errorInfo; exception.AppId = sa.AppId; exception.AppName = sa.AppName; exception.EntityState = EntityState.Added; contextSession.SaveObject(exception); } else { // 打款成功 sa.IsPaySuccess = true; LogHelper.Info("导入自营商家未设置结算价时的金币支付订单,结束打款,成功,OrderId:" + o.Id); } LogHelper.Info("ImportNotSettleGoldOrder,导入自营商家未设置结算价时的金币支付订单,结束生成结算单,OrderId:" + o.Id); } } } } if (saveList != null && saveList.Any()) { foreach (var o in saveList) { contextSession.SaveObject(o); } } contextSession.SaveChanges(); } catch (Exception ex) { LogHelper.Error(string.Format("SettleAccountHelper.ImportNotSettleGoldOrder 异常", ex)); } LogHelper.Info("SettleAccountHelper.ImportNotSettleGoldOrder 结束导入未设置结算价的金币支付订单"); }
/// <summary> /// 查询商城信息 /// </summary> /// <param name="search">查询类</param> /// <returns>结果</returns> public List <Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.MallApplyDTO> GetMallApplyInfoListExt(Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.MallApplyDTO search) { var searchlist = new List <Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.MallApplyDTO>(); if (search.EsAppId == Guid.Empty && search.AppId == Guid.Empty) { return(searchlist); } var mallapplylistQuery = MallApply.ObjectSet().Where(m => m.State.Value < 5); if (!string.IsNullOrWhiteSpace(search.AppName)) { mallapplylistQuery = mallapplylistQuery.Where(p => p.AppName.Contains(search.AppName)); } if (search.UserId != Guid.Empty) { mallapplylistQuery = mallapplylistQuery.Where(p => p.UserId == search.UserId); } if (!string.IsNullOrWhiteSpace(search.AppId.ToString()) && (!search.AppId.ToString().Contains("00000000-0000-0000-0000-000000000000"))) { mallapplylistQuery = mallapplylistQuery.Where(p => p.AppId == search.AppId); } if (!string.IsNullOrWhiteSpace(search.EsAppId.ToString()) && (!search.EsAppId.ToString().Contains("00000000-0000-0000-0000-000000000000"))) { mallapplylistQuery = mallapplylistQuery.Where(p => p.EsAppId == search.EsAppId); } if (search.Type.HasValue) { mallapplylistQuery = mallapplylistQuery.Where(p => p.Type == search.Type); } var baseCommissionlist = BaseCommission.ObjectSet().ToList(); var commoditySettleAmountQuery = CommoditySettleAmount.ObjectSet().AsQueryable(); foreach (var item in mallapplylistQuery.ToList()) { var model = new Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.MallApplyDTO(); model.Id = item.Id; model.SubTime = item.SubTime; model.ModifiedOn = item.ModifiedOn; model.AppId = item.AppId; model.EsAppId = item.EsAppId; model.AppName = item.AppName; model.EsAppName = item.EsAppName; model.ApplyContent = item.ApplyContent; int State = Convert.ToInt32(item.State.Value); #region 获取基础佣金比例 var baseCommission = baseCommissionlist .Where(p => p.MallApplyId == item.Id) .OrderByDescending(p => p.SubTime).FirstOrDefault(); if (baseCommission != null) { model.Commission = baseCommission.Commission; } #endregion model.State = State; model.StateShow = new EnumHelper().GetDescription((MallApplyEnum)State); //model.StateShow = (State == 0 // ? new EnumHelper().GetDescription(MallApplyEnum.RZSQ) // : State == 1 // ? new EnumHelper().GetDescription(MallApplyEnum.QXRZ) // : State == 2 // ? new EnumHelper().GetDescription(MallApplyEnum.TG) // : State == 3 // ? new EnumHelper().GetDescription(MallApplyEnum.BTG) // : State == 4 // ? new EnumHelper().GetDescription(MallApplyEnum.GQ) // : State == 5 // ? new EnumHelper().GetDescription(MallApplyEnum.QXRZQR) : ""); model.Type = item.Type; model.TypeString = item.GetTypeString(); model.IsAllSetSettlePrice = true; if (model.Type == 0) { // 查询是否有商品未设置结算价 if (Commodity.ObjectSet().Where(a => a.AppId == item.AppId && !a.IsDel).Count() > commoditySettleAmountQuery.Where(b => b.AppId == item.AppId).GroupBy(c => c.CommodityId).Select(g => g.Key).Count()) { model.IsAllSetSettlePrice = false; } } searchlist.Add(model); } return(searchlist); }
/// <summary> /// 根据订单生成待结算项 /// </summary> public static SettleAccountsDetails CreateSettleAccountDetails(ContextSession contextSession, CommodityOrder commodityOrder, MallApply mall, int?orderServiceState = null) { //LogHelper.Info("开始生成结算项,订单ID:" + commodityOrder.Id); var currentDate = DateTime.Now; // 1:商家,2:金和众销(给金和分的钱),3:商贸众销(给分享者分的钱),4:商贸众筹,5:推广主分成,6:应用主分成,7金和分润,8买家,9一级分销,10二级分销,11三级分销,12渠道推广,20:一级代理,21:二级代理 //var payeeType = new List<int> { 3, 5, 9, 10, 11, 20, 21 }; //var orderitemlist = OrderItem.ObjectSet().Where(n => n.CommodityOrderId == commodityOrder.Id). // GroupJoin(OrderItemShare.ObjectSet().Where(s => payeeType.Contains(s.PayeeType)), o => o.Id, s => s.OrderItemId, (o, s) => // new { o.Id, o.Name, o.Number, o.RealPrice, o.CommodityId, o.ComCategoryId, Commission = s.Sum(_ => (decimal?)_.Commission) }).ToList(); // 暂不计算推广佣金 var orderitemlist = OrderItem.ObjectSet().Where(n => n.CommodityOrderId == commodityOrder.Id).Select(o => new { o.Id, o.Name, o.Number, o.RealPrice, o.CommodityId, o.ComCategoryId, o.CommodityAttributes }).ToList(); bool isSetSettleAmount = true; List <SettleAccountsOrderItem> items = new List <SettleAccountsOrderItem>(); var payTime = commodityOrder.PaymentTime.Value; foreach (var orderItem in orderitemlist) { // 结算单订单项 SettleAccountsOrderItem saItem = new SettleAccountsOrderItem(); saItem.Id = saItem.OrderItemId = orderItem.Id; saItem.ModifiedOn = saItem.SubTime = currentDate; saItem.OrderId = commodityOrder.Id; saItem.OrderItemRefundAmount = 0; // 暂无单品退货 saItem.OrderItemPromotionCommissionAmount = 0M; // orderItem.Commission ?? 0M; saItem.OrderItemName = orderItem.Name; saItem.OrderItemNumber = orderItem.Number; saItem.OrderItemPrice = orderItem.RealPrice.Value; // 自营他配 if (mall.Type == 0) { var commoditySettleAmount = CommoditySettleAmount.ObjectSet() .Where(c => c.CommodityId == orderItem.CommodityId && c.EffectiveTime < payTime) .OrderByDescending(c => c.SubTime) .ThenByDescending(c => c.EffectiveTime) .FirstOrDefault(); if (commoditySettleAmount == null) { // 未设置结算价,暂不结算 //LogHelper.Info("开始生成结算项,订单ID:" + commodityOrder.Id + ",自营商家,未设置结算价,商品ID:" + orderItem.CommodityId); return(null); } //LogHelper.Info("开始生成结算项,订单ID:" + commodityOrder.Id + ",自营商家,商品ID:" + orderItem.CommodityId + ",商品属性:" + orderItem.CommodityAttributes + ",结算价:" + commoditySettleAmount.CommodityAttrJson); var saAttrs = JsonHelper.JsonDeserialize <List <Jinher.AMP.BTP.Deploy.CustomDTO.CommodityAttributePrice> >(commoditySettleAmount.CommodityAttrJson); var attrs = (orderItem.CommodityAttributes ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (attrs.Length == 0) { // 无属性 saItem.SettleAmount = saAttrs[0].SettlePrice.Value; } else if (attrs.Length == 1) { // 单属性 var settlePrice = saAttrs.Where(a => a.AttributeValue == attrs[0]).FirstOrDefault(); if (settlePrice == null) { LogHelper.Error("SettleAccountHelper.CreateSettleAccountDetails 生成结算单失败,结算价设置异常,商品ID:" + orderItem.CommodityId + ",商品属性:" + orderItem.CommodityAttributes + ",结算价ID:" + commoditySettleAmount.Id + ",结算价属性:" + commoditySettleAmount.CommodityAttrJson); return(null); } saItem.SettleAmount = settlePrice.SettlePrice.Value; } else if (attrs.Length == 2) { // 双属性 var settlePrice = saAttrs.Where(a => (a.AttributeValue == attrs[0] && a.SecAttributeValue == attrs[1]) || (a.AttributeValue == attrs[1] && a.SecAttributeValue == attrs[0])) .FirstOrDefault(); if (settlePrice == null) { LogHelper.Error("SettleAccountHelper.CreateSettleAccountDetails 生成结算单失败,结算价设置异常,商品ID:" + orderItem.CommodityId + ",商品属性:" + orderItem.CommodityAttributes + ",结算价ID:" + commoditySettleAmount.Id + ",结算价属性:" + commoditySettleAmount.CommodityAttrJson); return(null); } saItem.SettleAmount = settlePrice.SettlePrice.Value; } else { LogHelper.Error("SettleAccountHelper.CreateSettleAccountDetails 生成结算单失败,商品属性异常,商品ID:" + orderItem.CommodityId + ",商品属性:" + orderItem.CommodityAttributes); return(null); } //orderItem.com } // 第三方 else if (mall.Type == 1) { // 查询商品易捷币抵用数量 var yjbInfo = YJBSV.GetOrderItemYJBInfo(commodityOrder.EsAppId.Value, commodityOrder.Id); if (!yjbInfo.IsSuccess) { saItem.OrderItemYJBAmount = 0; } else { var currentCommodityYJBInfo = yjbInfo.Data.Items.Where(c => c.CommodityId == orderItem.CommodityId).FirstOrDefault(); if (currentCommodityYJBInfo != null && currentCommodityYJBInfo.IsMallYJB) { saItem.OrderItemYJBAmount = currentCommodityYJBInfo.InsteadCashAmount; } } // 计算实际成交价 #region 计算商品佣金比例 // 获取佣金比例:按结算日期获取有效的(启用日期小于等于结算日期的最近一次设置的佣金比例)佣金比例【基础、类目、商品】; saItem.BaseCommission = BaseCommission.ObjectSet().Join(MallApply.ObjectSet(), b => b.MallApplyId, m => m.Id, (b, m) => new { b.Commission, b.EffectiveTime, b.SubTime, m.AppId, m.EsAppId }). Where(t => t.EsAppId == commodityOrder.EsAppId && t.AppId == commodityOrder.AppId && t.EffectiveTime < payTime). OrderByDescending(t => t.SubTime).Select(t => (decimal?)t.Commission).FirstOrDefault(); // 查询当前商品的类目 List <Guid> categoryIds = new List <Guid>(); var tempCategories = CommodityCategory.ObjectSet().Where(c => c.AppId == commodityOrder.EsAppId && c.CommodityId == orderItem.CommodityId).Join(Category.ObjectSet(), cc => cc.CategoryId, c => c.Id, (cc, c) => new { c.Id, c.CurrentLevel, c.ParentId, cc.IsDel }).ToList(); foreach (var item in tempCategories) { if (item.IsDel.HasValue && item.IsDel.Value) { continue; } if (item.CurrentLevel == 3 || item.CurrentLevel == 4 || item.CurrentLevel == 5) { var lv2 = Category.FindByID(item.ParentId.Value); if (item.CurrentLevel == 3) { categoryIds.Add(lv2.ParentId.Value); continue; } var lv3 = Category.FindByID(lv2.ParentId.Value); if (item.CurrentLevel == 4) { categoryIds.Add(lv3.ParentId.Value); continue; } var lv4 = Category.FindByID(lv3.ParentId.Value); categoryIds.Add(lv4.ParentId.Value); } else if (item.CurrentLevel == 2) { categoryIds.Add(item.ParentId.Value); } else if (item.CurrentLevel == 1) { categoryIds.Add(item.Id); } } var commissions = CategoryCommission.ObjectSet(). Join(MallApply.ObjectSet(), b => b.MallApplyId, m => m.Id, (b, m) => new { b.CategoryId, b.Commission, b.EffectiveTime, b.SubTime, m.AppId, m.EsAppId }). Where(t => t.EsAppId == commodityOrder.EsAppId && t.AppId == commodityOrder.AppId && categoryIds.Contains(t.CategoryId) && t.EffectiveTime < payTime). GroupBy(t => t.CategoryId). Select(group => group.OrderByDescending(g => g.SubTime).Select(g => g.Commission).FirstOrDefault()). ToList(); if (commissions.Count > 0) { saItem.CategoryCommission = commissions.Min(); } saItem.CommodityCommission = CommodityCommission.ObjectSet().Join(MallApply.ObjectSet(), b => b.MallApplyId, m => m.Id, (b, m) => new { b.CommodityId, b.Commission, b.EffectiveTime, b.SubTime, m.AppId, m.EsAppId }). Where(t => t.EsAppId == commodityOrder.EsAppId && t.AppId == commodityOrder.AppId && t.CommodityId == orderItem.CommodityId && t.EffectiveTime < payTime). OrderByDescending(t => t.SubTime).Select(t => (decimal?)t.Commission).FirstOrDefault(); #endregion // 商城佣金计算公式:商品销售价*佣金比例【商品佣金优先,类目佣金其次、基础佣金最后,三选一计算】* 购买数量; saItem.PromotionAmount = Math.Truncate( (saItem.CommodityCommission.HasValue ? saItem.CommodityCommission.Value : (saItem.CategoryCommission.HasValue ? saItem.CategoryCommission.Value : (saItem.BaseCommission.HasValue ? saItem.BaseCommission.Value : 0) )) * saItem.OrderItemPrice * saItem.OrderItemNumber) / 100; } saItem.EntityState = EntityState.Added; items.Add(saItem); } // 结算单订单详情 SettleAccountsDetails sad = new SettleAccountsDetails(); sad.Id = sad.OrderId = commodityOrder.Id; sad.EntityState = EntityState.Added; sad.ModifiedOn = sad.SubTime = currentDate; sad.IsSettled = false; sad.AppId = commodityOrder.AppId; sad.EsAppId = commodityOrder.EsAppId.Value; sad.OrderCode = commodityOrder.Code; sad.OrderSubTime = payTime; sad.OrderAmount = commodityOrder.Price; sad.OrderRealAmount = commodityOrder.RealPrice.Value; sad.OrderFreight = commodityOrder.Freight; sad.IsSetSettleAmount = isSetSettleAmount; // 导入订单时,记录退款金额 if (commodityOrder.State == 7 || orderServiceState == 7) { var refund = OrderRefundAfterSales.ObjectSet().Where(o => o.OrderId == commodityOrder.Id).FirstOrDefault(); // 全额退款 不计入结算单 if (refund.IsFullRefund == 1) { sad.IsSettled = true; if (contextSession != null) { foreach (var item in items) { contextSession.SaveObject(item); } contextSession.SaveObject(sad); } return(sad); } else { sad.OrderRefundAmount = refund.RefundMoney; } } else { sad.OrderRefundAmount = 0; // 暂无单品退货 } //// 计算商城优惠券金额 //var orderP ayDetailId = OrderPayDetail.ObjectSet().Where(c => c.OrderId == commodityOrder.Id && c.ObjectType == 1).Select(c => c.ObjectId).FirstOrDefault(); //if (orderPayDetailId != Guid.Empty) //{ // var request = new Coupon.Deploy.CustomDTO.ListCouponNewRequestDTO // { // CouponIds = new List<Guid> { orderPayDetailId }, // UserId = commodityOrder.UserId // }; // var coupons = CouponSV.Instance.GetUserCouponsByIds(request); // if (coupons.IsSuccess) // { // var firstCoupon = coupons.Data[0]; // sad.OrderCouponAmount = firstCoupon.Cash; // // 判断是否为电商馆 // sad.IsMallCoupon = ZPHSV.Instance.IsAppPavilion(firstCoupon.ShopId); // } // else // { // LogHelper.Error(string.Format("CouponSV.GetUserCouponsByIds返回结果不成功,入参 CouponIds: {0} UserId: {1},出参 Code: {2} Info: {3}。", orderPayDetailId, commodityOrder.UserId, coupons.Code, coupons.Info)); // } //} // 计算商家结算金额 decimal spreadMoney = 0; if (commodityOrder.SpreadGold > 0) { spreadMoney = commodityOrder.SpreadGold.ToMoney(); } sad.OrderSpreadAmount = spreadMoney; // 1.第三方 if (mall.Type == 1) { sad.OrderYJBAmount = items.Sum(i => i.OrderItemYJBAmount); // 商城佣金 sad.PromotionAmount = items.Sum(i => i.PromotionAmount); // 优先级:1推广主、2三级分销、 3众销 //sad.OrderPromotionCommissionAmount = commodityOrder.SpreadGold > 0 ? commodityOrder.SpreadGold.ToMoney() : // commodityOrder.DistributeMoney > 0 ? commodityOrder.DistributeMoney : commodityOrder.Commission; // 老版本,已弃 商家结算金额 = 订单总额 + 商城优惠券总金额 - 退款总金额 - 推广佣金总额 - 商城佣金总额 // 版本1:商家结算金额 = 实收款 + 商城易捷币抵用金额 - 退款金额 - 商城佣金 // 版本2:商家结算金额 = 实收款 + 商城易捷币抵用金额 - 退款金额 - 商城佣金 - 推广佣金总额 // 商家结算金额 sad.SellerAmount = Math.Truncate((sad.OrderRealAmount + sad.OrderYJBAmount - sad.OrderRefundAmount - sad.PromotionAmount - sad.OrderSpreadAmount.Value) * 100) / 100; } // 0.自营他配 else if (mall.Type == 0) { // 商品结算价 decimal totalsSettlePrice = 0; foreach (var item in items) { totalsSettlePrice += item.SettleAmount * item.OrderItemNumber; } sad.SettleAmount = totalsSettlePrice; // 商家结算金额 = 商品结算价*数量 + 运费 - 退款金额 sad.SellerAmount = Math.Truncate((sad.SettleAmount + sad.OrderFreight - sad.OrderRefundAmount) * 100) / 100; // 商城佣金 sad.PromotionAmount = Math.Truncate((sad.OrderRealAmount - sad.SellerAmount - sad.OrderSpreadAmount.Value) * 100) / 100; } // 2.自营自配自采 // 3.自营自配统采 if (contextSession != null) { foreach (var item in items) { contextSession.SaveObject(item); } contextSession.SaveObject(sad); } return(sad); }
/// <summary> /// 担保交易(金币)支付,生成结算单 /// </summary> public static SettleAccounts CreateSettleAccount(ContextSession contextSession, CommodityOrder commodityOrder, MallApply mall) { if (!CheckPayType(commodityOrder)) { return(null); } if (mall == null) { LogHelper.Info("生成结算项失败,商城中未找到该APP,订单ID:" + commodityOrder.Id); return(null); } var sad = CreateSettleAccountDetails(contextSession, commodityOrder, mall); if (sad == null) { return(null); } LogHelper.Info("担保交易(金币)支付,生成结算单,OrderId:" + commodityOrder.Id); // 结算单 SettleAccounts sa = new SettleAccounts(); sad.SAId = sa.Id = Guid.NewGuid(); sa.UserId = Guid.Empty; // 系统生成结算单,UserId为空 sa.AmountDate = sa.ModifiedOn = sa.SubTime = DateTime.Now; sa.AppId = commodityOrder.AppId; sa.AppName = APPSV.GetAppName(sa.AppId); sa.EsAppId = commodityOrder.EsAppId.Value; sa.SellerType = mall.Type; var pInfo = ZPHSV.Instance.GetAppPavilionInfo(new Jinher.AMP.ZPH.Deploy.CustomDTO.QueryAppPavilionParam { id = sa.EsAppId }); if (string.IsNullOrEmpty(pInfo.pavilionName)) { sa.EsAppName = "未找到"; LogHelper.Error("OrderSV.CreateSettleAccount 生成结算单异常:未能从 ZPHSV.Instance.GetAppPavilionInfo 获取到场管名称。OrderId:" + commodityOrder.Id); } sa.EsAppName = pInfo.pavilionName; sa.OrderAmount = sad.OrderAmount; sa.OrderRealAmount = sad.OrderRealAmount; sa.CouponAmount = sad.OrderCouponAmount; sa.RefundAmount = sad.OrderRefundAmount; sa.PromotionCommissionAmount = sad.OrderPromotionCommissionAmount; sa.PromotionAmount = sad.PromotionAmount; sa.SellerAmount = sad.SellerAmount; sa.OrderYJBAmount = sad.OrderYJBAmount; sa.IsAmount = true; sa.SettleStatue = true; Random rd = new Random(); sa.Code = DateTime.Now.ToString("yyyyMMddHHmmss") + rd.Next(9999).ToString("D4"); if (sad.IsMallCoupon) { // 当商城佣金小于商城优惠券金额时,则商城不分佣金,表示当前订单结算异常,结算结果为:结算异常; if (sad.PromotionAmount < sad.OrderCouponAmount) { sa.PromotionAmount = 0; sa.SellerAmount += sa.PromotionAmount; sa.SettleStatue = false; } } else { // 当商家的结算金额小于0时,则先结算推广佣金,而后结算商城佣金,表示当前订单结算异常,结算结果为:结算异常; if (sa.SellerAmount < 0) { sa.SettleStatue = false; } } sa.State = new Deploy.SettleAccountsVO() { Value = 3 }; sa.EntityState = EntityState.Added; sad.IsSettled = true; sad.SAId = sa.Id; contextSession.SaveObject(sa); return(sa); }
public static MallApply GetMallApply(CommodityOrder commodityOrder) { // 查询场馆信息 return(MallApply.ObjectSet().Where(m => m.AppId == commodityOrder.AppId && m.EsAppId == commodityOrder.EsAppId && (m.State.Value == 2 || m.State.Value == 4)).FirstOrDefault()); }
/// <summary> /// 商家的移动坐席数据 /// </summary> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <param name="recordCount"></param> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <System.Collections.Generic.List <Jinher.AMP.BTP.Deploy.CustomDTO.AppSceneUserDTO> > GetAppSceneContentExt(int pageIndex) { LogHelper.Debug("进入客服服务,调用根据appId获取商家的移动坐席数据:请求时间:" + DateTime.Now); ResultDTO <List <AppSceneUserDTO> > Result = new ResultDTO <List <AppSceneUserDTO> > { isSuccess = false, Message = "查询失败" }; try { Jinher.AMP.SNS.ISV.Facade.AppSceneUserQueryFacade Facade = new SNS.ISV.Facade.AppSceneUserQueryFacade(); int pageSize = 100; var YJAppList = MallApply.ObjectSet().Where(p => p.EsAppId == Jinher.AMP.YJB.Deploy.CustomDTO.YJBConsts.YJAppId && p.State.Value == 2).Select(s => s.AppId);//获取分页数据 List <AppSceneUserDTO> AppSceneList = new List <AppSceneUserDTO>(); foreach (var item in YJAppList) { var AppSceneUser = Facade.GetAppSceneUser(item); if (AppSceneUser.Code == "0" && AppSceneUser.Content.Any()) { /*var AppScene = AppSceneUser.Content.Select(s => new AppSceneUserDTO * { * appId = item, * SceneId = s.SceneId, * SceneName = s.SceneName, * UserId = s.UserId, * UserName = s.UserName, * Account = GetCustomInfoExt(s.UserId).Data.Account, * Birthday = GetCustomInfoExt(s.UserId).Data.Birthday, * HeadIcon = GetCustomInfoExt(s.UserId).Data.HeadIcon * }).ToList();*/ var AppScene = new List <AppSceneUserDTO>(); foreach (var content in AppSceneUser.Content) { if (!string.IsNullOrEmpty(content.UserId.ToString())) { var user = GetCustomInfoExt(content.UserId); var userdto = new AppSceneUserDTO { appId = item, SceneId = content.SceneId, SceneName = content.SceneName, UserId = content.UserId, UserName = content.UserName, Account = user.Data.Account, Birthday = user.Data.Birthday, HeadIcon = user.Data.HeadIcon }; AppScene.Add(userdto); } else { var userdto = new AppSceneUserDTO { appId = item, SceneId = content.SceneId, SceneName = content.SceneName, UserId = content.UserId, UserName = content.UserName }; AppScene.Add(userdto); } } AppSceneList.AddRange(AppScene); } } if (AppSceneList.Any()) { Result.Data = AppSceneList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); //返回分页数据 Result.isSuccess = true; Result.Message = "获取成功"; } } catch (Exception ex) { Result.Message = "获取异常"; LogHelper.Error("CustomSV.GetAppSceneContentExt。根据appId获取商家的移动坐席数据:", ex); } return(Result); }
/// <summary> /// 修改商城信息状态 /// </summary> /// <returns></returns> public ResultDTO UpdateMallApplyExt(Jinher.AMP.BTP.Deploy.CustomDTO.MallApply.MallApplyDTO model) { ResultDTO dto = null; try { ContextSession contextSession = ContextFactory.CurrentThreadContext; var mallapply = MallApply.ObjectSet().FirstOrDefault(p => p.Id == model.Id); if (mallapply != null) { if (!string.IsNullOrWhiteSpace(model.AppId.ToString()) && (!model.AppId.ToString().Contains("00000000-0000-0000-0000-000000000000"))) { mallapply.AppId = model.AppId; } if (!string.IsNullOrWhiteSpace(model.EsAppId.ToString()) && (!model.EsAppId.ToString().Contains("00000000-0000-0000-0000-000000000000"))) { mallapply.EsAppId = model.EsAppId; } if (!string.IsNullOrWhiteSpace(model.UserId.ToString()) && (!model.UserId.ToString().Contains("00000000-0000-0000-0000-000000000000"))) { mallapply.UserId = model.UserId; } if (!string.IsNullOrWhiteSpace(model.AppName)) { mallapply.AppName = model.AppName; } if (!string.IsNullOrWhiteSpace(model.EsAppName)) { mallapply.EsAppName = model.EsAppName; } mallapply.ModifiedOn = DateTime.Now; if (!string.IsNullOrWhiteSpace(model.State.ToString())) { mallapply.State = new ApplyStateVO { Value = model.State }; } if (!string.IsNullOrWhiteSpace(model.ApplyContent)) { mallapply.ApplyContent = model.ApplyContent; } if (Convert.ToBoolean(model.CrcAppId)) { mallapply.CrcAppId = model.CrcAppId; } if (model.Type.HasValue) { mallapply.Type = model.Type.Value; } mallapply.EntityState = EntityState.Modified; // 同步Supplier表 if (model.Type.HasValue) { var supplier = Supplier.ObjectSet().Where(_ => _.EsAppId == mallapply.EsAppId && _.AppId == mallapply.AppId && !_.IsDel).FirstOrDefault(); if (supplier != null) { if (supplier.SupplierType != mallapply.Type) { supplier.SupplierType = mallapply.Type; supplier.EntityState = System.Data.EntityState.Modified; contextSession.SaveObject(supplier); } } } contextSession.SaveChanges(); dto = new ResultDTO() { ResultCode = 0, Message = "修改成功", isSuccess = true }; } else { dto = new ResultDTO() { ResultCode = 1, Message = "该信息不存在", isSuccess = false }; } } catch (Exception ex) { LogHelper.Error(string.Format("商家信息保存异常。MallApply:{0}", ex.Message)); dto = new ResultDTO() { ResultCode = 1, Message = ex.Message, isSuccess = false }; } return(dto); }