/// <summary>
        /// 获取VIP列表
        /// </summary>
        public string GetVipListData()
        {
            var    service = new VipCardBLL(CurrentUserInfo);
            string content = string.Empty;

            int pageIndex = Utils.GetIntVal(FormatParamValue(Request("page")));

            pageIndex = pageIndex < 1 ? 1 : pageIndex;
            var queryEntity = new VipSearchEntity();

            queryEntity.Page     = pageIndex;
            queryEntity.PageSize = PageSize;

            if (Request("vipName") != "")
            {
                queryEntity.VipInfo = FormatParamValue(Request("vipName"));
            }
            if (Request("phone") != "")
            {
                queryEntity.Phone = FormatParamValue(Request("phone"));
            }

            var data = service.GetVipList(queryEntity);

            var dataTotalCount = data.ICount;

            content = string.Format("{{\"totalCount\":{1},\"topics\":{0}}}",
                                    data.vipInfoList.ToJSON(),
                                    dataTotalCount);
            return(content);
        }
Exemple #2
0
        protected override EmptyResponseData ProcessRequest(DTO.Base.APIRequest <DelSysVipCardTypeRP> pRequest)
        {
            var rd   = new EmptyResponseData();
            var para = pRequest.Parameters;
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            var sysVipCardTypeBLL  = new SysVipCardTypeBLL(loggingSessionInfo);
            var vipCardBLL         = new VipCardBLL(loggingSessionInfo);

            var vipCardTypeInfo = sysVipCardTypeBLL.GetByID(para.VipCardTypeID);

            if (vipCardTypeInfo != null)
            {
                var vipCardInfo = vipCardBLL.QueryByEntity(new VipCardEntity()
                {
                    VipCardTypeID = para.VipCardTypeID
                }, null).FirstOrDefault();
                if (vipCardInfo == null)
                {
                    sysVipCardTypeBLL.Delete(para.VipCardTypeID, null);
                }
                else
                {
                    throw new APIException("卡类型正在使用不可以删除!")
                          {
                              ErrorCode = ERROR_CODES.INVALID_BUSINESS
                          }
                };
            }
            return(rd);
        }
    }
        /// <summary>
        /// 删除会员卡信息
        /// </summary>
        public string DeleteVipCard()
        {
            var service = new VipCardBLL(CurrentUserInfo);

            string content      = string.Empty;
            string error        = "";
            var    responseData = new ResponseData();

            string key = string.Empty;

            if (FormatParamValue(Request("ids")) != null && FormatParamValue(Request("ids")) != string.Empty)
            {
                key = FormatParamValue(Request("ids")).ToString().Trim();
            }

            if (key == null || key.Trim().Length == 0)
            {
                responseData.success = false;
                responseData.msg     = "会员卡ID不能为空";
                return(responseData.ToJSON());
            }

            string[] ids = key.Split(',');
            foreach (var id in ids)
            {
                //删除会员卡信息
                service.DeleteVipCardInfo(id);
            }

            responseData.success = true;
            responseData.msg     = error;

            content = responseData.ToJSON();
            return(content);
        }
        /// <summary>
        ///
        /// </summary>
        public string GetVipCardInfoData()
        {
            var    service = new VipCardBLL(CurrentUserInfo);
            string content = string.Empty;

            string key = string.Empty;

            if (Request("VipCardID") != null && Request("VipCardID") != string.Empty)
            {
                key = Request("VipCardID").ToString().Trim();
            }

            VipCardEntity data = new VipCardEntity();

            data = service.SearchTopVipCard(new VipCardEntity()
            {
                VipCardID = key
            });

            string Lock = string.Empty;

            if (Request("Lock") != null && Request("Lock") != string.Empty)
            {
                Lock = Request("Lock").ToString().Trim();
                if (Lock == "1")
                {
                    LockVipCardInfoData();
                }
            }

            content = data.ToJSON();
            return(content);
        }
        /// <summary>
        /// 订单查询
        /// </summary>
        public string SearchVipCard()
        {
            var form = Request("form").DeserializeJSONTo <VipCardEntity>();

            VipCardBLL vipService = new VipCardBLL(CurrentUserInfo);

            VipCardEntity data    = new VipCardEntity();
            string        content = string.Empty;

            //string order_no = FormatParamValue(form.order_no);
            //string sales_unit_id = "";
            //string purchase_unit_id = "";
            //    purchase_unit_id = FormatParamValue(Request("purchase_unit_id"));

            //string order_status = FormatParamValue(form.order_status);
            int maxRowCount   = PageSize;
            int startRowIndex = Utils.GetIntVal(FormatParamValue(Request("start")));

            VipCardEntity searchInfo = new VipCardEntity();

            searchInfo.VipCardCode     = form.VipCardCode;
            searchInfo.VipName         = form.VipName;
            searchInfo.maxRowCount     = maxRowCount;
            searchInfo.startRowIndex   = startRowIndex;
            searchInfo.VipCardStatusId = form.VipCardStatusId;
            searchInfo.VipCardGradeID  = form.VipCardGradeID;
            data = vipService.SearchVipCard(searchInfo);

            content = string.Format("{{\"totalCount\":{1},\"topics\":{0}}}",
                                    data.VipCardInfoList.ToJSON(),
                                    data.ICount);
            return(content);
        }
Exemple #6
0
        protected override DayVendingRD ProcessRequest(DTO.Base.APIRequest <DayVendingRP> pRequest)
        {
            var rd   = new DayVendingRD();
            var para = pRequest.Parameters;
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            var VipCardBLL         = new VipCardBLL(loggingSessionInfo);

            try
            {
                if (string.IsNullOrWhiteSpace(para.StareDate) || string.IsNullOrWhiteSpace(para.EndDate))
                {
                    throw new APIException("日期区间参数为NULL!")
                          {
                              ErrorCode = ERROR_CODES.INVALID_BUSINESS
                          }
                }
                ;
            }
            catch (APIException apiEx)
            {
                throw new APIException(apiEx.ErrorCode, apiEx.Message);
            }


            rd = VipCardBLL.GetDayVendingCount(para.StareDate, para.EndDate);
            if (rd == null)
            {
                rd = new DayVendingRD();
            }
            return(rd);
        }
        /// <summary>
        /// 查询
        /// </summary>
        public string GetVipData()
        {
            var    vipBLL     = new VipBLL(CurrentUserInfo);
            var    vipCardBLL = new VipCardBLL(CurrentUserInfo);
            string content    = string.Empty;
            var    respData   = new VipRespData();

            var VipCardCode = FormatParamValue(Request("VipCardNumber"));
            var VipName     = FormatParamValue(Request("VipName"));
            var CarCode     = FormatParamValue(Request("CarNumber"));

            string vipId     = "";
            string vipCardId = "";

            var vipCardEntity = vipCardBLL.SearchTopVipCard(new VipCardEntity()
            {
                VipCardCode = VipCardCode,
                VipName     = VipName,
                CarCode     = CarCode
            });

            vipId     = vipCardEntity.VipId;
            vipCardId = vipCardEntity.VipCardID;

            respData.VipData     = vipBLL.GetByID(vipId);
            respData.VipCardData = vipCardEntity;

            content = respData.ToJSON();
            return(content);
        }
        /// <summary>
        /// 保存会员卡信息
        /// </summary>
        public string SaveVipCard()
        {
            var vipCardService = new VipCardBLL(this.CurrentUserInfo);

            string content      = string.Empty;
            string error        = "";
            var    responseData = new ResponseData();

            string key       = string.Empty;
            string vipCardID = string.Empty;
            var    vipCards  = Request("vipCards");

            if (FormatParamValue(vipCards) != null && FormatParamValue(vipCards) != string.Empty)
            {
                key = FormatParamValue(vipCards).ToString().Trim();
            }
            if (FormatParamValue(Request("VipCardID")) != null && FormatParamValue(Request("VipCardID")) != string.Empty)
            {
                vipCardID = FormatParamValue(Request("VipCardID")).ToString().Trim();
            }

            var vipCardEntity = key.DeserializeJSONTo <VipCardEntity>();

            if (vipCardEntity.VipCardTypeID == null || vipCardEntity.VipCardTypeID.ToString().Trim().Length == 0)
            {
                responseData.success = false;
                responseData.msg     = "卡类型不能为空";
                return(responseData.ToJSON());
            }
            if (vipCardEntity.VipCardStatusId == null || vipCardEntity.VipCardStatusId.ToString().Trim().Length == 0)
            {
                responseData.success = false;
                responseData.msg     = "卡状态不能为空";
                return(responseData.ToJSON());
            }
            if (vipCardEntity.VipCardGradeID == null || vipCardEntity.VipCardGradeID.ToString().Trim().Length == 0)
            {
                responseData.success = false;
                responseData.msg     = "卡等级不能为空";
                return(responseData.ToJSON());
            }
            if (vipCardEntity.UnitID == null || vipCardEntity.UnitID.Trim().Length == 0)
            {
                responseData.success = false;
                responseData.msg     = "会籍店不能为空";
                return(responseData.ToJSON());
            }

            var flag = vipCardService.SaveVipCardInfo(vipCardID, vipCardEntity);

            responseData.success = flag;
            responseData.msg     = error;

            content = responseData.ToJSON();
            return(content);
        }
        /// <summary>
        /// 卡注销
        /// </summary>
        public string SaveVipCardRechargeData()
        {
            var    vipCardRechargeRecordBLL = new VipCardRechargeRecordBLL(CurrentUserInfo);
            var    vipCardBLL = new VipCardBLL(CurrentUserInfo);
            string content    = string.Empty;
            var    data       = new VipRespData();

            string key = string.Empty;

            if (Request("vip") != null && Request("vip") != string.Empty)
            {
                key = Request("vip").ToString().Trim();
            }

            var entity = key.DeserializeJSONTo <VipCardRechargeQueryEntity>();

            if (entity.VipCardID == null || entity.VipCardID.Trim().Length == 0)
            {
                data.success     = false;
                data.Description = "卡标识不能为空";
                return(data.ToJSON());
            }

            string error  = string.Empty;
            var    result = vipCardRechargeRecordBLL.SetVipCardRecjargeRpecord(
                entity.VipCardID, entity.RechargeAmount, entity.OrderNo,
                entity.PaymentTypeID, entity.UnitID, out error);

            if (!result)
            {
                data.success     = false;
                data.Description = "错误:" + error;
                return(data.ToJSON());
            }

            string Lock = string.Empty;

            if (Request("Lock") != null && Request("Lock") != string.Empty)
            {
                Lock = Request("Lock").ToString().Trim();
                if (Lock == "1")
                {
                    LockVipCardInfoData();
                }
            }

            content = data.ToJSON();
            return(content);
        }
Exemple #10
0
        protected override DayReconciliationRD ProcessRequest(DTO.Base.APIRequest <DayReconciliationRP> pRequest)
        {
            var rd   = new DayReconciliationRD();
            var para = pRequest.Parameters;
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            var VipCardBLL         = new VipCardBLL(loggingSessionInfo);
            int Days = 0;

            try
            {
                if (string.IsNullOrWhiteSpace(para.StareDate) || string.IsNullOrWhiteSpace(para.EndDate))
                {
                    throw new APIException("日期区间参数为NULL!")
                          {
                              ErrorCode = ERROR_CODES.INVALID_BUSINESS
                          }
                }
                ;

                //判断区间小于等于7天,开始日期和结束日期都算一天
                DateTime d1 = Convert.ToDateTime(para.StareDate).Date;
                DateTime d2 = Convert.ToDateTime(para.StareDate).Date;
                Days = (d2 - d1).Days;//天数差
                Days++;
                if (Days > 7)
                {
                    throw new APIException("查询天数大于7天!")
                          {
                              ErrorCode = ERROR_CODES.INVALID_BUSINESS
                          }
                }
                ;
            }
            catch (APIException apiEx)
            {
                throw new APIException(apiEx.ErrorCode, apiEx.Message);
            }

            DateTime m_StareDate = Convert.ToDateTime(para.StareDate).Date;
            DateTime m_EndDate   = Convert.ToDateTime(para.EndDate).Date;

            rd = VipCardBLL.GetDayReconciliation(m_StareDate, m_EndDate, para.UnitID, loggingSessionInfo.ClientID);
            if (rd == null)
            {
                rd = new DayReconciliationRD();
            }
            return(rd);
        }
        /// <summary>
        /// 导出卡号
        /// </summary>
        /// <param name="pRequest"></param>
        public void ExportVipCardCode(string pRequest)
        {
            var rp = pRequest.DeserializeJSONTo <APIRequest <ExportVipCardCodeRP> >();

            if (!string.IsNullOrWhiteSpace(rp.Parameters.BatchNo))
            {
                var si = new SessionManager().CurrentUserLoginInfo;
                if (null == si)
                {
                    si = Default.GetBSLoggingSession(rp.CustomerID, rp.UserID);
                }
                var VipCardBLL = new VipCardBLL(si);
                var ds         = VipCardBLL.ExportVipCardCode(rp.Parameters.BatchNo);
                var columns    = new Dictionary <string, string>();
                columns.Add("VipCardCode", "卡号");
                ExportVipInfo(columns, ds.Tables[0], "导出卡号");
            }
        }
        /// <summary>
        /// 卡注销
        /// </summary>
        public string SaveVipCardChangeLevelData()
        {
            var    vipCardGradeChangeLogBLL = new VipCardGradeChangeLogBLL(CurrentUserInfo);
            var    vipCardBLL = new VipCardBLL(CurrentUserInfo);
            string content    = string.Empty;
            var    data       = new VipRespData();

            string key = string.Empty;

            if (Request("vip") != null && Request("vip") != string.Empty)
            {
                key = Request("vip").ToString().Trim();
            }

            var entity = key.DeserializeJSONTo <VipCardChangeLevelQueryEntity>();

            if (entity.VipCardID == null || entity.VipCardID.Trim().Length == 0)
            {
                data.success     = false;
                data.Description = "卡标识不能为空";
                return(data.ToJSON());
            }
            if (entity.NowGradeID == null || entity.NowGradeID.Trim().Length == 0)
            {
                data.success     = false;
                data.Description = "等级不能为空";
                return(data.ToJSON());
            }

            string error  = string.Empty;
            var    result = vipCardGradeChangeLogBLL.SetVipCardGradeChange(
                entity.VipCardID, int.Parse(entity.ChangeBeforeGradeID), int.Parse(entity.NowGradeID),
                entity.ChangeReason, entity.UnitID, out error);

            if (!result)
            {
                data.success     = false;
                data.Description = "错误:" + error;
                return(data.ToJSON());
            }

            content = data.ToJSON();
            return(content);
        }
        protected override GetVipCardTypeListRD ProcessRequest(DTO.Base.APIRequest <GetVipCardTypeListRP> pRequest)
        {
            GetVipCardTypeListRP rp = pRequest.Parameters;
            GetVipCardTypeListRD rd = new GetVipCardTypeListRD();

            rd.VipCardTypeIdList = new List <VipCardTypeInfo>();


            VipCardBLL        vipCardBll        = new VipCardBLL(CurrentUserInfo);
            SysVipCardTypeBLL sysVipCardTypeBll = new SysVipCardTypeBLL(CurrentUserInfo);

            var vipCardInfo = vipCardBll.GetVipCardByVipMapping(rp.VipId);
            List <SysVipCardTypeEntity> sysVipCardTypeAllList = sysVipCardTypeBll.QueryByEntity(new SysVipCardTypeEntity()
            {
                CustomerID = CurrentUserInfo.ClientID
            }, null).ToList();

            if (sysVipCardTypeAllList != null && vipCardInfo != null)
            {
                SysVipCardTypeEntity sysVipCardTypeEntity = sysVipCardTypeBll.GetByID(vipCardInfo.VipCardTypeID);
                if (sysVipCardTypeEntity != null)
                {
                    List <SysVipCardTypeEntity> sysVipCardTypeList = sysVipCardTypeAllList.AsEnumerable().Where(t => t.VipCardLevel > sysVipCardTypeEntity.VipCardLevel).ToList();
                    if (sysVipCardTypeList != null)
                    {
                        foreach (var item in sysVipCardTypeList)
                        {
                            VipCardTypeInfo vipCardTypeInfo = new VipCardTypeInfo();
                            vipCardTypeInfo.VipCardTypeId   = item.VipCardTypeID.ToString();
                            vipCardTypeInfo.VipCardTypeName = item.VipCardTypeName.ToString();

                            rd.VipCardTypeIdList.Add(vipCardTypeInfo);
                        }
                    }
                }
            }
            return(rd);
        }
        /// <summary>
        /// 根据会员卡ID获取会员卡信息
        /// </summary>
        public string GetVipCardByVipCardID()
        {
            var    service    = new VipCardBLL(CurrentUserInfo);
            var    searchInfo = new VipCardEntity();
            string content    = string.Empty;

            if (Request("VipCardID") != "")
            {
                searchInfo.VipCardID = FormatParamValue(Request("VipCardID"));
            }

            int maxRowCount   = PageSize;
            int startRowIndex = Utils.GetIntVal(FormatParamValue(Request("start")));

            searchInfo.maxRowCount   = maxRowCount;
            searchInfo.startRowIndex = startRowIndex;
            var data = service.SearchVipCard(searchInfo);

            content = string.Format("{{\"totalCount\":{1},\"topics\":{0}}}",
                                    data.VipCardInfoList.ToJSON(),
                                    data.ICount);
            return(content);
        }
        /// <summary>
        ///
        /// </summary>
        public string LockVipCardInfoData()
        {
            var    service = new VipCardBLL(CurrentUserInfo);
            var    vipCardStatusChangeLogBLL = new VipCardStatusChangeLogBLL(CurrentUserInfo);
            string content = string.Empty;

            string key = string.Empty;

            if (Request("VipCardID") != null && Request("VipCardID") != string.Empty)
            {
                key = Request("VipCardID").ToString().Trim();
            }

            string Lock = string.Empty;

            if (Request("Lock") != null && Request("Lock") != string.Empty)
            {
                Lock = Request("Lock").ToString().Trim();
            }
            string UnitID = string.Empty;

            if (Request("UnitID") != null && Request("UnitID") != string.Empty)
            {
                UnitID = Request("UnitID").ToString().Trim();
            }
            string VipCardStatusId = string.Empty;

            if (Request("VipCardStatusId") != null && Request("VipCardStatusId") != string.Empty)
            {
                VipCardStatusId = Request("VipCardStatusId").ToString().Trim();
            }

            VipCardEntity data            = service.GetByID(key);
            int?          vipCardStatusId = data.VipCardStatusId;

            if (Lock == "1")
            {
                vipCardStatusId = 5;
                if (VipCardStatusId.Length > 0)
                {
                    vipCardStatusId = int.Parse(VipCardStatusId);
                }
            }

            service.Update(new VipCardEntity()
            {
                VipCardID = key, VipCardStatusId = vipCardStatusId
            }, null);

            vipCardStatusChangeLogBLL.Create(new VipCardStatusChangeLogEntity()
            {
                LogID           = Utils.NewGuid(),
                VipCardID       = key,
                VipCardStatusID = vipCardStatusId,
                OldStatusID     = data.VipCardStatusId,
                UnitID          = UnitID
            });

            content = data.ToJSON();
            return(content);
        }
Exemple #16
0
        protected override SetRechargeOrderRD ProcessRequest(APIRequest <SetRechargeOrderRP> pRequest)
        {
            SetRechargeOrderRP rp = pRequest.Parameters;
            SetRechargeOrderRD rd = new SetRechargeOrderRD();

            var            rechargeOrderBll     = new RechargeOrderBLL(CurrentUserInfo);
            TUnitExpandBLL serviceUnitExpandBll = new TUnitExpandBLL(CurrentUserInfo);

            var vipBll = new VipBLL(CurrentUserInfo);
            var vipCardVipMappingBll  = new VipCardVipMappingBLL(CurrentUserInfo);
            var vipCardBll            = new VipCardBLL(CurrentUserInfo);
            var sysVipCardTypeBll     = new SysVipCardTypeBLL(CurrentUserInfo);
            var vipCardUpgradeRuleBll = new VipCardUpgradeRuleBLL(CurrentUserInfo);

            //获取会员信息
            VipEntity vipInfo;
            string    userId = "";

            //微信
            if (pRequest.ChannelId == "2")
            {
                vipInfo = vipBll.GetByID(pRequest.UserID);
                UnitService unitServer = new UnitService(CurrentUserInfo);
                rp.UnitId = unitServer.GetUnitByUnitTypeForWX("OnlineShopping", null).Id; //获取在线商城的门店标识
            }
            //掌柜App
            else
            {
                vipInfo = vipBll.GetByID(rp.VipId);
                userId  = pRequest.UserID;
            }

            string  OrderDesc     = "ReRecharge"; //"升级","充值"
            int?    VipCardTypeId = null;         //会员卡类型
            decimal returnAmount  = 0;            //赠送金额

            //会员卡类型条件
            List <IWhereCondition> complexConditionOne = new List <IWhereCondition> {
            };
            //获取会员与会员卡关系表
            var vipCardVipMappingEntity = vipCardVipMappingBll.QueryByEntity(new VipCardVipMappingEntity()
            {
                CustomerID = CurrentUserInfo.ClientID, VIPID = vipInfo.VIPID
            }, null).FirstOrDefault();

            //该会员有会员卡
            if (vipCardVipMappingEntity != null)
            {
                //获取该会员会员卡信息
                var vipCardEntity = vipCardBll.QueryByEntity(new VipCardEntity()
                {
                    CustomerID = CurrentUserInfo.ClientID, VipCardID = vipCardVipMappingEntity.VipCardID
                }, null).FirstOrDefault();

                //获取该会员卡类型
                var sysVipCardTypeEntity = sysVipCardTypeBll.GetByID(vipCardEntity.VipCardTypeID);
                VipCardTypeId = vipCardEntity.VipCardTypeID;

                //获取会员卡的会员活动
                var rechargeStrategyBLL = new RechargeStrategyBLL(CurrentUserInfo);
                var RechargeActivityDS  = rechargeStrategyBLL.GetRechargeActivityList(CurrentUserInfo.ClientID, VipCardTypeId.ToString(), 3);
                var RechargeStrategy    = new RechargeStrategyInfo();

                if (RechargeActivityDS != null && RechargeActivityDS.Tables[0].Rows.Count > 0)
                {
                    var RechargeStrategyList = DataTableToObject.ConvertToList <RechargeStrategyInfo>(RechargeActivityDS.Tables[0]);
                    //获取与充值金额最接近的活动
                    RechargeStrategy = RechargeStrategyList.Where(n => n.RechargeAmount <= rp.ActuallyPaid).OrderByDescending(n => n.RechargeAmount).FirstOrDefault();
                    if (RechargeStrategy != null)
                    {
                        //梯度
                        if (RechargeStrategy.RuleType == "Step")
                        {
                            //赠送金额 = 会员活动梯度设置赠送金额
                            returnAmount = RechargeStrategy.GiftAmount;
                        }
                        //叠加
                        if (RechargeStrategy.RuleType == "Superposition")
                        {
                            //赠送金额与满赠条件金额比例
                            decimal discount = RechargeStrategy.GiftAmount / RechargeStrategy.RechargeAmount;
                            //赠送金额 = 充值金额 * (设置赠送金额 / 设置满赠条件金额)
                            returnAmount = rp.ActuallyPaid * RechargeStrategy.GiftAmount / RechargeStrategy.RechargeAmount;
                        }
                    }
                }

                //获取等级高的会员卡类型条件
                complexConditionOne.Add(new MoreThanCondition()
                {
                    FieldName = "VipCardLevel", Value = sysVipCardTypeEntity.VipCardLevel, IncludeEquals = false
                });
                complexConditionOne.Add(new EqualsCondition()
                {
                    FieldName = "CustomerID", Value = CurrentUserInfo.ClientID
                });
            }
            //该会员没有会员卡
            else
            {
                //获取所有的会员卡类型条件
                complexConditionOne.Add(new EqualsCondition()
                {
                    FieldName = "CustomerID", Value = CurrentUserInfo.ClientID
                });
            }

            var sysVipCardTypeList = sysVipCardTypeBll.Query(complexConditionOne.ToArray(), null).ToList();

            if (sysVipCardTypeList == null)
            {
                throw new APIException("没有建立会员体系")
                      {
                          ErrorCode = 200
                      };
            }

            //获取会员卡类型升级规则
            List <IWhereCondition> complexConditionTwo = new List <IWhereCondition> {
            };

            complexConditionTwo.Add(new EqualsCondition()
            {
                FieldName = "CustomerID", Value = CurrentUserInfo.ClientID
            });
            complexConditionTwo.Add(new EqualsCondition()
            {
                FieldName = "IsRecharge", Value = 1
            });
            var vipCardUpgradeRuleList = vipCardUpgradeRuleBll.Query(complexConditionTwo.ToArray(), null);

            //将升级卡规则和可升级的会员卡匹配
            var vipCardTypeDetailList = vipCardUpgradeRuleList.Join(sysVipCardTypeList, n => n.VipCardTypeID, m => m.VipCardTypeID, (n, m) => new { n, m }).OrderByDescending(t => t.m.VipCardLevel).ToList();

            //判断是否满充值条件
            bool isUpgrade = false;


            for (int i = 0; i < vipCardTypeDetailList.Count; i++)
            {
                //实付金额 >= 可升级金额
                if (vipCardTypeDetailList[i].n.OnceRechargeAmount <= rp.ActuallyPaid)
                {
                    isUpgrade     = true;
                    VipCardTypeId = vipCardTypeDetailList[i].n.VipCardTypeID ?? 0;
                    break;
                }
            }
            if (isUpgrade)
            {
                OrderDesc = "Upgrade";  //升级
            }


            //充值订单
            var rechargeOrderEntity = new RechargeOrderEntity()
            {
                OrderID       = Guid.NewGuid(),
                OrderNo       = serviceUnitExpandBll.GetUnitOrderNo(),
                OrderDesc     = OrderDesc,
                VipID         = vipInfo.VIPID,
                VipCardNo     = vipInfo.VipCode,
                UnitId        = rp.UnitId,
                UserId        = userId,
                TotalAmount   = rp.ActuallyPaid,
                ActuallyPaid  = rp.ActuallyPaid,
                PosSourceName = rp.PosSourceName,
                ReturnAmount  = returnAmount,
                PayerID       = vipInfo.VIPID,
                Status        = 0,
                CustomerID    = CurrentUserInfo.ClientID,
                VipCardTypeId = VipCardTypeId
            };

            rechargeOrderBll.Create(rechargeOrderEntity);
            rd.orderId = rechargeOrderEntity.OrderID.ToString();

            //支付完成
            if (rp.PayStatus == 1)
            {
                //获取门店信息
                t_unitBLL    unitBLL  = new t_unitBLL(CurrentUserInfo);
                t_unitEntity unitInfo = null;
                if (!string.IsNullOrEmpty(rechargeOrderEntity.UnitId))
                {
                    unitInfo = unitBLL.GetByID(rechargeOrderEntity.UnitId);
                }
                //充值
                rechargeOrderBll.Recharge(rechargeOrderEntity, vipInfo, unitInfo, "");
            }

            return(rd);
        }
        //<summary>
        //Pos订单入库
        //</summary>
        //<param name="pRequest"></param>
        //<returns></returns>
        protected override SetPosOrderRD ProcessRequest(APIRequest <SetPosOrderRP> pRequest)
        {
            //请求参数
            var rp = pRequest.Parameters;
            //返回参数
            var rd = new SetPosOrderRD();

            //订单
            var inoutBll    = new T_InoutBLL(CurrentUserInfo);
            var inoutDetail = new T_Inout_DetailBLL(CurrentUserInfo);
            //商品
            var itemCategoryBll = new T_Item_CategoryBLL(CurrentUserInfo);
            var itemBll         = new T_ItemBLL(CurrentUserInfo);
            var porpBll         = new T_PropBLL(CurrentUserInfo);
            var itemSkuPropBll  = new T_ItemSkuPropBLL(CurrentUserInfo);
            var skuBll          = new T_SkuBLL(CurrentUserInfo);
            var skuPriceBll     = new T_Sku_PriceBLL(CurrentUserInfo);
            var skuProperty     = new T_Sku_PropertyBLL(CurrentUserInfo);
            //获取会员信息
            var vipBll  = new VipBLL(CurrentUserInfo);
            var vipInfo = vipBll.GetByID(pRequest.UserID);
            var vipCardVipMappingBll    = new VipCardVipMappingBLL(CurrentUserInfo);
            var vipCardBll              = new VipCardBLL(CurrentUserInfo);
            var vipCardVipMappingEntity = vipCardVipMappingBll.QueryByEntity(new VipCardVipMappingEntity()
            {
                VIPID = vipInfo.VIPID, CustomerID = CurrentUserInfo.ClientID
            }, null).FirstOrDefault();
            string VipCardTypeID = ""; //卡类型Id

            if (vipCardVipMappingEntity != null)
            {
                var vipCardEntity = vipCardBll.GetByID(vipCardVipMappingEntity.VipCardID);
                VipCardTypeID = vipCardEntity.VipCardTypeID.ToString();
            }
            //员工
            var userBll = new T_UserBLL(CurrentUserInfo);

            //获取门店信息
            var          unitBll  = new t_unitBLL(CurrentUserInfo);
            t_unitEntity unitInfo = null;

            if (!string.IsNullOrEmpty(rp.UnitCode))
            {
                unitInfo = unitBll.QueryByEntity(new t_unitEntity()
                {
                    unit_code = rp.UnitCode, customer_id = CurrentUserInfo.ClientID
                }, null).FirstOrDefault();
                if (unitInfo == null)
                {
                    throw new APIException("请在正念商户后台录入相应门店")
                          {
                              ErrorCode = 100
                          };
                }
            }
            else
            {
                throw new APIException("缺少请求参数:门店编码")
                      {
                          ErrorCode = 102
                      };
            }

            //获取员工信息
            T_UserEntity userEntity = null;

            if (!string.IsNullOrEmpty(rp.MobliePhone))
            {
                userEntity = userBll.QueryByEntity(new T_UserEntity()
                {
                    user_telephone = rp.MobliePhone, customer_id = CurrentUserInfo.ClientID
                }, null).FirstOrDefault();
                //没有员工,新增默认员工(店员APP)
                if (userEntity == null)
                {
                    var roleBll    = new T_RoleBLL(CurrentUserInfo);
                    var roleEntity = roleBll.QueryByEntity(new T_RoleEntity()
                    {
                        role_code = "clerkAPP", customer_id = CurrentUserInfo.ClientID
                    }, null).FirstOrDefault();
                    if (roleEntity == null)
                    {
                        throw new APIException("请在正念商户后台录入相应角色")
                              {
                                  ErrorCode = 100
                              };
                    }
                    userEntity = new T_UserEntity();
                    userEntity.user_telephone = rp.MobliePhone;
                    userEntity.user_code      = rp.UserCode;
                    userEntity.user_name      = rp.UserCode;
                    userEntity.user_birthday  = rp.Birthday;
                    userEntity.user_email     = rp.EmailAddress;
                    userEntity.user_address   = rp.Address;
                    userEntity.user_postcode  = rp.Zip;
                    userBll.AddUser(ref userEntity, unitInfo, roleEntity);
                }
            }
            else
            {
                throw new APIException("缺少请求参数:员工手机号")
                      {
                          ErrorCode = 102
                      };
            }
            //获取会员折扣
            var     sysVipCardGradeBLL = new SysVipCardGradeBLL(CurrentUserInfo);
            decimal vipDiscount        = sysVipCardGradeBLL.GetVipDiscount() * 10;


            //订单号
            string        orderId      = BaseService.NewGuidPub();
            T_InoutEntity tInoutEntity = new T_InoutEntity();

            tInoutEntity.order_id = orderId;
            tInoutEntity.order_no = rp.OrderNo;

            //拼接ItemCodes
            //StringBuilder ItemCodes = new StringBuilder();
            //for (int j = 0; j < pRequest.Parameters.OrderDetailList.Count(); j++)
            //{
            //    if (j != 0)
            //    {
            //        ItemCodes.Append(",");
            //    }
            //    ItemCodes.Append(string.Format("{0}", pRequest.Parameters.OrderDetailList[j].ItemCode));
            //}

            ////通过itemCodes取出商品价格
            //SkuPriceService skuPriceService = new SkuPriceService(CurrentUserInfo);
            //List<SkuPrice> skuPriceList = skuPriceService.GetPriceListByItemCodes(ItemCodes.ToString(), CurrentUserInfo.ClientID);
            //if(skuPriceList.Count == 0)
            //{
            //    throw new APIException("未找到商品") { ErrorCode = 100 };
            //}

            //订单总金额
            decimal totalAmount = rp.TotalAmount;
            //订单实付金额
            decimal ActualAmount = rp.DiscountAmount;
            //订单折扣后金额
            decimal DiscountAmount = rp.DiscountAmount;
            //订单明细显示顺序
            int i = 1;

            //商品价格重新计算
            foreach (var item in pRequest.Parameters.OrderDetailList)
            {
                T_ItemEntity itemEntity = null; //商品
                T_SkuEntity  skuEntity  = null; //sku
                if (!string.IsNullOrEmpty(item.ItemCode))
                {
                    itemEntity = itemBll.QueryByEntity(new T_ItemEntity()
                    {
                        item_code = item.ItemCode, CustomerId = CurrentUserInfo.ClientID
                    }, null).FirstOrDefault();
                    if (itemEntity == null)
                    {
                        if (string.IsNullOrEmpty(item.ItemCategoryCode))
                        {
                            throw new APIException("缺少参数:商品类别名称")
                                  {
                                      ErrorCode = 200
                                  };
                        }
                        itemEntity           = new T_ItemEntity();
                        itemEntity.item_code = item.ItemCode;
                        itemEntity.item_name = item.ItemName;

                        itemBll.AddItem(itemEntity, out skuEntity, item.ItemCategoryName, item.ItemCategoryCode, item.SkuOriginPrice, item.SkuSalesPrice);
                    }
                    else
                    {
                        skuEntity = skuBll.QueryByEntity(new T_SkuEntity()
                        {
                            item_id = itemEntity.item_id
                        }, null).FirstOrDefault();
                    }
                }
                else
                {
                    throw new APIException("缺少参数:商品编码")
                          {
                              ErrorCode = 300
                          };
                }

                //订单明细相关处理
                T_Inout_DetailBLL    inoutDetailBll    = new T_Inout_DetailBLL(CurrentUserInfo);
                T_Inout_DetailEntity inoutDetailEntity = new T_Inout_DetailEntity()
                {
                    order_detail_id     = BaseService.NewGuidPub(),
                    order_id            = orderId,               //订单Id
                    sku_id              = skuEntity.sku_id,      //skuId
                    unit_id             = unitInfo.unit_id,      //门店Id
                    order_qty           = item.Qty,              //订单qty
                    enter_qty           = item.Qty,              //实际qty
                    enter_price         = item.price,            //折扣价
                    enter_amount        = item.price * item.Qty, //折扣价
                    std_price           = item.price,            //原价
                    discount_rate       = vipDiscount,           //折扣
                    retail_price        = item.price * item.Qty, //零售价
                    retail_amount       = item.price * item.Qty, //零售价
                    order_detail_status = "1",
                    display_index       = i,
                    if_flag             = 0
                };
                inoutDetailBll.Create(inoutDetailEntity);
                i++;
            }

            //优惠券使用
            if (!string.IsNullOrEmpty(rp.CouponId))
            {
                #region 判断优惠券是否是该会员的

                var vipcouponMappingBll = new VipCouponMappingBLL(CurrentUserInfo);

                var vipcouponmappingList = vipcouponMappingBll.QueryByEntity(new VipCouponMappingEntity()
                {
                    VIPID    = pRequest.UserID,
                    CouponID = rp.CouponId
                }, null);

                if (vipcouponmappingList == null || vipcouponmappingList.Length == 0)
                {
                    throw new APIException("此张优惠券不是该会员的")
                          {
                              ErrorCode = 103
                          };
                }

                #endregion

                #region 判断优惠券是否有效

                var couponBll = new CouponBLL(CurrentUserInfo);

                var couponEntity = couponBll.GetByID(rp.CouponId);

                if (couponEntity == null)
                {
                    throw new APIException("无效的优惠券")
                          {
                              ErrorCode = 103
                          };
                }

                if (couponEntity.Status == 1)
                {
                    throw new APIException("优惠券已使用")
                          {
                              ErrorCode = 103
                          };
                }

                if (couponEntity.EndDate < DateTime.Now)
                {
                    throw new APIException("优惠券已过期")
                          {
                              ErrorCode = 103
                          };
                }
                var couponTypeBll    = new CouponTypeBLL(CurrentUserInfo);
                var couponTypeEntity = couponTypeBll.GetByID(couponEntity.CouponTypeID);

                if (couponTypeEntity == null)
                {
                    throw new APIException("无效的优惠券类型")
                          {
                              ErrorCode = 103
                          };
                }

                #endregion

                #region 优惠券核销
                var couponUseBll    = new CouponUseBLL(CurrentUserInfo);
                var couponUseEntity = new CouponUseEntity()
                {
                    CouponUseID    = Guid.NewGuid(),
                    CouponID       = rp.CouponId,
                    VipID          = pRequest.UserID,
                    UnitID         = unitInfo.unit_id,
                    OrderID        = orderId,
                    Comment        = "商城使用电子券",
                    CustomerID     = pRequest.CustomerID,
                    CreateBy       = pRequest.UserID,
                    CreateTime     = DateTime.Now,
                    LastUpdateBy   = pRequest.UserID,
                    LastUpdateTime = DateTime.Now,
                    IsDelete       = 0
                };
                couponUseBll.Create(couponUseEntity);
                #endregion

                #region 更新CouponType数量
                var conponTypeBll    = new CouponTypeBLL(CurrentUserInfo);
                var conponTypeEntity = conponTypeBll.QueryByEntity(new CouponTypeEntity()
                {
                    CouponTypeID = new Guid(couponEntity.CouponTypeID), CustomerId = pRequest.CustomerID
                }, null).FirstOrDefault();
                conponTypeEntity.IsVoucher += 1;
                conponTypeBll.Update(conponTypeEntity);

                #endregion

                #region 更新优惠券状态

                couponEntity.Status = 1;
                couponBll.Update(couponEntity);

                #endregion

                ActualAmount -= couponTypeEntity.ParValue ?? 0;
            }

            #region 使用积分
            //使用积分
            if (rp.IntegralFlag == 1)
            {
                var vipIntegralBll = new VipIntegralBLL(CurrentUserInfo);

                string sourceId       = "20"; //积分抵扣
                var    IntegralDetail = new VipIntegralDetailEntity()
                {
                    Integral         = -Convert.ToInt32(rp.Integral),
                    IntegralSourceID = sourceId,
                    ObjectId         = orderId
                };
                if (IntegralDetail.Integral != 0)
                {
                    //变动前积分
                    string OldIntegral = (vipInfo.Integration ?? 0).ToString();
                    //变动积分
                    string ChangeIntegral      = (IntegralDetail.Integral ?? 0).ToString();
                    var    vipIntegralDetailId = vipIntegralBll.AddIntegral(ref vipInfo, unitInfo, IntegralDetail, CurrentUserInfo);
                    //发送微信积分变动通知模板消息
                    if (!string.IsNullOrWhiteSpace(vipIntegralDetailId))
                    {
                        var CommonBLL = new CommonBLL();
                        CommonBLL.PointsChangeMessage(OldIntegral, vipInfo, ChangeIntegral, vipInfo.WeiXinUserId, CurrentUserInfo);
                    }
                }
                tInoutEntity.pay_points     = rp.Integral;
                tInoutEntity.receive_points = rp.Integral;
                ActualAmount -= rp.IntegralAmount;
            }
            #endregion

            #region 余额和返现修改

            var vipAmountBll       = new VipAmountBLL(CurrentUserInfo);
            var vipAmountDetailBll = new VipAmountDetailBLL(CurrentUserInfo);

            var vipAmountEntity = vipAmountBll.QueryByEntity(new VipAmountEntity()
            {
                VipId = pRequest.UserID, VipCardCode = vipInfo.VipCode
            }, null).FirstOrDefault();
            if (vipAmountEntity != null)
            {
                //判断该会员账户是否被冻结
                if (vipAmountEntity.IsLocking == 1)
                {
                    throw new APIException("账户已被冻结,请先解冻")
                          {
                              ErrorCode = 103
                          }
                }
                ;

                //判断该会员的账户余额是否大于本次使用的余额
                if (vipAmountEntity.EndAmount < rp.EndAmount)
                {
                    throw new APIException(string.Format("账户余额不足,当前余额为【{0}】", vipAmountEntity.EndAmount))
                          {
                              ErrorCode = 103
                          }
                }
                ;
            }

            //使用余额
            if (rp.EndAmountFlag == 1)
            {
                var detailInfo = new VipAmountDetailEntity()
                {
                    Amount         = -rp.EndAmount,
                    AmountSourceId = "1",
                    ObjectId       = orderId
                };
                var vipAmountDetailId = vipAmountBll.AddVipAmount(vipInfo, unitInfo, ref vipAmountEntity, detailInfo, CurrentUserInfo);
                if (!string.IsNullOrWhiteSpace(vipAmountDetailId))
                {//发送微信账户余额变动模板消息
                    var CommonBLL = new CommonBLL();
                    CommonBLL.BalanceChangedMessage(tInoutEntity.order_no, vipAmountEntity, detailInfo, vipInfo.WeiXinUserId, vipInfo.VIPID, CurrentUserInfo);
                }
                tInoutEntity.Field3 = rp.EndAmount.ToString();
            }

            #endregion
            //订单主表更新
            tInoutEntity.VipCardCode      = vipInfo.VipCardCode;//会员卡号
            tInoutEntity.order_reason_id  = "2F6891A2194A4BBAB6F17B4C99A6C6F5";
            tInoutEntity.order_type_id    = "1F0A100C42484454BAEA211D4C14B80F";
            tInoutEntity.warehouse_id     = "67bb4c12785c42d4912aff7d34606592";
            tInoutEntity.data_from_id     = "";
            tInoutEntity.red_flag         = "1";
            tInoutEntity.order_date       = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //订单时间
            tInoutEntity.create_unit_id   = unitInfo.unit_id;                             //门店
            tInoutEntity.unit_id          = unitInfo.unit_id;                             //门店
            tInoutEntity.sales_unit_id    = unitInfo.unit_id;                             //门店
            tInoutEntity.purchase_unit_id = unitInfo.unit_id;
            tInoutEntity.sales_user       = userEntity.user_id;
            tInoutEntity.total_amount     = totalAmount;  //订单金额
            tInoutEntity.discount_rate    = vipDiscount;  //会员折扣
            tInoutEntity.actual_amount    = ActualAmount; //实付金额
            tInoutEntity.total_qty        = rp.qty;
            tInoutEntity.total_retail     = totalAmount;  //订单金额
            tInoutEntity.vip_no           = vipInfo.VIPID;
            tInoutEntity.Field6           = vipInfo.Phone;
            tInoutEntity.Field14          = vipInfo.VipName;
            tInoutEntity.Field17          = VipCardTypeID;
            tInoutEntity.Field12          = DiscountAmount.ToString();
            tInoutEntity.Field11          = "知行易";
            tInoutEntity.customer_id      = CurrentUserInfo.ClientID;

            tInoutEntity.Field1      = "1";   //支付完成
            tInoutEntity.Field7      = "700"; //已完成
            tInoutEntity.status      = "700"; //已完成
            tInoutEntity.status_desc = "已完成";
            tInoutEntity.Field10     = "已完成";
            rd.Amount = ActualAmount - rp.EndAmount;

            inoutBll.Create(tInoutEntity);

            //订单奖励
            new SendOrderRewardMsgBLL().OrderReward(tInoutEntity, this.CurrentUserInfo, null);//存入到缓存
            rd.orderId = orderId;
            return(rd);
        }
    }
}
Exemple #18
0
        protected override GetRechargeActivityListRD ProcessRequest(DTO.Base.APIRequest <GetRechargeActivityListRP> pRequest)
        {
            var rd   = new GetRechargeActivityListRD();
            var para = pRequest.Parameters;
            LoggingSessionInfo loggingSessionInfo = Default.GetBSLoggingSession(pRequest.CustomerID, pRequest.UserID);
            var vipBLL               = new VipBLL(loggingSessionInfo);
            var vipIntegralBLL       = new VipIntegralBLL(loggingSessionInfo);
            var sysVipCardTypeBLL    = new SysVipCardTypeBLL(loggingSessionInfo);
            var vipCardVipMappingBLL = new VipCardVipMappingBLL(loggingSessionInfo);
            var vipCardBLL           = new VipCardBLL(loggingSessionInfo);
            var vipCardRuleBLL       = new VipCardRuleBLL(loggingSessionInfo);
            var vipAmountBLL         = new VipAmountBLL(loggingSessionInfo);
            //获取当前会员卡等级
            VipEntity VipInfo         = null;
            int?      CurVipCardLevel = 0;

            VipInfo = vipBLL.GetByID(para.VipID);
            if (VipInfo != null)
            {
                rd.HeadImgUrl = VipInfo.HeadImgUrl == null ? "" : VipInfo.HeadImgUrl;
                rd.VipName    = VipInfo.VipName != null ? VipInfo.VipName : VipInfo.VipRealName != null ? VipInfo.VipRealName : "";
                //获取当前会员积分信息
                //var vipIntegralInfo = vipIntegralBLL.QueryByEntity(new VipIntegralEntity() { VipID = para.VipID, VipCardCode = VipInfo.VipCode }, null).FirstOrDefault();
                //if (vipIntegralInfo != null)
                //{
                //    rd.Integration = vipIntegralInfo.ValidIntegral != null ? vipIntegralInfo.ValidIntegral.Value : 0;
                //}
                //获取当前会员余额信息
                var vipAmountInfo = vipAmountBLL.QueryByEntity(new VipAmountEntity()
                {
                    VipId = para.VipID, VipCardCode = VipInfo.VipCode
                }, null).FirstOrDefault();
                if (vipAmountInfo != null)
                {
                    rd.VipAmount = vipAmountInfo.EndAmount != null ? vipAmountInfo.EndAmount : 0;
                }
                else
                {
                    rd.VipAmount = 0;
                }
                //获取当前关联信息
                var vipCardMappingInfo = vipCardVipMappingBLL.QueryByEntity(new VipCardVipMappingEntity()
                {
                    VIPID = para.VipID, CustomerID = loggingSessionInfo.ClientID
                },
                                                                            new OrderBy[] { new OrderBy()
                                                                                            {
                                                                                                FieldName = "CreateTime", Direction = OrderByDirections.Desc
                                                                                            } }).FirstOrDefault();
                if (vipCardMappingInfo != null)
                {
                    //获取卡等级主标识信息
                    var vipCardInfo = vipCardBLL.QueryByEntity(new VipCardEntity()
                    {
                        VipCardID = vipCardMappingInfo.VipCardID, VipCardStatusId = 1
                    }, null).FirstOrDefault();
                    if (vipCardInfo != null)
                    {
                        //获取卡等级信息
                        var vipCardTypeInfo = sysVipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity()
                        {
                            VipCardTypeID = vipCardInfo.VipCardTypeID
                        }, null).FirstOrDefault();
                        if (vipCardTypeInfo != null)
                        {
                            rd.VipCardTypeName = vipCardTypeInfo.VipCardTypeName != null ? vipCardTypeInfo.VipCardTypeName : "";
                            CurVipCardLevel    = vipCardTypeInfo.VipCardLevel;
                        }
                        //获取充值活动列表
                        var rechargeStrategyBLL  = new RechargeStrategyBLL(loggingSessionInfo);
                        var RechargeActivityInfo = rechargeStrategyBLL.GetRechargeActivityList(loggingSessionInfo.ClientID, vipCardInfo.VipCardTypeID.ToString(), 3);
                        if (RechargeActivityInfo != null && RechargeActivityInfo.Tables[0].Rows.Count > 0)
                        {
                            rd.RechargeStrategyList = DataTableToObject.ConvertToList <RechargeStrategyInfo>(RechargeActivityInfo.Tables[0]);
                        }
                    }
                }
            }
            return(rd);
        }
        protected override GetVipCardTypeVirtualItemRD ProcessRequest(DTO.Base.APIRequest <GetVipCardTypeVirtualItemRP> pRequest)
        {
            var rd   = new GetVipCardTypeVirtualItemRD();
            var para = pRequest.Parameters;
            LoggingSessionInfo loggingSessionInfo = Default.GetBSLoggingSession(pRequest.CustomerID, pRequest.UserID);
            var vipBLL               = new VipBLL(loggingSessionInfo);
            var vipIntegralBLL       = new VipIntegralBLL(loggingSessionInfo);
            var sysVipCardTypeBLL    = new SysVipCardTypeBLL(loggingSessionInfo);
            var vipCardVipMappingBLL = new VipCardVipMappingBLL(loggingSessionInfo);
            var vipCardBLL           = new VipCardBLL(loggingSessionInfo);
            var vipCardRuleBLL       = new VipCardRuleBLL(loggingSessionInfo);
            var vipT_InoutBLL        = new T_InoutBLL(loggingSessionInfo);
            List <VipCardUpgradeRewardInfo> VipCardUpgradeRewardList = new List <VipCardUpgradeRewardInfo>();
            List <VipCardTypeRelateInfo>    VipCardTypeRelateList    = new List <VipCardTypeRelateInfo>();
            //获取当前会员卡等级
            VipEntity VipInfo         = null;
            int?      CurVipCardLevel = 0;
            //处理会员开卡礼信息
            var VipCardUpgradeRewardInfoList = sysVipCardTypeBLL.GetCardUpgradeRewardList(loggingSessionInfo.ClientID);
            //定义卡体系信息
            DataSet VipCardTypeSystemInfoList = null;
            string  strVipID = string.Empty;

            switch (para.ApplicationType)
            {
            //为1是微信,为2时表示APP请求
            case "1":    //微信
                strVipID = pRequest.UserID;
                break;

            case "2":                  //APP
                strVipID = para.VipID; //获取会员信息
                break;
            }

            VipInfo = vipBLL.GetByID(strVipID);//获取会员信息
            if (VipInfo != null)
            {
                rd.HeadImgUrl = VipInfo.HeadImgUrl == null ? "" : VipInfo.HeadImgUrl;
                var vipIntegralInfo = vipIntegralBLL.QueryByEntity(new VipIntegralEntity()
                {
                    VipID = strVipID, VipCardCode = VipInfo.VipCode
                }, null).FirstOrDefault();
                if (vipIntegralInfo != null)//获取当前会员积分
                {
                    rd.Integration = vipIntegralInfo.ValidIntegral != null ? vipIntegralInfo.ValidIntegral.Value : 0;
                }
                //获取会员卡等级相关信息
                var vipCardMappingInfo = vipCardVipMappingBLL.QueryByEntity(new VipCardVipMappingEntity()
                {
                    VIPID = strVipID, CustomerID = loggingSessionInfo.ClientID
                },
                                                                            new OrderBy[] { new OrderBy()
                                                                                            {
                                                                                                FieldName = "CreateTime", Direction = OrderByDirections.Desc
                                                                                            } }).FirstOrDefault();
                if (vipCardMappingInfo != null)
                {
                    var vipCardInfo = vipCardBLL.QueryByEntity(new VipCardEntity()
                    {
                        VipCardID = vipCardMappingInfo.VipCardID, VipCardStatusId = 1
                    }, null).FirstOrDefault();
                    if (vipCardInfo != null)
                    {
                        var vipCardTypeInfo = sysVipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity()
                        {
                            VipCardTypeID = vipCardInfo.VipCardTypeID
                        }, null).FirstOrDefault();
                        if (vipCardTypeInfo != null)//获取当前会员卡等级信息
                        {
                            rd.VipCardTypeName = vipCardTypeInfo.VipCardTypeName != null ? vipCardTypeInfo.VipCardTypeName : "";
                            rd.VipCardLevel    = vipCardTypeInfo.VipCardLevel;
                            CurVipCardLevel    = vipCardTypeInfo.VipCardLevel;
                        }
                    }
                }
                else
                {
                    var vipCardTypeInfo = sysVipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity()
                    {
                        VipCardLevel = 1, CustomerID = loggingSessionInfo.ClientID
                    }, null).FirstOrDefault();
                    if (vipCardTypeInfo != null)
                    {
                        rd.VipCardTypeName = vipCardTypeInfo.VipCardTypeName != null ? vipCardTypeInfo.VipCardTypeName : "";
                        rd.VipCardLevel    = vipCardTypeInfo.VipCardLevel != null ? vipCardTypeInfo.VipCardLevel : 1;
                        CurVipCardLevel    = vipCardTypeInfo.VipCardLevel != null ? vipCardTypeInfo.VipCardLevel : 1;
                    }
                }
                //获取会员消费金额
                decimal VipConsumptionInfo = vipT_InoutBLL.GetVipSumAmount(strVipID);
                if (VipConsumptionInfo > 0)
                {
                    rd.VipConsumptionAmount = Convert.ToDecimal(VipConsumptionInfo).ToString("0.00");
                }
                else
                {
                    rd.VipConsumptionAmount = "0";
                }
                //获取卡等级相关信息(会员卡等级信息、升级条件、基本权益关联虚拟商品)
                VipCardTypeSystemInfoList = sysVipCardTypeBLL.GetVipCardTypeVirtualItemList(loggingSessionInfo.ClientID, CurVipCardLevel, para.ApplicationType, VipInfo.VIPID);
            }


            if (VipCardTypeSystemInfoList != null && VipCardTypeSystemInfoList.Tables[0].Rows.Count > 0)
            {
                int flag = 0;//定义下面开卡礼能否进行展示(0=不进,1=进)
                if (VipCardUpgradeRewardInfoList != null && VipCardUpgradeRewardInfoList.Tables[0].Rows.Count > 0)
                {
                    flag = 1;
                    //获取开卡礼信息 为之后筛选数据使用
                    VipCardUpgradeRewardList = DataTableToObject.ConvertToList <VipCardUpgradeRewardInfo>(VipCardUpgradeRewardInfoList.Tables[0]);
                }
                var dt = VipCardTypeSystemInfoList.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    var DataInfo = new VipCardTypeRelateInfo();
                    //VipCardTypeRelateList = new List<VipCardTypeRelateInfo>();
                    DataInfo.VipCardType              = new VipCardTypeInfo();        //会员卡体系
                    DataInfo.VipCardUpgradeRule       = new VipCardUpgradeRuleInfo(); //会员卡升级规则
                    DataInfo.VipCardRule              = new VipCardRuleInfo();        //会员卡基本体系
                    DataInfo.VipCardUpgradeRewardList = new List <VipCardUpgradeRewardInfo>();
                    //var VipCardTypeData = new VipCardTypeInfo();
                    //给会员卡等级赋值
                    DataInfo.VipCardType.VipCardTypeID   = Convert.ToInt32(dr["VipCardTypeID"]);
                    DataInfo.VipCardType.VipCardLevel    = Convert.ToInt32(dr["VipCardLevel"]);
                    DataInfo.VipCardType.VipCardTypeName = dr["VipCardTypeName"].ToString();
                    DataInfo.VipCardType.PicUrl          = dr["PicUrl"].ToString();
                    DataInfo.VipCardType.IsPrepaid       = Convert.ToInt32(dr["IsPrepaid"]);
                    DataInfo.VipCardType.IsOnlineSales   = Convert.ToInt32(dr["IsOnlineSales"]);
                    DataInfo.VipCardType.ItemID          = dr["ItemID"].ToString();
                    DataInfo.VipCardType.SkuID           = dr["SkuID"].ToString();
                    int cardStatus = 0;
                    //获取卡状态购买信息 0=没购买,1=已购买 pRequest.UserID
                    if (DataInfo.VipCardType.IsPrepaid != 1)//非可储值类型关联订单
                    {
                        cardStatus = vipT_InoutBLL.GetVirtualItemStatus(loggingSessionInfo.ClientID, strVipID, DataInfo.VipCardType.SkuID);
                    }
                    else//可储值类型关联充值订单
                    {
                        var RechargeOrderBll  = new RechargeOrderBLL(loggingSessionInfo);
                        var RechargeOrderInfo = RechargeOrderBll.QueryByEntity(new RechargeOrderEntity()
                        {
                            OrderDesc = "Upgrade", VipID = strVipID, VipCardTypeId = DataInfo.VipCardType.VipCardTypeID, Status = 1
                        }, null).FirstOrDefault();
                        if (RechargeOrderInfo != null)//如果为空需要在订单表里查找下记录
                        {
                            cardStatus = 1;
                        }
                        else
                        {
                            cardStatus = vipT_InoutBLL.GetVirtualItemStatus(loggingSessionInfo.ClientID, strVipID, DataInfo.VipCardType.SkuID);
                        }
                    }

                    DataInfo.VipCardType.Status = cardStatus;
                    //var VipCardUpgradeRuleData = new VipCardUpgradeRuleInfo();
                    DataInfo.VipCardUpgradeRule.VipCardTypeID        = Convert.ToInt32(dr["VipCardTypeID"]);
                    DataInfo.VipCardUpgradeRule.VipCardUpgradeRuleId = dr["VipCardUpgradeRuleId"].ToString();
                    DataInfo.VipCardUpgradeRule.IsPurchaseUpgrade    = Convert.ToInt32(dr["IsPurchaseUpgrade"]);
                    DataInfo.VipCardUpgradeRule.IsExtraMoney         = Convert.ToInt32(dr["IsExtraMoney"]);
                    DataInfo.VipCardUpgradeRule.Prices             = Convert.ToDecimal(dr["Prices"]);
                    DataInfo.VipCardUpgradeRule.ExchangeIntegral   = Convert.ToInt32(dr["ExchangeIntegral"]);
                    DataInfo.VipCardUpgradeRule.IsRecharge         = Convert.ToInt32(dr["IsRecharge"]);
                    DataInfo.VipCardUpgradeRule.OnceRechargeAmount = Convert.ToDecimal(dr["OnceRechargeAmount"]);
                    DataInfo.VipCardUpgradeRule.IsBuyUpgrade       = Convert.ToInt32(dr["IsBuyUpgrade"]);
                    DataInfo.VipCardUpgradeRule.BuyAmount          = Convert.ToDecimal(dr["BuyAmount"]);
                    DataInfo.VipCardUpgradeRule.OnceBuyAmount      = Convert.ToDecimal(dr["OnceBuyAmount"]);

                    //var VipCardRuleData = new VipCardUpgradeRuleInfo();
                    DataInfo.VipCardRule.VipCardTypeID        = Convert.ToInt32(dr["VipCardTypeID"]);
                    DataInfo.VipCardRule.RuleID               = Convert.ToInt32(dr["RuleID"]);
                    DataInfo.VipCardRule.CardDiscount         = Convert.ToDecimal(dr["CardDiscount"]);
                    DataInfo.VipCardRule.PaidGivePercetPoints = Convert.ToDecimal(dr["PaidGivePercetPoints"]);
                    DataInfo.VipCardRule.PaidGivePoints       = Convert.ToDecimal(dr["PaidGivePoints"]);
                    if (flag == 1)//当flag=1的时候进行开卡礼的展示
                    {
                        DataInfo.VipCardUpgradeRewardList = VipCardUpgradeRewardList.Where(m => m.VipCardTypeID == Convert.ToInt32(dr["VipCardTypeID"])).Select(
                            t => new VipCardUpgradeRewardInfo()
                        {
                            CardUpgradeRewardId = t.CardUpgradeRewardId,
                            VipCardTypeID       = t.VipCardTypeID,
                            CouponTypeID        = t.CouponTypeID,
                            CouponNum           = t.CouponNum,
                            CouponName          = t.CouponName,
                            ValidityPeriod      = t.BeginTime == null ? ("领取后" + (t.ServiceLife == 0 ? "1天内有效" : t.ServiceLife.ToString() + "天内有效")) : (t.BeginTime.Value.ToString("yyyy-MM-dd") + "至" + t.EndTime.Value.ToString("yyyy-MM-dd")),
                            BeginTime           = t.BeginTime,
                            EndTime             = t.EndTime,
                            BeginTimeDate       = t.BeginTime == null ? "" : t.BeginTime.Value.ToString("yyyy年MM月dd日"),
                            EndTimeDate         = t.EndTime == null ? "" : t.EndTime.Value.ToString("yyyy年MM月dd日"),
                            ServiceLife         = t.ServiceLife,
                            CouponDesc          = t.CouponDesc,
                            ParValue            = t.ParValue
                        }).ToList();
                    }
                    VipCardTypeRelateList.Add(DataInfo);
                }
                rd.VipCardTypeItemList = VipCardTypeRelateList;
            }
            return(rd);
        }
Exemple #20
0
        protected override GetVipIntegralInfoListRD ProcessRequest(DTO.Base.APIRequest <GetVipIntegralInfoListRP> pRequest)
        {
            LoggingSessionInfo loggingSessionInfo = Default.GetBSLoggingSession(pRequest.CustomerID, pRequest.UserID);
            SysVipCardTypeBLL  bll = new SysVipCardTypeBLL(loggingSessionInfo);
            VipCardRuleBLL     VipCardRuleService = new VipCardRuleBLL(loggingSessionInfo);
            var vipCardVipMappingBLL = new VipCardVipMappingBLL(loggingSessionInfo);
            var vipCardBLL           = new VipCardBLL(loggingSessionInfo);
            var vipCardTypeBLL       = new SysVipCardTypeBLL(loggingSessionInfo);
            var rd = new GetVipIntegralInfoListRD();

            string[] CustomerBaseSettingCode = new string[] { "IntegralAmountPer", "PointsRedeemLowestLimit", "PointsRedeemUpLimit", "PointsValidPeriod" };
            string[] CustomerBaseSettingDesc = new string[] { "积分抵扣比例", "账户积分累计满", "每单可使用积分上限", "积分有效期" };

            CustomerBasicSettingBLL CustomerBasicSettingService = new CustomerBasicSettingBLL(loggingSessionInfo);

            //循环获取积分信息
            for (int i = 0; i < CustomerBaseSettingCode.Length; i++)
            {
                var entity = CustomerBasicSettingService.QueryByEntity(new CustomerBasicSettingEntity()
                {
                    CustomerID = loggingSessionInfo.ClientID, IsDelete = 0, SettingCode = CustomerBaseSettingCode[i]
                }, null).FirstOrDefault();
                if (entity != null)
                {
                    rd.VipIntegralInfoList.Add(new VipIntegralInfo()
                    {
                        CustomerBaseSettingDesc = CustomerBaseSettingDesc[i], CustomerBaseSettingValue = entity.SettingValue
                    });
                }
                else
                {
                    rd.VipIntegralInfoList.Add(new VipIntegralInfo()
                    {
                        CustomerBaseSettingDesc = CustomerBaseSettingDesc[i], CustomerBaseSettingValue = "0"
                    });
                }
            }
            //获取会员 卡映射关系
            var vipCardMappingInfo = vipCardVipMappingBLL.QueryByEntity(new VipCardVipMappingEntity()
            {
                VIPID = pRequest.UserID, CustomerID = CurrentUserInfo.ClientID
            },
                                                                        new OrderBy[] { new OrderBy()
                                                                                        {
                                                                                            FieldName = "CreateTime", Direction = OrderByDirections.Desc
                                                                                        } }).FirstOrDefault();

            if (vipCardMappingInfo != null)
            {
                //获取卡信息
                var vipCardInfo = vipCardBLL.QueryByEntity(new VipCardEntity()
                {
                    VipCardID = vipCardMappingInfo.VipCardID, VipCardStatusId = 1
                }, null).FirstOrDefault();
                if (vipCardInfo != null)
                {
                    //获取会员卡信息
                    var vipCardTypeInfo = vipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity()
                    {
                        VipCardTypeID = vipCardInfo.VipCardTypeID
                    }, null).FirstOrDefault();
                    if (vipCardTypeInfo != null)
                    {
                        //获取卡升级规则信息
                        var cardrulemodel = VipCardRuleService.QueryByEntity(new VipCardRuleEntity()
                        {
                            VipCardTypeID = vipCardTypeInfo.VipCardTypeID
                        }, null).FirstOrDefault();
                        if (cardrulemodel != null)
                        {
                            if (cardrulemodel.PaidGivePoints > 0) //积分
                            {
                                rd.VipIntegralInfoList.Add(new VipIntegralInfo()
                                {
                                    CustomerBaseSettingDesc = "每消费" + Convert.ToInt32(cardrulemodel.PaidGivePoints) + "元返 1积分", CustomerBaseSettingValue = Convert.ToInt32(cardrulemodel.PaidGivePoints) + ""
                                });
                            }
                            if (cardrulemodel.PaidGivePercetPoints > 0) //积分比例
                            {
                                rd.VipIntegralInfoList.Add(new VipIntegralInfo()
                                {
                                    CustomerBaseSettingDesc = "消费返积分比例" + Convert.ToInt32(cardrulemodel.PaidGivePercetPoints) + "%", CustomerBaseSettingValue = Convert.ToInt32(cardrulemodel.PaidGivePercetPoints) + ""
                                });
                            }
                        }
                    }
                }
            }
            return(rd);
        }
Exemple #21
0
        protected override GetMemberInfoRD ProcessRequest(DTO.Base.APIRequest <GetMemberInfoRP> pRequest)
        {
            GetMemberInfoRD rd = new GetMemberInfoRD();

            rd.MemberInfo = new MemberInfo();
            var vipLoginBLL = new VipBLL(base.CurrentUserInfo);

            //如果有一个查询标识非空,就用查询标识查,发现没有会员就报错
            if (!string.IsNullOrEmpty(pRequest.Parameters.SearchFlag))
            {
                List <IWhereCondition> complexCondition = new List <IWhereCondition> {
                };
                complexCondition.Add(new EqualsCondition()
                {
                    FieldName = "ClientID", Value = CurrentUserInfo.ClientID
                });
                var cond1 = new LikeCondition()
                {
                    FieldName = "VipName", Value = "%" + pRequest.Parameters.SearchFlag + "%"
                };
                var cond2 = new LikeCondition()
                {
                    FieldName = "VipRealName", Value = "%" + pRequest.Parameters.SearchFlag + "%"
                };
                var com1 = new ComplexCondition()
                {
                    Left = cond1, Right = cond2, Operator = LogicalOperators.Or
                };

                var cond3 = new EqualsCondition()
                {
                    FieldName = "Phone", Value = pRequest.Parameters.SearchFlag
                };
                var com2 = new ComplexCondition()
                {
                    Left = com1, Right = cond3, Operator = LogicalOperators.Or
                };
                complexCondition.Add(com2);
                complexCondition.Add(new DirectCondition("(WeiXinUserId!='' Or WeiXinUserId IS NOT NULL)"));
                var tempVipList = vipLoginBLL.Query(complexCondition.ToArray(), null);
                if (tempVipList != null && tempVipList.Length != 0)
                {
                    pRequest.UserID = pRequest.Parameters.MemberID = tempVipList[0].VIPID;
                }
            }

            string m_MemberID = "";

            if (!string.IsNullOrWhiteSpace(pRequest.Parameters.OwnerVipID))
            {
                m_MemberID = string.IsNullOrWhiteSpace(pRequest.Parameters.OwnerVipID) ? pRequest.UserID : pRequest.Parameters.OwnerVipID;
            }
            else
            {
                m_MemberID = string.IsNullOrWhiteSpace(pRequest.Parameters.MemberID) ? pRequest.UserID : pRequest.Parameters.MemberID;
            }

            string UserID       = m_MemberID;
            var    VipLoginInfo = vipLoginBLL.GetByID(UserID);

            if (VipLoginInfo == null)
            {
                throw new APIException("用户不存在")
                      {
                          ErrorCode = 330
                      }
            }
            ;
            #region 20140909 kun.zou 发现状态为0,改为1
            if (VipLoginInfo.Status.HasValue && VipLoginInfo.Status == 0)
            {
                VipLoginInfo.Status = 1;
                vipLoginBLL.Update(VipLoginInfo, false);
                var log = new VipLogEntity()
                {
                    Action       = "更新",
                    ActionRemark = "vip状态为0的改为1.",
                    CreateBy     = UserID,
                    CreateTime   = DateTime.Now,
                    VipID        = VipLoginInfo.VIPID,
                    LogID        = Guid.NewGuid().ToString("N")
                };
                var logBll = new VipLogBLL(base.CurrentUserInfo);
                logBll.Create(log);
            }
            #endregion
            int couponCount = vipLoginBLL.GetVipCoupon(UserID);

            rd.MemberInfo.Mobile      = VipLoginInfo.Phone;      //手机号码
            rd.MemberInfo.Name        = VipLoginInfo.UserName;   //姓名
            rd.MemberInfo.VipID       = VipLoginInfo.VIPID;      //组标识
            rd.MemberInfo.VipName     = VipLoginInfo.VipName;    //会员名
            rd.MemberInfo.ImageUrl    = VipLoginInfo.HeadImgUrl; //会员头像  add by Henry 2014-12-5
            rd.MemberInfo.VipRealName = VipLoginInfo.VipRealName;
            rd.MemberInfo.VipNo       = VipLoginInfo.VipCode;
            rd.MemberInfo.IsDealer    = VipLoginInfo.Col48 != null?int.Parse(VipLoginInfo.Col48) : 0;

            //超级分销体系配置表 为判断是否存在分销体系使用
            var T_SuperRetailTraderConfigbll = new T_SuperRetailTraderConfigBLL(CurrentUserInfo);
            //获取分销体系信息
            var T_SuperRetailTraderConfigInfo = T_SuperRetailTraderConfigbll.QueryByEntity(new T_SuperRetailTraderConfigEntity()
            {
                IsDelete = 0, CustomerId = CurrentUserInfo.CurrentUser.customer_id
            }, null).FirstOrDefault();
            if (T_SuperRetailTraderConfigInfo != null)
            {
                rd.MemberInfo.CanBeSuperRetailTrader = 1;
            }
            else
            {
                rd.MemberInfo.CanBeSuperRetailTrader = 0;
            }
            rd.MemberInfo.SuperRetailTraderID = VipLoginInfo.Col26;
            //rd.MemberInfo.Integration = VipLoginInfo.Integration ?? 0;//会员积分

            #region 会员有效积分
            var vipIntegralBLL  = new VipIntegralBLL(CurrentUserInfo);
            var vipIntegralInfo = vipIntegralBLL.QueryByEntity(new VipIntegralEntity()
            {
                VipID = UserID, VipCardCode = VipLoginInfo.VipCode
            }, null).FirstOrDefault();
            if (vipIntegralInfo != null)
            {
                rd.MemberInfo.Integration = vipIntegralInfo.ValidIntegral != null ? vipIntegralInfo.ValidIntegral.Value : 0;
            }
            #endregion

            //会员等级
            //rd.MemberInfo.VipLevelName = string.IsNullOrEmpty(vipLoginBLL.GetVipLeave(UserID)) ? null : vipLoginBLL.GetVipLeave(UserID);
            #region 会员卡名称
            var                vipCardVipMappingBLL = new VipCardVipMappingBLL(CurrentUserInfo);
            var                vipCardBLL           = new VipCardBLL(CurrentUserInfo);
            var                vipCardTypeBLL       = new SysVipCardTypeBLL(CurrentUserInfo);
            var                vipCardRuleBLL       = new VipCardRuleBLL(CurrentUserInfo);
            var                vipT_InoutBLL        = new T_InoutBLL(CurrentUserInfo);
            VipAmountBLL       vipAmountBLL         = new VipAmountBLL(CurrentUserInfo);
            ShoppingCartBLL    service     = new ShoppingCartBLL(CurrentUserInfo);
            ShoppingCartEntity queryEntity = new ShoppingCartEntity();
            queryEntity.VipId = UserID;
            int totalQty = service.GetListQty(queryEntity);
            rd.MemberInfo.ShopCartCount = totalQty;
            //定义当前自定义等级
            int?CurVipLevel        = 0;
            var vipCardMappingInfo = vipCardVipMappingBLL.QueryByEntity(new VipCardVipMappingEntity()
            {
                VIPID = UserID, CustomerID = CurrentUserInfo.ClientID
            },
                                                                        new OrderBy[] { new OrderBy()
                                                                                        {
                                                                                            FieldName = "CreateTime", Direction = OrderByDirections.Desc
                                                                                        } }).FirstOrDefault();
            if (vipCardMappingInfo != null)
            {
                var vipCardInfo = vipCardBLL.QueryByEntity(new VipCardEntity()
                {
                    VipCardID = vipCardMappingInfo.VipCardID, VipCardStatusId = 1
                }, null).FirstOrDefault();
                if (vipCardInfo != null)
                {
                    var vipCardTypeInfo = vipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity()
                    {
                        VipCardTypeID = vipCardInfo.VipCardTypeID
                    }, null).FirstOrDefault();
                    if (vipCardTypeInfo != null)
                    {
                        rd.MemberInfo.VipLevelName     = vipCardTypeInfo.VipCardTypeName != null ? vipCardTypeInfo.VipCardTypeName : "";
                        rd.MemberInfo.CardTypeImageUrl = vipCardTypeInfo.PicUrl != null ? vipCardTypeInfo.PicUrl : "";
                        rd.MemberInfo.CardTypePrice    = vipCardTypeInfo.Prices != null ? vipCardTypeInfo.Prices.Value : 0;
                        rd.MemberInfo.IsExtraMoney     = vipCardTypeInfo.IsExtraMoney != null ? vipCardTypeInfo.IsExtraMoney : 0;
                        CurVipLevel             = vipCardTypeInfo.VipCardLevel;
                        rd.MemberInfo.IsPrepaid = vipCardTypeInfo.Isprepaid;
                        if (CurVipLevel > 1)
                        {
                            var VipCardTypeSysInfo = vipCardTypeBLL.GetBindVipCardTypeInfo(CurrentUserInfo.ClientID, VipLoginInfo.Phone, pRequest.UserID, CurVipLevel);
                            if (VipCardTypeSysInfo == null || VipCardTypeSysInfo.Tables[0].Rows.Count == 0)
                            {
                                rd.MemberInfo.IsNeedCard = 2;
                            }
                        }
                        else
                        {
                            rd.MemberInfo.IsNeedCard = 1;
                        }
                        //因为卡等级不能重复,知道当前等级后查找相应的下一级是否是自动升级(消费升级)
                        var NextVipCardTypeInfo = vipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity()
                        {
                            VipCardLevel = CurVipLevel + 1, CustomerID = CurrentUserInfo.ClientID
                        }, null).FirstOrDefault();
                        if (NextVipCardTypeInfo != null)
                        {
                            //获取当前会员的消费金额信息
                            decimal CurVipConsumptionAmount = 0;
                            decimal VipConsumptionInfo      = vipT_InoutBLL.GetVipSumAmount(UserID);
                            if (VipConsumptionInfo > 0)
                            {
                                CurVipConsumptionAmount = Convert.ToDecimal(Convert.ToDecimal(VipConsumptionInfo).ToString("0.00"));
                            }
                            //知道下一等级后要判断,升级条件是否是消费升级
                            //定义累积消费金额
                            decimal AccumulatedAmount      = 0;
                            var     vipCardTypeUpGradeInfo = vipCardTypeBLL.GetVipCardTypeUpGradeInfo(CurrentUserInfo.ClientID, CurVipLevel);
                            if (vipCardTypeUpGradeInfo != null && vipCardTypeUpGradeInfo.Tables[0].Rows.Count > 0)
                            {
                                //判断拉取的所有卡等级里的最近的一级满足条件即可返回提示所需的值
                                int flag = 0;
                                foreach (DataRow dr in vipCardTypeUpGradeInfo.Tables[0].Rows)
                                {
                                    AccumulatedAmount = Convert.ToDecimal(Convert.ToDecimal(dr["BuyAmount"].ToString()).ToString("0.00"));
                                    //获取消费升级还需多少钱
                                    if (AccumulatedAmount > CurVipConsumptionAmount && flag == 0)
                                    {
                                        flag = 1;
                                        rd.MemberInfo.UpGradeNeedMoney = AccumulatedAmount - CurVipConsumptionAmount;
                                        if (rd.MemberInfo.UpGradeNeedMoney > 0)
                                        {
                                            rd.MemberInfo.UpgradePrompt = "还需要消费" + rd.MemberInfo.UpGradeNeedMoney + "元可以升级啦,快点通知会员!";
                                        }
                                    }
                                }
                            }
                        }

                        var VipCardRuleInfo = vipCardRuleBLL.QueryByEntity(new VipCardRuleEntity()
                        {
                            CustomerID = CurrentUserInfo.ClientID, VipCardTypeID = vipCardTypeInfo.VipCardTypeID
                        }, null).FirstOrDefault();
                        if (VipCardRuleInfo != null)
                        {
                            rd.MemberInfo.CardDiscount = Convert.ToDecimal(Convert.ToDecimal((VipCardRuleInfo.CardDiscount / 10)).ToString("0.00"));
                        }
                    }
                }
            }
            else
            {
                //表示需要领卡,并展示等级为1的默认卡
                rd.MemberInfo.IsNeedCard = 0;
                var VipCardTypeData = vipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity()
                {
                    VipCardLevel = 1, CustomerID = CurrentUserInfo.ClientID
                }, null).FirstOrDefault();
                if (VipCardTypeData != null)
                {
                    rd.MemberInfo.CardTypeImageUrl = VipCardTypeData.PicUrl != null ? VipCardTypeData.PicUrl : "";
                }
            }
            //获取红利/// decimal[0]=总收入(红利) decimal[2]=支出余额 decimal[1]=总提现金额
            decimal[] array = vipAmountBLL.GetVipSumAmountByCondition(UserID, CurrentUserInfo.ClientID, true);
            if (array[0] != null)
            {
                rd.MemberInfo.ProfitAmount = array[0];
            }
            //是否有付费的会员卡
            List <IWhereCondition> freeCardCon = new List <IWhereCondition> {
            };
            freeCardCon.Add(new EqualsCondition()
            {
                FieldName = "CustomerID", Value = CurrentUserInfo.ClientID
            });
            freeCardCon.Add(new DirectCondition("Prices>0"));
            var freeCardTypeInfo = vipCardTypeBLL.Query(freeCardCon.ToArray(), null).FirstOrDefault();
            if (freeCardTypeInfo != null)
            {
                rd.MemberInfo.IsCostCardType = 1;
            }
            else
            {
                rd.MemberInfo.IsCostCardType = 0;
            }

            #endregion

            rd.MemberInfo.Status       = VipLoginInfo.Status.HasValue ? VipLoginInfo.Status.Value : 1;
            rd.MemberInfo.CouponsCount = couponCount;
            rd.MemberInfo.IsActivate   = (VipLoginInfo.IsActivate.HasValue && VipLoginInfo.IsActivate.Value == 1 ? true : false);
            var customerBasicSettingBll = new CustomerBasicSettingBLL(CurrentUserInfo);
            rd.MemberInfo.MemberBenefits = customerBasicSettingBll.GetMemberBenefits(pRequest.CustomerID);



            //获取标签信息
            TagsBLL TagsBLL = new TagsBLL(base.CurrentUserInfo);


            var dsIdentity = TagsBLL.GetVipTagsList("", UserID);//“车主标签”  传7
            if (dsIdentity != null && dsIdentity.Tables.Count > 0 && dsIdentity.Tables[0].Rows.Count > 0)
            {
                rd.IdentityTagsList = DataTableToObject.ConvertToList <TagsInfo>(dsIdentity.Tables[0]).ToArray(); //“年龄段”  传8
            }


            #region 获取注册表单的列明和值

            var vipEntity = vipLoginBLL.QueryByEntity(new VipEntity()
            {
                VIPID = UserID
            }, null);

            if (vipEntity == null || vipEntity.Length == 0)
            {
                return(rd);
            }
            else
            {
                var ds = vipLoginBLL.GetVipColumnInfo(CurrentUserInfo.ClientID, "online005");

                var vipDs = vipLoginBLL.GetVipInfo(UserID);

                if (ds.Tables[0].Rows.Count > 0)
                {
                    var temp = ds.Tables[0].AsEnumerable().Select(t => new MemberControlInfo()
                    {
                        ColumnName  = t["ColumnName"].ToString(),
                        ControlType = Convert.ToInt32(t["ControlType"]),
                        ColumnValue = vipDs.Tables[0].Rows[0][t["ColumnName"].ToString()].ToString(),
                        ColumnDesc  = t["columnDesc"].ToString()
                    });

                    rd.MemberControlList = temp.ToArray();
                }
            }

            //var vipamountBll = new VipAmountBLL(this.CurrentUserInfo);

            //var vipAmountEntity = vipamountBll.GetByID(UserID);


            var unitBll = new UnitBLL(this.CurrentUserInfo);
            //Hashtable htPara = new Hashtable();
            //htPara["MemberID"] = UserID;
            //htPara["CustomerID"] = CurrentUserInfo.ClientID;
            //htPara["PageIndex"] = 1;
            //htPara["PageSize"] = 10;
            //DataSet dsMyAccount = unitBll.GetMyAccount(htPara);

            //if (dsMyAccount.Tables[0].Rows.Count > 0)
            //{
            //    //rd.AccountList = DataTableToObject.ConvertToList<AccountInfo>(dsMyAccount.Tables[0]);
            //    //rd.MemberInfo.Balance = Convert.ToDecimal(dsMyAccount.Tables[0].Rows[0]["Total"].ToString());
            //    //rd.TotalPageCount = int.Parse(dsMyAccount.Tables[0].Rows[0]["PageCount"].ToString());

            //}
            //else
            //    rd.MemberInfo.Balance = 0;

            //返现 add by Henry 2015-4-15
            var vipAmountBll = new VipAmountBLL(CurrentUserInfo);
            //var vipAmountInfo = vipAmountBll.GetByID(UserID);
            var vipAmountInfo = vipAmountBll.QueryByEntity(new VipAmountEntity()
            {
                VipId = UserID, VipCardCode = VipLoginInfo.VipCode
            }, null).FirstOrDefault();
            decimal returnAmount = 0;
            decimal amount       = 0;
            if (vipAmountInfo != null)
            {
                returnAmount = vipAmountInfo.ValidReturnAmount == null ? 0 : vipAmountInfo.ValidReturnAmount.Value;
                amount       = vipAmountInfo.EndAmount == null ? 0 : vipAmountInfo.EndAmount.Value;
            }
            rd.MemberInfo.ReturnAmount = returnAmount; //返现
            rd.MemberInfo.Balance      = amount;       //余额
            #endregion


            //获取订单的日期和订单的里的商品名称、商品单价、商品数量
            //先获取订单列表,再获取订单详细信息
            int?         pageSize     = 3; //rp.Parameters.PageSize;,只取三条记录
            int?         pageIndex    = 1; //rp.Parameters.PageIndex;
            string       OrderBy      = "";
            string       OrderType    = "";
            T_InoutBLL   T_InoutBLL   = new T_InoutBLL(CurrentUserInfo);
            InoutService InoutService = new InoutService(CurrentUserInfo);
            //只取状态为700的
            //根据订单列表取订单详情
            DataSet dsOrder = T_InoutBLL.GetOrdersByVipID(rd.MemberInfo.VipID, pageIndex ?? 1, pageSize ?? 15, OrderBy, OrderType);//获取会员信息
            if (dsOrder != null && dsOrder.Tables.Count != 0 && dsOrder.Tables[0].Rows.Count != 0)
            {
                List <JIT.CPOS.DTO.Module.VIP.Login.Response.OrderInfo> orderList = DataTableToObject.ConvertToList <JIT.CPOS.DTO.Module.VIP.Login.Response.OrderInfo>(dsOrder.Tables[1]);
                foreach (JIT.CPOS.DTO.Module.VIP.Login.Response.OrderInfo oi in orderList)
                {
                    IList <InoutDetailInfo> detailList = InoutService.GetInoutDetailInfoByOrderId(oi.order_id);
                    oi.DetailList = detailList;
                }
                rd.OrderList = orderList;
            }

            MessageInfo message = new MessageInfo();


            InnerGroupNewsBLL InnerGroupNewsService = new InnerGroupNewsBLL(CurrentUserInfo);
            SetoffToolsBLL    setofftoolsService    = new SetoffToolsBLL(CurrentUserInfo);

            //1=微信用户 2=APP员工
            int UnReadInnerMessageCount = InnerGroupNewsService.GetVipInnerGroupNewsUnReadCount(CurrentUserInfo.UserID, pRequest.CustomerID, 1, null, Convert.ToDateTime(VipLoginInfo.CreateTime));
            var setofftoolsMessageCount = setofftoolsService.GetUnReadSetoffToolsCount(CurrentUserInfo.UserID, pRequest.CustomerID, 1, 1);
            message.InnerGroupNewsCount = UnReadInnerMessageCount;
            message.SetoffToolsCount    = setofftoolsMessageCount;
            var VipUpNewsInfo = InnerGroupNewsService.GetVipInnerNewsInfo(CurrentUserInfo.ClientID, 2, 1, 3, 0);
            if (VipUpNewsInfo != null && VipUpNewsInfo.Tables[0].Rows.Count > 0)
            {
                message.UpGradeSucess = VipUpNewsInfo.Tables[0].Rows[0]["Text"] != null ? VipUpNewsInfo.Tables[0].Rows[0]["Text"].ToString() : "";
                //获取通知信息 并更新已读状态 数据如果不是一条进行更新所有数据
                var newsUserMappingBLL = new NewsUserMappingBLL(CurrentUserInfo);
                if (VipUpNewsInfo.Tables[0].Rows.Count > 1)//数据如果不是一条进行更新所有数据
                {
                    foreach (DataRow VipNewsdr in VipUpNewsInfo.Tables[0].Rows)
                    {
                        var vipNewsInfo = newsUserMappingBLL.QueryByEntity(new NewsUserMappingEntity()
                        {
                            CustomerId = CurrentUserInfo.ClientID, MappingID = VipNewsdr["MappingID"].ToString()
                        }, null).FirstOrDefault();
                        if (vipNewsInfo != null)
                        {
                            vipNewsInfo.HasRead = 1;
                            newsUserMappingBLL.Update(vipNewsInfo);
                        }
                    }
                }
                else
                {
                    var vipNewsInfo = newsUserMappingBLL.QueryByEntity(new NewsUserMappingEntity()
                    {
                        CustomerId = CurrentUserInfo.ClientID, MappingID = VipUpNewsInfo.Tables[0].Rows[0]["MappingID"].ToString()
                    }, null).FirstOrDefault();
                    if (vipNewsInfo != null)
                    {
                        vipNewsInfo.HasRead = 1;
                        newsUserMappingBLL.Update(vipNewsInfo);
                    }
                }
            }
            else
            {
                message.UpGradeSucess = "";
            }
            rd.MessageInfo = message;
            return(rd);
        }
    }
Exemple #22
0
        protected override SetVipCardRD ProcessRequest(DTO.Base.APIRequest <OpenVipCardRP> pRequest)
        {
            var rd   = new SetVipCardRD();
            var para = pRequest.Parameters;
            var loggingSessionInfo        = new SessionManager().CurrentUserLoginInfo;         //登录状态信息
            var vipBLL                    = new VipBLL(loggingSessionInfo);                    //会员业务对象实例化
            var vipTagsMappingBLL         = new VipTagsMappingBLL(loggingSessionInfo);         //会员和标签关系业务对象实例化
            var vipCardBLL                = new VipCardBLL(loggingSessionInfo);                //会员卡业务对象实例化
            var vipCardVipMappingBLL      = new VipCardVipMappingBLL(loggingSessionInfo);      //会员和会员卡关系业务对象实例化
            var vipCardStatusChangeLogBLL = new VipCardStatusChangeLogBLL(loggingSessionInfo); //会员卡状态变更业务对象实例化
            var vipAddressBLL             = new VipAddressBLL(loggingSessionInfo);             //会员地址信息业务对象实例化
            var pTran = vipCardBLL.GetTran();                                                  //事务

            using (pTran.Connection)
            {
                try
                {
                    //创建会员信息
                    var vipEntity = new VipEntity()
                    {
                        VIPID       = Guid.NewGuid().ToString().Replace("-", ""),
                        VipName     = para.VipName,
                        VipRealName = para.VipName,
                        //VipCode = "Vip" + vipBLL.GetNewVipCode(loggingSessionInfo.ClientID), //获取会员编号
                        VipCode         = para.VipCardCode,                                  //会员卡号
                        CouponInfo      = loggingSessionInfo.CurrentUserRole.UnitId,         //原会集店字段
                        MembershipStore = loggingSessionInfo.CurrentUserRole.UnitId,         //新增的会集店字段
                        Phone           = para.Phone,
                        Birthday        = para.Birthday,
                        Gender          = para.Gender,
                        Email           = para.Email,
                        Col18           = para.IDCard, //身份证
                        Status          = 2,           //已注册状态
                        VipSourceId     = "20",        //来源开卡
                        ClientID        = loggingSessionInfo.ClientID
                    };
                    vipBLL.Create(vipEntity, pTran);
                    //保存年龄段标签
                    var vipTagsMappingEntity = new VipTagsMappingEntity()
                    {
                        MappingId = Guid.NewGuid().ToString().Replace("-", ""),
                        VipId     = vipEntity.VIPID,
                        TagsId    = para.TagsID
                    };
                    vipTagsMappingBLL.Create(vipTagsMappingEntity, pTran);

                    //保存会员地址信息
                    //var vipAddressEntity = new VipAddressEntity()
                    //{
                    //    VIPID = vipEntity.VIPID,
                    //    LinkMan = para.VipName,
                    //    LinkTel = para.Phone,
                    //    CityID = para.CityID,
                    //    Address = para.Address,
                    //    IsDefault = 1
                    //};
                    //vipAddressBLL.Create(vipAddressEntity, pTran);

                    //更新会员卡信息
                    var vipCardEntity = vipCardBLL.GetByID(para.VipCardID);
                    if (vipCardEntity != null)
                    {
                        #region 返回卡ID
                        rd.VipCardID = vipCardEntity.VipCardID;
                        #endregion
                        //vipCardEntity.VipCardStatusId = 1;
                        if (!string.IsNullOrEmpty(vipCardEntity.MembershipUnit))
                        {
                            throw new APIException("此会员卡已绑定会员")
                                  {
                                      ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                  }
                        }
                        ;
                        if (vipCardEntity.VipCardStatusId > 0)
                        {
                            throw new APIException("此会员卡状态异常")
                                  {
                                      ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                  }
                        }
                        ;
                        vipCardEntity.MembershipTime = DateTime.Now;
                        vipCardEntity.MembershipUnit = loggingSessionInfo.CurrentUserRole.UnitId;
                        vipCardEntity.IsGift         = para.IsGift;
                        //vipCardEntity.SalesUserId = para.SalesUserId;
                        vipCardEntity.SalesUserName = para.SalesUserName;        //用户输入名称,后期需要根据姓名查找用户ID,更新到SalesUserId
                        vipCardEntity.CreateBy      = loggingSessionInfo.UserID; //开卡人,即入会员工
                        vipCardBLL.Update(vipCardEntity, pTran);
                    }
                    else
                    {
                        throw new APIException("查不到此会员卡")
                              {
                                  ErrorCode = ERROR_CODES.INVALID_BUSINESS
                              }
                    };

                    //新增会员卡操作状态信息
                    var vipCardStatusChangeLogEntity = new VipCardStatusChangeLogEntity()
                    {
                        LogID           = Guid.NewGuid().ToString().Replace("-", ""),
                        VipCardStatusID = vipCardEntity.VipCardStatusId,
                        VipCardID       = para.VipCardID,
                        Action          = "开卡",
                        //Reason = "",
                        UnitID     = loggingSessionInfo.CurrentUserRole.UnitId,
                        CustomerID = loggingSessionInfo.ClientID
                    };
                    vipCardStatusChangeLogBLL.Create(vipCardStatusChangeLogEntity, pTran);

                    //绑定会员卡和会员
                    var vipCardVipMappingEntity = new VipCardVipMappingEntity()
                    {
                        MappingID  = Guid.NewGuid().ToString().Replace("-", ""),
                        VIPID      = vipEntity.VIPID,
                        VipCardID  = para.VipCardID,
                        CustomerID = loggingSessionInfo.ClientID
                    };
                    vipCardVipMappingBLL.Create(vipCardVipMappingEntity, pTran);

                    pTran.Commit();  //提交事物
                }
                catch (APIException apiEx)
                {
                    pTran.Rollback();//回滚事物
                    throw new APIException(apiEx.ErrorCode, apiEx.Message);
                }
                catch (Exception ex)
                {
                    pTran.Rollback();//回滚事物
                    throw new Exception(ex.Message);
                }
            }
            return(rd);
        }
        protected override GetVIPCardRD ProcessRequest(DTO.Base.APIRequest <GetVIPCardRP> pRequest)
        {
            GetVIPCardRD Data = new GetVIPCardRD();
            var          rd   = new GetVIPCardListRD();
            var          para = pRequest.Parameters;
            var          loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;

            #region 业务对象
            //会员卡
            var VipCardBLL = new VipCardBLL(loggingSessionInfo);
            //会员
            var VipBLL = new VipBLL(loggingSessionInfo);
            //卡状态变更记录
            var VipCardStatusChangeLogBLL = new VipCardStatusChangeLogBLL(loggingSessionInfo);
            //卡与Vip关系
            var VipCardVipMappingBLL = new VipCardVipMappingBLL(loggingSessionInfo);
            //门店
            var unitBll = new t_unitBLL(loggingSessionInfo);
            //员工
            var UserBLL = new T_UserBLL(loggingSessionInfo);
            //卡类型
            var SysVipCardTypeBLL = new SysVipCardTypeBLL(loggingSessionInfo);
            //商户配置
            var CustomerBasicSettingBLL = new CustomerBasicSettingBLL(loggingSessionInfo);
            //积分
            var VipIntegralBLL = new VipIntegralBLL(loggingSessionInfo);
            #endregion



            #region 会员卡
            VipCardEntity resultData = null;
            if (!string.IsNullOrWhiteSpace(para.VipID))
            {
                //会员编号获取详情
                VipCardVipMappingEntity m_VipMappingData = VipCardVipMappingBLL.QueryByEntity(new VipCardVipMappingEntity()
                {
                    VIPID = para.VipID
                }, null).FirstOrDefault();
                if (m_VipMappingData != null && !string.IsNullOrWhiteSpace(m_VipMappingData.VipCardID))
                {
                    resultData = VipCardBLL.GetByID(para.VipCardID);
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(para.VipCardID))
                {
                    //卡ID获取详情
                    resultData = VipCardBLL.GetByID(para.VipCardID);
                }
                else
                {
                    //刷卡获取详情
                    List <IWhereCondition> complexCondition = new List <IWhereCondition> {
                    };
                    if (!string.IsNullOrEmpty(para.VipCardISN))
                    {
                        complexCondition.Add(new DirectCondition("VipCardCode='" + para.VipCardISN + "' or VipCardISN='" + para.VipCardISN.ToString() + "' "));
                    }
                    resultData = VipCardBLL.Query(complexCondition.ToArray(), null).FirstOrDefault();
                }
            }

            //try
            //{
            //    if (resultData == null)
            //        throw new APIException("该卡不存在!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS };
            //}
            //catch (APIException apiEx)
            //{
            //    throw new APIException(apiEx.ErrorCode, apiEx.Message);
            //}
            #endregion

            #region 卡关系
            VipCardVipMappingEntity VipCardVipMappingData = null;
            if (resultData != null)
            {
                VipCardVipMappingData = VipCardVipMappingBLL.QueryByEntity(new VipCardVipMappingEntity()
                {
                    VipCardID = resultData.VipCardID
                }, null).FirstOrDefault();
            }
            //else
            //{
            //    return Data;
            //}
            #endregion

            #region 门店
            t_unitEntity unidData = null;
            if (resultData != null && !string.IsNullOrWhiteSpace(resultData.MembershipUnit))
            {
                unidData = unitBll.GetByID(resultData.MembershipUnit);
            }
            #endregion

            #region 会员,积分

            VipEntity         VipData      = null;
            VipIntegralEntity IntegralData = null;
            //string VIPID = VipCardVipMappingData == null ? "" : VipCardVipMappingData.VIPID;
            string VIPID = para.VipID;
            if (!string.IsNullOrWhiteSpace(VIPID))
            {
                VipData = VipBLL.NewGetByID(VIPID);
                //IntegralData = VipIntegralBLL.GetByID(VIPID);
                IntegralData = VipIntegralBLL.QueryByEntity(new VipIntegralEntity()
                {
                    VipID = VipData.VIPID, VipCardCode = VipData.VipCode
                }, null).FirstOrDefault();
            }
            #endregion

            #region 员工
            T_UserEntity UserData = null;
            if (resultData != null && !string.IsNullOrWhiteSpace(resultData.CreateBy))
            {
                UserData = UserBLL.GetByID(resultData.CreateBy);
            }
            #endregion

            #region 响应对象赋值
            if (resultData != null)
            {
                //卡
                Data.VipCardID      = resultData.VipCardID;
                Data.VipCardCode    = resultData.VipCardCode;
                Data.VipCardISN     = resultData.VipCardISN;
                Data.CraeteUserName = UserData == null ? "" : UserData.user_name;

                Data.VipCardStatusId    = resultData.VipCardStatusId.Value;
                Data.MembershipTime     = resultData.MembershipTime == null ? "" : resultData.MembershipTime.Value.ToString("yyyy-MM-dd");
                Data.MembershipUnitName = unidData == null ? "" : unidData.unit_name;
                //Data.TotalAmount = resultData.RechargeTotalAmount == null ? 0 : resultData.RechargeTotalAmount.Value;
                //Data.BalanceAmount = resultData.BalanceAmount == null ? 0 : resultData.BalanceAmount.Value;
                Data.BeginDate     = resultData.BeginDate;
                Data.EndDate       = "永久有效";
                Data.SalesUserName = resultData.SalesUserName == null ? "" : resultData.SalesUserName;
                #region 卡类型名称
                SysVipCardTypeEntity SysVipCardTypeData = SysVipCardTypeBLL.GetByID(resultData.VipCardTypeID);
                Data.VipCardName = SysVipCardTypeData == null ? "" : SysVipCardTypeData.VipCardTypeName;
                #endregion

                #region 状态变更记录列表

                var VipCardStatusChangeLogArray = VipCardStatusChangeLogBLL.Query
                                                      (new IWhereCondition[] { new EqualsCondition()
                                                                               {
                                                                                   FieldName = "VipCardID", Value = resultData.VipCardID
                                                                               } },
                                                      new OrderBy[] { new OrderBy()
                                                                      {
                                                                          FieldName = "CreateTime", Direction = OrderByDirections.Desc
                                                                      } }).ToList();
                //转换业务对象
                Data.StatusLogList = (from t in VipCardStatusChangeLogArray
                                      select new VipCardStatusChangeLog()
                {
                    CreateTime = t.CreateTime.Value.ToString("yyyy-MM-dd"),
                    UnitName = t.UnitName == null ? "" : t.UnitName,
                    Action = t.Action == null ? "" : t.Action,
                    ChangeReason = t.Reason == null ? "" : t.Reason,
                    Remark = t.Remark == null ? "" : t.Remark,
                    CreateBy = t.CreateByName,
                    ImageUrl = t.PicUrl == null ? "" : t.PicUrl
                }).ToList();
                #endregion
            }
            #region 会员
            if (VipData != null)
            {
                Data.VipID   = VipData.VIPID;
                Data.VipCode = VipData.VipCode;
                if (Data.VipCardCode == null)
                {
                    Data.VipCardCode = VipData.VipCode;
                }
                if (!string.IsNullOrWhiteSpace(VipData.VipRealName))
                {
                    Data.VipName = VipData.VipRealName;
                }
                else
                {
                    Data.VipName = VipData.VipName ?? "";
                }
                Data.Phone    = VipData.Phone;
                Data.Birthday = VipData.Birthday == null ? "" : VipData.Birthday;
                Data.Gender   = VipData.Gender ?? 0;
                //Data.Integration = VipData.Integration == null ? 0 : VipData.Integration.Value;
                //会员创建人姓名
                T_UserEntity VipUserData = null;
                if (resultData != null && !string.IsNullOrWhiteSpace(resultData.CreateBy))
                {
                    VipUserData = UserBLL.GetByID(resultData.CreateBy);
                }
                Data.VipCreateByName = VipUserData == null ? "" : VipUserData.user_name;
                Data.IDNumber        = VipData.IDNumber == null ? "" : VipData.IDNumber;

                #region 会员生日是否可修改字段赋值
                //Col22 字段赋值
                ////CustomerBasicSettingEntity SettingData = CustomerBasicSettingBLL.QueryByEntity(new CustomerBasicSettingEntity() { SettingCode = "FSR_NotTwoUpdateVipBirthday" }, null).FirstOrDefault();
                ////if (SettingData != null)
                Data.Col22 = VipData.Col22 == null ? "Y" : VipData.Col22;
                #endregion
            }
            #endregion

            #region 积分
            if (IntegralData != null)
            {
                Data.Integration        = IntegralData.ValidIntegral != null ? IntegralData.ValidIntegral.Value : 0;
                Data.CumulativeIntegral = IntegralData.CumulativeIntegral != null ? IntegralData.CumulativeIntegral.Value : 0;
            }
            #endregion

            #region 余额和返现
            var vipAmountBLL  = new VipAmountBLL(loggingSessionInfo);
            var vipAmountInfo = vipAmountBLL.QueryByEntity(new VipAmountEntity()
            {
                VipId = VipData.VIPID, VipCardCode = VipData.VipCode
            }, null).FirstOrDefault();
            if (vipAmountInfo != null)
            {
                Data.TotalAmount       = vipAmountInfo.TotalAmount == null ? 0 : vipAmountInfo.TotalAmount.Value;
                Data.BalanceAmount     = vipAmountInfo.EndAmount == null ? 0 : vipAmountInfo.EndAmount.Value;
                Data.ValidReturnAmount = vipAmountInfo.ValidReturnAmount == null ? 0 : vipAmountInfo.ValidReturnAmount.Value;
                Data.TotalReturnAmount = vipAmountInfo.TotalReturnAmount == null ? 0 : vipAmountInfo.TotalReturnAmount.Value;
            }
            #endregion


            #endregion
            return(Data);
        }
Exemple #24
0
        protected override SetVipCardRD ProcessRequest(DTO.Base.APIRequest <SetVipCardRP> pRequest)
        {
            var rd   = new SetVipCardRD();
            var para = pRequest.Parameters;
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;

            #region 业务对象
            //会员卡
            var VipCardBLL = new VipCardBLL(loggingSessionInfo);
            //余额变动记录
            var VipCardBalanceChangeBLL = new VipCardBalanceChangeBLL(loggingSessionInfo);
            //卡状态变更记录
            var VipCardStatusChangeLogBLL = new VipCardStatusChangeLogBLL(loggingSessionInfo);
            //卡关系
            var VipCardVipMappingBLL = new VipCardVipMappingBLL(loggingSessionInfo);
            //图片
            var objectImagesBLL = new ObjectImagesBLL(loggingSessionInfo);
            //会员
            var VipBLL = new VipBLL(loggingSessionInfo);

            var vipCardTransLogBLL = new VipCardTransLogBLL(loggingSessionInfo); //丰收日交易记录对象示例化
            var unitBLL            = new TUnitBLL(loggingSessionInfo);           //门店业务对象
            //事务
            var pTran = VipCardBLL.GetTran();
            #endregion



            using (pTran.Connection)
            {
                try
                {
                    if (string.IsNullOrWhiteSpace(para.VipCardID) || para.OperationType <= 0)
                    {
                        throw new APIException("卡ID或者操作类型参数不合法!")
                              {
                                  ErrorCode = ERROR_CODES.INVALID_REQUEST_LACK_REQUEST_PARAMETER
                              };
                    }

                    //定位当前卡业务对象
                    VipCardEntity changeEntity = VipCardBLL.GetByID(para.VipCardID);

                    if (changeEntity == null)
                    {
                        throw new APIException("当前卡信息对象为NULL!")
                              {
                                  ErrorCode = ERROR_CODES.INVALID_BUSINESS
                              };
                    }
                    #region 返回卡ID
                    rd.VipCardID = changeEntity.VipCardID;
                    #endregion
                    changeEntity.RechargeTotalAmount = changeEntity.RechargeTotalAmount ?? 0;
                    changeEntity.BalanceAmount       = changeEntity.BalanceAmount ?? 0;
                    string  OldVipCardCode = changeEntity.VipCardCode ?? "";                       //原卡号
                    string  NewVipCardCode = "";                                                   //新卡号,获取新卡赋值
                    decimal OldMoney       = changeEntity.BalanceAmount.Value;                     //原卡当前余额
                    decimal NewMoney       = changeEntity.BalanceAmount.Value + para.BalanceMoney; //原卡当余额+调整金额

                    //原卡会员映射关系
                    VipCardVipMappingEntity OldVipCardVipMappingData = VipCardVipMappingBLL.QueryByEntity(new VipCardVipMappingEntity()
                    {
                        VipCardID = para.VipCardID
                    }, null).FirstOrDefault();
                    if (OldVipCardVipMappingData == null)
                    {
                        throw new APIException("原卡会员关系映射对象为NULL!")
                              {
                                  ErrorCode = ERROR_CODES.INVALID_BUSINESS
                              };
                    }

                    //门店Entity
                    var UnitData = unitBLL.GetByID(loggingSessionInfo.CurrentUserRole.UnitId);
                    //会员
                    VipEntity VipData = VipBLL.GetByID(OldVipCardVipMappingData.VIPID);

                    #region 卡状态记录对象
                    VipCardStatusChangeLogEntity AddVCStatusEntity = new VipCardStatusChangeLogEntity();
                    AddVCStatusEntity.LogID       = System.Guid.NewGuid().ToString();
                    AddVCStatusEntity.VipCardID   = para.VipCardID;
                    AddVCStatusEntity.Reason      = para.ChangeReason;
                    AddVCStatusEntity.OldStatusID = changeEntity.VipCardStatusId;
                    AddVCStatusEntity.CustomerID  = loggingSessionInfo.ClientID;
                    AddVCStatusEntity.Remark      = para.Remark;
                    AddVCStatusEntity.UnitID      = loggingSessionInfo.CurrentUserRole.UnitId;
                    #endregion



                    #region 新卡
                    VipCardEntity NewChangeVipCardData = new VipCardEntity();
                    if (!string.IsNullOrWhiteSpace(para.NewCardCode))
                    {
                        //查询参数
                        List <IWhereCondition> complexCondition = new List <IWhereCondition> {
                        };
                        if (!string.IsNullOrEmpty(para.NewCardCode))
                        {
                            complexCondition.Add(new DirectCondition("VipCardCode='" + para.NewCardCode + "' or VipCardISN='" + para.NewCardCode.ToString() + "' "));
                        }
                        //新卡对象
                        NewChangeVipCardData = VipCardBLL.Query(complexCondition.ToArray(), null).FirstOrDefault();
                        if (NewChangeVipCardData == null)
                        {
                            throw new APIException("新卡不存在!")
                                  {
                                      ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                  };
                        }
                        //新卡号赋值
                        NewVipCardCode = NewChangeVipCardData.VipCardCode ?? "";
                        //新卡数据赋值
                        NewChangeVipCardData.VipCardGradeID      = changeEntity.VipCardGradeID;
                        NewChangeVipCardData.BatchNo             = changeEntity.BatchNo;
                        NewChangeVipCardData.BeginDate           = changeEntity.BeginDate;
                        NewChangeVipCardData.EndDate             = changeEntity.EndDate;
                        NewChangeVipCardData.TotalAmount         = changeEntity.TotalAmount == null ? 0 : changeEntity.TotalAmount.Value;
                        NewChangeVipCardData.BalanceAmount       = changeEntity.BalanceAmount == null ? 0 : changeEntity.BalanceAmount.Value;
                        NewChangeVipCardData.BalancePoints       = changeEntity.BalancePoints == null ? 0 : changeEntity.BalancePoints.Value;
                        NewChangeVipCardData.BalanceBonus        = changeEntity.BalanceBonus == null ? 0 : changeEntity.BalanceBonus.Value;
                        NewChangeVipCardData.CumulativeBonus     = changeEntity.CumulativeBonus == null ? 0 : changeEntity.CumulativeBonus.Value;
                        NewChangeVipCardData.PurchaseTotalAmount = changeEntity.PurchaseTotalAmount == null ? 0 : changeEntity.PurchaseTotalAmount.Value;
                        NewChangeVipCardData.PurchaseTotalCount  = changeEntity.PurchaseTotalCount == null ? 0 : changeEntity.PurchaseTotalCount.Value;
                        NewChangeVipCardData.CheckCode           = changeEntity.CheckCode;
                        NewChangeVipCardData.SingleTransLimit    = changeEntity.SingleTransLimit == null ? 0 : changeEntity.SingleTransLimit.Value;
                        NewChangeVipCardData.IsOverrunValid      = changeEntity.IsOverrunValid == null ? 0 : changeEntity.IsOverrunValid.Value;
                        NewChangeVipCardData.RechargeTotalAmount = changeEntity.RechargeTotalAmount == null ? 0 : changeEntity.RechargeTotalAmount.Value;
                        NewChangeVipCardData.LastSalesTime       = changeEntity.LastSalesTime;
                        NewChangeVipCardData.IsGift         = changeEntity.IsGift == null ? 0 : changeEntity.IsGift.Value;
                        NewChangeVipCardData.SalesAmount    = changeEntity.SalesAmount;
                        NewChangeVipCardData.SalesUserId    = changeEntity.SalesUserId;
                        NewChangeVipCardData.CustomerID     = changeEntity.CustomerID;
                        NewChangeVipCardData.MembershipTime = changeEntity.MembershipTime;
                        NewChangeVipCardData.SalesUserName  = changeEntity.SalesUserName == null ? "" : changeEntity.SalesUserName;
                        NewChangeVipCardData.CreateBy       = changeEntity.CreateBy;
                    }
                    #endregion


                    switch (para.OperationType)
                    {
                    case 1:
                        #region 调整卡余额
                        //卡更新

                        //卡内总金额
                        if (para.BalanceMoney > 0)
                        {
                            changeEntity.RechargeTotalAmount += para.BalanceMoney;
                            if (changeEntity.RechargeTotalAmount < 0)
                            {
                                throw new APIException("调整后的余额小于0!")
                                      {
                                          ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                      };
                            }
                        }
                        //changeEntity.BalanceAmount = changeEntity.BalanceAmount ?? 0;
                        //
                        changeEntity.BalanceAmount = NewMoney;
                        //执行更新
                        VipCardBLL.Update(changeEntity, pTran);

                        //新增余额变动记录
                        VipCardBalanceChangeEntity AddEntity = new VipCardBalanceChangeEntity();
                        AddEntity.ChangeID     = System.Guid.NewGuid().ToString();
                        AddEntity.VipCardCode  = changeEntity.VipCardCode;
                        AddEntity.ChangeAmount = para.BalanceMoney;
                        //变动前卡内余额
                        AddEntity.ChangeBeforeBalance = OldMoney;
                        //变动后卡内余额
                        AddEntity.ChangeAfterBalance = NewMoney;
                        AddEntity.ChangeReason       = para.ChangeReason;
                        AddEntity.Status             = 1;
                        AddEntity.Remark             = para.Remark;
                        AddEntity.CustomerID         = loggingSessionInfo.ClientID;
                        AddEntity.UnitID             = loggingSessionInfo.CurrentUserRole.UnitId;
                        //执行新增
                        VipCardBalanceChangeBLL.Create(AddEntity, pTran);

                        //增加图片上传
                        if (!string.IsNullOrEmpty(para.ImageUrl))
                        {
                            var objectImagesEntity = new ObjectImagesEntity()
                            {
                                ImageId  = Guid.NewGuid().ToString(),
                                ObjectId = AddEntity.ChangeID,
                                ImageURL = para.ImageUrl
                            };
                            objectImagesBLL.Create(objectImagesEntity, pTran);
                        }
                        #region 充值记录
                        //读取最近一次积分变更记录
                        List <OrderBy> lstOrder = new List <OrderBy> {
                        };                                                   //排序参数
                        lstOrder.Add(new OrderBy()
                        {
                            FieldName = "TransTime", Direction = OrderByDirections.Desc
                        });
                        var transLogInfo = vipCardTransLogBLL.QueryByEntity(new VipCardTransLogEntity()
                        {
                            VipCardCode = changeEntity.VipCardCode, TransType = "C"
                        }, lstOrder.ToArray()).FirstOrDefault();
                        //期末积分
                        int newValue = transLogInfo != null ? (transLogInfo.NewValue ?? 0) : 0;
                        var vipCardTransLogEntity = new VipCardTransLogEntity()
                        {
                            VipCardCode  = VipData == null ? "" : VipData.VipCode,
                            UnitCode     = UnitData == null ? "" : UnitData.UnitCode,
                            TransContent = "余额",
                            TransType    = "C",
                            TransTime    = DateTime.Now,
                            TransAmount  = para.BalanceMoney,
                            LastValue    = newValue,                                      //期初金额
                            NewValue     = Convert.ToInt32(para.BalanceMoney) + newValue, //期末金额
                            CustomerID   = loggingSessionInfo.ClientID
                        };
                        vipCardTransLogBLL.Create(vipCardTransLogEntity, pTran);

                        #endregion


                        #endregion
                        break;

                    case 2:
                        #region 卡升级

                        //卡类型升级
                        if (para.VipCardTypeId != 0)
                        {
                            VipCardVipMappingBLL.updateVipCardByType(VipData.VIPID, para.VipCardTypeId, para.ChangeReason, para.Remark, VipData.VipCode, pTran);
                        }
                        //卡号升级
                        else
                        {
                            #region 原卡

                            #region 更新原卡
                            changeEntity.VipCardStatusId = 3;
                            //当前月,累计金额清0
                            //changeEntity.BalanceAmount = 0;
                            //changeEntity.TotalAmount = 0;
                            VipCardBLL.Update(changeEntity, pTran);    //执行
                            #endregion

                            #region 新增原卡状态记录
                            AddVCStatusEntity.VipCardStatusID = 3;
                            AddVCStatusEntity.Action          = "卡升级";
                            AddVCStatusEntity.Remark         += "已升级为:" + NewChangeVipCardData.VipCardCode;
                            VipCardStatusChangeLogBLL.Create(AddVCStatusEntity, pTran);    //执行
                            #endregion

                            #region 新增原卡余额变动记录
                            //if (OldMoney > 0)
                            //{
                            //    VipCardBalanceChangeEntity AddOldCardBalanceData = new VipCardBalanceChangeEntity();
                            //    AddOldCardBalanceData.ChangeID = System.Guid.NewGuid().ToString();
                            //    AddOldCardBalanceData.VipCardCode = changeEntity.VipCardCode;
                            //    AddOldCardBalanceData.ChangeAmount = -OldMoney;
                            //    //变动前卡内余额
                            //    AddOldCardBalanceData.ChangeBeforeBalance = OldMoney;
                            //    //变动后卡内余额
                            //    AddOldCardBalanceData.ChangeAfterBalance = 0;
                            //    AddOldCardBalanceData.ChangeReason = para.ChangeReason;
                            //    AddOldCardBalanceData.Status = 1;
                            //    AddOldCardBalanceData.Remark = para.Remark;
                            //    AddOldCardBalanceData.CustomerID = loggingSessionInfo.ClientID;
                            //    AddOldCardBalanceData.UnitID = loggingSessionInfo.CurrentUserRole.UnitId;
                            //    VipCardBalanceChangeBLL.Create(AddOldCardBalanceData, pTran);//执行
                            //    //增加图片上传
                            //    if (!string.IsNullOrEmpty(para.ImageUrl))
                            //    {
                            //        var objectImagesEntity = new ObjectImagesEntity()
                            //        {
                            //            ImageId = Guid.NewGuid().ToString(),
                            //            ObjectId = AddOldCardBalanceData.ChangeID,
                            //            ImageURL = para.ImageUrl
                            //        };
                            //        objectImagesBLL.Create(objectImagesEntity, pTran);
                            //    }
                            //}
                            #endregion

                            #endregion

                            #region 新卡

                            VipData.VipCode = para.NewCardCode;
                            VipBLL.Update(VipData, pTran);

                            #region 更新新卡
                            if (!string.IsNullOrEmpty(NewChangeVipCardData.MembershipUnit))
                            {
                                throw new APIException("该会员卡已绑定会员!")
                                      {
                                          ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                      }
                            }
                            ;
                            if (NewChangeVipCardData.VipCardStatusId != 0)
                            {
                                throw new APIException("该会员卡已激活!")
                                      {
                                          ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                      }
                            }
                            ;
                            if (NewChangeVipCardData.VipCardTypeID.Value == changeEntity.VipCardTypeID.Value)
                            {
                                throw new APIException("该卡号与原卡等级相同,请更换卡号后重新尝试!")
                                      {
                                          ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                      }
                            }
                            ;

                            #region 返回新卡卡ID
                            rd.VipCardID = NewChangeVipCardData.VipCardID;
                            #endregion
                            NewChangeVipCardData.MembershipUnit  = changeEntity.MembershipUnit;
                            NewChangeVipCardData.VipCardStatusId = 1;
                            VipCardBLL.Update(NewChangeVipCardData, pTran);    //执行
                            #endregion

                            #region 新增新卡卡关系
                            VipCardVipMappingEntity AddVipCardVipMappingData = new VipCardVipMappingEntity();
                            AddVipCardVipMappingData.MappingID  = System.Guid.NewGuid().ToString();
                            AddVipCardVipMappingData.VIPID      = OldVipCardVipMappingData.VIPID;
                            AddVipCardVipMappingData.VipCardID  = NewChangeVipCardData.VipCardID;
                            AddVipCardVipMappingData.CustomerID = loggingSessionInfo.ClientID;
                            VipCardVipMappingBLL.Create(AddVipCardVipMappingData, pTran);    //执行
                            #endregion

                            #region 更新会员编号
                            //VipEntity SJ_VipData = VipBLL.GetByID(OldVipCardVipMappingData.VIPID);
                            //if (VipData == null)
                            //    throw new APIException("会员不存在!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS };

                            //VipData.VipCode = NewChangeVipCardData.VipCardCode;
                            //VipBLL.Update(VipData, pTran);//执行
                            #endregion

                            #region 新增新卡状态记录
                            //新增新卡状态记录

                            VipCardStatusChangeLogEntity AddNewVCStatusEntity = new VipCardStatusChangeLogEntity();
                            AddNewVCStatusEntity.LogID           = System.Guid.NewGuid().ToString();
                            AddNewVCStatusEntity.VipCardID       = NewChangeVipCardData.VipCardID;
                            AddNewVCStatusEntity.VipCardStatusID = 1;
                            AddNewVCStatusEntity.Reason          = para.ChangeReason;
                            AddNewVCStatusEntity.OldStatusID     = 0;
                            AddNewVCStatusEntity.CustomerID      = loggingSessionInfo.ClientID;
                            AddNewVCStatusEntity.Action          = "卡升级";
                            AddNewVCStatusEntity.Remark          = para.Remark + "由旧卡:" + changeEntity.VipCardCode + "升级";
                            AddNewVCStatusEntity.UnitID          = loggingSessionInfo.CurrentUserRole.UnitId;
                            VipCardStatusChangeLogBLL.Create(AddNewVCStatusEntity, pTran);    //执行

                            #endregion

                            #region 新增新卡余额记录
                            //新增余额记录
                            //if (OldMoney > 0)
                            //{
                            //    VipCardBalanceChangeEntity AddNewCardBalanceData = new VipCardBalanceChangeEntity();
                            //    AddNewCardBalanceData.ChangeID = System.Guid.NewGuid().ToString();
                            //    AddNewCardBalanceData.VipCardCode = NewChangeVipCardData.VipCardCode;
                            //    AddNewCardBalanceData.ChangeAmount = OldMoney;
                            //    //变动前卡内余额
                            //    AddNewCardBalanceData.ChangeBeforeBalance = 0;
                            //    //变动后卡内余额
                            //    AddNewCardBalanceData.ChangeAfterBalance = NewChangeVipCardData.BalanceAmount == null ? 0 : NewChangeVipCardData.BalanceAmount.Value;
                            //    AddNewCardBalanceData.ChangeReason = para.ChangeReason;
                            //    AddNewCardBalanceData.Status = 1;
                            //    AddNewCardBalanceData.Remark = para.Remark;
                            //    AddNewCardBalanceData.CustomerID = loggingSessionInfo.ClientID;
                            //    VipCardBalanceChangeBLL.Create(AddNewCardBalanceData, pTran);//执行
                            //    //增加图片上传
                            //    if (!string.IsNullOrEmpty(para.ImageUrl))
                            //    {
                            //        var objectImagesEntity = new ObjectImagesEntity()
                            //        {
                            //            ImageId = Guid.NewGuid().ToString(),
                            //            ObjectId = AddNewCardBalanceData.ChangeID,
                            //            ImageURL = para.ImageUrl
                            //        };
                            //        objectImagesBLL.Create(objectImagesEntity, pTran);
                            //    }
                            //}
                            #endregion

                            #endregion
                        }
                        #endregion

                        break;

                    case 3:
                        #region 挂失
                        changeEntity.VipCardStatusId = 4;
                        //执行更新
                        VipCardBLL.Update(changeEntity, pTran);
                        //执行
                        AddVCStatusEntity.VipCardStatusID = 4;
                        AddVCStatusEntity.PicUrl          = para.ImageUrl;
                        AddVCStatusEntity.Action          = "挂失";
                        VipCardStatusChangeLogBLL.Create(AddVCStatusEntity, pTran);
                        #endregion

                        break;

                    case 4:

                        #region 冻结
                        changeEntity.VipCardStatusId = 2;
                        //执行更新
                        VipCardBLL.Update(changeEntity, pTran);
                        //执行新增
                        AddVCStatusEntity.VipCardStatusID = 2;
                        AddVCStatusEntity.Action          = "冻结";
                        VipCardStatusChangeLogBLL.Create(AddVCStatusEntity, pTran);
                        #endregion
                        break;

                    case 5:
                        #region 转卡
                        #region 原卡
                        #region 更新原卡
                        changeEntity.VipCardStatusId = 3;
                        //当前月,累计金额清0
                        changeEntity.BalanceAmount = 0;
                        changeEntity.TotalAmount   = 0;
                        VipCardBLL.Update(changeEntity, pTran);    //执行
                        #endregion

                        #region 新增原卡状态记录
                        AddVCStatusEntity.VipCardStatusID = 3;
                        AddVCStatusEntity.Action          = "转卡";
                        AddVCStatusEntity.Remark         += "已转移为:" + NewChangeVipCardData.VipCardCode;
                        VipCardStatusChangeLogBLL.Create(AddVCStatusEntity, pTran);    //执行
                        #endregion


                        #region 新增原卡余额变动记录
                        if (OldMoney > 0)
                        {
                            VipCardBalanceChangeEntity AddOldZKCardBalanceData = new VipCardBalanceChangeEntity();
                            AddOldZKCardBalanceData.ChangeID     = System.Guid.NewGuid().ToString();
                            AddOldZKCardBalanceData.VipCardCode  = changeEntity.VipCardCode;
                            AddOldZKCardBalanceData.ChangeAmount = -OldMoney;
                            //变动前卡内余额
                            AddOldZKCardBalanceData.ChangeBeforeBalance = OldMoney;
                            //变动后卡内余额
                            AddOldZKCardBalanceData.ChangeAfterBalance = 0;
                            AddOldZKCardBalanceData.ChangeReason       = para.ChangeReason;
                            AddOldZKCardBalanceData.Status             = 1;
                            AddOldZKCardBalanceData.Remark             = para.Remark;
                            AddOldZKCardBalanceData.CustomerID         = loggingSessionInfo.ClientID;
                            AddOldZKCardBalanceData.UnitID             = loggingSessionInfo.CurrentUserRole.UnitId;
                            VipCardBalanceChangeBLL.Create(AddOldZKCardBalanceData, pTran);     //执行
                            //增加图片上传
                            if (!string.IsNullOrEmpty(para.ImageUrl))
                            {
                                var objectImagesEntity = new ObjectImagesEntity()
                                {
                                    ImageId  = Guid.NewGuid().ToString(),
                                    ObjectId = AddOldZKCardBalanceData.ChangeID,
                                    ImageURL = para.ImageUrl
                                };
                                objectImagesBLL.Create(objectImagesEntity, pTran);
                            }
                        }
                        #endregion

                        #endregion
                        #region 新卡

                        #region 更新新卡
                        if (!string.IsNullOrEmpty(NewChangeVipCardData.MembershipUnit))
                        {
                            throw new APIException("该会员卡已绑定会员!")
                                  {
                                      ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                  }
                        }
                        ;
                        if (NewChangeVipCardData.VipCardStatusId != 0)
                        {
                            throw new APIException("该会员卡已激活!")
                                  {
                                      ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                  }
                        }
                        ;
                        if (NewChangeVipCardData.VipCardTypeID.Value != changeEntity.VipCardTypeID.Value)
                        {
                            throw new APIException("该卡号与原卡等级不同,请更换卡号后重新尝试!")
                                  {
                                      ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                  }
                        }
                        ;

                        #region 返回新卡卡ID
                        rd.VipCardID = NewChangeVipCardData.VipCardID;
                        #endregion
                        NewChangeVipCardData.MembershipUnit  = changeEntity.MembershipUnit;
                        NewChangeVipCardData.VipCardStatusId = 1;
                        VipCardBLL.Update(NewChangeVipCardData, pTran);    //执行
                        #endregion



                        #region 新增新卡卡关系
                        VipCardVipMappingEntity AddZKVipCardVipMappingData = new VipCardVipMappingEntity();
                        AddZKVipCardVipMappingData.MappingID  = System.Guid.NewGuid().ToString();
                        AddZKVipCardVipMappingData.VIPID      = OldVipCardVipMappingData.VIPID;
                        AddZKVipCardVipMappingData.VipCardID  = NewChangeVipCardData.VipCardID;
                        AddZKVipCardVipMappingData.CustomerID = loggingSessionInfo.ClientID;
                        VipCardVipMappingBLL.Create(AddZKVipCardVipMappingData, pTran);    //执行
                        #endregion

                        #region 更新会员编号
                        //VipEntity ZK_VipData = VipBLL.GetByID(OldVipCardVipMappingData.VIPID);
                        if (VipData == null)
                        {
                            throw new APIException("会员不存在!")
                                  {
                                      ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                  }
                        }
                        ;

                        VipData.VipCode = NewChangeVipCardData.VipCardCode;
                        VipBLL.Update(VipData, pTran);    //执行
                        #endregion

                        #region 新增新卡状态记录
                        VipCardStatusChangeLogEntity AddNewZKVCStatusEntity = new VipCardStatusChangeLogEntity();
                        AddNewZKVCStatusEntity.LogID           = System.Guid.NewGuid().ToString();
                        AddNewZKVCStatusEntity.VipCardID       = NewChangeVipCardData.VipCardID;
                        AddNewZKVCStatusEntity.VipCardStatusID = 1;
                        AddNewZKVCStatusEntity.Reason          = para.ChangeReason;
                        AddNewZKVCStatusEntity.OldStatusID     = 0;
                        AddNewZKVCStatusEntity.CustomerID      = loggingSessionInfo.ClientID;
                        AddNewZKVCStatusEntity.Action          = "转卡";
                        AddNewZKVCStatusEntity.Remark          = para.Remark + para.Remark + "由旧卡:" + changeEntity.VipCardCode + "转移";
                        AddNewZKVCStatusEntity.UnitID          = loggingSessionInfo.CurrentUserRole.UnitId;
                        VipCardStatusChangeLogBLL.Create(AddNewZKVCStatusEntity, pTran);    //执行
                        #endregion

                        #region 新增新卡余额记录
                        if (OldMoney > 0)
                        {
                            VipCardBalanceChangeEntity AddNewZKCardBalanceData = new VipCardBalanceChangeEntity();
                            AddNewZKCardBalanceData.ChangeID     = System.Guid.NewGuid().ToString();
                            AddNewZKCardBalanceData.VipCardCode  = NewChangeVipCardData.VipCardCode;
                            AddNewZKCardBalanceData.ChangeAmount = OldMoney;
                            //变动前卡内余额
                            AddNewZKCardBalanceData.ChangeBeforeBalance = 0;
                            //变动后卡内余额
                            AddNewZKCardBalanceData.ChangeAfterBalance = NewChangeVipCardData.BalanceAmount == null ? 0 : NewChangeVipCardData.BalanceAmount.Value;
                            AddNewZKCardBalanceData.ChangeReason       = para.ChangeReason;
                            AddNewZKCardBalanceData.Status             = 1;
                            AddNewZKCardBalanceData.Remark             = para.Remark;
                            AddNewZKCardBalanceData.CustomerID         = loggingSessionInfo.ClientID;
                            AddNewZKCardBalanceData.UnitID             = loggingSessionInfo.CurrentUserRole.UnitId;
                            VipCardBalanceChangeBLL.Create(AddNewZKCardBalanceData, pTran);    //执行
                            //增加图片上传
                            if (!string.IsNullOrEmpty(para.ImageUrl))
                            {
                                var objectImagesEntity = new ObjectImagesEntity()
                                {
                                    ImageId  = Guid.NewGuid().ToString(),
                                    ObjectId = AddNewZKCardBalanceData.ChangeID,
                                    ImageURL = para.ImageUrl
                                };
                                objectImagesBLL.Create(objectImagesEntity, pTran);
                            }
                        }
                        #endregion



                        #endregion
                        #endregion
                        break;

                    case 6:

                        #region 解挂
                        changeEntity.VipCardStatusId = 1;
                        //执行更新
                        VipCardBLL.Update(changeEntity, pTran);
                        //执行新增
                        AddVCStatusEntity.VipCardStatusID = 1;
                        AddVCStatusEntity.Action          = "解挂";
                        VipCardStatusChangeLogBLL.Create(AddVCStatusEntity, pTran);
                        #endregion
                        break;

                    case 7:

                        #region 解冻
                        changeEntity.VipCardStatusId = 1;
                        //执行更新
                        VipCardBLL.Update(changeEntity, pTran);
                        //执行新增
                        AddVCStatusEntity.VipCardStatusID = 1;
                        AddVCStatusEntity.Action          = "解冻";
                        VipCardStatusChangeLogBLL.Create(AddVCStatusEntity, pTran);
                        #endregion
                        break;

                    case 8:
                        #region 作废
                        changeEntity.VipCardStatusId = 3;
                        //执行更新
                        VipCardBLL.Update(changeEntity, pTran);


                        //执行新增
                        AddVCStatusEntity.VipCardStatusID = 3;
                        AddVCStatusEntity.Action          = "作废";
                        VipCardStatusChangeLogBLL.Create(AddVCStatusEntity, pTran);
                        #endregion
                        break;

                    case 9:
                        #region 唤醒
                        changeEntity.VipCardStatusId = 1;
                        //执行更新
                        VipCardBLL.Update(changeEntity, pTran);
                        //执行新增
                        AddVCStatusEntity.VipCardStatusID = 1;
                        AddVCStatusEntity.Action          = "唤醒";
                        VipCardStatusChangeLogBLL.Create(AddVCStatusEntity, pTran);
                        #endregion
                        break;

                    case 10:
                        #region 激活
                        changeEntity.VipCardStatusId = 1;
                        //执行更新
                        VipCardBLL.Update(changeEntity, pTran);
                        //执行新增
                        AddVCStatusEntity.VipCardStatusID = 1;
                        AddVCStatusEntity.Action          = "激活";
                        VipCardStatusChangeLogBLL.Create(AddVCStatusEntity, pTran);
                        #endregion
                        break;

                    default:
                        throw new APIException("当前操作类型不匹配!")
                              {
                                  ErrorCode = ERROR_CODES.INVALID_REQUEST_LACK_REQUEST_PARAMETER
                              };
                        break;
                    }
                    ;
                    pTran.Commit();
                    #region 卡升级,转卡操作转移消费记录表
                    if ((para.OperationType == 2 || para.OperationType == 5) && string.IsNullOrEmpty(para.VipCardTypeId.ToString())) //卡类型升级不执行此操作
                    {
                        string StrSql = string.Format("update VipCardTransLog set VipCardCode='{0}',OldVipCardCode='{1}' where VipCardCode='{1}'", NewVipCardCode, OldVipCardCode);
                        vipCardTransLogBLL.UpdateVipCardTransLog(StrSql);//执行
                    }
                    #endregion

                    var eventService = new EventService();
                    var vipMsg       = new EventContract
                    {
                        Operation  = OptEnum.Update,
                        EntityType = EntityTypeEnum.Vip,
                        Id         = VipData.VIPID
                    };
                    eventService.PublishMsg(vipMsg);
                }
                catch (APIException apiEx)
                {
                    pTran.Rollback();//回滚事物
                    throw new APIException(apiEx.ErrorCode, apiEx.Message);
                }
                catch (Exception ex)
                {
                    pTran.Rollback();//回滚事务
                    throw new APIException(ex.Message);
                }
            }
            return(rd);
        }
        protected override GetVipCardTypeRD ProcessRequest(APIRequest <GetVipCardTypeRP> pRequest)
        {
            var rd   = new GetVipCardTypeRD();
            var para = pRequest.Parameters;
            LoggingSessionInfo loggingSessionInfo = Default.GetBSLoggingSession(pRequest.CustomerID, pRequest.UserID);
            //声明卡等级相关逻辑
            var    bllVipCardType         = new SysVipCardTypeBLL(loggingSessionInfo);
            var    bllVip                 = new VipBLL(loggingSessionInfo);
            string strPhone               = string.Empty;
            int?   CurVipLevel            = 0;
            List <IWhereCondition> wheres = new List <IWhereCondition>();

            wheres.Add(new EqualsCondition()
            {
                FieldName = "clientid", Value = pRequest.CustomerID
            });
            wheres.Add(new EqualsCondition()
            {
                FieldName = "VipID", Value = pRequest.UserID
            });
            wheres.Add(new EqualsCondition()
            {
                FieldName = "Status", Value = 2
            });
            //wheres.Add(new DirectCondition("Phone!=''"));
            var vipInfo = bllVip.Query(wheres.ToArray(), null).FirstOrDefault();

            if (vipInfo != null)
            {
                strPhone = vipInfo.Phone;
                var vipCardVipMappingBLL = new VipCardVipMappingBLL(CurrentUserInfo);
                var vipCardBLL           = new VipCardBLL(CurrentUserInfo);
                var vipCardTypeBLL       = new SysVipCardTypeBLL(CurrentUserInfo);
                var vipCardMappingInfo   = vipCardVipMappingBLL.QueryByEntity(new VipCardVipMappingEntity()
                {
                    VIPID = pRequest.UserID, CustomerID = CurrentUserInfo.ClientID
                },
                                                                              new OrderBy[] { new OrderBy()
                                                                                              {
                                                                                                  FieldName = "CreateTime", Direction = OrderByDirections.Desc
                                                                                              } }).FirstOrDefault();
                if (vipCardMappingInfo != null)//根据当前会员与卡关联表获取当前会员等级
                {
                    var vipCardInfo = vipCardBLL.QueryByEntity(new VipCardEntity()
                    {
                        VipCardID = vipCardMappingInfo.VipCardID, VipCardStatusId = 1
                    }, null).FirstOrDefault();
                    if (vipCardInfo != null)
                    {
                        var vipCardTypeInfo = vipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity()
                        {
                            VipCardTypeID = vipCardInfo.VipCardTypeID
                        }, null).FirstOrDefault();
                        if (vipCardTypeInfo != null)//获取当前会员等级
                        {
                            CurVipLevel = vipCardTypeInfo.VipCardLevel;
                            if (CurVipLevel <= 1)
                            {
                                CurVipLevel = 1;
                            }
                        }
                    }
                }
            }
            else
            {
                strPhone = para.Phone;
            }
            try
            {
                //获取当前会员可绑卡列表
                var VipCardTypeSysInfoList = bllVipCardType.GetBindVipCardTypeInfo(loggingSessionInfo.ClientID, strPhone, pRequest.UserID, CurVipLevel);
                if (VipCardTypeSysInfoList != null && VipCardTypeSysInfoList.Tables[0].Rows.Count > 0)
                {
                    rd.VipCardTypeList = DataTableToObject.ConvertToList <VipCardRelateInfo>(VipCardTypeSysInfoList.Tables[0]);
                }
                else
                {
                    throw new APIException("未检测到实体卡!")
                          {
                              ErrorCode = ERROR_CODES.INVALID_BUSINESS
                          };
                }
            }
            catch (APIException ex)
            {
                throw ex;
            }

            return(rd);
        }
        protected override GetVIPCardListRD ProcessRequest(DTO.Base.APIRequest <GetVIPCardListRP> pRequest)
        {
            var rd   = new GetVIPCardListRD();
            var para = pRequest.Parameters;
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            var VipCardBLL         = new VipCardBLL(loggingSessionInfo);
            var unitBLL            = new t_unitBLL(loggingSessionInfo);

            //查询参数
            List <IWhereCondition> complexCondition = new List <IWhereCondition> {
            };

            //商户条件
            complexCondition.Add(new EqualsCondition()
            {
                FieldName = "a.CustomerID", Value = loggingSessionInfo.ClientID
            });
            //if (!string.IsNullOrEmpty(para.Phone))
            //    complexCondition.Add(new EqualsCondition() { FieldName = "g.Phone", Value = para.Phone });
            if (!string.IsNullOrEmpty(para.VipCardCode))
            {
                complexCondition.Add(new EqualsCondition()
                {
                    FieldName = "a.VipCardCode", Value = para.VipCardCode
                });
            }
            if (!string.IsNullOrEmpty(para.VipCardTypeID))
            {
                complexCondition.Add(new EqualsCondition()
                {
                    FieldName = "a.VipCardTypeID", Value = para.VipCardTypeID
                });
            }
            if (!string.IsNullOrEmpty(para.VipCardStatusId))
            {
                complexCondition.Add(new EqualsCondition()
                {
                    FieldName = "a.VipCardStatusId", Value = para.VipCardStatusId
                });
            }

            if (!string.IsNullOrEmpty(para.BeginDate))
            {
                complexCondition.Add(new DirectCondition("a.BeginDate>=" + para.BeginDate + " "));
            }
            if (!string.IsNullOrEmpty(para.EndDate))
            {
                complexCondition.Add(new DirectCondition("a.EndDate<=" + para.EndDate + " "));
            }
            if (!string.IsNullOrEmpty(para.UnitID))
            {
                //门店对象
                t_unitEntity unitData = unitBLL.GetByID(para.UnitID);
                string       type_id  = unitData == null ? "" : unitData.type_id;
                //总部
                if (type_id != "2F35F85CF7FF4DF087188A7FB05DED1D")
                {
                    complexCondition.Add(new EqualsCondition()
                    {
                        FieldName = "u.Unit_ID", Value = para.UnitID
                    });
                }
            }
            else
            {
                //门店对象
                t_unitEntity D_unitData = unitBLL.GetByID(loggingSessionInfo.CurrentUserRole.UnitId);
                string       D_type_id  = D_unitData == null ? "" : D_unitData.type_id;

                if (D_type_id != "2F35F85CF7FF4DF087188A7FB05DED1D")
                {
                    complexCondition.Add(new EqualsCondition()
                    {
                        FieldName = "u.Unit_ID", Value = loggingSessionInfo.CurrentUserRole.UnitId
                    });
                }
            }
            if (!string.IsNullOrWhiteSpace(para.VIPID))
            {
                complexCondition.RemoveAt(complexCondition.Count() - 1);
            }

            //排序参数
            List <OrderBy> lstOrder = new List <OrderBy> {
            };

            lstOrder.Add(new OrderBy()
            {
                FieldName = "LastUpdateTime", Direction = OrderByDirections.Desc
            });
            //调用会员卡管理列表查询
            var tempList = VipCardBLL.GetVipCardList(para.VIPID, para.Phone, complexCondition.ToArray(), lstOrder.ToArray(), para.PageSize, para.PageIndex);

            rd.TotalPageCount = tempList.PageCount;
            rd.TotalCount     = tempList.RowCount;
            rd.VipCardList    = tempList.Entities.Select(t => new VipCardInfo()
            {
                VipCardID          = t.VipCardID,
                VipCardCode        = t.VipCardCode,
                VipCardName        = t.VipCardTypeName,
                VipName            = t.VipName,
                Phone              = t.Phone,
                MembershipTime     = t.MembershipTime == null ? "" : t.MembershipTime.Value.ToString("yyyy-MM-dd"),
                MembershipUnitName = t.UnitName == null ? "" : t.UnitName,
                VipCardStatusID    = t.VipCardStatusId.Value,
                SalesUserName      = t.SalesUserName == null?"":t.SalesUserName,
                ImageUrl           = t.picUrl,
                BalanceAmount      = t.BalanceAmount == null ? 0 : t.BalanceAmount.Value,
                VIPID              = t.VIPID
            }).ToList();
            return(rd);
        }