// 查看关注信息
        public List <FollowShopView> getFollowShops(string buyerid)
        {
            List <FollowShopView> followShopViews = new List <FollowShopView>();                            //  返回买家关注显示列表

            List <FollowShop> followShops = _context.FollowShops.Where(x => x.BuyerId == buyerid).ToList(); // 买家关注列表

            foreach (FollowShop followShop in followShops)
            {
                Shop shop = _context.Shops.Where(x => x.ShopId == followShop.ShopId).FirstOrDefault();                   // 关注的店铺

                List <Commodity> shopAllCommodities = _context.Commodities.Where(x => x.ShopId == shop.ShopId).ToList(); // 店铺的所有商品

                List <Commodity> shopOrderCommodities = shopAllCommodities.OrderBy(x => x.Soldnum).ToList();             // 商品列表排序

                List <Commodity> shopCommodities = new List <Commodity>();

                int count = 0;
                foreach (Commodity commodity in shopOrderCommodities)
                {
                    shopCommodities.Add(commodity);
                    count++;
                    if (count == 4)
                    {
                        break;
                    }
                }

                List <CommodityView> commodityViews = new List <CommodityView>();
                foreach (var shopcommodity in shopCommodities)
                {
                    CommodityView commodityView = new CommodityView
                    {
                        CommodityId = shopcommodity.CommodityId,
                        ShopId      = shopcommodity.ShopId,
                        Url         = shopcommodity.Url,
                        Category    = shopcommodity.Category,
                        Name        = shopcommodity.Name,
                        Price       = shopcommodity.Price,
                        Storage     = shopcommodity.Storage,
                        Soldnum     = shopcommodity.Soldnum,
                        Description = shopcommodity.Description
                    };
                    commodityViews.Add(commodityView);
                }

                FollowShopView followShopView = new FollowShopView
                {
                    BuyerId       = followShop.BuyerId,
                    ShopId        = followShop.ShopId,
                    DateCreated   = followShop.DateCreated,
                    ShopName      = shop.Name,
                    Url           = shop.Url,
                    commodityView = commodityViews
                };

                followShopViews.Add(followShopView);
            }

            return(followShopViews);
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            RegisterOEMSkins("form.css");
            RegisterOEMSkins("page.css");

            if (!IsPostBack)
            {
                title.InnerText = "添加商品";
                txtTime.Text    = DateTime.Today.AddMonths(3).ToString("yyyy-MM-dd");
                if (Request.QueryString["id"] != null)
                {
                    CommodityView view = CommodityServer.GetCommodity(Guid.Parse(Request.QueryString["id"]));
                    if (view != null)
                    {
                        btnAdd.Text          = "修改";
                        OldImgUrlDiv.Visible = true;
                        OldImgUrl.Text       = FileWeb + view.CoverImgUrl;
                        OldImgUrl.Style.Add(HtmlTextWriterStyle.Display, "none");
                        title.InnerText        = "修改商品";
                        txtTime.Text           = view.ValidityTime.ToString("yyyy-MM-dd");
                        txtCoommodityName.Text = view.CommodityName;
                        txtNeedIntegral.Text   = view.NeedIntegral + "";
                        txtRemark.Text         = view.Remark;
                        txtSort.Text           = view.SortNum + "";
                        ddlType.SelectedValue  = ((int)view.Type).ToString();
                        txtNum.Text            = view.ExchangSmsNumber.ToString();
                        lblName.Text           = view.CommodityName;
                        hidName.Value          = view.CommodityName;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataTransferObject.Commodity.CommodityView GetCommodity(Guid id)
        {
            CommodityView result = null;
            string        sql    = @"SELECT [ID] ,[CommodityName] ,[CoverImgUrl]  ,[NeedIntegral] ,[StockNumber]  ,[ExchangeNumber]  ,[State]   ,[ValidityTime],([StockNumber] - [ExchangeNumber]),Remark,SortNum,ExchangSmsNumber,Type FROM  [dbo].[T_Commodity] WHERE ID=@ID ";

            AddParameter("ID", id);
            using (var reader = ExecuteReader(sql))
            {
                if (reader.Read())
                {
                    result                  = new CommodityView();
                    result.ID               = reader.GetGuid(0);
                    result.CommodityName    = reader.GetString(1);
                    result.CoverImgUrl      = reader.GetString(2);
                    result.NeedIntegral     = reader.GetInt32(3);
                    result.StockNumber      = reader.GetInt32(4);
                    result.ExchangeNumber   = reader.GetInt32(5);
                    result.State            = reader.GetBoolean(6);
                    result.ValidityTime     = reader.GetDateTime(7);
                    result.SurplusNumber    = reader.GetInt32(8);
                    result.Remark           = reader.GetString(9);
                    result.SortNum          = reader.GetInt32(10);
                    result.ExchangSmsNumber = reader.GetInt32(11);
                    result.Type             = (CommodityType)reader.GetByte(12);
                }
            }
            return(result);
        }
Ejemplo n.º 4
0
        public void Delete(CommodityView view)
        {
            string sql = @"DELETE FROM [dbo].[T_Commodity] WHERE ID = @ID";

            AddParameter("ID", view.ID);
            ExecuteNonQuery(sql);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 修改单件商品信息
 /// </summary>
 public static void UpdateCommodity(CommodityView view, string operatorName)
 {
     using (var cmd = Factory.CreateCommand())
     {
         var reposity = Factory.CreateIntegralReposity(cmd);
         reposity.Update(view);
         saveUpdateLog(operatorName, view.CommodityName, OperatorRole.Platform, view.ID.ToString(), operatorName);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 取得商品列表
        /// </summary>
        /// <param name="falg">是true的时候就是查询展示商品</param>
        /// <returns></returns>
        public IEnumerable <CommodityView> GetCommodityList(bool falg, Pagination pagination)
        {
            List <CommodityView> result = null;

            var    fields     = " ROW_NUMBER() OVER (order by [ValidityTime]) as rownums,[ID] ,[CommodityName] ,[CoverImgUrl]  ,[NeedIntegral] ,[StockNumber]  ,[ExchangeNumber] ,[State] ,[ValidityTime],([StockNumber] - [ExchangeNumber]) as b ,Remark,ExchangSmsNumber,Type";
            string iCondition = " [State] = 1 AND (StockNumber- ExchangeNumber) > 0 AND ValidityTime>=CONVERT(DATE,GETDATE()) ";

            var catelog = "[dbo].[T_Commodity]";

            AddParameter("@iField", fields);
            AddParameter("@iCatelog", catelog);
            if (falg)
            {
                AddParameter("@iCondition", iCondition);
                AddParameter("@iOrderBy", "SortNum");
            }
            else
            {
                AddParameter("@iCondition", "");
                AddParameter("@iOrderBy", "ValidityTime");
            }
            AddParameter("@iPagesize", pagination.PageSize);
            AddParameter("@iPageIndex", pagination.PageIndex);
            AddParameter("@iGetCount", pagination.GetRowCount);
            var totalCount = AddParameter("@oTotalCount");

            totalCount.DbType    = System.Data.DbType.Int32;
            totalCount.Direction = System.Data.ParameterDirection.Output;
            using (var reader = ExecuteReader("dbo.P_Pagination", System.Data.CommandType.StoredProcedure))
            {
                result = new List <CommodityView>();
                while (reader.Read())
                {
                    CommodityView view = new CommodityView();
                    view.Num              = reader.GetValue(0);
                    view.ID               = reader.GetGuid(1);
                    view.CommodityName    = reader.GetString(2);
                    view.CoverImgUrl      = reader.GetString(3);
                    view.NeedIntegral     = reader.GetInt32(4);
                    view.StockNumber      = reader.GetInt32(5);
                    view.ExchangeNumber   = reader.GetInt32(6);
                    view.State            = reader.GetBoolean(7);
                    view.ValidityTime     = reader.GetDateTime(8);
                    view.SurplusNumber    = reader.GetInt32(9);
                    view.Remark           = reader.GetString(10);
                    view.ExchangSmsNumber = reader.GetInt32(11);
                    view.Type             = (CommodityType)reader.GetByte(12);
                    result.Add(view);
                }
            }
            if (pagination.GetRowCount)
            {
                pagination.RowCount = (int)totalCount.Value;
            }
            return(result);
        }
Ejemplo n.º 7
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (!IsVaild())
            {
                return;
            }
            string msg = "添加";

            try
            {
                string        path = fileImg.HasFile ? Service.FileService.Upload(fileImg, "Commodity", "(jpg)|(gif)|(png)|(jpeg)", int.MaxValue) : OldImgUrl.Text.Replace(FileWeb, "");
                CommodityView view = new CommodityView
                {
                    ID               = Guid.NewGuid(),
                    CommodityName    = ddlType.SelectedValue == "1" ? txtCoommodityName.Text : hidName.Value,
                    NeedIntegral     = int.Parse(txtNeedIntegral.Text),
                    SortNum          = int.Parse(txtSort.Text),
                    ExchangeNumber   = 0,
                    State            = radEnable.Checked,
                    StockNumber      = 0,
                    SurplusNumber    = 0,
                    ValidityTime     = DateTime.Parse(txtTime.Text),
                    Remark           = txtRemark.Text,
                    ExchangSmsNumber = ddlType.SelectedValue == "2" ? int.Parse(txtNum.Text) : 0,
                    Type             = (CommodityType)int.Parse(ddlType.SelectedValue)
                };
                if (Request.QueryString["id"] != null)
                {
                    CommodityView views = CommodityServer.GetCommodity(Guid.Parse(Request.QueryString["id"]));
                    view.ExchangeNumber = views.ExchangeNumber;
                    view.StockNumber    = views.StockNumber;
                    view.SurplusNumber  = views.SurplusNumber;
                    msg              = "修改";
                    view.ID          = Guid.Parse((Request.QueryString["id"]));
                    view.CoverImgUrl = path;
                    CommodityServer.UpdateCommodity(view, CurrentUser.UserName);
                }
                else
                {
                    view.CoverImgUrl = path;
                    CommodityServer.InsertCommodity(view, this.CurrentUser.UserName);
                }
                RegisterScript(Page, "alert('" + msg + "成功');window.location.href='./CommodityList.aspx';");
            }
            catch (Exception ex)
            {
                ShowExceptionMessage(ex, msg);
            }
        }
Ejemplo n.º 8
0
        public void Insert(CommodityView view)
        {
            string sql = @"INSERT INTO  [dbo].[T_Commodity] ([ID] ,[CommodityName] ,[CoverImgUrl] ,[NeedIntegral] ,[StockNumber] ,[ExchangeNumber] ,[State],[ValidityTime],Remark,SortNum,ExchangSmsNumber,Type) VALUES(@ID2, @CommodityName2, @CoverImgUrl2, @NeedIntegral2, @StockNumber2, @ExchangeNumber2, @State2, @ValidityTime2,@Remark2,@SortNum2,@ExchangSmsNumber2,@Type2)";

            AddParameter("ID2", view.ID);
            AddParameter("CommodityName2", view.CommodityName);
            AddParameter("CoverImgUrl2", view.CoverImgUrl);
            AddParameter("NeedIntegral2", view.NeedIntegral);
            AddParameter("StockNumber2", view.StockNumber);
            AddParameter("ExchangeNumber2", view.ExchangeNumber);
            AddParameter("State2", view.State);
            AddParameter("ValidityTime2", view.ValidityTime);
            AddParameter("Remark2", view.Remark);
            AddParameter("SortNum2", view.SortNum);
            AddParameter("ExchangSmsNumber2", view.ExchangSmsNumber);
            AddParameter("Type2", view.Type);
            ExecuteNonQuery(sql);
        }
Ejemplo n.º 9
0
        // 店铺信息及其拥有的所有商品
        //public List<ShopCommodityView> getShopCommodities(string shopid)
        public ShopCommodityView getShopCommodities(string shopid)
        {
            Shop shop = _context.Shops.Where(x => x.ShopId == shopid).FirstOrDefault();  // 店铺信息

            //List<ShopCommodityView> shopCommodityViews = new List<ShopCommodityView>();    //  返回信息列表

            List <Commodity> shopCommodities = _context.Commodities.Where(x => x.ShopId == shopid).ToList();    // 所有商品

            List <CommodityView> commodityViews = new List <CommodityView>();

            foreach (var shopcommodity in shopCommodities)
            {
                CommodityView commodityView = new CommodityView
                {
                    CommodityId = shopcommodity.CommodityId,
                    ShopId      = shopcommodity.ShopId,
                    Url         = shopcommodity.Url,
                    Category    = shopcommodity.Category,
                    Name        = shopcommodity.Name,
                    Price       = shopcommodity.Price,
                    Storage     = shopcommodity.Storage,
                    Soldnum     = shopcommodity.Soldnum,
                    Description = shopcommodity.Description
                };
                commodityViews.Add(commodityView);
            }
            ShopView shopView = new ShopView
            {
                shopID          = shop.ShopId,
                shopName        = shop.Name,
                shopDescription = shop.Description,
                img             = shop.Url,
                creditScore     = shop.CreditScore
            };

            ShopCommodityView shopCommodityView = new ShopCommodityView
            {
                Shop           = shopView,
                CommodityViews = commodityViews
            };

            return(shopCommodityView);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// 兑换商品
 /// </summary>
 public static void ExChangeCommodity(Guid id, int exChangeNum, CompanyDetailInfo compnay, EmployeeDetailInfo accountinfo, OEMCommodityState stata, string domainName, Guid?oemid)
 {
     using (var cmd = Factory.CreateCommand())
     {
         var           reposity      = Factory.CreateIntegralReposity(cmd);
         CommodityView commodityview = reposity.GetCommodity(id);
         if (commodityview.ValidityTime.Date < DateTime.Now.Date)
         {
             throw new Exception("该商品上架时间已经到期,不能兑换!");
         }
         if (!commodityview.State)
         {
             throw new Exception("该商品未启用,不能兑换!");
         }
         if (commodityview.SurplusNumber == 0)
         {
             throw new Exception("该商品已经兑换完毕,不能兑换!");
         }
         if (commodityview.SurplusNumber < exChangeNum)
         {
             throw new Exception("该商品库存不足,不能兑换!");
         }
         if (commodityview.NeedIntegral > 0)
         {
             IntegralParameterView paraemter = IntegralServer.GetIntegralParameter();
             IntegralCount         counts    = IntegralServer.GetIntegralByAccountIdZong(compnay.CompanyId);
             if (counts == null)
             {
                 throw new Exception("积分不够,暂不能兑换该商品!");
             }
             if (counts.IntegralAvailable < commodityview.NeedIntegral * exChangeNum)
             {
                 throw new Exception("积分不够,暂不能兑换该商品!");
             }
         }
         commodityview.SurplusNumber  = commodityview.SurplusNumber - exChangeNum;
         commodityview.ExchangeNumber = commodityview.ExchangeNumber + exChangeNum;
         cmd.BeginTransaction();
         try
         {
             reposity.Update(commodityview);
             var consumtion = new IntegralConsumption
             {
                 CompnayId        = compnay.CompanyId,
                 CompanyShortName = compnay.AbbreviateName,
                 AccountName      = accountinfo.Name,
                 AccountNo        = accountinfo.UserName,
                 AccountPhone     = compnay.ContactPhone,
                 DeliveryAddress  = commodityview.Type == CommodityType.Entity ? compnay.Address : "",
                 CommodityCount   = exChangeNum,
                 CommodityId      = commodityview.ID,
                 CommodityName    = commodityview.CommodityName,
                 Exchange         = commodityview.Type == CommodityType.Entity ? ExchangeState.Processing : ExchangeState.Success,
                 ExchangeTiem     = DateTime.Now,
                 ExpressCompany   = "",
                 ExpressDelivery  = "",
                 Reason           = "",
                 Remark           = commodityview.CommodityName,
                 Way = commodityview.Type == CommodityType.Entity ? IntegralWay.Exchange : IntegralWay.ExchangeSms,
                 ConsumptionIntegral = commodityview.NeedIntegral * exChangeNum,
                 OEMCommodityState   = commodityview.Type == CommodityType.SMS ? OEMCommodityState.Success : stata,
                 OEMName             = domainName,
                 OEMID = oemid
             };
             IntegralServer.InsertIntegralConsumption(consumtion);
             IntegralServer.UpdateIntegralCountByConsumption(0 - consumtion.ConsumptionIntegral, accountinfo.Owner);
             cmd.CommitTransaction();
         }
         catch (Exception)
         {
             cmd.RollbackTransaction();
             throw;
         }
         if (commodityview.Type == CommodityType.SMS)
         {
             var acc = from item in AccountService.Query(compnay.CompanyId)
                       where item.Type == Common.Enums.AccountType.Payment
                       select new { No = item.No };
             SMSOrderService.ExChangeSms(compnay.CompanyId, commodityview.NeedIntegral, exChangeNum, commodityview.ExchangSmsNumber, acc.First().No);
         }
     }
 }