Esempio n. 1
0
        /// <summary>
        /// 支付回调/收款处理虚拟商品订单
        /// </summary>
        public void SetVirtualItem(LoggingSessionInfo loggingSessionInfo, string orderId)
        {
            var inoutBLL  = new T_InoutBLL(loggingSessionInfo);
            var inoutInfo = this._currentDAO.GetByID(orderId);

            if (inoutInfo != null)
            {
                //如果是经销商订单,付款完成后,订单状态修改成完成状态
                if (inoutInfo.data_from_id == "21")
                {
                    inoutInfo.Field7 = "700";
                    inoutInfo.status = "700";
                    inoutBLL.Update(inoutInfo);
                    InoutService inoutService = new InoutService(loggingSessionInfo);
                    T_VirtualItemTypeSettingBLL virtualItemTypeSettingBLL = new T_VirtualItemTypeSettingBLL(loggingSessionInfo);
                    VipCardVipMappingBLL        vipCardVipMappingBLL      = new VipCardVipMappingBLL(loggingSessionInfo);
                    T_Inout_DetailBLL           inoutDetailBLL            = new T_Inout_DetailBLL(loggingSessionInfo);
                    var    VipBLL      = new VipBLL(loggingSessionInfo);
                    var    inoutDetail = inoutService.GetInoutDetailInfoByOrderId(orderId).FirstOrDefault();
                    string itemId      = inoutDetail.item_id;

                    var virtualItemTypeSettingInfo = virtualItemTypeSettingBLL.QueryByEntity(new T_VirtualItemTypeSettingEntity()
                    {
                        ItemId = itemId
                    }, null).FirstOrDefault();
                    if (virtualItemTypeSettingInfo != null)
                    {
                        int    objectTypeId = int.Parse(virtualItemTypeSettingInfo.ObjecetTypeId);
                        string objectNo     = vipCardVipMappingBLL.BindVirtualItem(inoutInfo.vip_no, inoutInfo.VipCardCode, "", objectTypeId);
                        //将卡/券的编号保存到订单明细
                        T_Inout_DetailEntity inoutDetailEntity = inoutDetailBLL.GetByID(inoutDetail.order_detail_id);
                        if (inoutDetailEntity != null)
                        {
                            inoutDetailEntity.Field10 = objectNo;
                            inoutDetailBLL.Update(inoutDetailEntity);
                        }
                    }
                    //将Col48至为1
                    var VipData = VipBLL.GetByID(inoutInfo.vip_no);
                    if (VipData != null)
                    {
                        VipData.Col48 = "1";
                        VipBLL.Update(VipData);
                    }
                    // 判断客户是否是符合潜在经销商条件
                    var isCan = VipBLL.IsSetVipDealer(inoutInfo.vip_no);

                    if (isCan)
                    {
                        new RetailTraderBLL(loggingSessionInfo).CreatePrepRetailTrader(loggingSessionInfo, inoutInfo.vip_no); // 创建潜在经销商
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 获取订单列表。Add by Alex Tian 2014-04-16
        /// </summary>
        /// <param name="pIsIncludeOrderDetails">是否获取订单商品详细</param>
        /// <param name="pOrderStatuses">订单状态</param>
        /// <param name="pOrderID">订单ID</param>
        /// <param name="pVIPID">会员ID</param>
        /// <param name="pPageSize">每页记录数,默认15</param>
        /// <param name="pPageIndex">当前页,默认为0</param>
        /// <returns></returns>
        public GetOrderListRD GetOrderList(bool pIsIncludeOrderDetails, int[] pOrderStatuses, string pOrderID,
                                           int pPageSize, int pPageIndex)
        {
            GetOrderListRD       RD   = new GetOrderListRD();
            DataSet              ds   = new DataSet();
            List <T_InoutEntity> list = new List <T_InoutEntity> {
            };
            var Orderlist             = new List <JIT.CPOS.DTO.Module.Order.Order.Response.OrderInfo> {
            };

            ds = _currentDAO.GetOrderList(pOrderStatuses, pOrderID, pPageSize, pPageIndex);
            using (var rd = ds.Tables[0].CreateDataReader())
            {
                while (rd.Read())
                {
                    T_InoutEntity m;
                    this._currentDAO.NewLoad(rd, out m);
                    list.Add(m);
                }
            }

            if (pIsIncludeOrderDetails == false)
            {
                foreach (var item in list)
                {
                    JIT.CPOS.DTO.Module.Order.Order.Response.OrderInfo orderinfo =
                        new DTO.Module.Order.Order.Response.OrderInfo();
                    orderinfo.OrderID        = item.order_id;
                    orderinfo.OrderNO        = item.order_no;
                    orderinfo.DeliveryTypeID = Convert.ToInt32(string.IsNullOrEmpty(item.Field8) ? "0" : item.Field8);
                    orderinfo.OrderDate      = Convert.ToDateTime(item.create_time);
                    //下单时间,由于下单表中的OrderDate没有时分秒。所以取得时间为create_time
                    orderinfo.OrderStatusDesc = item.status_desc;                      //订单状态描述
                    orderinfo.OrderStatus     = Convert.ToInt32(item.status);          //订单状态
                    orderinfo.TotalQty        = Convert.ToInt32(item.total_qty);       //订单数量
                    orderinfo.TotalAmount     = Convert.ToDecimal(item.actual_amount); //订单总金额之前用的是item.total_amount
                    orderinfo.OrderDetails    = null;
                    Orderlist.Add(orderinfo);
                }
                RD.OrderList = Orderlist.ToArray();
            }
            if (pIsIncludeOrderDetails == true) //查询订单详细信息。
            {
                var ids           = list.Select(t => t.order_id).ToArray();
                var detailBLL     = new T_Inout_DetailBLL(this.CurrentUserInfo as LoggingSessionInfo);
                var detailEntitys = detailBLL.GetByIDS(ids);

                foreach (var item in list)
                {
                    JIT.CPOS.DTO.Module.Order.Order.Response.OrderInfo orderinfo =
                        new DTO.Module.Order.Order.Response.OrderInfo();
                    orderinfo.OrderID        = item.order_id;
                    orderinfo.OrderNO        = item.order_no;
                    orderinfo.DeliveryTypeID = Convert.ToInt32(string.IsNullOrEmpty(item.Field8) ? "0" : item.Field8);
                    orderinfo.OrderDate      = Convert.ToDateTime(item.create_time);
                    //下单时间,由于下单表中的OrderDate没有时分秒。所以取得时间为create_time
                    orderinfo.OrderStatusDesc = item.status_desc;                      //订单状态描述
                    orderinfo.OrderStatus     = Convert.ToInt32(item.status);          //订单状态
                    orderinfo.TotalQty        = Convert.ToInt32(item.total_qty);       //订单数量
                    orderinfo.TotalAmount     = Convert.ToDecimal(item.actual_amount); //订单总金额//订单总金额之前用的是item.total_amount
                    var templist        = detailEntitys.Where(t => t.order_id == item.order_id).ToArray();
                    var tempDetailInfos = new List <JIT.CPOS.DTO.Module.Order.Order.Response.OrderDetailInfo> {
                    };
                    foreach (var it in templist)
                    {
                        var detailInfo = new JIT.CPOS.DTO.Module.Order.Order.Response.OrderDetailInfo();
                        detailInfo.ItemID            = it.ItemID;            //商品ID
                        detailInfo.ItemName          = it.ItemName;          //商品名称
                        detailInfo.SKUID             = it.SKUID;             //SKUID
                        detailInfo.Qty               = it.Qty;               //购买数量
                        detailInfo.SpecificationDesc = it.SpecificationDesc; //规格描述
                        detailInfo.SalesPrice        = it.SalesPrice;        //实际单价
                        detailInfo.ImageUrl          = it.ImageUrl;          //Url图片

                        #region 新增规格

                        var GGds = _currentDAO.GetInoutDetailGgByOrderId(pOrderID);
                        if (GGds != null && GGds.Tables.Count > 0)
                        {
                            detailInfo.GG =
                                GGds.Tables[0].AsEnumerable()
                                .Where(t => t["sku_id"].ToString() == it.SKUID.ToString())
                                .Select(t => new JIT.CPOS.DTO.Module.Order.Order.Response.GuiGeInfo
                            {
                                PropName1       = t["prop_1_name"].ToString(),
                                PropDetailName1 = t["prop_1_detail_name"].ToString(),
                                PropName2       = t["prop_2_name"].ToString(),
                                PropDetailName2 = t["prop_2_detail_name"].ToString(),
                                PropName3       = t["prop_3_name"].ToString(),
                                PropDetailName3 = t["prop_3_detail_name"].ToString(),
                                PropName4       = t["prop_4_name"].ToString(),
                                PropDetailName4 = t["prop_4_detail_name"].ToString(),
                                PropName5       = t["prop_5_name"].ToString(),
                                PropDetailName5 = t["prop_5_detail_name"].ToString()
                            }).FirstOrDefault();
                        }

                        #endregion

                        tempDetailInfos.Add(detailInfo);
                    }
                    orderinfo.OrderDetails = tempDetailInfos.ToArray();
                    Orderlist.Add(orderinfo);
                }
                RD.OrderList = Orderlist.ToArray();
            }
            return(RD);
        }
Esempio n. 3
0
        /// <summary>
        /// 获取订单状态 Add by Alex Tian 2014-04-16
        /// </summary>
        /// <returns></returns>
        public GetOrdersRD GetOrder(string vipno, int PageIndex, int PageSize, string customer_id, int GroupingType, string ChannelId, string UserId, bool isShowUnitName = false)
        {
            var loggingSessionInfo = this.CurrentUserInfo as LoggingSessionInfo;
            var unitbll            = new UnitBLL(loggingSessionInfo);

            GetOrdersRD rdata = new GetOrdersRD();
            DataSet     ds    = null;

            //switch (GroupingType)
            //{
            //    case 1:
            //        ds = this._currentDAO.GetOrderByObligation(vipno, PageIndex, PageSize, customer_id); //查询订单状态为待付款
            //        break;
            //    case 2:
            //        ds = this._currentDAO.GetOrderByNodelivery(vipno, PageIndex, PageSize, customer_id); //查询订单状态为待收货/提货
            //        break;
            //    case 3:
            //        ds = this._currentDAO.GetOrderBydonedeal(vipno, PageIndex, PageSize, customer_id); //订单状态为已完成
            //        break;
            //    default:
            //        break;
            //}


            //如果是人人销售渠道取新的存储过程 add by donal 2014-9-26 17:41:10
            if (ChannelId == "6")
            {
                ds = this._currentDAO.GetOrderByGroupingTypeEvery(UserId, PageIndex, PageSize, customer_id, GroupingType);
            }
            else
            {
                ds = this._currentDAO.GetOrderByGroupingType(vipno, PageIndex, PageSize, customer_id, GroupingType);
            }

            if (ds != null && ds.Tables[1] != null && ds.Tables[1].Rows.Count > 0)
            {
                List <T_InoutEntity> list = new List <T_InoutEntity> {
                };
                int count = Convert.ToInt32(ds.Tables[1].Rows[0][0]);

                if (count <= 0)
                {
                    return(rdata);
                }
                using (var rd = ds.Tables[1].CreateDataReader())
                {
                    while (rd.Read())
                    {
                        T_InoutEntity m;
                        this._currentDAO.NewLoad(rd, out m);
                        list.Add(m);
                    }
                }
                var ids           = list.Select(t => t.order_id).ToArray();
                var detailBLL     = new T_Inout_DetailBLL(this.CurrentUserInfo as LoggingSessionInfo);
                var detailEntitys = detailBLL.GetByIDS(ids);
                var Orderlist     = new List <JIT.CPOS.DTO.Module.VIP.Order.Response.OrderInfo> {
                };

                #region [ 组织orderInfo ]

                foreach (var item in list)
                {
                    JIT.CPOS.DTO.Module.VIP.Order.Response.OrderInfo orderinfo =
                        new DTO.Module.VIP.Order.Response.OrderInfo();
                    orderinfo.OrderID        = item.order_id; //订单ID
                    orderinfo.OrderNO        = item.order_no; //订单编码
                    orderinfo.DeliveryTypeID = Convert.ToInt32(string.IsNullOrEmpty(item.Field8) ? "0" : item.Field8);
                    //配送方式类别ID,1.送货上门。2.到店自取
                    orderinfo.purchase_unit_id = item.purchase_unit_id;           //提货门店
                    orderinfo.OrderDate        = item.create_time;                //在订单表中的下单时间没有时分秒。所以取create_time
                    orderinfo.OrderStatusDesc  = item.status_desc;                //订单状态描述
                    orderinfo.OrderStatus      = Convert.ToInt32(item.status);    //订单状态
                    orderinfo.TotalQty         = Convert.ToInt32(item.total_qty); //商品购买数量
                    if (string.IsNullOrEmpty(item.Field3))
                    {
                        item.Field3 = "0";
                    }
                    orderinfo.TotalAmount     = Convert.ToDecimal(item.actual_amount) - Convert.ToDecimal(item.Field3); //总金额
                    orderinfo.PaymentTypeCode = item.Payment_Type_Code;                                                 //支付方式
                    orderinfo.ReturnCash      = item.ReturnCash == null ? 0.00m : Convert.ToDecimal(item.ReturnCash);   //佣金
                    orderinfo.IsEvaluation    = item.IsEvaluation == null ? 0 : item.IsEvaluation.Value;                //是否评论
                    orderinfo.IsPayed         = item.Field1 == null ? "0" : item.Field1;
                    #region 根据OrderInfo组织detail

                    var templist        = detailEntitys.Where(t => t.order_id == item.order_id).ToArray();
                    var tempDetailInfos = new List <JIT.CPOS.DTO.Module.VIP.Order.Response.OrderDetailInfo> {
                    };

                    foreach (var it in templist)
                    {
                        var detailInfo = new JIT.CPOS.DTO.Module.VIP.Order.Response.OrderDetailInfo();
                        detailInfo.ItemID            = it.ItemID;                                         //商品ID
                        detailInfo.ItemName          = it.ItemName;                                       //商品名称
                        detailInfo.SKUID             = it.SKUID;                                          //SKUID
                        detailInfo.Qty               = it.Qty;                                            //购买数量
                        detailInfo.SpecificationDesc = it.SpecificationDesc;                              //规格描述
                        detailInfo.SalesPrice        = it.SalesPrice;                                     //实际单价
                        detailInfo.ImageUrl          = ImagePathUtil.GetImagePathStr(it.ImageUrl, "240"); //Url图片 update by Henry 2014-12-8
                        detailInfo.ReturnCash        = it.ReturnCash;
                        detailInfo.isGB              = it.isGB;
                        if (it.isGB == 0)
                        {
                            orderinfo.IsIncludeGB = 1;
                        }

                        #region 新增规格

                        var GGds = _currentDAO.GetInoutDetailGgByOrderId(orderinfo.OrderID);
                        if (GGds != null && GGds.Tables.Count > 0)
                        {
                            detailInfo.GG =
                                GGds.Tables[0].AsEnumerable()
                                .Where(t => t["sku_id"].ToString() == it.SKUID.ToString())
                                .Select(t => new JIT.CPOS.DTO.Module.VIP.Order.Response.GuiGeInfo
                            {
                                PropName1       = t["prop_1_name"].ToString(),
                                PropDetailName1 = t["prop_1_detail_name"].ToString(),
                                PropName2       = t["prop_2_name"].ToString(),
                                PropDetailName2 = t["prop_2_detail_name"].ToString(),
                                PropName3       = t["prop_3_name"].ToString(),
                                PropDetailName3 = t["prop_3_detail_name"].ToString(),
                                PropName4       = t["prop_4_name"].ToString(),
                                PropDetailName4 = t["prop_4_detail_name"].ToString(),
                                PropName5       = t["prop_5_name"].ToString(),
                                PropDetailName5 = t["prop_5_detail_name"].ToString()
                            }).FirstOrDefault();
                        }

                        #endregion

                        tempDetailInfos.Add(detailInfo);
                    }

                    #endregion

                    if (isShowUnitName)
                    {
                        var unit = unitbll.GetUnitDetail(item.sales_unit_id);
                        orderinfo.Unit = unit.unit_name;
                    }
                    orderinfo.OrderDetails = tempDetailInfos.ToArray();

                    Orderlist.Add(orderinfo);
                }

                #endregion

                rdata.PageIndex      = PageIndex;
                rdata.TotalPageCount = count;
                rdata.Orders         = Orderlist.ToArray();
            }

            //获得不同分组下的订单数量
            if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
            {
                var Grouplist = new List <JIT.CPOS.DTO.Module.VIP.Order.Response.GroupingOrderCount> {
                };

                if (ds.Tables[0].Rows.Count > 0)
                {
                    //待付款
                    var grouporder1 = new JIT.CPOS.DTO.Module.VIP.Order.Response.GroupingOrderCount();
                    grouporder1.GroupingType = 1;
                    grouporder1.OrderCount   = int.Parse(ds.Tables[0].Rows[0]["RowRnt1"].ToString());
                    Grouplist.Add(grouporder1);

                    if (ChannelId != "6")
                    {
                        //待服务
                        var grouporder10 = new JIT.CPOS.DTO.Module.VIP.Order.Response.GroupingOrderCount();
                        grouporder10.GroupingType = 10;
                        grouporder10.OrderCount   = int.Parse(ds.Tables[0].Rows[0]["RowRnt10"].ToString());
                        Grouplist.Add(grouporder10);
                        //待提货
                        var grouporder11 = new JIT.CPOS.DTO.Module.VIP.Order.Response.GroupingOrderCount();
                        grouporder11.GroupingType = 11;
                        grouporder11.OrderCount   = int.Parse(ds.Tables[0].Rows[0]["RowRnt11"].ToString());
                        Grouplist.Add(grouporder11);
                        //待发货
                        var grouporder12 = new JIT.CPOS.DTO.Module.VIP.Order.Response.GroupingOrderCount();
                        grouporder12.GroupingType = 12;
                        grouporder12.OrderCount   = int.Parse(ds.Tables[0].Rows[0]["RowRnt12"].ToString());
                        Grouplist.Add(grouporder12);
                        //已服务
                        var grouporder13 = new JIT.CPOS.DTO.Module.VIP.Order.Response.GroupingOrderCount();
                        grouporder13.GroupingType = 13;
                        grouporder13.OrderCount   = int.Parse(ds.Tables[0].Rows[0]["RowRnt13"].ToString());
                        Grouplist.Add(grouporder13);
                        //已提货
                        var grouporder14 = new JIT.CPOS.DTO.Module.VIP.Order.Response.GroupingOrderCount();
                        grouporder14.GroupingType = 14;
                        grouporder14.OrderCount   = int.Parse(ds.Tables[0].Rows[0]["RowRnt14"].ToString());
                        Grouplist.Add(grouporder14);
                        //退换货
                        var grouporder5 = new JIT.CPOS.DTO.Module.VIP.Order.Response.GroupingOrderCount();
                        grouporder5.GroupingType = 5;
                        grouporder5.OrderCount   = int.Parse(ds.Tables[0].Rows[0]["RowRnt5"].ToString());
                        Grouplist.Add(grouporder5);
                    }

                    //已发货
                    var grouporder2 = new JIT.CPOS.DTO.Module.VIP.Order.Response.GroupingOrderCount();
                    grouporder2.GroupingType = 2;
                    grouporder2.OrderCount   = int.Parse(ds.Tables[0].Rows[0]["RowRnt2"].ToString());
                    Grouplist.Add(grouporder2);
                    //已完成
                    var grouporder3 = new JIT.CPOS.DTO.Module.VIP.Order.Response.GroupingOrderCount();
                    grouporder3.GroupingType = 3;
                    grouporder3.OrderCount   = int.Parse(ds.Tables[0].Rows[0]["RowRnt3"].ToString());
                    Grouplist.Add(grouporder3);


                    //已付款且门店自提 Add by Henry 2014-12-18
                    if (ChannelId == "6")
                    {
                        var grouporder4 = new JIT.CPOS.DTO.Module.VIP.Order.Response.GroupingOrderCount();
                        grouporder4.GroupingType = 4;
                        grouporder4.OrderCount   = int.Parse(ds.Tables[0].Rows[0]["RowRnt4"].ToString());
                        Grouplist.Add(grouporder4);
                    }
                    else
                    {
                        //未评论订单个数
                        var noEvaluationCount = new JIT.CPOS.DTO.Module.VIP.Order.Response.GroupingOrderCount();
                        noEvaluationCount.GroupingType = 6;
                        noEvaluationCount.OrderCount   = int.Parse(ds.Tables[0].Rows[0]["NoEvaluationCount"].ToString());
                        Grouplist.Add(noEvaluationCount);
                    }
                }

                rdata.GroupingOrderCounts = Grouplist.ToArray();
            }

            return(rdata);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        /// <summary>
        /// 计算销售会员卡分润
        /// </summary>
        /// <param name="loggingSessionInfo"></param>
        /// <param name="orderInfo"></param>
        public void CalculateSalesVipCardOrder(LoggingSessionInfo loggingSessionInfo, T_InoutEntity orderInfo)
        {
            if (orderInfo != null)
            {
                if (orderInfo.Field17 != null && orderInfo.Field18 != null && orderInfo.Field17.Length > 0 && orderInfo.Field18.Length > 0)
                {
                    VipBLL bllVip = new VipBLL(loggingSessionInfo);

                    T_Inout_DetailBLL           bllInoutDetail            = new T_Inout_DetailBLL(loggingSessionInfo);
                    T_VirtualItemTypeSettingBLL bllVirtualItemTypeSetting = new T_VirtualItemTypeSettingBLL(loggingSessionInfo);

                    var entityInoutDetail = bllInoutDetail.QueryByEntity(new T_Inout_DetailEntity()
                    {
                        order_id = orderInfo.order_id
                    }, null).FirstOrDefault();
                    var vipCardType = bllVirtualItemTypeSetting.QueryByEntity(new T_VirtualItemTypeSettingEntity()
                    {
                        SkuId = entityInoutDetail.sku_id, IsDelete = 0
                    }, null).FirstOrDefault();
                    if (vipCardType != null)
                    {
                        VipCardUpgradeRuleBLL bllVipCardUpgradeRule = new VipCardUpgradeRuleBLL(loggingSessionInfo);

                        int intVipCardTypeID         = Convert.ToInt32(vipCardType.ObjecetTypeId);
                        var entityVipCardUpgradeRule = bllVipCardUpgradeRule.QueryByEntity(new VipCardUpgradeRuleEntity()
                        {
                            VipCardTypeID = intVipCardTypeID, IsPurchaseUpgrade = 1, IsDelete = 0
                        }, null).SingleOrDefault();
                        #region
                        //if (entityVipCardUpgradeRule != null)
                        //{
                        //    VipCardGradeChangeLogEntity entityVipCardGradeChangeLog = new VipCardGradeChangeLogEntity();
                        //    VipCardStatusChangeLogEntity entityVipCardStatusChangeLog = new VipCardStatusChangeLogEntity();

                        //    VipCardGradeChangeLogBLL bllVipCardGradeChangeLog = new VipCardGradeChangeLogBLL(loggingSessionInfo);
                        //    VipCardStatusChangeLogBLL bllVipCardStatusChangeLog = new VipCardStatusChangeLogBLL(loggingSessionInfo);
                        //    VipCardVipMappingBLL vipCardVipMappingBLL = new VipCardVipMappingBLL(loggingSessionInfo);

                        //    //会员等级改变以及如日志
                        //    DataSet dsVipInfo = bllVip.GetVipCardLevel(orderInfo.vip_no, loggingSessionInfo.ClientID);
                        //    if(dsVipInfo.Tables.Count>0 && dsVipInfo.Tables[0].Rows.Count>0)
                        //    {
                        //        //会员升级
                        //        vipCardVipMappingBLL.BindVirtualItem(orderInfo.vip_no, orderInfo.VipCardCode, "", intVipCardTypeID);
                        //        //日志
                        //        entityVipCardGradeChangeLog = new VipCardGradeChangeLogEntity()
                        //        {
                        //            ChangeLogID=Guid.NewGuid().ToString(),
                        //            VipCardUpgradeRuleId=entityVipCardUpgradeRule.VipCardUpgradeRuleId,
                        //            OrderType = "SalesCard",
                        //            OrderId=orderInfo.order_id,
                        //            VipCardID = dsVipInfo.Tables[0].Rows[0]["VipCardID"].ToString(),
                        //            ChangeBeforeVipCardID = dsVipInfo.Tables[0].Rows[0]["VipCardID"].ToString(),
                        //            ChangeBeforeGradeID = Convert.ToInt32(dsVipInfo.Tables[0].Rows[0]["VipCardTypeID"].ToString()),
                        //            NowGradeID = intVipCardTypeID,
                        //            ChangeReason="Upgrade",
                        //            OperationType = 2,
                        //            ChangeTime=DateTime.Now,
                        //            UnitID=orderInfo.sales_unit_id,
                        //            OperationUserID=orderInfo.sales_user
                        //        };
                        //        bllVipCardGradeChangeLog.Create(entityVipCardGradeChangeLog);
                        //    }
                        //}
                        #endregion
                        //计算分润
                        VipCardProfitRuleBLL bllVipCardProfitRule = new VipCardProfitRuleBLL(loggingSessionInfo);
                        var entityVipCardProfitRule = bllVipCardProfitRule.QueryByEntity(new VipCardProfitRuleEntity()
                        {
                            VipCardTypeID = intVipCardTypeID, IsDelete = 0
                        }, null);
                        if (entityVipCardProfitRule != null)
                        {
                            VipAmountBLL       bllVipAmount       = new VipAmountBLL(loggingSessionInfo);
                            VipAmountDetailBLL bllVipAmountDetail = new VipAmountDetailBLL(loggingSessionInfo);
                            VipAmountEntity    entityVipAmount    = new VipAmountEntity();

                            foreach (var ProfitRule in entityVipCardProfitRule)
                            {
                                decimal amount            = 0;
                                string  strAmountSourceId = string.Empty;
                                string  strVipId          = string.Empty;

                                if (ProfitRule.ProfitOwner == "Employee")
                                {
                                    strAmountSourceId = "37";
                                    strVipId          = orderInfo.sales_user;
                                }
                                if (ProfitRule.ProfitOwner == "Unit")
                                {
                                    strAmountSourceId = "40";
                                    strVipId          = orderInfo.sales_unit_id;
                                }
                                if (ProfitRule.IsApplyAllUnits == 0)
                                {
                                    VipCardProfitRuleUnitMappingBLL bllVipCardProfitRuleUnitMapping = new VipCardProfitRuleUnitMappingBLL(loggingSessionInfo);
                                    var vipCardProfitRuleUnitMapping = bllVipCardProfitRuleUnitMapping.QueryByEntity(new VipCardProfitRuleUnitMappingEntity()
                                    {
                                        CardBuyToProfitRuleId = ProfitRule.CardBuyToProfitRuleId, UnitID = orderInfo.sales_unit_id, IsDelete = 0, CustomerID = loggingSessionInfo.ClientID
                                    }, null).SingleOrDefault();
                                    if (vipCardProfitRuleUnitMapping != null)
                                    {
                                        amount = (decimal)ProfitRule.FirstCardSalesProfitPct * (decimal)orderInfo.actual_amount * (decimal)0.01;
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                }

                                amount = (decimal)ProfitRule.FirstCardSalesProfitPct * (decimal)orderInfo.actual_amount * (decimal)0.01;
                                if (amount > 0)
                                {
                                    IDbTransaction tran = new JIT.CPOS.BS.DataAccess.Base.TransactionHelper(loggingSessionInfo).CreateTransaction();

                                    VipAmountDetailEntity entityVipAmountDetail = new VipAmountDetailEntity
                                    {
                                        VipAmountDetailId = Guid.NewGuid(),
                                        VipId             = strVipId,
                                        Amount            = amount,
                                        UsedReturnAmount  = 0,
                                        EffectiveDate     = DateTime.Now,
                                        DeadlineDate      = Convert.ToDateTime("9999-12-31 23:59:59"),
                                        AmountSourceId    = strAmountSourceId,
                                        ObjectId          = orderInfo.order_id,
                                        CustomerID        = loggingSessionInfo.ClientID,
                                        Reason            = "超级分销商"
                                    };
                                    bllVipAmountDetail.Create(entityVipAmountDetail, (SqlTransaction)tran);

                                    entityVipAmount = new VipAmountEntity
                                    {
                                        VipId                  = strVipId,
                                        BeginAmount            = 0,
                                        InAmount               = amount,
                                        OutAmount              = 0,
                                        EndAmount              = amount,
                                        TotalAmount            = amount,
                                        BeginReturnAmount      = 0,
                                        InReturnAmount         = 0,
                                        OutReturnAmount        = 0,
                                        ReturnAmount           = 0,
                                        ImminentInvalidRAmount = 0,
                                        InvalidReturnAmount    = 0,
                                        ValidReturnAmount      = 0,
                                        TotalReturnAmount      = 0,
                                        IsLocking              = 0,
                                        CustomerID             = loggingSessionInfo.ClientID,
                                        VipCardCode            = ""
                                    };
                                    bllVipAmount.Create(entityVipAmount, tran);
                                }
                                else
                                {
                                    entityVipAmount.InReturnAmount    = (entityVipAmount.InReturnAmount == null ? 0 : entityVipAmount.InReturnAmount.Value) + amount;
                                    entityVipAmount.TotalReturnAmount = (entityVipAmount.TotalReturnAmount == null ? 0 : entityVipAmount.TotalReturnAmount.Value) + amount;

                                    entityVipAmount.ValidReturnAmount = (entityVipAmount.ValidReturnAmount == null ? 0 : entityVipAmount.ValidReturnAmount.Value) + amount;
                                    entityVipAmount.ReturnAmount      = (entityVipAmount.ReturnAmount == null ? 0 : entityVipAmount.ReturnAmount.Value) + amount;
                                    bllVipAmount.Update(entityVipAmount);
                                }
                            }
                        }
                    }
                }
            }
        }