Ejemplo 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;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 响应微信平台推送的消息
        /// </summary>
        public void ResponseMsg()
        {
            //获取会员信息
            VipBLL vipService = new VipBLL(requestParams.LoggingSessionInfo);
            var    vipId      = string.Empty;
            var    vipEntity  = vipService.QueryByEntity(new VipEntity
            {
                WeiXinUserId = requestParams.OpenId,
                WeiXin       = requestParams.WeixinId,
                ClientID     = requestParams.LoggingSessionInfo.ClientID
            }, null);
            VipEntity vip = null;

            if (vipEntity != null && vipEntity.Length > 0)
            {
                vipId = vipEntity.FirstOrDefault().VIPID;
                vip   = vipEntity.FirstOrDefault();
            }

            //先排重复的推送信息
            //关于重试的消息排重,有msgid的消息推荐使用msgid排重。事件类型消息推荐使用FromUserName + CreateTime 排重。
            var MsgId        = requestParams.XmlNode.SelectSingleNode("//MsgId") == null?"":requestParams.XmlNode.SelectSingleNode("//MsgId").InnerText.Trim();
            var FromUserName = requestParams.XmlNode.SelectSingleNode("//FromUserName") == null?"":requestParams.XmlNode.SelectSingleNode("//FromUserName").InnerText.Trim();
            var CreateTime   = requestParams.XmlNode.SelectSingleNode("//CreateTime") == null ? "" : requestParams.XmlNode.SelectSingleNode("//CreateTime").InnerText.Trim();

            if (!string.IsNullOrEmpty(MsgId))
            {
                if (JIT.CPOS.BS.BLL.WX.Const.Config.ListMsgId.ContainsKey(MsgId))//是否包含这个键值
                {
                    httpContext.Response.Write("");
                    httpContext.Response.Write("success");
                    return;
                    //  httpContext.Response.End();
                }
                else
                {
                    JIT.CPOS.BS.BLL.WX.Const.Config.ListMsgId.Add(MsgId, CreateTime);
                }
            }
            //else if (!string.IsNullOrEmpty(FromUserName) && !string.IsNullOrEmpty(CreateTime))
            //{
            //    var eventMsgId = FromUserName + CreateTime;
            //    if (JIT.CPOS.BS.BLL.WX.Const.Config.ListMsgId.ContainsKey(eventMsgId))
            //    {
            //        httpContext.Response.Write("");
            //        httpContext.Response.Write("success");
            //        // httpContext.Response.End();
            //        return;
            //    }
            //    else
            //    {
            //        JIT.CPOS.BS.BLL.WX.Const.Config.ListMsgId.Add(eventMsgId, CreateTime);
            //    }
            //}
            ////删除超过十分钟的数据
            // List<string> msgTemp = new List<string>();
            //foreach (var item in JIT.CPOS.BS.BLL.WX.Const.Config.ListMsgId)
            //{
            //      var a=  DateTime.Parse(new CommonBLL().GetRealTime(item.Value));//timestamp转换成的时间
            //    TimeSpan ts = DateTime.Now -  DateTime.Parse(  new CommonBLL().GetRealTime(item.Value));
            //    if (ts.TotalMinutes > 10)
            //    {
            //        msgTemp.Add(item.Key);
            //    }
            //}
            ////遍历删除数据
            //foreach (var item in msgTemp)
            //{
            //    JIT.CPOS.BS.BLL.WX.Const.Config.ListMsgId.Remove(item);
            //}



            //根据不同的消息类型,进行不同的处理操作
            switch (requestParams.MsgType)
            {
            case MsgType.TEXT:        //文本消息
                BaseService.WriteLogWeixin("消息类型:---------------texttext文本消息!");

                var content = requestParams.XmlNode.SelectSingleNode("//Content").InnerText.Trim();       //文本消息内容

                //HandlerText();
                //GetIsMoreCS(content); //多客服
                //StoreRebate(content, vipId);//门店返现推送消息
                #region
                var vipDcodeBll    = new VipDCodeBLL(requestParams.LoggingSessionInfo);
                var vipDcodeEntity = vipDcodeBll.GetByID(content.Replace(" ", ""));
                if (vipDcodeEntity == null)
                {
                    HandlerText();
                    GetIsMoreCS(content);     //多客服     (客服应该不需要加密吧)
                }
                else
                {
                    content = content.Replace(" ", "");    //去空格
                    if (vipDcodeEntity.IsReturn == 1)
                    {
                        if (DateTime.Now > (vipDcodeEntity.LastUpdateTime ?? DateTime.Now).AddSeconds(3))
                        {
                            StoreRebateRepeaterMessage(vipEntity[0], content);
                        }
                    }
                    else if (DateTime.Now > (vipDcodeEntity.CreateTime ?? DateTime.Now).AddDays(1))
                    {
                        StoreRebateByTimeOut(vipEntity[0]);
                    }
                    else
                    {
                        StoreRebate(content, vipId);    //门店返现推送消息
                    }
                }
                #endregion

                new WUserMessageDAO(requestParams.LoggingSessionInfo).Create(new WUserMessageEntity
                {
                    MessageId      = Utils.NewGuid(),
                    VipId          = vipId,
                    MaterialTypeId = "1",
                    Text           = content,
                    ImageUrl       = string.Empty,
                    OpenId         = requestParams.OpenId,
                    WeiXinId       = requestParams.WeixinId,
                    DataFrom       = 1
                });

                break;

            case MsgType.IMAGE:       //图片消息

                BaseService.WriteLogWeixin("消息类型:---------------image图片消息!");

                var picUrl = requestParams.XmlNode.SelectSingleNode("//PicUrl").InnerText.Trim(); //图片链接
                GetIsMoreCS(picUrl);                                                              //多客服
                new WUserMessageDAO(requestParams.LoggingSessionInfo).Create(new WUserMessageEntity
                {
                    MessageId      = Utils.NewGuid(),
                    VipId          = vipId,
                    MaterialTypeId = "2",
                    Text           = string.Empty,
                    ImageUrl       = picUrl,
                    OpenId         = requestParams.OpenId,
                    WeiXinId       = requestParams.WeixinId,
                    DataFrom       = 1
                });

                HandlerImage();

                break;

            case MsgType.LOCATION:        //地理位置
                BaseService.WriteLogWeixin("消息类型:---------------location地理位置!");
                HandlerLocation();
                break;

            case MsgType.EVENT:       //事件
                BaseService.WriteLogWeixin("消息类型:---------------event事件!");
                HandlerEvent(vip);
                break;
            }
        }
Ejemplo n.º 3
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;
            }
        }