Example #1
0
        private static void Init()
        {
            if (_yunClient == null || _appInfo == null)
            {
                lock (initLock)
                {
                    if (_yunClient != null && _appInfo != null) return;

                    if (_appInfo == null)
                    {
                        var init = new Yun.ClientCache.CacheFunc();
                        _appInfo = init.Fetch<AppModel>(_appTableName, "id = 0");
                        if (_appInfo == null)
                        {
                            throw new Exception("授权信息未设置,无法进行网站初始化");
                        }
                    }

                    if (_yunClient == null)
                    {
                        var apiUrl = WebConfigurationManager.AppSettings["ServerUrl"];
                        if (new[] { _appInfo.AppKey, _appInfo.AppSecret, apiUrl }.Any(string.IsNullOrWhiteSpace))
                        {
                            throw new Exception("服务端必要数据未初始化");
                        }

                        _yunClient = new DefaultYunClient(apiUrl, _appInfo.AppKey, _appInfo.AppSecret);
                    }
                }
            }
        }
Example #2
0
        public static void RemoveConfig()
        {
            var init = new Yun.ClientCache.CacheFunc();
            init.DropTable(_appTableName);

            _appInfo = null;
            _yunClient = null;
        }
Example #3
0
        /// <summary>
        /// 保存城购云配置信息
        /// </summary>
        /// <param name="key">客户KEY</param>
        /// <param name="secret">客户密钥</param>
        /// <returns></returns>
        public static void SaveConfig(string key, string secret)
        {
            //先更新内存中数据
            _appInfo = new AppModel { AppKey = key, AppSecret = secret};
            _yunClient = null;

            //将数据写入缓存中
            var init = new Yun.ClientCache.CacheFunc();
            init.DropTable(_appTableName);
            init.Insert(_appTableName, "id", _appInfo, null);
        }
 /// <summary>
 /// 获取所有分类
 /// </summary>
 /// <param name="dispaly"></param>
 /// <param name="parentId"></param>
 /// <returns></returns>
 public static List<ArticleCategory> GetCategorys(bool? dispaly, int? parentId)
 {
     var sql = "";
     if (dispaly != null)
     {
         sql += "display = " + ((bool)dispaly ? "'True'" : "'False'");
     }
     if (parentId != null && parentId >= 0)
     {
         sql += " " + (sql != "" ? "AND " : "") + "parentid = " + (int)parentId;
     }
     sql += " ORDER BY Sort DESC,id DESC";
     var ss = new Yun.ClientCache.CacheFunc().FetchAll<ArticleCategory>(_termCacheName, sql);
     return ss;
 }
Example #5
0
        /// <summary>
        /// 获取文章
        /// </summary>
        /// <param name="p"></param>
        /// <param name="pagesize"></param>
        /// <param name="title"></param>
        /// <param name="categoryId"></param>
        /// <param name="tagId"></param>
        /// <returns></returns>
        public static PageModel<ArticleDetail> GetArticles(int p, int pagesize, string title = null,
            int categoryId = 0, int tagId = 0)
        {
            var init = new Yun.ClientCache.CacheFunc();
            List<ArchiveInSql> data = null;
            long totalItem = 0;

            if (title.IsNotNullOrEmpty())
            {
                var r = YunClient.Instance.Execute(new GetArchivesRequest
                {
                    Title = title,
                    TaxonomyId = categoryId,
                    Fields = "id",
                    PageNum = p,
                    Sort = "sort",
                    PageSize = pagesize,
                    Status = "publish",
                });

                data = init.FetchAll<ArchiveInSql>(_cacheName,
                    _cacheName + ".id IN (" + string.Join(",", r.Articles.Select(e => e.Id)) + ")");

                totalItem = data.Count;
            }
            else
            {
                //不需要搜索文章标题的方法
                var sql = init.GenerateWhereSql(new List<WhereSql>
                {
                    new WhereSql("TaxonomyId", categoryId, true),
                    new WhereSql("TaxonomyId", tagId, true),
                });

                sql += " ORDER BY sort DESC, "+_cacheName+".id DESC";

                data = init.FetchAll<ArchiveInSql>(p, pagesize, _cacheName, sql, out totalItem);
            }

            return new PageModel<ArticleDetail>
            {
                CurrentPage = p,
                Items = data.ConvertAll(ArchiveInSql.ConvertArticleDetail),
                ItemsPerPage = pagesize,
                TotalItems = totalItem,
            };
        }
Example #6
0
        /// <summary>
        /// 获取系统信息
        /// </summary>
        private static void GetWebSettingRequest()
        {
            if (_webInfo != null) return;

            var init = new Yun.ClientCache.CacheFunc();
            var setting = init.Fetch<Settoins>("app", "id = 1");

            if (setting != null)
            {
                _webInfo = setting.Settoin.ConvertAll(x => new StringKeyValuePair { Key = x.Key, Value = x.Value });
               return;
                
            }
            var r = YunClient.Instance.Execute(new GetWebSettingRequest(), Extension.Member.Token).Settings;

            if (r == null || r.Count <= 0) return;
            init.Insert("app", "id", new Settoins {id = 1, Settoin = r}, null);
            _webInfo = r.ConvertAll(x => new StringKeyValuePair {Key = x.Key, Value = x.Value});
        }
Example #7
0
        public void WriteAllCache()
        {
            lock (writeLock)
            {
                if (writeRuning) return;

                writeRuning = true;
                //开单独的线程进行处理
                //Task.Factory.StartNew(() =>
                //{
                    var init = new Yun.ClientCache.CacheFunc();
                    init.DropTable(_cacheName);

                    var archives = new List<GoodsDetail>();
                    int i = 1;
                    while (true)
                    {
                        var d = YunClient.Instance.Execute(new GetItemsRequest { PageNum = i, PageSize = 40, NeedPromotion = true, IsDelete = 0, ItemState = 1, }).Items;
                        if (d != null && d.Any())
                        {
                            i++;
                            foreach (var tt in d)
                            {
                                if (archives.All(e => tt.Id != e.Id))
                                {
                                    archives.Add(tt);
                                }
                                else
                                {
                                    throw new Exception();
                                }

                            }
                            
                            continue;
                        }

                        break;
                    }

                    var addItems = archives.ConvertAll(GoodsDetailInSql.ConvertGoodsInSql);
                    if (addItems.Any())
                    {
                        init.BulkInsert(_cacheName, "Id", addItems,
                            new[]
                            {
                                "CategoryId", "AreaId", "IsRecommend", "ItemTitle", "MarketPrice", "OffShelfTime","OnShelfTime", "Partners", "Price", "Sales", "SaleType", "Stock", "UpdateTime","SaleType","ShopId","Recommend","CompanyId"
                            });
                    }

                    writeRuning = false;
               // });
            }
        }
Example #8
0
        /// <summary>
        /// 搜索商品
        /// </summary>
        /// <param name="page"></param>
        /// <param name="itemsperpage"></param>
        /// <param name="categoryId"></param>
        /// <param name="areaId"></param>
        /// <param name="title"></param>
        /// <param name="sort"></param>
        /// <param name="minPrice"></param>
        /// <param name="maxPrice"></param>
        /// <returns></returns>
        public static PageModel<GoodsDetail> Find(bool area, int page, int itemsperpage, int categoryId, int areaId, string title, string sort = "default", double minPrice = 0, double maxPrice = 0, int saleType = 1, int shopId = 0, string spid = "0", int itemcatid = 0, string recommend=null)
        {
            var init = new Yun.ClientCache.CacheFunc();
            List<GoodsDetailInSql> data = null;
            long totalItem = 0;

            if (title.IsNotNullOrEmpty() || spid != "0" || itemcatid > 0 || categoryId>0)
            {
                var itemss = new GetItemsRequest
                {
                    ItemTitle = title,
                    ShopCatIds = categoryId > 0 ? categoryId.ToString() : null,
                    Fields = "id",
                    PageNum = page,
                    PageSize = itemsperpage,
                    AreaIds = areaId > 0 ? areaId.ToString() : null,
                    Sorts = sort,
                    MinPrice = minPrice,
                    MaxPrice = maxPrice,
                    SaleType = saleType,
                    ShopId = shopId,
                    Recommend = recommend,
                    PropIds = spid != "0" ? spid : null,
                    Operation = "propids:and",
                    ItemCatIds = itemcatid > 0 ? itemcatid.ToString() : null
                };
                var r = YunClient.Instance.Execute(itemss);

                data = init.FetchAll<GoodsDetailInSql>(_cacheName, "id IN (" + string.Join(",", r.Items.Select(e => e.Id)) + ") " + GenerateSort(sort));

                totalItem = data.Count;
            }
            else
            {
                var sql="";
                if (area)
                {
                    sql = init.GenerateWhereSql(new List<WhereSql>
                {
                    new WhereSql("CompanyId", GlobeInfo.InitiatedCompanyId, true),
                    new WhereSql("ShopId", shopId, true),
                    new WhereSql("CategoryId", categoryId, true),
                    new WhereSql("AreaId", areaId, true),
                    new WhereSql("IsRecommend", recommend!=null?recommend=="1"?"True":"False":null, true),
                    new WhereSql("Price", minPrice, true, SqlOperatorsEnum.GreaterEqualThan),
                    new WhereSql("Price", maxPrice, true, SqlOperatorsEnum.LessEqualThan),
                    new WhereSql("SaleType",saleType, true),
                    new WhereSql("OffShelfTime", DateTime.Now.ToString(), true, SqlOperatorsEnum.GreaterThan),
                    new WhereSql("OnShelfTime", DateTime.Now.ToString(), true, SqlOperatorsEnum.LessEqualThan),
                });
                }
                else
                {
                    //不需要搜索文章标题的方法
                    sql = init.GenerateWhereSql(new List<WhereSql>
                {
                    new WhereSql("CompanyId", GlobeInfo.InitiatedCompanyId, true),
                    new WhereSql("ShopId", shopId, true),
                    new WhereSql("CategoryId", categoryId, true),
                    new WhereSql("AreaId", areaId, true),
                    new WhereSql("IsRecommend", recommend!=null?recommend=="1"?"True":"False":null, true),
                    new WhereSql("Price", minPrice, true, SqlOperatorsEnum.GreaterEqualThan),
                    new WhereSql("Price", maxPrice, true, SqlOperatorsEnum.LessEqualThan),
                    new WhereSql("SaleType",saleType, true),
                });
                
                }
                sql += GenerateSort(sort);

                data = init.FetchAll<GoodsDetailInSql>(page, itemsperpage, _cacheName, sql, out totalItem);
            }

            return new PageModel<GoodsDetail>
            {
                CurrentPage = page,
                Items = data.ConvertAll(GoodsDetailInSql.ConvertGoodsDetail),
                ItemsPerPage = itemsperpage,
                TotalItems = totalItem,
            };
        }
Example #9
0
 public static List<GoodsDetail> Gets(int p,int pageSize,IList<int> itemIds)
 {
     var init = new Yun.ClientCache.CacheFunc();
     List<GoodsDetail> data = null;
     data = init.FetchAll<GoodsDetail>(p, pageSize, _cacheName, "id in (" + string.Join(",", itemIds) + ")");
     return data;
 }
Example #10
0
        public void WriteAllCache()
        {
            lock (writeLock)
            {
                if(writeRuning) return;

                writeRuning = true;
                //开单独的线程进行处理
                //Task.Factory.StartNew(() =>
                //{
                    var init = new Yun.ClientCache.CacheFunc();
                    init.DropTable(_cacheName);

                    var archives = new List<ArticleDetail>();
                    int i = 1;
                    while (true)
                    {
                        var d = YunClient.Instance.Execute(new GetArchivesRequest { PageNum = i, PageSize = 40 }).Articles;
                        if (d != null && d.Any())
                        {
                            i++;
                            archives.Add(d);
                            continue;
                        }

                        break;
                    }

                    var addItems = archives.ConvertAll(ArchiveInSql.ConvertArchiveInSql);
                    if (addItems.Any())
                    {
                        init.BulkInsert(_cacheName, "Id", addItems,
                            new[] {"TaxonomyId", "Title", "Sort", "PostDateTime", "Status", "UserId" });
                    }

                    writeRuning = false;
                //});
            }
        }
Example #11
0
        /// <summary>
        /// 添加系统信息
        /// </summary>
        public static bool SetWebSettings(string isneedcates, string webName, string beian, string seoKey, string seoValue, string seoDescription, string stock, string qqKey, string qqValue, string sinaWeiBoKey, string sinaWeiBoValue, string alipayKey, string alipayValue, string qqUrl, string sinaWeiBoUrl, string alipayUrl, string logn = "", string alipayReturnUrl="")
        {
            var lognImg = Extension.Commodity.UpdateImages();
            var setting = new List<YunKeyValuePair<string, string>>
            {
                new YunKeyValuePair<string, string>("isneedcates", isneedcates),
                new YunKeyValuePair<string, string>("webname", webName),
                new YunKeyValuePair<string, string>("beian", beian),
                new YunKeyValuePair<string, string>("logo", lognImg != "" ? lognImg : logn),
                new YunKeyValuePair<string, string>("seokey", seoKey),
                new YunKeyValuePair<string, string>("seovalue", seoValue),
                new YunKeyValuePair<string, string>("seodescription", seoDescription),
                new YunKeyValuePair<string, string>("stock", stock),
                new YunKeyValuePair<string, string>("qqkey", qqKey),
                new YunKeyValuePair<string, string>("qqvalue", qqValue),
                new YunKeyValuePair<string, string>("qqurl", qqUrl),
                new YunKeyValuePair<string, string>("sinaweibokey", sinaWeiBoKey),
                new YunKeyValuePair<string, string>("sinaweibovalue", sinaWeiBoValue),
                new YunKeyValuePair<string, string>("sinaweibourl", sinaWeiBoUrl),
                new YunKeyValuePair<string, string>("alipaykey", alipayKey),
                new YunKeyValuePair<string, string>("alipayvalue", alipayValue),
                new YunKeyValuePair<string, string>("alipayurl", alipayUrl),
                new YunKeyValuePair<string, string>("alipayreturnurl", alipayReturnUrl),
            };

            var r = YunClient.Instance.Execute(new SetWebSettingRequest
            {
                Setting = setting,
            }, Extension.Member.Token);

            //将数据写入缓存中
            var init = new Yun.ClientCache.CacheFunc();
            init.Delete("app", "id", 1);
            _webInfo = null;

            init.Insert("app", "id", new Settoins { id = 1, Settoin = setting }, null);
            return r.Result;
        }
Example #12
0
        /// <summary>
        /// 扣除积分
        /// </summary>
        public static void DeductionIntegral(int tradeId)
        {
             lock (writeLock)
            {

                    var r = new Yun.ClientCache.CacheFunc().Fetch<Integralmodel>(_cacheName, "Id = @0", tradeId);
                    if (r != null) return;
                    var rr =  YunClient.Instance.Execute(new Yun.Trade.Request.GetTradeRequest
                    {
                    Id = tradeId
                    }).Trade;

                    if (rr == null) return;
                    var ext = 0;
                    if ((rr.Ext ?? "0").IndexOf(",") >= 0)
                    {
                        ext = int.Parse(rr.Ext.Split(',')[1]);
                    }
                    else if (int.Parse(rr.Ext ?? "0") > 0)
                    {
                        ext = int.Parse(rr.Ext);
                    }
                    if (ext<=0) return;
                    if (rr.TradeStatus == "WAIT_SELLER_SEND_GOODS" || rr.TradeStatus == "WAIT_BUYER_CONFIRM_GOODS" || rr.TradeStatus == "TRADE_BUYER_SIGNED" || rr.TradeStatus == "TRADE_FINISHED")
                    {
                        var title="";
                        foreach(var a in rr.Orders)
                        {
                            title += a.ItemTitle + ",";
                        }
                        var user = YunClient.Instance.Execute(new GetUserRequest() { UserId=rr.UserId}).User;
                        r = new Yun.ClientCache.CacheFunc().Fetch<Integralmodel>(_cacheName, "Id = @0", tradeId);
                        if (r != null) return;

                        var rrr = Integralbool(ext.TryTo(0) - rr.PaymentInfo.PrepaidCard.TryTo(0), tradeId, title.TrimEnd(','), 1, user != null ? user.IdCard : "");
                        if (rrr)
                        {
                                new Yun.ClientCache.CacheFunc().Insert(_cacheName, "Id", new Integralmodel { Id = tradeId, Integral = rr.Ext }, null);
                        }
                        else
                        {
                            string path = System.Web.HttpRuntime.AppDomainAppPath.ToString() + "trade\\";
                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }
                            string sPath = System.Web.HttpRuntime.AppDomainAppPath.ToString()+"trade\\" +tradeId +".txt";
                            if (!File.Exists(sPath))
                            {
                                FileStream fs1 = new FileStream(sPath, FileMode.Create, FileAccess.Write);//创建写入文件 
                                StreamWriter sw = new StreamWriter(fs1);
                                sw.WriteLine("该" + tradeId + "订单未扣取积分" + ext);//开始写入值
                                sw.Close();
                                fs1.Close();
                            }
                        }

                    }
                    else 
                    {
                        return;
                    }
            }
        }
Example #13
0
        public void WriteAllCache()
        {
            lock (writeLock)
            {
                if (writeRuning) return;

                writeRuning = true;
                var init = new Yun.ClientCache.CacheFunc();
                init.DropTable(_cacheName);

                var category = YunClient.Instance.Execute(new GetShopItemCategorysRequest { ShopId = 11595 }).Categorys;

                init.BulkInsert(_cacheName, "Id", category, new[] {"Title", "Sort", "ParentId", "Display" });

                writeRuning = false;
            }
        }
Example #14
0
        public void WriteAllCache()
        {
            lock (writeLock)
            {
                if (writeRuning) return;

                writeRuning = true;
                //开单独的线程进行处理
                Task.Factory.StartNew(() =>
                {
                    var init = new Yun.ClientCache.CacheFunc();
                    init.DropTable(_cacheName);

                    var archives = new List<ShopDetail>();
                    int i = 1;
                    while (true)
                    {
                        var d = YunClient.Instance.Execute(new SearchShopsRequest { PageNum = i, PageSize = 40 }).Shops;
                        if (d != null && d.Any())
                        {
                            i++;
                            archives.AddRange(d);
                            continue;
                        }

                        break;
                    }

                    var addItems = archives.ConvertAll(ShopInSql.ConvertShopInSql);
                    if (addItems.Any())
                    {
                        init.BulkInsert(_cacheName, "Id", addItems,
                            new[] { "Id", "CategoryId", "IsOpen", "Title" });
                    }

                    writeRuning = false;
                });
            }
        }
Example #15
0
        /// <summary>
        /// 搜索店铺
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <param name="areaId"></param>
        /// <param name="categoryId"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static PageModel<ShopDetail> Search(long page, int pageSize, int areaId, int categoryId, string name)
        {
            var init = new Yun.ClientCache.CacheFunc();
            long total = 0;
            var r = init.FetchAll<ShopInSql>(page, pageSize, _cacheName,
                init.GenerateWhereSql(new List<WhereSql>
                {
                    new WhereSql("AreaId", areaId, true),
                    new WhereSql("CategoryId", categoryId, true),
                    new WhereSql("Title", name, true)
                }), out total);

            return new PageModel<ShopDetail>
            {
                CurrentPage = page,
                Items = r.ConvertAll(ShopInSql.ConvertShopDetail),
                ItemsPerPage = pageSize,
                TotalItems = total
            };
        }