/// <summary> /// 获取特定app在电商中的当前生效的积分扩展信息。 /// </summary> /// <param name="paramDto">查询参数</param> /// <returns></returns> public ResultDTO <UserScoreDTO> GetUserScoreInAppExt(Param2DTO paramDto) { Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.UserScoreDTO> result = new ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.UserScoreDTO>(); UserScoreDTO usDto = new UserScoreDTO(); result.Data = usDto; try { if (paramDto == null) { result.Message = "参数错误,参数不能为空!"; result.ResultCode = 1; return(result); } if (paramDto.UserId == Guid.Empty) { result.Message = "参数错误,appId不能为空!"; result.ResultCode = 1; return(result); } if (paramDto.AppId == Guid.Empty) { result.Message = "参数错误,appId不能为空!"; result.ResultCode = 1; return(result); } var appIsCashForScore = (from ae in AppExtension.ObjectSet() where ae.Id == paramDto.AppId select ae.IsCashForScore).FirstOrDefault(); if (appIsCashForScore == null || appIsCashForScore == false) { usDto.IsCashForScore = false; return(result); } usDto.IsCashForScore = appIsCashForScore; var ssFirst = (from ss in ScoreSetting.ObjectSet() where ss.AppId == paramDto.AppId orderby ss.SubTime descending select ss.ScoreCost).FirstOrDefault(); if (!ssFirst.HasValue) { return(result); } usDto.ScoreCost = ssFirst.Value; int score = Jinher.AMP.BTP.TPS.SignSV.Instance.GiveUserScore(paramDto.UserId, paramDto.AppId); usDto.Score = score; usDto.Money = DecimalExt.ToMoney((decimal)score / usDto.ScoreCost); } catch (Exception ex) { string str = string.Format("ScoreSettingSV.GetUserScoreInAppExt中发生异常,参数AppId:{0},异常信息:{1}", paramDto.AppId, ex); LogHelper.Error(str); result.Message = "服务异常!"; result.ResultCode = 2; } return(result); }
/// <summary> /// 获取特定app在电商中的当前生效的扩展信息。 /// </summary> /// <param name="appId">应用id</param> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <Jinher.AMP.BTP.Deploy.ScoreSettingDTO> GetScoreSettingByAppIdExt(System.Guid appId) { Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <Jinher.AMP.BTP.Deploy.ScoreSettingDTO> resultAppExt = new ResultDTO <ScoreSettingDTO>(); try { if (appId == Guid.Empty) { resultAppExt.Message = "参数错误,appId不能为空!"; resultAppExt.ResultCode = 1; } var aeList = (from ae in ScoreSetting.ObjectSet() where ae.AppId == appId orderby ae.SubTime descending select ae).ToList(); if (aeList.Any()) { var aeFirst = aeList.FirstOrDefault(); ScoreSettingDTO aeDto = aeFirst.ToEntityData(); resultAppExt.Data = aeDto; } } catch (Exception ex) { string str = string.Format("ScoreSettingSV.GetScoreSettingByAppIdExt中发生异常,参数AppId:{0},异常信息:{1}", appId, ex); LogHelper.Error(str); resultAppExt.Message = "服务异常!"; resultAppExt.ResultCode = 2; } return(resultAppExt); }
/// <summary> /// 获取某时间点积分汇率 /// </summary> /// <param name="appId">应用id</param> /// <param name="cost"></param> /// <param name="time">时间点</param> /// <returns>校验是否成功</returns> public bool CheckOrderScoreCost(Guid appId, out int cost, DateTime time) { cost = 0; var signResult = SignSV.Instance.GetCurrencyScoreCost(appId, time); if (signResult == null) { return(false); } if (signResult.IsUnitiveScore) { cost = signResult.ExchangeRate; } else { var scoreSetting = (from ss in ScoreSetting.ObjectSet() where ss.AppId == appId && ss.SubTime <= time orderby ss.SubTime descending select new { Id = ss.Id, ScoreCost = ss.ScoreCost }).FirstOrDefault(); if (scoreSetting == null || scoreSetting.ScoreCost == null) { return(true); } cost = scoreSetting.ScoreCost.Value; } return(true); }
/// <summary> /// 获取某时间点积分汇率 /// </summary> /// <param name="appId">应用id</param> /// <param name="resultDto"></param> /// <param name="time">时间点</param> /// <returns></returns> public bool GetScoreCost(Guid appId, out CostScoreInfoDTO resultDto, DateTime time) { resultDto = new CostScoreInfoDTO(); var signResult = SignSV.Instance.GetCurrencyScoreCost(appId, time); if (signResult == null) { return(false); } if (signResult.IsUnitiveScore) { resultDto.Cost = signResult.ExchangeRate; resultDto.ScoreType = ScoreTypeEnum.Currency; } else { var scoreSetting = (from ss in ScoreSetting.ObjectSet() where ss.AppId == appId && ss.SubTime <= time orderby ss.SubTime descending select new { Id = ss.Id, ScoreCost = ss.ScoreCost }).FirstOrDefault(); if (scoreSetting == null || scoreSetting.ScoreCost == null) { return(false); } resultDto.Cost = scoreSetting.ScoreCost.Value; resultDto.ScoreType = ScoreTypeEnum.Self; } return(true); }
/// <summary> /// 获取app的积分抵现设置 /// </summary> /// <param name="appId"></param> /// <returns></returns> public AppScoreSettingDTO GetScoreSettingExt(Guid appId) { AppScoreSettingDTO result = new AppScoreSettingDTO(); if (appId == Guid.Empty) { return(result); } var appExtension = AppExtension.ObjectSet().FirstOrDefault(c => c.Id == appId); if (appExtension != null && appExtension.IsCashForScore) { result.IsCashForScore = true; } var scoreSetting = ScoreSetting.ObjectSet().Where(c => c.AppId == appId).OrderByDescending(c => c.SubTime).FirstOrDefault(); if (scoreSetting != null && scoreSetting.ScoreCost > 0) { result.ScoreCost = scoreSetting.ScoreCost.Value; } return(result); }
/// <summary> /// 修改用户支付方式 /// </summary> /// <param name="paymentsDTO">支付方式实体</param> /// <returns></returns> public ResultDTO UpdatePaymentExt(PaymentsVM paymentsVM) { if (paymentsVM == null || paymentsVM.PaymentIds == null || !paymentsVM.PaymentIds.Any()) { return new ResultDTO { ResultCode = 1, Message = "支付方式不能为空" } } ; if (paymentsVM.AppScoreSetting == null) { paymentsVM.AppScoreSetting = new AppScoreSettingDTO(); } //app是否有积分功能项 var isMyIntegral = BACBP.CheckMyIntegral(paymentsVM.AppId); if (isMyIntegral && paymentsVM.AppScoreSetting.IsCashForScore && CustomConfig.ScoreCostList.All(c => c != paymentsVM.AppScoreSetting.ScoreCost)) { return(new ResultDTO { ResultCode = 2, Message = "积分设置不合法" }); } Payments p = new Payments(); List <Payments> payments = Payments.ObjectSet().Where(n => n.AppId == paymentsVM.AppId).ToList(); ContextSession contextSession = ContextFactory.CurrentThreadContext; try { foreach (Payments item in payments) { item.EntityState = System.Data.EntityState.Deleted; contextSession.Delete(item); } if (paymentsVM.PaymentIds != null && paymentsVM.PaymentIds.Count() > 0) { foreach (var item in paymentsVM.PaymentIds) { Guid payId; if (!Guid.TryParse(item, out payId)) { continue; } string name = AllPayment.ObjectSet().Where(n => n.Id == payId).Select(n => n.PaymentName).FirstOrDefault(); DateTime dt = DateTime.Now; PaymentsDTO paymentsDTO = new PaymentsDTO(); paymentsDTO.Id = Guid.NewGuid(); paymentsDTO.Name = name; paymentsDTO.AppId = paymentsVM.AppId; paymentsDTO.Code = dt.ToFileTime().ToString(); paymentsDTO.SubTime = DateTime.Now; paymentsDTO.SubId = paymentsVM.AppId; paymentsDTO.PaymentId = new Guid(item); paymentsDTO.IsOnuse = paymentsVM.IsOnuse; paymentsDTO.PaymentName = name; if (name == "支付宝") { paymentsDTO.AliPayPartnerId = paymentsVM.AliPayPartnerId; paymentsDTO.AliPayPrivateKey = paymentsVM.AliPayPrivateKey; paymentsDTO.AliPayPublicKey = paymentsVM.AliPayPublicKey; paymentsDTO.AliPaySeller = paymentsVM.AliPaySeller; paymentsDTO.AliPayVerifyCode = paymentsVM.AliPayVerifyCode; } paymentsDTO.EntityState = System.Data.EntityState.Added; Payments payment = new Payments().FromEntityData(paymentsDTO); contextSession.SaveObject(payment); } } //保存积分抵现设置 if (isMyIntegral) { var appExt = AppExtension.ObjectSet().FirstOrDefault(c => c.Id == paymentsVM.AppId); if (appExt != null) { appExt.IsCashForScore = paymentsVM.AppScoreSetting.IsCashForScore; appExt.ModifiedOn = DateTime.Now; appExt.EntityState = EntityState.Modified; } else { appExt = AppExtension.CreateAppExtension(); appExt.Id = paymentsVM.AppId; appExt.IsCashForScore = paymentsVM.AppScoreSetting.IsCashForScore; contextSession.SaveObject(appExt); } if (paymentsVM.AppScoreSetting.IsCashForScore) { //差异判断,设置不变,不重新保存 var lastScoreSetting = ScoreSetting.ObjectSet().Where(c => c.AppId == paymentsVM.AppId).OrderByDescending(c => c.SubTime).FirstOrDefault(); if (lastScoreSetting == null || lastScoreSetting.ScoreCost != paymentsVM.AppScoreSetting.ScoreCost) { ScoreSetting scoreSetting = ScoreSetting.CreateScoreSetting(); scoreSetting.ScoreCost = paymentsVM.AppScoreSetting.ScoreCost; scoreSetting.AppId = paymentsVM.AppId; contextSession.SaveObject(scoreSetting); } } } contextSession.SaveChange(); //删除缓存 Jinher.JAP.Cache.GlobalCacheWrapper.Remove("G_PaymentInfo", paymentsVM.AppId.ToString(), "BTPCache"); Jinher.JAP.Cache.GlobalCacheWrapper.Remove("G_AliPayInfo", paymentsVM.AppId.ToString(), "BTPCache"); } catch (Exception ex) { LogHelper.Error(string.Format("修改用户支付方式服务异常。paymentsVM:{0}", JsonHelper.JsonSerializer(paymentsVM)), ex); return(new ResultDTO { ResultCode = 1, Message = "Error" }); } return(new ResultDTO { ResultCode = 0, Message = "Success" }); }
public ResultDTO <OrderScoreCheckResultDTO> OrderScoreCheckExt(OrderScoreCheckDTO paramDto) { ResultDTO <OrderScoreCheckResultDTO> result = new ResultDTO <OrderScoreCheckResultDTO>() { Message = "Success", Data = new OrderScoreCheckResultDTO() }; //OrderScoreCheckResultDTO resultData = new OrderScoreCheckResultDTO(); //resultData.IsCashForScore = true; //resultData.Score = 120000; //resultData.ScoreCost = 100; //resultData.ScoreType = ScoreTypeEnum.Self; //var price = (paramDto.Coms[0].RealPrice * paramDto.Coms[0].Num / 10.0m).ToMoney(); //resultData.Money = price; //resultData.List = new List<AppScoreDTO>(){new AppScoreDTO() // { // AppId = paramDto.EsAppId, // Money = price // }}; //result.Data = resultData; //return result; DateTime now = DateTime.Now; if (paramDto == null || paramDto.EsAppId == Guid.Empty || paramDto.Coms == null || !paramDto.Coms.Any()) { return new ResultDTO <OrderScoreCheckResultDTO>() { ResultCode = 1, Message = "参数有误" } } ; var comIds = paramDto.Coms.Select(c => c.CommodityId).Distinct().ToList(); var coms = Commodity.ObjectSet().Where(c => comIds.Contains(c.Id)).Select(m => new CommodityDTO { Id = m.Id, Price = m.Price, AppId = m.AppId, ScorePercent = m.ScorePercent }).ToList(); var appIds = coms.Select(c => c.AppId).ToList(); appIds.Add(paramDto.EsAppId); appIds = appIds.Distinct().ToList(); var appExts = AppExtension.ObjectSet() .Where(c => appIds.Contains(c.Id) && c.IsCashForScore && c.IsScoreAll != null) .Select(c => new Deploy.AppExtensionDTO() { Id = c.Id, IsCashForScore = c.IsCashForScore, IsScoreAll = c.IsScoreAll, ScorePercent = c.ScorePercent }) .ToList(); Dictionary <Guid, Deploy.AppExtensionDTO> appExtDict = appExts.ToDictionary(x => x.Id, y => y); //获取支持积分抵现所有app,(不支持积分抵现、未设置积分抵现比例均视为不支持积分抵现) var cashForScoreAppIds = appExts.Select(c => c.Id).ToList(); //如果所有的app都没有启用积分抵现,直接返回 if (!cashForScoreAppIds.Any()) { return(result); } List <Deploy.CommodityStockDTO> comStocks = getComStocks(paramDto); #region 获取可参加积分抵现商品 List <ComScoreCheckReDTO> canScoreComList = new List <ComScoreCheckReDTO>(); foreach (var requestCom in paramDto.Coms) { var com = coms.First(c => c.Id == requestCom.CommodityId); if (cashForScoreAppIds.All(c => c != com.AppId)) { continue; } Deploy.CommodityStockDTO comStock = null; if (requestCom.CommodityStockId != null && requestCom.CommodityStockId != Guid.Empty) { comStock = comStocks.FirstOrDefault(c => c.Id == requestCom.CommodityStockId); } if (getOriPrice(com, comStock) == requestCom.RealPrice) { var scorePercent = appExtDict[com.AppId].IsScoreAll == true ? (decimal?)appExtDict[com.AppId].ScorePercent : com.ScorePercent; if (!scorePercent.HasValue || scorePercent <= 0) { continue; } var item = ComScoreCheckReDTO.FromRequest(requestCom, com.AppId); item.CanScoreMoney = (requestCom.RealPrice * requestCom.Num * scorePercent.Value).ToMoney(); if (item.CanScoreMoney <= 0) { continue; } canScoreComList.Add(item); } } //只有不参加活动的商品才可以使用积分抵现 if (!canScoreComList.Any()) { return(result); } #endregion var checkResult = SignSV.Instance.QueryAllScores(appIds, paramDto.UserId); if (checkResult == null || checkResult.ScoreDetailList == null || !checkResult.ScoreDetailList.Any()) { return new ResultDTO <OrderScoreCheckResultDTO>() { ResultCode = 1, Message = "积分校验失败" } } ; //校验是否在本应用下单(非通用积分商城中下单不允许使用) bool isInSelfApp = coms.All(c => c.AppId == paramDto.EsAppId); int cost; //积分汇率 int scoreCount; //积分数量 //是否都是通用积分 bool isAllCurrency = checkResult.ScoreDetailList.All(returnUnitiveScoreDTO => returnUnitiveScoreDTO.IsUnitive); if (isAllCurrency) { //汇率无效 if (checkResult.ExchangeRate <= 0) { return(result); } cost = checkResult.ExchangeRate; scoreCount = checkResult.UnitiveScore; } //非通用积分只有在本app下才可以使用 else if (isInSelfApp) { var scoreSetting = (from ss in ScoreSetting.ObjectSet() where ss.AppId == paramDto.EsAppId && ss.SubTime <= now orderby ss.SubTime descending select new { ss.ScoreCost }).FirstOrDefault(); if (scoreSetting == null) { return(result); } cost = scoreSetting.ScoreCost.Value; var appInfo = checkResult.ScoreDetailList.FirstOrDefault(c => c.AppId == paramDto.EsAppId); if (appInfo == null) { return(result); } scoreCount = appInfo.AvailableScore; } else { return(result); } result.Data.IsCashForScore = true; result.Data.Score = scoreCount; result.Data.ScoreType = isAllCurrency ? ScoreTypeEnum.Currency : ScoreTypeEnum.Self; result.Data.ScoreCost = cost; //用户积分折现金额, decimal userScoreMoney = (scoreCount * 1.0m / cost).ToMoney(); //总可参与积分抵现的总金额 decimal canScoreMoney = canScoreComList.Sum(c => c.CanScoreMoney); if (userScoreMoney > canScoreMoney) { userScoreMoney = canScoreMoney; } var dict = canScoreComList.GroupBy(c => c.AppId).ToDictionary(x => x.Key, y => y.ToList()); foreach (var kv in dict) { var appExt = appExts.FirstOrDefault(c => c.Id == kv.Key); if (appExt == null) { continue; } AppScoreDTO appScoreDTO = new AppScoreDTO() { AppId = kv.Key }; foreach (var com in kv.Value) { com.Money = getScoreMoney(userScoreMoney * com.CanScoreMoney / canScoreMoney, cost); if (com.Money <= 0) { continue; } appScoreDTO.Money += com.Money; appScoreDTO.Coms.Add(com); } if (appScoreDTO.Money <= 0) { continue; } result.Data.List.Add(appScoreDTO); result.Data.Money += appScoreDTO.Money; } #region 订单减免->订单减免后余额小于积分抵现金额 decimal money = 0.0m; foreach (var appScoreDTO in result.Data.List) { var reducation = paramDto.Reductions.FirstOrDefault(c => c.AppId == appScoreDTO.AppId); if (reducation == null || reducation.Reduction <= 0) //不存在订单减免,不需要处理 { money += appScoreDTO.Money; continue; } var appComIds = coms.Where(c => c.AppId == appScoreDTO.AppId).Select(c => c.Id).ToList(); var appTotalPrice = paramDto.Coms.Where(c => appComIds.Contains(c.CommodityId)).Sum(c => c.RealPrice * c.Num); var appPrice = appTotalPrice - reducation.Reduction; if (appPrice > appScoreDTO.Money) //订单订单减免后金额足够支付,不需要处理 { money += appScoreDTO.Money; continue; } var percent = appPrice / appTotalPrice; appScoreDTO.Money = 0; for (int i = 0; i < appScoreDTO.Coms.Count - 1; i++) { appScoreDTO.Coms[i].Money = (appScoreDTO.Coms[i].Money * percent).ToMoney(); appScoreDTO.Money += appScoreDTO.Coms[i].Money; } //处理由于四舍五入造成除不尽的问题,剩余数据都给最后一条订单项 appScoreDTO.Coms[appScoreDTO.Coms.Count - 1].Money = appPrice - appScoreDTO.Money; appScoreDTO.Money += appScoreDTO.Coms[appScoreDTO.Coms.Count - 1].Money; money += appScoreDTO.Money; } result.Data.Money = money; #endregion return(result); }