/// <summary>
        /// 获取实体信息
        /// </summary>
        /// <param name="shopId"></param>
        /// <param name="platformId"></param>
        /// <param name="businessType"></param>
        /// <param name="authType"></param>
        /// <returns></returns>
        public ShopPlatformEntity GetEntity(long shopId, int platformId, int businessType, AuthBussinessType authType)
        {
            var sql   = @"SELECT * FROM bll_shop_platform WHERE ShopId = @shopId AND PlatformId = @platformId AND BusinessType = @businessType AND AuthBussiness = @authType ";
            var parms = new List <DbParameter>();

            parms.Add(DbParameters.CreateDbParameter("shopId", shopId));
            parms.Add(DbParameters.CreateDbParameter("platformId", platformId));
            parms.Add(DbParameters.CreateDbParameter("businessType", businessType));
            parms.Add(DbParameters.CreateDbParameter("authType", authType.GetHashCode()));

            return(this.BaseRepository().FindList(sql, parms.ToArray()).FirstOrDefault());
        }
Example #2
0
 /// <summary>
 /// 执行门店授权数据同步
 /// </summary>
 /// <param name="shopId"></param>
 /// <param name="appAuthToken"></param>
 /// <param name="expiresIn"></param>
 /// <param name="refreshToken"></param>
 /// <param name="pType"></param>
 /// <param name="authType"></param>
 /// <param name="tryNum"></param>
 /// <returns></returns>
 private bool SyncShopPlatformData(string shopId, string appAuthToken, long expiresIn, string refreshToken, PlatformType pType, AuthBussinessType authType, int tryNum, string pShopId = "")
 {
     LogUtil.Info(string.Format("第{0}次尝试执行门店授权数据同步。", tryNum));
     return(SingleInstance <PlatformBLL> .Instance.SyncShopPlatformData(shopId, appAuthToken, expiresIn, refreshToken, pType, authType, BusinessType.Waimai, pShopId) > 0);
 }
Example #3
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);
        }
Example #4
0
 /// <summary>
 /// 解除门店平台映射
 /// </summary>
 /// <param name="shopId"></param>
 /// <param name="pType"></param>
 /// <param name="authType"></param>
 /// <returns></returns>
 public int SyncUnMapShopPlatformData(long shopId, PlatformType pType, AuthBussinessType authType)
 {
     LogUtil.Info(string.Format("开始同步解除门店授权平台数据", string.Empty));
     return(spServ.Delete(shopId, pType.GetHashCode(), authType.GetHashCode()));
 }
Example #5
0
 /// <summary>
 /// 获取门店平台授权信息
 /// </summary>
 /// <param name="shopId"></param>
 /// <param name="platformId"></param>
 /// <param name="businessType"></param>
 /// <param name="authType"></param>
 /// <returns></returns>
 public ShopPlatformEntity GetShopPlatformInfo(long shopId, int platformId, int businessType, AuthBussinessType authType)
 {
     return(spServ.GetEntity(shopId, platformId, businessType, authType));
 }