Exemplo n.º 1
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string Login(HttpContext context)
        {
            Login  apiResult = new Login();
            string userName  = context.Request["userid"];
            string pwd       = context.Request["pwd"];
            string msg;

            string hasCheckCode    = context.Request["hascheckcode"];
            string checkCode       = context.Request["checkcode"];
            object serverCheckCode = context.Session["CheckCode"];

            if (!string.IsNullOrWhiteSpace(hasCheckCode) && hasCheckCode == "1" && serverCheckCode != null)
            {
                if (
                    string.IsNullOrWhiteSpace(checkCode)
                    ||
                    !checkCode.Equals(serverCheckCode.ToString(), StringComparison.OrdinalIgnoreCase)
                    )
                {
                    apiResult.message = "验证码错误";
                    apiResult.errcode = (int)BLLJIMP.Enums.APIErrCode.CheckCodeErr;
                    return(Common.JSONHelper.ObjectToJson(apiResult));
                }
            }

            UserInfo userInfo = new UserInfo();

            if (bllUser.Login(userName, pwd, out userInfo, out msg, this.webSiteOwner))
            {
                if (DateTime.Now.ToString("yyyy-MM-dd") != userInfo.LastLoginDate.ToString("yyyy-MM-dd"))
                {
                    bllUser.AddUserScoreDetail(userInfo.UserID, EnumStringHelper.ToString(ScoreDefineType.DayLogin), this.webSiteOwner, null, null);
                }
                bllUser.UpdateLoginInfo(userInfo);

                context.Session[SessionKey.LoginStatu] = 1;
                context.Session[SessionKey.UserID]     = userInfo.UserID;

                //绑定微信
                BindWXUser(context, userInfo.UserID);

                apiResult.issuccess = true;
                apiResult.userid    = userInfo.UserID;
                apiResult.headimg   = this.bllUser.GetUserDispalyAvatar(userInfo);
                apiResult.userName  = this.bllUser.GetUserDispalyName(userInfo);
                apiResult.avatar    = this.bllUser.GetUserDispalyAvatar(userInfo);
                apiResult.phone     = userInfo.Phone;
                apiResult.id        = userInfo.AutoID;
                apiResult.score     = userInfo.TotalScore;
                apiResult.im_token  = userInfo.IMToken;
            }
            else
            {
                apiResult.errcode = (int)BLLJIMP.Enums.APIErrCode.OperateFail;
                apiResult.message = msg;
            }
            return(Common.JSONHelper.ObjectToJson(apiResult));
        }
Exemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            //try
            //{
            BLLJIMP.BLLJuActivity   bllJuactivity   = new BLLJIMP.BLLJuActivity("");
            BLLJIMP.BLLUser         bllUser         = new BLLJIMP.BLLUser("");
            BLLJIMP.BLLMonitor      bllMonitor      = new BLLJIMP.BLLMonitor();
            BLLJIMP.BLLWebSite      bllwebSite      = new BLLJIMP.BLLWebSite();
            BLLJIMP.BLLShareMonitor bllShareMonitor = new BLLJIMP.BLLShareMonitor();

            ///推广用户信息
            UserInfo spreadUser = null;

            //分享用户
            UserInfo shareUser = null;

            CompanyWebsite_Config companyConfig = bllwebSite.GetCompanyWebsiteConfig();

            currentUrl = context.Request.Url.ToString(); //当前绝对地址
            string filePath = context.Request.FilePath;  //当前相对路径

            #region 微信推广(展示文章页面)
            if (filePath.Contains(".chtml"))
            {
                ToLog(context, " monitorhandler filePath:" + filePath);
                string[] parameters = filePath.Split('/');
                if (parameters.Length > 2)
                {
                    int activityId = Convert.ToInt32(parameters[1], 16);//ZCJ_JuActivityInfo 文章ID;
                    ToLog(context, " monitorhandler 文章ID:" + activityId);
                    long memberID = 0;

                    if (parameters.Length > 3)
                    {
                        //memberID = parameters[2] == "XXX" ? 0 : Convert.ToInt32(parameters[2], 16);//ZCJ_WXMemberInfo 会员注册ID;
                        spreadUser = bllUser.GetUserInfoByAutoID(Convert.ToInt32(parameters[2], 16));
                    }


                    string currOpenerOpenID = parameters.Length > 5 ? parameters[3] : string.Empty;//当前打开者的OpenID

                    string spreadUserID = context.Request["spreadU"] == null ? "" : context.Request["spreadU"].ToString();

                    string shareTimestamp = context.Request["shareTimestamp"];

                    if (!string.IsNullOrWhiteSpace(spreadUserID))
                    {
                        spreadUserID = Common.Base64Change.DecodeBase64ByUTF8(spreadUserID);
                    }

                    string spreadUserAutoIDStr = context.Request["ua"] == null ? "" : context.Request["ua"].ToString();//推广ID,原始id*1000,16进制后进行base64,然后“=”变成“_”
                    int    spreadUserAutoID    = 0;
                    if (!string.IsNullOrWhiteSpace(spreadUserAutoIDStr))
                    {
                        spreadUserAutoID = bllJuactivity.TransmitIntDeCode(spreadUserAutoIDStr);//Convert.ToInt32(Common.Base64Change.DecodeBase64ByUTF8(spreadUserAutoIDStr.Replace("_", "=")), 16) / 1000;
                    }

                    string shareId = context.Request["comeonshareid"] == null ? "" : context.Request["comeonshareid"].ToString();

                    if (!string.IsNullOrWhiteSpace(shareId))
                    {
                        ToLog(context, " monitorhandler 执行shareId查找分享任务: " + shareId);
                        try
                        {
                            var shareInfo = bllShareMonitor.GetShareInfo(shareId);

                            if (!string.IsNullOrWhiteSpace(shareInfo.UserId))
                            {
                                shareUser = bllUser.GetUserInfo(shareInfo.UserId);
                            }
                        }
                        catch (Exception ex)
                        {
                            ToLog(context, " monitorhandler 获取shareUser异常: " + ex.Message);
                        }
                    }



                    JuActivityInfo activityInfo = bllJuactivity.Get <JuActivityInfo>(string.Format("JuActivityID={0} AND IsDelete=0 ", activityId));//文章信息

                    if (activityInfo == null)
                    {
                        context.Response.WriteFile("/Error/NotExist.html");
                        return;
                    }

                    ToLog(context, " monitorhandler 找到文章,开始构造内容: " + activityInfo.JuActivityID);

                    //if (activityInfo.ArticleType == "activity")
                    //{
                    //    if (activityInfo.ActivityStatus == 1)
                    //    {
                    //        context.Response.Redirect("/Error/CommonMsg.aspx?msg=报名已结束,有疑问请联系我们&&icon=icon iconfont icon-kulian kulian");
                    //        return;
                    //    }
                    //}

                    #region 检查是否付费活动

                    if (activityInfo.IsFee == 1 && !bllJuactivity.IsLogin)
                    {
                        context.Response.Redirect("/App/Cation/Wap/FreeActivityPage.aspx?aid=" + activityInfo.JuActivityID);
                        return;
                    }
                    #endregion

                    #region 检查访问级别
                    if (activityInfo.AccessLevel > 0)
                    {
                        if (!bllUser.IsLogin)
                        {
                            appLoginUrl = Common.ConfigHelper.GetConfigString("appLoginUrl").ToLower();
                            context.Response.Redirect(appLoginUrl + string.Format("?redirect=" + HttpUtility.UrlEncode(currentUrl)), true);
                            return;
                        }
                        //else if (!bllUser.IsMember() && activityInfo.AccessLevel == 1)
                        //{

                        //}
                        else if (bllUser.GetCurrentUserInfo().AccessLevel < activityInfo.AccessLevel)
                        {
                            //if (companyConfig.NoPermissionsPage == 0)
                            //{
                            //    context.Response.WriteFile("/Error/NoPmsMobile.htm");
                            //    return;
                            //}
                            //else if (companyConfig.NoPermissionsPage == 1)
                            //{
                            //    context.Response.Redirect("/App/Cation/Wap/UserEdit.aspx",true);
                            //    context.Response.End();
                            //    return;
                            //}
                            context.Response.WriteFile("/Error/NoPmsMobile.htm");
                            return;
                        }
                    }
                    #endregion

                    #region 检查访问级别

                    //WXMemberInfo regInfo = juactivityBll.Get<WXMemberInfo>(string.Format("MemberID={0}", memberID));//会员注册信息
                    // UserInfo userInfo = juactivityBll.Get<UserInfo>(string.Format("UserID='{0}'", activityInfo.UserID));//文章发布者信息
                    SystemSet systemset  = bllJuactivity.Get <SystemSet>(""); //系统配置信息
                    string    pageSource = "";                                //待输出的html源代码

                    if (systemset != null)
                    {
                        if (string.IsNullOrWhiteSpace(currOpenerOpenID))
                        {
                            //取得Session里的当前OpenID
                            currOpenerOpenID = context.Session[systemset.WXCurrOpenerOpenIDKey] != null ? context.Session[systemset.WXCurrOpenerOpenIDKey].ToString() : "";
                        }

                        if (string.IsNullOrWhiteSpace(currOpenerOpenID))
                        {
                            //如果再为空,由链接上面get参数获取
                            currOpenerOpenID = context.Request[systemset.WXCurrOpenerOpenIDKey] != null ? context.Request[systemset.WXCurrOpenerOpenIDKey].ToString() : "";
                        }
                    }
                    #endregion



                    //if (regInfo == null)
                    //{
                    //    regInfo = new WXMemberInfo() { Name = "none", WeixinOpenID = "" };
                    //}

                    if ((activityInfo != null))//
                    {
                        //var planInfo = bllJuactivity.Get<MonitorPlan>(string.Format("MonitorPlanID={0}", activityInfo.MonitorPlanID));
                        //if (planInfo == null)
                        //{
                        //    return;
                        //}
                        //else
                        //{
                        //    if (planInfo.PlanStatus == "0")//任务已停止
                        //    {
                        //        return;
                        //    }

                        //}

                        ToLog(context, " monitorhandler 开始执行GetJuactivityHtml: " + activityInfo.JuActivityID);
                        pageSource = bllJuactivity.GetJuactivityHtml(activityInfo, currOpenerOpenID, context.Request.Url.ToString(), spreadUser, shareUser);
                        ToLog(context, " monitorhandler 执行GetJuactivityHtml完毕: " + activityInfo.JuActivityID);

                        #region 事件记录
                        //事件
                        //int OpenCount = 0;//打开人数
                        //int DistinctOpenCount = 0;//独立IP数量
                        MonitorEventDetailsInfo detailInfo = new MonitorEventDetailsInfo();
                        detailInfo.MonitorPlanID  = activityInfo.MonitorPlanID;
                        detailInfo.EventType      = 0;
                        detailInfo.EventBrowser   = HttpContext.Current.Request.Browser == null ? "" : HttpContext.Current.Request.Browser.ToString();
                        detailInfo.EventBrowserID = HttpContext.Current.Request.Browser.Id;;
                        if (HttpContext.Current.Request.Browser.Beta)
                        {
                            detailInfo.EventBrowserIsBata = "测试版";
                        }
                        else
                        {
                            detailInfo.EventBrowserIsBata = "正式版";
                        }

                        detailInfo.EventBrowserVersion = HttpContext.Current.Request.Browser.Version;
                        detailInfo.EventDate           = DateTime.Now;
                        if (HttpContext.Current.Request.Browser.Win16)
                        {
                            detailInfo.EventSysByte = "16位系统";
                        }
                        else
                        if (HttpContext.Current.Request.Browser.Win32)
                        {
                            detailInfo.EventSysByte = "32位系统";
                        }
                        else
                        {
                            detailInfo.EventSysByte = "64位系统";
                        }

                        detailInfo.EventSysPlatform = HttpContext.Current.Request.Browser.Platform;
                        detailInfo.SourceIP         = Common.MySpider.GetClientIP();
                        detailInfo.IPLocation       = Common.MySpider.GetIPLocation(detailInfo.SourceIP);
                        detailInfo.SourceUrl        = HttpContext.Current.Request.Url.ToString();
                        detailInfo.RequesSourcetUrl = HttpContext.Current.Request.UrlReferrer != null?HttpContext.Current.Request.UrlReferrer.ToString() : "";

                        if (spreadUser != null)
                        {
                            detailInfo.SpreadUserID = spreadUser.UserID;
                        }
                        detailInfo.SpreadUserAutoID = spreadUserAutoID;
                        detailInfo.ShareTimestamp   = shareTimestamp;
                        detailInfo.WebsiteOwner     = bllJuactivity.WebsiteOwner;
                        detailInfo.ModuleType       = activityInfo.ArticleType;
                        if (bllUser.IsLogin)
                        {
                            detailInfo.EventUserID = bllUser.GetCurrUserID();
                        }


                        if (spreadUser != null)//带推广信息
                        {
                            //try
                            //{
                            //    if (!string.IsNullOrWhiteSpace(currOpenerOpenID))
                            //    {
                            //        //记录触发人
                            //        UserInfo eventUser = new BLLJIMP.BLLUser("").GetUserInfoByOpenId(currOpenerOpenID);
                            //        detailInfo.EventUserID = eventUser.UserID;
                            //    }
                            //}
                            //catch { }
                            string          url = string.Format("http://{0}{1}", context.Request.Url.Host, filePath);
                            MonitorLinkInfo linkInfo;
                            try
                            {
                                linkInfo = bllJuactivity.Get <MonitorLinkInfo>(string.Format(" LinkName='{0}' And MonitorPlanID={1}", spreadUser.UserID, activityInfo.MonitorPlanID));
                            }
                            catch (Exception ex)
                            {
                                context.Response.Write("ex" + ex.ToString());
                                return;
                            }



                            if (linkInfo != null)
                            {
                                linkInfo.ActivityName   = activityInfo.ActivityName;
                                linkInfo.ThumbnailsPath = activityInfo.ThumbnailsPath;
                                //已经为该用户建立推广链接
                                detailInfo.LinkID = linkInfo.LinkID;
                                //if (linkInfo.OpenCount != null)//增加打开人数
                                //{
                                linkInfo.OpenCount++;
                                //}
                                //else
                                //{
                                //    linkInfo.OpenCount = 1;
                                //}
                                int shareCount = bllJuactivity.GetCount <MonitorEventDetailsInfo>("ShareTimestamp", string.Format(" LinkID ={0} and ShareTimestamp is not null and ShareTimestamp <> '' and ShareTimestamp <> '0' ", linkInfo.LinkID));
                                linkInfo.ShareCount = shareCount;
                                int ipCount = bllJuactivity.GetCount <MonitorEventDetailsInfo>(" SourceIP ", string.Format(" LinkID = {0} ", linkInfo.LinkID));
                                linkInfo.DistinctOpenCount = ipCount;
                                bllJuactivity.Update(linkInfo, string.Format(" OpenCount={0},DistinctOpenCount={1},ShareCount={2}", linkInfo.OpenCount, ipCount, shareCount), string.Format("LinkID={0}", linkInfo.LinkID));
                            }
                            else
                            {
                                //还没有为该用户建立推广链接
                                MonitorLinkInfo newLinkinfo = new MonitorLinkInfo();
                                newLinkinfo.LinkID            = int.Parse(bllJuactivity.GetGUID(ZentCloud.BLLJIMP.TransacType.MonitorLinkID));
                                newLinkinfo.MonitorPlanID     = activityInfo.MonitorPlanID;
                                newLinkinfo.WXMemberID        = memberID;
                                newLinkinfo.LinkName          = spreadUser.UserID;
                                newLinkinfo.RealLink          = url;
                                newLinkinfo.InsertDate        = DateTime.Now;
                                newLinkinfo.OpenCount         = 1;
                                newLinkinfo.ActivityName      = activityInfo.ActivityName;
                                newLinkinfo.ThumbnailsPath    = activityInfo.ThumbnailsPath;
                                newLinkinfo.WebsiteOwner      = bllJuactivity.WebsiteOwner;
                                newLinkinfo.DistinctOpenCount = 1; // ip
                                newLinkinfo.ShareCount        = 0; //分享数
                                if (activityInfo.ArticleType == "article")
                                {
                                    newLinkinfo.ForwardType = "fans";
                                    newLinkinfo.ActivityId  = activityInfo.JuActivityID;
                                }
                                if (!string.IsNullOrEmpty(activityInfo.SignUpActivityID) && activityInfo.ArticleType == "activity")
                                {
                                    newLinkinfo.ActivityId = int.Parse(activityInfo.SignUpActivityID);
                                }

                                StringBuilder sqlWhere = new StringBuilder();
                                sqlWhere.AppendFormat(@"
                                if not exists(select 1 from ZCJ_MonitorLinkInfo where LinkName='{14}' and MonitorPlanID={15} ) 
                                begin
                                    insert into ZCJ_MonitorLinkInfo (LinkID,MonitorPlanID,WXMemberID,LinkName,RealLink,InsertDate,OpenCount,ActivityName,ThumbnailsPath,WebsiteOwner,DistinctOpenCount,ShareCount,ForwardType,ActivityId)
                                                values({0},{1},{2},'{3}','{4}','{5}',{6},'{7}','{8}','{9}',{10},{11},'{12}',{13})
                                end 
                                ", newLinkinfo.LinkID, newLinkinfo.MonitorPlanID, newLinkinfo.WXMemberID, newLinkinfo.LinkName, newLinkinfo.RealLink, newLinkinfo.InsertDate, newLinkinfo.OpenCount, newLinkinfo.ActivityName, newLinkinfo.ThumbnailsPath, newLinkinfo.WebsiteOwner, newLinkinfo.DistinctOpenCount, newLinkinfo.ShareCount, newLinkinfo.ForwardType, newLinkinfo.ActivityId, spreadUser.UserID, activityInfo.MonitorPlanID);


                                if (ZentCloud.ZCDALEngine.DALEngine.ExecuteSql(sqlWhere.ToString()) > 0)
                                {
                                    detailInfo.LinkID = newLinkinfo.LinkID;
                                }
                            }
                        }


                        //添加事件详细
                        //if (!filePath.Contains("?"))
                        //{
                        bllJuactivity.Add(detailInfo);
                        //DistinctOpenCount = juactivityBll.GetCount<ZentCloud.BLLJIMP.Model.MonitorEventDetailsInfo>("SourceIP", string.Format("LinkID={0} and EventType=0", detailInfo.LinkID));
                        //juactivityBll.Update(new MonitorLinkInfo(), string.Format(" OpenCount={0},DistinctOpenCount={1}", OpenCount, DistinctOpenCount), string.Format("LinkID={0}", detailInfo.LinkID));
                        #region 微转发活动加积分
                        if (bllUser.IsLogin && spreadUser != null)
                        {
                            if (activityInfo.ArticleType == "activity")
                            {
                                if (bllJuactivity.GetCount <MonitorEventDetailsInfo>(string.Format(" MonitorPlanID='{0}' And EventUserID='{1}' And SpreadUserID='{2}' And EventUserID!='{2}'", detailInfo.MonitorPlanID, bllUser.GetCurrUserID(), spreadUser.UserID)) == 1)
                                {
                                    string remark = string.Format("转发活动《{0}》", activityInfo.ActivityName);
                                    //微转发加积分
                                    bllUser.AddUserScoreDetail(spreadUser.UserID, CommonPlatform.Helper.EnumStringHelper.ToString(ZentCloud.BLLJIMP.Enums.ScoreDefineType.ForwardArticle), spreadUser.WebsiteOwner, null, remark);
                                }
                            }
                        }
                        #endregion


                        //}
                        context.Response.ClearContent();
                        //处理完成
                        context.Response.Write(pageSource);
                        //更新微信阅读人数
                        //bllJuactivity.UpdateUVCount(activityInfo.JuActivityID);
                        bllJuactivity.UpDateIPPVShareCount(activityInfo);
                        bllJuactivity.UpdateActivityForwardPVUV(activityInfo);
                        if (spreadUser != null)
                        {
                            bllMonitor.UpdateUV(activityInfo.MonitorPlanID, spreadUser.UserID);
                            //bllMonitor.UpdateSignUpCount(activityInfo.MonitorPlanID, spreadUser.UserID);
                        }
                        if (!string.IsNullOrWhiteSpace(activityInfo.RedirectUrl))
                        {
                            context.Response.Redirect(activityInfo.RedirectUrl);
                        }
                        return;

                        #endregion

                        ToLog(context, " monitorhandler 事件记录完毕: " + activityInfo.JuActivityID);
                    }
                    else
                    {
                        context.Response.Write("<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1\" /></head><body>链接无效。</body></html>");
                        return;
                    }
                }
            }
            #endregion
            #region 注释
            //#region 微信会员注册
            //else if (filePath.StartsWith("/weixin"))
            //{

            //    //微信会员注册
            //    if (filePath.Contains("wx_reg.chtml") && (!filePath.Contains("/weixin/wx_reg.chtml")))
            //    {
            //        string[] parameters = filePath.Split('/');

            //        string weixinMemberId = Convert.ToInt32(parameters[2], 16).ToString();// ZCJ_WeixinMemberInfo WeixinMemberID
            //        var weixinmemberinfo = juactivityBll.Get<WeixinMemberInfo>(string.Format("WeixinMemberID={0}", weixinMemberId));
            //        string RegCode = Common.IOHelper.GetFileStr(context.Server.MapPath("/weixin/wx_reg.htm"), Encoding.UTF8);//注册代码

            //        if (RegCode.Contains("$CCWXOPENID$"))
            //        {
            //            RegCode = RegCode.Replace("$CCWXOPENID$", weixinmemberinfo.WeixinOpenID);
            //        }
            //        if (RegCode.Contains("$CCWXAID$"))//注册到哪个账户下
            //        {

            //            RegCode = RegCode.Replace("$CCWXAID$", Convert.ToString(juactivityBll.Get<UserInfo>(string.Format("UserID='{0}'", weixinmemberinfo.UserID)).AutoID, 16));

            //        }

            //        context.Response.Write(RegCode);//输出注册代码


            //        //微信会员注册

            //    }

            //}

            //#endregion
            #endregion

            //}
            //catch (Exception ex)
            //{
            //    using (StreamWriter sw = new StreamWriter(@"C:\MonitorHandlerException.txt", true, Encoding.UTF8))
            //    {
            //        sw.WriteLine(string.Format("{0} MonitorHandler拦截处理异常:{1}", DateTime.Now.ToString(), ex.ToString()));

            //    }
            //    context.Response.Write("exception");
            //}
        }
Exemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //Tolog("进入支付回调");
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(Request.InputStream);
                xmlDoc.Save(string.Format("C:\\WXPay\\Notify{0}.xml", DateTime.Now.ToString("yyyyMMddHHmmssfff")));//写入日志
                //全部参数
                Dictionary <string, string> parametersAll = new Dictionary <string, string>();
                foreach (XmlElement item in xmlDoc.DocumentElement.ChildNodes)
                {
                    string key   = item.Name;
                    string value = item.InnerText;
                    if ((!string.IsNullOrEmpty(key)) && (!string.IsNullOrEmpty(value)))
                    {
                        parametersAll.Add(key, value);
                    }
                }
                parametersAll = (from entry in parametersAll
                                 orderby entry.Key ascending
                                 select entry).ToDictionary(pair => pair.Key, pair => pair.Value);//全部参数排序
                orderInfo = bllMall.GetOrderInfo(parametersAll["out_trade_no"]);
                PayConfig payConfig = bllPay.GetPayConfig();
                if (!bllPay.VerifySignatureWx(parametersAll, payConfig.WXPartnerKey))//验证签名
                {
                    Tolog("验证签名出错");
                    Response.Write(failXml);
                    return;
                }
                if (orderInfo == null)
                {
                    Tolog("订单未找到");
                    Response.Write(failXml);
                    return;
                }
                if (orderInfo.PaymentStatus.Equals(1))
                {
                    //Tolog("已支付");
                    Response.Write(successXml);
                    return;
                }
                orderInfo.PaymentType = 2;

                //更新订单状态
                WXMallProductInfo tProductInfo = new WXMallProductInfo();
                if (parametersAll["return_code"].Equals("SUCCESS") && parametersAll["result_code"].Equals("SUCCESS")) //交易成功
                {
                    UserInfo orderUserInfo = bllUser.GetUserInfo(orderInfo.OrderUserID, bllUser.WebsiteOwner);        //下单用户信息
                    string   hasOrderIDs   = "";
                    int      maxCount      = 1;
                    //Tolog("准备检查更新订单状态");
                    if (BLLJIMP.BLLMall.bookingList.Contains(orderInfo.ArticleCategoryType))
                    {
                        //Tolog("预订类型");
                        #region 预约订单修改状态
                        orderInfo.PaymentStatus = 1;
                        orderInfo.PayTime       = DateTime.Now;
                        orderInfo.Status        = "预约成功";

                        #region 检查是否有预约成功的订单
                        List <WXMallOrderDetailsInfo> tDetailList = bllMall.GetOrderDetailsList(orderInfo.OrderID, null, orderInfo.ArticleCategoryType, null, null);
                        List <WXMallOrderDetailsInfo> oDetailList = bllMall.GetOrderDetailsList(null, tDetailList[0].PID, orderInfo.ArticleCategoryType, tDetailList.Min(p => p.StartDate), tDetailList.Max(p => p.EndDate));
                        tProductInfo = bllMall.GetByKey <WXMallProductInfo>("PID", tDetailList[0].PID);
                        maxCount     = tProductInfo.Stock;
                        List <string> hasOrderIDList = new List <string>();
                        foreach (var item in tDetailList)
                        {
                            List <WXMallOrderDetailsInfo> hasOrderDetailList = oDetailList.Where(p => !((item.StartDate >= p.EndDate && item.EndDate > p.EndDate) || (item.StartDate < p.StartDate && item.EndDate <= p.StartDate))).ToList();
                            if (hasOrderDetailList.Count >= maxCount)
                            {
                                hasOrderIDList.AddRange(hasOrderDetailList.Select(p => p.OrderID).Distinct());
                            }
                        }
                        hasOrderIDList = hasOrderIDList.Where(p => !p.Contains(orderInfo.OrderID)).ToList();
                        if (hasOrderIDList.Count > 0)
                        {
                            hasOrderIDList = hasOrderIDList.Distinct().ToList();
                            hasOrderIDs    = MyStringHelper.ListToStr(hasOrderIDList, "'", ",");
                        }
                        #endregion 检查是否有预约成功的订单

                        #endregion 预约订单修改状态
                    }
                    else
                    {
                        //Tolog("普通类型");
                        #region 原订单修改状态
                        orderInfo.PaymentStatus = 1;
                        orderInfo.Status        = "待发货";
                        orderInfo.PayTime       = DateTime.Now;
                        if (orderInfo.DeliveryType == 1)
                        {
                            orderInfo.Status = "待自提";
                        }
                        Tolog("更改状态start");
                        //if (bllMall.GetWebsiteInfoModelFromDataBase().IsDistributionMall.Equals(1))
                        //{
                        orderInfo.GroupBuyStatus     = "0";
                        orderInfo.DistributionStatus = 1;

                        //if (orderInfo.IsMain==1)
                        //{
                        //    bllMall.Update(orderInfo,string.Format(" DistributionStatus=1"),string.Format("ParentOrderId='{0}'",orderInfo.OrderID));
                        //}



                        #region 活动订单
                        if (orderInfo.OrderType == 4)
                        {
                            ActivityDataInfo data = bllMall.Get <ActivityDataInfo>(string.Format(" OrderId='{0}'", orderInfo.OrderID));
                            if (data != null)
                            {
                                bllMall.Update(data, string.Format(" PaymentStatus=1"), string.Format("  OrderId='{0}'", orderInfo.OrderID));
                            }
                        }
                        #endregion


                        bllMall.Update(orderInfo, string.Format("PaymentStatus=1,Status='待发货',PayTime=GETDATE(),DistributionStatus=1"), string.Format("ParentOrderId='{0}'", orderInfo.OrderID));


                        //}
                        #endregion 原订单修改状态

                        try
                        {
                            //设置交易流水号
                            orderInfo.PayTranNo = parametersAll["transaction_id"];
                        }
                        catch (Exception ex)
                        {
                            Tolog("设置交易流水号失败:" + ex.Message);
                        }
                    }
                    bool result = false;

                    if (BLLJIMP.BLLMall.bookingList.Contains(orderInfo.ArticleCategoryType))
                    {
                        if (string.IsNullOrWhiteSpace(hasOrderIDs))
                        {
                            hasOrderIDs = "'0'";
                        }
                        result = bllMall.Update(new WXMallOrderInfo(),
                                                string.Format("PaymentStatus={0},PayTime=GetDate(),Status='{1}'", 1, "预约成功"),
                                                string.Format("OrderID='{0}' and WebsiteOwner='{4}' AND (select count(1) from [ZCJ_WXMallOrderInfo] where Status='{3}' and WebsiteOwner='{4}' and  OrderID IN({1}))<{2}",
                                                              orderInfo.OrderID, hasOrderIDs, maxCount, "预约成功", bllMall.WebsiteOwner)
                                                ) > 0;
                        if (result)
                        {
                            // #region 交易成功加积分
                            //增加积分 (慧聚不需要)
                            //if (orderInfo.TotalAmount > 0)
                            //{
                            //    ScoreConfig scoreConfig = bllScore.GetScoreConfig();
                            //    int addScore = 0;
                            //    if (scoreConfig != null && scoreConfig.OrderAmount > 0 && scoreConfig.OrderScore > 0)
                            //    {
                            //        addScore = (int)(orderInfo.PayableAmount / (scoreConfig.OrderAmount / scoreConfig.OrderScore));
                            //    }
                            //    if (addScore > 0)
                            //    {
                            //        if (bllUser.Update(new UserInfo(),
                            //            string.Format(" TotalScore+={0},HistoryTotalScore+={0}", addScore),
                            //            string.Format(" UserID='{0}'", orderInfo.OrderUserID)) > 0)
                            //        {
                            //            UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo();
                            //            scoreRecord.AddTime = DateTime.Now;
                            //            scoreRecord.Score = addScore;
                            //            scoreRecord.ScoreType = "OrderSuccess";
                            //            scoreRecord.UserID = orderInfo.OrderUserID;
                            //            scoreRecord.AddNote = "预约-交易成功获得积分";
                            //            bllMall.Add(scoreRecord);
                            //        }
                            //    }
                            //}
                            // #endregion

                            #region 修改其他预约订单为预约失败 返还积分

                            if (BLLJIMP.BLLMall.bookingList.Contains(orderInfo.ArticleCategoryType) && !string.IsNullOrWhiteSpace(hasOrderIDs))
                            {
                                int tempCount = 0;
                                List <WXMallOrderInfo> tempList = bllMall.GetOrderList(0, 1, "", out tempCount, "预约成功", null, null, null,
                                                                                       null, null, null, null, null, null, null, orderInfo.ArticleCategoryType, hasOrderIDs);
                                tempCount = tempCount + 1; //加上当前订单的数量
                                if (tempCount >= maxCount)
                                {
                                    tempList = bllMall.GetColOrderListInStatus("'待付款','待审核'", hasOrderIDs, "OrderID,OrderUserID,UseScore", bllMall.WebsiteOwner);
                                    if (tempList.Count > 0)
                                    {
                                        string stopOrderIds = MyStringHelper.ListToStr(tempList.Select(p => p.OrderID).ToList(), "'", ",");
                                        tempList = tempList.Where(p => p.UseScore > 0).ToList();
                                        foreach (var item in tempList)
                                        {
                                            orderUserInfo.TotalScore += item.UseScore;
                                            if (bllUser.Update(new UserInfo(), string.Format(" TotalScore+={0}", item.UseScore),
                                                               string.Format(" UserID='{0}'", item.OrderUserID)) > 0)
                                            {
                                                UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo();
                                                scoreRecord.AddTime      = DateTime.Now;
                                                scoreRecord.Score        = item.UseScore;
                                                scoreRecord.TotalScore   = orderUserInfo.TotalScore;
                                                scoreRecord.ScoreType    = "OrderCancel";
                                                scoreRecord.UserID       = item.OrderUserID;
                                                scoreRecord.RelationID   = item.OrderID;
                                                scoreRecord.AddNote      = "预约-订单失败返还积分";
                                                scoreRecord.WebSiteOwner = item.WebsiteOwner;
                                                bllMall.Add(scoreRecord);
                                            }
                                        }
                                        bllMall.Update(new WXMallOrderInfo(),
                                                       string.Format("Status='{0}'", "预约失败"),
                                                       string.Format("OrderID In ({0}) and WebsiteOwner='{1}'", stopOrderIds, bllMall.WebsiteOwner));
                                    }
                                }
                                //Tolog("更改修改其他预约为预约失败");
                            }
                            #endregion
                        }
                    }
                    else
                    {
                        result = bllMall.Update(orderInfo);
                    }
                    if (result)
                    {
                        #region 拼团订单
                        if (orderInfo.OrderType == 2)
                        {
                            try
                            {
                                if (!string.IsNullOrEmpty(orderInfo.GroupBuyParentOrderId))
                                {
                                    var parentOrderInfo = bllMall.GetOrderInfo(orderInfo.GroupBuyParentOrderId);

                                    if (parentOrderInfo.Ex10 == "1")
                                    {
                                        if (bllMall.GetCount <WXMallOrderInfo>(string.Format("PaymentStatus=1 And GroupBuyParentOrderId='{0}' ", parentOrderInfo.OrderID)) >= parentOrderInfo.PeopleCount)
                                        {
                                            bllMall.Update(new WXMallOrderInfo(), string.Format("Status='已取消'"), string.Format("  GroupBuyParentOrderId='{0}' And PaymentStatus=0", parentOrderInfo.OrderID));
                                            parentOrderInfo.GroupBuyStatus = "1";
                                            bllMall.Update(parentOrderInfo);
                                        }
                                    }
                                    else
                                    {
                                        if (bllMall.GetCount <WXMallOrderInfo>(string.Format("PaymentStatus=1 And GroupBuyParentOrderId='{0}' Or OrderId='{0}'", parentOrderInfo.OrderID)) >= parentOrderInfo.PeopleCount)
                                        {
                                            bllMall.Update(new WXMallOrderInfo(), string.Format("Status='已取消'"), string.Format("  GroupBuyParentOrderId='{0}' And PaymentStatus=0", parentOrderInfo.OrderID));
                                            parentOrderInfo.GroupBuyStatus = "1";
                                            bllMall.Update(parentOrderInfo);
                                        }
                                    }
                                }
                            }
                            catch (Exception)
                            {
                            }
                        }
                        #endregion
                        Open.HongWareSDK.Client hongWareClient = new Open.HongWareSDK.Client(orderInfo.WebsiteOwner);

                        //Tolog("更改状态true");

                        #region Efast同步
                        //判读当前站点是否需要同步到驿氪和efast
                        if (bllCommRelation.ExistRelation(BLLJIMP.Enums.CommRelationType.SyncEfast, bllCommRelation.WebsiteOwner, ""))
                        {
                            try
                            {
                                Tolog("开始同步efast");

                                string outOrderId = string.Empty, msg = string.Empty;
                                var    syncResult = bllEfast.CreateOrder(orderInfo.OrderID, out outOrderId, out msg);
                                if (syncResult)
                                {
                                    orderInfo.OutOrderId = outOrderId;
                                    bllMall.Update(orderInfo);
                                }
                                Tolog(string.Format("efast订单同步结果:{0},订单号:{1},提示信息:{2}", syncResult, outOrderId, msg));
                            }
                            catch (Exception ex)
                            {
                                Tolog("efast订单同步异常:" + ex.Message);
                            }
                        }
                        #endregion

                        #region 驿氪同步
                        if (bllCommRelation.ExistRelation(BLLJIMP.Enums.CommRelationType.SyncYike, bllCommRelation.WebsiteOwner, ""))
                        {
                            try
                            {
                                Tolog("开始同步驿氪");
                                //同步成功订单到驿氪

                                //UserInfo orderUserInfo = bllUser.GetUserInfo(orderInfo.OrderUserID);
                                //if ((!string.IsNullOrEmpty(orderUserInfo.Ex1)) && (!string.IsNullOrEmpty(orderUserInfo.Ex2)) && (!string.IsNullOrEmpty(orderUserInfo.Phone)))
                                //{
                                //    client.BonusUpdate(orderUserInfo.Ex2, -(orderInfo.UseScore), "商城下单使用积分" + orderInfo.UseScore);

                                //}
                                var uploadOrderResult = yikeClient.OrderUpload(orderInfo);

                                Tolog(string.Format("驿氪订单同步结果:{0}", Common.JSONHelper.ObjectToJson(uploadOrderResult)));
                            }
                            catch (Exception ex)
                            {
                                Tolog("驿氪订单同步异常:" + ex.Message);
                            }
                        }
                        #endregion

                        #region 付款加积分
                        try
                        {
                            bllUser.AddUserScoreDetail(orderInfo.OrderUserID, CommonPlatform.Helper.EnumStringHelper.ToString(ZentCloud.BLLJIMP.Enums.ScoreDefineType.OrderPay), bllMall.WebsiteOwner, null, null);
                        }
                        catch (Exception)
                        { }

                        #endregion


                        #region 消息通知
                        if (!BLLJIMP.BLLMall.bookingList.Contains(orderInfo.ArticleCategoryType))
                        {
                            try
                            {
                                var    productName = bllMall.GetOrderDetailsList(orderInfo.OrderID)[0].ProductName;
                                string remark      = "";
                                if (!string.IsNullOrEmpty(orderInfo.OrderMemo))
                                {
                                    remark = string.Format("客户留言:{0}", orderInfo.OrderMemo);
                                }
                                bllWeiXin.SendTemplateMessageToKefu("有新的订单", string.Format("订单号:{0}\\n订单金额:{1}元\\n收货人:{2}\\n电话:{3}\\n商品:{4}\\n{5}", orderInfo.OrderID, Math.Round(orderInfo.TotalAmount, 2), orderInfo.Consignee, orderInfo.Phone, productName, remark));
                                if (orderInfo.OrderType != 4)//付费的活动不发消息
                                {
                                    if (orderInfo.WebsiteOwner != "jikuwifi")
                                    {
                                        string url = string.Format("http://{0}/customize/shop/?v=1.0&ngroute=/orderDetail/{1}#/orderDetail/{1}", Request.Url.Host, orderInfo.OrderID);
                                        if (orderInfo.IsMain == 1)
                                        {
                                            url = string.Format("http://{0}/customize/shop/?v=1.0&ngroute=/orderList#/orderList", Request.Url.Host);
                                        }
                                        bllWeiXin.SendTemplateMessageNotifyComm(orderUserInfo, "订单已成功支付,我们将尽快发货,请保持手机畅通等待物流送达!", string.Format("订单号:{0}\\n订单金额:{1}元\\n收货人:{2}\\n电话:{3}\\n商品:{4}...\\n查看详情", orderInfo.OrderID, Math.Round(orderInfo.TotalAmount, 2), orderInfo.Consignee, orderInfo.Phone, productName), url);
                                    }
                                }
                            }
                            catch (Exception)
                            {
                            }
                        }
                        else
                        {
                            try
                            {
                                bllWeiXin.SendTemplateMessageToKefu(orderInfo.Status, string.Format("预约:{2}\\n订单号:{0}\\n订单金额:{1}元\\n预约人:{3}\\n预约人手机:{4}", orderInfo.OrderID, orderInfo.TotalAmount, tProductInfo.PName, orderUserInfo.TrueName, orderUserInfo.Phone));
                                bllWeiXin.SendTemplateMessageNotifyComm(orderUserInfo, orderInfo.Status, string.Format("预约:{2}\\n订单号:{0}\\n订单金额:{1}元", orderInfo.OrderID, orderInfo.TotalAmount, tProductInfo.PName));
                            }
                            catch (Exception)
                            {
                            }
                        }
                        #endregion
                        WebsiteInfo websiteInfo = bllMall.Get <WebsiteInfo>(string.Format(" WebsiteOwner='{0}'", orderInfo.WebsiteOwner));
                        #region 分销相关
                        try
                        {
                            if (bllMenuPermission.CheckUserAndPmsKey(websiteInfo.WebsiteOwner, BLLPermission.Enums.PermissionSysKey.OnlineDistribution, websiteInfo.WebsiteOwner))
                            {
                                if (string.IsNullOrWhiteSpace(orderUserInfo.DistributionOwner))
                                {
                                    if (websiteInfo.DistributionRelationBuildMallOrder == 1)
                                    {
                                        orderUserInfo.DistributionOwner = orderInfo.WebsiteOwner;
                                        bllMall.Update(orderUserInfo);
                                    }
                                }
                                bllDis.AutoUpdateLevel(orderInfo);
                                bllDis.TransfersEstimate(orderInfo);
                                bllDis.SendMessageToUser(orderInfo);
                                bllDis.UpdateDistributionSaleAmountUp(orderInfo);
                            }
                        }
                        catch (Exception ex)
                        {
                            Tolog("设置分销员异常:" + ex.Message + " 用户id:" + orderUserInfo.UserID);
                        }
                        #endregion


                        #region 宏巍通知
                        try
                        {
                            if (websiteInfo.IsUnionHongware == 1)
                            {
                                hongWareClient.OrderNotice(orderUserInfo.WXOpenId, orderInfo.OrderID);
                            }
                        }
                        catch (Exception)
                        {
                        }

                        #endregion

                        bllCard.Give(orderInfo.TotalAmount, orderUserInfo);


                        string v1ProductId = Common.ConfigHelper.GetConfigString("YGBV1ProductId");
                        string v2ProductId = Common.ConfigHelper.GetConfigString("YGBV2ProductId");
                        string v1CouponId  = Common.ConfigHelper.GetConfigString("YGBV1CouponId");
                        string v2CouponId  = Common.ConfigHelper.GetConfigString("YGBV2CouponId");

                        List <WXMallOrderDetailsInfo> orderDetailList = bllMall.GetOrderDetailsList(orderInfo.OrderID);
                        foreach (var item in orderDetailList)
                        {
                            item.IsComplete = 1;
                            bllMall.Update(item);

                            #region 购买指定商品发送指定的优惠券
                            if (!string.IsNullOrEmpty(v1ProductId) && !string.IsNullOrEmpty(v1CouponId) && item.PID == v1ProductId)
                            {
                                bllCard.SendCardCouponsByCurrUserInfo(orderUserInfo, v1CouponId);
                            }

                            if (!string.IsNullOrEmpty(v2ProductId) && !string.IsNullOrEmpty(v2CouponId) && item.PID == v2ProductId)
                            {
                                bllCard.SendCardCouponsByCurrUserInfo(orderUserInfo, v2CouponId);
                            }
                            #endregion
                        }

                        //更新销量
                        bllMall.UpdateProductSaleCount(orderInfo);
                        Response.Write(successXml);
                        return;
                    }
                    else
                    {
                        Tolog("更改状态false");
                        Response.Write(failXml);
                        return;
                    }
                }
                Tolog("返回信息有误");
                Response.Write(failXml);
            }
            catch (Exception ex)
            {
                Tolog("出错了:" + ex.Message);
                Response.Write(failXml);
            }
        }
Exemplo n.º 4
0
        public void ProcessRequest(HttpContext context)
        {
            string articleId      = context.Request["activity_id"];
            string content        = context.Request["content"];
            var    replyId        = Convert.ToInt32(context.Request["reply_id"]);//评论了文章里的哪个评论
            int    isHideUserName = Convert.ToInt32(context.Request["is_hide_user_name"]);

            resp.isSuccess = false;
            if (string.IsNullOrWhiteSpace(articleId) || string.IsNullOrWhiteSpace(content))
            {
                resp.errcode = (int)BLLJIMP.Enums.APIErrCode.PrimaryKeyIncomplete;
                resp.errmsg  = "activity_id、content 为必填项,请检查";
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                return;
            }
            if (bllJuActivity.GetCount <JuActivityInfo>(string.Format(" WebsiteOwner='{0}' AND  JuActivityID = {1} ", bllJuActivity.WebsiteOwner, articleId)) == 0)
            {
                resp.errcode = (int)BLLJIMP.Enums.APIErrCode.IsNotFound;
                resp.errmsg  = "不存在活动";
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                return;
            }
            //敏感词检查
            string errmsg = "";

            if (!bllFilterWord.CheckFilterWord(content, this.bllJuActivity.WebsiteOwner, out errmsg, "0"))
            {
                resp.errmsg  = errmsg;
                resp.errcode = (int)BLLJIMP.Enums.APIErrCode.OperateFail;
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                return;
            }
            //添加评论
            int            reviewId = 0;
            JuActivityInfo article  = bllJuActivity.GetJuActivity(int.Parse(articleId), true);

            BLLJIMP.Enums.ReviewTypeKey reviewType = BLLJIMP.Enums.ReviewTypeKey.ArticleComment;
            if (article.ArticleType == "Question")
            {
                reviewType = BLLJIMP.Enums.ReviewTypeKey.Answer;
            }
            if (article.ArticleType == "Appointment")
            {
                reviewType = BLLJIMP.Enums.ReviewTypeKey.AppointmentComment;
            }
            var addResult = bllReview.AddReview(reviewType, articleId, replyId, this.CurrentUserInfo.UserID, "评论", content, this.bllJuActivity.WebsiteOwner, out reviewId, isHideUserName);

            if (addResult)
            {
                if (reviewType == BLLJIMP.Enums.ReviewTypeKey.Answer)
                {
                    bllUser.AddUserScoreDetail(this.CurrentUserInfo.UserID, EnumStringHelper.ToString(ScoreDefineType.AnswerQuestions), this.bllJuActivity.WebsiteOwner, null, null);
                }
                resp.isSuccess   = true;
                resp.returnValue = reviewId.ToString();

                if (article.ArticleType == "Question")
                {
                    bllSystemNotice.SendNotice(BLLJIMP.BLLSystemNotice.NoticeType.QuestionIsAnswered, this.CurrentUserInfo, article, article.UserID, content);
                    List <UserInfo> users = bllUser.GetRelationUserList(BLLJIMP.Enums.CommRelationType.JuActivityFollow, articleId);
                    bllSystemNotice.SendNotice(BLLJIMP.BLLSystemNotice.NoticeType.FollowQuestionIsAnswered, this.CurrentUserInfo, article, users, content);
                }
            }
            else
            {
                resp.errcode   = (int)BLLJIMP.Enums.APIErrCode.OperateFail;
                resp.isSuccess = false;
            }
            context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 抽奖
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string Scratch(HttpContext context)
        {
            try
            {
                if (!bll.IsLogin)
                {
                    return("请先登录");
                }
                string id = context.Request["id"];
                if (string.IsNullOrEmpty(id))
                {
                    return("id必传");
                }

                /*
                 * 检查是否是签到抽奖,是则:
                 * 1.当前是否是在周日,不在周日则不能抽奖
                 * 2.如果在周日,检查是否一周内有签到记录,否则不能抽奖
                 *
                 */

                var signInModel = new BLLJIMP.BLLSignIn().Get <SignInAddress>(string.Format(" WebsiteOwner='{0}' AND Type='Sign' ", currentUserInfo.WebsiteOwner));
                if (signInModel != null && signInModel.LotteryId == id)
                {
                    var dt = DateTime.Now;

                    if (dt.DayOfWeek != DayOfWeek.Sunday)
                    {
                        return("周日才可以抽奖");
                    }

                    //获取本周签到记录,倒退七天是否有七条
                    var signInCount = bll.GetCount <SignInLog>(string.Format("  cast(SignInDate as date) between '{0}' and '{1}' and  WebsiteOwner = '{2}' and UserID = '{3}' ",
                                                                             dt.AddDays(-6).ToString("yyyy-MM-dd"),
                                                                             dt.ToString("yyyy-MM-dd"),
                                                                             currentUserInfo.WebsiteOwner,
                                                                             currentUserInfo.UserID
                                                                             ));

                    if (signInCount < 7)
                    {
                        return("一周连续签到才可以抽奖");
                    }
                }

                #region 检查是否可以继续
                ScratchJsonModel apiResult = new ScratchJsonModel();
                apiResult.awardName = "谢谢参与";
                WXLotteryV1 model = bll.Get <WXLotteryV1>(string.Format("LotteryID={0}", id));
                if (model == null)
                {
                    goto outoff;
                }
                apiResult.awardId = model.LotteryID;
                apiResult.isStart = model.Status == 1 ? true : false;
                if (model.StartTime != null)
                {
                    apiResult.startTime = model.StartTime.Value.ToString("yyyy/MM/dd HH:mm:ss");
                    if (model.StartTime <= DateTime.Now)//已经到了开奖时间了
                    {
                        if (model.Status == 1)
                        {
                            apiResult.isStart = true;
                        }
                        else
                        {
                            apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.NotStart;
                            apiResult.awardName = "刮奖未开启";
                            apiResult.isStart   = false;
                        }
                    }
                    else//开奖时间还没到
                    {
                        apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.NotStart;
                        apiResult.awardName = "未到刮奖时间";
                        apiResult.isStart   = false;
                        goto outoff;
                    }
                }

                //检查结束时间
                if (model.EndTime != null)
                {
                    apiResult.startTime = model.EndTime.Value.ToString("yyyy/MM/dd HH:mm:ss");
                    if (model.EndTime.Value <= DateTime.Now)
                    {
                        apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.IsEnd;
                        apiResult.awardName = "已结束";
                        apiResult.isStart   = false;
                        goto outoff;
                    }
                }

                if (context.Request["hideAward"] != "1")
                {
                    apiResult.winRecord = bll.GetWXLotteryRecordList(model.LotteryID, currentUserInfo.UserID);
                }
                if (model.WinLimitType.Equals(0))
                {
                    var lotteryRecord = bll.GetWXLotteryRecordV1(currentUserInfo.UserID, model.LotteryID);
                    if (lotteryRecord != null)
                    {
                        if (context.Request["hideAward"] != "1")
                        {
                            WXLotteryLogV1 logWinLimit = new WXLotteryLogV1();
                            logWinLimit.LotteryId  = model.LotteryID;
                            logWinLimit.UserId     = currentUserInfo.UserID;
                            logWinLimit.InsertDate = DateTime.Now;
                            logWinLimit.IP         = Common.MySpider.GetClientIP();
                            if (bll.AddWXLotteryLogV1(logWinLimit))//下一步
                            {
                            }

                            apiResult.awardName = string.Format("{0}", lotteryRecord.WXAwardName);
                            apiResult.isAward   = true;

                            //告诉前端你已经中过奖了
                            apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.LotteryHaveRecord;; //LotteryHaveRecord
                        }
                        goto outoff;
                    }
                }

                if (!apiResult.isStart)
                {
                    apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.NotStart;
                    apiResult.awardName = "刮奖未开启";
                    apiResult.isStart   = false;
                    goto outoff;
                }
                #endregion

                #region 内定中奖
                List <WXLotteryWinningDataV1> winData = bll.GetList <WXLotteryWinningDataV1>(string.Format("LotteryId={0}", model.LotteryID));
                if (winData.SingleOrDefault(p => p.UserId.Equals(currentUserInfo.UserID)) != null)
                {
                    //给默认中奖者中奖
                    WXLotteryRecordV1 record = new WXLotteryRecordV1();
                    record.InsertDate = DateTime.Now;
                    record.LotteryId  = model.LotteryID;
                    record.Token      = "0";
                    record.WXAwardsId = winData.Single(p => p.UserId.Equals(currentUserInfo.UserID)).WXAwardsId;
                    record.UserId     = currentUserInfo.UserID;
                    record.IsGetPrize = 0;
                    if (bll.AddWXLotteryRecordV1(record))
                    {
                        apiResult.awardName = string.Format("{0}", winData.Single(p => p.UserId.Equals(currentUserInfo.UserID)).WXAwardName);
                        apiResult.isAward   = true;
                    }

                    goto outoff;
                }
                //设置默认中奖
                #endregion

                #region 外部积分读取
                var isSyncYike = new BLLJIMP.BLLCommRelation().ExistRelation(BLLJIMP.Enums.CommRelationType.SyncYike, currentUserInfo.WebsiteOwner, "");

                Open.EZRproSDK.Client zrClient = new Open.EZRproSDK.Client();

                if (isSyncYike)
                {
                    var getBonusResp = zrClient.GetBonus(currentUserInfo.Ex1, currentUserInfo.Ex2, currentUserInfo.Phone);
                    if (getBonusResp != null)
                    {
                        currentUserInfo.TotalScore = getBonusResp.Bonus;
                    }
                    else
                    {
                        currentUserInfo.TotalScore = 0;
                    }
                }
                #endregion


                #region 使用宏巍积分

                Open.HongWareSDK.Client hongWareClient = new Open.HongWareSDK.Client(websiteInfo.WebsiteOwner);
                if (websiteInfo.IsUnionHongware == 1)
                {
                    var hongWareMemberInfo = hongWareClient.GetMemberInfo(currentUserInfo.WXOpenId);
                    if (hongWareMemberInfo.member != null)
                    {
                        currentUserInfo.TotalScore = hongWareMemberInfo.member.point;
                    }
                    else
                    {
                        currentUserInfo.TotalScore = 0;
                    }
                }
                #endregion

                string tempMsg = "";
                #region 抽奖限制 总共多少次或每天几次  用购买的刮奖次数除外

                #region 总共多少次
                if (model.LuckLimitType.Equals(0))//总共多少次
                {
                    int count = bll.GetWXLotteryLogCountV1(model.LotteryID, currentUserInfo.UserID);
                    if (count >= model.MaxCount)
                    {
                        //判读是否够积分
                        if (model.UsePoints > 0)
                        {
                            if (currentUserInfo.TotalScore >= model.UsePoints)
                            {
                                //扣积分
                                if (isSyncYike)
                                {
                                    var resp = zrClient.BonusUpdate(currentUserInfo.Ex2, -model.UsePoints, "抽奖减少积分");
                                }
                                else
                                {
                                    bllUser.AddUserScoreDetail(currentUserInfo.UserID, EnumStringHelper.ToString(ScoreDefineType.Lottery), bllUser.WebsiteOwner, out tempMsg, -model.UsePoints, "抽奖减少积分", "", false);
                                }
                            }
                            else
                            {
                                if (currentUserInfo.LotteryCount == 0)
                                {
                                    apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.IntegralProblem;
                                    apiResult.awardName = "积分不足";
                                    apiResult.isStart   = false;
                                    goto outoff;
                                }
                                else
                                {
                                    //剩余刮奖次数减1
                                    if (bll.Update(currentUserInfo, string.Format(" LotteryCount-=1"), string.Format("AutoId={0}", currentUserInfo.AutoID)) <= 0)
                                    {
                                        apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.IntegralProblem;
                                        apiResult.awardName = "谢谢参与";
                                        apiResult.isStart   = false;
                                        goto outoff;
                                    }
                                }
                            }
                        }
                        else
                        {
                            apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.CountIsOver;
                            apiResult.awardName = "谢谢参与";
                            goto outoff;
                        }
                    }
                }
                #endregion

                #region 每天多少次
                else
                {
                    //判读一天有没有超出
                    int count = bll.GetWXLotteryLogCountV1(model.LotteryID, currentUserInfo.UserID, DateTime.Now);
                    if (count >= model.MaxCount)
                    {
                        //判读是否够积分
                        if (model.UsePoints > 0)
                        {
                            if (currentUserInfo.TotalScore >= model.UsePoints)
                            {
                                if (isSyncYike)
                                {
                                    var resp = zrClient.BonusUpdate(currentUserInfo.Ex2, -model.UsePoints, "抽奖减少积分");
                                }
                                else
                                {
                                    //扣积分
                                    bllUser.AddUserScoreDetail(currentUserInfo.UserID, EnumStringHelper.ToString(ScoreDefineType.Lottery), bllUser.WebsiteOwner, out tempMsg, -model.UsePoints, "抽奖减少积分", "", false);
                                }
                            }
                            else
                            {
                                if (currentUserInfo.LotteryCount == 0)
                                {
                                    apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.IntegralProblem;
                                    apiResult.awardName = "积分不足";
                                    apiResult.isStart   = false;
                                    goto outoff;
                                }
                                else
                                {
                                    //剩余刮奖次数减1
                                    if (bll.Update(currentUserInfo, string.Format(" LotteryCount-=1"), string.Format("AutoId={0}", currentUserInfo.AutoID)) <= 0)
                                    {
                                        apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.IntegralProblem;
                                        apiResult.awardName = "谢谢参与";
                                        apiResult.isStart   = false;
                                        goto outoff;
                                    }
                                }
                            }
                        }
                        else
                        {
                            apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.CountIsOver;
                            apiResult.awardName = "谢谢参与";
                            goto outoff;
                        }
                    }
                }
                #endregion

                #endregion

                WXLotteryLogV1 log = new WXLotteryLogV1();
                log.LotteryId  = model.LotteryID;
                log.UserId     = currentUserInfo.UserID;
                log.InsertDate = DateTime.Now;
                log.IP         = Common.MySpider.GetClientIP();
                if (bll.AddWXLotteryLogV1(log))//下一步
                {
                    #region 奖池生成
                    List <AwardModel> awardModelList = new List <AwardModel>();                                                             //奖池
                    List <WXAwardsV1> awardsList     = bll.GetAwardsListV1(model.LotteryID).Where(p => p.WinCount < p.PrizeCount).ToList(); //奖品列表 //已经中完的不参与
                    foreach (var item in awardsList)
                    {
                        for (int i = 1; i <= item.Probability; i++)
                        {
                            AwardModel m = new AwardModel();
                            m.AwardID    = item.AutoID;
                            m.PrizeName  = item.PrizeName;
                            m.AwardsType = item.AwardsType;
                            m.Img        = item.Img;
                            m.Value      = item.Value;
                            awardModelList.Add(m);
                        }
                    }
                    if (awardsList.Sum(p => p.Probability) < 100)//总中奖概率小于100 补足
                    {
                        for (int i = 1; i <= (100 - (awardsList.Sum(p => p.Probability))); i++)
                        {
                            AwardModel m = new AwardModel();
                            m.AwardID   = 0;
                            m.PrizeName = "谢谢参与";
                            awardModelList.Add(m);
                        }
                    }
                    #endregion
                    //打乱数组顺序
                    awardModelList = GetRandomList <AwardModel>(awardModelList);
                    Random rand  = new Random();
                    int    index = rand.Next(0, awardModelList.Count);

                    #region 抽奖
                    if (awardModelList[index].AwardID > 0)//随机数中奖
                    {
                        string sqlUpdate = string.Format(" Update ZCJ_WXAwardsV1  Set WinCount+=1  where AutoID={0} And WinCount<PrizeCount ", awardModelList[index].AwardID);
                        if (ZentCloud.ZCBLLEngine.BLLBase.ExecuteSql(sqlUpdate) > 0)
                        {
                            int token = rand.Next(1111, 9999);
                            //插入中奖记录
                            WXLotteryRecordV1 record = new WXLotteryRecordV1();
                            record.InsertDate = DateTime.Now;
                            record.LotteryId  = model.LotteryID;
                            record.Token      = token.ToString();
                            record.WXAwardsId = awardModelList[index].AwardID;
                            record.UserId     = currentUserInfo.UserID;
                            record.IsGetPrize = 0;
                            if (bll.AddWXLotteryRecordV1(record))
                            {
                                apiResult.awardName  = string.Format("{0}", awardModelList[index].PrizeName);
                                apiResult.isAward    = true;
                                apiResult.awardsType = awardModelList[index].AwardsType;
                                apiResult.img        = awardModelList[index].Img;
                                apiResult.value      = awardModelList[index].Value;

                                if (apiResult.awardsType == 2)
                                {
                                    BLLJIMP.BLLCardCoupon bllCardCoupon = new BLLJIMP.BLLCardCoupon();

                                    var coupon = bllCardCoupon.GetCardCoupon(int.Parse(apiResult.value));
                                    apiResult.cardcoupon_name  = coupon.Name;
                                    apiResult.cardcoupon_type  = coupon.CardCouponType;
                                    apiResult.cardcoupon_start = coupon.ValidFrom == null ? "" : coupon.ValidFrom.Value.ToShortDateString();
                                    apiResult.cardcoupon_end   = coupon.ValidTo == null ? "" : coupon.ValidTo.Value.ToShortDateString();
                                    if (coupon.ExpireTimeType == "1")
                                    {
                                        apiResult.cardcoupon_start = DateTime.Now.ToShortDateString();
                                        apiResult.cardcoupon_end   = DateTime.Now.AddDays(Convert.ToInt32(coupon.ExpireDay)).ToShortDateString();
                                    }
                                }
                                if (apiResult.awardsType == 1 || apiResult.awardsType == 2)
                                {
                                    //中奖记录标记为已经领奖
                                    WXLotteryRecordV1 rec = bll.Get <WXLotteryRecordV1>(string.Format(" UserId='{0}' And LotteryId={1} And WXAwardsId={2} And Token='{3}'", record.UserId, record.LotteryId, record.WXAwardsId, record.Token));
                                    if (rec != null)
                                    {
                                        rec.IsGetPrize = 1;
                                        bll.Update(rec);
                                    }
                                }

                                goto outoff;
                            }
                            else
                            {
                                goto outoff;
                            }
                        }
                        else
                        {
                            goto outoff;
                        }

                        //}
                        //else
                        //{   //#region 虽然随机数中奖,但是奖项数量已经达到上限,重新随机抽奖
                        //    //if (reCount >= 5)
                        //    //{
                        //    goto outoff;
                        //    //}
                        //    //reCount++;
                        //    //goto start;
                        //}
                    }
                    else
                    {
                        //随机数未中奖
                    }
                    #endregion
                }
outoff:
                if (!string.IsNullOrEmpty(context.Request["callback"]))
                {
                    return(string.Format("{0}({1})", context.Request["callback"], Common.JSONHelper.ObjectToJson(apiResult)));
                }
                return(Common.JSONHelper.ObjectToJson(apiResult));
            }
            catch (Exception ex)
            {
                return(ex.ToString());
            }
        }
Exemplo n.º 6
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                Tolog("京东支付通知start");
                var    payConfig = bllPay.GetPayConfig();
                byte[] byts      = new byte[context.Request.InputStream.Length];
                context.Request.InputStream.Read(byts, 0, byts.Length);
                string req = Encoding.UTF8.GetString(byts);
                Tolog("通知参数" + req);

                //var jdPubKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCKE5N2xm3NIrXON8Zj19GNtLZ8xwEQ6uDIyrS3S03UhgBJMkGl4msfq4Xuxv6XUAN7oU1XhV3/xtabr9rXto4Ke3d6WwNbxwXnK5LSgsQc1BhT5NcXHXpGBdt7P8NMez5qGieOKqHGvT0qvjyYnYA29a8Z4wzNR7vAVHp36uD5RwIDAQAB";

                //req = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><jdpay><version>V2.0</version><merchant>110226843002</merchant><result><code>000000</code><desc>success</desc></result><encrypt>MDIxZjNkNjI1YjU1NzQ4MWE5N2ExMTg3YjkxNmQ4NzkxYzQyMmFjZjM4YTM1MjZjY2JjNzM1ZDkxY2Q5ZDNmMTMzMGFjYTBkNTI0MzYzNjc3MTVhODI3OWUzZTAxMmY5ODEyOTVmNDNiNWY5MDZhZGJiYTcwYTYyOTFlYzVmYTU2Y2EyN2U1YzhkNzllMGE3ZTUyNDE4NWU4OWMxNjIwNDFkODcyYzJiZDA4ZWY4YWEyMmY5ZWUxNDk3YTg3MTI3YmU1NTMxNjc5NWJiOTlmN2ZmNGU1MTc1YWJhNjNkYjUzYWUwZDQzOTk4ZjIzMjBiYmVkNGJkMDcxOWUzOThjZjU1ODUwNzM4Y2RiNzM2Njc1N2U2ZTcxN2Q0N2ZiYTZmN2M1YzBiYzRmMjc4ZThiZDNhYTkxZTExNzBiYjg2ZDNjNmQ3OWUyZTBlYjUzZWNlZjFjODQ2MzdiN2E5MTQxN2Y3NmRhZmNkNDdiMzMwNjc1MGRhYjhiYzg0NTFkOWNiY2QyMDZhOTJiYzU2YTFiOWEwMjRmNTZhMWZhNTVhNjlmYTA1ZDFlMmI0YTI4MGE1YTU0N2NlMjc3ZWMwM2QyNWE4ODdlOTA0ZGM3YTY2MDViY2I1OTI5MDBlYWU4MGU0Mzc4MmEwOWY3ZjEwZTk5MGZkOGUzYTA4MzNkNGMyZGZkNWM3MDhkOGU4N2NhMmQyZGM1MDgwYzUyOTg3OGNkMzFhZWRkMTE1NDM5ZjExYTM2OGM2OGE4MGZjZTYyMjJkNzlmODcwNGYyNDMzMTYyZThhZTBkODM2ODBjYzg5ZGRjMWY3ZGVmYzQzYjc4MDZiMDNhMTBmZTc2YjI3MThjYjQ0YjQwZDkyY2E3OGUzYmYzZmFlNjBlOTI4OGU1ODVkNjBjMWZiNDBmMjFjNzVmNDkxYmRkYWFlNzQ0YjZkYmU1ODNkOWQ4OGYwN2EyMDViOWQ5MGNjMzViMTE3MDQ4NWVlNTdlN2Y5MTRhZDM3YzFlODY1NDFiZmQyNDg1MzhlZGZiNDNiZWZmZjY3YmE3NWQ5YjI0MzE4ZDMzMDE5NTE3YWM4ZTJiMDZhZWYyM2NhNjMwODc3MDhkNTdkZWI3MWVhMmY2MzA2ZDliZjBmZGFlNzQ3ODgzODg0ZjVhOWFkODIxYWM0NGQ1ZDlmMGRlNDhkMjBiYTJjYmQ4NTlkMmU3NDMxZDExZmRjMzkxMDU3ZmE3NGE0Yzg2OThkMmY0ZWQ1ZjE3MjIwOWQ1ZTBmZGIzZjFhNGYwOTllZWY5YzRiMWYyZDAxZjlhNzhlYWY5ZjU0YmIyZjczNmUxMjJkNWY2NzhlMDFmYjU0YjY3NWRlYTc1ZWZkNmMwNTJhZmY3ZGVhMGM5NjAyMWQwMGQyMjI2NzdhM2RlNDdhMTdkMWI4ZWQxYmEyYWZlZDg1ZjI4NDk2ZmI2MGVjOTc5OTc4MjgzZTEyNzY2ZmI1OWUzZjY1MWI4OTVlMmQ4OGNlNGRhODg0NzJiNTFiN2RmZDc5NzdkNDk4NTY0NGU4ZjBmNGZjMTM3MmUzMGNhMTUwOTFkNDFhODIzMjZiODU0YjMzNmI1N2EwZDVjMjZjOWNjMzBlMjFjZjNkMDA0NjQ4Zjk0NjQzZWRhOTU1MmIyZjJkYzZjNGJmOTU5MDIzNTBlODlmOTNhZDRhYmEyMzZiY2E1OWE4NzY5Mjc0ZTcwN2MyNGFjNGJmOTU5MDIzNTBlODlmNDNlZGE5NTUyYjJmMmRjNjU0MTNlZjYxZTNlODc4MDk3MmNiYjg3NTVjNmU1NWNlZDljNWU0ZDE5ZTRmZjJjZTAxNmJiMGIzYWFlOTdlYTQzYmM5NWVmMGU0ZjUyNzY4NDNlZGE5NTUyYjJmMmRjNmMyOWRiYWZkYTNjYzQ1M2E3ZGJhZWNjZWJmNGIxZmQ5MTMxMmRiMzliOTU2YzBmNmNiODMxMDQ1ZDBiYjM1ZTNmMzlmMGE0ODNiN2M3ODYyZjNjMTFiN2ZiODljNDNkMjE4NGFlNzU5M2JhMmQ2YTJkOWMwMmYxYTBlNTg2MzhkYzU0NzE0NjExNzkyNGU4ZjQ4NDgzMTAyNDY5OGRlNGZiMDVmNGQzNzE3NGMwOGI2NGU2NjkxMmU2NGY5M2I0YjNiMThmMzZiZmY0NTgwN2FjMDAxOWRlY2ZkYTcyOGFmNzIyZTQwNjhlMTViM2UwMmQzMmRiYjJkOTE2MmQzNWMzZWM2OGRkZjJjMjdmOTRhZGNmYzEzOTdlOWY0NjQwODFiYWU0Y2E3Y2NjZDY0NjQzNGFmZWU4ODExYWRiZTBlY2MwY2JlOThmNDliMDZkYjE2YjNjNTZhOTRiOGZkMDU=</encrypt></jdpay>";

                //req = Regex.Replace(req, @"[\t\n\r]", "", RegexOptions.IgnoreCase);

                req = req.Replace("\r", "").Replace("\n", "").Replace("\t", "");

                AsynNotifyResponse anyResponse = Payment.JDPay.XMLUtil.decryptResXml <AsynNotifyResponse>(Payment.JDPay.Config.JDPubKey, payConfig.JDPayDESKey, req);
                // System.Diagnostics.Debug.WriteLine("异步通知订单号:" + anyResponse.tradeNum + ",状态:" + anyResponse.status);
                Tolog("异步通知订单号:" + anyResponse.tradeNum + ",状态:" + anyResponse.status);
                var orderId   = anyResponse.tradeNum;
                var orderInfo = bllMall.GetOrderInfo(orderId);
                if (orderInfo == null)
                {
                    //context.Response.Write("订单未找到");
                    context.Response.StatusCode = 500;
                    context.Response.Write(failStr);
                    return;
                }
                if (orderInfo.PaymentStatus.Equals(1))
                {
                    //Tolog("已支付");
                    // context.Response.Write("订单已支付");
                    context.Response.StatusCode = 200;
                    context.Response.Write(successStr);
                    return;
                }



                if (anyResponse.status == "2")
                {
                    orderInfo.PaymentType = 3;

                    //支付成功
                    WXMallProductInfo tProductInfo  = new WXMallProductInfo();
                    UserInfo          orderUserInfo = bllUser.GetUserInfo(orderInfo.OrderUserID, orderInfo.WebsiteOwner);//下单用户信息
                    string            hasOrderIDs   = "";
                    int maxCount = 1;
                    //Tolog("准备检查更新订单状态");
                    if (BLLJIMP.BLLMall.bookingList.Contains(orderInfo.ArticleCategoryType))
                    {
                        //Tolog("预订类型");
                        #region 预约订单修改状态
                        orderInfo.PaymentStatus = 1;
                        orderInfo.PayTime       = DateTime.Now;
                        orderInfo.Status        = "预约成功";

                        #region 检查是否有预约成功的订单
                        List <WXMallOrderDetailsInfo> tDetailList = bllMall.GetOrderDetailsList(orderInfo.OrderID, null, orderInfo.ArticleCategoryType, null, null);
                        List <WXMallOrderDetailsInfo> oDetailList = bllMall.GetOrderDetailsList(null, tDetailList[0].PID, orderInfo.ArticleCategoryType, tDetailList.Min(p => p.StartDate), tDetailList.Max(p => p.EndDate));
                        tProductInfo = bllMall.GetByKey <WXMallProductInfo>("PID", tDetailList[0].PID);
                        maxCount     = tProductInfo.Stock;
                        List <string> hasOrderIDList = new List <string>();
                        foreach (var item in tDetailList)
                        {
                            List <WXMallOrderDetailsInfo> hasOrderDetailList = oDetailList.Where(p => !((item.StartDate >= p.EndDate && item.EndDate > p.EndDate) || (item.StartDate < p.StartDate && item.EndDate <= p.StartDate))).ToList();
                            if (hasOrderDetailList.Count >= maxCount)
                            {
                                hasOrderIDList.AddRange(hasOrderDetailList.Select(p => p.OrderID).Distinct());
                            }
                        }
                        hasOrderIDList = hasOrderIDList.Where(p => !p.Contains(orderInfo.OrderID)).ToList();
                        if (hasOrderIDList.Count > 0)
                        {
                            hasOrderIDList = hasOrderIDList.Distinct().ToList();
                            hasOrderIDs    = MyStringHelper.ListToStr(hasOrderIDList, "'", ",");
                        }
                        #endregion 检查是否有预约成功的订单

                        #endregion 预约订单修改状态
                    }
                    else
                    {
                        //Tolog("普通类型");
                        #region 原订单修改状态
                        orderInfo.PaymentStatus = 1;
                        orderInfo.Status        = "待发货";
                        orderInfo.PayTime       = DateTime.Now;
                        Tolog("更改状态start");
                        //if (bllMall.GetWebsiteInfoModelFromDataBase().IsDistributionMall.Equals(1))
                        //{
                        orderInfo.GroupBuyStatus     = "0";
                        orderInfo.DistributionStatus = 1;

                        #region 拼团订单
                        if (orderInfo.OrderType == 2)
                        {
                            try
                            {
                                if (!string.IsNullOrEmpty(orderInfo.GroupBuyParentOrderId))
                                {
                                    var parentOrderInfo = bllMall.GetOrderInfo(orderInfo.GroupBuyParentOrderId);

                                    if (bllMall.GetCount <WXMallOrderInfo>(string.Format("PaymentStatus=1 And GroupBuyParentOrderId='{0}' Or OrderId='{0}'", parentOrderInfo.OrderID)) >= parentOrderInfo.PeopleCount)
                                    {
                                        bllMall.Update(new WXMallOrderInfo(), string.Format("Status='已取消'"), string.Format("  GroupBuyParentOrderId='{0}' And PaymentStatus=0", parentOrderInfo.OrderID));
                                        parentOrderInfo.GroupBuyStatus = "1";
                                        bllMall.Update(parentOrderInfo);
                                    }
                                }
                            }
                            catch (Exception)
                            {
                            }
                        }
                        #endregion

                        #region 活动订单
                        if (orderInfo.OrderType == 4)
                        {
                            ActivityDataInfo data = bllMall.Get <ActivityDataInfo>(string.Format(" OrderId='{0}'", orderInfo.OrderID));
                            if (data != null)
                            {
                                bllMall.Update(data, string.Format(" PaymentStatus=1"), string.Format("  OrderId='{0}'", orderInfo.OrderID));
                            }
                        }
                        #endregion

                        bllMall.Update(orderInfo, string.Format("PaymentStatus=1,Status='待发货',PayTime=GETDATE(),DistributionStatus=1"), string.Format("ParentOrderId='{0}'", orderInfo.OrderID));

                        //}
                        #endregion 原订单修改状态

                        //orderInfo.PayTranNo = tradeNo;
                    }
                    bool result = false;

                    if (BLLJIMP.BLLMall.bookingList.Contains(orderInfo.ArticleCategoryType))
                    {
                        if (string.IsNullOrWhiteSpace(hasOrderIDs))
                        {
                            hasOrderIDs = "'0'";
                        }
                        result = bllMall.Update(new WXMallOrderInfo(),
                                                string.Format("PaymentStatus={0},PayTime=GetDate(),Status='{1}'", 1, "预约成功"),
                                                string.Format("OrderID='{0}' and WebsiteOwner='{4}' AND (select count(1) from [ZCJ_WXMallOrderInfo] where Status='{3}' and WebsiteOwner='{4}' and  OrderID IN({1}))<{2}",
                                                              orderInfo.OrderID, hasOrderIDs, maxCount, "预约成功", bllMall.WebsiteOwner)
                                                ) > 0;
                        if (result)
                        {
                            // #region 交易成功加积分
                            //增加积分 (慧聚不需要)
                            //if (orderInfo.TotalAmount > 0)
                            //{
                            //    ScoreConfig scoreConfig = bllScore.GetScoreConfig();
                            //    int addScore = 0;
                            //    if (scoreConfig != null && scoreConfig.OrderAmount > 0 && scoreConfig.OrderScore > 0)
                            //    {
                            //        addScore = (int)(orderInfo.PayableAmount / (scoreConfig.OrderAmount / scoreConfig.OrderScore));
                            //    }
                            //    if (addScore > 0)
                            //    {
                            //        if (bllUser.Update(new UserInfo(),
                            //            string.Format(" TotalScore+={0},HistoryTotalScore+={0}", addScore),
                            //            string.Format(" UserID='{0}'", orderInfo.OrderUserID)) > 0)
                            //        {
                            //            UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo();
                            //            scoreRecord.AddTime = DateTime.Now;
                            //            scoreRecord.Score = addScore;
                            //            scoreRecord.ScoreType = "OrderSuccess";
                            //            scoreRecord.UserID = orderInfo.OrderUserID;
                            //            scoreRecord.AddNote = "预约-交易成功获得积分";
                            //            bllMall.Add(scoreRecord);
                            //        }
                            //    }
                            //}
                            // #endregion

                            #region 修改其他预约订单为预约失败 返还积分

                            if (BLLJIMP.BLLMall.bookingList.Contains(orderInfo.ArticleCategoryType) && !string.IsNullOrWhiteSpace(hasOrderIDs))
                            {
                                int tempCount = 0;
                                List <WXMallOrderInfo> tempList = bllMall.GetOrderList(0, 1, "", out tempCount, "预约成功", null, null, null,
                                                                                       null, null, null, null, null, null, null, orderInfo.ArticleCategoryType, hasOrderIDs);
                                tempCount = tempCount + 1; //加上当前订单的数量
                                if (tempCount >= maxCount)
                                {
                                    tempList = bllMall.GetColOrderListInStatus("'待付款','待审核'", hasOrderIDs, "OrderID,OrderUserID,UseScore", bllMall.WebsiteOwner);
                                    if (tempList.Count > 0)
                                    {
                                        string stopOrderIds = MyStringHelper.ListToStr(tempList.Select(p => p.OrderID).ToList(), "'", ",");
                                        tempList = tempList.Where(p => p.UseScore > 0).ToList();
                                        foreach (var item in tempList)
                                        {
                                            orderUserInfo.TotalScore += item.UseScore;
                                            if (bllUser.Update(new UserInfo(), string.Format(" TotalScore+={0}", item.UseScore),
                                                               string.Format(" UserID='{0}'", item.OrderUserID)) > 0)
                                            {
                                                UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo();
                                                scoreRecord.AddTime      = DateTime.Now;
                                                scoreRecord.Score        = item.UseScore;
                                                scoreRecord.TotalScore   = orderUserInfo.TotalScore;
                                                scoreRecord.ScoreType    = "OrderCancel";
                                                scoreRecord.UserID       = item.OrderUserID;
                                                scoreRecord.RelationID   = item.OrderID;
                                                scoreRecord.AddNote      = "预约-订单失败返还积分";
                                                scoreRecord.WebSiteOwner = item.WebsiteOwner;
                                                bllMall.Add(scoreRecord);
                                            }
                                        }
                                        bllMall.Update(new WXMallOrderInfo(),
                                                       string.Format("Status='{0}'", "预约失败"),
                                                       string.Format("OrderID In ({0}) and WebsiteOwner='{1}'", stopOrderIds, bllMall.WebsiteOwner));
                                    }
                                }
                                //Tolog("更改修改其他预约为预约失败");
                            }
                            #endregion
                        }
                    }
                    else
                    {
                        result = bllMall.Update(orderInfo);
                    }
                    if (result)
                    {
                        Open.HongWareSDK.Client hongWareClient = new Open.HongWareSDK.Client(orderInfo.WebsiteOwner);

                        //Tolog("更改状态true");

                        #region Efast同步
                        //判读当前站点是否需要同步到驿氪和efast
                        if (bllCommRelation.ExistRelation(BLLJIMP.Enums.CommRelationType.SyncEfast, bllCommRelation.WebsiteOwner, ""))
                        {
                            try
                            {
                                Tolog("开始同步efast");

                                string outOrderId = string.Empty, msg = string.Empty;
                                var    syncResult = bllEfast.CreateOrder(orderInfo.OrderID, out outOrderId, out msg);
                                if (syncResult)
                                {
                                    orderInfo.OutOrderId = outOrderId;
                                    bllMall.Update(orderInfo);
                                }
                                Tolog(string.Format("efast订单同步结果:{0},订单号:{1},提示信息:{2}", syncResult, outOrderId, msg));
                            }
                            catch (Exception ex)
                            {
                                Tolog("efast订单同步异常:" + ex.Message);
                            }
                        }
                        #endregion

                        #region 驿氪同步
                        if (bllCommRelation.ExistRelation(BLLJIMP.Enums.CommRelationType.SyncYike, bllCommRelation.WebsiteOwner, ""))
                        {
                            try
                            {
                                Tolog("开始同步驿氪");
                                //同步成功订单到驿氪

                                //UserInfo orderUserInfo = bllUser.GetUserInfo(orderInfo.OrderUserID);
                                //if ((!string.IsNullOrEmpty(orderUserInfo.Ex1)) && (!string.IsNullOrEmpty(orderUserInfo.Ex2)) && (!string.IsNullOrEmpty(orderUserInfo.Phone)))
                                //{
                                //    client.BonusUpdate(orderUserInfo.Ex2, -(orderInfo.UseScore), "商城下单使用积分" + orderInfo.UseScore);

                                //}
                                var uploadOrderResult = yikeClient.OrderUpload(orderInfo);

                                Tolog(string.Format("驿氪订单同步结果:{0}", Common.JSONHelper.ObjectToJson(uploadOrderResult)));
                            }
                            catch (Exception ex)
                            {
                                Tolog("驿氪订单同步异常:" + ex.Message);
                            }
                        }
                        #endregion

                        #region 付款加积分
                        try
                        {
                            bllUser.AddUserScoreDetail(orderInfo.OrderUserID, CommonPlatform.Helper.EnumStringHelper.ToString(ZentCloud.BLLJIMP.Enums.ScoreDefineType.OrderPay), bllMall.WebsiteOwner, null, null);
                        }
                        catch (Exception)
                        { }

                        #endregion


                        #region 消息通知
                        if (!BLLJIMP.BLLMall.bookingList.Contains(orderInfo.ArticleCategoryType))
                        {
                            try
                            {
                                var    productName = bllMall.GetOrderDetailsList(orderInfo.OrderID)[0].ProductName;
                                string remark      = "";
                                if (!string.IsNullOrEmpty(orderInfo.OrderMemo))
                                {
                                    remark = string.Format("客户留言:{0}", orderInfo.OrderMemo);
                                }
                                bllWeiXin.SendTemplateMessageToKefu("有新的订单", string.Format("订单号:{0}\\n订单金额:{1}元\\n收货人:{2}\\n电话:{3}\\n商品:{4}\\n{5}", orderInfo.OrderID, orderInfo.TotalAmount, orderInfo.Consignee, orderInfo.Phone, productName, remark));
                                if (orderInfo.OrderType != 4)//付费的活动不发消息
                                {
                                    if (orderInfo.WebsiteOwner != "jikuwifi")
                                    {
                                        string url = string.Format("http://{0}/customize/shop/?v=1.0&ngroute=/orderDetail/{1}#/orderDetail/{1}", context.Request.Url.Host, orderInfo.OrderID);
                                        bllWeiXin.SendTemplateMessageNotifyComm(orderUserInfo, "订单已成功支付,我们将尽快发货,请保持手机畅通等待物流送达!", string.Format("订单号:{0}\\n订单金额:{1}元\\n收货人:{2}\\n电话:{3}\\n商品:{4}...\\n查看详情", orderInfo.OrderID, orderInfo.TotalAmount, orderInfo.Consignee, orderInfo.Phone, productName), url);
                                    }
                                }
                            }
                            catch (Exception)
                            {
                            }
                        }
                        else
                        {
                            try
                            {
                                bllWeiXin.SendTemplateMessageToKefu(orderInfo.Status, string.Format("预约:{2}\\n订单号:{0}\\n订单金额:{1}元\\n预约人:{3}\\n预约人手机:{4}", orderInfo.OrderID, orderInfo.TotalAmount, tProductInfo.PName, orderUserInfo.TrueName, orderUserInfo.Phone));
                                bllWeiXin.SendTemplateMessageNotifyComm(orderUserInfo, orderInfo.Status, string.Format("预约:{2}\\n订单号:{0}\\n订单金额:{1}元", orderInfo.OrderID, orderInfo.TotalAmount, tProductInfo.PName));
                            }
                            catch (Exception)
                            {
                            }
                        }
                        #endregion
                        WebsiteInfo websiteInfo = bllMall.Get <WebsiteInfo>(string.Format(" WebsiteOwner='{0}'", orderInfo.WebsiteOwner));
                        #region 分销相关
                        try
                        {
                            if (bllMenuPermission.CheckUserAndPmsKey(websiteInfo.WebsiteOwner, BLLPermission.Enums.PermissionSysKey.OnlineDistribution, websiteInfo.WebsiteOwner))
                            {
                                if (string.IsNullOrWhiteSpace(orderUserInfo.DistributionOwner))
                                {
                                    if (websiteInfo.DistributionRelationBuildMallOrder == 1)
                                    {
                                        orderUserInfo.DistributionOwner = bllMall.WebsiteOwner;
                                        bllMall.Update(orderUserInfo);
                                    }
                                }

                                bllDis.AutoUpdateLevel(orderInfo);
                                bllDis.TransfersEstimate(orderInfo);
                                bllDis.SendMessageToUser(orderInfo);
                                bllDis.UpdateDistributionSaleAmountUp(orderInfo);
                            }
                        }
                        catch (Exception ex)
                        {
                            Tolog("设置分销员异常:" + ex.Message + " 用户id:" + orderUserInfo.UserID);
                        }
                        #endregion


                        #region 宏巍通知
                        try
                        {
                            if (websiteInfo.IsUnionHongware == 1)
                            {
                                hongWareClient.OrderNotice(orderUserInfo.WXOpenId, orderInfo.OrderID);
                            }
                        }
                        catch (Exception)
                        {
                        }

                        #endregion

                        bllCard.Give(orderInfo.TotalAmount, orderUserInfo);


                        string v1ProductId = Common.ConfigHelper.GetConfigString("YGBV1ProductId");
                        string v2ProductId = Common.ConfigHelper.GetConfigString("YGBV2ProductId");
                        string v1CouponId  = Common.ConfigHelper.GetConfigString("YGBV1CouponId");
                        string v2CouponId  = Common.ConfigHelper.GetConfigString("YGBV2CouponId");

                        List <WXMallOrderDetailsInfo> orderDetailList = bllMall.GetOrderDetailsList(orderInfo.OrderID);
                        foreach (var item in orderDetailList)
                        {
                            item.IsComplete = 1;
                            bllMall.Update(item);
                            #region 购买指定商品发送指定的优惠券
                            if (!string.IsNullOrEmpty(v1ProductId) && !string.IsNullOrEmpty(v1CouponId) && item.PID == v1ProductId)
                            {
                                bllCard.SendCardCouponsByCurrUserInfo(orderUserInfo, v1CouponId);
                            }

                            if (!string.IsNullOrEmpty(v2ProductId) && !string.IsNullOrEmpty(v2CouponId) && item.PID == v2ProductId)
                            {
                                bllCard.SendCardCouponsByCurrUserInfo(orderUserInfo, v2CouponId);
                            }
                            #endregion
                        }
                        //更新销量
                        bllMall.UpdateProductSaleCount(orderInfo);

                        context.Response.StatusCode = 200;
                        context.Response.Write(successStr);
                        Tolog("支付成功" + orderInfo.OrderID);
                        return;
                    }
                    else
                    {
                        Tolog("更改状态false");
                        context.Response.StatusCode = 500;
                        context.Response.Write(failStr);
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                //error = "fail";
                Tolog("京东支付异常:" + ex.ToString());
            }

            context.Response.ContentType = "text/plain";
            context.Response.StatusCode  = 500;
            context.Response.Write(failStr);
        }
Exemplo n.º 7
0
        public void ProcessRequest(HttpContext context)
        {
            var articleId = context.Request["articleid"];
            var content   = context.Request["content"];
            var replyId   = Convert.ToInt32(context.Request["replyid"]);//评论了文章里的哪个评论

            int isHideUserName = Convert.ToInt32(context.Request["ishideusername"]);

            currentUserInfo = bllUser.GetCurrentUserInfo();
            if (this.currentUserInfo == null)
            {
                apiResp.code = (int)BLLJIMP.Enums.APIErrCode.UserIsNotLogin;
                apiResp.msg  = "请先登录";
                bllUser.ContextResponse(context, apiResp);
                return;
            }

            if (string.IsNullOrWhiteSpace(articleId) || string.IsNullOrWhiteSpace(content))
            {
                apiResp.code = (int)BLLJIMP.Enums.APIErrCode.PrimaryKeyIncomplete;
                bllUser.ContextResponse(context, apiResp);
                return;
            }

            if (bllUser.GetCount <JuActivityInfo>(string.Format(" JuActivityID = {0} ", articleId)) == 0)
            {
                apiResp.code = (int)BLLJIMP.Enums.APIErrCode.ContentNotFound;
                bllUser.ContextResponse(context, apiResp);
                return;
            }
            //敏感词检查
            BLLFilterWord bllFilterWord = new BLLFilterWord();
            string        errmsg        = "";

            if (!bllFilterWord.CheckFilterWord(content, this.bllUser.WebsiteOwner, out errmsg, "0"))
            {
                apiResp.msg  = errmsg;
                apiResp.code = (int)BLLJIMP.Enums.APIErrCode.OperateFail;
                bllUser.ContextResponse(context, apiResp);
                return;
            }
            //添加评论
            int            reviewId = 0;
            JuActivityInfo article  = bll.GetJuActivity(int.Parse(articleId), true);

            BLLJIMP.Enums.ReviewTypeKey reviewType = BLLJIMP.Enums.ReviewTypeKey.ArticleComment;
            if (article.ArticleType == "Question")
            {
                reviewType = BLLJIMP.Enums.ReviewTypeKey.Answer;
            }
            var addResult = bllReview.AddReview(reviewType, articleId, replyId, this.currentUserInfo.UserID, "评论", content, this.bll.WebsiteOwner, out reviewId, isHideUserName);

            if (addResult)
            {
                if (reviewType == BLLJIMP.Enums.ReviewTypeKey.Answer)
                {
                    bllUser.AddUserScoreDetail(this.currentUserInfo.UserID, EnumStringHelper.ToString(ScoreDefineType.AnswerQuestions), this.bll.WebsiteOwner, null, null);
                }

                if (article.ArticleType == "Question")
                {
                    bllSystemNotice.SendNotice(BLLJIMP.BLLSystemNotice.NoticeType.QuestionIsAnswered, this.currentUserInfo, article, article.UserID, content);

                    List <UserInfo> users = bllUser.GetRelationUserList(BLLJIMP.Enums.CommRelationType.JuActivityFollow, articleId);
                    bllSystemNotice.SendNotice(BLLJIMP.BLLSystemNotice.NoticeType.FollowQuestionIsAnswered, this.currentUserInfo, article, users, content);
                }
                apiResp.status = true;
                apiResp.msg    = "评论完成";
                apiResp.result = reviewId.ToString();
                apiResp.code   = (int)BLLJIMP.Enums.APIErrCode.IsSuccess;
            }
            else
            {
                apiResp.code = (int)BLLJIMP.Enums.APIErrCode.OperateFail;
                apiResp.msg  = "评论出错";
            }
            bllReview.ContextResponse(context, apiResp);
        }