Esempio n. 1
0
        /// <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;
            }
        }
Esempio n. 2
0
        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;
            }
        }