/// <summary> /// 根据用户发送的二维码去二维码表中VipDCode匹配 /// </summary> /// <param name="content"></param> /// <param name="vipID"></param> public void StoreRebate(string content, string vipID) { content = content.Trim(); BaseService.WriteLogWeixin("返利信息:" + content); VipDCodeBLL bll = new VipDCodeBLL(requestParams.LoggingSessionInfo); WXSalesPolicyRateBLL SalesPolicybll = new WXSalesPolicyRateBLL(requestParams.LoggingSessionInfo); //var tran = bll.GetTran(); try { //判断当前发送二维码的微信号是否是 二维码表中当前二维码Code的会员 VipId=vipID; //var temp = bll.QueryByEntity(new VipDCodeEntity { IsDelete = 0, DCodeId = content}, null); var temp = bll.GetByID(content); decimal?ReturnAmount = 0; string PushInfo = string.Empty; //using (tran.Connection) //{ if (temp != null) //如果可以匹配,则更新二维码表中的会员ID,OpenId { #region 1.更新返现金额。更新返现状态 VipDCodeEntity entity = new VipDCodeEntity(); entity = temp; DataSet ds = SalesPolicybll.getReturnAmount(Convert.ToDecimal(entity.SalesAmount), entity.CustomerId); if (ds != null && ds.Tables[0].Rows.Count == 0 && ds.Tables[1].Rows.Count == 0) { BaseService.WriteLogWeixin("该客户没有配置策略信息"); throw new Exception("该客户没有配置策略信息"); } if (ds != null && ds.Tables[0].Rows.Count > 0) { //返现金额 ReturnAmount = entity.ReturnAmount = Convert.ToDecimal(ds.Tables[0].Rows[0]["ReturnAmount"].ToString()); //返现消息内容 PushInfo = ds.Tables[0].Rows[0]["PushInfo"].ToString(); BaseService.WriteLogWeixin("PushInfo1:" + PushInfo); } else { //返现金额 ReturnAmount = entity.ReturnAmount = Convert.ToDecimal(ds.Tables[1].Rows[0]["ReturnAmount"].ToString()); //返现消息内容 PushInfo = ds.Tables[1].Rows[0]["PushInfo"].ToString(); BaseService.WriteLogWeixin("PushInfo2:" + PushInfo); } entity.OpenId = requestParams.OpenId; entity.VipId = vipID; entity.ReturnAmount = ReturnAmount; VipAmountBLL Amountbll = new VipAmountBLL(requestParams.LoggingSessionInfo); var vipBll = new VipBLL(requestParams.LoggingSessionInfo); var vipEntity = vipBll.GetByID(vipID); string strErrormessage = ""; if (entity.IsReturn != 1) //当未返现的时候金额变更 { Loggers.Debug(new DebugLogInfo() { Message = "begin update VipDcode:" }); if (Amountbll.SetVipAmountChange(entity.CustomerId, 2, vipID, ReturnAmount ?? 0, entity.ObjectId, "门店返现", "IN", out strErrormessage)) { entity.IsReturn = 1; entity.DCodeId = content; bll.Update(entity); //更新返现金额 Loggers.Debug(new DebugLogInfo() { Message = "update VipDcode success" }); } } #endregion var vipamountBll = new VipAmountBLL(requestParams.LoggingSessionInfo); var vipAmountEntity = vipamountBll.GetByID(vipID); decimal endAmount = 0; if (vipAmountEntity != null) { endAmount = vipAmountEntity.EndAmount ?? 0; } var message = PushInfo.Replace("#SalesAmount#", entity.SalesAmount.ToString()).Replace("#ReturnAmount#", Convert.ToDecimal(ReturnAmount).ToString("0.00")).Replace("#EndAmount#", endAmount.ToString("0.00")).Replace("#VipName#", vipEntity.VipName); #region 插入门店返现推送消息日志表 WXSalesPushLogBLL PushLogbll = new WXSalesPushLogBLL(requestParams.LoggingSessionInfo); WXSalesPushLogEntity pushLog = new WXSalesPushLogEntity(); pushLog.LogId = Guid.NewGuid(); pushLog.WinXin = requestParams.WeixinId; pushLog.OpenId = requestParams.OpenId; pushLog.VipId = vipID; pushLog.PushInfo = message; pushLog.DCodeId = content; pushLog.RateId = Guid.NewGuid(); PushLogbll.Create(pushLog); #endregion Loggers.Debug(new DebugLogInfo() { Message = message }); string code = JIT.CPOS.BS.BLL.WX.CommonBLL.SendWeixinMessage(message, "1", requestParams.LoggingSessionInfo, vipEntity); Loggers.Debug(new DebugLogInfo() { Message = "消息推送完成,code=" + code + ", message=" + message }); #region 增加抽奖信息 var rateList = SalesPolicybll.QueryByEntity(new WXSalesPolicyRateEntity { CustomerId = temp.CustomerId }, null); if (rateList == null || rateList.Length == 0) { //rateList = SalesPolicybll.QueryByEntity(new WXSalesPolicyRateEntity{CustomerId =null},null); rateList = SalesPolicybll.GetWxSalesPolicyRateList().ToArray(); } if (rateList != null && rateList.Length > 0) { var wxSalespolicyRateMapBll = new WXSalesPolicyRateObjectMappingBLL(requestParams.LoggingSessionInfo); var rateMappingEntity = wxSalespolicyRateMapBll.QueryByEntity(new WXSalesPolicyRateObjectMappingEntity { RateId = rateList[0].RateId }, null); if (rateMappingEntity != null && rateMappingEntity.Length > 0) { if (Convert.ToDecimal(temp.SalesAmount) >= rateMappingEntity[0].CoefficientAmount) { if (rateMappingEntity[0].PushInfo != null) { var eventMessage = rateMappingEntity[0].PushInfo.Replace("#CustomerId#", temp.CustomerId).Replace("#EventId#", rateMappingEntity[0].ObjectId).Replace("#VipId#", vipID).Replace("#OpenId#", vipEntity.WeiXinUserId); BaseService.WriteLogWeixin("微信推送的抽奖活动URL:" + eventMessage); WXSalesPushLogEntity qrLog = new WXSalesPushLogEntity(); qrLog.LogId = Guid.NewGuid(); qrLog.WinXin = requestParams.WeixinId; qrLog.OpenId = requestParams.OpenId; qrLog.VipId = vipID; qrLog.PushInfo = eventMessage; qrLog.DCodeId = content; qrLog.RateId = Guid.NewGuid(); PushLogbll.Create(qrLog); #region 增加抽奖机会 LEventsVipObjectBLL eventbll = new LEventsVipObjectBLL(requestParams.LoggingSessionInfo); LEventsVipObjectEntity evententity = new LEventsVipObjectEntity(); evententity.MappingId = Guid.NewGuid().ToString(); evententity.EventId = rateMappingEntity[0].ObjectId; evententity.VipId = vipID; evententity.ObjectId = ""; evententity.IsCheck = 0; evententity.LotteryCode = "0"; evententity.IsLottery = 0; eventbll.Create(evententity); #endregion JIT.CPOS.BS.BLL.WX.CommonBLL.SendWeixinMessage(eventMessage, "1", requestParams.LoggingSessionInfo, vipEntity); } } } } #endregion } // } } catch (Exception) { // tran.Rollback(); throw; } }
const int MEMBER_HAVECARDNOTIPS = 320; //领取成功 不提示 但跳到实体卡 #endregion protected override AuthCodeLoginRD ProcessRequest(DTO.Base.APIRequest <AuthCodeLoginRP> pRequest) { var vipCardVipMappingBLL = new VipCardVipMappingBLL(CurrentUserInfo); //参数验证 if (string.IsNullOrEmpty(pRequest.Parameters.Mobile)) { throw new APIException("请求参数中缺少Mobile或值为空.") { ErrorCode = ERROR_LACK_MOBILE }; } if (pRequest.Parameters.VipSource.HasValue == false) { pRequest.Parameters.VipSource = 1; //throw new APIException("请求参数中缺少VipSource或值为空.") { ErrorCode = ERROR_LACK_VIP_SOURCE }; } // AuthCodeLoginRD rd = new AuthCodeLoginRD(); var bll = new VipBLL(this.CurrentUserInfo); var codebll = new RegisterValidationCodeBLL(base.CurrentUserInfo); VipEntity vipByID = null; //根据VIP ID查找出来的VIP记录 VipEntity vipByPhone = null; //根据手机号查找出来的VIP记录 //var list = codebll.QueryByEntity(new RegisterValidationCodeEntity() //{ // Mobile = pRequest.Parameters.Mobile //}, null); //bool b = false; //if (list != null) //{ // foreach (var entity in list) // { // if (entity == null) // throw new APIException("未找到此手机的验证信息") {ErrorCode = ERROR_AUTHCODE_NOTEXISTS}; // //if (entity.IsValidated.Value == 1) // // throw new APIException("此验证码已被使用") {ErrorCode = ERROR_AUTHCODE_WAS_USED}; // //if (entity.Expires.Value < DateTime.Now) // // throw new APIException("此验证码已失效") {ErrorCode = ERROR_AUTHCODE_INVALID}; // if (entity.Code == pRequest.Parameters.AuthCode) // b = true; // } //} //if (!b) //{ // throw new APIException("验证码不正确.") { ErrorCode = ERROR_AUTHCODE_NOT_EQUALS }; //} #region 验证验证码 var entity = codebll.GetByMobile(pRequest.Parameters.Mobile); if (entity == null) { throw new APIException("未找到此手机的验证信息") { ErrorCode = ERROR_AUTHCODE_NOTEXISTS } } ; if (entity.IsValidated.Value == 1) { throw new APIException("此验证码已被使用") { ErrorCode = ERROR_AUTHCODE_WAS_USED } } ; if (entity.Expires.Value < DateTime.Now) { throw new APIException("此验证码已失效") { ErrorCode = ERROR_AUTHCODE_INVALID } } ; if (entity.Code != pRequest.Parameters.AuthCode) { throw new APIException("验证码不正确.") { ErrorCode = ERROR_AUTHCODE_NOT_EQUALS } } ; #endregion #region 获取会员权益 var customerBasicSettingBll = new CustomerBasicSettingBLL(CurrentUserInfo); var memberBenefit = customerBasicSettingBll.GetMemberBenefits(pRequest.CustomerID); var bllPrize = new LPrizesBLL(CurrentUserInfo); #endregion //自定义没有实体卡,有实体卡时变为1 int HaveVipcard = 0; //要发送给rabbitmq的信息 var eventService = new EventService(); EventContract vipMsg = null; switch (pRequest.Parameters.VipSource.Value) { case 3: //来源是微信时,做自动合并 { #region 根据手机号查找下,看下是否存在同样手机号的VIP记录 { List <IWhereCondition> wheres = new List <IWhereCondition>(); wheres.Add(new MoreThanCondition() { FieldName = "status", Value = 0, IncludeEquals = false }); //潜在或者正式会员 wheres.Add(new EqualsCondition() { FieldName = "phone", Value = pRequest.Parameters.Mobile }); wheres.Add(new EqualsCondition() { FieldName = "clientid", Value = pRequest.CustomerID }); var result = bll.Query(wheres.ToArray(), null); if (result != null && result.Length > 0) { vipByPhone = result[0]; } if (vipByPhone != null && vipByPhone.VipSourceId == "3" && vipByPhone.Status.Value >= 2) { throw new APIException("会员已经注册") { ErrorCode = ERROR_MEMBER_REGISTERED }; } } #endregion #region 根据VIP ID查找下,看下是否存在该VIP的记录 if (!string.IsNullOrEmpty(pRequest.UserID)) { List <IWhereCondition> wheres = new List <IWhereCondition>(); //wheres.Add(new MoreThanCondition() { FieldName = "status", Value = 0, IncludeEquals = false }); wheres.Add(new MoreThanCondition() { FieldName = "status", Value = 0, IncludeEquals = true }); wheres.Add(new EqualsCondition() { FieldName = "vipid", Value = pRequest.UserID }); wheres.Add(new EqualsCondition() { FieldName = "clientid", Value = pRequest.CustomerID }); var result = bll.Query(wheres.ToArray(), null); if (result != null && result.Length > 0) { vipByID = result[0]; } } else { //如果前端未指定VIP ID则后台指定 pRequest.UserID = Guid.NewGuid().ToString("N"); } //判断用户是从点击领取过来的 还是从点击绑定实体卡过来的 int?RegisterType = 0; if (pRequest.Parameters.registerType != null) { RegisterType = pRequest.Parameters.registerType; } //当手机号不为空时需要查询是否存在实体卡 if (!string.IsNullOrEmpty(pRequest.Parameters.Mobile) && (!string.IsNullOrEmpty(pRequest.UserID) || !string.IsNullOrEmpty(vipByPhone.VIPID))) { List <IWhereCondition> wheres = new List <IWhereCondition>(); wheres.Add(new EqualsCondition() { FieldName = "phone", Value = pRequest.Parameters.Mobile }); wheres.Add(new EqualsCondition() { FieldName = "clientid", Value = pRequest.CustomerID }); wheres.Add(new DirectCondition("VipID!='" + pRequest.UserID + "'")); var vipInfo = bll.Query(wheres.ToArray(), null); //若是从绑定实体卡进入,进行实体卡的判断,并不注册成功 if (RegisterType == 2) { if (vipInfo == null || vipInfo.Length == 0) { throw new APIException("未检测到实体卡") { ErrorCode = MEMBER_HAVENOCARD }; } else { vipCardVipMappingBLL.BindVipCard(vipByID.VIPID, vipByID.VipCode, vipByID.CouponInfo); HaveVipcard = 1; //需要给绑定实体卡的提示 } } else { vipCardVipMappingBLL.BindVipCard(vipByID.VIPID, vipByID.VipCode, vipByID.CouponInfo); //若是从"点击领取"进入则进行判断有没有实体卡 有没有实体卡都进行领卡成功的提示 if (vipInfo != null && vipInfo.Length > 0) { HaveVipcard = 1; //需要给绑定实体卡的提示 } else { HaveVipcard = 2; //注册成功但没有实体卡 } } } if (vipByID == null && vipByPhone == null) //根据vipid查不出记录,并且根据手机号也查不出记录 新增一条vip { //如果不存在则首先创建一条VIP记录,补充记录 vipByID = new VipEntity() { Phone = pRequest.Parameters.Mobile, VipName = pRequest.Parameters.Mobile, UserName = pRequest.Parameters.Mobile, VipRealName = pRequest.Parameters.VipRealName, VIPID = pRequest.UserID, Status = 2, ClientID = pRequest.CustomerID, VipCode = "Vip" + bll.GetNewVipCode(pRequest.CustomerID), VipSourceId = pRequest.Parameters.VipSource.ToString(), WeiXinUserId = string.IsNullOrWhiteSpace(pRequest.UserID) ? Guid.NewGuid().ToString("N") : pRequest.UserID, RegistrationTime = DateTime.Now }; bll.Create(vipByID); #region 注册会员触点活动奖励 //bllPrize.CheckIsWinnerForShare(CurrentUserInfo.UserID, "", "Reg"); RedisContactBLL redisContactBll = new RedisContactBLL(); redisContactBll.SetRedisContact(new RedisOpenAPIClient.Models.CC.CC_Contact() { CustomerId = CurrentUserInfo.ClientID, ContactType = "Reg", VipId = CurrentUserInfo.UserID }); #endregion } else if (vipByID != null) { VipEntity vipUpdateInfo = new VipEntity(); List <IWhereCondition> wheres = new List <IWhereCondition>(); //wheres.Add(new MoreThanCondition() { FieldName = "status", Value = 0, IncludeEquals = false }); wheres.Add(new MoreThanCondition() { FieldName = "status", Value = 0, IncludeEquals = true }); wheres.Add(new EqualsCondition() { FieldName = "vipid", Value = pRequest.UserID }); wheres.Add(new EqualsCondition() { FieldName = "clientid", Value = pRequest.CustomerID }); var result = bll.Query(wheres.ToArray(), null); if (result != null && result.Length > 0) { vipUpdateInfo = result[0]; } vipUpdateInfo.Phone = pRequest.Parameters.Mobile; if (!string.IsNullOrEmpty(pRequest.Parameters.VipRealName)) { vipUpdateInfo.VipRealName = pRequest.Parameters.VipRealName; } vipUpdateInfo.Status = 2; vipUpdateInfo.RegistrationTime = DateTime.Now; bll.Update(vipUpdateInfo); #region 注册会员触点活动奖励 //bllPrize.CheckIsWinnerForShare(CurrentUserInfo.UserID, "", "Reg"); RedisContactBLL redisContactBll = new RedisContactBLL(); redisContactBll.SetRedisContact(new RedisOpenAPIClient.Models.CC.CC_Contact() { CustomerId = CurrentUserInfo.ClientID, ContactType = "Reg", VipId = CurrentUserInfo.UserID }); #endregion #region 会员金矿、注册集客奖励 bll.SetOffActionReg(vipByID); #endregion } #endregion #region 根据VIP ID及手机号查询出的结果,尝试自动合并会员 (因目前会员注册不自动绑卡,实现用户自行选择绑卡业务故将绑卡业务注释掉) //if (vipByPhone == null) //{//如果未有相同手机号的用户,则无须绑定,直接使用VIP ID对应的VIP记录作为当前注册用户的记录 // rd.MemberInfo = new MemberInfo() // { // Mobile = vipByID.Phone // , // VipID = vipByID.VIPID // , // Name = vipByID.UserName // , // VipName = vipByID.VipName // , // VipNo = vipByID.VipCode // , // MemberBenefits = memberBenefit // , // IsActivate = vipByID.IsActivate.HasValue && vipByID.IsActivate.Value == 1 ? true : false // }; // //处理绑卡业务 add by Henry 2015/10/28 // vipCardVipMappingBLL.BindVipCard(vipByID.VIPID, vipByID.VipCode, vipByID.CouponInfo); //} //else //{//否则调用存储过程,做自动会员合并 // //如果会员已经注册过,并且来源是微信的则表示该帐号已经被注册过不能再次绑定 // if (vipByPhone.VipSourceId == "3" && vipByPhone.Status.Value >= 2) // { // throw new APIException("会员已经注册") { ErrorCode = ERROR_MEMBER_REGISTERED }; // } // //否则做会员合并 // if (!bll.MergeVipInfo(pRequest.CustomerID, pRequest.UserID, pRequest.Parameters.Mobile)) // { // throw new APIException("自动绑定会员信息失败") { ErrorCode = ERROR_AUTO_MERGE_MEMBER_FAILED }; // } // //合并成功后重新读取信息 // List<IWhereCondition> wheres = new List<IWhereCondition>(); // wheres.Add(new MoreThanCondition() { FieldName = "status", Value = 0, IncludeEquals = false }); // wheres.Add(new EqualsCondition() { FieldName = "vipid", Value = pRequest.UserID }); // wheres.Add(new EqualsCondition() { FieldName = "clientid", Value = pRequest.CustomerID }); // var result = bll.Query(wheres.ToArray(), null); // vipByID = result[0]; // rd.MemberInfo = new MemberInfo() // { // Mobile = vipByID.Phone // , // VipID = vipByID.VIPID // , // Name = vipByID.UserName // , // VipName = vipByID.VipName // , // VipNo = vipByID.VipCode // , // MemberBenefits = memberBenefit // , // IsActivate = vipByID.IsActivate.HasValue && vipByID.IsActivate.Value == 1 ? true : false // }; // //处理绑卡业务 add by Henry 2015/10/28 // vipCardVipMappingBLL.BindVipCard(vipByID.VIPID, vipByID.VipCode, vipByID.CouponInfo); //} #endregion } //注册会员信息发布到rabbitmq vipMsg = new EventContract { Operation = OptEnum.Create, EntityType = EntityTypeEnum.Vip, Id = pRequest.UserID }; eventService.PublishMsg(vipMsg); break; default: //其他来源则为自动注册 { #region 根据手机号查找下,看下是否存在同样手机号的VIP记录 { List <IWhereCondition> wheres = new List <IWhereCondition>(); wheres.Add(new MoreThanCondition() { FieldName = "status", Value = 0, IncludeEquals = false }); wheres.Add(new EqualsCondition() { FieldName = "phone", Value = pRequest.Parameters.Mobile }); wheres.Add(new EqualsCondition() { FieldName = "clientid", Value = pRequest.CustomerID }); var result = bll.Query(wheres.ToArray(), null); if (result != null && result.Length > 0) { vipByPhone = result[0]; } if (vipByPhone != null && vipByPhone.Status.Value >= 2) { throw new APIException("会员已经注册") { ErrorCode = ERROR_MEMBER_REGISTERED }; } } #endregion #region 没有找到相同电话的会员则自动注册 if (vipByPhone == null) { //没有找到相同电话的会员则自动注册 vipByPhone = new VipEntity() { Phone = pRequest.Parameters.Mobile, VipName = pRequest.Parameters.Mobile, UserName = pRequest.Parameters.Mobile, VipRealName = pRequest.Parameters.VipRealName, VIPID = string.IsNullOrWhiteSpace(pRequest.UserID) ? Guid.NewGuid().ToString("N") : pRequest.UserID, Status = 2, //状态为注册 VipCode = "Vip" + bll.GetNewVipCode(pRequest.CustomerID), ClientID = pRequest.CustomerID, VipSourceId = pRequest.Parameters.VipSource.ToString(), WeiXinUserId = string.IsNullOrWhiteSpace(pRequest.UserID) ? Guid.NewGuid().ToString("N") : pRequest.UserID, RegistrationTime = DateTime.Now }; bll.Create(vipByPhone); #region 注册会员触点活动奖励 //bllPrize.CheckIsWinnerForShare(CurrentUserInfo.UserID, "", "Reg"); RedisContactBLL redisContactBll = new RedisContactBLL(); redisContactBll.SetRedisContact(new RedisOpenAPIClient.Models.CC.CC_Contact() { CustomerId = CurrentUserInfo.ClientID, ContactType = "Reg", VipId = CurrentUserInfo.UserID }); #endregion } #endregion #region decimal EndAmount = 0; VipAmountBLL AmountBLL = new VipAmountBLL(this.CurrentUserInfo); VipAmountEntity amountEntity = AmountBLL.GetByID(vipByPhone.VIPID); if (amountEntity != null) { EndAmount = amountEntity.EndAmount.HasValue ? amountEntity.EndAmount ?? 0 : 0; } #endregion #region 返回用户信息 rd.MemberInfo = new MemberInfo() { Mobile = vipByPhone.Phone , VipID = vipByPhone.VIPID , Name = vipByPhone.UserName , VipName = vipByPhone.VipName , VipRealName = vipByPhone.VipRealName , VipNo = vipByPhone.VipCode , MemberBenefits = memberBenefit , IsActivate = false , Integration = vipByPhone.Integration ?? 0 , Balance = EndAmount }; #endregion } //注册会员信息发布到rabbitmq vipMsg = new EventContract { Operation = OptEnum.Create, EntityType = EntityTypeEnum.Vip, Id = rd.MemberInfo.VipID }; eventService.PublishMsg(vipMsg); break; } T_LEventsRegVipLogBLL lEventRegVipLogBll = new T_LEventsRegVipLogBLL(CurrentUserInfo); if (!string.IsNullOrEmpty(pRequest.Parameters.CTWEventId)) { lEventRegVipLogBll.CTWRegOrFocusLog(pRequest.Parameters.CTWEventId, pRequest.UserID, "", CurrentUserInfo, "Reg"); } //如果是通过优惠券进来的就有couponId 新注册的需要加记录 if (!string.IsNullOrEmpty(pRequest.Parameters.couponId)) { lEventRegVipLogBll.CouponRegOrFocusLog(pRequest.Parameters.couponId, pRequest.UserID, "", CurrentUserInfo, "Reg"); } //当手机号不为空时需要查询是否存在实体卡 //if (!string.IsNullOrEmpty(pRequest.Parameters.Mobile) && (!string.IsNullOrEmpty(pRequest.UserID) || !string.IsNullOrEmpty(vipByPhone.VIPID))) //{ // List<IWhereCondition> wheres = new List<IWhereCondition>(); // wheres.Add(new EqualsCondition() { FieldName = "phone", Value = pRequest.Parameters.Mobile }); // wheres.Add(new EqualsCondition() { FieldName = "clientid", Value = pRequest.CustomerID }); // wheres.Add(new DirectCondition("VipID!='" + pRequest.UserID + "'")); // var vipInfo = bll.Query(wheres.ToArray(), null); // if (vipInfo != null && vipInfo.Length > 0) // { // throw new APIException("检测到会员相关实体卡") { ErrorCode = MEMBER_HAVECARD }; // } // else // { // //如果会员当前没有实体卡,则默认绑定等级为1的卡 // vipCardVipMappingBLL.BindVipCard(vipByID.VIPID, vipByID.VipCode, vipByID.CouponInfo); // throw new APIException("未检测到实体卡") { ErrorCode = MEMBER_HAVENOCARD }; // } //} //判定是否有可绑卡的定义 1=有可绑卡 if (HaveVipcard == 1 || HaveVipcard == 2) { //有积分的话给相应领取成功的积分提示 var contactEventBLL = new ContactEventBLL(CurrentUserInfo); int sendIntegral = 0; if (!string.IsNullOrEmpty(pRequest.Parameters.CTWEventId)) { sendIntegral = contactEventBLL.GetContactEventIntegral(CurrentUserInfo.ClientID, "Reg", "Point", 1); } else { sendIntegral = contactEventBLL.GetContactEventIntegral(CurrentUserInfo.ClientID, "Reg", "Point", 0); } if (sendIntegral > 0) { if (pRequest.Parameters.registerType != 2 && HaveVipcard == 2) { throw new APIException("恭喜您领取成功并获得" + sendIntegral + "注册积分") { ErrorCode = MEMBER_GETSUCCESS }; //领取成功不跳转跳转到实体卡 } else if (pRequest.Parameters.registerType == 2 && HaveVipcard == 1) { throw new APIException("恭喜您领取成功并获得" + sendIntegral + "注册积分") { ErrorCode = MEMBER_HAVECARD_Integral }; //检测到有相关实体卡前端不提示领取成功 并跳到实体卡列表 } else { throw new APIException("恭喜您领取成功并获得" + sendIntegral + "注册积分") { ErrorCode = MEMBER_HAVECARD }; //领取成功,提示领取成功,并跳到相关实体卡 } } else { if (pRequest.Parameters.registerType != 2 && HaveVipcard == 2) { throw new APIException("领取成功") { ErrorCode = MEMBER_GETSUCCESS }; //领取成功不跳转跳转到实体卡 } else if (pRequest.Parameters.registerType == 2 && HaveVipcard == 1) { throw new APIException("检测到有相关实体卡") { ErrorCode = MEMBER_HAVECARD }; //检测到有相关实体卡前端不提示领取成功 并跳到实体卡列表 } else if (pRequest.Parameters.registerType != 2 && HaveVipcard == 1) { throw new APIException("领取成功") { ErrorCode = MEMBER_HAVECARD }; //领取成功有实体卡,并跳转 } else { throw new APIException("检测到有相关实体卡") { ErrorCode = MEMBER_HAVECARD }; //领取成功,提示领取成功,并跳到相关实体卡 } } } #region 将验证码设置为已验证 //entity.IsValidated = 1; //codebll.Update(entity); #endregion return(rd); //AuthCodeLoginRD rd = new AuthCodeLoginRD(); //rd.MemberInfo = new MemberInfo(); //var codebll = new RegisterValidationCodeBLL(base.CurrentUserInfo); //var entity = codebll.GetByMobile(pRequest.Parameters.Mobile); //if (entity == null) // throw new APIException("未找到此手机的验证信息") { ErrorCode = ERROR_AUTHCODE_NOTEXISTS }; //if (entity.IsValidated.Value == 1) // throw new APIException("此验证码已失效") { ErrorCode = ERROR_AUTHCODE_FAILURE }; //if (entity.Expires.Value < DateTime.Now) // throw new APIException("此验证码已失效") { ErrorCode = ERROR_AUTHCODE_FAILURE }; //var vipbll = new VipBLL(base.CurrentUserInfo); //var vipinfo = vipbll.GetByMobile(pRequest.Parameters.Mobile, pRequest.CustomerID); //#region VIP来源更新 //switch (pRequest.Parameters.VipSource.Value) //{ // case 4: // case 9: // vipinfo.VipSourceId = pRequest.Parameters.VipSource.ToString(); // vipbll.Update(vipinfo); // break; //} //#endregion //if (string.IsNullOrEmpty(vipinfo.ClientID)) //{ // vipinfo.ClientID = pRequest.CustomerID; // vipbll.Update(vipinfo); //} //rd.MemberInfo.Mobile = vipinfo.Phone; //rd.MemberInfo.Name = vipinfo.UserName; //rd.MemberInfo.VipID = vipinfo.VIPID; //rd.MemberInfo.VipName = vipinfo.VipName; //var customerBasicSettingBll = new CustomerBasicSettingBLL(CurrentUserInfo); //rd.MemberInfo.MemberBenefits = customerBasicSettingBll.GetMemberBenefits(pRequest.CustomerID); //entity.IsValidated = 1; //codebll.Update(entity); //return rd; } } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; var OrderID = context.Request["OrderID"]; var OrderStatus = context.Request["OrderStatus"]; var CustomerID = context.Request["CustomerID"]; var UserID = context.Request["UserID"]; var ChannelID = context.Request["ChannelID"]; var SerialPay = context.Request["SerialPay"]; try { if (string.IsNullOrEmpty(OrderID) || string.IsNullOrEmpty(OrderStatus) || string.IsNullOrEmpty(CustomerID) || string.IsNullOrEmpty(UserID) || string.IsNullOrEmpty(ChannelID)) { throw new Exception("参数不全:OrderID,OrderStatus,CustomerID,UserID"); } else { if (OrderStatus == "2") { //支付成功,更新卡的支付状态 //OrderID就是VIPCardID // //var rp = pRequest.DeserializeJSONTo<APIRequest<SetVipCardRP>>(); //if (string.IsNullOrEmpty(rp.Parameters.PayID)) //{ // throw new APIException("缺少参数【PayID】或参数值为空") { ErrorCode = 135 }; //} var loggingSessionInfo = Default.GetBSLoggingSession(CustomerID, UserID); //会员 var vipBll = new VipBLL(loggingSessionInfo); var vipAmountBll = new VipAmountBLL(loggingSessionInfo); var vipCardVipMappingBll = new VipCardVipMappingBLL(loggingSessionInfo); //支付 var tPaymentTypeCustomerMappingBll = new TPaymentTypeCustomerMappingBLL(loggingSessionInfo); var tPaymentTypeBll = new T_Payment_TypeBLL(loggingSessionInfo); var paymentDetailBll = new T_Payment_detailBLL(loggingSessionInfo); //门店 var unitBLL = new t_unitBLL(loggingSessionInfo); //商品订单支付 //更新积分和状态 //var loggingSessionInfo = Default.GetBSLoggingSession(CustomerID, "1"); var inoutBll = new T_InoutBLL(loggingSessionInfo);//订单业务对象实例化 var trrBll = new T_RewardRecordBLL(loggingSessionInfo); //辨别打赏订单 var rewardOrderPrefix = "REWARD|"; if (OrderID.Contains(rewardOrderPrefix)) { OrderID = OrderID.Substring(rewardOrderPrefix.Length, OrderID.Length - rewardOrderPrefix.Length); var trrEntity = trrBll.GetByID(OrderID); trrEntity.PayStatus = 2; trrEntity.LastUpdateTime = DateTime.Now; trrEntity.LastUpdateBy = loggingSessionInfo.UserID; trrBll.Update(trrEntity); #region 员工余额变更--需要独立出来处理 var userAmountBll = new VipAmountBLL(loggingSessionInfo); //作为员工余额使用 var employeeId = trrEntity.RewardedOP; var rewardAmount = trrEntity.RewardAmount == null ? 0 : (decimal)trrEntity.RewardAmount; //转为非null的decimal类型 //门店 var unitService = new UnitService(loggingSessionInfo); var unitInfo = unitService.GetUnitByUser(CustomerID, employeeId).FirstOrDefault();//获取员工所属门店 var tran = userAmountBll.GetTran(); using (tran.Connection)//事务 { try { var userAmountEntity = userAmountBll.GetByID(trrEntity.RewardedOP); if (userAmountEntity == null) { //创建 userAmountEntity = new VipAmountEntity { VipId = employeeId,//员工ID VipCardCode = string.Empty, BeginAmount = 0, InAmount = rewardAmount, OutAmount = 0, EndAmount = rewardAmount, TotalAmount = rewardAmount, BeginReturnAmount = 0, InReturnAmount = 0, OutReturnAmount = 0, ReturnAmount = 0, ImminentInvalidRAmount = 0, InvalidReturnAmount = 0, ValidReturnAmount = 0, TotalReturnAmount = 0, IsLocking = 0, CustomerID = CustomerID }; userAmountBll.Create(userAmountEntity, tran);//创建员工余额表 } else { //修改 if (rewardAmount > 0) { userAmountEntity.InAmount = (userAmountEntity.InAmount == null ? 0 : userAmountEntity.InAmount.Value) + rewardAmount; userAmountEntity.TotalAmount = (userAmountEntity.TotalAmount == null ? 0 : userAmountEntity.TotalAmount.Value) + rewardAmount; } else { userAmountEntity.OutAmount = (userAmountEntity.OutAmount == null ? 0 : userAmountEntity.OutAmount.Value) + Math.Abs(rewardAmount); } userAmountEntity.EndAmount = (userAmountEntity.EndAmount == null ? 0 : userAmountEntity.EndAmount.Value) + rewardAmount; userAmountBll.Update(userAmountEntity, tran);//更新余额 } var vipamountDetailBll = new VipAmountDetailBLL(loggingSessionInfo); var vipAmountDetailEntity = new VipAmountDetailEntity { VipAmountDetailId = Guid.NewGuid(), VipCardCode = string.Empty, VipId = employeeId,//员工ID UnitID = unitInfo != null ? unitInfo.unit_id : string.Empty, UnitName = unitInfo != null ? unitInfo.Name : string.Empty, Amount = rewardAmount, UsedReturnAmount = 0, EffectiveDate = DateTime.Now, DeadlineDate = Convert.ToDateTime("9999-12-31 23:59:59"), AmountSourceId = "26", Reason = "Reward", CustomerID = CustomerID }; vipamountDetailBll.Create(vipAmountDetailEntity, tran); //创建余额详情 tran.Commit(); //提交事务 } catch (Exception ex) { tran.Rollback(); Loggers.Debug(new DebugLogInfo() { Message = "异常-->支付成功回调时更新会员打赏金额出错(PayNotify.ashx):" + ex }); } } #endregion if (trrEntity != null) { context.Response.Write("SUCCESS"); } else { context.Response.Write("FAIL"); } return; } //获取会员信息 var vipInfo = vipBll.GetByID(loggingSessionInfo.UserID); //支付信息 Bear //var tPaymentTypeCustomerMappingEntity = tPaymentTypeCustomerMappingBll.QueryByEntity(new TPaymentTypeCustomerMappingEntity(){ChannelId = ChannelID,CustomerId = loggingSessionInfo.ClientID },null).FirstOrDefault(); var paymentTypeList = tPaymentTypeBll.GetAll(); var tPaymentType = paymentTypeList.ToList() .Find(t => t.Payment_Type_Code == "WXJS"); //var tPaymentType = tPaymentTypeBll.GetByID(tPaymentTypeCustomerMappingEntity.PaymentTypeID); //获取订单信息 var inoutInfo = inoutBll.GetByID(OrderID); if (inoutInfo != null) { var bll = new TInOutStatusNodeBLL(loggingSessionInfo); string msg; if (!bll.SetOrderPayment(OrderID, out msg, ChannelID, SerialPay)) //if (!bll.SetOrderPayment(OrderID, out msg, ChannelID)) { throw new Exception(msg); } else if (string.IsNullOrEmpty(inoutInfo.Field17) && string.IsNullOrEmpty(inoutInfo.Field18)) { #region 发送订单支付成功微信模板消息 var SuccessCommonBLL = new CommonBLL(); //SuccessCommonBLL.SentPaymentMessage(inoutInfo, vipInfo.WeiXinUserId,vipInfo.VIPID, loggingSessionInfo); new SendOrderPaySuccessMsgBLL().SentPaymentMessage(inoutInfo, vipInfo.WeiXinUserId, vipInfo.VIPID, loggingSessionInfo); #endregion Loggers.Debug(new DebugLogInfo() { Message = "调用SetOrderPayment方法更新订单成功" }); } //获取订单信息,根据Field3==1判断,如果是ALD订单,则调用ALD接口更新ALD订单的状态 #region 更新ALD状态 //var orderbll = new InoutService(loggingSessionInfo); //var orderInfo = orderbll.GetInoutInfoById(OrderID); //if (orderInfo.Field3 == "1") //{ // Loggers.Debug(new DebugLogInfo() { Message = string.Format("更新O2OMarketing订单状态成功[OrderID={0}].", OrderID) }); // //更新阿拉丁的订单状态 // JIT.CPOS.Web.OnlineShopping.data.DataOnlineShoppingHandler.ALDChangeOrderStatus aldChangeOrder = new data.DataOnlineShoppingHandler.ALDChangeOrderStatus(); // if (string.IsNullOrEmpty(orderInfo.vip_no)) // throw new Exception("会员ID不能为空,OrderID:" + OrderID); // aldChangeOrder.MemberID = new Guid(orderInfo.vip_no); // aldChangeOrder.SourceOrdersID = OrderID; // aldChangeOrder.Status = int.Parse(orderInfo.status); // aldChangeOrder.IsPaid = true; // JIT.CPOS.Web.OnlineShopping.data.DataOnlineShoppingHandler.ALDChangeOrderStatusRequest aldRequest = new data.DataOnlineShoppingHandler.ALDChangeOrderStatusRequest(); // aldRequest.BusinessZoneID = 1;//写死 // aldRequest.Locale = 1; // aldRequest.UserID = new Guid(orderInfo.vip_no); // aldRequest.Parameters = aldChangeOrder; // var url = ConfigurationManager.AppSettings["ALDGatewayURL"]; // var postContent = string.Format("Action=ChangeOrderStatus&ReqContent={0}", aldRequest.ToJSON()); // Loggers.Debug(new DebugLogInfo() { Message = "通知ALD更改状态:" + postContent }); // var strAldRsp = HttpWebClient.DoHttpRequest(url, postContent); // var aldRsp = strAldRsp.DeserializeJSONTo<JIT.CPOS.Web.OnlineShopping.data.DataOnlineShoppingHandler.ALDResponse>(); // if (!aldRsp.IsSuccess()) // { // Loggers.Debug(new DebugLogInfo() { Message = string.Format("更新阿拉丁订单状态失败[Request ={0}][Response={1}]", aldRequest.ToJSON(), strAldRsp) }); // } //} #endregion #region 格力推送通知 //try //{ // GLServiceOrderBLL glsobll = new GLServiceOrderBLL(loggingSessionInfo); // if (glsobll.ValidateGree(CustomerID, "cpos_bs_lj"))//先写死 // glsobll.GreePushPaymentOorder(CustomerID, OrderID, loggingSessionInfo); //} //catch (Exception ex) //{ // Loggers.Debug(new DebugLogInfo() { Message = string.Format("付款推送评价师傅链接失败[OrderID={0}].", OrderID) }); //} #endregion #region ALD生活服务处理 //var rechargeBll = new RechargeStrategyBLL(loggingSessionInfo); //var vipAmountBll = new VipAmountBLL(loggingSessionInfo); //var couponBll = new CouponBLL(loggingSessionInfo); //var vipCouponMappingBll = new VipCouponMappingBLL(loggingSessionInfo); //var unitBll = new UnitBLL(loggingSessionInfo); //DataSet dsOrderInfo = rechargeBll.GetInoutOrderItems(OrderID); //int itemSort = 0; //商品业务分类 //string skuId = string.Empty; //商品SkuId //string vipId = string.Empty; //会员ID //string itemId = string.Empty;//商品ID //string couponId = string.Empty;//优惠券ID //if (dsOrderInfo.Tables[0].Rows.Count > 0) //{ // //if (dsOrderInfo.Tables[0].Rows[0]["ItemSort"] != DBNull.Value && Convert.ToString(dsOrderInfo.Tables[0].Rows[0]["ItemSort"]) != "0") // itemSort = int.Parse(dsOrderInfo.Tables[0].Rows[0]["ItemSort"].ToString()); // switch (itemSort) // { // case 2://充 // #region 充值金额处理 // VipAmountDetailBLL vipAmountDetailBll = new VipAmountDetailBLL(loggingSessionInfo); // List<IWhereCondition> complexCondition = new List<IWhereCondition> { }; // complexCondition.Add(new EqualsCondition() { FieldName = "ObjectId", Value = OrderID }); // var vipAmountDetal = vipAmountDetailBll.Query(complexCondition.ToArray(), null); // if (vipAmountDetal.Count() == 0)//确认没有多次执行回调 // { // ////查询 // //RechargeStrategyEntity[] rechargeList = rechargeBll.Query(complexCondition.ToArray(), lstOrder.ToArray()); // skuId = dsOrderInfo.Tables[0].Rows[0]["SkuId"].ToString(); // //RechargeStrategyEntity rechargeEntity = rechargeBll.GetByID(skuId); // DataSet dsSkuPirce = unitBll.GetSkuPirce(skuId); // decimal salePrice = 0;//购买金额 // decimal returnCash = 0;//奖励金额 // if (dsSkuPirce.Tables[0].Rows.Count > 0) // { // salePrice = Convert.ToDecimal(dsSkuPirce.Tables[0].Rows[0]["SalesPrice"].ToString()); // returnCash = Convert.ToDecimal(dsSkuPirce.Tables[0].Rows[0]["ReturnCash"].ToString()); // InoutService server = new InoutService(loggingSessionInfo); // #region 充值金额 // var tran = server.GetTran(); // using (tran.Connection)//事物 // { // try // { // //充值金额 // vipAmountBll.AddVipEndAmount(UserID, salePrice, tran, "4", OrderID, loggingSessionInfo);//4=充值 // tran.Commit(); // } // catch (Exception) // { // tran.Rollback(); // throw; // } // } // #endregion // #region 奖励金额 // var tran2 = server.GetTran(); // using (tran2.Connection)//事物 // { // try // { // //奖励金额 // vipAmountBll.AddVipEndAmount(UserID, returnCash, tran2, "6", OrderID, loggingSessionInfo);//6=奖励金额 // tran2.Commit(); // } // catch (Exception) // { // tran2.Rollback(); // throw; // } // } // #endregion // } // } // #endregion // break; // case 3://券 // #region 券类商品绑定到会员 // itemId = dsOrderInfo.Tables[0].Rows[0]["ItemId"].ToString(); // vipId = dsOrderInfo.Tables[0].Rows[0]["VipId"].ToString(); // couponId = couponBll.GetCouponByItemId(itemId); // if (!string.IsNullOrEmpty(couponId)) // { // VipCouponMappingEntity coupon = new VipCouponMappingEntity // { // VIPID = vipId, // CouponID = couponId, // }; // vipCouponMappingBll.Create(coupon); // } // #endregion // break; // default: // break; // } //} #endregion #region 订单与分润关系处理 add by Henry 2014-10-10 //var orderSubBll = new OrderOrderSubRunObjectMappingBLL(loggingSessionInfo); //dynamic o = orderSubBll.SetOrderSub(CustomerID, OrderID); //Type t = o.GetType(); //var Desc = t.GetProperty("Desc").GetValue(o, null).ToString(); //var IsSuccess = t.GetProperty("IsSuccess").GetValue(o, null).ToString(); //if (int.Parse(IsSuccess.ToString()) == 0) //失败 // Loggers.Debug(new DebugLogInfo() { Message = string.Format("订单与分润关系处理失败:{0}", Desc) }); #endregion CustomerBasicSettingBLL customerBasicSettingBll = new CustomerBasicSettingBLL(loggingSessionInfo); string AfterPaySetStock = customerBasicSettingBll.GetSettingValueByCode("AfterPaySetStock"); if (AfterPaySetStock == "1") { var inoutServiceBLL = new InoutService(loggingSessionInfo); var inoutDetailList = inoutServiceBLL.GetInoutDetailInfoByOrderId(OrderID); inoutBll.SetStock(OrderID, inoutDetailList, 1, loggingSessionInfo); } ///超级分销商订单入队列 if (inoutInfo.data_from_id == "35" || inoutInfo.data_from_id == "36") { BS.BLL.RedisOperationBLL.Order.SuperRetailTraderOrderBLL bllSuperRetailTraderOrder = new BS.BLL.RedisOperationBLL.Order.SuperRetailTraderOrderBLL(); bllSuperRetailTraderOrder.SetRedisToSuperRetailTraderOrder(loggingSessionInfo, inoutInfo); } //购卡 if (!string.IsNullOrEmpty(inoutInfo.Field17) && !string.IsNullOrEmpty(inoutInfo.Field18)) { //更新订单状态 inoutInfo = inoutBll.GetByID(OrderID); inoutInfo.Field7 = "700"; inoutInfo.status = "700"; inoutInfo.status_desc = "已完成"; inoutInfo.Field10 = "已完成"; inoutBll.Update(inoutInfo); //会员卡升级 vipCardVipMappingBll.BindVirtualItem(vipInfo.VIPID, vipInfo.VipCode, inoutInfo.sales_unit_id, Convert.ToInt32(inoutInfo.Field18), orderId: inoutInfo.order_id); //分润计算 RedisSalesVipCardOrderBLL redisSalesVipCardOrderBll = new RedisSalesVipCardOrderBLL(); redisSalesVipCardOrderBll.SetRedisSalesVipCardOrder(loggingSessionInfo, inoutInfo); //售卡处理积分、返现、佣金[完成订单] new SendOrderRewardMsgBLL().OrderReward(inoutInfo, loggingSessionInfo, null);//存入到缓存 } else { //订单入队列 RedisCalculateVipConsumeForUpgrade redisCalculateVipConsumeForUpgrade = new RedisCalculateVipConsumeForUpgrade(); redisCalculateVipConsumeForUpgrade.SetVipConsumeForUpgradeList(loggingSessionInfo, inoutInfo); } // add by liangx 2016-09-27 获取订单中的虚拟商品 start CouponTypeBLL couponTypeBLL = new CouponTypeBLL(loggingSessionInfo); RedisVipMappingCouponBLL redisVipMappingCouponBLL = new RedisVipMappingCouponBLL(); var couponTypes = couponTypeBLL.GetVirtualItemCouponTypes(inoutInfo.order_id); if (couponTypes.Any()) { redisVipMappingCouponBLL.SetVipMappingCoupon(couponTypes, "", couponTypes.FirstOrDefault().VipId, "PayVirtualItem"); } // add by liangx 2016-09-27 获取订单中的虚拟商品 end //获取门店信息 t_unitEntity unitInfo = null; if (!string.IsNullOrEmpty(inoutInfo.sales_unit_id)) { unitInfo = unitBLL.GetByID(inoutInfo.sales_unit_id); } //入支付明细表 var paymentDetail = new T_Payment_detailEntity() { Payment_Id = Guid.NewGuid().ToString(), Inout_Id = inoutInfo.order_id, UnitCode = unitInfo == null ? "" : unitInfo.unit_code, Payment_Type_Id = tPaymentType.Payment_Type_Id, Payment_Type_Code = tPaymentType.Payment_Type_Code, Payment_Type_Name = tPaymentType.Payment_Type_Name, Price = inoutInfo.actual_amount, Total_Amount = inoutInfo.total_amount, Pay_Points = inoutInfo.pay_points, CustomerId = loggingSessionInfo.ClientID }; paymentDetailBll.Create(paymentDetail); List <IWhereCondition> complexCondition = new List <IWhereCondition> { }; complexCondition.Add(new EqualsCondition() { FieldName = "Inout_Id", Value = inoutInfo.order_id }); var paymentDetailList = paymentDetailBll.Query(complexCondition.ToArray(), null); try { var msgRabbitMQ = new EventContract { Operation = OptEnum.Create, EntityType = EntityTypeEnum.Order, Id = inoutInfo.order_id }; var service = new EventService(); service.PublishMsg(msgRabbitMQ); foreach (var detail in paymentDetailList) { var paymentMQ = new EventContract { Operation = OptEnum.Create, EntityType = EntityTypeEnum.OrderPayment, Id = detail.Payment_Id }; service.PublishMsg(paymentMQ); } } catch (Exception) { throw new Exception("RabbitMQ Error"); } } else//充值订单 { var rechargeOrderBll = new RechargeOrderBLL(loggingSessionInfo); var vipamountDetailBll = new VipAmountDetailBLL(loggingSessionInfo); var rechargeOrderInfo = rechargeOrderBll.GetByID(OrderID); if (rechargeOrderInfo != null) { //获取门店信息 t_unitEntity unitInfo = null; if (!string.IsNullOrEmpty(rechargeOrderInfo.UnitId)) { unitInfo = unitBLL.GetByID(rechargeOrderInfo.UnitId); } //充值 rechargeOrderBll.Recharge(rechargeOrderInfo, vipInfo, unitInfo, tPaymentType.Payment_Type_Id); //入支付明细表 var paymentDetail = new T_Payment_detailEntity() { Payment_Id = Guid.NewGuid().ToString(), Inout_Id = rechargeOrderInfo.OrderID.ToString(), UnitCode = unitInfo == null ? "" : unitInfo.unit_code, Payment_Type_Id = tPaymentType.Payment_Type_Id, Payment_Type_Code = tPaymentType.Payment_Type_Code, Payment_Type_Name = tPaymentType.Payment_Type_Name, Price = rechargeOrderInfo.ActuallyPaid, Total_Amount = rechargeOrderInfo.TotalAmount, Pay_Points = rechargeOrderInfo.PayPoints, CustomerId = loggingSessionInfo.ClientID }; paymentDetailBll.Create(paymentDetail); } else { var receiveAmountOrderBll = new ReceiveAmountOrderBLL(loggingSessionInfo); var receiveAmountOrderEntity = receiveAmountOrderBll.GetByID(OrderID); //更新订单状态 if (receiveAmountOrderEntity != null) { VipIntegralBLL vipIntegralBll = new VipIntegralBLL(loggingSessionInfo); //更新订单 receiveAmountOrderEntity.PayStatus = "10"; // Bear //receiveAmountOrderEntity.PayTypeId = tPaymentTypeCustomerMappingEntity.PaymentTypeID; receiveAmountOrderEntity.PayTypeId = tPaymentType.Payment_Type_Id; receiveAmountOrderEntity.PayDatetTime = DateTime.Now; receiveAmountOrderBll.Update(receiveAmountOrderEntity); //获取门店信息 t_unitEntity unitInfo = null; if (!string.IsNullOrEmpty(receiveAmountOrderEntity.ServiceUnitId)) { unitInfo = unitBLL.GetByID(receiveAmountOrderEntity.ServiceUnitId); } //使用过积分,处理积分 if (receiveAmountOrderEntity.PayPoints != 0 && receiveAmountOrderEntity.PayPoints != null) { string sourceId = "20"; //积分抵扣 var IntegralDetail = new VipIntegralDetailEntity() { Integral = -Convert.ToInt32(receiveAmountOrderEntity.PayPoints), IntegralSourceID = sourceId, ObjectId = receiveAmountOrderEntity.OrderId.ToString() }; if (IntegralDetail.Integral != 0) { //变动前积分 string OldIntegral = (vipInfo.Integration ?? 0).ToString(); //变动积分 string ChangeIntegral = (IntegralDetail.Integral ?? 0).ToString(); var vipIntegralDetailId = vipIntegralBll.AddIntegral(ref vipInfo, unitInfo, IntegralDetail, loggingSessionInfo); //发送微信积分变动通知模板消息 if (!string.IsNullOrWhiteSpace(vipIntegralDetailId)) { var CommonBLL = new CommonBLL(); CommonBLL.PointsChangeMessage(OldIntegral, vipInfo, ChangeIntegral, vipInfo.WeiXinUserId, loggingSessionInfo); } } } //if (receiveAmountOrderEntity.CouponUsePay != 0 || receiveAmountOrderEntity.CouponUsePay != null) //{ // //更新使用记录 // var couponUseBll = new CouponUseBLL(loggingSessionInfo); // var couponUseEntity = new CouponUseEntity() // { // CouponUseID = Guid.NewGuid(), // CouponID = rp.CouponId, // VipID = vipInfo.VIPID, // UnitID = rp.UnitId, // OrderID = orderId.ToString(), // Comment = "商城使用电子券", // CustomerID = CurrentUserInfo.ClientID, // CreateBy = CurrentUserInfo.UserID, // CreateTime = DateTime.Now, // LastUpdateBy = CurrentUserInfo.UserID, // LastUpdateTime = DateTime.Now, // IsDelete = 0 // }; // couponUseBll.Create(couponUseEntity); // var couponBll = new CouponBLL(CurrentUserInfo); // var couponEntity = couponBll.GetByID(rp.CouponId); // //更新CouponType数量 // var conponTypeBll = new CouponTypeBLL(CurrentUserInfo); // var conponTypeEntity = conponTypeBll.QueryByEntity(new CouponTypeEntity() { CouponTypeID = new Guid(couponEntity.CouponTypeID), CustomerId = CurrentUserInfo.ClientID }, null).FirstOrDefault(); // conponTypeEntity.IsVoucher += 1; // conponTypeBll.Update(conponTypeEntity); // //停用该优惠券 // couponEntity.Status = 1; // couponBll.Update(couponEntity); //} //处理余额 if (receiveAmountOrderEntity.AmountAcctPay != null && receiveAmountOrderEntity.AmountAcctPay != 0) { var vipAmountDetailBll = new VipAmountDetailBLL(loggingSessionInfo); var vipAmountEntity = vipAmountBll.QueryByEntity(new VipAmountEntity() { VipId = vipInfo.VIPID, VipCardCode = vipInfo.VipCode }, null).FirstOrDefault(); if (vipAmountEntity != null) { var detailInfo = new VipAmountDetailEntity() { Amount = -receiveAmountOrderEntity.AmountAcctPay, AmountSourceId = "1", ObjectId = receiveAmountOrderEntity.OrderId.ToString() }; var vipAmountDetailId = vipAmountBll.AddVipAmount(vipInfo, unitInfo, ref vipAmountEntity, detailInfo, loggingSessionInfo); if (!string.IsNullOrWhiteSpace(vipAmountDetailId)) {//发送微信账户余额变动模板消息 var CommonBLL = new CommonBLL(); CommonBLL.BalanceChangedMessage(receiveAmountOrderEntity.OrderNo, vipAmountEntity, detailInfo, vipInfo.WeiXinUserId, vipInfo.VIPID, loggingSessionInfo); } } } //收款订单积分奖励 vipIntegralBll.OrderReward(receiveAmountOrderEntity, null); var paymentDetail = new T_Payment_detailEntity() { Payment_Id = Guid.NewGuid().ToString(), Inout_Id = receiveAmountOrderEntity.OrderId.ToString(), UnitCode = unitInfo == null ? "" : unitInfo.unit_code, Payment_Type_Id = tPaymentType.Payment_Type_Id, Payment_Type_Code = tPaymentType.Payment_Type_Code, Payment_Type_Name = tPaymentType.Payment_Type_Name, Price = receiveAmountOrderEntity.TransAmount, Total_Amount = receiveAmountOrderEntity.TotalAmount, Pay_Points = receiveAmountOrderEntity.PayPoints, CustomerId = loggingSessionInfo.ClientID }; paymentDetailBll.Create(paymentDetail); } } } context.Response.Write("SUCCESS"); } } } catch (Exception ex) { Loggers.Exception(new ExceptionLogInfo(ex)); context.Response.Write("ERROR:" + ex.Message); } }
public HttpResponseMessage Password(string vipId, string password) { Loggers.Debug(new DebugLogInfo() { Message = $"[api/Vip/Password]接口,参数:\"vipId:{vipId}&&password:{password}\"" }); try { if (string.IsNullOrEmpty(password)) { throw new APIException("请求参数中缺少Password或值为空.") { ErrorCode = 121 }; } if (string.IsNullOrEmpty(password)) { throw new APIException("请求参数中缺少Password或值为空.") { ErrorCode = 121 }; } var rd = new EmptyResponseData(); string customerid = ConfigurationManager.AppSettings["CustomerId"].Trim(); var loggingSessionInfo = Default.GetLoggingSession(customerid, "1"); var vipbll = new VipBLL(loggingSessionInfo); var vipEntity = vipbll.GetByID(vipId); if (vipEntity == null) { throw new APIException("无效的会员ID【VipId】") { ErrorCode = 121 }; } var bll = new VipAmountBLL(loggingSessionInfo); var vipAmountEntity = bll.GetByID(vipId); if (vipAmountEntity == null) { throw new APIException("该会员暂无绑定账户") { ErrorCode = 121 }; } else { if (vipAmountEntity.PayPassword != password) { throw new APIException("密码不正确") { ErrorCode = 122 }; } } var responseModel = new BaseResponeModel { IsSucess = true }; return(Request.CreateResponse(HttpStatusCode.OK, responseModel)); } catch (Exception ex) { var responseModel = new BaseResponeModel { IsSucess = false, ErrorMessage = ex.Message }; return(Request.CreateResponse(HttpStatusCode.InternalServerError, responseModel)); } }
public void StoreRebate(string content, string vipID) { Loggers.Debug(new DebugLogInfo() { Message = "返利信息:" + content }); var loggingSessionInfo = Default.GetBSLoggingSession("e703dbedadd943abacf864531decdac1", "1"); VipDCodeBLL bll = new VipDCodeBLL(loggingSessionInfo); WXSalesPolicyRateBLL SalesPolicybll = new WXSalesPolicyRateBLL(loggingSessionInfo); //var tran = bll.GetTran(); try { //判断当前发送二维码的微信号是否是 二维码表中当前二维码Code的会员 VipId=vipID; //var temp = bll.QueryByEntity(new VipDCodeEntity { IsDelete = 0, DCodeId = content}, null); var temp = bll.GetByID(content); decimal?ReturnAmount = 0; string PushInfo = string.Empty; //using (tran.Connection) //{ if (temp != null) //如果可以匹配,则更新二维码表中的会员ID,OpenId { #region 1.更新返现金额。更新返现状态 VipDCodeEntity entity = new VipDCodeEntity(); entity = temp; DataSet ds = SalesPolicybll.getReturnAmount(Convert.ToDecimal(entity.SalesAmount), entity.CustomerId); if (ds != null && ds.Tables[0].Rows.Count == 0 && ds.Tables[1].Rows.Count == 0) { Loggers.Debug(new DebugLogInfo() { Message = "该客户没有配置策略信息" }); throw new Exception("该客户没有配置策略信息"); } if (ds != null && ds.Tables[0].Rows.Count > 0) { //返现金额 ReturnAmount = entity.ReturnAmount = Convert.ToDecimal(ds.Tables[0].Rows[0]["ReturnAmount"].ToString()); //返现消息内容 PushInfo = ds.Tables[0].Rows[0]["PushInfo"].ToString(); Loggers.Debug(new DebugLogInfo() { Message = "PushInfo1:" + PushInfo }); } else { //返现金额 ReturnAmount = entity.ReturnAmount = Convert.ToDecimal(ds.Tables[1].Rows[0]["ReturnAmount"].ToString()); //返现消息内容 PushInfo = ds.Tables[1].Rows[0]["PushInfo"].ToString(); Loggers.Debug(new DebugLogInfo() { Message = "PushInfo2:" + PushInfo }); } entity.OpenId = "oxbbcjg5NBbdpK1T9mDkIzTn434U"; entity.VipId = vipID; entity.ReturnAmount = ReturnAmount; VipAmountBLL Amountbll = new VipAmountBLL(loggingSessionInfo); var vipBll = new VipBLL(loggingSessionInfo); var vipEntity = vipBll.GetByID(vipID); if (temp.IsReturn == 1) { //发送消息 JIT.CPOS.BS.BLL.WX.CommonBLL.SendWeixinMessage("对不起,该返利码已经被领取", "1", loggingSessionInfo, vipEntity); return; } if (DateTime.Now > (temp.CreateTime ?? DateTime.Now).AddDays(1)) { //发送消息 JIT.CPOS.BS.BLL.WX.CommonBLL.SendWeixinMessage("对不起,您的返利码已经过期,请在收到返利码后的24小时内使用", "1", loggingSessionInfo, vipEntity); return; } string strErrormessage = ""; if (entity.IsReturn != 1) //当未返现的时候金额变更 { Loggers.Debug(new DebugLogInfo() { Message = "begin update VipDcode:" }); if (Amountbll.SetVipAmountChange(entity.CustomerId, 2, vipID, ReturnAmount ?? 0, entity.ObjectId, "门店返现", "IN", out strErrormessage)) { entity.IsReturn = 1; entity.DCodeId = content; bll.Update(entity); //更新返现金额 Loggers.Debug(new DebugLogInfo() { Message = "update VipDcode success" }); } } #endregion var vipamountBll = new VipAmountBLL(loggingSessionInfo); var vipAmountEntity = vipamountBll.GetByID(vipID); decimal endAmount = 0; if (vipAmountEntity != null) { endAmount = vipAmountEntity.EndAmount ?? 0; } var message = PushInfo.Replace("#SalesAmount#", entity.SalesAmount.ToString()).Replace("#ReturnAmount#", Convert.ToDecimal(ReturnAmount).ToString("0.00")).Replace("#EndAmount#", endAmount.ToString("0.00")).Replace("#VipName#", vipEntity.VipName); #region 插入门店返现推送消息日志表 WXSalesPushLogBLL PushLogbll = new WXSalesPushLogBLL(loggingSessionInfo); WXSalesPushLogEntity pushLog = new WXSalesPushLogEntity(); pushLog.LogId = Guid.NewGuid(); pushLog.WinXin = "gh_e2b2da1e6edf"; pushLog.OpenId = "oxbbcjg5NBbdpK1T9mDkIzTn434U"; pushLog.VipId = vipID; pushLog.PushInfo = message; pushLog.DCodeId = content; pushLog.RateId = Guid.NewGuid(); PushLogbll.Create(pushLog); #endregion Loggers.Debug(new DebugLogInfo() { Message = message }); string code = JIT.CPOS.BS.BLL.WX.CommonBLL.SendWeixinMessage(message, "1", loggingSessionInfo, vipEntity); Loggers.Debug(new DebugLogInfo() { Message = "消息推送完成,code=" + code + ", message=" + message }); #region 增加抽奖信息 var rateList = SalesPolicybll.QueryByEntity(new WXSalesPolicyRateEntity { CustomerId = temp.CustomerId }, null); if (rateList == null || rateList.Length == 0) { //rateList = SalesPolicybll.QueryByEntity(new WXSalesPolicyRateEntity{CustomerId =null},null); rateList = SalesPolicybll.GetWxSalesPolicyRateList().ToArray(); } if (rateList != null && rateList.Length > 0) { var wxSalespolicyRateMapBll = new WXSalesPolicyRateObjectMappingBLL(loggingSessionInfo); var rateMappingEntity = wxSalespolicyRateMapBll.QueryByEntity(new WXSalesPolicyRateObjectMappingEntity { RateId = rateList[0].RateId }, null); if (rateMappingEntity != null && rateMappingEntity.Length > 0) { if (Convert.ToDecimal(temp.SalesAmount) >= rateMappingEntity[0].CoefficientAmount) { if (rateMappingEntity[0].PushInfo != null) { var eventMessage = rateMappingEntity[0].PushInfo.Replace("#CustomerId#", temp.CustomerId).Replace("#EventId#", rateMappingEntity[0].ObjectId).Replace("#VipId#", vipID).Replace("#OpenId#", vipEntity.WeiXinUserId); JIT.CPOS.BS.BLL.WX.CommonBLL.SendWeixinMessage(eventMessage, "1", loggingSessionInfo, vipEntity); } } } } #endregion } // } } catch (Exception) { // tran.Rollback(); throw; } }