Beispiel #1
0
        /// 修改订单信息
        /// </summary>
        public void UpdateOrderInfo(List <string> orderList, int AddressID, string remark, bool isziti, string paytype)
        {
            //获取地址
            ShopMyAddress address = DB.ShopMyAddress.FindEntity(q => q.ID == AddressID);

            if (address == null)
            {
                throw new Exception("获取收货地址失败");
            }
            foreach (var item in orderList)
            {
                ShopOrder orderModel = DB.ShopOrder.FindEntity(item);
                if (orderModel != null)
                {
                    orderModel.Receiver    = address.Name;
                    orderModel.PostAddress = address.ShowAddressName;
                    orderModel.Type        = address.ShowAddressId;

                    orderModel.Tel    = address.Tel;
                    orderModel.Remark = remark;
                    orderModel.IsZiTi = isziti;
                    orderModel.PayWay = paytype;
                    //if (orderModel.IsZiTi && orderModel.RealCongXiao > 0)
                    //{
                    //    orderModel.RealCongXiao = 0;
                    //}

                    DB.ShopOrder.Update(orderModel);
                }
            }
        }
 /// <summary>
 /// 添加或修改收货地址
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public JsonResult AddAddress(ShopMyAddress model)
 {
     try
     {
         //修改省市县内容
         if (model.ProvId > 0)
         {
             model.ProvinceName = DB.Area_Province.FindEntity(q => q.id == model.ProvId).name;
         }
         if (model.CityID > 0)
         {
             model.CityName = DB.Area_City.FindEntity(q => q.id == model.CityID.Value).name;
         }
         if (model.CountyID > 0)
         {
             model.CountyName = DB.Area_County.FindEntity(q => q.id == model.CountyID).name;
         }
         if (model.ID > 0)
         {
             //修改
             ShopMyAddress oldModel = DB.ShopMyAddress.FindEntity(q => q.ID == model.ID);
             oldModel.Name         = model.Name;
             oldModel.Tel          = model.Tel;
             oldModel.PostCode     = model.PostCode;
             oldModel.Address      = model.Address;
             oldModel.ProvId       = model.ProvId;
             oldModel.ProvinceName = model.ProvinceName;
             oldModel.CityID       = model.CityID;
             oldModel.CityName     = model.CityName;
             oldModel.CountyID     = model.CountyID;
             oldModel.CountyName   = model.CountyName;
             if (DB.ShopMyAddress.Update(oldModel) == false)
             {
                 throw new Exception("修改失败");
             }
             return(Success("修改成功"));
         }
         else
         {
             //添加
             model.CreateTime = DateTime.Now;
             model.MemberID   = CurrentUserID;
             if (DB.ShopMyAddress.Insert(model) == false)
             {
                 throw new Exception("添加收货地址失败");
             }
             return(Success("添加成功"));
         }
     }
     catch (Exception ex)
     {
         return(Error(ex));
     }
 }
Beispiel #3
0
        public ActionResult AddressDetail(int id)
        {
            var address = DB.ShopMyAddress.FindEntity(id);

            if (id == 0)
            {
                address = new ShopMyAddress();
            }
            ViewBag.m       = DB.Member_Info.FindEntity(CurrentUser.MemberId);
            ViewBag.address = address;

            return(View());
        }
Beispiel #4
0
        /// <summary>
        /// 生成订单,进入代付款状态
        /// </summary>
        /// <returns></returns>
        public bool GenerateOrder(Member_Info curUser, int AddressID, string remark)
        {
            //1.获取购物车
            List <ShopCat> catList = DB.ShopCat.Where(q => q.MemberID == curUser.MemberId).ToList();
            var            member  = DB.Member_Info.Where(p => p.MemberId == curUser.MemberId).FirstOrDefault();
            var            Level   = DB.Sys_Level.Where(p => p.LevelId == member.MemberLevelId).FirstOrDefault();

            using (var tran = BeginTransaction)
            {
                try
                {
                    //获取地址
                    ShopMyAddress address = DB.ShopMyAddress.FindEntity(q => q.ID == AddressID);

                    //2. 生成订单
                    ShopOrder order   = new ShopOrder();
                    string    orderID = Guid.NewGuid().ToString().Replace("-", "");
                    order.GUID       = orderID;
                    order.ShopID     = 1;
                    order.TraceNo    = orderID;
                    order.OrderCode  = generateCode();
                    order.MemberID   = curUser.MemberId;
                    order.MemberCode = curUser.Code;
                    order.NickName   = curUser.NickName;
                    order.PayState   = ShopEnum.OrderPayState.WaitPay.GetHashCode();
                    order.State      = ShopEnum.OrderState.Submit.GetHashCode();
                    order.SubmitTime = DateTime.Now;
                    order.Remark     = remark;

                    if (address != null)
                    {
                        order.Receiver    = address.Name;
                        order.PostAddress = address.ShowAddressName;
                        order.Tel         = address.Tel;
                        order.Type        = address.ShowAddressId;
                    }
                    foreach (var item in catList)
                    {
                        //if (member.MemberLevelId < 1)
                        //{
                        //    if (item.ShopProduct.CategoryID1 != 8)
                        //        throw new Exception("您不是会员无法去购买其他专区");
                        //}

                        int shopID = item.ShopProduct.ShopID;

                        order.PayWay = "";
                        //if (catList.Count > 1 && item.ShopProduct.IsDingDan())
                        //    throw new Exception("订单产品必须单独结算,请移除后提交");

                        //decimal totalPrice = 0;
                        decimal totalShopping = 0;
                        decimal totalScore    = 0;
                        decimal totalCongXiao = 0;
                        //3.统计价格
                        var catItem = item;


                        totalShopping += DB.ShopProduct.GetSPrice(catItem.ShopProduct, catItem.GuiGe).LingShou.Value *catItem.Count; //零售价
                        totalScore    += DB.ShopProduct.GetSPrice(catItem.ShopProduct, catItem.GuiGe).YouHui.Value *catItem.Count;   //优惠价
                        totalCongXiao += DB.ShopProduct.GetSPrice(catItem.ShopProduct, catItem.GuiGe).PeiHuo.Value *catItem.Count;   //配货价

                        order.ShopID      = shopID;
                        order.Postage     = 0;
                        order.RealAmount += totalScore;//优惠价
                        if (catItem.ShopProduct.CategoryID1 == DB.XmlConfig.XmlSite.Scores)
                        {
                            order.OrderType = "团购订单";
                        }
                        else
                        {
                            order.OrderType = "报单订单";
                        }
                        order.StoreCode     = "未发放";
                        order.RealShopping += totalScore; //零售价
                        order.RealScore    += totalScore; //优惠价

                        order.Postage += catItem.ShopProduct.Postage;

                        order.RealCongXiao += totalCongXiao; //pv
                        order.ZongDay       = catItem.Count; //挂卖总数量
                        order.YiDay         = catItem.Count; //剩余数量
                        order.Count        += catItem.Count;
                    }
                    if (order.RealAmount >= DB.XmlConfig.XmlSite.MinAmountHuZ)
                    {
                        order.Postage = 0;
                    }

                    if (DB.ShopOrder.Insert(order) == false)
                    {
                        throw new Exception("添加订单失败");
                    }

                    //生成订单关联
                    foreach (var item in catList)
                    {
                        var catItem = item;
                        var gg      = DB.ShopProduct.GetSPrice(catItem.ShopProduct, catItem.GuiGe);

                        ShopOrderProduct orderProduct = new ShopOrderProduct();
                        orderProduct.OrderID       = orderID;
                        orderProduct.ProductID     = catItem.ProductID;
                        orderProduct.Name          = catItem.ShopProduct.Title;
                        orderProduct.Count         = catItem.Count;
                        orderProduct.PriceShopping = gg.LingShou.Value; //零售
                        orderProduct.PriceScore    = gg.YouHui.Value;   //优惠
                        orderProduct.PriceCongXiao = gg.PeiHuo.Value;   //pv

                        orderProduct.MoneyShopping = orderProduct.PriceShopping * catItem.Count;
                        orderProduct.MoneyScore    = orderProduct.PriceScore * catItem.Count;
                        orderProduct.MoneyCongXiao = orderProduct.PriceCongXiao * catItem.Count;

                        orderProduct.Price = gg.YouHui.Value;

                        orderProduct.Money += orderProduct.MoneyScore;//配货价

                        orderProduct.GuiGe = catItem.GuiGe;
                        DB.ShopOrderProduct.Insert(orderProduct);

                        ////扣除订单的销售量
                        //catItem.ShopProduct.Sales += orderProduct.Count;
                        //catItem.ShopProduct.Inventory -= orderProduct.Count;
                        //if (catItem.ShopProduct.Inventory < 0)
                        //    throw new Exception("库存不足");
                        //DB.ShopProduct.Update(catItem.ShopProduct);

                        gg.KuCun  -= orderProduct.Count;
                        gg.YiShou += orderProduct.Count;
                        DB.GuiGeProduct_Info.Update(gg);
                    }



                    //4.清空购物车
                    DB.ShopCat.Delete(catList);
                    tran.Complete();
                    return(true);
                }
                catch (Exception ex)
                {
                    DB.Rollback();
                    throw ex;
                }
            }
        }