Beispiel #1
0
        /// <summary>
        /// 获得订单商品列表
        /// </summary>
        /// <param name="oid">订单id</param>
        /// <returns></returns>
        public static List <OrderProductInfo> GetOrderProductList(int oid)
        {
            List <OrderProductInfo> orderProductList = null;

            if (_ordernosql != null)
            {
                orderProductList = _ordernosql.GetOrderProductList(oid);
                if (orderProductList == null)
                {
                    orderProductList = new List <OrderProductInfo>();
                    IDataReader reader = NStore.Core.BMAData.RDBS.GetOrderProductList(oid);
                    while (reader.Read())
                    {
                        OrderProductInfo orderProductInfo = BuildOrderProductFromReader(reader);
                        orderProductList.Add(orderProductInfo);
                    }
                    reader.Close();
                    _ordernosql.CreateOrderProductList(oid, orderProductList);
                }
            }
            else
            {
                orderProductList = new List <OrderProductInfo>();
                IDataReader reader = NStore.Core.BMAData.RDBS.GetOrderProductList(oid);
                while (reader.Read())
                {
                    OrderProductInfo orderProductInfo = BuildOrderProductFromReader(reader);
                    orderProductList.Add(orderProductInfo);
                }
                reader.Close();
            }

            return(orderProductList);
        }
Beispiel #2
0
        public static OrderProductInfo GetInfo(int _order_ID, int _content_ID)
        {
            OrderProductInfo retVal = null;
            SqlConnection    dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand       dbCmd  = new SqlCommand("Main_OrderProduct_GetInfo", dbConn);

            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@Order_ID", _order_ID);
            dbCmd.Parameters.AddWithValue("@Content_ID", _content_ID);
            try
            {
                dbConn.Open();
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.Read())
                {
                    retVal            = new OrderProductInfo();
                    retVal.Order_ID   = Convert.ToInt32(dr["Order_ID"]);
                    retVal.Content_ID = Convert.ToInt32(dr["Content_ID"]);
                    retVal.Quantity   = Convert.ToInt32(dr["Quantity"]);
                    retVal.Price      = Convert.ToDouble(dr["Price"]);
                    retVal.PriceSum   = Convert.ToDouble(dr["PriceSum"]);
                }
                if (dr != null)
                {
                    dr.Close();
                }
            }
            finally
            {
                dbConn.Close();
            }
            return(retVal);
        }
Beispiel #3
0
        /// <summary>
        /// 从IDataReader创建OrderProductInfo
        /// </summary>
        private OrderProductInfo BuildOrderProductFromReader(IDataReader reader)
        {
            OrderProductInfo orderProductInfo = new OrderProductInfo();

            orderProductInfo.RecordId      = TypeHelper.ObjectToInt(reader["recordid"]);
            orderProductInfo.Oid           = TypeHelper.ObjectToInt(reader["oid"]);
            orderProductInfo.Uid           = TypeHelper.ObjectToInt(reader["uid"]);
            orderProductInfo.Sid           = reader["sid"].ToString();
            orderProductInfo.Pid           = TypeHelper.ObjectToInt(reader["pid"]);
            orderProductInfo.PSN           = reader["psn"].ToString();
            orderProductInfo.CateId        = TypeHelper.ObjectToInt(reader["cateid"]);
            orderProductInfo.BrandId       = TypeHelper.ObjectToInt(reader["brandid"]);
            orderProductInfo.Name          = reader["name"].ToString();
            orderProductInfo.ShowImg       = reader["showimg"].ToString();
            orderProductInfo.DiscountPrice = TypeHelper.ObjectToDecimal(reader["discountprice"]);
            orderProductInfo.ShopPrice     = TypeHelper.ObjectToDecimal(reader["shopprice"]);
            orderProductInfo.CostPrice     = TypeHelper.ObjectToDecimal(reader["costprice"]);
            orderProductInfo.MarketPrice   = TypeHelper.ObjectToDecimal(reader["marketprice"]);
            orderProductInfo.Weight        = TypeHelper.ObjectToInt(reader["weight"]);
            orderProductInfo.IsReview      = TypeHelper.ObjectToInt(reader["isreview"]);
            orderProductInfo.RealCount     = TypeHelper.ObjectToInt(reader["realcount"]);
            orderProductInfo.BuyCount      = TypeHelper.ObjectToInt(reader["buycount"]);
            orderProductInfo.SendCount     = TypeHelper.ObjectToInt(reader["sendcount"]);
            orderProductInfo.Type          = TypeHelper.ObjectToInt(reader["type"]);
            orderProductInfo.PayCredits    = TypeHelper.ObjectToInt(reader["paycredits"]);
            orderProductInfo.CouponTypeId  = TypeHelper.ObjectToInt(reader["coupontypeid"]);
            orderProductInfo.ExtCode1      = TypeHelper.ObjectToInt(reader["extcode1"]);
            orderProductInfo.ExtCode2      = TypeHelper.ObjectToInt(reader["extcode2"]);
            orderProductInfo.ExtCode3      = TypeHelper.ObjectToInt(reader["extcode3"]);
            orderProductInfo.ExtCode4      = TypeHelper.ObjectToInt(reader["extcode4"]);
            orderProductInfo.ExtCode5      = TypeHelper.ObjectToInt(reader["extcode5"]);
            orderProductInfo.AddTime       = TypeHelper.ObjectToDateTime(reader["addtime"]);
            return(orderProductInfo);
        }
Beispiel #4
0
        /// <summary>
        /// 发放评价商品积分
        /// </summary>
        /// <param name="partUserInfo">用户信息</param>
        /// <param name="orderProductInfo">订单商品</param>
        /// <param name="reviewTime">评价时间</param>
        public static int SendReviewProductCredits(ref PartUserInfo partUserInfo, OrderProductInfo orderProductInfo, DateTime reviewTime)
        {
            if (_creditconfiginfo.ReviewProductPayCredits > 0 || _creditconfiginfo.ReviewProductRankCredits > 0)
            {
                int surplusPayCredits  = GetDaySurplusPayCredits(partUserInfo.Uid, reviewTime.Date);
                int surplusRankCredits = GetDaySurplusRankCredits(partUserInfo.Uid, reviewTime.Date);
                if (surplusPayCredits == 0 && surplusRankCredits == 0)
                {
                    return(0);
                }

                int payCredits  = 0;
                int rankCredits = 0;
                if (surplusPayCredits > 0)
                {
                    payCredits = surplusPayCredits < _creditconfiginfo.ReviewProductPayCredits ? surplusPayCredits : _creditconfiginfo.ReviewProductPayCredits;
                }
                else if (surplusPayCredits == -1)
                {
                    payCredits = _creditconfiginfo.ReviewProductPayCredits;
                }
                if (surplusRankCredits > 0)
                {
                    rankCredits = surplusRankCredits < _creditconfiginfo.ReviewProductRankCredits ? surplusRankCredits : _creditconfiginfo.ReviewProductRankCredits;
                }
                else if (surplusRankCredits == -1)
                {
                    rankCredits = _creditconfiginfo.ReviewProductRankCredits;
                }

                partUserInfo.PayCredits  += payCredits;
                partUserInfo.RankCredits += rankCredits;

                int userRid = UserRanks.GetUserRankByCredits(partUserInfo.RankCredits).UserRid;
                if (userRid != partUserInfo.UserRid)
                {
                    partUserInfo.UserRid = userRid;
                }
                else
                {
                    userRid = 0;
                }

                CreditLogInfo creditLogInfo = new CreditLogInfo();
                creditLogInfo.Uid         = partUserInfo.Uid;
                creditLogInfo.PayCredits  = payCredits;
                creditLogInfo.RankCredits = rankCredits;
                creditLogInfo.Action      = (int)CreditAction.ReviewProduct;
                creditLogInfo.ActionCode  = orderProductInfo.Oid;
                creditLogInfo.ActionTime  = reviewTime;
                creditLogInfo.ActionDes   = "评价商品:" + orderProductInfo.Name;
                creditLogInfo.Operator    = 0;

                SendCredits(userRid, creditLogInfo);

                return(payCredits);
            }
            return(0);
        }
Beispiel #5
0
        /// <summary>
        /// 删除购物车中商品
        /// </summary>
        public ActionResult DelPruduct()
        {
            //当商城不允许游客使用购物车时
            if (WorkContext.ShopConfig.IsGuestSC == 0 && WorkContext.Uid < 1)
            {
                return(AjaxResult("nologin", "请先登录"));
            }

            int    pid = WebHelper.GetQueryInt("pid");                                            //商品id
            int    pos = WebHelper.GetQueryInt("pos");                                            //位置
            string selectedCartItemKeyList = WebHelper.GetQueryString("selectedCartItemKeyList"); //选中的购物车项键列表

            //购物车商品列表
            List <OrderProductInfo> orderProductList = Carts.GetCartProductList(WorkContext.Uid, WorkContext.Sid);
            //对应商品
            OrderProductInfo orderProductInfo = Carts.GetCommonOrderProductByPid(pid, orderProductList);

            if (orderProductInfo != null)
            {
                Carts.DeleteCartProduct(ref orderProductList, orderProductInfo);
            }

            //商品数量
            int pCount = Carts.SumOrderProductCount(orderProductList);
            //选中的订单商品列表
            List <OrderProductInfo> selectedOrderProductList = null;
            //购物车项列表
            List <CartItemInfo> cartItemList = Carts.TidyOrderProductList(StringHelper.SplitString(selectedCartItemKeyList), orderProductList, out selectedOrderProductList);

            //商品总数量
            int totalCount = Carts.SumOrderProductCount(selectedOrderProductList);
            //商品合计
            decimal productAmount = Carts.SumOrderProductAmount(selectedOrderProductList);
            //满减折扣
            int fullCut = Carts.SumFullCut(cartItemList);
            //订单合计
            decimal orderAmount = productAmount - fullCut;

            CartModel model = new CartModel
            {
                TotalCount    = totalCount,
                ProductAmount = productAmount,
                FullCut       = fullCut,
                OrderAmount   = orderAmount,
                CartItemList  = cartItemList
            };

            //将购物车中商品数量写入cookie
            Carts.SetCartProductCountCookie(pCount);

            if (pos == 0)
            {
                return(View("ajaxindex", model));
            }
            else
            {
                return(View("snap", model));
            }
        }
        /// <summary>
        /// 修改购物车中商品数量
        /// </summary>
        public ActionResult ChangeProductCount()
        {
            //当商城不允许游客使用购物车时
            if (WorkContext.ShopConfig.IsGuestSC == 0 && WorkContext.Uid < 1)
            {
                return(AjaxResult("nologin", "请先登录"));
            }

            int    pid      = WebHelper.GetQueryInt("pid");                                       //商品id
            int    buyCount = WebHelper.GetQueryInt("buyCount");                                  //购买数量
            string selectedCartItemKeyList = WebHelper.GetQueryString("selectedCartItemKeyList"); //选中的购物车项键列表

            //购物车商品列表
            List <OrderProductInfo> orderProductList = Carts.GetCartProductList(WorkContext.Uid, WorkContext.Sid);
            //对应商品
            OrderProductInfo orderProductInfo = Carts.GetCommonOrderProductByPid(pid, orderProductList);

            if (orderProductInfo != null) //当商品已经存在
            {
                if (buyCount < 1)         //当购买数量小于1时,删除此商品
                {
                    Carts.DeleteCartProduct(ref orderProductList, orderProductInfo);
                }
                else if (buyCount != orderProductInfo.BuyCount)
                {
                    Carts.AddExistProductToCart(ref orderProductList, buyCount, orderProductInfo, DateTime.Now);
                }
            }

            //商品数量
            int pCount = Carts.SumOrderProductCount(orderProductList);
            //购物车信息
            CartInfo cartInfo = Carts.TidyOrderProductList(StringHelper.SplitString(selectedCartItemKeyList), orderProductList);

            //商品总数量
            int totalCount = Carts.SumOrderProductCount(cartInfo.SelectedOrderProductList);
            //商品合计
            decimal productAmount = Carts.SumOrderProductAmount(cartInfo.SelectedOrderProductList);
            //满减折扣
            int fullCut = Carts.SumFullCut(cartInfo);
            //订单合计
            decimal orderAmount = productAmount - fullCut;

            CartModel model = new CartModel
            {
                TotalCount    = totalCount,
                ProductAmount = productAmount,
                FullCut       = fullCut,
                OrderAmount   = orderAmount,
                CartInfo      = cartInfo
            };

            //将购物车中商品数量写入cookie
            Carts.SetCartProductCountCookie(pCount);

            return(View("ajaxindex", model));
        }
        /// <summary>
        /// 购买商品
        /// </summary>
        /// <returns></returns>
        public ActionResult BuyProduct()
        {
            int    pid      = WebHelper.GetQueryInt("pid");      //商品id
            string note     = WebHelper.GetQueryString("note");  //备注
            int    buyCount = WebHelper.GetQueryInt("buyCount"); //购买数量

            //当商城不允许游客使用购物车时
            if (WorkContext.ShopConfig.IsGuestSC == 0 && WorkContext.Uid < 1)
            {
                return(AjaxResult("nologin", "请先登录"));
            }

            //判断商品是否存在
            PartProductInfo partProductInfo = Products.GetPartProductById(pid);

            if (partProductInfo == null)
            {
                return(AjaxResult("noproduct", "请选择商品"));
            }

            //购买数量不能小于1
            if (buyCount < 1)
            {
                return(AjaxResult("buycountmin", "请填写购买数量"));
            }

            //商品库存
            int stockNumber = Products.GetProductStockNumberByPid(pid);

            if (stockNumber < buyCount)
            {
                return(AjaxResult("stockout", "商品库存不足"));
            }

            //购物车中已经存在的商品列表
            List <OrderProductInfo> orderProductList = Carts.GetCartProductList(WorkContext.Uid, WorkContext.Sid);
            OrderProductInfo        orderProductInfo = Carts.GetCommonOrderProductByPid(pid, orderProductList);

            if (orderProductInfo == null)
            {
                if ((WorkContext.Uid > 0 && orderProductList.Count >= WorkContext.ShopConfig.MemberSCCount) || (WorkContext.Uid < 1 && orderProductList.Count >= WorkContext.ShopConfig.GuestSCCount))
                {
                    return(AjaxResult("full", "购物车已满"));
                }
            }

            buyCount = orderProductInfo == null ? buyCount : orderProductInfo.BuyCount + buyCount;
            //将商品添加到购物车
            Carts.AddProductToCart(ref orderProductList, buyCount, partProductInfo, WorkContext.Sid, WorkContext.Uid, DateTime.Now, WorkContext.IsMember, note);
            //将购物车中商品数量写入cookie
            Carts.SetCartProductCountCookie(Carts.SumOrderProductCount(orderProductList));

            return(AjaxResult("success", Url.Action("confirmorder", "order", new RouteValueDictionary {
                { "selectedCartItemKeyList", "0_" + pid }
            })));
        }
Beispiel #8
0
        /// <summary>
        /// 添加商品到购物车
        /// </summary>
        public ActionResult AddProduct()
        {
            int pid          = WebHelper.GetQueryInt("pid");        //商品id
            int buyCount     = WebHelper.GetQueryInt("buyCount");   //购买数量
            int scSubmitType = WorkContext.ShopConfig.SCSubmitType; //购物车的提交方式

            //当商城不允许游客使用购物车时
            if (WorkContext.ShopConfig.IsGuestSC == 0 && WorkContext.Uid < 1)
            {
                return(AjaxResult("nologin", "请先登录"));
            }

            //判断商品是否存在
            PartProductInfo partProductInfo = Products.GetPartProductById(pid);

            if (partProductInfo == null)
            {
                return(AjaxResult("noproduct", "请选择商品"));
            }

            //购买数量不能小于1
            if (buyCount < 1)
            {
                return(AjaxResult("buycountmin", "请填写购买数量"));
            }

            //商品库存
            int stockNumber = Products.GetProductStockNumberByPid(pid);

            if (stockNumber < buyCount)
            {
                return(AjaxResult("stockout", "商品库存不足"));
            }

            //购物车中已经存在的商品列表
            List <OrderProductInfo> orderProductList = Carts.GetCartProductList(WorkContext.Uid, WorkContext.Sid);
            OrderProductInfo        orderProductInfo = Carts.GetCommonOrderProductByPid(pid, orderProductList);

            if (orderProductInfo == null)
            {
                if ((WorkContext.Uid > 0 && orderProductList.Count >= WorkContext.ShopConfig.MemberSCCount) || (WorkContext.Uid < 1 && orderProductList.Count >= WorkContext.ShopConfig.GuestSCCount))
                {
                    return(AjaxResult("full", "购物车已满"));
                }
            }

            buyCount = orderProductInfo == null ? buyCount : orderProductInfo.BuyCount + buyCount;
            //将商品添加到购物车
            Carts.AddProductToCart(ref orderProductList, buyCount, partProductInfo, WorkContext.Sid, WorkContext.Uid, DateTime.Now);
            //将购物车中商品数量写入cookie
            Carts.SetCartProductCountCookie(Carts.SumOrderProductCount(orderProductList));

            return(AjaxResult("success", "添加成功"));
        }
Beispiel #9
0
        protected bool InputProductInfoWithSaveChange(OMSContext db, OrderDTO orderDTO, OrderEntity item)
        {
            //判断该商品的ERP编号是否存在,不存在则停止录入
            string temp = orderDTO.productsku.Trim();
            var    foo  = db.ProductsSet.Include(p => p.weightModel).FirstOrDefault(p => p.sku.Trim() == temp);

            if (foo == null)
            {
                OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productsku})对应ERP商品记录未找到");
                InputExceptionOrder(orderDTO, ExceptionType.ProductCodeUnKnown);
                return(false);
            }

            if (item.Products.FirstOrDefault(p => p.sku == foo.sku) == null)
            {
                decimal          weight           = foo == null ? 0 : foo.QuantityPerUnit * orderDTO.count;
                OrderProductInfo orderProductInfo = new OrderProductInfo()
                {
                    ProductPlatId   = orderDTO.productsku,
                    ProductPlatName = orderDTO.productName,
                    //   Warehouse = item.OrderLogistics.Logistics,
                    MonthNum       = orderDTO.createdDate.Month,
                    weightCode     = foo.weightModel == null ? 0 : foo.weightModel.Code,
                    weightCodeDesc = foo.weightModel == null ? string.Empty : $"{foo.weightModel.Value}g",
                    OrderSn        = orderDTO.orderSN,
                    TotalAmount    = orderDTO.totalAmount,
                    AmounPerUnit   = orderDTO.pricePerUnit,
                    DiscountFee    = orderDTO.discountFee,
                    ProductCount   = orderDTO.count,
                    ProductWeight  = weight,
                    Source         = orderDTO.source,
                    sku            = foo.sku
                };
                item.Products.Add(orderProductInfo);
                OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productsku})解析完毕");
            }
            else
            {
                OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productsku})重复录入");
            }
            db.SaveChanges();


            return(true);
        }
Beispiel #10
0
        /// <summary>
        /// 获得购物车商品列表
        /// </summary>
        /// <param name="sid">用户sid</param>
        /// <returns></returns>
        public List <OrderProductInfo> GetCartProductList(string sid)
        {
            List <OrderProductInfo> orderProductList = new List <OrderProductInfo>();

            DbParameter[] parms =
            {
                GenerateInParam("@sid", SqlDbType.Char, 16, sid)
            };
            IDataReader reader = RDBSHelper.ExecuteReader(CommandType.StoredProcedure,
                                                          string.Format("{0}getcartproductlistbysid", RDBSHelper.RDBSTablePre),
                                                          parms);

            while (reader.Read())
            {
                OrderProductInfo orderProductInfo = BuildOrderProductFromReader(reader);
                orderProductList.Add(orderProductInfo);
            }
            reader.Close();

            return(orderProductList);
        }
Beispiel #11
0
        public static void Update(OrderProductInfo _orderDetailInfo)
        {
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand    dbCmd  = new SqlCommand("Main_OrderProduct_Update", dbConn);

            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@Order_ID", _orderDetailInfo.Order_ID);
            dbCmd.Parameters.AddWithValue("@Content_ID", _orderDetailInfo.Content_ID);
            dbCmd.Parameters.AddWithValue("@Quantity", _orderDetailInfo.Quantity);
            dbCmd.Parameters.AddWithValue("@Price", _orderDetailInfo.Price);
            dbCmd.Parameters.AddWithValue("@PriceSum", _orderDetailInfo.PriceSum);
            try
            {
                dbConn.Open();
                dbCmd.ExecuteNonQuery();
            }
            finally
            {
                dbConn.Close();
            }
        }
Beispiel #12
0
        public static int Insert(OrderProductInfo _orderDetailInfo)
        {
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand    dbCmd  = new SqlCommand("Main_OrderProduct_Insert", dbConn);

            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@Order_ID", _orderDetailInfo.Order_ID);
            dbCmd.Parameters.AddWithValue("@Content_ID", _orderDetailInfo.Content_ID);
            dbCmd.Parameters.AddWithValue("@Quantity", _orderDetailInfo.Quantity);
            dbCmd.Parameters.AddWithValue("@Price", _orderDetailInfo.Price);
            dbCmd.Parameters.AddWithValue("@PriceSum", _orderDetailInfo.PriceSum);
            dbCmd.Parameters.AddWithValue("@RETURN_VALUE", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
            try
            {
                dbConn.Open();
                dbCmd.ExecuteNonQuery();
                return((int)dbCmd.Parameters["@RETURN_VALUE"].Value);
            }
            finally
            {
                dbConn.Close();
            }
        }
Beispiel #13
0
        /// <summary>
        /// 获得订单商品列表
        /// </summary>
        /// <param name="oidList">订单id列表</param>
        /// <returns></returns>
        public static List <OrderProductInfo> GetOrderProductList(string oidList)
        {
            List <OrderProductInfo> orderProductList = new List <OrderProductInfo>();

            if (_ordernosql != null)
            {
                foreach (string oid in StringHelper.SplitString(oidList))
                {
                    orderProductList.AddRange(GetOrderProductList(TypeHelper.StringToInt(oid)));
                }
            }
            else
            {
                IDataReader reader = NStore.Core.BMAData.RDBS.GetOrderProductList(oidList);
                while (reader.Read())
                {
                    OrderProductInfo orderProductInfo = BuildOrderProductFromReader(reader);
                    orderProductList.Add(orderProductInfo);
                }
                reader.Close();
            }

            return(orderProductList);
        }
        /// <summary>
        /// 申请订单售后服务
        /// </summary>
        /// <param name="orderProductInfo">订单商品信息</param>
        /// <param name="count">数量</param>
        /// <param name="type">类型(0代表退货,1代表换货,2代表维修)</param>
        /// <param name="applyReason">申请原因</param>
        public static void ApplyOrderAfterService(OrderProductInfo orderProductInfo, int count, int type, string applyReason)
        {
            decimal money = type == 0 ? (orderProductInfo.DiscountPrice * (count < orderProductInfo.BuyCount ? count : orderProductInfo.BuyCount)) : 0M;

            ApplyOrderAfterService(orderProductInfo.Uid, orderProductInfo.Oid, orderProductInfo.RecordId, orderProductInfo.Pid, orderProductInfo.CateId, orderProductInfo.BrandId, orderProductInfo.StoreId, orderProductInfo.Name, orderProductInfo.ShowImg, count, money, type, applyReason, DateTime.Now);
        }
Beispiel #15
0
        /// <summary>
        /// 添加商品到购物车
        /// </summary>
        public ActionResult AddProduct()
        {
            int pid          = WebHelper.GetQueryInt("pid");        //商品id
            int buyCount     = WebHelper.GetQueryInt("buyCount");   //购买数量
            int scSubmitType = WorkContext.ShopConfig.SCSubmitType; //购物车的提交方式

            //当商城不允许游客使用购物车时
            if (WorkContext.ShopConfig.IsGuestSC == 0 && WorkContext.Uid < 1)
            {
                switch (scSubmitType)
                {
                case 0:
                    return(Redirect(Url.Action("login", "account", new RouteValueDictionary {
                        { "returnUrl", Url.Action("product", "catalog", new RouteValueDictionary {
                                { "pid", pid }
                            }) }
                    })));

                case 1:
                    return(Redirect(Url.Action("login", "account", new RouteValueDictionary {
                        { "returnUrl", Url.Action("product", "catalog", new RouteValueDictionary {
                                { "pid", pid }
                            }) }
                    })));

                case 2:
                    return(AjaxResult("nologin", "请先登录"));

                default:
                    return(Redirect(Url.Action("login", "account", new RouteValueDictionary {
                        { "returnUrl", Url.Action("product", "catalog", new RouteValueDictionary {
                                { "pid", pid }
                            }) }
                    })));
                }
            }

            //判断商品是否存在
            PartProductInfo partProductInfo = Products.GetPartProductById(pid);

            if (partProductInfo == null)
            {
                switch (scSubmitType)
                {
                case 0:
                    return(PromptView("/", "商品不存在"));

                case 1:
                    return(PromptView("/", "商品不存在"));

                case 2:
                    return(AjaxResult("noproduct", "请选择商品"));

                default:
                    return(PromptView("/", "商品不存在"));
                }
            }

            //购买数量不能小于1
            if (buyCount < 1)
            {
                switch (scSubmitType)
                {
                case 0:
                    return(PromptView(Url.Action("product", "catalog", new RouteValueDictionary {
                        { "pid", pid }
                    }), "购买数量不能小于1"));

                case 1:
                    return(PromptView(Url.Action("product", "catalog", new RouteValueDictionary {
                        { "pid", pid }
                    }), "购买数量不能小于1"));

                case 2:
                    return(AjaxResult("buycountmin", "请填写购买数量"));

                default:
                    return(PromptView(Url.Action("product", "catalog", new RouteValueDictionary {
                        { "pid", pid }
                    }), "购买数量不能小于1"));
                }
            }

            //商品库存
            int stockNumber = Products.GetProductStockNumberByPid(pid);

            if (stockNumber < buyCount)
            {
                switch (scSubmitType)
                {
                case 0:
                    return(PromptView(Url.Action("product", "catalog", new RouteValueDictionary {
                        { "pid", pid }
                    }), "商品已售空"));

                case 1:
                    return(PromptView(Url.Action("product", "catalog", new RouteValueDictionary {
                        { "pid", pid }
                    }), "商品已售空"));

                case 2:
                    return(AjaxResult("stockout", "商品库存不足"));

                default:
                    return(PromptView(Url.Action("product", "catalog", new RouteValueDictionary {
                        { "pid", pid }
                    }), "商品已售空"));
                }
            }

            //购物车中已经存在的商品列表
            List <OrderProductInfo> orderProductList = Carts.GetCartProductList(WorkContext.Uid, WorkContext.Sid);
            OrderProductInfo        orderProductInfo = Carts.GetCommonOrderProductByPid(pid, orderProductList);

            if (orderProductInfo == null)
            {
                if ((WorkContext.Uid > 0 && orderProductList.Count >= WorkContext.ShopConfig.MemberSCCount) || (WorkContext.Uid < 1 && orderProductList.Count >= WorkContext.ShopConfig.GuestSCCount))
                {
                    switch (scSubmitType)
                    {
                    case 2:
                        return(AjaxResult("full", "购物车已满"));

                    default:
                        return(PromptView(Url.Action("index", "cart"), "购物车已满,请先结账"));
                    }
                }
            }

            buyCount = orderProductInfo == null ? buyCount : orderProductInfo.BuyCount + buyCount;
            //将商品添加到购物车
            Carts.AddProductToCart(ref orderProductList, buyCount, partProductInfo, WorkContext.Sid, WorkContext.Uid, DateTime.Now);
            //将购物车中商品数量写入cookie
            Carts.SetCartProductCountCookie(Carts.SumOrderProductCount(orderProductList));

            switch (scSubmitType)
            {
            case 0:
                return(RedirectToAction("addsuccess", new RouteValueDictionary {
                    { "type", 0 }, { "id", pid }
                }));

            case 1:
                return(RedirectToAction("index"));

            case 2:
                return(AjaxResult("success", "添加成功"));

            default:
                return(RedirectToAction("addsuccess", new RouteValueDictionary {
                    { "type", 0 }, { "id", pid }
                }));
            }
        }
Beispiel #16
0
        protected List <OrderEntity> ResolveOrders(DataTable excelTable, string file, List <OrderEntity> items)
        {
            foreach (DataRow row in excelTable.Rows)
            {
                if (row["商品名称"] == DBNull.Value || row["商品编码"] == DBNull.Value)
                {
                    continue;
                }

                var source   = Name;
                var sourceSN = Convert.ToString(row["订单编号"]);

                var sOrderDate  = sourceSN.Substring(0, 8);
                var currentYear = DateTime.Now.Year.ToString();
                if (sOrderDate.StartsWith("90"))
                {
                    sOrderDate = sOrderDate.Remove(0, 2).Insert(0, currentYear.Substring(0, 2));
                }
                var createdDate = DateTime.ParseExact(sOrderDate, "yyyyMMdd", CultureInfo.InvariantCulture);
                var orderSN     = string.Format("{0}-{1}", source, sourceSN); //订单SN=来源+原来的SN


                var item = items.Find(o => o.OrderSn == orderSN);
                using (var db = new OMSContext())
                {
                    var foo = db.OrderSet.Find(orderSN);
                    if (foo != null)
                    {
                        Util.Logs.Log.GetLog(nameof(TMExcelOrderOption)).Error($"订单{foo.OrderSn}已经存在");
                        continue;
                    }
                }
                if (item == null)
                {
                    var sourceAccount = string.Empty;

                    var productName  = Convert.ToString(row["商品名称"]);
                    var productsku   = Convert.ToString(row["商品编码"]);
                    var quantity     = Convert.ToInt32(row["数量"]);
                    var itemPriceStr = Convert.ToString(row["商品价格(广发售价)"]).Replace("¥", "").Trim();
                    var itemPrice    = Convert.ToDecimal(itemPriceStr);

                    var totalAmount = itemPrice * quantity;

                    var consigneeName  = Convert.ToString(row["收货人"]);
                    var consigneePhone = Convert.ToString(row["收货人电话1"]);

                    var consigneePhone2 = Convert.ToString(row["收货人电话2"]);


                    var consigneeProvince = string.Empty;
                    var consigneeCity     = string.Empty;
                    var consigneeCounty   = string.Empty;
                    var consigneeAddress  = Convert.ToString(row["收货地址"]);
                    var consigneeZipCode  = Convert.ToString(row["收货人邮编"]);


                    var addrInfo = DistrictService.DistrictService.ResolveAddress(consigneeAddress);
                    consigneeProvince = addrInfo.Province;
                    consigneeCity     = addrInfo.City;
                    consigneeCounty   = addrInfo.County;
                    //   consigneeAddress = addrInfo.Address;


                    //NOTE: #此处设置为现金支付金额#
                    var invoiceType   = string.Empty;
                    var invoiceName   = Convert.ToString(row["发票抬头"]);
                    var cashAmountStr = Convert.ToString(row["现金支付金额"]).Replace("¥", "").Trim();
                    var cashAmount    = Convert.ToDecimal(cashAmountStr);
                    if (!string.IsNullOrEmpty(invoiceName))
                    {
                        invoiceType = string.Format("{0:F2}", cashAmount);
                    }

                    var userRemarks    = Convert.ToString(row["用户留言"]);
                    var serviceRemarks = Convert.ToString(row["客服留言"]);
                    var deliverRemarks = Convert.ToString(row["送货时间要求"]);

                    var remarks = new StringBuilder();
                    if (!string.IsNullOrEmpty(userRemarks))
                    {
                        remarks.AppendLine(string.Format("[用户留言] {0}", userRemarks));
                    }
                    if (!string.IsNullOrEmpty(serviceRemarks))
                    {
                        remarks.AppendLine(string.Format("[客服留言] {0}", serviceRemarks));
                    }
                    if (!string.IsNullOrEmpty(deliverRemarks))
                    {
                        remarks.AppendLine(string.Format("[送货时间要求] {0}", deliverRemarks));
                    }
                    var orderItem = new OrderEntity()
                    {
                        OrderSn     = orderSN,
                        Source      = OrderSource.CGB,
                        SourceDesc  = Util.Helpers.Reflection.GetDescription <OrderSource>(OrderSource.CGB),
                        SourceSn    = sourceSN,
                        CreatedDate = createdDate,
                        Consignee   = new CustomerEntity()
                        {
                            Name       = consigneeName,
                            Phone      = consigneePhone,
                            Phone2     = consigneePhone2 == consigneePhone ? null : consigneePhone2,
                            CreateDate = createdDate
                        },
                        ConsigneeAddress = new AddressEntity()
                        {
                            Address  = consigneeAddress,
                            City     = consigneeCity,
                            County   = consigneeCounty,
                            Province = consigneeProvince,
                            ZipCode  = consigneeZipCode
                        },
                        OrderDateInfo = new OrderDateInfo()
                        {
                            CreateTime = createdDate,
                            MonthNum   = createdDate.Month,
                            WeekNum    = Util.Helpers.Time.GetWeekNum(createdDate),
                            SeasonNum  = Util.Helpers.Time.GetSeasonNum(createdDate),
                            Year       = createdDate.Year,
                            DayNum     = createdDate.DayOfYear,
                            TimeStamp  = Util.Helpers.Time.GetUnixTimestamp(createdDate)
                        },


                        OrderStatus     = (int)OrderStatus.Confirmed,
                        OrderStatusDesc = Util.Helpers.Enum.GetDescription(typeof(OrderStatus), OrderStatus.Confirmed),

                        Remarks = remarks.ToString()
                    };
                    if (orderItem.Products == null)
                    {
                        orderItem.Products = new List <OrderProductInfo>();
                    }
                    using (var db = new OMSContext())
                    {
                        // 查找联系人
                        if (!string.IsNullOrEmpty(orderItem.Consignee.Phone))
                        {
                            string md5 = Util.Helpers.Encrypt.Md5By32(orderItem.ConsigneeAddress.Address.Trim().Replace(" ", ""));
                            var    s   = db.CustomersSet.Include <CustomerEntity, ICollection <AddressEntity> >(c => c.Addresslist).FirstOrDefault(c => c.Name == orderItem.Consignee.Name && c.Phone == orderItem.Consignee.Phone);
                            if (s != null)
                            {
                                orderItem.Consignee       = s;
                                orderItem.OrderExtendInfo = new OrderExtendInfo()
                                {
                                    IsReturningCustomer = true
                                };
                                DateTime startSeasonTime, endSeasonTime, startYearTime, endYearTime, startWeekTime, endWeekTime;
                                Util.Helpers.Time.GetTimeBySeason(orderItem.CreatedDate.Year, Util.Helpers.Time.GetSeasonNum(orderItem.CreatedDate), out startSeasonTime, out endSeasonTime);
                                Util.Helpers.Time.GetTimeByYear(orderItem.CreatedDate.Year, out startYearTime, out endYearTime);
                                Util.Helpers.Time.GetTimeByWeek(orderItem.CreatedDate.Year, Util.Helpers.Time.GetWeekNum(orderItem.CreatedDate), out startWeekTime, out endWeekTime);

                                orderItem.OrderRepurchase = new OrderRepurchase()
                                {
                                    DailyRepurchase  = true,
                                    MonthRepurchase  = s.CreateDate.Value.Date < new DateTime(orderItem.CreatedDate.Year, orderItem.CreatedDate.Month, 1).Date ? true : false,
                                    SeasonRepurchase = s.CreateDate.Value.Date < startSeasonTime.Date ? true : false,
                                    WeekRepurchase   = s.CreateDate.Value.Date < startWeekTime.Date ? true : false,
                                    YearRepurchase   = s.CreateDate.Value.Date < startYearTime.Date ? true : false,
                                };

                                //更新收件人与地址的关系

                                if (s.Addresslist.Any(a => a.MD5 == md5))
                                {
                                    var addr = s.Addresslist.First(a => a.MD5 == md5);
                                    orderItem.ConsigneeAddress = addr;//替换地址对象
                                }
                                else
                                {
                                    orderItem.ConsigneeAddress.MD5 = md5;
                                    s.Addresslist.Add(orderItem.ConsigneeAddress);
                                }
                            }
                            else//没找到备案的收货人
                            {
                                orderItem.OrderRepurchase = new OrderRepurchase();

                                orderItem.ConsigneeAddress.MD5 = md5;
                                if (orderItem.Consignee.Addresslist == null)
                                {
                                    orderItem.Consignee.Addresslist = new List <AddressEntity>();
                                }
                                orderItem.Consignee.Addresslist.Add(orderItem.ConsigneeAddress);
                                db.AddressSet.Add(orderItem.ConsigneeAddress);
                                db.CustomersSet.Add(orderItem.Consignee);
                            }
                        }
                        else //异常订单
                        {
                            ExceptionOrder exceptionOrder = new ExceptionOrder()
                            {
                                OrderFileName = file,
                                OrderInfo     = Util.Helpers.Json.ToJson(orderItem),
                                ErrorCode     = ExceptionType.PhoneNumOrPersonNameIsNull,
                                ErrorMessage  = Util.Helpers.Enum.GetDescription <ExceptionType>(ExceptionType.PhoneNumOrPersonNameIsNull),
                                Source        = this.Name
                            };
                            db.ExceptionOrders.Add(exceptionOrder);
                            db.SaveChanges();
                            continue;
                        }
                        //查找商品字典
                        var bar = db.ProductDictionarySet.FirstOrDefault(p => p.ProductId == productsku);
                        if (bar == null || string.IsNullOrEmpty(bar.ProductCode))
                        {
                            bar = db.ProductDictionarySet.FirstOrDefault(p => p.ProductNameInPlatform == productName);
                            if (bar == null || string.IsNullOrEmpty(bar.ProductCode))
                            {
                                Util.Logs.Log.GetLog(nameof(TMExcelOrderOption)).Error($"订单文件:{file}中平台商品:{productName}未找到");
                                //  Util.Logs.Log.GetLog(nameof(CIBVIPCSVOrderOption)).Debug($"订单文件:{file}中平台商品:{productName}未找到.order:{Util.Helpers.Json.ToJson(orderItem)}");
                                continue;
                            }
                        }
                        if (string.IsNullOrEmpty(bar.ProductNameInPlatform))
                        {
                            bar.ProductNameInPlatform = productName;
                            db.SaveChanges();
                        }
                        var foo = db.ProductsSet.Include(p => p.weightModel).FirstOrDefault(p => p.sku == bar.ProductCode);
                        if (foo == null)
                        {
                            Util.Logs.Log.GetLog(nameof(TMExcelOrderOption)).Error($"订单文件:{file}中平台商品名称:{productName}对应系统商品未找到");
                            Util.Logs.Log.GetLog(nameof(TMExcelOrderOption)).Debug($"订单文件:{file}中平台商品名称:{productName}对应系统商品未找到.order:{Util.Helpers.Json.ToJson(orderItem)}");
                            continue;
                        }

                        decimal          weight           = foo == null ? 0 : foo.QuantityPerUnit * quantity;
                        OrderProductInfo orderProductInfo = new OrderProductInfo()
                        {
                            ProductPlatId   = productsku,
                            ProductPlatName = productName,
                            //   Warehouse = orderItem.OrderLogistics.Logistics,
                            MonthNum       = createdDate.Month,
                            weightCode     = foo.weightModel == null ? 0 : foo.weightModel.Code,
                            weightCodeDesc = foo.weightModel == null ? string.Empty : $"{foo.weightModel.Value}g",
                            OrderSn        = orderItem.OrderSn,
                            TotalAmount    = totalAmount,
                            ProductCount   = quantity,
                            ProductWeight  = weight,
                            Source         = source,

                            sku = foo.sku
                        };
                        orderItem.Products.Add(orderProductInfo);
                        items.Add(orderItem);
                        db.OrderRepurchases.Add(orderItem.OrderRepurchase);
                        db.OrderDateInfos.Add(orderItem.OrderDateInfo);


                        db.SaveChanges();
                    }
                }
                else
                {
                    var productName  = Convert.ToString(row["商品名称"]);
                    var productsku   = Convert.ToString(row["商品编码"]);
                    var quantity     = Convert.ToInt32(row["数量"]);
                    var itemPriceStr = Convert.ToString(row["商品价格(广发售价)"]).Replace("¥", "").Trim();
                    var itemPrice    = Convert.ToDecimal(itemPriceStr);

                    var totalAmount = itemPrice * quantity;

                    using (var db = new OMSContext())
                    {
                        var bar = db.ProductDictionarySet.FirstOrDefault(p => p.ProductId == productsku);
                        if (bar == null || string.IsNullOrEmpty(bar.ProductCode))
                        {
                            bar = db.ProductDictionarySet.FirstOrDefault(p => p.ProductNameInPlatform == productName);
                            if (bar == null || string.IsNullOrEmpty(bar.ProductCode))
                            {
                                Util.Logs.Log.GetLog(nameof(TMExcelOrderOption)).Error($"订单文件:{file}中平台商品:{productName}未找到");
                                Util.Logs.Log.GetLog(nameof(TMExcelOrderOption)).Debug($"订单文件:{file}中平台商品:{productName}未找到.order:{Util.Helpers.Json.ToJson(item)}");
                                continue;
                            }
                        }
                        if (string.IsNullOrEmpty(bar.ProductNameInPlatform))
                        {
                            bar.ProductNameInPlatform = productName;
                            db.SaveChanges();
                        }
                        var foo = db.ProductsSet.Include(p => p.weightModel).FirstOrDefault(p => p.sku == bar.ProductCode);
                        if (foo == null)
                        {
                            Util.Logs.Log.GetLog(nameof(TMExcelOrderOption)).Error($"订单文件:{file}中平台商品名称:{productName}对应系统商品未找到");
                            Util.Logs.Log.GetLog(nameof(TMExcelOrderOption)).Debug($"订单文件:{file}中平台商品名称:{productName}对应系统商品未找到.order:{Util.Helpers.Json.ToJson(item)}");
                            continue;
                        }

                        decimal          weight           = foo == null ? 0 : foo.QuantityPerUnit * quantity;
                        OrderProductInfo orderProductInfo = new OrderProductInfo()
                        {
                            ProductPlatId   = productsku,
                            ProductPlatName = productName,
                            //   Warehouse = item.OrderLogistics.Logistics,
                            MonthNum       = createdDate.Month,
                            weightCode     = foo.weightModel == null ? 0 : foo.weightModel.Code,
                            weightCodeDesc = foo.weightModel == null ? string.Empty : $"{foo.weightModel.Value}g",
                            OrderSn        = item.OrderSn,
                            TotalAmount    = totalAmount,
                            ProductCount   = quantity,
                            ProductWeight  = weight,
                            Source         = source,
                            sku            = foo.sku
                        };
                        if (item.Products.FirstOrDefault(p => p.sku == foo.sku) == null)
                        {
                            item.Products.Add(orderProductInfo);
                            db.OrderProductSet.Add(orderProductInfo);
                            db.SaveChanges();
                        }
                    }
                }
            }
            return(items);
        }
Beispiel #17
0
        protected void butSubmit_Click(object sender, EventArgs e)
        {
            if (chkAgree.Checked)
            {
                var fullname  = HTMLUtility.SecureHTML(txtFullName.Text.Trim());
                var tel       = HTMLUtility.SecureHTML(txtTel.Text.Trim());
                var address   = HTMLUtility.SecureHTML(txtAddress.Text.Trim());
                var district  = HTMLUtility.SecureHTML(txtDistrict.Text.Trim());
                var city      = HTMLUtility.SecureHTML(txtCity.Text.Trim());
                var note      = HTMLUtility.SecureHTML(txtNote.Text.Trim());
                var orderdate = DateTime.Now;


                if (fullname.Length == 0 || tel.Length == 0 || address.Length == 0 || district.Length == 0 || city.Length == 0)
                {
                    MessageBox.Show("Bạn phải điền đủ các trường (*)");
                    return;
                }



                var cart = (CommonLibrary.CartShopping.Cart)Session["cart"];

                string email = CookieUtility.GetCookie("Member_Email");

                var totalprice = cart.TotalPrice;

                var memberInfo = MemberDB.GetInfoByEmail(email);
                if (memberInfo.Member_Fullname.Length == 0)
                {
                    memberInfo.Member_Fullname = fullname;
                }
                if (memberInfo.Member_Tel.Length == 0)
                {
                    memberInfo.Member_Tel = tel;
                }
                if (memberInfo.Member_Address.Length == 0)
                {
                    memberInfo.Member_Address = address;
                }
                if (memberInfo.Member_District.Length == 0)
                {
                    memberInfo.Member_District = district;
                }
                if (memberInfo.Member_City.Length == 0)
                {
                    memberInfo.Member_City = city;
                }

                MemberDB.Update(memberInfo);

                var info = new OrderInfo();

                info.Member_ID        = MemberDB.GetIDByEmail(email);
                info.Order_Fullname   = fullname;
                info.Order_Email      = email;
                info.Order_Tel        = tel;
                info.Order_Address    = address;
                info.Order_District   = district;
                info.Order_City       = city;
                info.Order_Note       = note;
                info.Order_CreateDate = orderdate;
                info.Order_Status     = 0;
                info.Order_Price      = ConvertUtility.ToDouble(totalprice);
                info.Order_Quantity   = ConvertUtility.ToInt32(cart.Items.Count);

                var orderid = OrderDB.Insert(info);

                var sbProducts = new StringBuilder();

                sbProducts.Append("<tr>");

                foreach (DataGridItem item in dtgProduct.Items)
                {
                    var id       = ConvertUtility.ToInt32(item.Cells[0].Text);
                    var quantity = ConvertUtility.ToInt32(item.Cells[1].Text);
                    var price    = ConvertUtility.ToInt32(item.Cells[2].Text);
                    var sum      = price * quantity;
                    var oinfo    = new OrderProductInfo();


                    oinfo.Order_ID   = orderid;
                    oinfo.Content_ID = id;
                    oinfo.Quantity   = quantity;
                    oinfo.Price      = price;
                    oinfo.PriceSum   = sum;

                    OrderProductDB.Insert(oinfo);

                    sbProducts.Append("<td style=\"padding: 4px; border: 1px #b1d1e6 solid; text-align: center;\">" + item.ItemIndex + 1 + "</td>");
                    sbProducts.Append("<td style=\"padding: 4px; border: 1px #b1d1e6 solid;\">" + ContentDB.GetName(id) + "</td>");
                    sbProducts.Append("<td style=\"padding: 4px; border: 1px #b1d1e6 solid; text-align: center;\">" + quantity + "</td>");
                    sbProducts.Append("<td style=\"padding: 4px; border: 1px #b1d1e6 solid; text-align: center;\">" + string.Format("{0:0,0}", price) + "</td>");
                    sbProducts.Append("<td style=\"padding: 4px; border: 1px #b1d1e6 solid; text-align: center;\">" + string.Format("{0:0,0}", sum) + "</td>");
                }

                sbProducts.Append("</tr>");

                string emailadd = AppEnv.ContactEmail;

                var sb = new StringBuilder();
                sb.Append("Ban co don dat hang #" + orderid + " tu My-Deal.vn:");
                sb.Append("<br><br><b>Ten</b>: ");
                sb.Append(fullname);
                sb.Append("<br><b>Email</b>: ");
                sb.Append(email);
                sb.Append("<br><b>Dien thoai</b>: ");
                sb.Append(tel);
                sb.Append("<br><b>Dia chi</b>: ");
                sb.Append(txtAddress.Text);
                sb.Append("<br><b>Noi dung</b>:<br>");
                sb.Append(txtNote.Text);
                sb.Append("<br><br>-----------------------------<br>De biet thong tin chi tiet don hang, hay dang nhang vao website<br>");

                // new email solution start

                MailMessage emailmess = new MailMessage(email, emailadd);
                emailmess.Subject    = "Don dat hang cua khach hang tu website";
                emailmess.IsBodyHtml = true;
                emailmess.Body       = sb.ToString();

                SmtpClient smtp = new SmtpClient();

                if (AppEnv.MailServer.Length == 0)
                {
                    smtp.Host = "localhost";
                }
                else
                {
                    smtp.Host = AppEnv.MailServer;
                }

                if (AppEnv.MailServerPort.Length == 0)
                {
                    smtp.Port = 25;
                }
                else
                {
                    smtp.Port = ConvertUtility.ToInt32(AppEnv.MailServerPort);
                }

                // if authentication
                if (AppEnv.MailUsername.Length > 0 && AppEnv.MailPassword.Length > 0)
                {
                    smtp.Credentials    = new NetworkCredential(AppEnv.MailUsername, AppEnv.MailPassword);
                    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                }
                // if authentication end

                // gui cho khach hang thong tin deal

                var emailForCusContent = "";

                //try
                //{
                const string templateUrl = "/templates/deal_confirm.htm";
                var          htmlpage    = GetHtmlPage(templateUrl);
                if (htmlpage != "NULL")
                {
                    emailForCusContent = htmlpage;
                }
                //}
                //catch
                //{
                //    ErrorReportDB.NewReport(Request.RawUrl, "Thong tin CK HOSE:" + DateTime.Now);
                //}

                emailForCusContent = emailForCusContent.Replace("[[order_id]]", orderid.ToString()).Replace("[[order_datetime]]", orderdate.ToString("dd/MM/yyyy HH:mm")).Replace("[[order_note]]", note).Replace("[[order_products]]", sbProducts.ToString()).Replace("[[order_pricesum]]", string.Format("{0:0,0}", totalprice) + " VNĐ").Replace("[[order_fullname]]", fullname).Replace("[[order_address]]", address).Replace("[[order_tel]]", tel);

                // new email solution start
                var emailmess2 = new MailMessage(emailadd, email);
                emailmess2.Subject    = "[My-deal.vn] Thong tin dat hang #" + orderid;
                emailmess2.IsBodyHtml = true;
                emailmess2.Body       = emailForCusContent;

                var smtp2 = new SmtpClient();

                if (AppEnv.MailServer.Length == 0)
                {
                    smtp2.Host = "localhost";
                }
                else
                {
                    smtp2.Host = AppEnv.MailServer;
                }

                if (AppEnv.MailServerPort.Length == 0)
                {
                    smtp2.Port = 25;
                }
                else
                {
                    smtp2.Port = ConvertUtility.ToInt32(AppEnv.MailServerPort);
                }

                // if authentication
                if (AppEnv.MailUsername.Length > 0 && AppEnv.MailPassword.Length > 0)
                {
                    smtp2.Credentials    = new NetworkCredential(AppEnv.MailUsername, AppEnv.MailPassword);
                    smtp2.DeliveryMethod = SmtpDeliveryMethod.Network;
                }
                // if authentication end

                try
                {
                    smtp.Send(emailmess);

                    smtp2.Send(emailmess2);
                    notice.InnerHtml = "<br><br><br><font color=black><b>Đơn đặt hàng của bạn đã được gửi tới " + emailadd + ".Chúng tôi sẽ liên hệ với bạn trong thời gian ngắn nhất<br /><br />Xin chân thành cảm ơn!</b></font>";
                }
                catch (Exception z)
                {
                    notice.InnerHtml =
                        "<br><br><br><font color=black><b>Đơn đặt hàng của bạn đã được gửi đi..Chúng tôi sẽ liên hệ với bạn trong thời gian ngắn nhất<br /><br />Xin chân thành cảm ơn!</b></font><br>";
                }
                finally
                {
                    pnPayment.Visible = false;
                    notice.Visible    = true;
                    SessionUtility.Remove("cart");
                }
            }
            else
            {
                MessageBox.Show("Bạn cần phải đồng ý với điều khoản của My-Deal.vn");
            }
        }
Beispiel #18
0
        /// <summary>
        /// 拉取订单待发货订单
        /// </summary>
        /// <returns></returns>
        public string List()
        {
            var    result   = new JsonResult();
            string appid    = HttpContext.Current.Request["appid"];
            string sign     = HttpContext.Current.Request["sign"];
            string jsonData = HttpContext.Current.Request["jsonData"];

            //验证秘钥
            bool isPass = Security.SecurityCheck(appid, sign, jsonData);

            if (!isPass)
            {
                result.code    = (int)OrderError.接口秘钥无效;
                result.message = OrderError.接口秘钥无效.ToString();
                result.data    = null;
                return(JsonHelper.GetJson(result));
            }

            //序列化json
            PageForm pageFrom = JsonHelper.ConvertToObj <PageForm>(jsonData);

            string strWhere = string.Empty;

            strWhere += " CreateTime > '" + ConvertDataTimeHelper.ConvertLongDateTime(pageFrom.StartTime).ToString() + "'";
            strWhere += " AND CreateTime < '" + ConvertDataTimeHelper.ConvertLongDateTime(pageFrom.EndTime).ToString() + "'";
            int count = 0;//总条数
            OperationResult <IList <OrdersInfo> > orderInfoList =
                OrderLogisticsSqlBLL.Instance.Orders_GetList(pageFrom.Page, pageFrom.Size, " CreateTime DESC ", strWhere, 0, out count);

            OperationResult <IList <OrderProductInfo> > orderProductInfoList =
                OrderLogisticsSqlBLL.Instance.OrderProduct_GetList(strWhere);
            //数据组合
            IList <OrdersResponse> response = new List <OrdersResponse>();

            foreach (var o in orderInfoList.AppendData)
            {
                OrdersResponse or = new OrdersResponse();
                or.OrderID      = o.OrderID;
                or.PaySum       = o.PaySum;
                or.ProductFee   = o.ProductFee;
                or.NewShipFee   = o.NewShipFee;
                or.VoucherFee   = o.VoucherFee;
                or.ShipMethodID = o.ShipMethodID;
                or.Province     = o.Province;
                or.City         = o.City;
                or.County       = o.County;
                or.Address      = o.Address;
                or.Receiver     = o.Receiver;
                or.Telephone    = o.Telephone;
                or.Mobile       = o.Mobile;
                or.Invoice      = o.Invoice;
                or.Remarks      = o.Remarks;
                or.CreateTime   = ConvertDataTimeHelper.ConvertDataTimeLong(o.CreateTime);
                or.OrderDetails = new List <OrderProductInfo>();
                foreach (var op in orderProductInfoList.AppendData)
                {
                    if (o.OrderID == op.OrderID)
                    {
                        OrderProductInfo opInfo = new OrderProductInfo();
                        opInfo.OrderID        = op.OrderID;
                        opInfo.ProductCode    = op.ProductCode;
                        opInfo.ProductID      = op.ProductID;
                        opInfo.ProductName    = op.ProductName;
                        opInfo.ProfeeDiscount = op.ProfeeDiscount;
                        opInfo.Quantity       = opInfo.Quantity;
                        or.OrderDetails.Add(opInfo);
                    }
                }
                response.Add(or);
            }
            //返回结果
            if (orderInfoList.ResultType != OperationResultType.Success)
            {
                result.message = orderInfoList.Message;
                result.code    = (int)OrderError.数据连接失败;
                result.data    = null;
            }
            else
            {
                result.message = OrderError.数据返回成功.ToString();
                result.code    = (int)OrderError.数据返回成功;
                result.data    = JsonHelper.GetJson(response);
            }
            return(JsonHelper.GetJson(result));
        }
Beispiel #19
0
        private List <OrderEntity> ResolveOrders(CsvReader csv, string file, List <OrderEntity> items)
        {
            csv.Read();
            csv.ReadHeader();
            while (csv.Read())
            {
                OrderDTO orderDTO = new OrderDTO();
                orderDTO.fileName   = file;
                orderDTO.source     = this.Name;
                orderDTO.sourceDesc = Util.Helpers.Reflection.GetDescription <OrderSource>(orderDTO.source);
                orderDTO.sourceSN   = csv.GetField <string>("订单编号").Trim();
                orderDTO.orderType  = 0;
                if (string.IsNullOrEmpty(orderDTO.sourceSN))
                {
                    InputExceptionOrder(orderDTO, ExceptionType.SourceSnIsNull);

                    continue;
                }



                var orderDate = csv.GetField <string>("行权日期");
                var orderTime = csv.GetField <string>("行权时间");
                orderDTO.createdDate = DateTime.ParseExact(string.Format("{0}{1}", orderDate, orderTime), "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
                // orderDTO.orderSN_old = string.Format("{0}-{1}", orderDTO.source, orderDTO.sourceSN); //订单SN=来源+原来的SN
                orderDTO.orderSN = string.Format("{0}-{1}_{2}", orderDTO.source, orderDTO.sourceSN, orderDTO.createdDate.ToString("yyyyMMdd"));

                orderDTO.orderStatus = OrderStatus.Confirmed;

                var sourceStatus = csv.GetField <string>("订单状态").Trim();
                if (sourceStatus.Contains("撤消"))
                {
                    orderDTO.orderStatus = OrderStatus.Cancelled;
                    orderDTO.orderType   = 2;
                }


                orderDTO.productName = csv.GetField <string>("服务项目").Trim();
                orderDTO.count       = csv.GetField <int>("本人次数");

                orderDTO.consigneeName = csv.GetField <string>("使用人姓名").Trim();
                if (string.IsNullOrEmpty(orderDTO.consigneeName))
                {
                    orderDTO.consigneeName = csv.GetField <string>("姓名").Trim();
                }

                orderDTO.consigneePhone = csv.GetField <string>("手机号").Trim();



                orderDTO.consigneeAddress = csv.GetField <string>("地址").Trim();

                if (string.IsNullOrEmpty(orderDTO.consigneeProvince) &&
                    string.IsNullOrEmpty(orderDTO.consigneeCity) && !string.IsNullOrEmpty(orderDTO.consigneeAddress))
                {
                    var addrInfo = DistrictService.DistrictService.ResolveAddress(orderDTO.consigneeAddress);
                    orderDTO.consigneeProvince = addrInfo.Province;
                    orderDTO.consigneeCity     = addrInfo.City;
                    orderDTO.consigneeCounty   = addrInfo.County;
                }
                //数据库中查找订单,如果找到订单了就跳过
                if (CheckOrderInDataBase(orderDTO))
                {
                    continue;
                }
                //内存中查找,没找到就新增对象,找到就关联新的商品
                var item = items.Find(o => o.OrderSn == orderDTO.orderSN);
                if (item == null)
                {
                    OrderEntity orderItem = OrderEntityService.CreateOrderEntity(orderDTO);
                    //处理订单与地址、收货人、商品的关联关系。消除重复项
                    using (var db = new OMSContext())
                    {
                        //查找联系人
                        if (!string.IsNullOrEmpty(orderItem.Consignee.Phone))
                        {
                            OrderEntityService.InputConsigneeInfo(orderItem, db);
                        }
                        else //异常订单
                        {
                            InputExceptionOrder(orderDTO, ExceptionType.PhoneNumOrPersonNameIsNull);
                            continue;
                        }


                        if (!InputProductInfoWithoutSaveChange(db, orderDTO, orderItem))
                        {
                            continue;
                        }
                        items.Add(orderItem);

                        db.OrderRepurchases.Add(orderItem.OrderRepurchase);
                        db.OrderDateInfos.Add(orderItem.OrderDateInfo);


                        db.SaveChanges();
                    }
                }
                else
                {
                    using (var db = new OMSContext())
                    {
                        var bar = db.ProductDictionarySet.FirstOrDefault(p => p.ProductNameInPlatform == orderDTO.productName);
                        if (bar == null || string.IsNullOrEmpty(bar.ProductCode))
                        {
                            Util.Logs.Log.GetLog(nameof(CIBVIPCSVOrderOption)).Error($"订单文件:{file}中平台商品:{orderDTO.productName}未找到");
                            //  Util.Logs.Log.GetLog(nameof(CIBVIPCSVOrderOption)).Debug($"订单文件:{file}中平台商品:{productName}未找到.order:{Util.Helpers.Json.ToJson(item)}");
                            if (bar == null)
                            {
                                ProductDictionary productDictionary = new ProductDictionary()
                                {
                                    ProductNameInPlatform = orderDTO.productName
                                };
                                db.ProductDictionarySet.Add(productDictionary);
                                db.SaveChanges();
                            }
                            items.Remove(item);
                            continue;
                        }
                        var foo = db.ProductsSet.Include(p => p.weightModel).FirstOrDefault(p => p.sku == bar.ProductCode);
                        if (foo == null)
                        {
                            Util.Logs.Log.GetLog(nameof(CIBVIPCSVOrderOption)).Error($"订单文件:{file}中平台商品名称:{orderDTO.productName}对应系统商品未找到");

                            items.Remove(item);
                            continue;
                        }

                        decimal weight = foo == null ? 0 : foo.QuantityPerUnit * orderDTO.count;
                        if (orderDTO.orderStatus == OrderStatus.Cancelled)
                        {
                            var p = item.Products.FirstOrDefault(o => o.sku == foo.sku);
                            if (p != null)
                            {
                                p.ProductCount  -= orderDTO.count;
                                p.ProductWeight -= weight;
                            }
                        }
                        else
                        {
                            if (item.Products.FirstOrDefault(p => p.sku == foo.sku) == null)
                            {
                                OrderProductInfo orderProductInfo = new OrderProductInfo()
                                {
                                    ProductPlatId   = orderDTO.productsku,
                                    ProductPlatName = orderDTO.productName.Trim(),
                                    //   Warehouse = item.OrderLogistics.Logistics,
                                    MonthNum       = orderDTO.createdDate.Month,
                                    weightCode     = foo.weightModel == null ? 0 : foo.weightModel.Code,
                                    weightCodeDesc = foo.weightModel == null ? string.Empty : $"{foo.weightModel.Value}g",
                                    OrderSn        = orderDTO.orderSN,
                                    //  TotalAmount = totalAmount,
                                    ProductCount  = orderDTO.count,
                                    ProductWeight = weight,
                                    Source        = orderDTO.source,
                                    sku           = foo.sku
                                };
                                item.Products.Add(orderProductInfo);
                            }
                        }
                    }
                }
            }

            return(items);
        }
Beispiel #20
0
        /// <summary>
        /// 评价商品
        /// </summary>
        public ActionResult ReviewProduct()
        {
            int    oid      = WebHelper.GetQueryInt("oid");       //订单id
            int    recordId = WebHelper.GetQueryInt("recordId");  //订单商品记录id
            int    star     = WebHelper.GetFormInt("star");       //星星
            string message  = WebHelper.GetFormString("message"); //评价内容

            if (star > 5 || star < 0)
            {
                return(AjaxResult("wrongstar", "请选择正确的星星"));
            }

            if (message.Length == 0)
            {
                return(AjaxResult("emptymessage", "请填写评价内容"));
            }
            if (message.Length > 100)
            {
                return(AjaxResult("muchmessage", "评价内容最多输入100个字"));
            }
            //禁止词
            string bannedWord = FilterWords.GetWord(message);

            if (bannedWord != "")
            {
                return(AjaxResult("bannedWord", "评价内容中不能包含违禁词"));
            }

            OrderInfo orderInfo = Orders.GetOrderByOid(oid);

            if (orderInfo == null || orderInfo.Uid != WorkContext.Uid)
            {
                return(AjaxResult("noexistorder", "订单不存在"));
            }
            if (orderInfo.OrderState != (int)OrderState.Completed)
            {
                return(AjaxResult("nocomplete", "订单还未完成,不能评价"));
            }

            OrderProductInfo        orderProductInfo = null;
            List <OrderProductInfo> orderProductList = Orders.GetOrderProductList(oid);

            foreach (OrderProductInfo item in orderProductList)
            {
                if (item.RecordId == recordId)
                {
                    orderProductInfo = item;
                    break;
                }
            }
            if (orderProductInfo == null)
            {
                return(AjaxResult("noproduct", "商品不存在"));
            }
            //商品已评价
            if (orderProductInfo.IsReview == 1)
            {
                return(AjaxResult("reviewed", "商品已经评价"));
            }

            int payCredits = Credits.SendReviewProductCredits(ref WorkContext.PartUserInfo, orderProductInfo, DateTime.Now);
            ProductReviewInfo productReviewInfo = new ProductReviewInfo()
            {
                Pid        = orderProductInfo.Pid,
                Uid        = orderProductInfo.Uid,
                OPRId      = orderProductInfo.RecordId,
                Oid        = orderProductInfo.Oid,
                ParentId   = 0,
                State      = 0,
                Star       = star,
                Quality    = 0,
                Message    = WebHelper.HtmlEncode(FilterWords.HideWords(message)),
                ReviewTime = DateTime.Now,
                PayCredits = payCredits,
                PName      = orderProductInfo.Name,
                PShowImg   = orderProductInfo.ShowImg,
                BuyTime    = orderProductInfo.AddTime,
                IP         = WorkContext.IP
            };

            ProductReviews.ReviewProduct(productReviewInfo);

            orderProductInfo.IsReview = 1;
            if (Orders.IsReviewAllOrderProduct(orderProductList))
            {
                Orders.UpdateOrderIsReview(oid, 1);
            }

            return(AjaxResult("success", recordId.ToString()));
        }
Beispiel #21
0
        protected override bool InputProductInfoWithoutSaveChange(OMSContext db, OrderDTO orderDTO, OrderEntity item)
        {
            if (string.IsNullOrEmpty(orderDTO.productsku))//京东订单的productsku===sku,若值为null ,意味着用户取消了订单,这个订单不计入OMS
            {
                return(false);
            }
            var foo = db.ProductsSet.Include(p => p.weightModel).FirstOrDefault(p => p.sku.Trim() == orderDTO.productsku);



            if (foo == null)
            {
                OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productsku})对应ERP商品记录未找到");
                InputExceptionOrder(orderDTO, ExceptionType.ProductCodeUnKnown);
                return(false);
            }

            /*
             * 订单来源是ERP,同时商品SKU是周期购商品的SKU,判定为周期购日常发货订单
             * 周期购日常发货订单不纳入日常统计中,为了和客户下的周期购订单区分开
             * 统计报表中只统计销售订单
             *
             */
            if (foo.sku == "S0010030002" || foo.sku == "S0010040002")//标识该订单是周期购订单
            {
                item.OrderType += 4;
            }
            var     bar    = item.Products.FirstOrDefault(p => p.sku == foo.sku);
            decimal weight = foo == null ? 0 : foo.QuantityPerUnit * orderDTO.count;

            if (bar == null)
            {
                OrderProductInfo orderProductInfo = new OrderProductInfo()
                {
                    ProductPlatId   = orderDTO.productsku,
                    ProductPlatName = orderDTO.productName,
                    //   Warehouse = item.OrderLogistics.Logistics,
                    MonthNum       = orderDTO.createdDate.Month,
                    weightCode     = foo.weightModel == null ? 0 : foo.weightModel.Code,
                    weightCodeDesc = foo.weightModel == null ? string.Empty : $"{foo.weightModel.Value}g",
                    OrderSn        = orderDTO.orderSN,
                    TotalAmount    = orderDTO.totalAmount,
                    DiscountFee    = orderDTO.discountFee,
                    AmounPerUnit   = orderDTO.pricePerUnit,
                    ProductCount   = orderDTO.count,
                    ProductWeight  = weight,
                    Source         = orderDTO.source,
                    sku            = foo.sku
                };
                item.Products.Add(orderProductInfo);
            }
            else
            {
                bar.ProductWeight += weight;
                bar.ProductCount  += orderDTO.count;
            }



            OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productsku})解析完毕");
            return(true);
        }
Beispiel #22
0
        /// <summary>
        /// 修改购物车中套装数量
        /// </summary>
        public ActionResult ChangeSuitCount()
        {
            //当商城不允许游客使用购物车时
            if (WorkContext.ShopConfig.IsGuestSC == 0 && WorkContext.Uid < 1)
            {
                return(AjaxResult("nologin", "请先登录"));
            }

            int    pmId     = WebHelper.GetQueryInt("pmId");                                      //套装id
            int    buyCount = WebHelper.GetQueryInt("buyCount");                                  //购买数量
            string selectedCartItemKeyList = WebHelper.GetQueryString("selectedCartItemKeyList"); //选中的购物车项键列表

            //购物车商品列表
            List <OrderProductInfo> orderProductList = Carts.GetCartProductList(WorkContext.Uid, WorkContext.Sid);
            //套装商品列表
            List <OrderProductInfo> suitOrderProductList = Carts.GetSuitOrderProductList(pmId, orderProductList, true);

            if (suitOrderProductList.Count > 0) //当套装已经存在
            {
                if (buyCount < 1)               //当购买数量小于1时,删除此套装
                {
                    Carts.DeleteCartSuit(ref orderProductList, pmId);
                }
                else
                {
                    OrderProductInfo orderProductInfo = suitOrderProductList.Find(x => x.Type == 3);
                    int oldBuyCount = orderProductInfo.RealCount / orderProductInfo.ExtCode2;
                    if (buyCount != oldBuyCount)
                    {
                        Carts.AddExistSuitToCart(ref orderProductList, suitOrderProductList, buyCount);
                    }
                }
            }

            //商品数量
            int pCount = Carts.SumOrderProductCount(orderProductList);
            //选中的订单商品列表
            List <OrderProductInfo> selectedOrderProductList = null;
            //购物车项列表
            List <CartItemInfo> cartItemList = Carts.TidyOrderProductList(StringHelper.SplitString(selectedCartItemKeyList), orderProductList, out selectedOrderProductList);

            //商品总数量
            int totalCount = Carts.SumOrderProductCount(selectedOrderProductList);
            //商品合计
            decimal productAmount = Carts.SumOrderProductAmount(selectedOrderProductList);
            //满减折扣
            int fullCut = Carts.SumFullCut(cartItemList);
            //订单合计
            decimal orderAmount = productAmount - fullCut;

            CartModel model = new CartModel
            {
                TotalCount    = totalCount,
                ProductAmount = productAmount,
                FullCut       = fullCut,
                OrderAmount   = orderAmount,
                CartItemList  = cartItemList
            };

            //将购物车中商品数量写入cookie
            Carts.SetCartProductCountCookie(pCount);

            return(View("ajaxindex", model));
        }
Beispiel #23
0
        /// <summary>
        /// 订单商品来自京东仓,商品ID需要做对应关系
        /// </summary>
        /// <param name="db"></param>
        /// <param name="orderDTO"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        protected bool InputProductInfoWithoutSaveChange_JD(OMSContext db, OrderDTO orderDTO, OrderEntity item)
        {
            ProductDictionary pd = null;

            pd = db.ProductDictionarySet.FirstOrDefault(p => p.ProductId.Trim() == orderDTO.productsku.Trim() && orderDTO.productsku != null && p.ProductCode != null);
            if (pd == null)
            {
                OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productsku})录入失败");
                InputExceptionOrder(orderDTO, ExceptionType.ProductIdUnKnown);
                if (db.ProductDictionarySet.FirstOrDefault(p => p.ProductId == orderDTO.productsku) == null)
                {
                    ProductDictionary productDictionary = new ProductDictionary()
                    {
                        ProductId             = orderDTO.productsku,
                        Source                = orderDTO.source,
                        ProductNameInPlatform = orderDTO.productName.Trim()
                    };
                    db.ProductDictionarySet.Add(productDictionary);
                    db.SaveChanges();
                }
                return(false);
            }
            string temp = pd.ProductCode.Trim();//"S0010040003\t"
            var    foo  = db.ProductsSet.Include(p => p.weightModel).FirstOrDefault(p => p.sku.Trim() == temp);



            if (foo == null)
            {
                OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productsku})对应ERP商品记录未找到");
                InputExceptionOrder(orderDTO, ExceptionType.ProductCodeUnKnown);
                return(false);
            }

            /*
             * 订单来源是ERP,同时商品SKU是周期购商品的SKU,判定为周期购日常发货订单
             * 周期购日常发货订单不纳入日常统计中,为了和客户下的周期购订单区分开
             * 统计报表中只统计销售订单
             *
             */
            if (foo.sku == "S0010030002" || foo.sku == "S0010040002")//标识该订单是周期购订单
            {
                item.OrderType += 4;
            }
            var     bar    = item.Products.FirstOrDefault(p => p.sku == foo.sku);
            decimal weight = foo == null ? 0 : foo.QuantityPerUnit * orderDTO.count;

            if (bar == null)
            {
                OrderProductInfo orderProductInfo = new OrderProductInfo()
                {
                    ProductPlatId   = orderDTO.productsku,
                    ProductPlatName = orderDTO.productName,
                    //   Warehouse = item.OrderLogistics.Logistics,
                    MonthNum       = orderDTO.createdDate.Month,
                    weightCode     = foo.weightModel == null ? 0 : foo.weightModel.Code,
                    weightCodeDesc = foo.weightModel == null ? string.Empty : $"{foo.weightModel.Value}g",
                    OrderSn        = orderDTO.orderSN,
                    TotalAmount    = orderDTO.totalAmount,
                    DiscountFee    = orderDTO.discountFee,
                    AmounPerUnit   = orderDTO.pricePerUnit,
                    ProductCount   = orderDTO.count,
                    ProductWeight  = weight,
                    Source         = orderDTO.source,
                    sku            = foo.sku
                };
                item.Products.Add(orderProductInfo);
            }
            else
            {
                bar.ProductWeight += weight;
                bar.ProductCount  += orderDTO.count;
            }



            OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productsku})解析完毕");
            return(true);
        }
Beispiel #24
0
        /// <summary>
        /// 添加满赠到购物车
        /// </summary>
        public ActionResult AddFullSend()
        {
            //当商城不允许游客使用购物车时
            if (WorkContext.ShopConfig.IsGuestSC == 0 && WorkContext.Uid < 1)
            {
                return(AjaxResult("nologin", "请先登录"));
            }

            int    pmId = WebHelper.GetQueryInt("pmId");                                          //满赠id
            int    pid  = WebHelper.GetQueryInt("pid");                                           //商品id
            string selectedCartItemKeyList = WebHelper.GetQueryString("selectedCartItemKeyList"); //选中的购物车项键列表

            //添加的商品
            PartProductInfo partProductInfo = Products.GetPartProductById(pid);

            if (partProductInfo == null)
            {
                return(AjaxResult("noproduct", "请选择商品"));
            }

            //商品库存
            int stockNumber = Products.GetProductStockNumberByPid(pid);

            if (stockNumber < 1)
            {
                return(AjaxResult("stockout", "商品库存不足"));
            }

            //满赠促销活动
            FullSendPromotionInfo fullSendPromotionInfo = Promotions.GetFullSendPromotionByPmIdAndTime(pmId, DateTime.Now);

            if (partProductInfo == null)
            {
                return(AjaxResult("nopromotion", "满赠促销活动不存在或已经结束"));
            }

            //购物车商品列表
            List <OrderProductInfo> orderProductList = Carts.GetCartProductList(WorkContext.Uid, WorkContext.Sid);

            //满赠主商品列表
            List <OrderProductInfo> fullSendMainOrderProductList = Carts.GetFullSendMainOrderProductList(pmId, orderProductList);

            if (fullSendMainOrderProductList.Count < 1)
            {
                return(AjaxResult("nolimit", "不符合活动条件"));
            }
            decimal amount = Carts.SumOrderProductAmount(fullSendMainOrderProductList);

            if (fullSendPromotionInfo.LimitMoney > amount)
            {
                return(AjaxResult("nolimit", "不符合活动条件"));
            }

            if (!Promotions.IsExistFullSendProduct(pmId, pid, 1))
            {
                return(AjaxResult("nofullsendproduct", "此商品不是满赠商品"));
            }

            //赠送商品
            OrderProductInfo fullSendMinorOrderProductInfo = Carts.GetFullSendMinorOrderProduct(pmId, orderProductList);

            if (fullSendMinorOrderProductInfo != null)
            {
                if (fullSendMinorOrderProductInfo.Pid != pid)
                {
                    Carts.DeleteCartFullSend(ref orderProductList, fullSendMinorOrderProductInfo);
                }
                else
                {
                    return(AjaxResult("exist", "此商品已经添加"));
                }
            }

            //添加满赠商品
            Carts.AddFullSendToCart(ref orderProductList, partProductInfo, fullSendPromotionInfo, WorkContext.Sid, WorkContext.Uid, DateTime.Now);

            //商品数量
            int pCount = Carts.SumOrderProductCount(orderProductList);
            //选中的订单商品列表
            List <OrderProductInfo> selectedOrderProductList = null;
            //购物车项列表
            List <CartItemInfo> cartItemList = Carts.TidyOrderProductList(StringHelper.SplitString(selectedCartItemKeyList), orderProductList, out selectedOrderProductList);

            //商品总数量
            int totalCount = Carts.SumOrderProductCount(selectedOrderProductList);
            //商品合计
            decimal productAmount = Carts.SumOrderProductAmount(selectedOrderProductList);
            //满减折扣
            int fullCut = Carts.SumFullCut(cartItemList);
            //订单合计
            decimal orderAmount = productAmount - fullCut;

            CartModel model = new CartModel
            {
                TotalCount    = totalCount,
                ProductAmount = productAmount,
                FullCut       = fullCut,
                OrderAmount   = orderAmount,
                CartItemList  = cartItemList
            };

            //将购物车中商品数量写入cookie
            Carts.SetCartProductCountCookie(pCount);

            return(View("ajaxindex", model));
        }
Beispiel #25
0
        /// <summary>
        /// 插入商品记录
        /// </summary>
        /// <param name="db"></param>
        /// <param name="orderDTO"></param>
        /// <param name="item"></param>
        protected virtual bool InputProductInfoWithoutSaveChange(OMSContext db, OrderDTO orderDTO, OrderEntity item)
        {
            ProductDictionary pd = null;

            switch (item.Source)
            {
            case OrderSource.CIB:
            case OrderSource.CIBAPP:
            case OrderSource.CIBEVT:
            case OrderSource.CIBSTM:
                pd = db.ProductDictionarySet.FirstOrDefault(p => p.ProductId.Trim() == orderDTO.productsku.Trim() && orderDTO.productsku != null && p.ProductCode != null);
                if (pd == null)
                {
                    OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productsku})录入失败");
                    InputExceptionOrder(orderDTO, ExceptionType.ProductIdUnKnown);
                    if (db.ProductDictionarySet.FirstOrDefault(p => p.ProductId == orderDTO.productsku) == null)
                    {
                        ProductDictionary productDictionary = new ProductDictionary()
                        {
                            ProductId             = orderDTO.productsku,
                            Source                = orderDTO.source,
                            ProductNameInPlatform = orderDTO.productName.Trim()
                        };
                        db.ProductDictionarySet.Add(productDictionary);

                        db.SaveChanges();
                    }
                    return(false);
                }
                break;

            case OrderSource.CMBC:
            case OrderSource.CIBVIP:
            case OrderSource.ICBC_JINWEN:
            case OrderSource.BANK_JINWEN:
            case OrderSource.XUNXIAO:
            case OrderSource.JINGDONG:
            case OrderSource.ICIB:
                pd = db.ProductDictionarySet.FirstOrDefault(p => p.ProductNameInPlatform.Trim() == orderDTO.productName.Trim() && orderDTO.productName != null && p.ProductCode != null);
                if (pd == null)
                {
                    OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productName})录入失败");
                    InputExceptionOrder(orderDTO, ExceptionType.ProductNameUnKnown);
                    if (db.ProductDictionarySet.FirstOrDefault(p => p.ProductNameInPlatform == orderDTO.productName) == null)
                    {
                        ProductDictionary productDictionary = new ProductDictionary()
                        {
                            ProductId             = orderDTO.productsku,
                            Source                = orderDTO.source,
                            ProductNameInPlatform = orderDTO.productName.Trim()
                        };
                        db.ProductDictionarySet.Add(productDictionary);
                        db.SaveChanges();
                    }
                    return(false);
                }
                break;

            default:
                if (string.IsNullOrEmpty(orderDTO.productsku))
                {
                    pd = db.ProductDictionarySet.FirstOrDefault(p => p.ProductNameInPlatform.Trim() == orderDTO.productName.Trim() && orderDTO.productName != null && p.ProductCode != null);
                    if (pd == null)
                    {
                        OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productName})录入失败");
                        InputExceptionOrder(orderDTO, ExceptionType.ProductNameUnKnown);
                        if (db.ProductDictionarySet.FirstOrDefault(p => p.ProductNameInPlatform == orderDTO.productName) == null)
                        {
                            ProductDictionary productDictionary = new ProductDictionary()
                            {
                                ProductId             = orderDTO.productsku,
                                Source                = orderDTO.source,
                                ProductNameInPlatform = orderDTO.productName.Trim()
                            };
                            db.ProductDictionarySet.Add(productDictionary);
                            db.SaveChanges();
                        }
                        return(false);
                    }
                }
                else
                {
                    pd = db.ProductDictionarySet.FirstOrDefault(p => p.ProductId.Trim() == orderDTO.productsku.Trim() && orderDTO.productsku != null && p.ProductCode != null);
                    if (pd == null)
                    {
                        OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productsku})录入失败");
                        InputExceptionOrder(orderDTO, ExceptionType.ProductIdUnKnown);
                        if (db.ProductDictionarySet.FirstOrDefault(p => p.ProductId == orderDTO.productsku) == null)
                        {
                            ProductDictionary productDictionary = new ProductDictionary()
                            {
                                ProductId             = orderDTO.productsku,
                                Source                = orderDTO.source,
                                ProductNameInPlatform = orderDTO.productName.Trim()
                            };
                            db.ProductDictionarySet.Add(productDictionary);
                            db.SaveChanges();
                        }
                        return(false);
                    }
                }
                break;
            }


            // var foo = db.ProductsSet.Include(p => p.weightModel).FirstOrDefault(p => p.sku.Trim() == "S0010040003\t".Trim());
            string temp = pd.ProductCode.Trim();//"S0010040003\t"
            var    foo  = db.ProductsSet.Include(p => p.weightModel).FirstOrDefault(p => p.sku.Trim() == temp);

            if (foo == null)
            {
                OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productsku})对应ERP商品记录未找到");
                InputExceptionOrder(orderDTO, ExceptionType.ProductCodeUnKnown);
                return(false);
            }
            if (item.Products.FirstOrDefault(p => p.sku == foo.sku) == null)
            {
                decimal          weight           = foo == null ? 0 : foo.QuantityPerUnit * orderDTO.count;
                decimal          totalAmount      = pd.PayPrice * orderDTO.count;
                decimal          totalCostPrice   = foo.CostPrice * orderDTO.count;
                decimal          totalFlatAmount  = foo.FlatPrice * orderDTO.count;
                OrderProductInfo orderProductInfo = new OrderProductInfo()
                {
                    ProductPlatId   = orderDTO.productsku,
                    ProductPlatName = orderDTO.productName.Trim(),
                    //   Warehouse = item.OrderLogistics.Logistics,
                    MonthNum        = orderDTO.createdDate.Month,
                    weightCode      = foo.weightModel == null ? 0 : foo.weightModel.Code,
                    weightCodeDesc  = foo.weightModel == null ? string.Empty : $"{foo.weightModel.Value}g",
                    OrderSn         = orderDTO.orderSN,
                    TotalAmount     = totalAmount,
                    TotalCostPrice  = totalCostPrice,
                    TotalFlatAmount = totalFlatAmount,
                    ProductCount    = orderDTO.count,
                    ProductWeight   = weight,
                    Source          = orderDTO.source,

                    sku = foo.sku
                };
                item.Products.Add(orderProductInfo);
            }



            OnUIMessageEventHandle($"订单文件:{orderDTO.fileName}中平台单号:{orderDTO.sourceSN}({orderDTO.productsku})解析完毕");
            return(true);
        }