Exemple #1
0
        public static void WXLocation(HttpContext httpContext, CommonBLL commonService, RequestParams requestParams, string locationX, string locationY)
        {
            WMenuDAO wMenuDAO = new WMenuDAO(requestParams.LoggingSessionInfo);
            var      custId   = wMenuDAO.GetCustomerIdByWx(requestParams.WeixinId);

            if (requestParams.LoggingSessionInfo.CurrentUser == null)
            {
                requestParams.LoggingSessionInfo.CurrentUser = new Entity.User.UserInfo();
            }
            requestParams.LoggingSessionInfo.CurrentUser.customer_id = custId;

            BaseService.WriteLogWeixin("customerId:---------------" + custId);
            BaseService.WriteLogWeixin("openID:---------------" + requestParams.OpenId);
            BaseService.WriteLogWeixin("weixinID:---------------" + requestParams.WeixinId);

            string HandlerLocation_xyds = ConfigurationManager.AppSettings["HandlerLocation_xyds"];

            BaseService.WriteLogWeixin("HandlerLocation_xyds:---------------" + HandlerLocation_xyds);
            if (HandlerLocation_xyds != null && HandlerLocation_xyds.Length > 0 && HandlerLocation_xyds.Contains(requestParams.WeixinId))
            {
                BaseService.WriteLogWeixin("xyds:---------------");
                VipBLL server  = new VipBLL(requestParams.LoggingSessionInfo);
                var    vipInfo = server.SearchVipInfoLocation(new VipSearchEntity()
                {
                    RoleCode  = "CampusAmbassadors",
                    Longitude = locationY,
                    Latitude  = locationX,
                    OrderBy   = " a.Distance asc ",
                    Page      = 1,
                    PageSize  = 1,
                });

                if (vipInfo != null && vipInfo.vipInfoList != null && vipInfo.vipInfoList.Count > 0)
                {
                    var vip = vipInfo.vipInfoList[0];
                    if (vip != null)
                    {
                        var content = "";
                        content += "目前离你最近的校园产品专家是{0},电话:{1},{2},距离{3}米。如有任何疑问也可直接回复消息与我们联系,我们将尽快答复。";
                        content  = string.Format(
                            content,
                            vip.VipName,
                            vip.Phone,
                            vip.DeliveryAddress,
                            vip.Distance * 1000
                            );

                        BaseService.WriteLogWeixin("发送微信消息:---------------");
                        commonService.ResponseTextMessage(requestParams.WeixinId, requestParams.OpenId, content, httpContext, requestParams);
                        BaseService.WriteLogWeixin("发送微信消息完成:---------------");

                        MarketSendLogBLL marketSendLogBLL = new BLL.MarketSendLogBLL(requestParams.LoggingSessionInfo);
                        var logObj = new MarketSendLogEntity()
                        {
                            LogId           = Common.Utils.NewGuid(),
                            VipId           = vip.VIPID,
                            MarketEventId   = "华硕校园大使推介活动",
                            TemplateContent = content,
                            SendTypeId      = "1",
                            WeiXinUserId    = vip.WeiXinUserId,
                            Phone           = vip.Phone,
                            IsSuccess       = 0
                        };
                        marketSendLogBLL.Create(logObj);

                        VipVipMappingBLL vipVipMappingBLL = new VipVipMappingBLL(requestParams.LoggingSessionInfo);
                        var vipMapObj = new VipVipMappingEntity()
                        {
                            MappingId = Guid.NewGuid(),
                            VipIdSrc  = vip.VIPID,
                            VipIdDst  = requestParams.OpenId
                        };
                        vipVipMappingBLL.Create(vipMapObj);

                        logObj.IsSuccess = 1;
                        marketSendLogBLL.Update(logObj, false);
                    }
                }
            }
            else
            {
                string strError             = "";
                StoreBrandMappingBLL server = new StoreBrandMappingBLL(requestParams.LoggingSessionInfo);
                var storeInfo = server.GetStoreListByItem(null
                                                          , 1
                                                          , 10
                                                          , locationY
                                                          , locationX
                                                          , out strError);

                if (storeInfo != null && storeInfo.StoreBrandList != null && storeInfo.StoreBrandList.Count > 0)
                {
                    var newsList     = new List <WMaterialTextEntity>();
                    var original_url = ConfigurationManager.AppSettings["website_WWW"].ToString();
                    if (!original_url.EndsWith("/"))
                    {
                        original_url += "/";
                    }
                    foreach (var store in storeInfo.StoreBrandList)
                    {
                        var url = original_url + "HtmlApps/Auth.html?pageName=Map&customerId=" + requestParams.LoggingSessionInfo.CurrentUser.customer_id;
                        url += "&lng=" + store.Longitude + "&lat=" + store.Latitude;
                        url += "&storeId=" + store.StoreId;
                        url += "&addr=" + HttpUtility.UrlEncode(store.Address);
                        url += "&store=" + HttpUtility.UrlEncode(store.StoreName);

                        #region 分享业务 链接后面加上openId和userId

                        //if (url.IndexOf("ParAll=") != -1)
                        //{
                        //    var vipId = string.Empty;

                        //    VipBLL vipService = new VipBLL(requestParams.LoggingSessionInfo);
                        //    var vipEntity = vipService.QueryByEntity(new VipEntity { WeiXinUserId = requestParams.OpenId, WeiXin = requestParams.WeixinId }, null);
                        //    if (vipEntity != null && vipEntity.Length > 0)
                        //    {
                        //        vipId = vipEntity.FirstOrDefault().VIPID;
                        //    }

                        //    url += "&openId=" + requestParams.OpenId + "&userId=" + vipId;
                        //}

                        #endregion

                        newsList.Add(new WMaterialTextEntity()
                        {
                            Title         = store.StoreName + "(" + store.Distance.ToString("f1") + "公里)", // Title
                            Text          = store.StoreName + "(" + store.Distance.ToString("f1") + "公里)", // Author
                            CoverImageUrl = store.ImageUrl,                                                // CoverImageUrl
                            OriginalUrl   = url
                        });
                    }

                    commonService.ResponseNewsMessage(requestParams.WeixinId, requestParams.OpenId, newsList, httpContext, requestParams);
                }
            }
        }