Example #1
0
        public ResultMessage UpdShoppingCartQuantity(int commodityId, int shoppingCartId, int quantity)
        {
            try
            {
                //TransactionHelper.BeginTransaction();
                var ShoppingCart = ShoppingCartService.GetById(shoppingCartId);
                if (ShoppingCart != null)
                {
                    var commodity = JuMeiMallService.GetById(commodityId);
                    if (commodity != null)//检测商品信息
                    {
                        if (commodity.commodityState == CommodityStates.soldOut)
                        {
                            return new ResultMessage()
                                   {
                                       Code = -1, Msg = "商品已下架,请重新生成订单!"
                                   }
                        }
                        ;
                    }
                    else
                    {
                        return(new ResultMessage()
                        {
                            Code = -1, Msg = "商品不存在,请重新生成购物车!"
                        });
                    }



                    if (commodity.commodityInventory < quantity)
                    {
                        ShoppingCart.quantity = commodity.commodityInventory;
                        ShoppingCartService.Update(ShoppingCart);
                        TransactionHelper.Commit();
                        return(new ResultMessage()
                        {
                            Code = -1, Msg = string.Format("{0}库存不足,此商品库存剩余{1}件", commodity.commodityName, commodity.commodityInventory), quantity = commodity.commodityInventory
                        });
                    }

                    ShoppingCart.quantity = quantity;
                    ShoppingCartService.Update(ShoppingCart);
                }
                // TransactionHelper.Commit();
                return(new ResultMessage()
                {
                    Code = 0, Msg = "购物车修改数量成功"
                });
            }
            catch (Exception ex)
            {
                logService.Insert(ex);
                return(new ResultMessage()
                {
                    Code = -1, Msg = "购物车数量修改-网络错误,请稍后重试..."
                });
            }
        }
Example #2
0
        /// <summary>
        /// 获取购物车商品信息
        /// </summary>
        /// <param name="commodityId"></param>
        /// <param name="type">1:图像 2:销售价 3:原价 4:名称 5:运费</param>
        /// <returns></returns>
        public T GetByComId <T>(int commodityId, int type = 0)
        {
            var commodity = JuMeiMallService.GetById(commodityId);

            if (commodity != null)
            {
                if (type == 1)
                {
                    object Image = commodity.images;

                    return((T)Image);
                }
                else if (type == 2)
                {
                    TotalAmt += commodity.commodityPrice;//购物车总金额
                    object commodityPrice = commodity.commodityPrice;
                    return((T)commodityPrice);
                }
                else if (type == 3)
                {
                    object commodityPrice1 = commodity.commodityPrice1;
                    return((T)commodityPrice1);
                }
                else if (type == 4)
                {
                    object commodityName = commodity.commodityName;
                    return((T)commodityName);
                }
                else if (type == 5)
                {
                    if (commodity.commodityFreight > Freight)//运费
                    {
                        Freight = commodity.commodityFreight;
                    }
                    object commodityFreight = commodity.commodityFreight;
                    return((T)commodityFreight);
                }
            }
            object flag = 0;

            return((T)flag);
        }
Example #3
0
        //public ResultMessage SaveOrderDetailsSpecification(int commodityId, string orderNo, string liuyanContent)
        //{

        //    try
        //    {
        //        TransactionHelper.BeginTransaction();
        //        var model = OrderDetailService.GetBycommodityIdAndOrderNo(commodityId, orderNo);
        //        if (model !=null)
        //        {
        //            model.remark = liuyanContent;
        //            OrderDetailService.Update(model);
        //            TransactionHelper.Commit();
        //            return new ResultMessage() { Code = 0, Msg = "留言录入成功!" };
        //        }
        //        return new ResultMessage() { Code = -1, Msg = "留言录入失败,请稍后重试!" };



        //    }
        //    catch (Exception ex)
        //    {
        //        logService.Insert(ex);
        //        return new ResultMessage() { Code = -1, Msg = "留言录入失败,请稍后重试!" };
        //    }



        //}

        public ResultMessage SaveGDtlOrder(int commodityId, int quantity, int userId, string Specification)
        {
            var tran = TransactionHelper.BeginTransaction();

            try
            {
                decimal amount = 0;
                decimal point  = 0;
                ///订单
                Order  model       = new Order();
                string dateTime    = string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now);
                var    GetUserInfo = MembershipService.GetUserById(userId);

                if (GetUserInfo != null)
                {
                    //accountId = GetUserInfo.accountId;
                    ///订单
                    model.orderNo = dateTime + userId;
                }
                bool isFirs = false;
                var  Firs   = OrderService.MicroMallQuery(new MicroMallOrderRequest()
                {
                    PageSize = 1, UserId = GetUserInfo.UserId, OrderType = 1
                });
                if (Firs == null || Firs.ModelList == null || Firs.ModelList.Count <= 0)
                {
                    isFirs = true;
                }
                ///订单详情
                var commodity = JuMeiMallService.GetById(commodityId);
                if (commodity == null)
                {
                    return new ResultMessage()
                           {
                               Code = -1, Msg = "商品不存在,请重新生成订单!"
                           }
                }
                ;
                if (commodity.commodityState == CommodityStates.soldOut)
                {
                    return new ResultMessage()
                           {
                               Code = -1, Msg = "商品已下架,请重新生成订单!"
                           }
                }
                ;
                if (commodity != null)
                {
                    if (commodity.commodityInventory < quantity)
                    {
                        return new ResultMessage()
                               {
                                   Code = -1, Msg = string.Format("库存不足:{0}", commodity.commodityName)
                               }
                    }
                    ;

                    var orderDetail = new OrderDetail();
                    orderDetail.commodityId   = commodity.commodityId;
                    orderDetail.commodityName = commodity.commodityName;
                    orderDetail.orderNo       = model.orderNo;
                    orderDetail.price         = commodity.commodityPrice;
                    orderDetail.quantity      = quantity;
                    orderDetail.specification = Specification;
                    orderDetail.point         = commodity.commodityJifen;
                    orderDetail.amount        = orderDetail.price;
                    amount += orderDetail.price * orderDetail.quantity;
                    point  += orderDetail.point * orderDetail.quantity;
                    ///插入订单详情
                    OrderDetailService.Insert(orderDetail);
                }

                //运费
                model.freight = commodity.commodityFreight;

                //商品库存减少
                commodity.commodityInventory = commodity.commodityInventory - quantity;
                commodity.sellQuantity       = commodity.sellQuantity + quantity;
                commodity.sellQuantity1      = commodity.sellQuantity1 + quantity;


                JuMeiMallService.Update(commodity);


                //订单
                model.orderState = OrderStates.awaitPay;
                model.payState   = PayStates.non_payment;
                model.submitTime = DateTime.Now;
                model.orderType  = OrderType.normal;
                //model.distributionType = DistributionWay.kuaidi;
                model.userId = userId;
                //model.distributionstate = DistributionStates.unfilled;
                model.amount    = amount;
                model.point     = point;
                model.payAmount = 0;
                model.IsFirs    = isFirs;
                //用户地址首次为空,待用户选择provinceId,cityId,detailedAddress


                model.orderId = OrderService.Insert(model);

                var GetOrderService = OrderService.GetByOrderNo(model.orderNo);
                if (GetOrderService != null)
                {
                    var UpdDtl = OrderDetailService.GetByOrderNo(model.orderNo);
                    if (UpdDtl != null)
                    {
                        OrderDetailService.UpdateOrderDetailOrderId(GetOrderService.item.orderId, model.orderNo);
                    }
                }


                //if (!string.IsNullOrWhiteSpace(GetUserInfo))
                //{
                //    var message = new Fz_Messages();
                //    message.accountId = GetUserInfo.accountId;
                //    message.openId = GetUserInfo.openID;
                //    message.state = MessagesState.staySend;
                //    message.submitTime = DateTime.Now;
                //    message.keyword1 = model.orderNo;
                //    message.keyword2 = "等待付款";
                //    message.msgType = MsgType.orderState;
                //    IMessagesService.Insert(message);
                //}
                tran.Commit();
                //测试
                // RebateService.Rebate3(model.orderId);
                return(new ResultMessage()
                {
                    Code = 0, Msg = model.orderNo
                });
            }
            catch (Exception ex)
            {
                logService.Insert(ex);
                return(new ResultMessage()
                {
                    Code = -1, Msg = "生成订单失败!请稍后再试"
                });
            }
            finally { tran.Dispose(); }
        }
Example #4
0
        /// <summary>
        /// 订单详情
        /// </summary>
        /// <param name="quantity"></param>
        /// <param name="openId"></param>
        /// <returns></returns>
        public ListOrderDetail GetOrders(string orderNo)
        {
            var     model     = new ListOrderDetail();
            decimal totalAmt  = 0;
            var     orderInfo = OrderService.GetOrderNo(orderNo);

            if (orderInfo == null)
            {
                return(null);
            }
            else
            {
                model.payState        = orderInfo.orderState;
                model.recipients      = orderInfo.recipients == null ? " " : orderInfo.recipients;
                model.detailedAddress = orderInfo.detailedAddress == null ? " " : orderInfo.detailedAddress;
                model.moblie          = orderInfo.moblie == null ? " " : orderInfo.moblie;
                model.Remark          = orderInfo.remark == null ? " " : orderInfo.remark;
                model.orderState      = orderInfo.orderState;
                model.Freight         = orderInfo.freight;
                model.ExpressCompany  = orderInfo.ExpressCompany == null ? " " : orderInfo.ExpressCompany;
                model.ExpressNumber   = orderInfo.ExpressNumber == null ? " " : orderInfo.ExpressNumber;
                model.UserAddressId   = orderInfo.UserAddressId;
                model.orderNo         = orderInfo.orderNo;
            }
            var orderDtlInfo = OrderDetailService.GetAllByOrderNo(orderNo).ToList();

            if (orderDtlInfo != null)
            {
                foreach (var item in orderDtlInfo)
                {
                    var dtlModel  = new OrderDetailsModel();
                    var commodity = JuMeiMallService.GetById(item.commodityId);
                    if (commodity == null)
                    {
                        return(null);
                    }
                    if (commodity.commodityState == CommodityStates.soldOut)
                    {
                        return(null);
                    }
                    //数量

                    dtlModel.Image = GetFirstImage(commodity.images);

                    dtlModel.Id = item.commodityId;

                    dtlModel.Price = item.price;

                    dtlModel.quantity = item.quantity;

                    dtlModel.Title = commodity.commodityName;

                    dtlModel.specification = item.specification;
                    // totalAmt += commodity.commodityPrice * item.quantity;
                    //freight = commodity.commodityFreight;
                    model.OrderDetailsList.Add(dtlModel);
                }
            }
            model.TotalAmt = orderInfo.amount;
            model.Freight  = orderInfo.freight;
            var GetAddressInfo = UserAddressService.GetByAccountId(orderInfo.userId);

            if (GetAddressInfo != null && GetAddressInfo.ModelList != null && GetAddressInfo.ModelList.Count > 0)
            {
                //地址列表赋值
                model.ListUserAddress = GetAddressInfo.ModelList.ToList().Select(x => new UserAddress()
                {
                    userAddressId   = x.userAddressId,
                    moblie          = x.moblie,
                    recipients      = x.recipients,
                    detailedAddress = x.detailedAddress,
                    //city = CityService.GetById(x.cityId) == null ? "" : CityService.GetById(x.cityId).Name,
                    //province = ProvinceService.GetById(x.provinceId) == null ? "" : ProvinceService.GetById(x.provinceId).Name,
                    //ProvinceName = x.provinceName,
                    //zipCode = x.zipCode
                }).ToList();

                return(model);
            }
            return(model);
        }
Example #5
0
        /// <summary>
        /// 生成订单
        /// </summary>
        /// <param name="Ids"></param>
        /// <param name="quantity"></param>
        /// <param name="openId"></param>
        /// <returns></returns>
        public ResultMessage SaveOrder(string[] strArray, int userId)
        {
            var tran = TransactionHelper.BeginTransaction();

            try
            {
                Order model = new Order();   ///订单
                ///
                //int accountId = 0;
                decimal amount = 0;
                decimal point  = 0;

                string dateTime    = string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now);
                var    GetUserInfo = MembershipService.GetUserById(userId);// IAccountService.get(accountId);
                //var GetUserInfo = JuMeiMallService.GetUserInfoByOpenId(openId);

                if (GetUserInfo != null)
                {
                    //accountId = GetUserInfo.accountId;
                    ///订单
                    model.orderNo = dateTime + userId;//流水号
                }
                bool isFirs = false;
                var  Firs   = OrderService.MicroMallQuery(new MicroMallOrderRequest()
                {
                    PageSize = 1, UserId = GetUserInfo.UserId, OrderType = 1
                });
                if (Firs == null || Firs.ModelList == null || Firs.ModelList.Count <= 0)
                {
                    isFirs = true;
                }

                foreach (var item in strArray)//1.commodityId 2.quantity 3.shoppingCartId
                {
                    //将数组再分割为单个值
                    string[] strArray2 = item.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                    if (strArray2 != null && strArray2.Length > 0)
                    {
                        int[] intArray       = Array.ConvertAll <string, int>(strArray2, s => int.Parse(s));
                        int   commodityId    = intArray[0];
                        int   quantity       = intArray[1];
                        int   shoppingCartId = intArray[2];


                        if (commodityId == 0 || shoppingCartId == 0)
                        {
                            return(new ResultMessage()
                            {
                                Code = -1, Msg = "请选择商品,若多次无效请联系管理员!"
                            });
                        }
                        if (quantity == 0)
                        {
                            return(new ResultMessage()
                            {
                                Code = -1, Msg = "请选择商品数量!"
                            });
                        }


                        ///订单详情
                        var commodity = JuMeiMallService.GetById(commodityId);
                        if (commodity == null)
                        {
                            return new ResultMessage()
                                   {
                                       Code = -1, Msg = "商品不存在,请重新生成订单!"
                                   }
                        }
                        ;
                        if (commodity.commodityState == CommodityStates.soldOut)
                        {
                            return new ResultMessage()
                                   {
                                       Code = -1, Msg = "商品已下架,请重新生成订单!"
                                   }
                        }
                        ;


                        if (commodity != null)
                        {
                            if (commodity.commodityInventory < quantity)
                            {
                                return new ResultMessage()
                                       {
                                           Code = -1, Msg = string.Format("库存不足:{0}", commodity.commodityName)
                                       }
                            }
                            ;


                            var orderDetail = new OrderDetail();
                            orderDetail.commodityId   = commodity.commodityId;
                            orderDetail.commodityName = commodity.commodityName;
                            orderDetail.orderNo       = model.orderNo;
                            orderDetail.price         = commodity.commodityPrice;
                            orderDetail.quantity      = quantity;
                            orderDetail.point         = commodity.commodityJifen;


                            var    ShoppingCart  = ShoppingCartService.GetById(shoppingCartId);
                            string specification = "";
                            if (ShoppingCart != null)
                            {
                                specification = ShoppingCart.specification;
                            }
                            else
                            {
                                return(new ResultMessage()
                                {
                                    Code = -1, Msg = "购物车商品不存在,请重新加入购物车!"
                                });
                            }
                            orderDetail.specification = specification;
                            orderDetail.amount        = orderDetail.price * orderDetail.quantity;
                            amount += orderDetail.price * orderDetail.quantity;
                            point  += orderDetail.point * orderDetail.quantity;
                            ///插入订单详情
                            OrderDetailService.Insert(orderDetail);



                            //运费
                            model.freight = commodity.commodityFreight;

                            //商品库存减少

                            commodity.commodityInventory = commodity.commodityInventory - quantity;
                            commodity.sellQuantity       = commodity.sellQuantity + quantity;
                            commodity.sellQuantity1      = commodity.sellQuantity1 + quantity;


                            JuMeiMallService.Update(commodity);
                            ///删除购物车数据
                            if (ShoppingCart != null)
                            {
                                ShoppingCartService.Delete(ShoppingCart);
                            }
                        }
                    }
                }



                //订单
                model.orderState = OrderStates.awaitPay;
                model.payState   = PayStates.non_payment;
                model.submitTime = DateTime.Now;
                model.orderType  = OrderType.normal;
                //model.distributionType = DistributionWay.kuaidi;
                model.userId = userId;
                //model.distributionstate = DistributionStates.unfilled;
                model.amount    = amount;
                model.point     = point;
                model.payAmount = 0;
                model.IsFirs    = isFirs;
                //用户地址首次为空,待用户选择provinceId,cityId,detailedAddress


                OrderService.Insert(model);

                //var GetOrderService = OrderService.GetByOrderNo(model.orderNo);
                //if (GetOrderService != null)
                //{
                //    var UpdDtl = OrderDetailService.GetByOrderNo(model.orderNo);
                //    if (UpdDtl != null)
                //    {
                //        OrderDetailService.UpdateOrderDetailOrderId(GetOrderService.item.orderId, model.orderNo);

                //    }
                //}


                //if (accountId != 0)
                //{
                //    var message = new Fz_Messages();
                //    message.accountId = GetUserInfo.accountId;
                //    message.openId = GetUserInfo.openID;
                //    message.state = MessagesState.staySend;
                //    message.submitTime = DateTime.Now;
                //    message.keyword1 = model.orderNo;
                //    message.keyword2 = "等待付款";
                //    message.msgType = MsgType.orderState;
                //    IMessagesService.Insert(message);
                //}

                tran.Commit();

                return(new ResultMessage()
                {
                    Code = 0, Msg = model.orderNo
                });
            }
            catch (Exception ex)
            {
                logService.Insert(ex);
                return(new ResultMessage()
                {
                    Code = -1, Msg = "生成订单失败!请稍后再试"
                });
            }
            finally { tran.Dispose(); }
        }
Example #6
0
        public ResultMessage SaveShoppingCart(int commodityId, int quantity, int accountId, string Specification)
        {
            var tran = TransactionHelper.BeginTransaction();

            try
            {
                //int accountId = 0;
                var commodity = JuMeiMallService.GetById(commodityId);
                if (commodity == null)
                {
                    return new ResultMessage()
                           {
                               Code = -1, Msg = "商品不存在!"
                           }
                }
                ;
                if (commodity.commodityState == CommodityStates.soldOut)
                {
                    return new ResultMessage()
                           {
                               Code = -1, Msg = "商品已下架!"
                           }
                }
                ;
                if (commodity.commodityInventory < quantity)
                {
                    return new ResultMessage()
                           {
                               Code = -1, Msg = "库存不足!"
                           }
                }
                ;
                //var GetUserInfo = JuMeiMallService.GetUserInfoByOpenId(openId);
                //if (GetUserInfo != null)
                //{
                //accountId = GetUserInfo.accountId;
                //}
                var Cart = JuMeiMallService.GetByAccountIdAndCommodityId(accountId, commodityId, Specification);
                if (Cart != null)
                {
                    Cart.quantity = quantity;

                    //Cart.specification = specification;
                    Cart.submitTime = DateTime.Now;
                    JuMeiMallService.UpdateCart(Cart);
                }
                else
                {
                    var item = new ShoppingCart();
                    item.commodityId   = commodity.commodityId;
                    item.quantity      = quantity;
                    item.specification = Specification;
                    item.submitTime    = DateTime.Now;
                    item.userId        = accountId;
                    JuMeiMallService.InsertCart(item);
                }
                tran.Commit();
                return(new ResultMessage()
                {
                    Code = 0, Msg = "成功加入购物车"
                });
            }
            catch (Exception ex)
            {
                logService.Insert(ex);
                return(new ResultMessage()
                {
                    Code = -1, Msg = "加入购物车失败!请稍后再试"
                });
            }
            finally { tran.Dispose(); }
        }