Esempio n. 1
0
        /// <summary>
        /// 从IDataReader创建OrderInfo
        /// </summary>
        public static OrderInfo BuildOrderFromReader(IDataReader reader)
        {
            OrderInfo orderInfo = new OrderInfo();

            orderInfo.Oid = TypeHelper.ObjectToInt(reader["oid"]);
            orderInfo.OSN = reader["osn"].ToString();
            orderInfo.Uid = TypeHelper.ObjectToInt(reader["uid"]);

            orderInfo.OrderState = TypeHelper.ObjectToInt(reader["orderstate"]);

            orderInfo.ProductAmount = TypeHelper.ObjectToDecimal(reader["productamount"]);
            orderInfo.OrderAmount = TypeHelper.ObjectToDecimal(reader["orderamount"]);
            orderInfo.SurplusMoney = TypeHelper.ObjectToDecimal(reader["surplusmoney"]);

            orderInfo.ParentId = TypeHelper.ObjectToInt(reader["parentid"]);
            orderInfo.IsReview = TypeHelper.ObjectToInt(reader["isreview"]);
            orderInfo.AddTime = TypeHelper.ObjectToDateTime(reader["addtime"]);
            orderInfo.StoreId = TypeHelper.ObjectToInt(reader["storeid"]);
            orderInfo.StoreName = reader["storename"].ToString();
            orderInfo.ShipSN = reader["shipsn"].ToString();
            orderInfo.ShipCoId = TypeHelper.ObjectToInt(reader["shipcoid"]);
            orderInfo.ShipCoName = reader["shipconame"].ToString();
            orderInfo.ShipTime = TypeHelper.ObjectToDateTime(reader["shiptime"]);
            orderInfo.PaySN = reader["paysn"].ToString();
            orderInfo.PayFriendName = reader["payfriendname"].ToString();
            orderInfo.PaySystemName = reader["paysystemname"].ToString();
            orderInfo.PayMode = TypeHelper.ObjectToInt(reader["paymode"]);
            orderInfo.PayTime = TypeHelper.ObjectToDateTime(reader["paytime"]);

            orderInfo.RegionId = TypeHelper.ObjectToInt(reader["regionid"]);
            orderInfo.Consignee = reader["consignee"].ToString();
            orderInfo.Mobile = reader["mobile"].ToString();
            orderInfo.Phone = reader["phone"].ToString();
            orderInfo.Email = reader["email"].ToString();
            orderInfo.ZipCode = reader["zipcode"].ToString();
            orderInfo.Address = reader["address"].ToString();
            orderInfo.BestTime = TypeHelper.ObjectToDateTime(reader["besttime"]);

            orderInfo.ShipFee = TypeHelper.ObjectToDecimal(reader["shipfee"]);
            orderInfo.PayFee = TypeHelper.ObjectToDecimal(reader["payfee"]);
            orderInfo.FullCut = TypeHelper.ObjectToInt(reader["fullcut"]);
            orderInfo.Discount = TypeHelper.ObjectToDecimal(reader["discount"]);
            orderInfo.PayCreditCount = TypeHelper.ObjectToInt(reader["paycreditcount"]);
            orderInfo.PayCreditMoney = TypeHelper.ObjectToDecimal(reader["paycreditmoney"]);
            orderInfo.CouponMoney = TypeHelper.ObjectToInt(reader["couponmoney"]);
            orderInfo.Weight = TypeHelper.ObjectToInt(reader["weight"]);

            orderInfo.BuyerRemark = reader["buyerremark"].ToString();
            orderInfo.IP = reader["ip"].ToString();

            return orderInfo;
        }
Esempio n. 2
0
        /// <summary>
        /// 创建订单
        /// </summary>
        /// <param name="orderInfo">订单信息</param>
        /// <param name="isPersistOrderProduct">是否需要持久化订单商品</param>
        /// <param name="orderProductList">订单商品列表</param>
        /// <returns>订单id</returns>
        public int CreateOrder(OrderInfo orderInfo, bool isPersistOrderProduct, List<OrderProductInfo> orderProductList)
        {
            DbParameter[] parms = {
	                                    GenerateInParam("@osn", SqlDbType.Char,30,orderInfo.OSN),
	                                    GenerateInParam("@uid", SqlDbType.Int,4 ,orderInfo.Uid),
	                                    GenerateInParam("@orderstate", SqlDbType.TinyInt,1 ,orderInfo.OrderState),
                                        GenerateInParam("@productamount", SqlDbType.Decimal,8 ,orderInfo.ProductAmount),
                                        GenerateInParam("@orderamount", SqlDbType.Decimal,8 ,orderInfo.OrderAmount),
                                        GenerateInParam("@surplusmoney", SqlDbType.Decimal,8 ,orderInfo.SurplusMoney),
                                        GenerateInParam("@parentid", SqlDbType.Int,4 ,orderInfo.ParentId),
                                        GenerateInParam("@isreview", SqlDbType.TinyInt,1 ,orderInfo.IsReview),
                                        GenerateInParam("@addtime", SqlDbType.DateTime, 8,orderInfo.AddTime),
                                        GenerateInParam("@storeid", SqlDbType.Int,4 ,orderInfo.StoreId),
                                        GenerateInParam("@storename", SqlDbType.NChar,60 ,orderInfo.StoreName),
                                        GenerateInParam("@shipsn", SqlDbType.Char,30 ,orderInfo.ShipSN),
                                        GenerateInParam("@shipcoid", SqlDbType.SmallInt,2 ,orderInfo.ShipCoId),
                                        GenerateInParam("@shipconame", SqlDbType.NChar,30 ,orderInfo.ShipCoName),
                                        GenerateInParam("@shiptime", SqlDbType.DateTime, 8,orderInfo.ShipTime),
                                        GenerateInParam("@paysn", SqlDbType.Char,30 ,orderInfo.PaySN),
                                        GenerateInParam("@paysystemname", SqlDbType.Char,20 ,orderInfo.PaySystemName),
                                        GenerateInParam("@payfriendname", SqlDbType.NChar,30 ,orderInfo.PayFriendName),
                                        GenerateInParam("@paymode", SqlDbType.TinyInt,1 ,orderInfo.PayMode),
                                        GenerateInParam("@paytime", SqlDbType.DateTime, 8,orderInfo.PayTime),
                                        GenerateInParam("@regionid", SqlDbType.SmallInt,2 ,orderInfo.RegionId),
                                        GenerateInParam("@consignee", SqlDbType.NVarChar,30 ,orderInfo.Consignee),
                                        GenerateInParam("@mobile", SqlDbType.VarChar,15 ,orderInfo.Mobile),
                                        GenerateInParam("@phone", SqlDbType.VarChar,12 ,orderInfo.Phone),
                                        GenerateInParam("@email", SqlDbType.VarChar,50 ,orderInfo.Email),
                                        GenerateInParam("@zipcode", SqlDbType.Char,6 ,orderInfo.ZipCode),
	                                    GenerateInParam("@address", SqlDbType.NVarChar,150 ,orderInfo.Address),
                                        GenerateInParam("@besttime", SqlDbType.DateTime,8 ,orderInfo.BestTime),
	                                    GenerateInParam("@shipfee", SqlDbType.Decimal,8 ,orderInfo.ShipFee),
                                        GenerateInParam("@payfee", SqlDbType.Decimal,8 ,orderInfo.PayFee),
                                        GenerateInParam("@fullcut", SqlDbType.Int,4 ,orderInfo.FullCut),
	                                    GenerateInParam("@discount", SqlDbType.Decimal,8 ,orderInfo.Discount),
	                                    GenerateInParam("@paycreditcount", SqlDbType.Int,4 ,orderInfo.PayCreditCount),
	                                    GenerateInParam("@paycreditmoney", SqlDbType.Decimal,8 ,orderInfo.PayCreditMoney),
                                        GenerateInParam("@couponmoney", SqlDbType.Int,4 ,orderInfo.CouponMoney),
	                                    GenerateInParam("@weight", SqlDbType.Int,4 ,orderInfo.Weight),
                                        GenerateInParam("@buyerremark", SqlDbType.NVarChar,250 ,orderInfo.BuyerRemark),
                                        GenerateInParam("@ip", SqlDbType.VarChar,15 ,orderInfo.IP)
                                    };
            int oid = TypeHelper.ObjectToInt(RDBSHelper.ExecuteScalar(CommandType.StoredProcedure,
                                                                      string.Format("{0}createorder", RDBSHelper.RDBSTablePre),
                                                                      parms), -1);

            if (oid > 0)
            {
                if (isPersistOrderProduct)
                {
                    StringBuilder recordIdList = new StringBuilder();
                    foreach (OrderProductInfo orderProductInfo in orderProductList)
                    {
                        recordIdList.AppendFormat("{0},", orderProductInfo.RecordId);
                    }
                    parms = new DbParameter[] {
                                                GenerateInParam("@recordidlist", SqlDbType.NVarChar, 1000, recordIdList.Remove(recordIdList.Length - 1,1).ToString()),
                                                GenerateInParam("@oid", SqlDbType.Int, 4, oid),
                                              };
                    RDBSHelper.ExecuteNonQuery(CommandType.StoredProcedure,
                                               string.Format("{0}updateorderproductoid", RDBSHelper.RDBSTablePre),
                                               parms);
                }
                else
                {
                    foreach (OrderProductInfo orderProductInfo in orderProductList)
                    {
                        orderProductInfo.Oid = oid;
                        parms = new DbParameter[] {
                                                GenerateInParam("@oid", SqlDbType.Int, 4, orderProductInfo.Oid),
                                                GenerateInParam("@uid", SqlDbType.Int, 4, orderProductInfo.Uid),
                                                GenerateInParam("@sid", SqlDbType.Char, 16, orderProductInfo.Sid),
                                                GenerateInParam("@pid", SqlDbType.Int, 4, orderProductInfo.Pid),
                                                GenerateInParam("@psn", SqlDbType.Char, 30, orderProductInfo.PSN),
                                                GenerateInParam("@cateid", SqlDbType.SmallInt, 2, orderProductInfo.CateId),
                                                GenerateInParam("@brandid", SqlDbType.Int, 4, orderProductInfo.BrandId),
                                                GenerateInParam("@storeid", SqlDbType.Int, 4, orderProductInfo.StoreId),
                                                GenerateInParam("@storecid", SqlDbType.Int, 4, orderProductInfo.StoreCid),
                                                GenerateInParam("@storestid", SqlDbType.Int, 4, orderProductInfo.StoreSTid),
                                                GenerateInParam("@name", SqlDbType.NVarChar, 200, orderProductInfo.Name),
                                                GenerateInParam("@showimg", SqlDbType.NVarChar, 100, orderProductInfo.ShowImg),
                                                GenerateInParam("@discountprice", SqlDbType.Decimal, 4, orderProductInfo.DiscountPrice),
                                                GenerateInParam("@costprice", SqlDbType.Decimal, 4, orderProductInfo.CostPrice),
                                                GenerateInParam("@shopprice", SqlDbType.Decimal, 4, orderProductInfo.ShopPrice),
                                                GenerateInParam("@marketprice", SqlDbType.Decimal, 4, orderProductInfo.MarketPrice),
                                                GenerateInParam("@weight", SqlDbType.Int, 4, orderProductInfo.Weight),
                                                GenerateInParam("@isreview", SqlDbType.TinyInt, 1, orderProductInfo.IsReview),
                                                GenerateInParam("@realcount", SqlDbType.Int, 4, orderProductInfo.RealCount),
                                                GenerateInParam("@buycount", SqlDbType.Int, 4, orderProductInfo.BuyCount),
                                                GenerateInParam("@sendcount", SqlDbType.Int, 4, orderProductInfo.SendCount),
                                                GenerateInParam("@type", SqlDbType.TinyInt, 1, orderProductInfo.Type),
                                                GenerateInParam("@paycredits", SqlDbType.Int, 4, orderProductInfo.PayCredits),
                                                GenerateInParam("@coupontypeid", SqlDbType.Int, 4, orderProductInfo.CouponTypeId),
                                                GenerateInParam("@extcode1", SqlDbType.Int, 4, orderProductInfo.ExtCode1),
                                                GenerateInParam("@extcode2", SqlDbType.Int, 4, orderProductInfo.ExtCode2),
                                                GenerateInParam("@extcode3", SqlDbType.Int, 4, orderProductInfo.ExtCode3),
                                                GenerateInParam("@extcode4", SqlDbType.Int, 4, orderProductInfo.ExtCode4),
                                                GenerateInParam("@extcode5", SqlDbType.Int, 4, orderProductInfo.ExtCode5),
                                                GenerateInParam("@addtime", SqlDbType.DateTime, 8, orderProductInfo.AddTime)
                                            };
                        RDBSHelper.ExecuteNonQuery(CommandType.StoredProcedure,
                                                   string.Format("{0}addorderproduct", RDBSHelper.RDBSTablePre),
                                                   parms);
                    }
                }
            }

            return oid;
        }
Esempio n. 3
0
        /// <summary>
        /// 退回用户订单发放的积分
        /// </summary>
        /// <param name="partUserInfo">用户信息</param>
        /// <param name="orderInfo">订单信息</param>
        /// <param name="payCredits">支付积分</param>
        /// <param name="rankCredits">等级积分</param>
        /// <param name="operatorId">操作人</param>
        /// <param name="returnTime">退回时间</param>
        public static void ReturnUserOrderSendCredits(ref PartUserInfo partUserInfo, OrderInfo orderInfo, int payCredits, int rankCredits, int operatorId, DateTime returnTime)
        {
            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 = orderInfo.Uid;
            creditLogInfo.PayCredits = -1 * payCredits;
            creditLogInfo.RankCredits = -1 * rankCredits;
            creditLogInfo.Action = (int)CreditAction.ReturnOrderSend;
            creditLogInfo.ActionCode = orderInfo.Oid;
            creditLogInfo.ActionTime = returnTime;
            creditLogInfo.ActionDes = "收回订单发放的积分:" + orderInfo.OSN;
            creditLogInfo.Operator = operatorId;

            SendCredits(userRid, creditLogInfo);
        }
Esempio n. 4
0
        /// <summary>
        /// 退回用户订单使用的积分
        /// </summary>
        /// <param name="partUserInfo">用户信息</param>
        /// <param name="orderInfo">订单信息</param>
        /// <param name="operatorId">操作人</param>
        /// <param name="returnTime">退回时间</param>
        public static void ReturnUserOrderUseCredits(ref PartUserInfo partUserInfo, OrderInfo orderInfo, int operatorId, DateTime returnTime)
        {
            partUserInfo.PayCredits += orderInfo.PayCreditCount;

            CreditLogInfo creditLogInfo = new CreditLogInfo();
            creditLogInfo.Uid = orderInfo.Uid;
            creditLogInfo.PayCredits = orderInfo.PayCreditCount;
            creditLogInfo.RankCredits = 0;
            creditLogInfo.Action = (int)CreditAction.ReturnOrderUse;
            creditLogInfo.ActionCode = orderInfo.Oid;
            creditLogInfo.ActionTime = returnTime;
            creditLogInfo.ActionDes = "退回用户订单使用的积分:" + orderInfo.OSN;
            creditLogInfo.Operator = operatorId;

            SendCredits(0, creditLogInfo);
        }
Esempio n. 5
0
        /// <summary>
        /// 支付订单
        /// </summary>
        /// <param name="partUserInfo">用户信息</param>
        /// <param name="orderInfo">订单信息</param>
        /// <param name="credits">积分数量</param>
        /// <param name="payTime">支付时间</param>
        public static void PayOrder(ref PartUserInfo partUserInfo, OrderInfo orderInfo, int credits, DateTime payTime)
        {
            if (credits > 0)
            {
                partUserInfo.PayCredits -= credits;

                CreditLogInfo creditLogInfo = new CreditLogInfo();
                creditLogInfo.Uid = partUserInfo.Uid;
                creditLogInfo.PayCredits = -1 * credits;
                creditLogInfo.RankCredits = 0;
                creditLogInfo.Action = (int)CreditAction.PayOrder;
                creditLogInfo.ActionCode = orderInfo.Oid;
                creditLogInfo.ActionTime = payTime;
                creditLogInfo.ActionDes = "支付订单:" + orderInfo.OSN;
                creditLogInfo.Operator = partUserInfo.Uid;

                SendCredits(0, creditLogInfo);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 发放单品促销活动积分
        /// </summary>
        /// <param name="partUserInfo">用户信息</param>
        /// <param name="orderInfo">订单信息</param>
        /// <param name="credits">积分</param>
        /// <param name="sendTime">发放时间</param>
        public static void SendSinglePromotionCredits(ref PartUserInfo partUserInfo, OrderInfo orderInfo, int credits, DateTime sendTime)
        {
            int surplusPayCredits = GetDaySurplusPayCredits(partUserInfo.Uid, sendTime.Date);
            if (surplusPayCredits != 0)
            {
                int creditCount = credits;
                if (surplusPayCredits > 0 && surplusPayCredits < creditCount)
                    creditCount = surplusPayCredits;

                partUserInfo.PayCredits += creditCount;

                CreditLogInfo creditLogInfo = new CreditLogInfo();
                creditLogInfo.Uid = partUserInfo.Uid;
                creditLogInfo.PayCredits = creditCount;
                creditLogInfo.RankCredits = 0;
                creditLogInfo.Action = (int)CreditAction.SinglePromotion;
                creditLogInfo.ActionCode = orderInfo.Oid;
                creditLogInfo.ActionTime = sendTime;
                creditLogInfo.ActionDes = "促销活动发放";
                creditLogInfo.Operator = 0;

                SendCredits(0, creditLogInfo);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 发放完成订单积分
        /// </summary>
        /// <param name="partUserInfo">用户信息</param>
        /// <param name="orderInfo">订单信息</param>
        /// <param name="orderProductList">订单商品列表</param>
        /// <param name="completeTime">完成时间</param>
        public static void SendCompleteOrderCredits(ref PartUserInfo partUserInfo, OrderInfo orderInfo, List<OrderProductInfo> orderProductList, DateTime completeTime)
        {
            if (_creditconfiginfo.CompleteOrderPayCredits > 0 || _creditconfiginfo.CompleteOrderRankCredits > 0)
            {
                int surplusPayCredits = GetDaySurplusPayCredits(partUserInfo.Uid, completeTime.Date);
                int surplusRankCredits = GetDaySurplusRankCredits(partUserInfo.Uid, completeTime.Date);
                if (surplusPayCredits == 0 && surplusRankCredits == 0)
                    return;

                int payCredits = 0;
                int rankCredits = 0;
                int tempPayCredits = (int)Math.Floor(orderInfo.OrderAmount * _creditconfiginfo.CompleteOrderPayCredits / 100);
                int tempRankCredits = (int)Math.Floor(orderInfo.OrderAmount * _creditconfiginfo.CompleteOrderRankCredits / 100);
                if (surplusPayCredits > 0)
                    payCredits = surplusPayCredits < tempPayCredits ? surplusPayCredits : tempPayCredits;
                else if (surplusPayCredits == -1)
                    payCredits = tempPayCredits;
                if (surplusRankCredits > 0)
                    rankCredits = surplusRankCredits < tempRankCredits ? surplusRankCredits : tempRankCredits;
                else if (surplusRankCredits == -1)
                    rankCredits = tempRankCredits;

                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.CompleteOrder;
                creditLogInfo.ActionCode = orderInfo.Oid;
                creditLogInfo.ActionTime = completeTime;
                creditLogInfo.ActionDes = "完成订单:" + orderInfo.OSN;
                creditLogInfo.Operator = 0;

                SendCredits(userRid, creditLogInfo);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 发放单品促销活动优惠劵
        /// </summary>
        /// <param name="partUserInfo">用户信息</param>
        /// <param name="couponTypeId">优惠劵类型id</param>
        /// <param name="orderInfo">订单信息</param>
        /// <param name="ip">ip</param>
        public static void SendSinglePromotionCoupon(PartUserInfo partUserInfo, int couponTypeId, OrderInfo orderInfo, string ip)
        {
            CouponTypeInfo couponTypeInfo = GetCouponTypeById(couponTypeId);
            if (couponTypeInfo == null || couponTypeInfo.State == 0 || couponTypeInfo.UserRankLower > partUserInfo.UserRid || couponTypeInfo.OrderAmountLower > orderInfo.OrderAmount)
                return;

            CouponInfo couponInfo = new CouponInfo();

            couponInfo.CouponSN = Coupons.GenerateCouponSN();
            couponInfo.Uid = partUserInfo.Uid;
            couponInfo.CouponTypeId = couponTypeId;
            couponInfo.StoreId = couponTypeInfo.StoreId;
            couponInfo.Oid = 0;
            couponInfo.UseTime = new DateTime(1900, 1, 1);
            couponInfo.UseIP = "";
            couponInfo.Money = couponTypeInfo.Money;
            couponInfo.ActivateTime = couponInfo.CreateTime = DateTime.Now;
            couponInfo.ActivateIP = couponInfo.CreateIP = ip;
            couponInfo.CreateUid = 0;
            couponInfo.CreateOid = orderInfo.Oid;

            CreateCoupon(couponInfo);
        }
Esempio n. 9
0
 /// <summary>
 /// 锁定订单
 /// </summary>
 /// <param name="orderInfo">订单信息</param>
 public static void LockOrder(OrderInfo orderInfo)
 {
     UpdateOrderState(orderInfo.Oid, OrderState.Locked);
     Products.IncreaseProductStockNumber(GetOrderProductList(orderInfo.Oid));//增加商品库存数量
 }
Esempio n. 10
0
        /// <summary>
        /// 取消订单
        /// </summary>
        /// <param name="partUserInfo">用户信息</param>
        /// <param name="orderInfo">订单信息</param>
        /// <param name="operatorId">操作人id</param>
        /// <param name="cancelTime">取消时间</param>
        public static void CancelOrder(ref PartUserInfo partUserInfo, OrderInfo orderInfo, int operatorId, DateTime cancelTime)
        {
            UpdateOrderState(orderInfo.Oid, OrderState.Cancelled);//将订单状态设为取消状态

            if (orderInfo.CouponMoney > 0)//退回用户使用的优惠劵
                Coupons.ReturnUserOrderUseCoupons(orderInfo.Oid);

            if (orderInfo.PayCreditCount > 0)//退回用户使用的积分
                Credits.ReturnUserOrderUseCredits(ref partUserInfo, orderInfo, operatorId, cancelTime);

            Products.IncreaseProductStockNumber(GetOrderProductList(orderInfo.Oid));//增加商品库存数量
        }
Esempio n. 11
0
        /// <summary>
        /// 退货
        /// </summary>
        /// <param name="partUserInfo">用户信息</param>
        /// <param name="orderInfo">订单信息</param>
        /// <param name="operatorId">操作人id</param>
        /// <param name="returnTime">退货时间</param>
        public static void ReturnOrder(ref PartUserInfo partUserInfo, OrderInfo orderInfo, int operatorId, DateTime returnTime)
        {
            UpdateOrderState(orderInfo.Oid, OrderState.Returned);//将订单状态设为退货状态

            if (orderInfo.OrderState == (int)OrderState.Sended)//用户收货时退货
            {
                if (orderInfo.CouponMoney > 0)//退回用户使用的优惠劵
                    Coupons.ReturnUserOrderUseCoupons(orderInfo.Oid);

                if (orderInfo.PayCreditCount > 0)//退回用户使用的积分
                    Credits.ReturnUserOrderUseCredits(ref partUserInfo, orderInfo, operatorId, returnTime);

                if (orderInfo.PaySN.Length > 0)//退回用户支付的金钱(此操作只是将退款记录保存到表'orderrefunds'中,实际退款还需要再次操作)
                    OrderRefunds.ApplyRefund(new OrderRefundInfo
                    {
                        Oid = orderInfo.Oid,
                        OSN = orderInfo.OSN,
                        Uid = orderInfo.Uid,
                        State = 0,
                        ApplyTime = returnTime,
                        PayMoney = orderInfo.SurplusMoney,
                        RefundMoney = orderInfo.SurplusMoney,
                        PaySN = orderInfo.PaySN,
                        PaySystemName = orderInfo.PaySystemName,
                        PayFriendName = orderInfo.PayFriendName
                    });

            }
            else if (orderInfo.OrderState == (int)OrderState.Completed)//订单完成后退货
            {
                if (orderInfo.CouponMoney > 0)//退回用户使用的优惠劵
                    Coupons.ReturnUserOrderUseCoupons(orderInfo.Oid);

                if (orderInfo.PayCreditCount > 0)//退回用户使用的积分
                    Credits.ReturnUserOrderUseCredits(ref partUserInfo, orderInfo, operatorId, returnTime);

                //应退金钱
                decimal returnMoney = orderInfo.SurplusMoney;

                //订单发放的积分
                DataTable sendCredits = Credits.GetUserOrderSendCredits(orderInfo.Oid);
                int payCreditAmount = TypeHelper.ObjectToInt(sendCredits.Rows[0]["paycreditamount"]);
                int rankCreditAmount = TypeHelper.ObjectToInt(sendCredits.Rows[0]["rankcreditamount"]);
                //判断用户当前积分是否足够退回,如果不足够就将差额核算成金钱并在应退金钱中减去
                if (partUserInfo.PayCredits < payCreditAmount)
                {
                    returnMoney = returnMoney - Credits.PayCreditsToMoney(payCreditAmount - partUserInfo.PayCredits);
                    payCreditAmount = partUserInfo.PayCredits;
                }
                //收回订单发放的积分
                Credits.ReturnUserOrderSendCredits(ref partUserInfo, orderInfo, payCreditAmount, rankCreditAmount, operatorId, returnTime);

                StringBuilder couponIdList = new StringBuilder();
                //订单发放的优惠劵列表
                List<CouponInfo> couponList = Coupons.GetUserOrderSendCouponList(orderInfo.Oid);
                //判断优惠劵是否已经被使用,如果已经使用就在应退金钱中减去优惠劵金额
                foreach (CouponInfo couponInfo in couponList)
                {
                    if (couponInfo.Oid > 0)
                        returnMoney = returnMoney - couponInfo.Money;
                    else
                        couponIdList.AppendFormat("{0},", couponInfo.CouponId);
                }
                //收回订单发放的优惠劵
                if (couponIdList.Length > 0)
                {
                    Coupons.DeleteCouponById(couponIdList.Remove(couponIdList.Length - 1, 1).ToString());
                }

                if (returnMoney > 0)//退回用户支付的金钱(此操作只是将退款记录保存到表'orderrefunds'中,实际退款还需要再次操作)
                    OrderRefunds.ApplyRefund(new OrderRefundInfo
                    {
                        Oid = orderInfo.Oid,
                        OSN = orderInfo.OSN,
                        Uid = orderInfo.Uid,
                        State = 0,
                        ApplyTime = returnTime,
                        PayMoney = orderInfo.SurplusMoney,
                        RefundMoney = returnMoney,
                        PaySN = orderInfo.PaySN,
                        PaySystemName = orderInfo.PaySystemName,
                        PayFriendName = orderInfo.PayFriendName
                    });
            }

            Products.IncreaseProductStockNumber(GetOrderProductList(orderInfo.Oid));//增加商品库存数量
        }
Esempio n. 12
0
        /// <summary>
        /// 完成订单
        /// </summary>
        /// <param name="partUserInfo">用户信息</param>
        /// <param name="orderInfo">订单信息</param>
        /// <param name="completeTime">完成时间</param>
        /// <param name="ip">ip</param>
        public static void CompleteOrder(ref PartUserInfo partUserInfo, OrderInfo orderInfo, DateTime completeTime, string ip)
        {
            UpdateOrderState(orderInfo.Oid, OrderState.Completed);//将订单状态设为完成状态

            //订单商品列表
            List<OrderProductInfo> orderProductList = GetOrderProductList(orderInfo.Oid);

            //发放完成订单积分
            Credits.SendCompleteOrderCredits(ref partUserInfo, orderInfo, orderProductList, completeTime);

            //发放单品促销活动支付积分和优惠劵
            foreach (OrderProductInfo orderProductInfo in orderProductList)
            {
                if (orderProductInfo.Type == 0)
                {
                    if (orderProductInfo.PayCredits > 0)
                        Credits.SendSinglePromotionCredits(ref partUserInfo, orderInfo, orderProductInfo.PayCredits, completeTime);
                    if (orderProductInfo.CouponTypeId > 0)
                        Coupons.SendSinglePromotionCoupon(partUserInfo, orderProductInfo.CouponTypeId, orderInfo, ip);
                }
            }
        }
Esempio n. 13
0
 /// <summary>
 /// 备货
 /// </summary>
 /// <param name="orderInfo">订单信息</param>
 public static void PreProduct(OrderInfo orderInfo)
 {
     UpdateOrderState(orderInfo.Oid, OrderState.PreProducting);
 }
Esempio n. 14
0
 /// <summary>
 /// 确认订单
 /// </summary>
 /// <param name="orderInfo">订单信息</param>
 public static void ConfirmOrder(OrderInfo orderInfo)
 {
     UpdateOrderState(orderInfo.Oid, OrderState.Confirmed);
 }
Esempio n. 15
0
        /// <summary>
        /// 创建订单
        /// </summary>
        /// <param name="partUserInfo">用户信息</param>
        /// <param name="storeInfo">店铺信息</param>
        /// <param name="orderProductList">订单商品列表</param>
        /// <param name="singlePromotionList">单品促销活动列表</param>
        /// <param name="fullShipAddressInfo">配送地址</param>
        /// <param name="payPluginInfo">支付方式</param>
        /// <param name="payCreditCount">支付积分数</param>
        /// <param name="couponList">优惠劵列表</param>
        /// <param name="fullCut">满减</param>
        /// <param name="buyerRemark">买家备注</param>
        /// <param name="bestTime">最佳配送时间</param>
        /// <param name="ip">ip地址</param>
        /// <returns>订单信息</returns>
        public static OrderInfo CreateOrder(PartUserInfo partUserInfo, StoreInfo storeInfo, List<OrderProductInfo> orderProductList, List<SinglePromotionInfo> singlePromotionList, FullShipAddressInfo fullShipAddressInfo, PluginInfo payPluginInfo, ref int payCreditCount, List<CouponInfo> couponList, int fullCut, string buyerRemark, DateTime bestTime, string ip)
        {
            DateTime nowTime = DateTime.Now;
            IPayPlugin payPlugin = (IPayPlugin)payPluginInfo.Instance;

            OrderInfo orderInfo = new OrderInfo();

            orderInfo.OSN = GenerateOSN(storeInfo.StoreId, partUserInfo.Uid, fullShipAddressInfo.RegionId, nowTime); ;
            orderInfo.Uid = partUserInfo.Uid;

            orderInfo.Weight = Carts.SumOrderProductWeight(orderProductList);
            orderInfo.ProductAmount = Carts.SumOrderProductAmount(orderProductList);
            orderInfo.FullCut = fullCut;
            orderInfo.ShipFee = GetShipFee(fullShipAddressInfo.ProvinceId, fullShipAddressInfo.CityId, orderProductList);
            orderInfo.PayFee = payPlugin.GetPayFee(orderInfo.ProductAmount - orderInfo.FullCut, nowTime, partUserInfo);
            orderInfo.OrderAmount = orderInfo.ProductAmount - orderInfo.FullCut + orderInfo.ShipFee + orderInfo.PayFee;

            decimal payCreditMoney = Credits.PayCreditsToMoney(payCreditCount);
            if (orderInfo.OrderAmount >= payCreditMoney)
            {
                orderInfo.PayCreditCount = payCreditCount;
                orderInfo.PayCreditMoney = payCreditMoney;
                payCreditCount = 0;
            }
            else
            {
                int orderPayCredits = Credits.MoneyToPayCredits(orderInfo.OrderAmount);
                orderInfo.PayCreditCount = orderPayCredits;
                orderInfo.PayCreditMoney = orderInfo.OrderAmount;
                payCreditCount = payCreditCount - orderPayCredits;
            }

            orderInfo.CouponMoney = Coupons.SumCouponMoney(couponList);
            orderInfo.SurplusMoney = orderInfo.OrderAmount - orderInfo.PayCreditMoney - orderInfo.CouponMoney;

            orderInfo.OrderState = (orderInfo.SurplusMoney <= 0 || payPlugin.PayMode == 0) ? (int)OrderState.Confirming : (int)OrderState.WaitPaying;

            orderInfo.ParentId = 0;
            orderInfo.IsReview = 0;
            orderInfo.AddTime = nowTime;
            orderInfo.StoreId = storeInfo.StoreId;
            orderInfo.StoreName = storeInfo.Name;
            orderInfo.PaySystemName = payPluginInfo.SystemName;
            orderInfo.PayFriendName = payPluginInfo.FriendlyName;
            orderInfo.PayMode = payPlugin.PayMode;

            orderInfo.RegionId = fullShipAddressInfo.RegionId;
            orderInfo.Consignee = fullShipAddressInfo.Consignee;
            orderInfo.Mobile = fullShipAddressInfo.Mobile;
            orderInfo.Phone = fullShipAddressInfo.Phone;
            orderInfo.Email = fullShipAddressInfo.Email;
            orderInfo.ZipCode = fullShipAddressInfo.ZipCode;
            orderInfo.Address = fullShipAddressInfo.Address;
            orderInfo.BestTime = bestTime;

            orderInfo.BuyerRemark = buyerRemark;
            orderInfo.IP = ip;

            try
            {
                //添加订单
                int oid = _iorderstrategy.CreateOrder(orderInfo, Carts.IsPersistOrderProduct, orderProductList);
                if (oid > 0)
                {
                    orderInfo.Oid = oid;

                    //减少商品库存数量
                    Products.DecreaseProductStockNumber(orderProductList);
                    //更新限购库存
                    if (singlePromotionList.Count > 0)
                        Promotions.UpdateSinglePromotionStock(singlePromotionList);
                    //使用支付积分
                    Credits.PayOrder(ref partUserInfo, orderInfo, orderInfo.PayCreditCount, nowTime);
                    //使用优惠劵
                    foreach (CouponInfo couponInfo in couponList)
                    {
                        if (couponInfo.Uid > 0)
                            Coupons.UseCoupon(couponInfo.CouponId, oid, nowTime, ip);
                        else
                            Coupons.ActivateAndUseCoupon(couponInfo.CouponId, partUserInfo.Uid, oid, nowTime, ip);
                    }

                    return orderInfo;
                }
            }
            catch (Exception ex)
            {
                //throw ex;
            }

            return null;
        }