예제 #1
0
        public object Do_InputCart(BaseApi baseApi)
        {
            InputCartParam inputCartParam = JsonConvert.DeserializeObject <InputCartParam>(baseApi.param.ToString());

            if (inputCartParam == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }
            MallDao  mallDao  = new MallDao();
            OrderDao orderDao = new OrderDao();
            string   memberId = Utils.GetMemberID(baseApi.token);
            Goods    goods    = mallDao.GetGoodsByGoodsId(inputCartParam.goodsId);

            if (inputCartParam.goodsNum < 0)
            {
                throw new ApiException(CodeMessage.ErrorNum, "ErrorNum");
            }

            if (goods == null)
            {
                throw new ApiException(CodeMessage.InvalidGoods, "InvalidGoods");
            }

            if (goods.goodsStock < inputCartParam.goodsNum)
            {
                throw new ApiException(CodeMessage.NotEnoughGoods, "NotEnoughGoods");
            }

            CartGoods cartGoods = orderDao.GetCartGoodsByGoodsId(memberId, inputCartParam.goodsId);

            if (cartGoods == null)
            {
                if (!orderDao.InsertCart(memberId, inputCartParam.goodsId, inputCartParam.goodsNum))
                {
                    throw new ApiException(CodeMessage.UpdateCartError, "UpdateCartError");
                }
            }
            else
            {
                if (!orderDao.UpdateAddCart(cartGoods.cartId, inputCartParam.goodsNum))
                {
                    throw new ApiException(CodeMessage.UpdateCartError, "UpdateCartError");
                }
            }

            return("");
        }
예제 #2
0
        public object Do_GetGoods(BaseApi baseApi)
        {
            GetGoodsParam getGoodsParam = JsonConvert.DeserializeObject <GetGoodsParam>(baseApi.param.ToString());

            if (getGoodsParam == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }

            Goods goods = Utils.GetCache <Goods>(getGoodsParam);

            if (goods == null)
            {
                MallDao mallDao = new MallDao();
                goods        = mallDao.GetGoodsByGoodsId(getGoodsParam.goodsId);
                goods.Unique = getGoodsParam.GetUnique();
                Utils.SetCache(goods, 0, 1, 0);
            }

            return(goods);
        }