public OrderModel GetOrder(long orderId, int userId)
        {
            var orderModel = new OrderModel();
            using (var cmd = DataCommandManager.GetDataCommand("GetOrder"))
            {
                cmd.SetParameterValue("@UserId", userId);
                cmd.SetParameterValue("@OrderId", orderId);
                using (var dr = cmd.ExecuteDataReader())
                {
                    while (dr.Read())
                    {
                        orderModel.OrderId = !Convert.IsDBNull("OrderId") ? long.Parse(dr["OrderId"].ToString()) : 0;
                        orderModel.UserId = !Convert.IsDBNull("UserId") ? int.Parse(dr["UserId"].ToString()) : 0;
                        orderModel.ProductId = !Convert.IsDBNull("ProductId") ? int.Parse(dr["ProductId"].ToString()) : 0;
                        orderModel.ProductCount = !Convert.IsDBNull("ProductCount") ? int.Parse(dr["ProductCount"].ToString()) : 0;
                        orderModel.Price = !Convert.IsDBNull("Price") ? decimal.Parse(dr["Price"].ToString()) : 0;
                        orderModel.Status = !Convert.IsDBNull("Status") ? int.Parse(dr["Status"].ToString()) : 0;
                        orderModel.PayType = !Convert.IsDBNull("PayType") ? int.Parse(dr["PayType"].ToString()) : 0;
                        orderModel.CreateTime = !Convert.IsDBNull("CreateTime") ? DateTime.Parse(dr["CreateTime"].ToString()) : DateTime.MinValue;
                    }
                }
            }

            return orderModel;
        }
        /// <summary>
        /// 提交订单
        /// </summary>
        /// <param name="orderModel"></param>
        /// <returns></returns>
        public OrderModel SubmitOrder(OrderModel orderModel)
        {
            var result = new OrderModel();
            using (var cmd = DataCommandManager.GetDataCommand("InsertOrder"))
            {
                cmd.SetParameterValue("@OrderId", orderModel.OrderId);
                cmd.SetParameterValue("@UserId", orderModel.UserId);
                cmd.SetParameterValue("@ProductId", orderModel.ProductId);
                cmd.SetParameterValue("@ProductCount", orderModel.ProductCount);
                cmd.SetParameterValue("@Price", orderModel.Price);
                cmd.SetParameterValue("@Status", orderModel.Status);
                cmd.SetParameterValue("@PayType", orderModel.PayType);
                cmd.SetParameterValue("@CreateTime", orderModel.CreateTime);

                var resultInt = cmd.ExecuteNonQuery();
                if (resultInt > 0)
                {
                    result = GetOrder(orderModel.OrderId, orderModel.UserId);
                }
            }
            return result;
        }
示例#3
0
        /// <summary>
        /// 提交订单
        /// </summary>
        /// <param name="orderModel"></param>
        /// <returns></returns>
        public Result<OrderModel> SubmitOrder(OrderModel orderModel)
        {
            var result = new Result<OrderModel>();
            var productModel = productService.GetProductById(orderModel.ProductId);
            if (productModel.CanSale)
            {
                //订单表 扣去库存
                var tempOrderModel = orderDataAccess.SubmitOrder(orderModel);
                if (tempOrderModel.OrderId > 0)
                {

                    result.Data = tempOrderModel;
                    result.Status = new Status() { Code = "1", Message = "提交订单成功。" };
                    UserModel user = userService.GetUserByUserId(tempOrderModel.UserId);
                    //发送消息
                    messageService.SendSms(user.UserId, string.Format("【科羊云牧-羊客】您的订单<a href=\"/Home/OrderList?orderid={0}&tab=3#Order_{0}\">{0}</a>已经提交成功。", tempOrderModel.OrderId));

                    //发送下单成功短信息
                    smsService.SendSMSOrderCreated(user.Mobile, tempOrderModel.OrderId, tempOrderModel.Price * tempOrderModel.ProductCount);
                }
                else
                {
                    result.Status = new Status() { Code = "0", Message = "提交订单失败,请稍后重试。" };
                }
            }
            else
            {
                result.Status = new Status() { Code = "0", Message = "该产品暂无法销售。" };
            }

            return result;
        }
 private OrderViewModel OrderModelToOrderViewModel(OrderModel orderModel,ProductModel productModel)
 {
     var orderViewModel = new OrderViewModel();
     if (orderModel != null)
     {
         orderViewModel.OrderId = orderModel.OrderId;
         orderViewModel.UserId = orderModel.UserId;
         orderViewModel.CreateTime = orderModel.CreateTime;
         orderViewModel.ProductId = orderModel.ProductId;
         orderViewModel.ProductCount = orderModel.ProductCount;
         orderViewModel.Price = orderModel.Price;
         orderViewModel.Status = orderModel.Status;
         orderViewModel.PayType = orderModel.PayType;
         orderViewModel.TotalMoney = orderModel.Price*orderModel.ProductCount;
     }
     if (productModel != null)
     {
         orderViewModel.ProductName = productModel.Name;
     }
     
     return orderViewModel;
 }
示例#5
0
 public JsonResult SubmitOrder(ConfirmOrderViewModel confirmOrderViewModel)
 {
     var orderModel = new OrderModel
     {
         OrderId = OrderService.GetNewOrderId(),
         UserId = this.UserInfo.UserId,
         ProductId = confirmOrderViewModel.Product.Id,
         Price = confirmOrderViewModel.Product.Price,
         ProductCount = confirmOrderViewModel.Count,
         Status = OrderStatus.Init.GetHashCode(),
         PayType = 0,
         CreateTime = DateTime.Now
     };
     var data=OrderService.SubmitOrder(orderModel);
     var result = new JsonResult();
     result.Data = data;
     return result;
 }