Beispiel #1
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);
        }
        /// <summary>
        /// 处理门店和激励规则信息
        /// </summary>
        /// <param name="item"></param>
        /// <param name="CardBuyToProfitRuleId"></param>
        /// <param name="tran"></param>
        public void SetUnitAndProfitRule(CardBuyToProfitRuleInfoInfo item, Guid?CardBuyToProfitRuleId, LoggingSessionInfo loggingSessionInfo, IDbTransaction tran)
        {
            VipCardProfitRuleBLL            RuleService                 = new VipCardProfitRuleBLL(loggingSessionInfo);
            SysVipCardTypeBLL               SysCardTypeService          = new SysVipCardTypeBLL(loggingSessionInfo);
            VipCardProfitRuleUnitMappingBLL UnitMappService             = new VipCardProfitRuleUnitMappingBLL(loggingSessionInfo);
            VipCardReRechargeProfitRuleBLL  ReRechargeProfitRuleService = new VipCardReRechargeProfitRuleBLL(loggingSessionInfo);
            UnitBLL UnitService = new UnitBLL(loggingSessionInfo);

            #region 处理门店映射信息
            if (item.IsApplyAllUnits == 0) //部分门店 添加门店映射关系
            {
                if (item.RuleUnitInfoList != null)
                {
                    foreach (var unitInfo in item.RuleUnitInfoList) //门店集合列表
                    {
                        VipCardProfitRuleUnitMappingEntity UnitMappEntity = new VipCardProfitRuleUnitMappingEntity()
                        {
                            CardBuyToProfitRuleId = CardBuyToProfitRuleId,
                            CustomerID            = CurrentUserInfo.ClientID,
                            UnitID = unitInfo.UnitID
                        };
                        if (unitInfo.Id == null) //门店编号为空 既 添加门店
                        {
                            UnitMappService.Create(UnitMappEntity, tran);
                        }
                        else   //门店编号不为空  既 {修改门店| 删除门店 }
                        {
                            UnitMappEntity.CardBuyToProfitRuleId = item.CardBuyToProfitRuleId;
                            UnitMappEntity.Id       = unitInfo.Id;
                            UnitMappEntity.IsDelete = unitInfo.IsDelete;
                            UnitMappService.Update(UnitMappEntity, tran);
                        }
                    }
                }
            }
            else
            {
                //全部门店 默认将该规则下面的 门店删除
                UnitMappService.UpdateUnitMapping(item.CardBuyToProfitRuleId, tran);
            }
            #endregion

            #region 处理充值分润规则
            if (item.ProfitTypeInfoList != null)
            {
                foreach (var ProfitTypeInfo in item.ProfitTypeInfoList) //续费充值列表
                {
                    VipCardReRechargeProfitRuleEntity VipCardReRechargeProfitRuleInfo = new VipCardReRechargeProfitRuleEntity()
                    {
                        CardBuyToProfitRuleId = CardBuyToProfitRuleId,
                        CustomerID            = loggingSessionInfo.ClientID,
                        LimitAmount           = ProfitTypeInfo.LimitAmount,
                        ProfitPct             = ProfitTypeInfo.ProfitPct,
                        ProfitType            = ProfitTypeInfo.ProfitType,
                        VipCardTypeID         = item.VipCardTypeID
                    };

                    if (ProfitTypeInfo.ReRechargeProfitRuleId == null) //续费充值分润主键为空 --->添加续费充值分润方式
                    {
                        if (ProfitTypeInfo.LimitAmount > 0)            //防止 不可充值方式参数传递问题
                        {
                            ReRechargeProfitRuleService.Create(VipCardReRechargeProfitRuleInfo, tran);
                        }
                    }
                    else //----->修改续费充值分润方式
                    {
                        VipCardReRechargeProfitRuleInfo.ReRechargeProfitRuleId = ProfitTypeInfo.ReRechargeProfitRuleId;
                        VipCardReRechargeProfitRuleInfo.IsDelete = ProfitTypeInfo.IsDelete;
                        ReRechargeProfitRuleService.Update(VipCardReRechargeProfitRuleInfo, tran);
                    }
                }
            }
            #endregion
        }