/// <summary>
        /// 根据商品Id获取商品的信息
        /// </summary>
        /// <param name="accId"></param>
        /// <returns></returns>
        private List <GoodsInfoModel> GetGoodsInfo(int accId)
        {
            StringBuilder sqlStr       = new StringBuilder();
            var           goodInfoList = new List <GoodsInfoModel>();

            sqlStr.Append("select * from dbo.T_GoodsInfo where accID=@accID  AND  IsExtend  is null and isDown <> 1 ; ");
            var dataResult = DapperHelper.Query <dynamic>(sqlStr.ToString(), new { accID = accId });

            if (dataResult != null)
            {
                foreach (var item in dataResult)
                {
                    var goodInfo = new GoodsInfoModel();
                    goodInfo.Gid        = Convert.ToInt32(item.gid);
                    goodInfo.AccId      = Convert.ToInt32(item.accID);
                    goodInfo.GName      = item.gName;
                    goodInfo.GQuantity  = Convert.ToDecimal(item.gQuantity);
                    goodInfo.LimitLower = item.LimitLower;
                    goodInfo.LimitUpper = item.LimitUpper;
                    goodInfo.IsExtend   = 0;
                    goodInfoList.Add(goodInfo);
                }
            }

            return(goodInfoList);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取商品信息
        /// </summary>
        /// <returns>商品信息</returns>
        public static GoodsInfoModel getGoodsInfo(int pageIndex, int pageSize, out int recordCount)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(" select Barcode,GoodName,GoodPhoteURL,GoodTypeName,MinValue,MaxValue,Price,Points,StatusName,Note from ");
            sb.Append(" ( ");
            sb.Append(@" select ROW_NUMBER() over (order by GoodName desc) as RowId, Barcode,GoodName,GoodPhoteURL,
                        case GoodType when 0 then '销售商品' when 1 then '兑换礼品' when 2 then '办公用品' 
                        when 3 then '终端设备' when 4 then '系统耗材' when 5 then '代币' 
                        when 6 then '数字币' when 7 then '会员卡' when 8 then '其他'  end as GoodTypeName,
                        MinValue,MaxValue,Price,Points,case [Status] when 0 then '停用' when 1 then '正常' end StatusName,Note 
                        from dbo.Base_GoodsInfo ");
            sb.Append(" ) a ");
            sb.Append(string.Format(" where RowId >= {0} and RowId <= {1}", pageIndex * pageSize, (pageIndex + 1) * pageSize));
            sb.Append(" select COUNT(0) from dbo.Base_GoodsInfo ");

            DataAccess ac     = new DataAccess(DataAccessDB.XCCloudDB);
            string     sqlStr = sb.ToString();
            DataSet    ds     = ac.ExecuteQuery(sqlStr);
            List <GoodsInfoDetailModel> goodsDetail = Utils.GetModelList <GoodsInfoDetailModel>(ds.Tables[0]);

            recordCount = Convert.ToInt32(ds.Tables[1].Rows[0][0]);
            Page           pages     = new Page(pageIndex, pageSize, recordCount);
            GoodsInfoModel goodsInfo = new GoodsInfoModel(goodsDetail, pages);

            return(goodsInfo);
        }
        /// <summary>
        /// 根据商品的Id获取拓展商品的信息
        /// </summary>
        /// <param name="accId"></param>
        /// <returns></returns>
        private List <GoodsInfoModel> GetGoodsExtendInfo(int accId)
        {
            StringBuilder sqlStr             = new StringBuilder();
            var           goodInfoExtendList = new List <GoodsInfoModel>();

            sqlStr.Append(
                "SELECT m.gid AS gid,n.gsId as gsId, m.accID AS accID,M.gName AS gName,N.gsQuantity AS gQuantity,N.LimitLower AS LimitLower,N.LimitUpper AS LimitUpper  FROM dbo.T_GoodsInfo m LEFT JOIN dbo.T_Goods_Sku n ON m.gid =n.gid WHERE m.accID=@accID  AND  m.IsExtend =1  AND m.isDown <> 1;");
            var dataResult = DapperHelper.Query <dynamic>(sqlStr.ToString(), new { accID = accId });

            if (dataResult != null)
            {
                foreach (var item in dataResult)
                {
                    var goodInfo = new GoodsInfoModel();
                    goodInfo.Gid        = Convert.ToInt32(item.gid);
                    goodInfo.AccId      = Convert.ToInt32(item.accID);
                    goodInfo.Gsid       = item.gsId;
                    goodInfo.GName      = item.gName + "_" + GetAttributeName(Convert.ToInt32(item.gsId));
                    goodInfo.GQuantity  = Convert.ToDecimal(item.gQuantity);
                    goodInfo.LimitLower = item.LimitLower;
                    goodInfo.LimitUpper = item.LimitUpper;
                    goodInfo.IsExtend   = 1;
                    goodInfoExtendList.Add(goodInfo);
                }
            }
            return(goodInfoExtendList);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 修改商品信息
 /// </summary>
 /// <param name="goodsInfo"></param>
 /// <returns></returns>
 public bool UpdateGoodsInfo(GoodsInfoModel goodsInfo)
 {
     if (goodsInfo != null)
     {
         return(goodsDAL.UpdateGoodsInfo(goodsInfo));
     }
     throw new Exception("修改的商品信息不能为空!");
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 添加商品
 /// </summary>
 /// <param name="goodsInfo"></param>
 /// <returns></returns>
 public bool AddGoodsInfo(GoodsInfoModel goodsInfo)
 {
     if (goodsInfo != null)
     {
         return(goodsDAL.AddGoodsInfo(goodsInfo));
     }
     throw new Exception("添加的商品信息不能为空!");
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 首页
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            GoodsInfoModel model        = new GoodsInfoModel();
            GoodsLogic     goodsLogic   = new GoodsLogic();
            var            categoryList = goodsLogic.GetCategory();
            var            goodsList    = goodsLogic.GetGoodsList();

            model.DirectoryList = categoryList;
            model.GoodsList     = goodsList;
            ViewBag.Category    = categoryList.Where(m => m.Rank == 0).ToList();
            return(View(model));
        }
Ejemplo n.º 7
0
 public MessageResult GetGoodsInfo(int goodsId)
 {
     try
     {
         GoodsInfoModel info = goodsBLL.GetGoodsInfo(goodsId);;
         return(MessageResult.Success(info));
     }
     catch (Exception ex)
     {
         return(MessageResult.Fail(ex.Message));
     }
 }
Ejemplo n.º 8
0
        public MessageResult UpdateGoodsInfo(GoodsInfoModel goodsInfo)
        {
            bool rsult = goodsBLL.UpdateGoodsInfo(goodsInfo);

            if (rsult)
            {
                return(MessageResult.Success());
            }
            else
            {
                return(MessageResult.Fail());
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 关键词获取商品名称
        /// </summary>
        /// <param name="keywords"></param>
        /// <returns></returns>
        public string GetGoodsInfoByKeywords(string keywords)
        {
            GoodsInfoModel goods = goodsDAL.GetGoodsInfoByKeywords(keywords);

            if (goods != null)
            {
                return(goods.GoodsName);
            }
            else
            {
                return("");
            }
        }
Ejemplo n.º 10
0
        //public ResultModel GetClearingInfo()
        //{

        //}

        public List <GoodsInfoModel> SetGoodsByCartIdArr(List <CartIdArr> cartIdArr)
        {
            List <GoodsInfoModel> result = new List <GoodsInfoModel>();

            foreach (var item in cartIdArr)
            {
                GoodsInfoModel model = new GoodsInfoModel();
                model.GoodsId               = item.ProductId;
                model.SkuNumber             = item.SKUId;
                model.Count                 = Convert.ToInt32(item.BuyNum);
                model.AddToShoppingCartTime = DateTime.Now.ToString();
                model.IsChecked             = "1";
                result.Add(model);
            }

            return(result);
        }
        /// <summary>
        /// 保存库存预警数据
        /// </summary>
        /// <returns></returns>
        private int SaveSingleGoodsWarningData(StockAlertSetting stockalertInfo, GoodsInfoModel goodInfo)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(goodInfo.IsExtend == 1
                ? " if(exists( SELECT id FROM [Sys_I200].[dbo].T_SingleGoodsWaring WHERE  DATEDIFF(DAY,currentDate,@insertDate)=0 AND accId=@accId AND gid=@gid AND gsId=@gsId))"
                : " if(exists( SELECT id FROM [Sys_I200].[dbo].T_SingleGoodsWaring WHERE  DATEDIFF(DAY,currentDate,@insertDate)=0 AND accId=@accId AND gid=@gid AND gsId is null))");
            strSql.Append(" begin");
            strSql.Append("   select 1");
            //strSql.Append("UPDATE T_SingleGoodsWaring SET userRealName=@userRealName,alertStatus=@alertStatus,alertTime=@alertTime,isWeb=@isWeb,isSms=@isSms,isMob=@isMob,isEmail=@isEmail,gQuantity=@gQuantity,limitLower=@limitLower,limitUpper=@limitUpper,operateTime=@operateTime  WHERE DATEDIFF(DAY,currentDate,@insertDate)=0 AND accId=@accId AND gid=@gid AND gsId IS NULL; ");
            strSql.Append(" end");
            strSql.Append(" else");
            strSql.Append("  begin");
            strSql.Append("    INSERT INTO [Sys_I200].[dbo].T_SingleGoodsWaring(currentDate,accid,userRealName,alertStatus,alertTime,isWeb,isSms,isMob,isEmail,gid,gsId,gName,gQuantity,limitLower,limitUpper,warningType,isExtend,remark,operateTime) VALUES(@currentDate,@accId,@userRealName,@alertStatus,@alertTime,@isWeb,@isSms,@isMob,@isEmail,@gid,@gsId,@gName,@gQuantity,@limitLower,@limitUpper,@warningType,@isExtend,@remark,@operateTime);");
            strSql.Append(" end");
            var result = CommonHelpers.DapperHelper.Execute(strSql.ToString(),
                                                            new
            {
                currentDate  = DateTime.Now.AddDays(-1).Date,
                accId        = goodInfo.AccId,
                insertDate   = DateTime.Now.AddDays(-1).Date,
                userRealName = stockalertInfo.UserRealName,
                alertStatus  = stockalertInfo.AlertStatus,
                alertTime    = stockalertInfo.AlertTime,
                isWeb        = stockalertInfo.IsWeb,
                isSms        = stockalertInfo.IsSms,
                isMob        = stockalertInfo.IsMob,
                isEmail      = stockalertInfo.IsEmail,
                gid          = goodInfo.Gid,
                gsId         = goodInfo.Gsid,
                gName        = goodInfo.GName,
                gQuantity    = goodInfo.GQuantity,
                limitLower   = goodInfo.LimitLower,
                limitUpper   = goodInfo.LimitUpper,
                warningType  = goodInfo.WarningType,
                isExtend     = goodInfo.IsExtend,
                remark       = "",
                operateTime  = DateTime.Now
            });

            return(result);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 加载商品信息
        /// </summary>
        /// <param name="fId"></param>
        private void InitGoodsInfo(int goodsId)
        {
            GoodsInfoModel goodsInfo = RequestStar.GetGoodsInfo(goodsId);

            if (goodsInfo != null)
            {
                txtBidPrice.Text   = goodsInfo.BidPrice.ToString();
                txtDiscount.Text   = goodsInfo.Discount.ToString();
                txtGoodsName.Text  = goodsInfo.GoodsName;
                oldName            = goodsInfo.GoodsName;
                txtGoodsNo.Text    = goodsInfo.GoodsNo;
                txtGoodsPYNo.Text  = goodsInfo.GoodsPYNo;
                txtGoodsSName.Text = goodsInfo.GoodsSName;
                string gtypeName = RequestStar.GetGoodsType(goodsInfo.GTypeId).GTypeName;
                txtGoodsType.Text = gtypeName;
                gTypeInfo         = new GoodsTypeInfoModel()
                {
                    GTypeId   = goodsInfo.GTypeId,
                    GTypeName = gtypeName
                };
                txtGoodTXNo.Text    = goodsInfo.GoodsTXNo;
                txtLowPrice.Text    = goodsInfo.LowPrice.ToString();
                txtPrePrice.Text    = goodsInfo.PrePrice.ToString();
                txtRemark.Text      = goodsInfo.Remark;
                txtRetailPrice.Text = goodsInfo.RetailPrice.ToString();
                if (goodsInfo.IsStopped == 1)
                {
                    chkStop.Checked = true;
                }
                cboGoodsProperties.Text = goodsInfo.GProperties;
                cboGUnits.Text          = goodsInfo.GUnit;
                if (!string.IsNullOrEmpty(goodsInfo.GoodsPic))
                {
                    string picPath = Application.StartupPath + "/" + goodsInfo.GoodsPic;
                    picGoods.ImageLocation = picPath;
                    oldPic = picPath;
                }
            }
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> AddGoods([FromServices] IHostingEnvironment env, GoodsInfoModel model, IList <IFormFile> imgfiles, IList <IFormFile> skufiles)
        {
            const string fileFilt   = ".gif|.jpg|.jpeg|.png|.webp|";
            const string saveSuffix = ".jpeg";

            foreach (var file in Request.Form.Files)
            {
                var fileExtension = Path.GetExtension(file.FileName);
                if (fileExtension == null)
                {
                    return(Json(new StatusMessageData(StatusMessageType.Error, "上传的文件没有后缀")));
                }
                if (fileFilt.IndexOf(fileExtension.ToLower(), StringComparison.Ordinal) <= -1)
                {
                    return(Json(new StatusMessageData(StatusMessageType.Error, "上传的文件不是图片")));
                }
                if (file.Length > 1024 * 1024 * 2)
                {
                    return(Json(new StatusMessageData(StatusMessageType.Error, "上传的文件不能大于2M")));
                }
            }

            var skuArr = Request.Get <string>("SkuArr");

            string[] skuNumArr = skuArr.Split(',');

            GoodsInfo infoModel = model.AsGoodsInfo();

            infoModel.Status      = (int)GoodsInfoStatus.Shelves;
            infoModel.IsEnable    = false;
            infoModel.DateCreated = DateTime.Now;
            infoModel.Userid      = UserContext.CurrentUser.UserId;

            List <GoodsSkuInfo>         skuModels = new List <GoodsSkuInfo>();
            List <GoodsInRotationImage> imgModels = new List <GoodsInRotationImage>();

            var index = 0;

            foreach (var skuNum in skuNumArr)
            {
                GoodsSkuInfo goodsSkuInfo = new GoodsSkuInfo();
                goodsSkuInfo.SkuName          = Request.Get <string>($"SkuName{skuNum}");
                goodsSkuInfo.SkuOriginalPrice = Request.Get <string>($"SkuOriginalPrice{skuNum}").AsDecimal();
                goodsSkuInfo.SkuMaketPrice    = Request.Get <decimal>($"SkuMaketPrice{skuNum}");
                goodsSkuInfo.SkuFactoryPrice  = Request.Get <decimal>($"SkuFactoryPrice{skuNum}");
                goodsSkuInfo.SkuVipPrice      = Request.Get <string>($"SkuVipPrice{skuNum}").AsDecimal();
                goodsSkuInfo.Stock            = Request.Get <string>($"Stock{skuNum}").AsInt();
                goodsSkuInfo.Number           = Request.Get <int>($"Number{skuNum}");
                goodsSkuInfo.IsDefault        = Request.Get <bool>($"IsDefault{skuNum}");
                goodsSkuInfo.Status           = (int)GoodsSkuInfoStatus.Show;
                IFormFile file = skufiles[index];
                goodsSkuInfo.SkuImage = await Utility.SaveImage(env, file, Request, saveSuffix);

                if (index == 0)
                {
                    infoModel.GoodsPrice     = goodsSkuInfo.SkuMaketPrice;
                    infoModel.GoodsRealPrice = goodsSkuInfo.SkuFactoryPrice;
                }

                skuModels.Add(goodsSkuInfo);
                index++;
            }


            foreach (var img in imgfiles)
            {
                GoodsInRotationImage imgModel = new GoodsInRotationImage();
                var       imgIndex            = imgfiles.IndexOf(img);
                IFormFile file = imgfiles[imgIndex];
                imgModel.Number             = imgIndex + 1;
                imgModel.GoodsRotationImage = await Utility.SaveImage(env, file, Request, saveSuffix);

                if (imgIndex == 0)
                {
                    infoModel.ImageUrl = imgModel.GoodsRotationImage;
                }
                imgModels.Add(imgModel);
            }
            var detailsImg = Request.Get <string>("goodsDetailsImg");

            string[] detailsImgArr = detailsImg.Split(',');

            if (goodsInfoService.ReleaseGoods(infoModel, skuModels, imgModels, detailsImgArr, UserContext.CurrentUser.UserId))
            {
                return(Json(new StatusMessageData(StatusMessageType.Success, "发布成功")));
            }
            return(Json(new StatusMessageData(StatusMessageType.Error, "发布失败")));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 保存按钮提交
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsbtnSave_Click(object sender, EventArgs e)
        {
            Action act = () =>
            {
                //获取信息
                string  goodsName       = txtGoodsName.Text.Trim();
                string  goodsNo         = txtGoodsNo.Text.Trim();
                string  goodsPYNo       = txtGoodsPYNo.Text.Trim();
                int     gTypeId         = gTypeInfo == null ? 0 : gTypeInfo.GTypeId;
                string  goodsProperties = cboGoodsProperties.Text;
                string  goodsSName      = txtGoodsSName.Text.Trim();
                string  goodsTXNo       = txtGoodTXNo.Text.Trim();
                string  gUnit           = cboGUnits.Text.Trim();
                decimal rPrice          = txtRetailPrice.Text.Trim().GetDecimal();
                decimal lPrice          = txtLowPrice.Text.Trim().GetDecimal();
                decimal pPrice          = txtPrePrice.Text.Trim().GetDecimal();
                decimal bPrice          = txtBidPrice.Text.Trim().GetDecimal();
                int     disCount        = txtDiscount.Text.Trim().GetInt();
                if (disCount == 0)
                {
                    disCount = 100;
                }
                string remark   = txtRemark.Text.Trim();
                string goodsPic = null;
                if (!string.IsNullOrEmpty(picGoods.ImageLocation))
                {
                    goodsPic = GetImgPath();
                }
                int isStopped = chkStop.Checked ? 1 : 0;
                //判断
                if (string.IsNullOrEmpty(goodsName))
                {
                    MsgBoxHelper.MsgErrorShow("请输入商品名称");
                    txtGoodsName.Focus();
                    return;
                }
                else if (fModel.ActType == 1 || (!string.IsNullOrEmpty(oldName) && oldName != goodsName))
                {
                    if (RequestStar.ExistGoodsName(goodsName))
                    {
                        MsgBoxHelper.MsgErrorShow("商品名称已存在!");
                        txtGoodsName.Focus();
                        return;
                    }
                }
                if (gTypeId == 0)
                {
                    MsgBoxHelper.MsgErrorShow("请选择商品类别!");
                    return;
                }
                //封装商品信息
                GoodsInfoModel goodsInfo = new GoodsInfoModel()
                {
                    GoodsId     = fModel.FId,
                    GoodsName   = goodsName,
                    GoodsNo     = goodsNo,
                    GoodsPYNo   = goodsPYNo,
                    GProperties = goodsProperties,
                    GTypeId     = gTypeId,
                    GoodsTXNo   = goodsTXNo,
                    GoodsSName  = goodsSName,
                    Remark      = remark,
                    GUnit       = gUnit,
                    RetailPrice = rPrice,
                    LowPrice    = lPrice,
                    PrePrice    = pPrice,
                    BidPrice    = bPrice,
                    Discount    = disCount,
                    GoodsPic    = goodsPic,
                    IsStopped   = isStopped,
                    Creator     = fModel.UName
                };
                //执行
                bool bl = false;
                bl = fModel.ActType == 1 ? RequestStar.AddGoodsInfo(goodsInfo) : RequestStar.UpdateGoodsInfo(goodsInfo);
                string actMsg   = fModel.ActType == 1 ? "添加" : "修改";
                string titleMsg = $"{actMsg}商品信息";
                string sucType  = bl ? "成功" : "失败";
                string msg      = $"商品信息{actMsg} {sucType}";
                if (bl)
                {
                    MsgBoxHelper.MsgBoxShow(titleMsg, msg);
                    this.ReLoadHandler?.Invoke();
                }
                else
                {
                    MsgBoxHelper.MsgErrorShow(msg);
                    return;
                }
            };

            act.TryCatch("商品信息提交异常!");
        }
Ejemplo n.º 15
0
        public ApiResultModel SetOnSale(GoodsInfoModel model)
        {
            ApiResultModel resultModel = new ApiResultModel();

            try
            {
                //获取当前商家用户
                IShopUserBLL userBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

                T_ShopUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);
                //如果商家用户存在
                if (user != null)
                {
                    //如果验证Token不通过或已过期
                    if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token)
                    {
                        resultModel.Msg = APIMessage.TOKEN_INVALID;
                        return(resultModel);
                    }
                    //更新最近登录时间和Token失效时间
                    user.LatelyLoginTime  = DateTime.Now;
                    user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid")));
                    userBll.Update(user);

                    if (model.Id.HasValue)
                    {
                        IShopSaleBLL shopSaleBll = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL");

                        var goods = shopSaleBll.GetEntity(g => g.Id == model.Id.Value);
                        //修改商品上/下架
                        if (goods != null)
                        {
                            goods.InSales = model.InSales;

                            if (goods.InSales == 0)
                            {
                                goods.UnShelveTime = DateTime.Now;
                            }
                            else
                            {
                                goods.CreateTime = DateTime.Now;
                            }

                            shopSaleBll.Update(goods);
                        }
                        else
                        {
                            resultModel.Msg = "不存在当前商品分类";
                        }
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }
Ejemplo n.º 16
0
        public ApiResultModel DelGoods(GoodsInfoModel model)
        {
            ApiResultModel resultModel = new ApiResultModel();

            try
            {
                //获取当前商家用户
                IShopUserBLL userBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

                T_ShopUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);
                //如果商家用户存在
                if (user != null)
                {
                    //如果验证Token不通过或已过期
                    if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token)
                    {
                        resultModel.Msg = APIMessage.TOKEN_INVALID;
                        return(resultModel);
                    }
                    //更新最近登录时间和Token失效时间
                    user.LatelyLoginTime  = DateTime.Now;
                    user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid")));
                    userBll.Update(user);

                    if (model.Id.HasValue)
                    {
                        IShopSaleBLL shopSaleBll = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL");

                        var goods = shopSaleBll.GetEntity(g => g.Id == model.Id.Value);

                        if (goods == null)
                        {
                            resultModel.Msg = "该商品不存在";
                        }
                        else
                        {
                            if (goods.OrderDetails.Count > 0)
                            {
                                resultModel.Msg = "该商品已被订购,无法删除";
                            }
                            else
                            {
                                var imagePath    = goods.ImgPath;
                                var imgThumbnail = goods.ImgThumbnail;

                                shopSaleBll.Delete(goods);

                                if (!string.IsNullOrWhiteSpace(imagePath))
                                {
                                    if (imagePath.Contains(";"))
                                    {
                                        foreach (var path in imagePath.Split(';'))
                                        {
                                            DelFile(path);
                                        }
                                    }
                                    else
                                    {
                                        DelFile(imagePath);
                                    }
                                }

                                if (!string.IsNullOrWhiteSpace(imgThumbnail))
                                {
                                    if (imgThumbnail.Contains(";"))
                                    {
                                        foreach (var path in imgThumbnail.Split(';'))
                                        {
                                            DelFile(path);
                                        }
                                    }
                                    else
                                    {
                                        DelFile(imgThumbnail);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }
Ejemplo n.º 17
0
        public ApiResultModel EditGoods(GoodsInfoModel model)
        {
            ApiResultModel resultModel = new ApiResultModel();

            try
            {
                //获取当前商家用户
                IShopUserBLL userBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

                T_ShopUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);
                //如果商家用户存在
                if (user != null)
                {
                    //如果验证Token不通过或已过期
                    if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token)
                    {
                        resultModel.Msg = APIMessage.TOKEN_INVALID;
                        return(resultModel);
                    }
                    //更新最近登录时间和Token失效时间
                    user.LatelyLoginTime  = DateTime.Now;
                    user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid")));
                    userBll.Update(user);

                    if (model.Id.HasValue)
                    {
                        IShopSaleBLL shopSaleBll = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL");

                        var goods = shopSaleBll.GetEntity(g => g.Id == model.Id.Value);

                        //修改商品分类
                        if (goods != null)
                        {
                            //基础信息
                            goods.Title           = model.Name;
                            goods.Content         = model.Content;
                            goods.Price           = model.Price;
                            goods.RemainingAmout  = model.RemainingAmount;
                            goods.GoodsCategoryId = model.GoodCategoryId;

                            //图片和压缩图
                            var sourceImgList           = goods.ImgPath == null ? null : goods.ImgPath.Split(';').ToList();
                            var sourceImgThumbnailArray = goods.ImgThumbnail == null ? null : goods.ImgThumbnail.Split(';').ToArray();

                            var remainingImgList          = goods.ImgPath == null ? new List <string>() : goods.ImgPath.Split(';').ToList();
                            var remainingImgThumbnailList = goods.ImgThumbnail == null ? new List <string>() : goods.ImgThumbnail.Split(';').ToList();


                            //要删除的缩略图列表
                            var delImgThumbnailList = new List <string>();

                            if (sourceImgList != null)
                            {
                                //对要删除的图片列表进行删除
                                if (!string.IsNullOrWhiteSpace(model.delPicList))
                                {
                                    foreach (var path in model.delPicList.Split(';'))
                                    {
                                        int index = sourceImgList.FindIndex(m => m == path);

                                        if (index < sourceImgThumbnailArray.Count())
                                        {
                                            delImgThumbnailList.Add(sourceImgThumbnailArray[index]);
                                        }

                                        remainingImgList.Remove(path);
                                        DelFile(path);
                                    }
                                }
                            }


                            foreach (var path in delImgThumbnailList)
                            {
                                remainingImgThumbnailList.Remove(path);
                                DelFile(path);
                            }

                            var strRemainedImg = "";

                            foreach (var item in remainingImgList)
                            {
                                if (!string.IsNullOrEmpty(item.Trim()))
                                {
                                    strRemainedImg = strRemainedImg + item + ";";
                                }
                            }

                            var strReminedThumbnailImg = "";

                            foreach (var item in remainingImgThumbnailList)
                            {
                                if (!string.IsNullOrEmpty(item.Trim()))
                                {
                                    strReminedThumbnailImg = strReminedThumbnailImg + item + ";";
                                }
                            }

                            //图片上传
                            if (!string.IsNullOrEmpty(model.PicList))
                            {
                                //文件资源保存目录
                                string dir = HttpContext.Current.Server.MapPath(ConstantParam.SHOP_Sales);

                                if (!Directory.Exists(dir))
                                {
                                    Directory.CreateDirectory(dir);
                                }

                                var    fileName = DateTime.Now.ToFileTime().ToString() + ".zip";
                                string filepath = Path.Combine(dir, fileName);

                                using (FileStream fs = new FileStream(filepath, FileMode.Create))
                                {
                                    using (BinaryWriter bw = new BinaryWriter(fs))
                                    {
                                        byte[] datas = Convert.FromBase64String(model.PicList);
                                        bw.Write(datas);
                                        bw.Close();
                                    }
                                }

                                var imgZipParth = PropertyUtils.UnZip(filepath, dir, ConstantParam.SHOP_Sales);
                                //图片集路径保存
                                goods.ImgPath = strRemainedImg + imgZipParth;

                                StringBuilder imgsSB = new StringBuilder();
                                //生成缩略图保存
                                foreach (var path in imgZipParth.Split(';'))
                                {
                                    string thumpFile = DateTime.Now.ToFileTime().ToString() + ".jpg";
                                    string thumpPath = Path.Combine(HttpContext.Current.Server.MapPath(ConstantParam.SHOP_Sales_ThumIMG), thumpFile);
                                    PropertyUtils.getThumImage(Path.Combine(HttpContext.Current.Server.MapPath(path)), 18, 3, thumpPath);

                                    imgsSB.Append(ConstantParam.SHOP_Sales_ThumIMG + "/" + thumpFile + ";");
                                }

                                goods.ImgThumbnail = imgsSB.ToString();
                                goods.ImgThumbnail = strReminedThumbnailImg + goods.ImgThumbnail.Substring(0, goods.ImgThumbnail.Length - 1);
                            }
                            else
                            {
                                goods.ImgPath      = strRemainedImg;
                                goods.ImgThumbnail = strReminedThumbnailImg;
                            }

                            shopSaleBll.Update(goods);
                        }
                        else
                        {
                            resultModel.Msg = "不存在当前商品";
                        }
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }
Ejemplo n.º 18
0
        public ApiResultModel AddGoods(GoodsInfoModel model)
        {
            ApiResultModel resultModel = new ApiResultModel();

            try
            {
                //获取当前商家用户
                IShopUserBLL userBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

                T_ShopUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);
                //如果商家用户存在
                if (user != null)
                {
                    //如果验证Token不通过或已过期
                    if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token)
                    {
                        resultModel.Msg = APIMessage.TOKEN_INVALID;
                        return(resultModel);
                    }
                    //更新最近登录时间和Token失效时间
                    user.LatelyLoginTime  = DateTime.Now;
                    user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid")));
                    userBll.Update(user);

                    //商品分类实例化
                    T_ShopSale goods = new T_ShopSale()
                    {
                        Title           = model.Name,
                        Content         = model.Content,
                        CreateTime      = DateTime.Now,
                        GoodsCategoryId = model.GoodCategoryId,
                        Price           = model.Price,
                        RemainingAmout  = model.RemainingAmount,
                        InSales         = 1
                    };

                    //话题文件资源保存目录
                    string dir = HttpContext.Current.Server.MapPath(ConstantParam.SHOP_Sales);

                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    //图片上传
                    if (!string.IsNullOrEmpty(model.PicList))
                    {
                        var    fileName = DateTime.Now.ToFileTime().ToString() + ".zip";
                        string filepath = Path.Combine(dir, fileName);

                        using (FileStream fs = new FileStream(filepath, FileMode.Create))
                        {
                            using (BinaryWriter bw = new BinaryWriter(fs))
                            {
                                byte[] datas = Convert.FromBase64String(model.PicList);
                                bw.Write(datas);
                                bw.Close();
                            }
                        }
                        //图片集路径保存
                        goods.ImgPath = PropertyUtils.UnZip(filepath, dir, ConstantParam.SHOP_Sales);

                        StringBuilder imgsSB = new StringBuilder();
                        //生成缩略图保存
                        foreach (var path in goods.ImgPath.Split(';'))
                        {
                            string thumpFile = DateTime.Now.ToFileTime() + ".jpg";
                            string thumpPath = Path.Combine(HttpContext.Current.Server.MapPath(ConstantParam.SHOP_Sales_ThumIMG), thumpFile);
                            PropertyUtils.getThumImage(Path.Combine(HttpContext.Current.Server.MapPath(path)), 18, 3, thumpPath);
                            imgsSB.Append(ConstantParam.SHOP_Sales_ThumIMG + "/" + thumpFile + ";");
                        }

                        goods.ImgThumbnail = imgsSB.ToString();
                        goods.ImgThumbnail = goods.ImgThumbnail.Substring(0, goods.ImgThumbnail.Length - 1);
                    }

                    //保存商品
                    IShopSaleBLL goodsBLL = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL");

                    goodsBLL.Save(goods);

                    //绿色直供推送
                    if (model.IsPush == 1)
                    {
                        IShopBLL shopBLL = BLLFactory <IShopBLL> .GetBLL("ShopBLL");

                        string shopName = shopBLL.GetEntity(s => s.Id == model.ShopId).ShopName;

                        //推送给业主客户端
                        IUserPushBLL userPushBLL = BLLFactory <IUserPushBLL> .GetBLL("UserPushBLL");

                        var registrationIds = userPushBLL.GetList(p => !string.IsNullOrEmpty(p.RegistrationId)).Select(p => p.RegistrationId).ToArray();

                        string alert = shopName + "的商品" + goods.Title + "上架了";
                        bool   flag  = PropertyUtils.SendPush("商品上架", alert, ConstantParam.MOBILE_TYPE_OWNER, registrationIds);
                        if (!flag)
                        {
                            resultModel.Msg = "推送发生异常";
                        }
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch (Exception ex)
            {
                PropertyUtils.WriteLogInfo("test");
                PropertyUtils.WriteLogError(ex);
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }
Ejemplo n.º 19
0
        public ApiResultModel GetGoods([FromUri] GoodsInfoModel model)
        {
            ApiResultModel resultModel = new ApiResultModel();

            try
            {
                //获取当前商家用户
                IShopUserBLL userBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

                T_ShopUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);
                //如果商家用户存在
                if (user != null)
                {
                    //如果验证Token不通过或已过期
                    if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token)
                    {
                        resultModel.Msg = APIMessage.TOKEN_INVALID;
                        return(resultModel);
                    }
                    //更新最近登录时间和Token失效时间
                    user.LatelyLoginTime  = DateTime.Now;
                    user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid")));
                    userBll.Update(user);

                    if (model.Id.HasValue)
                    {
                        IShopSaleBLL shopSaleBll = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL");

                        var goods = shopSaleBll.GetEntity(g => g.Id == model.Id.Value);
                        //商品详情
                        if (goods != null)
                        {
                            resultModel.result = new
                            {
                                Name              = goods.Title,
                                Content           = goods.Content,
                                Price             = goods.Price,
                                RemaintAmount     = goods.RemainingAmout,
                                GoodsCategoryId   = goods.GoodsCategoryId,
                                GoodsCategoryName = goods.GoodsCategory.Name,
                                ImgPath           = goods.ImgPath,
                                ImgThumbnail      = goods.ImgThumbnail
                            };
                        }
                        else
                        {
                            resultModel.Msg = "不存在当前商品";
                        }
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }