Beispiel #1
0
        /// <summary>
        /// 获取饿了么门店令牌
        /// </summary>
        /// <param name="shopAuth">门店饿了么平台授权信息</param>
        /// <returns></returns>
        public string GetEleShopAccessToken(ShopPlatformEntity shopAuth)
        {
            var token = string.Empty;

            if (shopAuth != null && !string.IsNullOrWhiteSpace(shopAuth.AuthToken))
            {
                token = shopAuth.AuthToken;
                LogUtil.Info(string.Format("token有效期:{0},当前时间:{1}", shopAuth.ModifyDate.Value.AddSeconds(shopAuth.ExpiresIn), TimeUtil.Now));
                if (shopAuth.ModifyDate.Value.AddSeconds(shopAuth.ExpiresIn) < TimeUtil.Now)
                {
                    var rToken = eleServ.GetAccessTokenByRefreshToken(shopAuth.RefreshToken);
                    token = rToken != null ? rToken.access_token : string.Empty;
                    var refreshToken = rToken != null ? rToken.refresh_token : string.Empty;
                    var platformName = PlatformType.Eleme.GetRemark();
                    LogUtil.Info(string.Format("{0}门店:{1}, accessToken:{2}已过期,通过refreshToken获取新accessToken:{3},RefreshToken:{4}", platformName, shopAuth.ShopId, shopAuth.AuthToken, token, refreshToken));

                    //更新token到DB
                    shopAuth.AuthToken         = token;
                    shopAuth.ExpiresIn         = rToken.expires_in;
                    shopAuth.RefreshToken      = refreshToken;
                    shopAuth.RefreshExpireTime = TimeUtil.Now.AddDays(ConfigUtil.EleReTokenExpiresDays);
                    shopAuth.ModifyDate        = TimeUtil.Now;
                    SingleInstance <PlatformBLL> .Instance.UpdateEntity(shopAuth);
                }
            }
            return(token);
        }
Beispiel #2
0
 /// <summary>
 /// 门店百度平台映射申请
 /// </summary>
 /// <param name="shopId">微云打门店ID</param>
 /// <param name="pShopId">百度平台门店ID</param>
 /// <returns></returns>
 public bool MapBaiduShopAuth(long shopId, string pShopId)
 {
     try
     {
         var platformId   = PlatformType.Baidu.GetHashCode();
         var businessType = BusinessType.Waimai;
         var pList        = FindShopPlatformList(businessType);
         var isExists     = pList.Exists(t => t.PlatformId == platformId && t.PlatformShopId == pShopId && t.ShopId != shopId);
         if (!isExists)
         {
             var dbNow        = TimeUtil.Now;
             var platformName = PlatformType.Baidu.GetRemark();
             var authType     = AuthBussinessType.Waimai;
             var authPlatform = GetShopPlatformInfo(shopId, platformId, businessType.GetHashCode(), authType);
             if (authPlatform != null)
             {
                 //更新映射
                 authPlatform.PlatformShopId = pShopId;
                 authPlatform.PlatformId     = platformId;
                 authPlatform.PlatformName   = platformName;
                 authPlatform.BusinessType   = businessType.GetHashCode();
                 authPlatform.AuthBussiness  = authType.GetHashCode();
                 authPlatform.ModifyUserId   = shopId.ToString();
                 authPlatform.ModifyDate     = dbNow;
                 return(spServ.UpdateEntity(authPlatform) > 0);
             }
             else
             {
                 //新增映射
                 authPlatform                  = new ShopPlatformEntity();
                 authPlatform.ShopId           = shopId;
                 authPlatform.PlatformShopId   = pShopId;
                 authPlatform.PlatformId       = platformId;
                 authPlatform.PlatformName     = platformName;
                 authPlatform.BusinessType     = businessType.GetHashCode();
                 authPlatform.AuthBussiness    = authType.GetHashCode();
                 authPlatform.AuthToken        = string.Empty;
                 authPlatform.ExpiresIn        = 0;
                 authPlatform.PlatformShopName = string.Empty;
                 authPlatform.Mobile           = string.Empty;
                 authPlatform.EnabledFlag      = EnabledFlagType.Valid.GetHashCode();
                 authPlatform.DeleteFlag       = DeleteFlagType.Valid.GetHashCode();
                 authPlatform.CreateUserId     = shopId.ToString();
                 authPlatform.CreateDate       = dbNow;
                 return(spServ.InsertEntity(authPlatform) > 0);
             }
         }
         else
         {
             var msg = string.Format("百度门店ID:【{0}】已授权,请核对!", pShopId);
             LogUtil.Error(msg);
             throw new BusinessException(msg);
         }
     }
     catch (Exception ex)
     {
         var msg = string.Format("授权申请失败,{0}", ex.Message);
         LogUtil.Error(msg);
         throw new BusinessException(msg);
     }
 }
Beispiel #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public int InserEntity(ShopPlatformEntity entity)
 {
     return(spServ.InsertEntity(entity));
 }
Beispiel #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public int UpdateEntity(ShopPlatformEntity entity)
 {
     return(spServ.UpdateEntity(entity));
 }
Beispiel #5
0
        /// <summary>
        /// 同步门店平台数据
        /// </summary>
        /// <param name="shopId"></param>
        /// <param name="appAuthToken"></param>
        /// <param name="expiresIn"></param>
        /// <param name="refreshToken"></param>
        /// <param name="paltformType"></param>
        /// <param name="authType"></param>
        /// <param name="businessType"></param>
        /// <returns></returns>
        public int SyncShopPlatformData(string shopId, string appAuthToken, long expiresIn, string refreshToken, PlatformType paltformType, AuthBussinessType authType, BusinessType businessType, string pShopId = "", string source = "", string secret = "", string remark = "")
        {
            //同步平台数据
            LogUtil.Info(string.Format("开始同步门店授权【{0}】平台数据", paltformType.GetRemark()));
            var cnt        = 0;
            var platformId = paltformType.GetHashCode();
            var shop       = GetPlatformShopModel(platformId, appAuthToken, shopId, pShopId, source, secret);
            var db         = new RepositoryFactory().BaseRepository().BeginTrans();

            try
            {
                var dbNow        = TimeUtil.Now;
                var authPlatform = GetShopPlatformInfo(shopId.ToInt(), platformId, businessType.GetHashCode(), authType);
                if (authPlatform != null)
                {
                    authPlatform.AuthToken     = appAuthToken;
                    authPlatform.ExpiresIn     = expiresIn;
                    authPlatform.IsAutoConfirm = 1;

                    if (paltformType == PlatformType.Meituan)
                    {
                        //美团外卖
                        authPlatform.PlatformShopName = shop != null ? shop.name : string.Empty;
                        authPlatform.Mobile           = shop != null ? shop.phone : string.Empty;
                        authPlatform.ShopAddress      = shop != null ? shop.address : string.Empty;
                        authPlatform.BusinessScope    = shop != null ? shop.tagName : string.Empty;
                        authPlatform.Latitude         = shop != null ? shop.latitude : string.Empty;
                        authPlatform.Longitude        = shop != null ? shop.longitude : string.Empty;
                        authPlatform.PictureUrl       = shop != null ? shop.pictureUrl : string.Empty;
                        authPlatform.OpenTime         = shop != null ? shop.openTime : string.Empty;
                        authPlatform.ShippingFee      = shop != null ? shop.shippingFee : 0.00f;
                        authPlatform.PreBook          = shop != null ? shop.preBook : 0;
                        authPlatform.TimeSelect       = shop != null ? shop.timeSelect : 0;
                    }
                    else if (paltformType == PlatformType.Eleme)
                    {
                        //饿了么
                        if (shop != null && shop.error != null)
                        {
                            LogUtil.Error(shop.error.ToString());
                        }
                        var eShop = Yme.Util.JsonUtil.ToObject <Dictionary <string, object> >((shop != null && shop.result != null) ? shop.result.ToString() : string.Empty);
                        authPlatform.PlatformShopName  = (eShop != null && eShop["name"] != null) ? eShop["name"].ToString() : string.Empty;
                        authPlatform.PlatformShopId    = (eShop != null && eShop["id"] != null) ? eShop["id"].ToString() : string.Empty;
                        authPlatform.Mobile            = (eShop != null && eShop["mobile"] != null) ? eShop["mobile"].ToString() : string.Empty;
                        authPlatform.ShopAddress       = (eShop != null && eShop["addressText"] != null) ? eShop["addressText"].ToString() : string.Empty;
                        authPlatform.Latitude          = (eShop != null && eShop["latitude"] != null) ? eShop["latitude"].ToString() : string.Empty;
                        authPlatform.Longitude         = (eShop != null && eShop["longitude"] != null) ? eShop["longitude"].ToString() : string.Empty;
                        authPlatform.PictureUrl        = (eShop != null && eShop["imageUrl"] != null) ? eShop["imageUrl"].ToString() : string.Empty;
                        authPlatform.OpenTime          = (eShop != null && eShop["servingTime"] != null) ? eShop["servingTime"].ToString() : string.Empty;
                        authPlatform.RefreshToken      = refreshToken;
                        authPlatform.RefreshExpireTime = TimeUtil.Now.AddDays(ConfigUtil.EleReTokenExpiresDays);
                    }
                    else if (paltformType == PlatformType.Baidu)
                    {
                        //百度外卖
                        if (shop != null && shop.error != null)
                        {
                            LogUtil.Error(shop.error.ToString());
                        }
                        var category = string.Empty;
                        var bShop    = Yme.Util.JsonUtil.ToObject <Dictionary <string, object> >((shop != null && shop.data != null) ? shop.data.ToString() : string.Empty);
                        if (bShop != null)
                        {
                            if (!string.IsNullOrWhiteSpace(bShop["category1"]))
                            {
                                category = bShop["category1"].ToString();
                            }
                            if (!string.IsNullOrWhiteSpace(bShop["category2"]))
                            {
                                category += string.Format("-{0}", bShop["category2"].ToString());
                            }
                            if (!string.IsNullOrWhiteSpace(bShop["category3"]))
                            {
                                category += string.Format("-{0}", bShop["category3"].ToString());
                            }
                        }
                        authPlatform.PlatformShopName = (bShop != null && bShop["name"] != null) ? bShop["name"].ToString() : string.Empty;
                        authPlatform.PlatformShopId   = (bShop != null && bShop["baidu_shop_id"] != null) ? bShop["baidu_shop_id"].ToString() : string.Empty;
                        authPlatform.Mobile           = (bShop != null && bShop["service_phone"] != null) ? bShop["service_phone"].ToString() : string.Empty;
                        authPlatform.ShopAddress      = (bShop != null && bShop["address"] != null) ? bShop["address"].ToString() : string.Empty;
                        authPlatform.BusinessScope    = category;
                        authPlatform.Latitude         = (bShop != null && bShop["latitude"] != null) ? bShop["latitude"].ToString() : string.Empty;
                        authPlatform.Longitude        = (bShop != null && bShop["longitude"] != null) ? bShop["longitude"].ToString() : string.Empty;
                        authPlatform.PictureUrl       = (bShop != null && bShop["shop_logo"] != null) ? bShop["shop_logo"].ToString() : string.Empty;
                        authPlatform.OpenTime         = (bShop != null && bShop["business_time"] != null) ? bShop["business_time"].ToString() : string.Empty;
                        authPlatform.RefreshToken     = refreshToken;
                        authPlatform.Description      = remark;
                    }

                    authPlatform.ModifyUserId = paltformType.GetRemark();
                    authPlatform.ModifyDate   = dbNow;
                    db.Update(authPlatform);
                }
                else
                {
                    authPlatform               = new ShopPlatformEntity();
                    authPlatform.ShopId        = shopId.ToInt();
                    authPlatform.PlatformId    = platformId;
                    authPlatform.PlatformName  = paltformType.GetRemark();
                    authPlatform.BusinessType  = businessType.GetHashCode();
                    authPlatform.AuthBussiness = authType.GetHashCode();
                    authPlatform.AuthToken     = appAuthToken;
                    authPlatform.ExpiresIn     = expiresIn;
                    authPlatform.IsAutoConfirm = 1;

                    if (paltformType == PlatformType.Meituan)
                    {
                        //美团外卖
                        authPlatform.PlatformShopName = shop != null ? shop.name : string.Empty;
                        authPlatform.Mobile           = shop != null ? shop.phone : string.Empty;
                        authPlatform.ShopAddress      = shop != null ? shop.address : string.Empty;
                        authPlatform.BusinessScope    = shop != null ? shop.tagName : string.Empty;
                        authPlatform.Latitude         = shop != null ? shop.latitude : string.Empty;
                        authPlatform.Longitude        = shop != null ? shop.longitude : string.Empty;
                        authPlatform.PictureUrl       = shop != null ? shop.pictureUrl : string.Empty;
                        authPlatform.OpenTime         = shop != null ? shop.openTime : string.Empty;
                        authPlatform.ShippingFee      = shop != null ? shop.shippingFee : 0.00f;
                        authPlatform.PreBook          = shop != null ? shop.preBook : 0;
                        authPlatform.TimeSelect       = shop != null ? shop.timeSelect : 0;
                    }
                    else if (paltformType == PlatformType.Eleme)
                    {
                        //饿了么
                        if (shop != null && shop.error != null)
                        {
                            LogUtil.Error(shop.error.ToString());
                        }
                        var eShop = Yme.Util.JsonUtil.ToObject <Dictionary <string, object> >((shop != null && shop.result != null) ? shop.result.ToString() : string.Empty);
                        authPlatform.PlatformShopName  = (eShop != null && eShop["name"] != null) ? eShop["name"].ToString() : string.Empty;
                        authPlatform.PlatformShopId    = (eShop != null && eShop["id"] != null) ? eShop["id"].ToString() : appAuthToken;
                        authPlatform.Mobile            = (eShop != null && eShop["mobile"] != null) ? eShop["mobile"].ToString() : string.Empty;
                        authPlatform.ShopAddress       = (eShop != null && eShop["addressText"] != null) ? eShop["addressText"].ToString() : string.Empty;
                        authPlatform.Latitude          = (eShop != null && eShop["latitude"] != null) ? eShop["latitude"].ToString() : string.Empty;
                        authPlatform.Longitude         = (eShop != null && eShop["longitude"] != null) ? eShop["longitude"].ToString() : string.Empty;
                        authPlatform.PictureUrl        = (eShop != null && eShop["imageUrl"] != null) ? eShop["imageUrl"].ToString() : string.Empty;
                        authPlatform.OpenTime          = (eShop != null && eShop["servingTime"] != null) ? eShop["servingTime"].ToString() : string.Empty;
                        authPlatform.RefreshToken      = refreshToken;
                        authPlatform.RefreshExpireTime = TimeUtil.Now.AddDays(ConfigUtil.EleReTokenExpiresDays);
                        authPlatform.ModifyDate        = dbNow;
                    }
                    else if (paltformType == PlatformType.Baidu)
                    {
                        //百度外卖
                        if (shop != null && shop.errno != 0)
                        {
                            LogUtil.Error(shop.error.ToString());
                        }
                        var category = string.Empty;
                        var bShop    = Yme.Util.JsonUtil.ToObject <Dictionary <string, object> >((shop != null && shop.data != null) ? shop.data.ToString() : string.Empty);
                        if (bShop != null)
                        {
                            if (!string.IsNullOrWhiteSpace(bShop["category1"]))
                            {
                                category = bShop["category1"].ToString();
                            }
                            if (!string.IsNullOrWhiteSpace(bShop["category2"]))
                            {
                                category += string.Format("-{0}", bShop["category2"].ToString());
                            }
                            if (!string.IsNullOrWhiteSpace(bShop["category3"]))
                            {
                                category += string.Format("-{0}", bShop["category3"].ToString());
                            }
                        }
                        authPlatform.PlatformShopName = (bShop != null && bShop["name"] != null) ? bShop["name"].ToString() : string.Empty;
                        authPlatform.PlatformShopId   = (bShop != null && bShop["baidu_shop_id"] != null) ? bShop["baidu_shop_id"].ToString() : string.Empty;
                        authPlatform.Mobile           = (bShop != null && bShop["service_phone"] != null) ? bShop["service_phone"].ToString() : string.Empty;
                        authPlatform.ShopAddress      = (bShop != null && bShop["address"] != null) ? bShop["address"].ToString() : string.Empty;
                        authPlatform.BusinessScope    = category;
                        authPlatform.Latitude         = (bShop != null && bShop["latitude"] != null) ? bShop["latitude"].ToString() : string.Empty;
                        authPlatform.Longitude        = (bShop != null && bShop["longitude"] != null) ? bShop["longitude"].ToString() : string.Empty;
                        authPlatform.PictureUrl       = (bShop != null && bShop["shop_logo"] != null) ? bShop["shop_logo"].ToString() : string.Empty;
                        authPlatform.OpenTime         = (bShop != null && bShop["business_time"] != null) ? bShop["business_time"].ToString() : string.Empty;
                        authPlatform.RefreshToken     = refreshToken;
                        authPlatform.Description      = remark;
                    }

                    authPlatform.EnabledFlag  = EnabledFlagType.Valid.GetHashCode();
                    authPlatform.DeleteFlag   = DeleteFlagType.Valid.GetHashCode();
                    authPlatform.CreateUserId = paltformType.GetRemark();
                    authPlatform.CreateDate   = dbNow;
                    db.Insert(authPlatform);
                }

                //同步门店数据
                var platformList = GetShopPlatformList(shopId.ToInt(), businessType);
                if (platformList != null && platformList.Count > 0)
                {
                    var isFirstAuth = platformList.Count(d => d.AuthStasus == 1) == 0;
                    if (isFirstAuth)
                    {
                        var shopEntity = SingleInstance <ShopBLL> .Instance.GetShopById(shopId.ToInt());

                        if (shopEntity != null)
                        {
                            shopEntity.ShopName      = authPlatform.PlatformShopName;
                            shopEntity.ShopAddress   = authPlatform.ShopAddress;
                            shopEntity.BusinessScope = authPlatform.BusinessScope;
                            shopEntity.ModifyUserId  = paltformType.GetRemark();
                            shopEntity.ModifyDate    = dbNow;
                            db.Update(shopEntity);
                        }
                    }
                }

                db.Commit();
                cnt = 1;
            }
            catch (Exception ex)
            {
                db.Rollback();
                var msg = string.Format("同步门店平台数据失败,参考消息:{0}", ex.Message);
                LogUtil.Error(msg);
                throw new BusinessException(msg);
            }
            return(cnt);
        }