Ejemplo n.º 1
0
        public static void Save_Mall_OrderTradeNo(string TradeNo, List <int> OrderIDList = null)
        {
            var condtions = new List <string>();

            if (OrderIDList != null && OrderIDList.Count > 0)
            {
                condtions.Add("[OrderID] in (" + string.Join(",", OrderIDList.ToArray()) + ")");
            }
            else
            {
                condtions.Add("TradeNo=@TradeNo");
            }
            string cmdtext = "select * from [Mall_OrderTradeNo] where " + string.Join(" and ", condtions.ToArray());
            List <SqlParameter> parameters = new List <SqlParameter>();

            parameters.Add(new SqlParameter("@TradeNo", TradeNo));
            var orderTradeList = GetList <Mall_OrderTradeNo>(cmdtext, parameters);

            if (OrderIDList == null)
            {
                OrderIDList = orderTradeList.Select(p => p.OrderID).ToList();
            }
            using (SqlHelper helper = new SqlHelper())
            {
                try
                {
                    helper.BeginTransaction();
                    if (OrderIDList == null || OrderIDList.Count == 0)
                    {
                        OrderIDList = new List <int>();
                    }
                    if (OrderIDList.Count == 0)
                    {
                        var payment = Payment.GetPaymentByTradeNo(TradeNo, helper);
                        if (payment != null)
                        {
                            OrderIDList.Add(payment.OrderID);
                        }
                    }
                    foreach (var OrderID in OrderIDList)
                    {
                        var data = orderTradeList.FirstOrDefault(p => p.TradeNo.Equals(TradeNo) && p.OrderID == OrderID);
                        if (data == null)
                        {
                            data         = new Mall_OrderTradeNo();
                            data.OrderID = OrderID;
                            data.TradeNo = TradeNo;
                            data.AddTime = DateTime.Now;
                            data.Save(helper);
                        }
                    }
                    cmdtext    = "update [Mall_Order] set TradeNo=@TradeNo where [ID] in (" + string.Join(",", OrderIDList.ToArray()) + ")";
                    parameters = new List <SqlParameter>();
                    parameters.Add(new SqlParameter("@TradeNo", TradeNo));
                    helper.Execute(cmdtext, CommandType.Text, parameters);
                    helper.Commit();
                }
                catch (Exception ex)
                {
                    Utility.LogHelper.WriteError("Mall_OrderTradeNo", "Save_Mall_OrderTradeNo", ex);
                }
            }
        }
Ejemplo n.º 2
0
        public static Payment Insert_Payment(decimal Amount, string PaymentType, string TradeNo, int Status, string AddUser, string Remark, string ResponseContent = "", Payment payment = null, bool CanSave = true, List <Payment_Request> request_list = null, List <RoomFee> fee_list = null, List <Mall_Order> order_list = null, int OrderID = 0, bool IsWuYe = false, bool IsRoomFee = false)
        {
            if (payment == null)
            {
                payment                = new Payment();
                payment.AddTime        = DateTime.Now;
                payment.PayRequestTime = DateTime.Now;
            }
            payment.Amount          = Amount;
            payment.PaymentType     = PaymentType;
            payment.TradeNo         = TradeNo;
            payment.Status          = Status;
            payment.AddUser         = AddUser;
            payment.Remark          = Remark;
            payment.ResponseContent = ResponseContent;
            var OrderIDList = new List <int>();

            if (new Utility.SiteConfig().IsMallOn&& order_list == null)
            {
                order_list = Mall_Order.GetMall_OrderListByTradeNo(TradeNo).ToList();
            }
            if (order_list != null)
            {
                OrderIDList = order_list.Select(p => p.ID).ToList();
            }
            if (OrderID > 0 && !OrderIDList.Contains(OrderID))
            {
                OrderIDList.Add(OrderID);
            }
            if (OrderIDList.Count > 0)
            {
                payment.OrderID = OrderIDList[0];
                Mall_OrderTradeNo.Save_Mall_OrderTradeNo(payment.TradeNo, OrderIDList: OrderIDList);
            }
            if (order_list != null && order_list.Count > 0)
            {
                IsRoomFee = order_list.FirstOrDefault(p => p.ProductTypeID == 10) != null;
            }
            if (IsRoomFee)
            {
                if (request_list == null || request_list.Count == 0)
                {
                    request_list = Foresight.DataAccess.Payment_Request.GetPayment_RequestByTradeNo(TradeNo, payment.OrderID).ToList();
                }
                if ((fee_list == null || fee_list.Count == 0) && request_list.Count > 0)
                {
                    fee_list = Foresight.DataAccess.RoomFee.GetRoomFeeListByIDs(request_list.Select(p => p.RoomFeeID).ToList()).ToList();
                }
            }
            if (CanSave)
            {
                using (SqlHelper helper = new SqlHelper())
                {
                    try
                    {
                        helper.BeginTransaction();
                        payment.Save(helper);
                        if (order_list != null && order_list.Count > 0)
                        {
                            foreach (var item in order_list)
                            {
                                if (item.ProductTypeID == 10)
                                {
                                    IsRoomFee = true;
                                }
                                item.TradeNo = payment.TradeNo;
                                item.Save(helper);
                            }
                        }
                        if (request_list != null && request_list.Count > 0)
                        {
                            foreach (var item in request_list)
                            {
                                item.PaymentID = payment.ID;
                                item.OrderID   = payment.OrderID;
                                item.Save(helper);
                            }
                        }
                        if (fee_list != null && fee_list.Count > 0)
                        {
                            foreach (var item in fee_list)
                            {
                                item.TradeNo = payment.TradeNo;
                                item.OrderID = payment.OrderID;
                                item.Save(helper);
                            }
                        }

                        helper.Commit();
                        return(payment);
                    }
                    catch (Exception ex)
                    {
                        helper.Rollback();
                        throw ex;
                    }
                }
            }
            return(payment);
        }