public string Process(RequestMsgModel msg)
        {
            SubscribeEventRequestMsgModel msgMode = msg as SubscribeEventRequestMsgModel;

            if (msgMode != null)
            {
                SiteActivityDAL dal      = new SiteActivityDAL();
                SiteActivity    activity = dal.GetSiteAct(Params["SiteCode"].ToString(), "Coupon");
                if (activity != null)
                {
                    CouponDAL cdal = new CouponDAL();
                    if (!cdal.ExistCoupon(Params["SiteCode"].ToString(), activity.ID, msgMode.FromUserName))
                    {
                        Coupon coupon = new Coupon()
                        {
                            SiteCode       = Params["SiteCode"].ToString(),
                            SiteActivityID = activity.ID,
                            OpenID         = msgMode.FromUserName,
                            CouponCode     = GetCouponCode(msgMode.FromUserName),
                            CouponStatus   = 0
                        };
                        cdal.InsertInfo(coupon);
                    }
                }
            }
            return(string.Empty);
        }
Esempio n. 2
0
        protected override bool BeforeLoad()
        {
            if (null == Request.QueryString["id"])
            {
                return(false);
            }
            CouponID = Common.Common.NoHtml(Request.QueryString["id"].ToString());
            string strGuid = string.Empty;

            if (null != Request.QueryString["sitecode"] && null != Request.QueryString["openid"])
            {
                SiteCode = Common.Common.NoHtml(Request.QueryString["sitecode"].ToString());
                OpenID   = Common.Common.NoHtml(Request.QueryString["openid"].ToString());
                //插入优惠券
                SiteActivityDAL dalActive = new SiteActivityDAL();
                DataSet         dsActive  = dalActive.GetActivityDetail(CouponID);
                if (null != dsActive && dsActive.Tables.Count > 0 && dsActive.Tables[0].Rows.Count > 0)
                {
                    strGuid = Guid.NewGuid().ToString("N");
                    CouponDAL cdal = new CouponDAL();
                    if (!cdal.ExistCoupon(SiteCode, CouponID, OpenID))
                    {
                        Coupon coupon = new Coupon()
                        {
                            ID             = strGuid,
                            SiteCode       = SiteCode,
                            SiteActivityID = CouponID,
                            OpenID         = OpenID,
                            CouponStatus   = 0
                        };
                        cdal.InsertInfo(coupon);
                    }
                }
                CouponID = strGuid;
            }
            else
            {
                SiteActivityDAL dalActive = new SiteActivityDAL();
                DataSet         dsActive  = dalActive.GetActivityDetail(CouponID);
                if (null != dsActive && dsActive.Tables.Count > 0 && dsActive.Tables[0].Rows.Count > 0)
                {
                    SiteCode = dsActive.Tables[0].Rows[0]["SIteCode"].ToString();
                }
            }
            return(base.BeforeLoad());
        }
Esempio n. 3
0
        protected override void AddTempData(JinianNet.JNTemplate.TemplateContext context)
        {
            base.AddTempData(context);
            //取最新抢购的优惠活动
            List <Model.ACT.SiteActivity> liActive = new List <Model.ACT.SiteActivity>();

            DAL.ACT.SiteActivityDAL dalActive = new SiteActivityDAL();

            List <MyCouponInfo> liCoupon = new List <MyCouponInfo>();
            CouponDAL           dalCoup  = new CouponDAL();

            DataSet dsActive = dalActive.GetActivityList(" SiteCode = '" + SiteCode + "' AND ActStatus = 1 AND ActType = 'RushCoupon' AND StartTime < GETDATE() AND EndTime > GETDATE() ");

            if (null != dsActive && dsActive.Tables.Count > 0 && dsActive.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow row in dsActive.Tables[0].Rows)
                {
                    if (!dalCoup.ExistCoupon(SiteCode, row["ID"].ToString(), OpenID))
                    {
                        Model.ACT.SiteActivity modelActive = DataConvert.DataRowToModel <Model.ACT.SiteActivity>(row);
                        liActive.Add(modelActive);
                    }
                }
            }

            DataSet ds      = dalCoup.GetCouponInfoList(SiteCode, OpenID);
            string  strInfo = string.Empty;

            if (null != ds && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    MyCouponInfo model = DataConvert.DataRowToModel <MyCouponInfo>(row);
                    liCoupon.Add(model);
                }
            }
            else
            {
                strInfo = "亲,你还没有参加过活动哦,多多关注我们的新活动!";
            }
            context.TempData["openid"]          = OpenID;
            context.TempData["rushcoupon_list"] = liActive;
            context.TempData["coupon_list"]     = liCoupon;
            context.TempData["couponinfo"]      = strInfo;
        }
Esempio n. 4
0
        /// <summary>
        /// 处理回复消息
        /// "text":回复文本消息处理,MsgValue对应回复的文本
        /// "sub_auto_coupon":回复订阅自动优惠券处理,MsgValue对应回复的图文消息ID
        /// "auto_news_article":根据文章自动生成图文消息进行回复,MsgValue为类别ID
        /// "news":回复图文表中的消息,MsgValue为图文消息表ID集,用逗号分隔
        /// </summary>
        /// <param name="replyMsgType"></param>
        /// <param name="replyMsgValue"></param>
        /// <param name="customParams"></param>
        /// <returns></returns>
        private string ProcessReply(RequestMsgModel msgModel, string replyMsgType, string replyMsgValue)
        {
            string res = string.Empty;

            try
            {
                switch (replyMsgType.ToLower())
                {
                case "text":
                    //回复文本消息处理,MsgValue对应回复的文本
                    TextResponseMsgModel textMsg = new TextResponseMsgModel()
                    {
                        ToUserName   = msgModel.FromUserName,
                        FromUserName = msgModel.ToUserName,
                        CreateTime   = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(),
                        Content      = replyMsgValue == null ? string.Empty : TransformText(replyMsgValue, msgModel)
                    };
                    res = textMsg.ToString();
                    break;

                case "voice":
                    //回复语音消息处理,MsgValue对应回复的文本
                    VoiceResponseMsgModel voiceMsg = new VoiceResponseMsgModel()
                    {
                        ToUserName   = msgModel.FromUserName,
                        FromUserName = msgModel.ToUserName,
                        CreateTime   = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(),
                    };
                    Media media = MediaDAL.CreateInstance().GetMediaByID(replyMsgValue);
                    if (media != null && !string.IsNullOrEmpty(media.MediaID))
                    {
                        voiceMsg.MediaId = media.MediaID;
                    }
                    res = voiceMsg.ToString();
                    break;

                case "wxpay_test":
                    //用于微信支付测试
                    TextResponseMsgModel textMsgx = new TextResponseMsgModel()
                    {
                        ToUserName   = msgModel.FromUserName,
                        FromUserName = msgModel.ToUserName,
                        CreateTime   = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(),
                        Content      = string.Format("<a href='{0}/Payment/wxpay/wxpayDemo.aspx?openid={1}'>微信支付测试</a>", GetSiteUrl(), msgModel.FromUserName)
                    };
                    res = textMsgx.ToString();
                    break;

                case "transfer_customer_service":
                    //将消息转发到多客服
                    TransferCustomerServiceResponseMsgModel transferMsg = new TransferCustomerServiceResponseMsgModel()
                    {
                        ToUserName   = msgModel.FromUserName,
                        FromUserName = msgModel.ToUserName,
                        CreateTime   = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(),
                    };
                    res = transferMsg.ToString();
                    break;

                case "sub_auto_coupon":
                    //回复订阅自动优惠券处理,MsgValue对应回复的优惠券图文消息ID
                    //SubscribeCouponActHandle sch = new SubscribeCouponActHandle();
                    SiteActivityDAL dal      = new SiteActivityDAL();
                    SiteActivity    activity = dal.GetSiteAct(siteCode, "Coupon");
                    if (activity != null)
                    {
                        CouponDAL cdal = new CouponDAL();
                        if (!cdal.ExistCoupon(siteCode, activity.ID, msgModel.FromUserName))
                        {
                            Coupon coupon = new Coupon()
                            {
                                SiteCode       = siteCode,
                                SiteActivityID = activity.ID,
                                OpenID         = msgModel.FromUserName,
                                //CouponCode = msgModel.FromUserName,
                                CouponStatus = 0
                            };
                            cdal.InsertInfo(coupon);
                        }
                    }
                    CouponNewsDAL nmDAL = new CouponNewsDAL();
                    CouponNews    nm    = nmDAL.GetCouponNews(replyMsgValue);
                    if (nm != null)
                    {
                        NewsResponseMsgModel newsModel = new NewsResponseMsgModel()
                        {
                            ToUserName   = msgModel.FromUserName,
                            FromUserName = msgModel.ToUserName,
                            CreateTime   = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString()
                        };
                        List <Article> articles = new List <Article>();
                        articles.Add(new Article()
                        {
                            Title       = nm.Title,
                            Description = nm.Description,
                            PicUrl      = GetPicUrl(nm.PicUrl),
                            Url         = TransformUrl(nm.Url, msgModel)
                        });
                        newsModel.Articles = articles;
                        res = newsModel.ToString();
                    }
                    break;

                case "auto_coupon_category":
                    SiteActivityDAL dalCatList  = new SiteActivityDAL();
                    SiteActivity    activityCat = dalCatList.GetSiteAct(siteCode, "Coupon");
                    if (activityCat != null)
                    {
                        CouponDAL cdal = new CouponDAL();
                        if (!cdal.ExistCoupon(siteCode, activityCat.ID, msgModel.FromUserName))
                        {
                            Coupon coupon = new Coupon()
                            {
                                SiteCode       = siteCode,
                                SiteActivityID = activityCat.ID,
                                OpenID         = msgModel.FromUserName,
                                //CouponCode = msgModel.FromUserName,
                                CouponStatus = 0
                            };
                            cdal.InsertInfo(coupon);
                        }
                    }
                    ArticleDAL catDal = new ArticleDAL();
                    DataSet    cdsCat = catDal.GetCategoryList(siteCode, replyMsgValue);
                    if (cdsCat != null && cdsCat.Tables.Count > 0 && cdsCat.Tables[0] != null && cdsCat.Tables[0].Rows.Count > 0)
                    {
                        int i = 0;
                        NewsResponseMsgModel newsModel = new NewsResponseMsgModel()
                        {
                            ToUserName   = msgModel.FromUserName,
                            FromUserName = msgModel.ToUserName,
                            CreateTime   = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString()
                        };
                        List <Article> articles = new List <Article>();
                        foreach (DataRow dr in cdsCat.Tables[0].Rows)
                        {
                            if (++i > 4)
                            {
                                break;
                            }
                            articles.Add(new Article()
                            {
                                Title       = dr["Title"].ToString(),
                                Description = dr["Summary"].ToString(),
                                //Description = RemoveHtmlTag(dr["Content"].ToString(), 30),
                                PicUrl = GetPicUrl(dr["Pic"].ToString()),
                                Url    = GetArticleUrl(dr["ID"].ToString())
                            });
                        }
                        newsModel.Articles = articles;
                        res = newsModel.ToString();
                    }
                    break;

                case "auto_news_article":
                    //根据文章自动生成图文消息进行回复,MsgValue为文章ID
                    ArticleDAL aDal = new ArticleDAL();
                    DataSet    ds   = aDal.GetArticleDetail(replyMsgValue);
                    if (ds != null && ds.Tables.Count > 0 && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                    {
                        int i = 0;
                        NewsResponseMsgModel newsModel = new NewsResponseMsgModel()
                        {
                            ToUserName   = msgModel.FromUserName,
                            FromUserName = msgModel.ToUserName,
                            CreateTime   = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString()
                        };
                        List <Article> articles = new List <Article>();
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            if (++i > 4)
                            {
                                break;
                            }
                            articles.Add(new Article()
                            {
                                Title       = dr["Title"].ToString(),
                                Description = dr["Summary"].ToString(),
                                //Description = RemoveHtmlTag(dr["Content"].ToString(), 100),
                                PicUrl = GetPicUrl(dr["Pic"].ToString()),
                                Url    = GetArticleUrl(dr["ID"].ToString())
                            });
                        }
                        newsModel.Articles = articles;
                        res = newsModel.ToString();
                    }
                    break;

                case "auto_news_category":
                    //根据类别自动生成图文消息进行回复,MsgValue为类别ID
                    ArticleDAL cDal = new ArticleDAL();
                    DataSet    cds  = cDal.GetCategoryList(siteCode, replyMsgValue);
                    if (cds != null && cds.Tables.Count > 0 && cds.Tables[0] != null && cds.Tables[0].Rows.Count > 0)
                    {
                        int i = 0;
                        NewsResponseMsgModel newsModel = new NewsResponseMsgModel()
                        {
                            ToUserName   = msgModel.FromUserName,
                            FromUserName = msgModel.ToUserName,
                            CreateTime   = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString()
                        };
                        List <Article> articles = new List <Article>();
                        foreach (DataRow dr in cds.Tables[0].Rows)
                        {
                            if (++i > 4)
                            {
                                break;
                            }
                            articles.Add(new Article()
                            {
                                Title       = dr["Title"].ToString(),
                                Description = dr["Summary"].ToString(),
                                //Description = RemoveHtmlTag(dr["Content"].ToString(), 30),
                                PicUrl = GetPicUrl(dr["Pic"].ToString()),
                                Url    = GetArticleUrl(dr["ID"].ToString())
                            });
                        }
                        newsModel.Articles = articles;
                        res = newsModel.ToString();
                    }
                    break;

                case "coupon":
                    //回复图文表中的消息,MsgValue为图文消息表ID集,用逗号分隔
                    NewsMsgDAL nmDAL1 = new NewsMsgDAL();
                    NewsMsg    nms    = nmDAL1.GetNewsMsg(replyMsgValue);
                    if (nms != null)
                    {
                        NewsResponseMsgModel newsModel = new NewsResponseMsgModel()
                        {
                            ToUserName   = msgModel.FromUserName,
                            FromUserName = msgModel.ToUserName,
                            CreateTime   = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString()
                        };
                        List <Article> articles = new List <Article>();
                        articles.Add(new Article()
                        {
                            Title       = nms.Title,
                            Description = nms.Description,
                            PicUrl      = GetPicUrl(nms.PicUrl),
                            Url         = TransformUrl(nms.Url, msgModel)
                        });
                        newsModel.Articles = articles;
                        res = newsModel.ToString();
                    }
                    break;

                case "news":
                    //回复图文表中的消息,MsgValue为图文消息表ID集,用逗号分隔
                    NewsMsgDAL      nmDALs   = new NewsMsgDAL();
                    IList <NewsMsg> newsMsgs = nmDALs.GetNewsMsgs(replyMsgValue);
                    if (newsMsgs != null)
                    {
                        NewsResponseMsgModel newsModel = new NewsResponseMsgModel()
                        {
                            ToUserName   = msgModel.FromUserName,
                            FromUserName = msgModel.ToUserName,
                            CreateTime   = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString()
                        };
                        List <Article> articles = new List <Article>();
                        foreach (NewsMsg msg in newsMsgs)
                        {
                            articles.Add(new Article()
                            {
                                Title       = msg.Title,
                                Description = msg.Description,
                                PicUrl      = GetPicUrl(msg.PicUrl),
                                Url         = TransformUrl(msg.Url, msgModel)
                            });
                        }
                        newsModel.Articles = articles;
                        res = newsModel.ToString();
                    }
                    break;

                case "url":
                    //根据文章自动生成图文消息进行回复,MsgValue为文章ID
                    DAL.SYS.AccountDAL dalUrl = new DAL.SYS.AccountDAL();
                    DataSet            dsUrl  = dalUrl.GetAccountExtData(replyMsgValue);
                    if (dsUrl != null && dsUrl.Tables.Count > 0 && dsUrl.Tables[0] != null && dsUrl.Tables[0].Rows.Count > 0)
                    {
                        int i = 0;
                        NewsResponseMsgModel newsModel = new NewsResponseMsgModel()
                        {
                            ToUserName   = msgModel.FromUserName,
                            FromUserName = msgModel.ToUserName,
                            CreateTime   = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString()
                        };
                        List <Article> articles = new List <Article>();
                        foreach (DataRow dr in dsUrl.Tables[0].Rows)
                        {
                            if (++i > 4)
                            {
                                break;
                            }
                            articles.Add(new Article()
                            {
                                Title       = dr["Name"].ToString(),
                                Description = dr["Summary"].ToString(),
                                PicUrl      = GetPicUrl(dr["Photo"].ToString()),
                                Url         = GetSiteInfo(dr["ID"].ToString())
                            });
                        }
                        newsModel.Articles = articles;
                        res = newsModel.ToString();
                    }
                    break;

                case "hp_photo_text":
                    //为当前hp_photo对应的照片附加文字信息
                    PhotoDAL photoDal = new PhotoDAL();
                    if (photoDal.ExistPhoto(siteCode, msgModel.FromUserName, 0))
                    {
                        TextRequestMsgModel temp = msgModel as TextRequestMsgModel;
                        string text = temp.Content.Replace("#ms", "");
                        //附加图片文字
                        photoDal.UpdateAttachText(siteCode, msgModel.FromUserName, text);
                        TextResponseMsgModel textMsg2 = new TextResponseMsgModel()
                        {
                            ToUserName   = msgModel.FromUserName,
                            FromUserName = msgModel.ToUserName,
                            CreateTime   = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(),
                            Content      = replyMsgValue == null ? string.Empty : TransformText(replyMsgValue, msgModel)
                        };
                        res = textMsg2.ToString();
                    }
                    else
                    {
                        TextResponseMsgModel textMsg2 = new TextResponseMsgModel()
                        {
                            ToUserName   = msgModel.FromUserName,
                            FromUserName = msgModel.ToUserName,
                            CreateTime   = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(),
                            Content      = "对不起,您暂未参加图片打印活动!"
                        };
                        res = textMsg2.ToString();
                    }
                    break;

                case "hp_photo_ticket":
                    //对当前hp_photo对应的照片进行打印认证
                    PrintCodeDAL        printCodeDAL = new PrintCodeDAL();
                    TextRequestMsgModel temp1        = msgModel as TextRequestMsgModel;
                    string printCode = temp1.Content.Replace("#dy", "");
                    string clientID  = printCodeDAL.GetClientIDByPrintCode(printCode, siteCode);
                    ExceptionLogDAL.InsertExceptionLog(new ExceptionLog()
                    {
                        Message = clientID
                    });
                    if (!string.IsNullOrEmpty(clientID))
                    {
                        PhotoDAL photoDal1 = new PhotoDAL();
                        photoDal1.UpdatePrintInfo(printCode, clientID, siteCode, msgModel.FromUserName);
                        TextResponseMsgModel textMsg2 = new TextResponseMsgModel()
                        {
                            ToUserName   = msgModel.FromUserName,
                            FromUserName = msgModel.ToUserName,
                            CreateTime   = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(),
                            Content      = replyMsgValue == null ? string.Empty : TransformText(replyMsgValue, msgModel)
                        };
                        res = textMsg2.ToString();
                        //TextResponseMsgModel textMsg2 = new TextResponseMsgModel()
                        //{
                        //    ToUserName = msgModel.FromUserName,
                        //    FromUserName = msgModel.ToUserName,
                        //    CreateTime = WeiXinHelper.ConvertDateTimeInt(DateTime.Now).ToString(),
                        //    Content = "照片打印中,请稍侯..."
                        //};
                        //res = textMsg2.ToString();
                    }
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                ExceptionLogDAL.InsertExceptionLog(ex);
            }
            return(res);
        }
Esempio n. 5
0
        protected override bool BeforeLoad()
        {
            string strGuid = string.Empty;


            if (null != Request.QueryString["sitecode"] && null != Request.QueryString["openid"] && null != Request.QueryString["couponid"])
            {
                CouponID = Common.Common.NoHtml(Request.QueryString["couponid"].ToString());
                SiteCode = Common.Common.NoHtml(Request.QueryString["sitecode"].ToString());

                if (Request.QueryString["sitecode"].ToString().Length > 6)
                {
                    return(false);
                }

                if (Request.QueryString["couponid"].ToString().Length != 32)
                {
                    return(false);
                }

                if (Request.QueryString["openid"].ToString().Length > 29 || Request.QueryString["openid"].ToString().Length < 25)
                {
                    return(false);
                }
                else
                {
                    OpenID = Request.QueryString["openid"].ToString();
                }

                //插入优惠券
                SiteActivityDAL dalActive = new SiteActivityDAL();
                DataSet         dsActive  = dalActive.GetActivityDetail(CouponID);
                if (null != dsActive && dsActive.Tables.Count > 0 && dsActive.Tables[0].Rows.Count > 0)
                {
                    strGuid = Guid.NewGuid().ToString("N");
                    CouponDAL cdal = new CouponDAL();
                    if (!cdal.ExistCoupon(SiteCode, CouponID, OpenID))
                    {
                        //判断是否可以参加
                        //取当前已经参加的人数
                        int iCount = 10000000;
                        if (null != dsActive.Tables[0].Rows[0]["DayLimit"].ToString())
                        {
                            string strCount = "SiteCode = '" + SiteCode + "' AND SiteActivityID = '" + CouponID + "' AND CONVERT(VARCHAR(10),AddTime,120) = CONVERT(VARCHAR(10),GETDATE(),120)";
                            iCount = cdal.GetCouponCount(strCount);
                        }
                        string strStartTime = dsActive.Tables[0].Rows[0]["StartTime"].ToString();
                        string strEndTime   = dsActive.Tables[0].Rows[0]["EndTime"].ToString();
                        string strOpenTime  = dsActive.Tables[0].Rows[0]["OpenTime"].ToString();
                        string strCloseTime = dsActive.Tables[0].Rows[0]["CloseTime"].ToString();
                        string strDayLimit  = dsActive.Tables[0].Rows[0]["DayLimit"].ToString();

                        if (DateTime.Now >= Convert.ToDateTime(strStartTime) &&
                            DateTime.Now < Convert.ToDateTime(strEndTime) &&
                            DateTime.Now.Hour >= int.Parse(strOpenTime) &&
                            DateTime.Now.Hour < int.Parse(strCloseTime)
                            )
                        {
                            if (iCount < int.Parse(strDayLimit))
                            {
                                Coupon coupon = new Coupon()
                                {
                                    ID             = strGuid,
                                    SiteCode       = SiteCode,
                                    SiteActivityID = CouponID,
                                    OpenID         = OpenID,
                                    CouponStatus   = 0
                                };
                                cdal.InsertInfo(coupon);
                                strReHtml = "RushBuyOK.html";
                            }
                            else
                            {
                                strReHtml  = "RushBuyOver.html";
                                strMessage = "抱歉!优惠券已经被抢完,请关注下期活动!";
                            }
                        }
                        else
                        {
                            strReHtml  = "RushBuyOver.html";
                            strMessage = "抱歉!近期活动未开始或者已经结束,请关注公方微信优惠消息!";
                        }
                    }
                    else
                    {
                        strReHtml  = "RushBuyOver.html";
                        strMessage = "抱歉!您已经参与了活动,请把机会留给其余的顾客。";
                    }
                }
                CouponID = strGuid;
            }
            else
            {
                Response.Write("<script>window.opener=null;window.close();</script>");
                return(false);
            }
            return(base.BeforeLoad());
        }