Пример #1
0
 public static void SaveMallOrder(Mall_Order order)
 {
     try
     {
         bool can_socket_notify = false;
         if (order.OrderStatus != 1 || string.IsNullOrEmpty(order.TradeNo))
         {
             return;
         }
         int PayStatus = APPCode.PaymentHelper.OrderQuery(order.TradeNo);
         if (PayStatus != 2)
         {
             return;
         }
         var payment = Foresight.DataAccess.Payment.GetPaymentByTradeNo(order.TradeNo);
         if (payment != null)
         {
             if (payment.Status != 1)
             {
                 return;
             }
         }
         Payment.CompletePayment(TradeNo: order.TradeNo, payment: payment, order: order);
         Mall_UserBalance.GetEarnThroughBuy(order, payment);
         if (can_socket_notify)
         {
             APPCode.SocketNotify.PushSocketNotifyAlert(type: Utility.EnumModel.SocketNotifyDefine.notifyorderpaied);
         }
     }
     catch (Exception ex)
     {
         LogHelper.WriteError("PaymentHelper.css", "SaveMallOrder", ex);
     }
 }
Пример #2
0
        public async Task UpdateOrder(Mall_Order order, OrderStatus status)
        {
            //1:添加订单记录
            await _recordRepository.InsertAsync(new Mall_OrderRecord()
            {
                OrderId     = order.Id,
                OrderStatus = status
            });

            //2:更新订单记录
            var initStatus = order.OrderStatus;

            order.OrderStatus = status;

            //3:只有在商品发货后,才进行通知和更新产品数量
            if (status == OrderStatus.Receive)
            {
                //更新订单产品的销售记录
                var products = _cartItemRepository.GetAllIncluding((c) => c.Product).Where(u => u.CartId.Equals(order.CartId)).ToList();
                products.ForEach(u =>
                {
                    u.Product.SaleNums += u.ItemNum;
                });
                //通知提醒
                EventBus.Default.Trigger(new OrderEventData()
                {
                    Order = order, OldStatus = initStatus
                });
            }
        }
Пример #3
0
        public async Task CheckOut(int addressId)
        {
            //1:获取购物车
            var cart = await GetCurrentCart();

            //2:设置状态
            cart.ItemStatus = CartStatus.Pay;
            //3:生成订单
            Mall_Order order = new Mall_Order();

            order.CartId    = cart.Id;
            order.AddressId = addressId;
            //4:订单编号,自动生成
            order.OrderNo = GenerateOrderNo();
            //5:计算该订单的总金额
            decimal allIntegral = _cartItemRepository.GetAll().Where(u => u.CartId.Equals(cart.Id)).Sum(u => u.ItemNum * u.ItemPrice);

            order.AllPrice = allIntegral;
            if (allIntegral == 0)
            {
                throw new UserFriendlyException("购物车物品为0,请添加物品...");
            }
            //6: 检查一下积分是否充足
            //6:获取人员当前积分
            var user = await _accountRepository.GetAsync(UserId);

            if (user.Integral < allIntegral)
            {
                throw new UserFriendlyException("个人积分不够,请努力赚取积分...");
            }

            //6:插入订单
            await _orderRepository.InsertAsync(order);

            //7:保存订单
            await CurrentUnitOfWork.SaveChangesAsync();

            //8:插入积分变更记录
            await _integralAppService.Create(new CreateIntegralInput()
            {
                ValidationCode = MallConsts.SecurityCode,
                Current        = user.Integral.Value,
                Integral       = allIntegral,
                UserId         = UserId,
                CostType       = CostType.Cost,
                DeptId         = 0,
                ActDate        = Clock.Now,
                Describe       = $"订单:{order.Id}_{order.OrderNo} 付款",
                TypeName       = "人员"
            });


            //9:添加订单流水
            await _orderRecordRepository.InsertAsync(new Mall_OrderRecord()
            {
                OrderStatus = OrderStatus.Init,
                OrderId     = order.Id
            });
        }
Пример #4
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);
        }
Пример #5
0
        public static void CompletePayment(SqlHelper helper, string TradeNo = "", Payment payment = null, Mall_Order order = null)
        {
            if (payment == null)
            {
                payment = Payment.GetPaymentByTradeNo(TradeNo, helper);
            }
            int OrderID = 0;

            if (payment != null)
            {
                OrderID = payment.OrderID;
                TradeNo = payment.TradeNo;
                if (payment.Status != 2)
                {
                    payment.Status          = 2;
                    payment.PayCompleteTime = DateTime.Now;
                    payment.PayResult       = "Success";
                    payment.Save(helper);
                }
            }
            if (!new Utility.SiteConfig().IsMallOn)
            {
                return;
            }
            if (order == null)
            {
                order = Mall_Order.GetMall_OrderByTradeNo(helper, TradeNo, OrderID: OrderID);
            }
            if (order != null)
            {
                order.PayTime = DateTime.Now;
                if (payment != null)
                {
                    if (payment.PaymentType.Equals(Utility.EnumModel.PaymentTypeDefine.app_wx.ToString()))
                    {
                        order.PaymentMethod = Utility.EnumModel.Mall_OrderPaymentMethodDefine.wxpay.ToString();
                    }
                    else if (payment.PaymentType.Equals(Utility.EnumModel.PaymentTypeDefine.app_alipay.ToString()))
                    {
                        order.PaymentMethod = Utility.EnumModel.Mall_OrderPaymentMethodDefine.alipay.ToString();
                    }
                    else if (payment.PaymentType.Equals(Utility.EnumModel.PaymentTypeDefine.app_balance_pay.ToString()))
                    {
                        order.PaymentMethod = Utility.EnumModel.Mall_OrderPaymentMethodDefine.balance.ToString();
                    }
                }
                if (order.ProductTypeID == 10)
                {
                    if (order.OrderStatus != 3)
                    {
                        order.OrderStatus  = 3;
                        order.CompleteTime = DateTime.Now;
                        order.Save(helper);
                    }
                }
                else
                {
                    if (order.OrderStatus != 5)
                    {
                        order.OrderStatus    = 5;
                        order.IsReadNewOrder = false;
                        order.Save(helper);
                    }
                }
            }
        }
Пример #6
0
 public static void CompletePayment(string TradeNo = "", Payment payment = null, Mall_Order order = null)
 {
     using (SqlHelper helper = new SqlHelper())
     {
         CompletePayment(helper, TradeNo: TradeNo, payment: payment, order: order);
     }
 }
Пример #7
0
        /// <summary>
        /// 消费处理
        /// </summary>
        /// <param name="order"></param>
        /// <param name="payment"></param>
        public static void GetEarnThroughBuy(Mall_Order order = null, Payment payment = null)
        {
            //消费赠与处理
            if (order == null)
            {
                return;
            }
            int[] ProductIDList = Mall_OrderItem.GetProductIDListByOrderID(order.ID, IsProduct: true);
            int[] ServiceIDList = Mall_OrderItem.GetProductIDListByOrderID(order.ID, IsService: true);
            if (payment == null)
            {
                payment = Payment.GetPaymentByTradeNo(order.TradeNo);
            }
            decimal TotalCost = order.TotalCost;

            if (payment != null)
            {
                TotalCost = payment.Amount / 100;
            }
            Dictionary <string, object> BackObject = new Dictionary <string, object>();

            Mall_AmountRule.GetBackAmountPoint(TotalCost, out BackObject, ProductIDList, ServiceIDList, AmountType: 2, UserID: order.UserID);
            string Title        = "消费赠与";
            int    CategoryType = 6;

            using (SqlHelper helper = new SqlHelper())
            {
                try
                {
                    helper.BeginTransaction();
                    decimal  BackAmount            = Utility.Tools.GetValueFromDic <decimal>(BackObject, "BackAmount");
                    int      AmountRuleID          = Utility.Tools.GetValueFromDic <int>(BackObject, "AmountRuleID");
                    bool     AmountIsSendNow       = Utility.Tools.GetValueFromDic <bool>(BackObject, "AmountIsSendNow");
                    DateTime AmountIsReadySendTime = Utility.Tools.GetValueFromDic <DateTime>(BackObject, "AmountIsReadySendTime");
                    if (BackAmount > 0 && AmountRuleID > 0)
                    {
                        Insert_Mall_UserBalance(order.UserID, 1, BackAmount, Title, "BalaceID:" + order.ID, CategoryType, "System", 1, "", RelatedID: order.ID, AmountRuleID: AmountRuleID, helper: helper, PaymentMethod: order.PaymentMethod, IsSent: AmountIsSendNow, IsReadySendTime: AmountIsReadySendTime);
                    }
                    int      BackPoint            = Utility.Tools.GetValueFromDic <int>(BackObject, "BackPoint");
                    int      PointRuleID          = Utility.Tools.GetValueFromDic <int>(BackObject, "PointRuleID");
                    bool     PointIsSendNow       = Utility.Tools.GetValueFromDic <bool>(BackObject, "PointIsSendNow");
                    DateTime PointIsReadySendTime = Utility.Tools.GetValueFromDic <DateTime>(BackObject, "PointIsReadySendTime");
                    if (BackPoint > 0 && PointRuleID > 0)
                    {
                        Mall_UserPoint.Insert_Mall_UserPoint(order.UserID, 1, 0, Title, "BalaceID:" + order.ID, CategoryType, "System", 1, "", 0, helper, RelatedID: order.ID, PointValue: BackPoint, AmountRuleID: PointRuleID, IsSent: PointIsSendNow, IsReadySendTime: PointIsReadySendTime);
                    }
                    if (order.TotalOrderPointCost > 0)
                    {
                        Mall_UserPoint.Insert_Mall_UserPoint(order.UserID, 2, 0, "购买商品", "OrderID:" + order.ID, 1, "System", 1, order.TradeNo, order.ID, helper, RelatedID: order.ID, PointValue: -order.TotalOrderPointCost, AmountRuleID: 0);
                    }

                    List <int> CouponIDList          = Utility.Tools.GetValueFromDic <List <int> >(BackObject, "CouponIDList");
                    int        CouponRuleID          = Utility.Tools.GetValueFromDic <int>(BackObject, "CouponRuleID");
                    bool       CouponIsSendNow       = Utility.Tools.GetValueFromDic <bool>(BackObject, "CouponIsSendNow");
                    DateTime   CouponIsReadySendTime = Utility.Tools.GetValueFromDic <DateTime>(BackObject, "CouponIsReadySendTime");
                    int        SendCouponCount       = Utility.Tools.GetValueFromDic <int>(BackObject, "SendCouponCount");
                    if (CouponIDList != null && CouponIDList.Count > 0 && CouponRuleID > 0)
                    {
                        foreach (var CouponID in CouponIDList)
                        {
                            for (int i = 0; i < SendCouponCount; i++)
                            {
                                Mall_CouponUser.Insert_Mall_CouponUser(order.UserID, CouponID, 3, CouponRuleID, CouponIsReadySendTime, helper: helper, IsSent: CouponIsSendNow);
                            }
                        }
                    }
                    if (payment != null)
                    {
                        payment.Save(helper);
                    }
                    if (order != null)
                    {
                        order.Save(helper);
                    }
                    helper.Commit();
                }
                catch (Exception ex)
                {
                    helper.Rollback();
                    Utility.LogHelper.WriteError("Mall_UserBalance.cs", "GetEarnThroughBuy", ex);
                }
            }
        }
Пример #8
0
 /// <summary>
 /// 初始化B2C订单结算实例
 /// </summary>
 /// <param name="order">需要结算的订单</param>
 /// <param name="needProcessOrder">是否需要处理订单</param>
 public MallOrderSettlementCenter(Mall_Order order, bool needProcessOrder)
 {
     _order            = order;
     _needProcessOrder = needProcessOrder;
 }