/// <summary>
        /// 获取点击的商品详情
        /// </summary>
        /// <param name="favoritesId">选品库ID</param>
        /// <param name="numiid">商品ID</param>
        /// <param name="adzoneid"></param>
        /// <returns></returns>
        public UatmTbkItem GetFavoritItemsDetail(int favoritesId, long numiid)
        {
            var taoBaoClient = new TaoBaoClient();
            var uid          = Convert.ToInt64(TaoBaoConfig.UId);
            var result       = new UatmTbkItem();

            try
            {
                var req = new TbkUatmFavoritesItemGetRequest()
                {
                    AdzoneId    = uid,
                    FavoritesId = favoritesId,
                    Fields      = "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,click_url,seller_id,volume,nick,shop_title,zk_final_price_wap,event_start_time,event_end_time,tk_rate,status,type,coupon_info,commission_rate,coupon_click_url,coupon_end_time",
                    PageNo      = 1,
                    PageSize    = 20
                };
                var responseresult = taoBaoClient.GetFavoritesList(req);
                result = responseresult.Results.FirstOrDefault(x => x.NumIid == numiid);

                if (!string.IsNullOrEmpty(result?.CouponInfo))
                {
                    var coupon = result.CouponInfo.Split('减')[1]
                                 .Substring(0, result.CouponInfo.Split('减')[1].IndexOf("元", StringComparison.Ordinal));
                    result.CouponInfo = coupon;
                }
            }
            catch (Exception ex)
            {
                LogHelper.Exception(ex);
            }
            return(result);
        }
        /// <summary>
        /// 生成淘口令
        /// </summary>
        /// <param name="url">口令跳转目标页</param>
        /// <param name="text">口令弹框内容</param>
        /// <param name="logo"></param>
        /// <returns></returns>
        public TbkTpwdCreateResponse TpwdCreate(string url, string text, string logo)
        {
            var taoBaoClient = new TaoBaoClient();
            var result       = new TbkTpwdCreateResponse();

            if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(text))
            {
                LogHelper.Error("参数不能为空");
                return(null);
            }
            try
            {
                var req = new TbkTpwdCreateRequest()
                {
                    Url  = url,
                    Text = text,
                    Logo = logo
                };

                var responseresult = taoBaoClient.CreateTbkpwd(req);
                result = responseresult;
            }
            catch (Exception ex)
            {
                LogHelper.Exception(ex);
            }
            return(result);
        }
        //public ResponseDataList<UatmFavoritItems> GetItemsesList(long typeId, int pageSize = 10, int pageIndex = 1)
        //{
        //    var list = _favoritItemsDbDal.GetFavoritItemsesList(typeId, pageSize, pageIndex);
        //    return list;
        //}


        ///// <summary>
        ///// 把淘宝客商品信息数据保存到本地数据库
        ///// </summary>
        ///// <param name="info"></param>
        ///// <returns></returns>
        //public bool AddFavoritesDetail(List<TbkFavoritesDetail> info)
        //{
        //    var dataList = new List<UatmFavoritItems>();
        //    foreach (var temp in info)
        //    {
        //        //小图转换成字符串用,隔开
        //        var strSmallImages = string.Join(",", temp.SmallImages.ToArray());
        //        var cendTime = Convert.ToDateTime(temp.CouponEndTime);
        //        var cStartTime = Convert.ToDateTime(temp.CouponStartTime);

        //        var data = new UatmFavoritItems
        //        {
        //            num_iid = temp.NumIid,
        //            title = temp.Title,
        //            pic_url = temp.PictUrl,
        //            small_images = strSmallImages,
        //            reserve_price = Convert.ToDouble(temp.ReservePrice),
        //            zk_final_price = Convert.ToDouble(temp.ZkFinalPrice),
        //            provcity = temp.Provcity,
        //            item_url = temp.ItemUrl,
        //            click_url = temp.ClickUrl,
        //            nick = temp.Nick,
        //            seller_id = temp.SellerId,
        //            volume = temp.Volume,
        //            tk_rate = Convert.ToDouble(temp.TkRate),
        //            zk_final_price_wap = Convert.ToDouble(temp.ZkFinalPriceWap),
        //            category = temp.Category,
        //            coupon_click_url = temp.CouponClickUrl,
        //            coupon_end_time = cendTime,
        //            coupon_info = temp.CouponInfo,
        //            coupon_start_time = cStartTime,
        //            coupon_total_count = temp.CouponTotalCount,
        //            coupon_remain_count = temp.CouponRemainCount,
        //            commission_rate = temp.CommissionRate,
        //            event_end_time = temp.EventEndTime,
        //            event_start_time = temp.EventStartTime,
        //            shop_title = temp.ShopTitle,
        //            status = temp.Status,
        //            type = temp.Type

        //        };
        //        dataList.Add(data);

        //    }
        //    var isSuccess = _favoritItemsDbDal.AddTbItemsList(dataList);
        //    return isSuccess;
        //}

        ///// <summary>
        ///// 添加选品库信息到本地数据库
        ///// </summary>
        ///// <param name="info"></param>
        ///// <returns></returns>
        //public bool AddTbItemsList(List<TbkFavorites> info)
        //{
        //    var datalist = new List<TBItemsList>();
        //    foreach (var temp in info)
        //    {
        //        //var data = new TBItemsList
        //        //{
        //        //    type = temp.Type,
        //        //    favorites_id = temp.FavoritesId,
        //        //    favorites_title = temp.FavoritesTitle
        //        //};
        //        //datalist.Add(data);
        //    }
        //    var isSuccess = _favoritItemsDbDal.AddTbItemsList(datalist);
        //    return isSuccess;
        //}
        #endregion
        /// <summary>
        /// 淘宝联盟后台获取分类信息
        /// </summary>
        /// <returns></returns>
        public ResponseDataList <TbkFavorites> GetTaoBaoFavorites()
        {
            var          responseresult    = new TbkUatmFavoritesGetResponse();
            var          result            = new ResponseDataList <TbkFavorites>();
            TaoBaoClient taoBaoClient      = new TaoBaoClient();
            TbkUatmFavoritesGetRequest req = new TbkUatmFavoritesGetRequest
            {
                PageNo   = 1L,
                PageSize = 50L,
                Fields   = "favorites_title,favorites_id,type",
                Type     = 1L
            };

            try
            {
                responseresult = taoBaoClient.GetTaoBaoFavorites(req);
                if (responseresult.IsError)
                {
                    LogHelper.Error(responseresult.ErrMsg);
                    return(null);
                }
                result.Count    = responseresult.TotalResults;
                result.DataList = responseresult.Results;
                //开一个线程插入数据库
                //System.Threading.Tasks.Task.Run(() => AddTabItems(responseresult));
            }
            catch (Exception ex)
            {
                LogHelper.Exception(ex);
            }
            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// 创建广告位id
        /// </summary>
        /// <returns></returns>
        public TbkAdzoneCreateResponse CreatePid()
        {
            var taoBaoClient = new TaoBaoClient();
            var result       = new TbkAdzoneCreateResponse();
            var siteid       = Convert.ToInt64(TaoBaoConfig.TaoBaoSiteId);
            var name         = TaoBaoConfig.AdzoneName;

            try
            {
                var req = new TbkAdzoneCreateRequest()
                {
                    AdzoneName = name,
                    SiteId     = siteid
                };
                var responseresult = taoBaoClient.CreatePid(req);
                //pid只取最后一段信息
                string[] arr = responseresult.Data.Model.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);//按照‘-分割并去除空
                responseresult.Data.Model = arr[3];
                result = responseresult;
            }
            catch (Exception ex)
            {
                LogHelper.Exception(ex);
            }
            return(result);
        }
        public void Execute(IJobExecutionContext context)
        {
            log.log("开始执行Job任务" + "----" + DateTime.Now.ToString(CultureInfo.InvariantCulture));
            log.log("获取淘宝联盟后台分类id" + "----" + DateTime.Now.ToString(CultureInfo.InvariantCulture));
            TaoBaoClient taoBaoClient      = new TaoBaoClient();
            TbkUatmFavoritesGetRequest req = new TbkUatmFavoritesGetRequest
            {
                PageNo   = 1L,
                PageSize = 50L,
                Fields   = "favorites_title,favorites_id,type",
                Type     = 1L
            };
            var responseresulttap = taoBaoClient.GetTaoBaoFavorites(req);

            _favoritItemsSrv.AddTabItems(responseresulttap);


            foreach (var data in responseresulttap.Results)
            {
                log.log("循环淘宝联盟后台分类id" + "----" + data.FavoritesId);
                //var result = _favoritItemsSrv.GetTaoBaoFavoritesItemsListAsync(data.FavoritesId);

                TbkUatmFavoritesItemGetResponse responseresult;
                var result = new ResponseDataList <UatmTbkItem>();
                var uid    = Convert.ToInt64(TaoBaoConfig.UId);

                TbkUatmFavoritesItemGetRequest req2 = new TbkUatmFavoritesItemGetRequest()
                {
                    AdzoneId    = uid,
                    FavoritesId = data.FavoritesId,
                    Fields      = "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,click_url,seller_id,volume,nick,shop_title,zk_final_price_wap,event_start_time,event_end_time,tk_rate,status,type,coupon_info,commission_rate,coupon_click_url,coupon_end_time",
                    PageNo      = 1,
                    PageSize    = 500
                };
                responseresult         = taoBaoClient.GetFavoritesList(req2);
                responseresult.Results = responseresult.Results.Where(x => x.CouponInfo != null).ToList();

                //查找每一个商品到券信息
                foreach (var tamp in responseresult.Results)
                {
                    //var coupon = GetCouponInfo(data.NumIid);
                    var coupon = tamp.CouponInfo.Split('减')[1].Substring(0, tamp.CouponInfo.Split('减')[1].IndexOf("元", StringComparison.Ordinal));
                    var index  = responseresult.Results.IndexOf(tamp);
                    if (!string.IsNullOrEmpty(coupon) && Convert.ToDouble(tamp.ZkFinalPrice) > Convert.ToDouble(coupon))
                    {
                        responseresult.Results[index].CouponInfo = coupon;
                    }
                    else
                    {
                        responseresult.Results[index].CouponInfo = "0";
                    }
                    log.log("插入数据库的物品id" + "----" + tamp.NumIid);
                }
                _favoritItemsSrv.AddItems(responseresult, data.FavoritesId);

                log.log("插入数据库的列表id" + "----" + data.FavoritesId);
            }
        }
Beispiel #6
0
        public ActionResult ThirdPartyTBLogin()
        {
            //初始化开放平台客户端(请替换成自己的ClientId,ClientScrert,CallbackUrl)
            m_oauthClients           = new Dictionary <string, IOAuthClient>();
            m_oauthClients["taobao"] = new TaoBaoClient("You ClientId", "You ClientScrert", "You Callback Url");
            //OAuthTest("taobao");

            return(null);
        }
        /// <summary>
        /// 获取商品列表
        /// </summary>
        /// <param name="favoritesId">选品库ID</param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public ResponseDataList <UatmTbkItem> GetTaoBaoFavoritesItemsListAsync(long favoritesId, int pageSize = 10, int pageIndex = 1)
        {
            TaoBaoClient taoBaoClient = new TaoBaoClient();
            TbkUatmFavoritesItemGetResponse responseresult;
            var result = new ResponseDataList <UatmTbkItem>();
            var uid    = Convert.ToInt64(TaoBaoConfig.UId);

            TbkUatmFavoritesItemGetRequest req = new TbkUatmFavoritesItemGetRequest()
            {
                AdzoneId    = uid,
                FavoritesId = favoritesId,
                Fields      = "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,click_url,seller_id,volume,nick,shop_title,zk_final_price_wap,event_start_time,event_end_time,tk_rate,status,type,coupon_info,commission_rate,coupon_click_url,coupon_end_time",
                PageNo      = pageIndex,
                PageSize    = pageSize
            };

            try
            {
                responseresult = taoBaoClient.GetFavoritesList(req);
                if (responseresult.IsError)
                {
                    LogHelper.Error(responseresult.ErrMsg);
                    return(null);
                }
                else
                {
                    //查找每一个商品到券信息
                    foreach (var data in responseresult.Results.Where(x => x.CouponInfo != null))
                    {
                        //var coupon = GetCouponInfo(data.NumIid);
                        var coupon = data.CouponInfo.Split('减')[1].Substring(0, data.CouponInfo.Split('减')[1].IndexOf("元", StringComparison.Ordinal));
                        var index  = responseresult.Results.IndexOf(data);
                        if (!string.IsNullOrEmpty(coupon) && Convert.ToDouble(data.ZkFinalPrice) > Convert.ToDouble(coupon))
                        {
                            responseresult.Results[index].CouponInfo = coupon;
                        }
                        else
                        {
                            responseresult.Results[index].CouponInfo = "0";
                        }
                    }
                }
                result.DataList = responseresult.Results.Where(x => x.CouponInfo != null).ToList();
                result.Count    = result.DataList.Count;

                //开一个线程插入数据库
                System.Threading.Tasks.Task.Run(() => AddItems(responseresult, favoritesId));
            }
            catch (Exception ex)
            {
                LogHelper.Exception(ex);
            }
            return(result);
        }
        /// <summary>
        /// 获取优惠券信息
        /// </summary>
        /// <param name="itemId"></param>
        /// <returns></returns>
        public TbkCouponGetResponse GetCouponInfo(long itemId)
        {
            var taoBaoClient = new TaoBaoClient();
            var result       = new TbkCouponGetResponse();

            try
            {
                var req = new TbkCouponGetRequest
                {
                    ItemId = itemId
                };
                result = taoBaoClient.GetCouponInfo(req);
            }
            catch (Exception ex)
            {
                LogHelper.Exception(ex);
            }
            return(result);
        }
        /// <summary>
        /// 获取商铺信息
        /// </summary>
        /// <param name="shopTitle"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public NTbkShop GetShopInfo(string shopTitle, long userId)
        {
            var taoBaoClient = new TaoBaoClient();
            var result       = new NTbkShop();

            try
            {
                var req = new TbkShopGetRequest
                {
                    Fields = "user_id,shop_title,shop_type,seller_nick,pict_url,shop_url",
                    Q      = shopTitle
                };

                var responseresult = taoBaoClient.GetShopInfo(req);

                result = responseresult.Results.FirstOrDefault(x => x.UserId == userId);
            }
            catch (Exception ex)
            {
                LogHelper.Exception(ex);
            }
            return(result);
        }