Example #1
0
        /// <summary>
        /// 获取店铺信息
        /// </summary>
        /// <param name="UserId"></param>
        /// <param name="ScoreId"></param>
        /// <returns></returns>
        internal tbShopInfo GetInfoFromTb(string NickName, int ScoreId)
        {
            tbShopInfo     shopinfo = new tbShopInfo();
            ITopClient     client   = new DefaultTopClient(StaticSystemConfig.soft.ApiURL, StaticSystemConfig.soft.AppKey, StaticSystemConfig.soft.AppSecret);
            ShopGetRequest req      = new ShopGetRequest();

            req.Fields = "sid,cid,title,nick,desc,bulletin,pic_path,created,modified";
            req.Nick   = NickName;
            ShopGetResponse response = client.Execute(req);

            Top.Api.Domain.Shop shop = response.Shop;

            shopinfo.Bulletin      = shop.Bulletin;
            shopinfo.CateId        = (int)shop.Cid;
            shopinfo.Created       = DateTime.Parse(shop.Created);
            shopinfo.Desc          = shop.Desc;
            shopinfo.Modified      = DateTime.Parse(shop.Modified);
            shopinfo.NickName      = shop.Nick;
            shopinfo.PicPath       = shop.PicPath;
            shopinfo.Score         = new tbShopScore();
            shopinfo.Score.ScoreId = ScoreId;
            if (shop.ShopScore != null)
            {
                shopinfo.Score.ItemScore     = shop.ShopScore.ItemScore;
                shopinfo.Score.ServiceScore  = shop.ShopScore.ServiceScore;
                shopinfo.Score.DeliveryScore = shop.ShopScore.DeliveryScore;
            }
            shopinfo.TbShopId = (int)shop.Sid;
            shopinfo.Title    = shop.Title;

            return(shopinfo);
        }
Example #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool UpdateShopInfo(tbShopInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update tbShopInfo set ");
            strSql.Append("TbShopId=@TbShopId,");
            strSql.Append("ScoreId=@ScoreId,");
            strSql.Append("CateId=@CateId,");
            strSql.Append("NickName=@NickName,");
            strSql.Append("Title=@Title,");
            strSql.Append("[Desc]=@Desc,");
            strSql.Append("Bulletin=@Bulletin,");
            strSql.Append("PicPath=@PicPath,");
            strSql.Append("Created=@Created,");
            strSql.Append("Modified=@Modified");
            strSql.Append(" where ShopId=@ShopId");
            SqlParameter[] parameters =
            {
                new SqlParameter("@TbShopId", SqlDbType.Int,         4),
                new SqlParameter("@ScoreId",  SqlDbType.Int,         4),
                new SqlParameter("@CateId",   SqlDbType.Int,         4),
                new SqlParameter("@NickName", SqlDbType.VarChar,    50),
                new SqlParameter("@Title",    SqlDbType.VarChar,   100),
                new SqlParameter("@Desc",     SqlDbType.VarChar,   500),
                new SqlParameter("@Bulletin", SqlDbType.VarChar,   200),
                new SqlParameter("@PicPath",  SqlDbType.VarChar,   200),
                new SqlParameter("@Created",  SqlDbType.DateTime),
                new SqlParameter("@Modified", SqlDbType.DateTime),
                new SqlParameter("@ShopId",   SqlDbType.Int, 4)
            };
            parameters[0].Value  = model.TbShopId;
            parameters[1].Value  = model.Score.ScoreId;
            parameters[2].Value  = model.CateId;
            parameters[3].Value  = model.NickName;
            parameters[4].Value  = model.Title;
            parameters[5].Value  = model.Desc;
            parameters[6].Value  = model.Bulletin;
            parameters[7].Value  = model.PicPath;
            parameters[8].Value  = model.Created;
            parameters[9].Value  = model.Modified;
            parameters[10].Value = model.ShopId;

            int rows = DBHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        /// <summary>
        /// 插入一条数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int InsertShopInfo(tbShopInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tbShopInfo(");
            strSql.Append("TbShopId,ScoreId,CateId,NickName,Title,[Desc],Bulletin,PicPath,Created,Modified)");
            strSql.Append(" values (");
            strSql.Append("@TbShopId,@ScoreId,@CateId,@NickName,@Title,@Desc,@Bulletin,@PicPath,@Created,@Modified)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@TbShopId", SqlDbType.Int,         4),
                new SqlParameter("@ScoreId",  SqlDbType.Int,         4),
                new SqlParameter("@CateId",   SqlDbType.Int,         4),
                new SqlParameter("@NickName", SqlDbType.VarChar,    50),
                new SqlParameter("@Title",    SqlDbType.VarChar,   100),
                new SqlParameter("@Desc",     SqlDbType.VarChar,   500),
                new SqlParameter("@Bulletin", SqlDbType.VarChar,   200),
                new SqlParameter("@PicPath",  SqlDbType.VarChar,   200),
                new SqlParameter("@Created",  SqlDbType.DateTime),
                new SqlParameter("@Modified", SqlDbType.DateTime)
            };
            parameters[0].Value = model.TbShopId;
            parameters[1].Value = model.Score.ScoreId;
            parameters[2].Value = model.CateId;
            parameters[3].Value = model.NickName;
            parameters[4].Value = model.Title;
            parameters[5].Value = model.Desc;
            parameters[6].Value = model.Bulletin;
            parameters[7].Value = model.PicPath;
            parameters[8].Value = model.Created;
            parameters[9].Value = model.Modified;

            object obj = DBHelper.ExecuteScalar(CommandType.Text, strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Example #4
0
        /// <summary>
        /// 查询数据(by ShopId)
        /// </summary>
        /// <param name="ShopId"></param>
        /// <returns></returns>
        public tbShopInfo SelecttbShopInfoByShopId(string ShopId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ShopId,TbShopId,ScoreId,CateId,NickName,Title,[Desc],Bulletin,PicPath,Created,Modified from tbShopInfo ");
            strSql.Append(" where ShopId=@ShopId");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ShopId", SqlDbType.Int, 4)
            };
            parameters[0].Value = ShopId;

            tbShopInfo model = new tbShopInfo();
            DataSet    ds    = DBHelper.ExecuteDataSet(CommandType.Text, strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ShopId"].ToString() != "")
                {
                    model.ShopId = int.Parse(ds.Tables[0].Rows[0]["ShopId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["TbShopId"].ToString() != "")
                {
                    model.TbShopId = int.Parse(ds.Tables[0].Rows[0]["TbShopId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ScoreId"].ToString() != "")
                {
                    model.Score         = new tbShopScore();
                    model.Score.ScoreId = int.Parse(ds.Tables[0].Rows[0]["ScoreId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CateId"].ToString() != "")
                {
                    model.CateId = int.Parse(ds.Tables[0].Rows[0]["CateId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["NickName"] != null)
                {
                    model.NickName = ds.Tables[0].Rows[0]["NickName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Title"] != null)
                {
                    model.Title = ds.Tables[0].Rows[0]["Title"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Desc"] != null)
                {
                    model.Desc = ds.Tables[0].Rows[0]["Desc"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Bulletin"] != null)
                {
                    model.Bulletin = ds.Tables[0].Rows[0]["Bulletin"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PicPath"] != null)
                {
                    model.PicPath = ds.Tables[0].Rows[0]["PicPath"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Created"].ToString() != "")
                {
                    model.Created = DateTime.Parse(ds.Tables[0].Rows[0]["Created"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Modified"].ToString() != "")
                {
                    model.Modified = DateTime.Parse(ds.Tables[0].Rows[0]["Modified"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Example #5
0
        /// <summary>
        /// 保存用户信息到数据库
        /// </summary>
        /// <param name="us"></param>
        private tbClientUser Save(tbClientUser us, string token, string ExpiresIn)
        {
            GetShop gs = new GetShop();

            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    int          shopid     = 0;
                    tbClientUser ClientUser = BClientUser.ExitisUser(us.TbUserId.ToString(), us.UserNick);
                    if (ClientUser == null)
                    {
                        int ScoreId = 0;
                        //从淘宝获取店铺信息
                        tbShopInfo ShopInfo = gs.GetInfoFromTb(us.UserNick, 0);
                        if (ShopInfo.Score.ItemScore != null && ShopInfo.Score.ServiceScore != null)
                        {
                            //往数据库插入店铺评分表
                            ScoreId = BShopScore.InsertShopScore(ShopInfo.Score);
                        }
                        //获取返回自动生成的主键
                        ShopInfo.Score.ScoreId = ScoreId;
                        //往店铺信息表中插入数据
                        shopid          = BShopInfo.InsertShopInfo(ShopInfo);
                        ShopInfo.ShopId = shopid;
                        //插入用户信用表,并获取返回的ID
                        int Creditid = BClientUserCredit.InsertUserCredit(new tbClientUserCredit {
                            GoodNum = us.Credit.GoodNum, Level = us.Credit.Level, Score = us.Credit.Score, TotalNum = us.Credit.TotalNum
                        });
                        us.UserShops       = new List <tbClientUserShop>();
                        us.Credit.CreditId = Creditid;
                        //插入用户信息表
                        int userid = BClientUser.InsertUser(us);
                        //往用户店铺关系对应表中插入数据
                        BClientUserShop.InsertUserShop(new tbClientUserShop()
                        {
                            Shop = ShopInfo, SessionKey = token, UserId = userid
                        });
                        us.UserShops.Add(new tbClientUserShop()
                        {
                            Shop = ShopInfo, SessionKey = token, UserId = userid
                        });
                    }
                    else
                    {
                        tbShopInfo       shopinfo = new tbShopInfo();
                        tbClientUserShop usershop = BClientUserShop.SelectUserShopByUserId(ClientUser.UserId.ToString());
                        usershop.SessionKey = token;
                        shopid   = usershop.Shop.ShopId;
                        shopinfo = BShopInfo.SelecttbShopInfoByShopId(shopid.ToString());
                        BClientUserShop.UpdateUserShop(usershop);
                        //从淘宝获取店铺信息
                        tbShopInfo TBShopInfo = gs.GetInfoFromTb(us.UserNick, shopinfo.Score.ScoreId);
                        TBShopInfo.ShopId = shopid;
                        if (TBShopInfo.Score.ItemScore != null && TBShopInfo.Score.ServiceScore != null)
                        {
                            BShopScore.UpdateShopScore(new tbShopScore()
                            {
                                DeliveryScore = TBShopInfo.Score.DeliveryScore, ItemScore = TBShopInfo.Score.ItemScore, ServiceScore = TBShopInfo.Score.ServiceScore, ScoreId = shopinfo.Score.ScoreId
                            });
                        }
                        BShopInfo.UpdateShopInfo(TBShopInfo);
                        us.UserId = ClientUser.UserId;
                        BClientUserCredit.UpdateUserCredit(new tbClientUserCredit()
                        {
                            CreditId = ClientUser.Credit.CreditId, GoodNum = us.Credit.GoodNum, Level = us.Credit.Level, Score = us.Credit.Level, TotalNum = us.Credit.GoodNum
                        });
                        us.Credit          = new tbClientUserCredit();
                        us.Credit.CreditId = ClientUser.Credit.CreditId;
                        BClientUser.UpdateUser(us);

                        us.UserShops = new List <tbClientUserShop>();
                        us.UserShops.Add(usershop);
                        usershop.Shop = new tbShopInfo();
                        usershop.Shop = shopinfo;
                    }
                    scope.Complete();
                    Hashtable ht = new Hashtable();
                    ht.Add("TBNick", us.UserNick);
                    ht.Add("token", token);
                    ht.Add("TbUserId", us.TbUserId);
                    ht.Add("Shopid", shopid);
                    DataCache.SetCache("UserInfo" + us.UserId, ht);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(us);
        }
Example #6
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 /// <param name="ShopScore"></param>
 /// <returns></returns>
 public static bool UpdateShopInfo(tbShopInfo ShopInfo)
 {
     return(SetShopInfo.UpdateShopInfo(ShopInfo));
 }
Example #7
0
 /// <summary>
 /// 添加一条数据
 /// </summary>
 /// <param name="ShopScore"></param>
 /// <returns></returns>
 public static int InsertShopInfo(tbShopInfo ShopInfo)
 {
     return(SetShopInfo.InsertShopInfo(ShopInfo));
 }