Exemplo n.º 1
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;
            }
        }
Exemplo n.º 2
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;
            }
        }
Exemplo n.º 3
0
        public HttpResponseMessage ScanQRCode([FromBody] ScanQRCodeRequestModel requestParameter)
        {
            var json = new JavaScriptSerializer().Serialize(requestParameter);

            Loggers.Debug(new DebugLogInfo()
            {
                Message = $"[api/Order/ScanQRCode]接口,参数:\"{json}\""
            });
            try
            {
                #region MyRegion

                string customerId = ConfigurationManager.AppSettings["CustomerId"].Trim();
                string content    = string.Empty;

                #endregion

                #region

                var loggingSessionInfo = Default.GetLoggingSession(customerId, "1");

                if (string.IsNullOrWhiteSpace(requestParameter.ParaTmp))
                {
                    throw new APIException("paraTmp不能为空")
                          {
                              ErrorCode = 302
                          };
                }

                #endregion

                #region 创建临时匹配表

                VipDCodeBLL    vipDCodeServer = new VipDCodeBLL(loggingSessionInfo);
                VipDCodeEntity info           = new VipDCodeEntity();
                //由于CodeId有重复的概率,因此只取出最新的一条记录
                info = vipDCodeServer.QueryByEntity(
                    new VipDCodeEntity()
                {
                    DCodeId = ToStr(requestParameter.ParaTmp.Replace(" ", ""))
                }                                                                                     //又去掉了中间的空格
                    , new OrderBy[] { new OrderBy()
                                      {
                                          FieldName = "CreateTime", Direction = OrderByDirections.Desc
                                      } }
                    )[0];
                string status = string.Empty;
                string vipId  = string.Empty;
                string openId = string.Empty;
                if (info == null || info.DCodeId == null)
                {
                    throw new APIException("不存在对应的记录")
                          {
                              ErrorCode = 303
                          };
                }
                else
                {
                    status = info.Status;
                    openId = info.OpenId;
                    vipId  = info.VipId;
                }
                string mode = "Inbound";
                //if ((RP.Parameters.special.Mode == null || (!string.IsNullOrEmpty(RP.Parameters.special.Mode) && RP.Parameters.special.Mode.Equals("Inbound"))) && !string.IsNullOrEmpty(info.VipId) && info.VipId != RP.UserID)
                if ((mode == null || (!string.IsNullOrEmpty(mode) && mode.Equals("Inbound"))) &&
                    !string.IsNullOrEmpty(info.VipId) && info.VipId != requestParameter.UserId)
                {
                    VipBLL vipBll  = new VipBLL(loggingSessionInfo);
                    var    unitBll = new t_unitBLL(loggingSessionInfo);
                    var    UserBll = new T_UserBLL(loggingSessionInfo);

                    var vipInfo    = vipBll.GetByID(info.VipId);
                    var tt         = vipBll.GetUnitByUserId(requestParameter.UserId); //获取员工的会集店****
                    var UserEntity = UserBll.GetByID(vipInfo.SetoffUserId);           //当前会员集客员工

                    //
                    string UserStatus = "";
                    if (UserEntity != null)
                    {
                        UserStatus = UserEntity.user_status;
                    }

                    #region 会员会籍店、集客员工变动处理

                    //string.IsNullOrWhiteSpace(vipInfo.CouponInfo) || string.IsNullOrWhiteSpace(vipInfo.SetoffUserId) 目前未用到
                    if (string.IsNullOrWhiteSpace(vipInfo.HigherVipID) &&
                        string.IsNullOrWhiteSpace(vipInfo.SetoffUserId))
                    {
//当会员会籍店、集客员工为空时
                        if (!string.IsNullOrEmpty(tt))
                        {
                            vipInfo.CouponInfo   = tt;                                           //设为门店
                            vipInfo.SetoffUserId = requestParameter.UserId;                      //设为门店员工
                            vipInfo.Col21        = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //集客时间*****
                            vipInfo.Col23        = "1";
                        }
                        if (vipInfo != null && vipInfo.SetoffUserId == requestParameter.UserId)
                        {
                            //rsp.Message = "恭喜你集客成功。会员需要用心经营才会有订单哦!";
                        }
                    }
                    else
                    {
                        if (vipInfo != null && !string.IsNullOrEmpty(vipInfo.CouponInfo) &&
                            vipInfo.SetoffUserId != requestParameter.UserId)
                        {
                            //rsp.Message = "此客户已是会员,无需再集客。老会员更要服务好哦!";
                        }
                        else if (vipInfo != null && vipInfo.SetoffUserId == requestParameter.UserId &&
                                 !string.IsNullOrEmpty(vipInfo.Col21) &&
                                 Convert.ToDateTime(vipInfo.Col21).AddSeconds(3) < DateTime.Now) //col21:员工集客/或者分销商集客时间
                        {
                            //rsp.Message = "此客户此前已经被您集客,无需重复集客。!";
                        }
                    }
                    if (UserStatus.Trim().Equals("-1"))
                    {
// 当前会员的集客员工离职时
                        if (!string.IsNullOrEmpty(tt))
                        {
                            vipInfo.CouponInfo   = tt;                                           //设为门店
                            vipInfo.SetoffUserId = requestParameter.UserId;                      //设为门店员工
                            vipInfo.Col21        = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //集客时间*****
                            vipInfo.Col23        = "1";
                        }
                    }

                    #endregion

                    vipBll.Update(vipInfo);
                }

                #endregion


                var responseModel = new ScanQRCodeResponseModel()
                {
                    IsSucess = true,
                    Status   = status,
                    VipId    = vipId
                };
                return(Request.CreateResponse(HttpStatusCode.OK, responseModel));
            }
            catch (Exception ex)
            {
                var responseModel = new ScanQRCodeResponseModel()
                {
                    IsSucess     = false,
                    ErrorMessage = ex.Message
                };
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "error"));
            }
        }
Exemplo n.º 4
0
        public HttpResponseMessage QRCode(string UnitId, string ObjectID)
        {
            Loggers.Debug(new DebugLogInfo()
            {
                Message = $"[api/Vip/QRCode]接口,参数:\"UnitId:{UnitId}&ObjectID:{ObjectID}\""
            });
            try
            {
                string customerId         = ConfigurationManager.AppSettings["CustomerId"].Trim();
                var    loggingSessionInfo = Default.GetLoggingSession(customerId, ObjectID);
                loggingSessionInfo.Conn = ConfigurationManager.AppSettings["Conn"].Trim();

                var    imageUrl = string.Empty;
                Random ro       = new Random();
                var    iUp      = 100000000;
                var    iDown    = 50000000;


                var rpVipDCode = 0;                   //临时二维码
                var iResult    = ro.Next(iDown, iUp); //随机数

                string objectid = ObjectID;

                #region 获取微信帐号

                //门店关联的公众号
                var tuBll    = new t_unitBLL(loggingSessionInfo);
                var tuEntity = new t_unitEntity();
                if (!string.IsNullOrEmpty(UnitId))
                {
                    tuEntity =
                        tuBll.QueryByEntity(new t_unitEntity()
                    {
                        unit_id = UnitId
                    }, null)
                        .FirstOrDefault();
                }

                var server = new WApplicationInterfaceBLL(loggingSessionInfo);
                var wxObj  = new WApplicationInterfaceEntity();
                if (tuEntity != null && !string.IsNullOrEmpty(tuEntity.weiXinId))
                {
                    wxObj =
                        server.QueryByEntity(
                            new WApplicationInterfaceEntity {
                        WeiXinID = tuEntity.weiXinId, CustomerId = customerId
                    },
                            null).FirstOrDefault();
                }
                else
                {
                    wxObj =
                        server.QueryByEntity(new WApplicationInterfaceEntity {
                        CustomerId = customerId
                    }, null)
                        .FirstOrDefault();
                }

                if (wxObj == null)
                {
                    throw new APIException("不存在对应的微信帐号")
                          {
                              ErrorCode = 302
                          };
                }
                else
                {
                    var commonServer = new CommonBLL();

                    imageUrl = commonServer.GetQrcodeUrl(wxObj.AppID
                                                         , wxObj.AppSecret
                                                         , rpVipDCode.ToString("")       //二维码类型  0: 临时二维码  1:永久二维码
                                                         , iResult, loggingSessionInfo); //iResult作为场景值ID,临时二维码时为32位整型,永久二维码时只支持1--100000
                    //"https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQGN7zoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL1dreENCS1htX0xxQk94SEJ6MktIAAIEUk88VwMECAcAAA==";
                    //"https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQGN7zoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL1dreENCS1htX0xxQk94SEJ6MktIAAIEUk88VwMECAcAAA==";
                    if (imageUrl != null && !imageUrl.Equals(""))
                    {
                        DownloadImage downloadServer   = new DownloadImage();
                        string        downloadImageUrl = ConfigurationManager.AppSettings["website_WWW"];
                        imageUrl = downloadServer.DownloadFile(imageUrl, downloadImageUrl);
                    }
                }

                #endregion


                #region 创建临时匹配表

                VipDCodeBLL    vipDCodeServer = new VipDCodeBLL(loggingSessionInfo);
                VipDCodeEntity info           = new VipDCodeEntity();
                info.DCodeId              = iResult.ToString(); //记录传过去的二维码场景值****(保存到数据库时没加空格)
                info.CustomerId           = customerId;
                info.UnitId               = UnitId;             //获取会集店
                info.Status               = "0";
                info.IsReturn             = 0;
                info.DCodeType            = 2; // add by donal 2014-9-22 10:02:08
                loggingSessionInfo.UserID = ObjectID;
                info.CreateBy             = ObjectID;
                info.ImageUrl             = imageUrl;
                //info.VipId = RP.UserID;
                info.ObjectId = ObjectID; //分享经销商的vipid
                vipDCodeServer.Create(info);

                #endregion


                var model = new QRCodeResponseModel()
                {
                    IsSucess = true,
                    ImageUrl = imageUrl,
                    paraTmp  = iResult.ToString().Insert(4, " ")
                };

                Loggers.Debug(new DebugLogInfo()
                {
                    Message = $"setSignUp content: {model}"
                });


                return(Request.CreateResponse(HttpStatusCode.OK, model));
            }
            catch (Exception ex)
            {
                var model = new QRCodeResponseModel()
                {
                    IsSucess     = false,
                    ErrorMessage = string.Format("获取二维码出错:{0}", ex.Message)
                };
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("获取二维码出错:{0}", ex.Message)
                });
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, model));
            }
        }
        const int ERROR_LOAD_WRONG  = 302; //打开出错
        protected override GetSetoffToolDetailRD ProcessRequest(APIRequest <GetSetoffToolDetailRP> pRequest)
        {
            string content    = string.Empty;
            string customerId = string.Empty;
            GetSetoffToolDetailRD setoffToolDetailRD = new GetSetoffToolDetailRD();
            var para = pRequest.Parameters;

            customerId = CurrentUserInfo.CurrentUser.customer_id;
            try
            {
                var    imageUrl              = string.Empty;
                Random ro                    = new Random();
                var    iUp                   = 100000000;
                var    iDown                 = 50000000;
                var    rpVipDCode            = 0;                   //临时二维码
                var    iResult               = ro.Next(iDown, iUp); //随机数
                var    userQrCodeBll         = new WQRCodeManagerBLL(CurrentUserInfo);
                var    imgBll                = new ObjectImagesBLL(CurrentUserInfo);
                var    setOffPosterBLL       = new SetoffPosterBLL(CurrentUserInfo);
                var    SetoffToolUserViewBLL = new SetoffToolUserViewBLL(CurrentUserInfo);
                var    SetoffToolsBll        = new SetoffToolsBLL(CurrentUserInfo);
                var    SetOffPosterInfo      = setOffPosterBLL.QueryByEntity(new SetoffPosterEntity()
                {
                    SetoffPosterID = new Guid(para.ObjectId)
                }, null);                                                                                                                         //获取集客海报信息
                var setoffEventBLL  = new SetoffEventBLL(CurrentUserInfo);
                var setoffEventInfo = setoffEventBLL.QueryByEntity(new SetoffEventEntity()
                {
                    Status = "10", SetoffType = 1, CustomerId = customerId
                }, null);
                //var SetoffToolsInfo = SetoffToolsBll.QueryByEntity(new SetoffToolsEntity() { ObjectId = para.ObjectId, Status = "10", ToolType = para.ToolType, SetoffEventID = setoffEventInfo[0].SetoffEventID }, null);//获取工具信息
                //VipDcode=9生成永久二维码
                if (para.VipDCode == 9)
                {
                    //根据分享人ID和对象ID获取永久二维码信息
                    var userQrCode = userQrCodeBll.QueryByEntity(new WQRCodeManagerEntity()
                    {
                        ObjectId = para.ObjectId
                    }, null);
                    if (userQrCode != null && userQrCode.Length > 0)
                    {
                        if (para.ToolType == "Coupon")//如果类型为优惠券则返回二维码
                        {
                            setoffToolDetailRD.ToolType = para.ToolType;
                        }
                        if (para.ToolType == "SetoffPoster")//如果为集客海报则返回背景图和二维码
                        {
                            if (SetOffPosterInfo != null)
                            {
                                var backImgInfo = imgBll.QueryByEntity(new ObjectImagesEntity()
                                {
                                    ObjectId = SetOffPosterInfo[0].ImageId
                                }, null);
                                setoffToolDetailRD.ToolType   = para.ToolType;
                                setoffToolDetailRD.imageUrl   = userQrCode[0].ImageUrl;
                                setoffToolDetailRD.paraTemp   = userQrCode[0].QRCode;
                                setoffToolDetailRD.backImgUrl = backImgInfo[0].ImageURL;
                            }
                        }
                        setoffToolDetailRD.imageUrl = userQrCode[0].ImageUrl;
                        setoffToolDetailRD.paraTemp = userQrCode[0].QRCode;
                        return(setoffToolDetailRD);
                    }
                    //获取当前二维码 最大值
                    iResult    = new WQRCodeManagerBLL(CurrentUserInfo).GetMaxWQRCod() + 1;
                    rpVipDCode = 1;
                }

                #region 获取微信帐号
                var server = new WApplicationInterfaceBLL(CurrentUserInfo);
                var wxObj  = new WApplicationInterfaceEntity();
                wxObj = server.QueryByEntity(new WApplicationInterfaceEntity {
                    CustomerId = customerId
                }, null).FirstOrDefault();
                if (wxObj == null)
                {
                    throw new APIException("不存在对应的微信帐号.")
                          {
                              ErrorCode = ERROR_NULL_WXOBJ
                          };
                }
                else
                {
                    var commonServer = new CommonBLL();
                    //rpVipDCode 二维码类型  0: 临时二维码  1:永久二维码
                    imageUrl = commonServer.GetQrcodeUrl(wxObj.AppID, wxObj.AppSecret, rpVipDCode.ToString(""), iResult, CurrentUserInfo);//iResult作为场景值ID,临时二维码时为32位整型,永久二维码时只支持1--100000
                    //供本地测试时使用  "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQGN7zoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL1dreENCS1htX0xxQk94SEJ6MktIAAIEUk88VwMECAcAAA==";
                }
                #endregion

                if (para.VipDCode == 9 && !string.IsNullOrEmpty(imageUrl))    //永久二维码
                {
                    #region 创建店员永久二维码匹配表
                    var    userQrTypeBll = new WQRCodeTypeBLL(CurrentUserInfo);
                    string pTypeCode     = string.Empty;
                    if (para.ToolType.ToLower() == "coupon")
                    {
                        pTypeCode = "CouponQrCode";
                    }
                    if (para.ToolType.ToLower() == "setoffposter")
                    {
                        pTypeCode = "SetoffPosterQrCode";
                    }
                    if (para.ToolType.ToLower() == "superretail")
                    {
                        pTypeCode = "SuperRetailQrCode";
                    }
                    var userQrType = userQrTypeBll.QueryByEntity(new WQRCodeTypeEntity()
                    {
                        TypeCode = pTypeCode
                    }, null);                                                                                            //"SuperRetailQrCode=超级分销商二维码"
                    if (userQrType != null && userQrType.Length > 0)
                    {
                        var userQrcodeBll = new WQRCodeManagerBLL(CurrentUserInfo);
                        var userQrCode    = new WQRCodeManagerEntity();
                        userQrCode.QRCode        = iResult.ToString();//记录传过去的二维码场景值
                        userQrCode.QRCodeTypeId  = userQrType[0].QRCodeTypeId;
                        userQrCode.IsUse         = 1;
                        userQrCode.CustomerId    = customerId;
                        userQrCode.ImageUrl      = imageUrl;
                        userQrCode.ApplicationId = wxObj.ApplicationId;
                        //objectId 为集客海报ID或者优惠券ID
                        userQrCode.ObjectId = para.ObjectId;
                        userQrcodeBll.Create(userQrCode);
                    }
                    #endregion
                }
                else
                {
                    #region 创建临时匹配表
                    VipDCodeBLL    vipDCodeServer = new VipDCodeBLL(CurrentUserInfo);
                    VipDCodeEntity info           = new VipDCodeEntity();
                    info.DCodeId    = iResult.ToString();//记录传过去的二维码场景值****(保存到数据库时没加空格)
                    info.CustomerId = customerId;
                    VipBLL vipBll = new VipBLL(CurrentUserInfo);
                    info.UnitId      = "";
                    info.Status      = "0";
                    info.IsReturn    = 0;
                    info.DCodeType   = para.VipDCode;
                    info.CreateBy    = CurrentUserInfo.UserID;
                    info.ImageUrl    = imageUrl;
                    info.VipId       = "";
                    info.ObjectId    = para.ObjectId;   //工具对象ID(优惠券或集客海报对象ID)
                    info.OwnerUserId = para.ShareVipId; //分享人ID
                    vipDCodeServer.Create(info);
                    #endregion
                }
                int flag         = 0;//定义是否需要新增打开数据,0=不需要新增,1=需要新增
                var UserViewData = SetoffToolUserViewBLL.QueryByEntity(new SetoffToolUserViewEntity()
                {
                    ObjectId = para.ObjectId, UserID = CurrentUserInfo.UserID
                }, null);
                if (!string.IsNullOrEmpty(para.SetoffToolID))
                {
                    UserViewData = SetoffToolUserViewBLL.QueryByEntity(new SetoffToolUserViewEntity()
                    {
                        ObjectId = para.ObjectId, UserID = CurrentUserInfo.UserID, SetoffToolID = new Guid(para.SetoffToolID)
                    }, null);
                }
                if (UserViewData.Length == 0 && !string.IsNullOrEmpty(para.SetoffToolID) && para.PlatformType != "3")
                {
                    flag = 1;                  //当为1时进行增加打开工具记录
                }
                if (para.ToolType == "Coupon") //如果类型为优惠券则返回二维码
                {
                    #region 用户领优惠券过程
                    var CouponTypeBLL       = new CouponTypeBLL(CurrentUserInfo);
                    var couponBLL           = new CouponBLL(CurrentUserInfo);
                    var CouponSourceBLL     = new CouponSourceBLL(CurrentUserInfo);
                    var VipCouponMappingBLL = new VipCouponMappingBLL(CurrentUserInfo);

                    int?SurplusCount   = 0; //先获得剩余张数
                    int hasCouponCount = 0; //已领张数 如果>0表示已领取过就不让他领,=0就领取
                    var couponTypeInfo = CouponTypeBLL.QueryByEntity(new CouponTypeEntity()
                    {
                        CouponTypeID = new Guid(para.ObjectId)
                    }, null);

                    if (couponTypeInfo != null)
                    {
                        string couponIsVocher = string.Empty;
                        if (couponTypeInfo[0].IsVoucher == null)
                        {
                            SurplusCount = couponTypeInfo[0].IssuedQty - 0;
                        }
                        else
                        {
                            SurplusCount = couponTypeInfo[0].IssuedQty - couponTypeInfo[0].IsVoucher;
                        }
                        if (SurplusCount != 0 && para.ShareVipId != null && para.ShareVipId != "")// 通过列表进详细自己不能领券
                        {
                            //当剩余数量不为0时,进行下一步判断是否存在已领券的信息
                            hasCouponCount = VipCouponMappingBLL.GetReceiveCouponCount(CurrentUserInfo.UserID, para.ObjectId, "Share");
                            if (hasCouponCount == 0)//如果等于零,开始领券流程
                            {
                                //关联优惠券让用户领券
                                var redisVipMappingCouponBLL = new JIT.CPOS.BS.BLL.RedisOperationBLL.Coupon.RedisVipMappingCouponBLL();
                                try
                                {
                                    //执行领取操作
                                    redisVipMappingCouponBLL.InsertDataBase(CurrentUserInfo.CurrentUser.customer_id, CurrentUserInfo.UserID, para.SetoffToolID, "Share", new CC_Coupon()
                                    {
                                        CustomerId   = CurrentUserInfo.CurrentUser.customer_id,
                                        CouponTypeId = para.ObjectId
                                    });
                                    setoffToolDetailRD.Name = couponTypeInfo[0].CouponTypeName + ",已飞入您的账户";
                                }
                                catch (Exception ex)
                                {
                                    setoffToolDetailRD.Name = "很遗憾此次优惠券" + couponTypeInfo[0].CouponTypeName + "的分享已失效,下次请及时领取.";
                                }
                            }
                        }
                        else
                        {
                            //如果剩余数量为0时,给出已领完提示
                            if (para.ShareVipId != null && para.ShareVipId != "")
                            {
                                setoffToolDetailRD.Name = "很遗憾您来迟一步优惠券" + couponTypeInfo[0].CouponTypeName + "已被领完.";
                                //throw new APIException("很遗憾您来迟一步券已被领完.") { ErrorCode = ERROR_LOAD_WRONG };
                            }
                        }
                        if (setoffToolDetailRD.Name == null || setoffToolDetailRD.Name == "")
                        {
                            setoffToolDetailRD.Name = couponTypeInfo[0].CouponTypeName;
                        }
                        setoffToolDetailRD.StartTime = couponTypeInfo[0].BeginTime == null?Convert.ToDateTime(couponTypeInfo[0].CreateTime).ToString("yyyy-MM-dd") : Convert.ToDateTime(couponTypeInfo[0].BeginTime).ToString("yyyy-MM-dd");

                        setoffToolDetailRD.EndTime     = couponTypeInfo[0].EndTime == null ? "" : Convert.ToDateTime(couponTypeInfo[0].EndTime).ToString("yyyy-MM-dd");
                        setoffToolDetailRD.ServiceLife = couponTypeInfo[0].ServiceLife.ToString();
                    }
                    #endregion
                    setoffToolDetailRD.ToolType = para.ToolType;                     //返回工具类别
                    setoffToolDetailRD.imageUrl = imageUrl;                          //返回临时二维码
                    setoffToolDetailRD.paraTemp = iResult.ToString().Insert(4, " "); //加空格,加空格有什么作用?
                }
                if (para.ToolType == "SetoffPoster")                                 //如果为集客海报则返回背景图和二维码
                {
                    if (SetOffPosterInfo != null && SetOffPosterInfo.Length > 0)
                    {
                        var backImgInfo = imgBll.QueryByEntity(new ObjectImagesEntity()
                        {
                            ImageId = SetOffPosterInfo[0].ImageId
                        }, null);
                        setoffToolDetailRD.ToolType   = para.ToolType;
                        setoffToolDetailRD.imageUrl   = imageUrl;
                        setoffToolDetailRD.paraTemp   = iResult.ToString().Insert(4, " "); //加空格,加空格有什么作用?
                        setoffToolDetailRD.backImgUrl = backImgInfo[0].ImageURL;
                        setoffToolDetailRD.Name       = SetOffPosterInfo[0].Name;
                    }
                }
                if (flag == 1)//当为1是需进行打开工具的记录
                {
                    var SetoffToolUserView = new SetoffToolUserViewEntity();
                    SetoffToolUserView.SetoffToolUserViewID = Guid.NewGuid();
                    SetoffToolUserView.SetoffEventID        = setoffEventInfo[0].SetoffEventID;
                    SetoffToolUserView.SetoffToolID         = new Guid(para.SetoffToolID);
                    SetoffToolUserView.ToolType             = para.ToolType;
                    SetoffToolUserView.ObjectId             = para.ObjectId;
                    SetoffToolUserView.NoticePlatformType   = 1;
                    SetoffToolUserView.UserID         = CurrentUserInfo.UserID;
                    SetoffToolUserView.IsOpen         = 1;
                    SetoffToolUserView.OpenTime       = System.DateTime.Now;
                    SetoffToolUserView.CustomerId     = customerId;
                    SetoffToolUserView.CreateTime     = System.DateTime.Now;
                    SetoffToolUserView.CreateBy       = CurrentUserInfo.UserID;
                    SetoffToolUserView.LastUpdateTime = System.DateTime.Now;
                    SetoffToolUserView.LastUpdateBy   = CurrentUserInfo.UserID;
                    SetoffToolUserView.IsDelete       = 0;
                    SetoffToolUserViewBLL.Create(SetoffToolUserView);
                }
            }
            catch (Exception ex)
            {
                throw new APIException(ex.Message)
                      {
                          ErrorCode = ERROR_CODES.DEFAULT_ERROR
                      };
            }
            return(setoffToolDetailRD);
        }
Exemplo n.º 6
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;
            }
        }