Ejemplo n.º 1
0
        /// <summary>
        /// 购物车生成订单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public dynamic AddOrderFromShoppingCar(string StuId, int System_Station_ID)
        {
            List <W_CourseModel> Courses = GetShoppingCar(StuId);

            if (Courses != null && Courses.Count > 0)
            {
                bool     flag  = false;
                DateTime time  = DateTime.Now;
                W_Order  order = new W_Order();
                order.AddTime           = time;
                order.PayTime           = time;
                order.OrderNo           = time.ToString("yyyyMMddHHmmss") + new Random().Next(1000, 9999).ToString();
                order.StuId             = StuId;
                order.System_Station_ID = System_Station_ID;
                decimal sum = Courses.Sum(x => x.Price); //如果定价全部为0
                if (sum == 0)                            //免费课程直接支付成功
                {
                    order.Price        = sum;
                    order.PayStatus    = 1;
                    order.PayTime      = time;
                    order.TicketNumber = time.ToString("yyyyMMddHHmmss") + new Random().Next(1000, 9999).ToString();
                    order.PayType      = 1;
                }
                order.Price   = Courses.Sum(x => ((x.PreferentialPrice > 0 && x.Price > 0) ? x.PreferentialPrice : x.Price));
                order.OrderId = Guid.NewGuid().ToString("N").ToUpper();
                int o_id = (int)Orm.Insert(order, true);
                if (o_id > 0)
                {
                    foreach (W_CourseModel course in Courses)
                    {
                        W_Order_Detail orderdetail = new W_Order_Detail();
                        orderdetail.CID       = o_id;
                        orderdetail.Course_ID = course.ID;
                        orderdetail.Price     = (course.PreferentialPrice > 0 && course.Price > 0) ? course.PreferentialPrice : course.Price;
                        flag = Orm.Insert(orderdetail) > 0;
                        if (!flag)
                        {
                            DeleteOrder(order.ID, System_Station_ID);
                            break;
                        }
                    }
                    if (flag)//清空购物车
                    {
                        ClearShoppingCar(StuId);
                    }
                    return(order);
                }
                else
                {
                    throw new ApiException("下单失败");
                }
            }
            else
            {
                throw new ApiException("您的购物车空空如也");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 删除订单课程 hx add 2018-01-12
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteOrderCourse(CampusModel model)
        {
            bool           flag       = false;
            W_Order_Detail Ordermodel = Orm.Single <W_Order_Detail>(x => x.ID == model.orderDetailId);

            if (Ordermodel == null)
            {
                throw new ApiException("未找到该数据,请刷新后再试");
            }

            try
            {
                SqlMapper.BeginTransaction();//开启事务
                if (SqlMapper.Update("DeleteOrderCourse", new { orderDetailId = model.orderDetailId }) > 0)
                {
                    int count = SqlMapper.QueryForObject <int>("OrderByDetailId_Count", new { CID = Ordermodel.CID });
                    if (count == 0)
                    {
                        SqlMapper.Update("UpdateW_OrderState", new { CID = Ordermodel.CID });
                    }
                    else
                    {
                        SqlMapper.Update("UpdateW_OrderPrice", new { CID = Ordermodel.CID });
                    }
                    flag = true;
                }
                SqlMapper.CommitTransaction();  //提交
            }
            catch (Exception ex)
            {
                SqlMapper.RollBackTransaction(); //回滚
                throw new ApiException(ex.Message);
            }
            finally
            {
                //SqlMapper.CloseConnection();
            }

            return(flag);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 学生开课数据录入
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public bool AddOrderStudent(OrderModel model, int System_Station_ID, string StuId)
        {
            bool   flag  = false;
            string stuID = string.IsNullOrEmpty(StuId) ? model.StuId : StuId;
            Random ran   = new Random();

            model.AddTime           = DateTime.Now;
            model.PayTime           = DateTime.Now;
            model.OrderNo           = DateTime.Now.ToString("yyyyMMddHHmmss") + ran.Next(1000, 9999).ToString();
            model.StuId             = stuID;
            model.System_Station_ID = System_Station_ID;
            model.OrderId           = Guid.NewGuid().ToString("N").ToUpper();

            if (!string.IsNullOrWhiteSpace(model.Course_IDs))
            {
                W_Order order = new W_Order();
                order.StuId             = model.StuId;
                order.OrderNo           = model.OrderNo;
                order.System_Station_ID = model.System_Station_ID;
                order.AddTime           = model.AddTime;
                order.Price             = model.Price;
                order.PayStatus         = model.PayStatus;
                order.PayType           = model.PayType;
                order.PayTime           = model.PayTime;
                order.PayPrice          = model.PayPrice;
                order.TicketNumber      = model.TicketNumber;
                order.OrderState        = model.OrderState;
                order.OrderId           = model.OrderId;

                try
                {
                    SqlMapper.BeginTransaction();//开启事务

                    //添加订单
                    int id = (int)Orm.Insert(order, true);
                    if (id > 0)
                    {
                        string[] c_id    = model.Course_IDs.Split(',');
                        string[] c_price = model.Prices.Split(',');
                        for (int i = 0; i < c_id.Length; i++)
                        {
                            W_Order_Detail orderdetail = new W_Order_Detail();
                            orderdetail.CID       = id;
                            orderdetail.Course_ID = int.Parse(c_id[i]);
                            orderdetail.Price     = decimal.Parse(c_price[i]);

                            //添加订单详细
                            Orm.Insert(orderdetail);
                        }

                        flag = true;
                    }

                    SqlMapper.CommitTransaction();  //提交
                }
                catch (Exception ex)
                {
                    SqlMapper.RollBackTransaction(); //回滚
                    throw new ApiException(ex.Message);
                }
                finally
                {
                    //SqlMapper.CloseConnection();
                }
            }
            return(flag);
        }