Exemple #1
0
        public string SetOrderInfo(SetOrderInfoReqPara para)
        {
            var loggingSessionInfo = this.CurrentUserInfo as LoggingSessionInfo;
            //获取订单号
            TUnitExpandBLL serviceUnitExpand = new TUnitExpandBLL(loggingSessionInfo);
            string         OrderCode         = serviceUnitExpand.GetUnitOrderNo();

            ////如果StoreID为空,是在线商城订单,重复的逻辑
            //if (string.IsNullOrEmpty(para.storeId.Trim()))
            //{
            //    UnitService unitServer = new UnitService(loggingSessionInfo);
            //    para.storeId = unitServer.GetUnitByUnitType("OnlineShopping", null).Id; //获取在线商城的门店标识
            //}

            //判断活动的有效性

            #region 活动有效性


            decimal salesPrice = 0;                         //活动销售价
            decimal qty        = Convert.ToInt32(para.qty); //所购数量
            //砍价活动
            if (para.isBargain == "1")
            {
                var eventBll = new PanicbuyingEventBLL(loggingSessionInfo);
                var detail   = eventBll.GetKJEventWithSkuDetail(para.eventId.ToString(), para.orderDetailList[0].skuId.ToString());
                if (detail == null)
                {
                    throw new Exception("未找到相关活动商品信息");
                }
                //1.需要判断,该订单的商品是否还有盈余
                if (detail.RemainingQty <= 0)
                {
                    throw new Exception("活动商品数量不足,当前数量:0");
                }
                //2.判断,该商品活动是否已经终止
                if (!string.IsNullOrEmpty(detail.StopReason))
                {
                    throw new Exception("活动已停止,停止原因:" + detail.StopReason);
                }
                //3.判断购买个数是否小于等于剩余个数
                if (int.Parse(para.qty) > detail.RemainingQty)
                {
                    throw new Exception("活动商品数量不足,当前数量:" + detail.RemainingQty);
                }

                //获取当前会员购买个数
                if (detail.SinglePurchaseQty > 0)//限购
                {
                    List <IWhereCondition> buyCondition = new List <IWhereCondition> {
                    };
                    buyCondition.Add(new EqualsCondition()
                    {
                        FieldName = "VipId", Value = para.userId
                    });
                    buyCondition.Add(new EqualsCondition()
                    {
                        FieldName = "itemId", Value = detail.ItemId
                    });
                    //修改为商品与活动都筛选 xiaowen.qin 2016.5.21
                    buyCondition.Add(new EqualsCondition()
                    {
                        FieldName = "EventId", Value = para.eventId
                    });
                    buyCondition.Add(new DirectCondition(" EventOrderMappingId IS NOT NULL "));
                    var panicbuyingKJEventJoinBLL = new PanicbuyingKJEventJoinBLL(loggingSessionInfo);
                    int buyCount = panicbuyingKJEventJoinBLL.Query(buyCondition.ToArray(), null).Count();
                    if (buyCount + int.Parse(para.qty) > detail.SinglePurchaseQty)
                    {
                        throw new Exception("限购" + detail.SinglePurchaseQty + "件,你还能购买" + (detail.SinglePurchaseQty - buyCount) + "件,请修改购买数量");
                    }
                }
            }
            else //团购抢购
            {
                var eventBll = new vwItemPEventDetailBLL(loggingSessionInfo);
                var detail   = eventBll.GetByEventIDAndSkuID(para.eventId, para.orderDetailList[0].skuId.ToString());
                salesPrice       = detail.SalesPrice ?? 0;        //团购抢购销售价
                para.totalAmount = (salesPrice * qty).ToString(); //团购抢购总金额
                if (detail == null)
                {
                    throw new Exception("未找到相关活动商品信息");
                }
                //1.需要判断,该订单的商品是否还有盈余
                if (detail.RemainingQty <= 0)
                {
                    throw new Exception("活动商品数量不足,当前数量:0");
                }
                //2.判断,该商品活动是否已经终止
                if (!string.IsNullOrEmpty(detail.StopReason))
                {
                    throw new Exception("活动已停止,停止原因:" + detail.StopReason);
                }
                //3.判断购买个数是否小于等于剩余个数
                if (int.Parse(para.qty) > detail.RemainingQty)
                {
                    throw new Exception("活动商品数量不足,当前数量:" + detail.RemainingQty);
                }
            }

            if (string.IsNullOrEmpty(para.userId))
            {
                throw new Exception("会员信息不存在");
            }

            #endregion

            //订单类型

            #region 根据订单参数设置订单类型

            string order_reason_id = string.Empty;
            if (para.isGroupBy == "1") //团购
            {
                order_reason_id = "CB43DD7DD1C94853BE98C4396738E00C";
            }
            else if (para.isPanicbuying == "1") //抢购
            {
                order_reason_id = "671E724C85B847BDA1E96E0E5A62055A";
            }
            else if (para.isBargain == "1") //砍价
            {
                order_reason_id = "096419BFDF394F7FABFE0DFCA909537F";
            }
            else //普通
            {
                order_reason_id = "2F6891A2194A4BBAB6F17B4C99A6C6F5";
            }

            #endregion

            //创建事务
            var tran    = this._currentDAO.GetTran();
            var orderId = string.Empty;
            try
            {
                using (tran.Connection)
                {
                    T_InoutEntity entity = new T_InoutEntity()
                    {
                        #region 订单初始化
                        order_date       = DateTime.Now.ToString("yyyy-MM-dd"),
                        order_type_id    = "1F0A100C42484454BAEA211D4C14B80F",
                        create_time      = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                        customer_id      = para.customerId,
                        status           = "1",
                        total_qty        = Convert.ToDecimal(para.qty),
                        unit_id          = para.storeId,
                        order_no         = OrderCode,
                        order_id         = Guid.NewGuid().ToString("N"),
                        order_reason_id  = order_reason_id,                    //订单类型:普通,团购,抢购
                        red_flag         = "1",
                        warehouse_id     = "67bb4c12785c42d4912aff7d34606592", //???是否是这个??
                        create_unit_id   = para.storeId,
                        create_user_id   = para.userId,
                        total_amount     = Convert.ToDecimal(para.totalAmount),
                        actual_amount    = Convert.ToDecimal(para.actualAmount),
                        discount_rate    = para.Rate,
                        total_retail     = Convert.ToDecimal(para.totalAmount),
                        print_times      = Convert.ToInt32(para.joinNo),
                        vip_no           = para.userId,
                        data_from_id     = para.reqBy,
                        if_flag          = "0",
                        remark           = para.remark,
                        Field1           = "0",
                        Field3           = para.isALD,
                        Field7           = "-99",
                        Field8           = para.deliveryId,
                        send_time        = para.deliveryTime,
                        Field9           = para.deliveryTime,
                        Field4           = para.deliveryAddress,
                        Field6           = para.mobile,
                        Field12          = para.email,
                        Field13          = para.openId,
                        Field10          = "未审核",
                        Field14          = para.username,
                        Field20          = para.tableNumber,
                        Field16          = para.couponsPrompt,
                        Field15          = order_reason_id,
                        sales_unit_id    = para.storeId,
                        purchase_unit_id = para.storeId
                                           #endregion
                    };
                    //订单状态
                    if (loggingSessionInfo.CurrentLoggingManager.IsApprove == null ||
                        loggingSessionInfo.CurrentLoggingManager.IsApprove.Equals("0"))
                    {
                        entity.status      = "100";
                        entity.status_desc = "未审批";
                    }
                    //创建订单
                    this._currentDAO.Create(entity, tran);
                    orderId = entity.order_id;
                    //创建订单明细

                    #region 订单明细列表

                    var detailbll = new T_Inout_DetailBLL(loggingSessionInfo);
                    foreach (var item in para.orderDetailList)
                    {
                        var detailEntity = new T_Inout_DetailEntity()
                        {
                            create_time         = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                            create_user_id      = para.userId,
                            modify_time         = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                            modify_user_id      = para.userId,
                            unit_id             = para.storeId,
                            discount_rate       = para.Rate,
                            std_price           = Convert.ToDecimal(item.salesPrice),
                            enter_price         = Convert.ToDecimal(item.salesPrice),
                            sku_id              = item.skuId,
                            enter_qty           = Convert.ToDecimal(para.qty),
                            order_id            = entity.order_id,
                            order_detail_id     = Guid.NewGuid().ToString("N"),
                            order_qty           = entity.total_qty,
                            enter_amount        = item.Amount,
                            order_detail_status = "1",
                            retail_amount       = item.Amount,
                            retail_price        = item.Amount,
                            display_index       = 1,
                            if_flag             = 0
                        };
                        detailbll.Create(detailEntity, tran);
                    }

                    #endregion

                    //下订单,修改抢购商品的数量信息存储过程ProcPEventItemQty
                    //var eventbll = new vwItemPEventDetailBLL(loggingSessionInfo);
                    //eventbll.ExecProcPEventItemQty(para, entity, tran);
                    tran.Commit();
                }
            }
            catch (Exception ex)
            {
                tran.Rollback();
                throw ex;
            }
            //
            return(orderId);
        }
Exemple #2
0
        /// <summary>
        /// 取消订单(Api和后台通用)
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="userType">0=会员;1=后台用户</param>
        /// <param name="loggingSessionInfo"></param>
        public void SetCancelOrder(string orderId, int userType, LoggingSessionInfo loggingSessionInfo)
        {
            var vipBll         = new VipBLL(loggingSessionInfo);                                                                           //会员业务实例化
            var inoutDetailBLL = new Inout3Service(loggingSessionInfo);                                                                    //订单业务实例化
            var refundOrderBll = new T_RefundOrderBLL(loggingSessionInfo);                                                                 //退货业务实例化
            var inoutBll       = new T_InoutBLL(loggingSessionInfo);                                                                       //订单业务实例化
            PanicbuyingEventBLL panicbuyingEventBLL = new PanicbuyingEventBLL(loggingSessionInfo);                                         //活动订单业务实例化
            T_SuperRetailTraderItemMappingBLL superRetailTraderItemMappingBll = new T_SuperRetailTraderItemMappingBLL(loggingSessionInfo); //分销商业务实例化

            //获取订单详情
            var inoutInfo = inoutBll.GetInoutInfo(orderId, loggingSessionInfo);

            //处理积分、余额、返现和优惠券
            vipBll.ProcSetCancelOrder(loggingSessionInfo.ClientID, inoutInfo.order_id, inoutInfo.vip_no);
            //获取订单明细
            var inoutDetailList = inoutDetailBLL.GetInoutDetailInfoByOrderId(inoutInfo.order_id, loggingSessionInfo.ClientID);

            #region 处理退款业务
            if (inoutInfo != null)
            {
                //if (inoutInfo.Field1 == "1" && (inoutInfo.actual_amount - inoutInfo.DeliveryAmount) > 0)//已付款,并且实付款-运费>0
                if (inoutInfo.Field1 == "1" && inoutInfo.actual_amount > 0)//已付款,并且实付款>0,未发货所以不用减运费
                {
                    #region 新增退货单(默认状态为确认收货)
                    var salesReturnBLL = new T_SalesReturnBLL(loggingSessionInfo);
                    var historyBLL     = new T_SalesReturnHistoryBLL(loggingSessionInfo);
                    T_SalesReturnEntity        salesReturnEntity = null;
                    T_SalesReturnHistoryEntity historyEntity     = null;

                    var       userBll   = new T_UserBLL(loggingSessionInfo); //店员BLL实例化
                    VipEntity vipEntity = null;                              //会员信息

                    salesReturnEntity = new T_SalesReturnEntity();
                    salesReturnEntity.SalesReturnNo = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                    salesReturnEntity.VipID         = loggingSessionInfo.UserID;
                    salesReturnEntity.ServicesType  = 1; //退货
                    salesReturnEntity.DeliveryType  = 1; //快递送回;
                    salesReturnEntity.OrderID       = inoutInfo.order_id;
                    var inoutDetailInfo = inoutDetailList.FirstOrDefault();
                    if (inoutDetailInfo != null)
                    {
                        salesReturnEntity.ItemID = inoutDetailInfo.item_id;
                        salesReturnEntity.SkuID  = inoutDetailInfo.sku_id;
                    }
                    salesReturnEntity.Qty       = 0;
                    salesReturnEntity.ActualQty = 0;
                    if (inoutInfo != null)
                    {
                        salesReturnEntity.UnitID = inoutInfo.sales_unit_id;
                        //salesReturnEntity.UnitName = para.UnitName;
                        //salesReturnEntity.UnitTel = para.UnitTel;
                        salesReturnEntity.Address  = inoutInfo.Field4;
                        salesReturnEntity.Contacts = inoutInfo.Field14 != null ? inoutInfo.Field14 : "";
                        salesReturnEntity.Phone    = inoutInfo.Field6 != null ? inoutInfo.Field6 : "";
                    }
                    salesReturnEntity.Reason = "取消订单";
                    //if (inoutInfo.actual_amount - inoutInfo.DeliveryAmount > 0)
                    if (inoutInfo.actual_amount > 0)
                    {
                        salesReturnEntity.Status = 6; //已完成(待退款)
                    }
                    else
                    {
                        salesReturnEntity.Status = 7; //已完成(已退款)
                    }
                    salesReturnEntity.CustomerID = loggingSessionInfo.ClientID;
                    salesReturnBLL.Create(salesReturnEntity);

                    string userName = string.Empty; //操作人姓名
                    if (userType == 0)              //会员操作
                    {
                        vipEntity = vipBll.GetByID(loggingSessionInfo.UserID);
                        userName  = vipEntity != null ? vipEntity.VipName : "";
                    }
                    else//后台用户操作
                    {
                        userName = loggingSessionInfo.CurrentUser.User_Name;
                    }
                    historyEntity = new T_SalesReturnHistoryEntity()
                    {
                        SalesReturnID = salesReturnEntity.SalesReturnID,
                        OperationType = 14,
                        OperationDesc = "取消订单",
                        OperatorID    = loggingSessionInfo.UserID,
                        HisRemark     = "取消订单",
                        OperatorName  = userName,
                        OperatorType  = userType  //0=会员;1=管理用户
                    };
                    historyBLL.Create(historyEntity);
                    #endregion

                    #region 新增退款单
                    //if (inoutInfo.actual_amount - inoutInfo.DeliveryAmount > 0)
                    if (inoutInfo.actual_amount > 0)
                    {
                        T_RefundOrderEntity refundOrderEntity = new T_RefundOrderEntity()
                        {
                            RefundNo      = DateTime.Now.ToString("yyyyMMddhhmmfff"),
                            VipID         = inoutInfo.vip_no,
                            SalesReturnID = salesReturnEntity.SalesReturnID,
                            //ServicesType = 1,//退货
                            DeliveryType = 1,//快递送回
                            ItemID       = inoutDetailInfo.item_id,
                            SkuID        = inoutDetailInfo.sku_id,
                            Qty          = 0,
                            ActualQty    = 0,
                            UnitID       = inoutInfo.sales_unit_id,
                            //salesReturnEntity.UnitName = para.UnitName;
                            //salesReturnEntity.UnitTel = para.UnitTel;
                            Address       = inoutInfo.Field4,
                            Contacts      = inoutInfo.Field14,
                            Phone         = inoutInfo.Field6,
                            OrderID       = inoutInfo.order_id,
                            PayOrderID    = inoutInfo.paymentcenter_id,
                            RefundAmount  = inoutInfo.total_amount,
                            ConfirmAmount = inoutInfo.total_amount,
                            //ActualRefundAmount = inoutInfo.actual_amount - inoutInfo.DeliveryAmount,//实退金额=实付款-运费
                            ActualRefundAmount = inoutInfo.actual_amount,//实退金额=实付款
                            Points             = inoutInfo.pay_points == null ? 0 : Convert.ToInt32(inoutInfo.pay_points),
                            ReturnAmount       = inoutInfo.ReturnAmount,
                            Amount             = inoutInfo.VipEndAmount,
                            Status             = 1,//待退款
                            CustomerID         = loggingSessionInfo.ClientID
                        };
                        refundOrderBll.Create(refundOrderEntity);
                    }
                    #endregion
                }
            }
            #endregion

            //普通订单库存处理
            if (inoutInfo.order_reason_id == "2F6891A2194A4BBAB6F17B4C99A6C6F5")
            {
                inoutBll.SetStock(orderId, inoutDetailList, 2, loggingSessionInfo);
            }
            //团购抢购订单库存处理
            if (inoutInfo.order_reason_id == "CB43DD7DD1C94853BE98C4396738E00C" || inoutInfo.order_reason_id == "671E724C85B847BDA1E96E0E5A62055A")
            {
                panicbuyingEventBLL.SetEventStock(orderId, inoutDetailList.ToList());
            }
            //砍价订单库存处理
            if (inoutInfo.order_reason_id == "096419BFDF394F7FABFE0DFCA909537F")
            {
                panicbuyingEventBLL.SetKJEventStock(orderId, inoutDetailList.ToList());
            }
            //超级分销商库存处理
            if (inoutInfo.data_from_id == "35" || inoutInfo.data_from_id == "36")
            {
                superRetailTraderItemMappingBll.DeleteSuperRetailTraderItemStock(inoutDetailList.ToList());
            }
        }