Example #1
0
        /// <summary>
        /// 添加商品至购物车
        /// </summary>
        /// <returns></returns>
        public ActionResult AddGoodsCarData()
        {
            returnObj = new Return_Msg_APP();
            string attrSpacStr = Context.GetRequest("attrspacstr", "");
            //商品规格(格式):规格1:属性1 规格2:属性2 如:(颜色:白色 尺码:M)
            string specInfo = Context.GetRequest("specinfo", "");
            string specImg  = Context.GetRequest("specimg", "");
            int    goodId   = Context.GetRequestInt("goodid", 0);
            int    userId   = Context.GetRequestInt("userid", 0);
            int    qty      = Context.GetRequestInt("qty", 0);
            //立即购买,1:立即购买,0:添加到购物车
            int gotoBuy = Context.GetRequestInt("gotobuy", 2);

            if (qty <= 0)
            {
                returnObj.Msg = "数量必须大于0";
                return(Json(returnObj));
            }

            PlatChildGoods good = PlatChildGoodsBLL.SingleModel.GetModel(goodId);

            if (good == null)
            {
                returnObj.Msg = "未找到该商品";
                return(Json(returnObj));
            }
            PlatStore store = PlatStoreBLL.SingleModel.GetModelByAId(good.AId);

            if (store == null)
            {
                returnObj.Msg = "店铺已关闭";
                return(Json(returnObj));
            }
            if (!string.IsNullOrWhiteSpace(attrSpacStr))
            {
                //log4net.LogHelper.WriteInfo(this.GetType(),$"{JsonConvert.SerializeObject(good.GASDetailList)},{attrSpacStr}");
                if (!good.GASDetailList.Any(x => x.Id.Equals(attrSpacStr)))
                {
                    returnObj.Msg = "商品已过期";
                    return(Json(returnObj));
                }
            }
            if (!(good.State == 1 && good.Tag == 1))
            {
                returnObj.Msg = "无法添加失效商品";
                return(Json(returnObj));
            }
            C_UserInfo userInfo = C_UserInfoBLL.SingleModel.GetModel(userId);

            if (userInfo == null)
            {
                returnObj.Msg = "用户不存在";
                return(Json(returnObj));
            }

            PlatChildGoodsCart car = PlatChildGoodsCartBLL.SingleModel.GetModelBySpec(userInfo.Id, goodId, attrSpacStr, 0);
            //商品价格
            int price = Convert.ToInt32(good.Price * 100);

            price = Convert.ToInt32(!string.IsNullOrWhiteSpace(attrSpacStr) ? good.GASDetailList.First(x => x.Id.Equals(attrSpacStr)).Price * 100 : good.Price * 100);

            if (car == null || gotoBuy == 1)
            {
                car = new PlatChildGoodsCart
                {
                    //FoodId = store.Id,
                    StoreId   = store.Id,
                    GoodsName = good.Name,
                    GoodsId   = good.Id,
                    SpecIds   = attrSpacStr,
                    Count     = qty,
                    Price     = price,
                    SpecInfo  = specInfo,
                    SpecImg   = specImg,//规格图片
                    UserId    = userInfo.Id,
                    AddTime   = DateTime.Now,
                    State     = 0,
                    GoToBuy   = gotoBuy,
                    AId       = good.AId,
                };

                //加入购物车
                int id = Convert.ToInt32(PlatChildGoodsCartBLL.SingleModel.Add(car));
                if (id > 0)
                {
                    int cartcount = PlatChildGoodsCartBLL.SingleModel.GetCartGoodsCountByUserId(userInfo.Id);
                    returnObj.Msg     = "成功";
                    returnObj.dataObj = new { id = id, count = cartcount };
                    returnObj.isok    = true;
                    return(Json(returnObj));
                }
            }
            else
            {
                car.Count += qty;
                if (PlatChildGoodsCartBLL.SingleModel.Update(car, "Count"))
                {
                    int cartcount = PlatChildGoodsCartBLL.SingleModel.GetCartGoodsCountByUserId(userInfo.Id);
                    returnObj.dataObj = new { id = car.Id, count = cartcount };
                    returnObj.Msg     = "成功";
                    returnObj.isok    = true;
                    return(Json(returnObj));
                }
            }

            returnObj.Msg = "失败";
            return(Json(returnObj));
        }
Example #2
0
        /// <summary>
        /// 是否已评论
        /// </summary>
        /// <param name="xcxtemplateType">模板类型</param>
        /// <param name="goodsType">商品类型</param>
        /// <param name="goodsId">商品ID(拼团entgoods表ID,团购groups表ID,普通商品entgoods表ID,砍价bargain表ID)</param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool IsComment(int xcxtemplateType, int goodsType, int goodsId, int orderId, int aid)
        {
            bool iscomment = false;

            switch (xcxtemplateType)
            {
            case (int)TmpType.小程序专业模板:
                switch (goodsType)
                {
                case (int)EntGoodsType.团购商品:
                    GroupUser groupuser = GroupUserBLL.SingleModel.GetModel(orderId);
                    if (groupuser == null)
                    {
                        return(true);
                    }
                    iscomment = ExitModel(aid, groupuser.ObtainUserId, groupuser.GroupId, orderId, goodsType);
                    groupuser.IsCommentting = true;
                    GroupUserBLL.SingleModel.Update(groupuser, "IsCommentting");
                    break;

                case (int)EntGoodsType.拼团产品:
                    EntGoodsCart gentgoodscart = EntGoodsCartBLL.SingleModel.GetModelByGoodsId(orderId, goodsId);
                    if (gentgoodscart == null)
                    {
                        return(true);
                    }
                    iscomment = ExitModel(aid, gentgoodscart.UserId, goodsId, orderId, goodsType);
                    gentgoodscart.IsCommentting = true;
                    EntGoodsCartBLL.SingleModel.Update(gentgoodscart, "IsCommentting");
                    break;

                case (int)EntGoodsType.普通产品:
                    EntGoodsCart entgoodscart = EntGoodsCartBLL.SingleModel.GetModelByGoodsId(orderId, goodsId);
                    if (entgoodscart == null)
                    {
                        return(true);
                    }
                    iscomment = ExitModel(aid, entgoodscart.UserId, goodsId, orderId, goodsType);
                    entgoodscart.IsCommentting = true;
                    EntGoodsCartBLL.SingleModel.Update(entgoodscart, "IsCommentting");
                    break;

                case (int)EntGoodsType.价产品:
                    BargainUser bargainuser = BargainUserBLL.SingleModel.GetModel(orderId);
                    if (bargainuser == null)
                    {
                        return(true);
                    }
                    iscomment = ExitModel(aid, bargainuser.UserId, bargainuser.BId, orderId, goodsType);
                    bargainuser.IsCommentting = true;
                    BargainUserBLL.SingleModel.Update(bargainuser, "IsCommentting");
                    break;
                }
                break;

            case (int)TmpType.小未平台子模版:

                PlatChildGoodsCart platChildGoodsCart = PlatChildGoodsCartBLL.SingleModel.GetModelByGoodsId(orderId, goodsId);
                if (platChildGoodsCart == null)
                {
                    return(true);
                }
                iscomment = ExitModel(aid, platChildGoodsCart.UserId, goodsId, orderId, goodsType);
                platChildGoodsCart.IsCommentting = true;
                PlatChildGoodsCartBLL.SingleModel.Update(platChildGoodsCart, "IsCommentting");
                break;
            }

            return(iscomment);
        }