コード例 #1
0
        /// <summary>
        /// 删除产品列表
        /// </summary>
        public void DelGoodsList()
        {
            var gids = GetString("gids");

            var gidList = Utility.GetListint(gids);

            if (gidList.Count == 0)
            {
                ReturnErrorMsg("参数有误");
                return;
            }
            var wheresql    = string.Format(" and a.Id in({0})", gids);
            var goodsresult = GoodsHelper.GetGoodsList(CurSellerId, wheresql);

            if (goodsresult.Results.Count != gidList.Count)
            {
                ReturnErrorMsg("没有权限删除其他商户产品或产品不存在");
                return;
            }
            var data = new List <ChangeCountItem>();

            foreach (var goods in goodsresult.Results)
            {
                var item = data.FirstOrDefault(o => o.Id == goods.Cid);
                if (item == null)
                {
                    data.Add(new ChangeCountItem()
                    {
                        Id = goods.Cid, Change = -1
                    });
                }
                else
                {
                    item.Change--;
                }
            }
            bool ur = true;

            if (data.Count > 0)
            {
                ur = GoodsCategoriesHelper.UpdateGoodsCategoriesCount(data);
            }
            if (ur && GoodsHelper.DelGoodsList(CurSellerId, gids))
            {
                ReturnCorrectMsg("删除成功");
            }
            else
            {
                ReturnErrorMsg("删除失败");
            }
        }