예제 #1
0
        public void Deal(EventContract msg)
        {
            var     bus = MqBusMgr.GetInstance();
            OptEnum operation;

            Enum.TryParse(msg.Operation.ToString(), out operation);
            var vipContract = new VipContract
            {
                Operation = operation,
                VipId     = msg.Id
            };

            if (msg.Operation != Zmind.EventBus.Contract.OptEnum.Delete)
            {
                var vipFacade = new VipFacade();
                var vipEntity = vipFacade.GetById(msg.Id);
                if (vipEntity == null)
                {
                    return;
                }
                vipContract.VipName    = vipEntity.VipName;
                vipContract.VipCode    = vipEntity.VipCode;
                vipContract.CreateTime = vipEntity.CreateTime;
                vipContract.ModifyTime = vipEntity.LastUpdateTime;

                vipContract.Phone    = vipEntity.Phone;
                vipContract.IdType   = vipEntity.IDType;
                vipContract.IdNumber = vipEntity.IDNumber;
                if (string.IsNullOrEmpty(vipEntity.Birthday))
                {
                    vipContract.Birthday = null;
                }
                else
                {
                    vipContract.Birthday = DateTime.Parse(vipEntity.Birthday);
                }
                vipContract.Gender   = vipEntity.Gender != null ? vipEntity.Gender.Value : 1;
                vipContract.Email    = vipEntity.Email;
                vipContract.OpenID   = vipEntity.WeiXinUserId;
                vipContract.WeiXinID = vipEntity.WeiXin;
                //  vipContract.VipLevel = vipEntity.VipLevel != null ? vipEntity.VipLevel.Value : 1;
                //获取会员对应的卡类别
                //查询最低等级的会员卡类型
                SysVipCardTypeFacade _SysVipCardTypeFacade = new SysVipCardTypeFacade();
                SysVipCardTypeEntity vipCardTypeInfo       = _SysVipCardTypeFacade.GetVipCardTypeByVipID(msg.Id);
                if (vipCardTypeInfo != null)
                {
                    vipContract.VipCardTypeID = (int)vipCardTypeInfo.VipCardTypeID;
                }
                vipContract.OldVipID = msg.OtherCon;
            }


            bus.Publish <IZmindToXgx>(vipContract);
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public IEnumerable <EventContract> GetAllEvents()
        {
            var db = new TimeTableDbContext();

            var now = DateTime.Now;
            //alle zukünftigen Events
            var events = db.Activities.OfType <Event>()
                         .Where(ev => ev.Dates.Any(d => d.End >= now)).ToList();

            //andere ansatz
            //var events = db.Activities.OfType<Event>()
            //.Where(ev => ev.Published == true && ev.Dates.Any(d => d.End >= now)).ToList();

            var eventList = new List <EventContract>();

            //jedes zukünftige event soll hinzugefügt werden mit Datum um Veranstalter
            foreach (var @event in events)
            {
                var nextEvent = new EventContract
                {
                    EventId         = @event.Id.ToString(),
                    EventName       = @event.Name,
                    EventDesciption = @event.Description,

                    //geht des so?
                    EventSlots     = @event.Occurrence.Capacity,
                    AvailableSlots = @event.Occurrence.Capacity - @event.Occurrence.Subscriptions.Count(),
                };
                //Die einzelnen Termine der Veranstaltung
                var eventDateList = new List <EventDate>();

                //Alle Termine der Veranstaltung in der Zukunft
                foreach (var date in @event.Dates)
                {
                    //nur zukünftige Termine oder in zukuft reichende
                    if (date.Begin >= now || (date.Begin <= now && date.End > now))
                    {
                        eventDateList.Add(new EventDate
                        {
                            Start          = date.Begin.ToString("hh\\:mm"),
                            End            = date.End.ToString("hh\\:mm"),
                            Date           = date.Begin.Date.ToString("dd.MM.yyyy"),
                            PlaceName      = date.Rooms.FirstOrDefault() != null ? date.Rooms.First().Number : "N.N.",
                            PlaceId        = date.Rooms.FirstOrDefault() != null ? date.Rooms.First().Id.ToString() : "N.N.",
                            EventOrganiser = date.Hosts.FirstOrDefault() != null ? date.Hosts.First().Name : "N.N.",
                        });
                        nextEvent.Dates = eventDateList;
                    }
                }
                eventList.Add(nextEvent);
            }
            //return eventList.OrderBy(ev => ev.Dates.First(e => e.Start>=now));
            return(eventList);
        }
예제 #3
0
        public async Task <string> TriggerEvent()
        {
            var eventContract = new EventContract();

            await TriggerEvent(eventContract);

            var msg = $"Triggered new event with id: {eventContract.Id}";

            Logger.LogInformation(msg);
            return(msg);
        }
예제 #4
0
 /// <summary>
 /// Tries the set member.
 /// </summary>
 /// <param name="binder">The binder.</param>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public override bool TrySetMember(SetMemberBinder binder, object value)
 {
     if (base.TrySetMember(binder, value))
     {
         if (value is AddRemoveMarker m)
         {
             if (m.IsAdding)
             {
                 if (m.Delegate is Delegate md)
                 {
                     value = md;
                 }
                 else if (m.Delegate is Expression exp)
                 {
                     value = exp.GetContract(binder.Name);
                 }
                 else
                 {
                     value = null;
                     return(false);
                 }
             }
             else // -=
             {
                 if (m.Delegate is Delegate md)
                 {
                     var contract = new EventContract(binder.Name, md.Method.Name, false);
                     RemoteDelegates.Remove(contract.Description);
                     value = contract;
                 }
                 else if (m.Delegate is Expression exp)
                 {
                     var contract = exp.GetContract(binder.Name);
                     contract.IsAdd = false;
                     value          = contract;
                 }
                 else
                 {
                     value = null;
                 }
             }
         }
         if (value is Delegate d)
         {
             var contract = new EventContract(binder.Name, d.Method.Name, true);
             RemoteDelegates[contract.Description] = d;
             value = contract;
         }
         Agent.Execute(new RemoteInvocation(InvocationKind.Set, binder.Name, value));
         return(true);
     }
     return(false);
 }
예제 #5
0
    IEnumerator Creation()
    {
        yield return(new WaitForSeconds(0.1f));

        _currentVisitor    = Instantiate(_standardVisitor);
        _contractCurrent   = Instantiate(_standardContract);
        _dataInfo          = _dbContract.getBestContract();
        _contractBehaviour = _contractCurrent.GetComponent <ContractBehaviour>();
        _contractInfo      = _contractCurrent.GetComponent <ContractInfo>();
        _contractInfo.updateInfoContract(_dataInfo);
        _contractCurrent.transform.parent        = _currentVisitor.transform.GetChild(0).transform;
        _contractCurrent.transform.localRotation = new Quaternion(0, 0, 0, 0);
    }
예제 #6
0
        public async Task <string> TriggerEvent(string eventMessage)
        {
            var eventContract = new EventContract {
                Event = eventMessage
            };

            await TriggerEvent(eventContract);

            var msg = $"Triggered new event with id: {eventContract.Id} and message: '{eventContract.Event}'";

            Logger.LogInformation(msg);
            return(msg);
        }
예제 #7
0
        public static Task Execute(
            IDbConfig dbConfig,
            IDbConnection dbConnection,
            EventContract eventContract)
        {
            var @params = new DynamicParameters();

            @params.Add(Columns.Id, dbConfig.CreateParameterResolver().WithGuidParameterValue(eventContract.Id));
            @params.Add(Columns.Event, eventContract.Event);
            @params.Add(Columns.Stop, dbConfig.CreateParameterResolver().WithBooleanParameterValue(eventContract.Stop));
            var sql = dbConfig.BuildSql();

            return(dbConnection.ExecuteAsync(sql, @params));
        }
예제 #8
0
        public async Task TriggerEvent([FromBody] EventContract eventContract)
        {
            Logger.LogInformation($"Storing event with id {eventContract.Id.ToString()} in outbox for publishing.");

            if (eventContract.Event.Length > EventContract.MaxEventLength)
            {
                eventContract.Event = eventContract.Event.Substring(0, EventContract.MaxEventLength);
            }

            using (var rebusTransactionScope = new RebusTransactionScope())
            {
                await Bus.Advanced.Topics.Publish(EventContract.Topic, eventContract);

                rebusTransactionScope.Complete();
            }

            Logger.LogInformation($"Event with id {eventContract.Id.ToString()} successfully stored in outbox.");
        }
예제 #9
0
        public async Task TestEventContractAsync()
        {
            var factory = new FakeConnectionFactory();
            var pusher  = new Pusher(factory, "abcd1234", new Options()
            {
                Authenticator = new FakeAuthenticator()
            });

            pusher.AddContract(EventContract.Create <FakeEvent>("fooHappened"));
            await pusher.ConnectAsync();

            var sentEvent = new IncomingEvent <FakeEvent>
            {
                Channel    = "foo",
                DataObject = new FakeEvent {
                    Id = 1, Text = "foo"
                },
                EventName = "fooHappened"
            };
            var channel = await pusher.SubscribeToChannelAsync("foo");

            var eventsReceived = 0;

            channel.GetEventSubscription <FakeEvent>().EventEmitted += (sender, receivedEvent) =>
            {
                Assert.AreEqual(sentEvent.DataObject.Id, receivedEvent.DataObject.Id);
                Assert.AreEqual(sentEvent.DataObject.Text, receivedEvent.DataObject.Text);
                Assert.AreEqual(sentEvent.EventName, receivedEvent.EventName);
                Assert.AreEqual(sentEvent.Channel, receivedEvent.Channel);
                eventsReceived++;
            };

            channel.EventEmitted += (sender, receivedEvent) =>
            {
                Assert.AreEqual(sentEvent.EventName, receivedEvent.EventName);
                Assert.AreEqual(sentEvent.Channel, receivedEvent.Channel);
                eventsReceived++;

                Assert.AreEqual(typeof(IncomingEvent <FakeEvent>), receivedEvent.GetType());
            };

            factory.LastCreated.SendData(JsonConvert.SerializeObject(sentEvent));
            Assert.AreEqual(2, eventsReceived);
        }
예제 #10
0
 /// <summary>
 /// 创建一个新实例
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 public void Create(T_UserEntity pEntity)
 {
     _currentDAO.Create(pEntity);
     try
     {
         var msg = new EventContract
         {
             Operation  = OptEnum.Create,
             EntityType = EntityTypeEnum.User,
             Id         = pEntity.user_id
         };
         var service = new EventService();
         service.PublishMsg(msg);
     }
     catch (Exception)
     {
         throw new Exception("RabbitMQ Error");
     }
 }
예제 #11
0
        public void Start()
        {
            _cancellationTokenSource = new();
            _loggerTask = Task.Factory.StartNew(() =>
            {
                string message;

                do
                {
                    GoBytes e = PInvoke.GetEvent();
                    message   = e.ConvertToString();
                    EventContract eventContract = GetEventContract(message);
                    if (eventContract != null)
                    {
                        HandleEvent(eventContract);
                    }
                } while (!string.IsNullOrEmpty(message));
            }, _cancellationTokenSource.Token);
        }
예제 #12
0
 public bool TryCreateEventContract(EventInfo evnt, out EventContract contract)
 {
     try
     {
         contract = new EventContract();
         contract.ParameterType = evnt.EventHandlerType
                                  .GetMethod("Invoke")
                                  .GetParameters()[1]
                                  .ParameterType;
         var displayAttribute = evnt.GetCustomAttribute <DisplayNameAttribute>();
         contract.Description = displayAttribute?.DisplayName;
         return(true);
     }
     catch
     {
         contract = null;
         return(false);
     }
 }
예제 #13
0
        public void Deal(EventContract msg)
        {
            var     bus = MqBusMgr.GetInstance();
            OptEnum operation;

            Enum.TryParse(msg.Operation.ToString(), out operation);
            var unitContract = new UnitContract
            {
                Operation = operation,
                UnitId    = msg.Id
            };

            if (msg.Operation != Zmind.EventBus.Contract.OptEnum.Delete)
            {
                var unitFacade = new t_unitFacade();
                var result     = unitFacade.GetUnitById(msg.Id);
                if (result == null)
                {
                    return;
                }
                unitContract.UnitCode      = result.unit_code;
                unitContract.UnitName      = result.unit_name;
                unitContract.TypeCode      = result.type_code;
                unitContract.ParentUnitId  = result.src_unit_id;
                unitContract.UnitNameEn    = result.unit_name_en;
                unitContract.UnitNameShort = result.unit_name_short;
                unitContract.City1Name     = result.city1_name;
                unitContract.City2Name     = result.city2_name;
                unitContract.City3Name     = result.city3_name;
                unitContract.UnitAddress   = result.unit_address;
                unitContract.UnitContact   = result.unit_contract;
                unitContract.UnitTel       = result.unit_tel;
                unitContract.UnitFax       = result.unit_fax;
                unitContract.UnitEmail     = result.unit_email;
                unitContract.UnitPostcode  = result.unit_postcode;
                unitContract.UnitRemark    = result.unit_remark;
                unitContract.CreateTime    = string.IsNullOrEmpty(result.create_time) ? null : DateTime.Parse(result.create_time);
                unitContract.ModifyTime    = string.IsNullOrEmpty(result.modify_time) ? null : DateTime.Parse(result.modify_time);
                unitContract.StoreType     = result.StoreType;
            }
            bus.Publish <IZmindToXgx>(unitContract);
        }
예제 #14
0
파일: ServiceRunner.cs 프로젝트: radtek/crm
        private void HandleEventContract(EventContract msg)
        {
            try
            {
                var service = PublishFactory.GetInstance(msg);

                _log.Debug(new {
                    from = "publish",
                    msg  = msg
                });

                if (service != null)
                {
                    service.Deal(msg);
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex);
            }
        }
예제 #15
0
        public void Deal(EventContract msg)
        {
            var     bus = MqBusMgr.GetInstance();
            OptEnum operation;

            Enum.TryParse(msg.Operation.ToString(), out operation);
            var userContract = new UserContract
            {
                Operation = operation,
                UnitId    = msg.Id
            };

            if (msg.Operation != Zmind.EventBus.Contract.OptEnum.Delete)
            {
                var userFacade = new T_UserFacade();
                var result     = userFacade.GetUserById(msg.Id);
                if (result == null)
                {
                    return;
                }
                userContract.UserCode      = result.user_code;
                userContract.UserName      = result.user_name;
                userContract.UserTelephone = result.user_telephone;
                userContract.CreateTime    = string.IsNullOrEmpty(result.create_time) ? null : DateTime.Parse(result.create_time);
                userContract.ModifyTime    = string.IsNullOrEmpty(result.modify_time) ? null : DateTime.Parse(result.modify_time);
                userContract.UnitId        = result.unit_id;
                userContract.RoleCode      = new List <RoleEnum>();
                var roleResult = userFacade.GetUserRoleCode(msg.Id);
                if (roleResult != null)
                {
                    foreach (var i in roleResult)
                    {
                        RoleEnum role;
                        Enum.TryParse(i, out role);
                        userContract.RoleCode.Add(role);
                    }
                }
            }
            bus.Publish <IZmindToXgx>(userContract);
        }
예제 #16
0
        public void PublishMsg(EventContract contract)
        {
            var bus = MqBusMgr.GetInstance();

            if (!ConfigMgr.IsOpenEventBus)
            {
                return;
            }
            if (contract.EntityType == EntityTypeEnum.Vip && ConfigMgr.IsOpenVipEvent)
            {
                bus.Publish(contract);
            }
            else if (contract.EntityType == EntityTypeEnum.Unit && ConfigMgr.IsOpenUnitEvent)
            {
                bus.Publish(contract);
            }
            else if (contract.EntityType == EntityTypeEnum.User && ConfigMgr.IsOpenUserEvent)
            {
                bus.Publish(contract);
            }
            else if (contract.EntityType == EntityTypeEnum.Order && ConfigMgr.IsOpenOrderEvent)
            {
                bus.Publish(contract);
            }
            else if (contract.EntityType == EntityTypeEnum.VipCardType && ConfigMgr.IsOpenVipCardTypeEvent)
            {
                bus.Publish(contract);
            }
            else if (contract.EntityType == EntityTypeEnum.OrderComment && ConfigMgr.IsOpenOrderEvaluationEvent)
            {
                bus.Publish(contract);
            }
            else if (contract.EntityType == EntityTypeEnum.OrderPayment && ConfigMgr.IsOpenOrderPaymanetEvent)
            {
                bus.Publish(contract);
            }
        }
예제 #17
0
        public void Deal(EventContract msg)
        {
            var     bus = MqBusMgr.GetInstance();
            OptEnum operation;

            Enum.TryParse(msg.Operation.ToString(), out operation);
            var paymentDetails = new OrderPaymentDetailsContract()
            {
                Operation = operation
            };

            if (msg.Operation != Zmind.EventBus.Contract.OptEnum.Delete)
            {
                var paymentFacade = new PaymentDetailFacade();
                var result        = paymentFacade.GetPaymentById(msg.Id);

                paymentDetails.OrderId     = result.Inout_Id;
                paymentDetails.PayAmount   = result.Price;
                paymentDetails.PayTime     = result.CreateTime;
                paymentDetails.PaymentType = GetEnumByCode(result.Payment_Type_Code);
            }

            bus.Publish <IZmindToXgx>(paymentDetails);
        }
예제 #18
0
        protected override EmptyResponseData ProcessRequest(APIRequest <UpdateVipCardTypeRP> pRequest)
        {
            var rd   = new EmptyResponseData();
            var para = pRequest.Parameters;
            LoggingSessionInfo loggingSessionInfo = Default.GetBSLoggingSession(pRequest.CustomerID, pRequest.UserID);
            var bllVip = new VipBLL(loggingSessionInfo);
            var bllVipCardVipMapping = new VipCardVipMappingBLL(loggingSessionInfo);
            //获取当前会员信息
            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();

            try
            {
                string strObjectNo = string.Empty;
                if (vipInfo != null)
                {
                    //根据当前会员执行变更卡操作
                    strObjectNo = bllVipCardVipMapping.BindVirtualItem(vipInfo.VIPID, vipInfo.VipCode, vipInfo.CouponInfo, para.VipCardTypeID);
                    if (string.IsNullOrEmpty(strObjectNo))
                    {
                        throw new APIException("绑定失败!")
                              {
                                  ErrorCode = ERROR_CODES.INVALID_BUSINESS
                              };
                    }
                    else
                    {
                        //同步相关会员信息(姓名、性别、生日、邮箱、积分、消费金额、消费次数、状态)
                        bllVip.MergeVipInfo(pRequest.CustomerID, pRequest.UserID, vipInfo.Phone, para.BindVipID);
                        //记录会员信息改变,并且把旧的会员的标识也放在契约里
                        var eventService = new EventService();
                        var vipMsg       = new EventContract
                        {
                            Operation  = OptEnum.Update,
                            EntityType = EntityTypeEnum.Vip,
                            Id         = pRequest.UserID,
                            OtherCon   = para.BindVipID
                        };
                        eventService.PublishMsg(vipMsg);

                        throw new APIException("绑定成功!")
                              {
                                  ErrorCode = 0
                              };
                    }
                }
            }
            catch (APIException ex) { throw ex; }
            return(rd);
        }
예제 #19
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            var OrderID     = context.Request["OrderID"];
            var OrderStatus = context.Request["OrderStatus"];
            var CustomerID  = context.Request["CustomerID"];
            var UserID      = context.Request["UserID"];
            var ChannelID   = context.Request["ChannelID"];
            var SerialPay   = context.Request["SerialPay"];

            try
            {
                if (string.IsNullOrEmpty(OrderID) || string.IsNullOrEmpty(OrderStatus) || string.IsNullOrEmpty(CustomerID) || string.IsNullOrEmpty(UserID) || string.IsNullOrEmpty(ChannelID))
                {
                    throw new Exception("参数不全:OrderID,OrderStatus,CustomerID,UserID");
                }
                else
                {
                    if (OrderStatus == "2")
                    {
                        //支付成功,更新卡的支付状态
                        //OrderID就是VIPCardID
                        //
                        //var rp = pRequest.DeserializeJSONTo<APIRequest<SetVipCardRP>>();

                        //if (string.IsNullOrEmpty(rp.Parameters.PayID))
                        //{
                        //    throw new APIException("缺少参数【PayID】或参数值为空") { ErrorCode = 135 };
                        //}
                        var loggingSessionInfo = Default.GetBSLoggingSession(CustomerID, UserID);
                        //会员
                        var vipBll               = new VipBLL(loggingSessionInfo);
                        var vipAmountBll         = new VipAmountBLL(loggingSessionInfo);
                        var vipCardVipMappingBll = new VipCardVipMappingBLL(loggingSessionInfo);
                        //支付
                        var tPaymentTypeCustomerMappingBll = new TPaymentTypeCustomerMappingBLL(loggingSessionInfo);
                        var tPaymentTypeBll  = new T_Payment_TypeBLL(loggingSessionInfo);
                        var paymentDetailBll = new T_Payment_detailBLL(loggingSessionInfo);
                        //门店
                        var unitBLL = new t_unitBLL(loggingSessionInfo);
                        //商品订单支付
                        //更新积分和状态
                        //var loggingSessionInfo = Default.GetBSLoggingSession(CustomerID, "1");
                        var inoutBll = new T_InoutBLL(loggingSessionInfo);//订单业务对象实例化

                        var trrBll = new T_RewardRecordBLL(loggingSessionInfo);
                        //辨别打赏订单
                        var rewardOrderPrefix = "REWARD|";
                        if (OrderID.Contains(rewardOrderPrefix))
                        {
                            OrderID = OrderID.Substring(rewardOrderPrefix.Length, OrderID.Length - rewardOrderPrefix.Length);
                            var trrEntity = trrBll.GetByID(OrderID);
                            trrEntity.PayStatus      = 2;
                            trrEntity.LastUpdateTime = DateTime.Now;
                            trrEntity.LastUpdateBy   = loggingSessionInfo.UserID;
                            trrBll.Update(trrEntity);

                            #region 员工余额变更--需要独立出来处理
                            var userAmountBll = new VipAmountBLL(loggingSessionInfo);                                 //作为员工余额使用
                            var employeeId    = trrEntity.RewardedOP;
                            var rewardAmount  = trrEntity.RewardAmount == null ? 0 : (decimal)trrEntity.RewardAmount; //转为非null的decimal类型
                            //门店
                            var unitService = new UnitService(loggingSessionInfo);
                            var unitInfo    = unitService.GetUnitByUser(CustomerID, employeeId).FirstOrDefault();//获取员工所属门店

                            var tran = userAmountBll.GetTran();
                            using (tran.Connection)//事务
                            {
                                try
                                {
                                    var userAmountEntity = userAmountBll.GetByID(trrEntity.RewardedOP);
                                    if (userAmountEntity == null)
                                    {
                                        //创建
                                        userAmountEntity = new VipAmountEntity
                                        {
                                            VipId                  = employeeId,//员工ID
                                            VipCardCode            = string.Empty,
                                            BeginAmount            = 0,
                                            InAmount               = rewardAmount,
                                            OutAmount              = 0,
                                            EndAmount              = rewardAmount,
                                            TotalAmount            = rewardAmount,
                                            BeginReturnAmount      = 0,
                                            InReturnAmount         = 0,
                                            OutReturnAmount        = 0,
                                            ReturnAmount           = 0,
                                            ImminentInvalidRAmount = 0,
                                            InvalidReturnAmount    = 0,
                                            ValidReturnAmount      = 0,
                                            TotalReturnAmount      = 0,
                                            IsLocking              = 0,
                                            CustomerID             = CustomerID
                                        };
                                        userAmountBll.Create(userAmountEntity, tran);//创建员工余额表
                                    }
                                    else
                                    {
                                        //修改
                                        if (rewardAmount > 0)
                                        {
                                            userAmountEntity.InAmount    = (userAmountEntity.InAmount == null ? 0 : userAmountEntity.InAmount.Value) + rewardAmount;
                                            userAmountEntity.TotalAmount = (userAmountEntity.TotalAmount == null ? 0 : userAmountEntity.TotalAmount.Value) + rewardAmount;
                                        }
                                        else
                                        {
                                            userAmountEntity.OutAmount = (userAmountEntity.OutAmount == null ? 0 : userAmountEntity.OutAmount.Value) + Math.Abs(rewardAmount);
                                        }
                                        userAmountEntity.EndAmount = (userAmountEntity.EndAmount == null ? 0 : userAmountEntity.EndAmount.Value) + rewardAmount;

                                        userAmountBll.Update(userAmountEntity, tran);//更新余额
                                    }

                                    var vipamountDetailBll    = new VipAmountDetailBLL(loggingSessionInfo);
                                    var vipAmountDetailEntity = new VipAmountDetailEntity
                                    {
                                        VipAmountDetailId = Guid.NewGuid(),
                                        VipCardCode       = string.Empty,
                                        VipId             = employeeId,//员工ID
                                        UnitID            = unitInfo != null ? unitInfo.unit_id : string.Empty,
                                        UnitName          = unitInfo != null ? unitInfo.Name : string.Empty,
                                        Amount            = rewardAmount,
                                        UsedReturnAmount  = 0,
                                        EffectiveDate     = DateTime.Now,
                                        DeadlineDate      = Convert.ToDateTime("9999-12-31 23:59:59"),
                                        AmountSourceId    = "26",
                                        Reason            = "Reward",
                                        CustomerID        = CustomerID
                                    };
                                    vipamountDetailBll.Create(vipAmountDetailEntity, tran); //创建余额详情

                                    tran.Commit();                                          //提交事务
                                }
                                catch (Exception ex)
                                {
                                    tran.Rollback();
                                    Loggers.Debug(new DebugLogInfo()
                                    {
                                        Message = "异常-->支付成功回调时更新会员打赏金额出错(PayNotify.ashx):" + ex
                                    });
                                }
                            }
                            #endregion

                            if (trrEntity != null)
                            {
                                context.Response.Write("SUCCESS");
                            }
                            else
                            {
                                context.Response.Write("FAIL");
                            }
                            return;
                        }
                        //获取会员信息
                        var vipInfo = vipBll.GetByID(loggingSessionInfo.UserID);
                        //支付信息 Bear
                        //var tPaymentTypeCustomerMappingEntity = tPaymentTypeCustomerMappingBll.QueryByEntity(new TPaymentTypeCustomerMappingEntity(){ChannelId = ChannelID,CustomerId = loggingSessionInfo.ClientID },null).FirstOrDefault();
                        var paymentTypeList = tPaymentTypeBll.GetAll();
                        var tPaymentType    =
                            paymentTypeList.ToList()
                            .Find(t => t.Payment_Type_Code == "WXJS");

                        //var tPaymentType = tPaymentTypeBll.GetByID(tPaymentTypeCustomerMappingEntity.PaymentTypeID);
                        //获取订单信息
                        var inoutInfo = inoutBll.GetByID(OrderID);
                        if (inoutInfo != null)
                        {
                            var    bll = new TInOutStatusNodeBLL(loggingSessionInfo);
                            string msg;
                            if (!bll.SetOrderPayment(OrderID, out msg, ChannelID, SerialPay))
                            //if (!bll.SetOrderPayment(OrderID, out msg, ChannelID))
                            {
                                throw new Exception(msg);
                            }
                            else if (string.IsNullOrEmpty(inoutInfo.Field17) && string.IsNullOrEmpty(inoutInfo.Field18))
                            {
                                #region 发送订单支付成功微信模板消息
                                var SuccessCommonBLL = new CommonBLL();
                                //SuccessCommonBLL.SentPaymentMessage(inoutInfo, vipInfo.WeiXinUserId,vipInfo.VIPID, loggingSessionInfo);
                                new SendOrderPaySuccessMsgBLL().SentPaymentMessage(inoutInfo, vipInfo.WeiXinUserId, vipInfo.VIPID, loggingSessionInfo);
                                #endregion
                                Loggers.Debug(new DebugLogInfo()
                                {
                                    Message = "调用SetOrderPayment方法更新订单成功"
                                });
                            }
                            //获取订单信息,根据Field3==1判断,如果是ALD订单,则调用ALD接口更新ALD订单的状态
                            #region 更新ALD状态
                            //var orderbll = new InoutService(loggingSessionInfo);
                            //var orderInfo = orderbll.GetInoutInfoById(OrderID);
                            //if (orderInfo.Field3 == "1")
                            //{
                            //    Loggers.Debug(new DebugLogInfo() { Message = string.Format("更新O2OMarketing订单状态成功[OrderID={0}].", OrderID) });
                            //    //更新阿拉丁的订单状态
                            //    JIT.CPOS.Web.OnlineShopping.data.DataOnlineShoppingHandler.ALDChangeOrderStatus aldChangeOrder = new data.DataOnlineShoppingHandler.ALDChangeOrderStatus();
                            //    if (string.IsNullOrEmpty(orderInfo.vip_no))
                            //        throw new Exception("会员ID不能为空,OrderID:" + OrderID);
                            //    aldChangeOrder.MemberID = new Guid(orderInfo.vip_no);
                            //    aldChangeOrder.SourceOrdersID = OrderID;
                            //    aldChangeOrder.Status = int.Parse(orderInfo.status);
                            //    aldChangeOrder.IsPaid = true;
                            //    JIT.CPOS.Web.OnlineShopping.data.DataOnlineShoppingHandler.ALDChangeOrderStatusRequest aldRequest = new data.DataOnlineShoppingHandler.ALDChangeOrderStatusRequest();
                            //    aldRequest.BusinessZoneID = 1;//写死
                            //    aldRequest.Locale = 1;

                            //    aldRequest.UserID = new Guid(orderInfo.vip_no);
                            //    aldRequest.Parameters = aldChangeOrder;
                            //    var url = ConfigurationManager.AppSettings["ALDGatewayURL"];
                            //    var postContent = string.Format("Action=ChangeOrderStatus&ReqContent={0}", aldRequest.ToJSON());
                            //    Loggers.Debug(new DebugLogInfo() { Message = "通知ALD更改状态:" + postContent });
                            //    var strAldRsp = HttpWebClient.DoHttpRequest(url, postContent);
                            //    var aldRsp = strAldRsp.DeserializeJSONTo<JIT.CPOS.Web.OnlineShopping.data.DataOnlineShoppingHandler.ALDResponse>();
                            //    if (!aldRsp.IsSuccess())
                            //    {
                            //        Loggers.Debug(new DebugLogInfo() { Message = string.Format("更新阿拉丁订单状态失败[Request ={0}][Response={1}]", aldRequest.ToJSON(), strAldRsp) });
                            //    }
                            //}
                            #endregion

                            #region 格力推送通知
                            //try
                            //{
                            //    GLServiceOrderBLL glsobll = new GLServiceOrderBLL(loggingSessionInfo);
                            //    if (glsobll.ValidateGree(CustomerID, "cpos_bs_lj"))//先写死
                            //        glsobll.GreePushPaymentOorder(CustomerID, OrderID, loggingSessionInfo);
                            //}
                            //catch (Exception ex)
                            //{
                            //    Loggers.Debug(new DebugLogInfo() { Message = string.Format("付款推送评价师傅链接失败[OrderID={0}].", OrderID) });
                            //}
                            #endregion

                            #region ALD生活服务处理
                            //var rechargeBll = new RechargeStrategyBLL(loggingSessionInfo);
                            //var vipAmountBll = new VipAmountBLL(loggingSessionInfo);
                            //var couponBll = new CouponBLL(loggingSessionInfo);
                            //var vipCouponMappingBll = new VipCouponMappingBLL(loggingSessionInfo);
                            //var unitBll = new UnitBLL(loggingSessionInfo);
                            //DataSet dsOrderInfo = rechargeBll.GetInoutOrderItems(OrderID);
                            //int itemSort = 0;            //商品业务分类
                            //string skuId = string.Empty; //商品SkuId
                            //string vipId = string.Empty; //会员ID
                            //string itemId = string.Empty;//商品ID
                            //string couponId = string.Empty;//优惠券ID
                            //if (dsOrderInfo.Tables[0].Rows.Count > 0)
                            //{
                            //    //if (dsOrderInfo.Tables[0].Rows[0]["ItemSort"] != DBNull.Value && Convert.ToString(dsOrderInfo.Tables[0].Rows[0]["ItemSort"]) != "0")
                            //    itemSort = int.Parse(dsOrderInfo.Tables[0].Rows[0]["ItemSort"].ToString());
                            //    switch (itemSort)
                            //    {
                            //        case 2://充
                            //            #region 充值金额处理

                            //            VipAmountDetailBLL vipAmountDetailBll = new VipAmountDetailBLL(loggingSessionInfo);

                            //            List<IWhereCondition> complexCondition = new List<IWhereCondition> { };
                            //            complexCondition.Add(new EqualsCondition() { FieldName = "ObjectId", Value = OrderID });

                            //            var vipAmountDetal = vipAmountDetailBll.Query(complexCondition.ToArray(), null);
                            //            if (vipAmountDetal.Count() == 0)//确认没有多次执行回调
                            //            {
                            //                ////查询
                            //                //RechargeStrategyEntity[] rechargeList = rechargeBll.Query(complexCondition.ToArray(), lstOrder.ToArray());

                            //                skuId = dsOrderInfo.Tables[0].Rows[0]["SkuId"].ToString();
                            //                //RechargeStrategyEntity rechargeEntity = rechargeBll.GetByID(skuId);
                            //                DataSet dsSkuPirce = unitBll.GetSkuPirce(skuId);
                            //                decimal salePrice = 0;//购买金额
                            //                decimal returnCash = 0;//奖励金额
                            //                if (dsSkuPirce.Tables[0].Rows.Count > 0)
                            //                {
                            //                    salePrice = Convert.ToDecimal(dsSkuPirce.Tables[0].Rows[0]["SalesPrice"].ToString());
                            //                    returnCash = Convert.ToDecimal(dsSkuPirce.Tables[0].Rows[0]["ReturnCash"].ToString());
                            //                    InoutService server = new InoutService(loggingSessionInfo);
                            //                    #region 充值金额
                            //                    var tran = server.GetTran();
                            //                    using (tran.Connection)//事物
                            //                    {
                            //                        try
                            //                        {
                            //                            //充值金额
                            //                            vipAmountBll.AddVipEndAmount(UserID, salePrice, tran, "4", OrderID, loggingSessionInfo);//4=充值
                            //                            tran.Commit();
                            //                        }
                            //                        catch (Exception)
                            //                        {
                            //                            tran.Rollback();
                            //                            throw;
                            //                        }
                            //                    }
                            //                    #endregion

                            //                    #region 奖励金额
                            //                    var tran2 = server.GetTran();
                            //                    using (tran2.Connection)//事物
                            //                    {
                            //                        try
                            //                        {
                            //                            //奖励金额
                            //                            vipAmountBll.AddVipEndAmount(UserID, returnCash, tran2, "6", OrderID, loggingSessionInfo);//6=奖励金额
                            //                            tran2.Commit();
                            //                        }
                            //                        catch (Exception)
                            //                        {
                            //                            tran2.Rollback();
                            //                            throw;
                            //                        }
                            //                    }
                            //                    #endregion
                            //                }
                            //            }
                            //            #endregion
                            //            break;
                            //        case 3://券
                            //            #region 券类商品绑定到会员
                            //            itemId = dsOrderInfo.Tables[0].Rows[0]["ItemId"].ToString();
                            //            vipId = dsOrderInfo.Tables[0].Rows[0]["VipId"].ToString();
                            //            couponId = couponBll.GetCouponByItemId(itemId);
                            //            if (!string.IsNullOrEmpty(couponId))
                            //            {
                            //                VipCouponMappingEntity coupon = new VipCouponMappingEntity
                            //                {
                            //                    VIPID = vipId,
                            //                    CouponID = couponId,
                            //                };
                            //                vipCouponMappingBll.Create(coupon);
                            //            }
                            //            #endregion
                            //            break;
                            //        default:
                            //            break;
                            //    }
                            //}

                            #endregion

                            #region 订单与分润关系处理 add by Henry 2014-10-10
                            //var orderSubBll = new OrderOrderSubRunObjectMappingBLL(loggingSessionInfo);
                            //dynamic o = orderSubBll.SetOrderSub(CustomerID, OrderID);
                            //Type t = o.GetType();
                            //var Desc = t.GetProperty("Desc").GetValue(o, null).ToString();
                            //var IsSuccess = t.GetProperty("IsSuccess").GetValue(o, null).ToString();
                            //if (int.Parse(IsSuccess.ToString()) == 0) //失败
                            //    Loggers.Debug(new DebugLogInfo() { Message = string.Format("订单与分润关系处理失败:{0}", Desc) });
                            #endregion

                            CustomerBasicSettingBLL customerBasicSettingBll = new CustomerBasicSettingBLL(loggingSessionInfo);
                            string AfterPaySetStock = customerBasicSettingBll.GetSettingValueByCode("AfterPaySetStock");
                            if (AfterPaySetStock == "1")
                            {
                                var inoutServiceBLL = new InoutService(loggingSessionInfo);
                                var inoutDetailList = inoutServiceBLL.GetInoutDetailInfoByOrderId(OrderID);
                                inoutBll.SetStock(OrderID, inoutDetailList, 1, loggingSessionInfo);
                            }
                            ///超级分销商订单入队列
                            if (inoutInfo.data_from_id == "35" || inoutInfo.data_from_id == "36")
                            {
                                BS.BLL.RedisOperationBLL.Order.SuperRetailTraderOrderBLL bllSuperRetailTraderOrder = new BS.BLL.RedisOperationBLL.Order.SuperRetailTraderOrderBLL();
                                bllSuperRetailTraderOrder.SetRedisToSuperRetailTraderOrder(loggingSessionInfo, inoutInfo);
                            }

                            //购卡
                            if (!string.IsNullOrEmpty(inoutInfo.Field17) && !string.IsNullOrEmpty(inoutInfo.Field18))
                            {
                                //更新订单状态
                                inoutInfo             = inoutBll.GetByID(OrderID);
                                inoutInfo.Field7      = "700";
                                inoutInfo.status      = "700";
                                inoutInfo.status_desc = "已完成";
                                inoutInfo.Field10     = "已完成";
                                inoutBll.Update(inoutInfo);
                                //会员卡升级
                                vipCardVipMappingBll.BindVirtualItem(vipInfo.VIPID, vipInfo.VipCode, inoutInfo.sales_unit_id, Convert.ToInt32(inoutInfo.Field18), orderId: inoutInfo.order_id);

                                //分润计算
                                RedisSalesVipCardOrderBLL redisSalesVipCardOrderBll = new RedisSalesVipCardOrderBLL();
                                redisSalesVipCardOrderBll.SetRedisSalesVipCardOrder(loggingSessionInfo, inoutInfo);

                                //售卡处理积分、返现、佣金[完成订单]
                                new SendOrderRewardMsgBLL().OrderReward(inoutInfo, loggingSessionInfo, null);//存入到缓存
                            }
                            else
                            {
                                //订单入队列
                                RedisCalculateVipConsumeForUpgrade redisCalculateVipConsumeForUpgrade = new RedisCalculateVipConsumeForUpgrade();
                                redisCalculateVipConsumeForUpgrade.SetVipConsumeForUpgradeList(loggingSessionInfo, inoutInfo);
                            }

                            // add by liangx 2016-09-27 获取订单中的虚拟商品 start
                            CouponTypeBLL            couponTypeBLL            = new CouponTypeBLL(loggingSessionInfo);
                            RedisVipMappingCouponBLL redisVipMappingCouponBLL = new RedisVipMappingCouponBLL();

                            var couponTypes = couponTypeBLL.GetVirtualItemCouponTypes(inoutInfo.order_id);

                            if (couponTypes.Any())
                            {
                                redisVipMappingCouponBLL.SetVipMappingCoupon(couponTypes, "", couponTypes.FirstOrDefault().VipId, "PayVirtualItem");
                            }

                            // add by liangx 2016-09-27 获取订单中的虚拟商品 end

                            //获取门店信息
                            t_unitEntity unitInfo = null;
                            if (!string.IsNullOrEmpty(inoutInfo.sales_unit_id))
                            {
                                unitInfo = unitBLL.GetByID(inoutInfo.sales_unit_id);
                            }
                            //入支付明细表
                            var paymentDetail = new T_Payment_detailEntity()
                            {
                                Payment_Id        = Guid.NewGuid().ToString(),
                                Inout_Id          = inoutInfo.order_id,
                                UnitCode          = unitInfo == null ? "" : unitInfo.unit_code,
                                Payment_Type_Id   = tPaymentType.Payment_Type_Id,
                                Payment_Type_Code = tPaymentType.Payment_Type_Code,
                                Payment_Type_Name = tPaymentType.Payment_Type_Name,
                                Price             = inoutInfo.actual_amount,
                                Total_Amount      = inoutInfo.total_amount,
                                Pay_Points        = inoutInfo.pay_points,
                                CustomerId        = loggingSessionInfo.ClientID
                            };
                            paymentDetailBll.Create(paymentDetail);

                            List <IWhereCondition> complexCondition = new List <IWhereCondition> {
                            };
                            complexCondition.Add(new EqualsCondition()
                            {
                                FieldName = "Inout_Id", Value = inoutInfo.order_id
                            });
                            var paymentDetailList = paymentDetailBll.Query(complexCondition.ToArray(), null);

                            try
                            {
                                var msgRabbitMQ = new EventContract
                                {
                                    Operation  = OptEnum.Create,
                                    EntityType = EntityTypeEnum.Order,
                                    Id         = inoutInfo.order_id
                                };
                                var service = new EventService();
                                service.PublishMsg(msgRabbitMQ);

                                foreach (var detail in paymentDetailList)
                                {
                                    var paymentMQ = new EventContract
                                    {
                                        Operation  = OptEnum.Create,
                                        EntityType = EntityTypeEnum.OrderPayment,
                                        Id         = detail.Payment_Id
                                    };
                                    service.PublishMsg(paymentMQ);
                                }
                            }
                            catch (Exception)
                            {
                                throw new Exception("RabbitMQ Error");
                            }
                        }
                        else//充值订单
                        {
                            var rechargeOrderBll   = new RechargeOrderBLL(loggingSessionInfo);
                            var vipamountDetailBll = new VipAmountDetailBLL(loggingSessionInfo);
                            var rechargeOrderInfo  = rechargeOrderBll.GetByID(OrderID);
                            if (rechargeOrderInfo != null)
                            {
                                //获取门店信息
                                t_unitEntity unitInfo = null;
                                if (!string.IsNullOrEmpty(rechargeOrderInfo.UnitId))
                                {
                                    unitInfo = unitBLL.GetByID(rechargeOrderInfo.UnitId);
                                }
                                //充值
                                rechargeOrderBll.Recharge(rechargeOrderInfo, vipInfo, unitInfo, tPaymentType.Payment_Type_Id);
                                //入支付明细表
                                var paymentDetail = new T_Payment_detailEntity()
                                {
                                    Payment_Id        = Guid.NewGuid().ToString(),
                                    Inout_Id          = rechargeOrderInfo.OrderID.ToString(),
                                    UnitCode          = unitInfo == null ? "" : unitInfo.unit_code,
                                    Payment_Type_Id   = tPaymentType.Payment_Type_Id,
                                    Payment_Type_Code = tPaymentType.Payment_Type_Code,
                                    Payment_Type_Name = tPaymentType.Payment_Type_Name,
                                    Price             = rechargeOrderInfo.ActuallyPaid,
                                    Total_Amount      = rechargeOrderInfo.TotalAmount,
                                    Pay_Points        = rechargeOrderInfo.PayPoints,
                                    CustomerId        = loggingSessionInfo.ClientID
                                };
                                paymentDetailBll.Create(paymentDetail);
                            }
                            else
                            {
                                var receiveAmountOrderBll    = new ReceiveAmountOrderBLL(loggingSessionInfo);
                                var receiveAmountOrderEntity = receiveAmountOrderBll.GetByID(OrderID);



                                //更新订单状态
                                if (receiveAmountOrderEntity != null)
                                {
                                    VipIntegralBLL vipIntegralBll = new VipIntegralBLL(loggingSessionInfo);
                                    //更新订单
                                    receiveAmountOrderEntity.PayStatus = "10";
                                    // Bear
                                    //receiveAmountOrderEntity.PayTypeId = tPaymentTypeCustomerMappingEntity.PaymentTypeID;
                                    receiveAmountOrderEntity.PayTypeId    = tPaymentType.Payment_Type_Id;
                                    receiveAmountOrderEntity.PayDatetTime = DateTime.Now;
                                    receiveAmountOrderBll.Update(receiveAmountOrderEntity);

                                    //获取门店信息
                                    t_unitEntity unitInfo = null;
                                    if (!string.IsNullOrEmpty(receiveAmountOrderEntity.ServiceUnitId))
                                    {
                                        unitInfo = unitBLL.GetByID(receiveAmountOrderEntity.ServiceUnitId);
                                    }


                                    //使用过积分,处理积分
                                    if (receiveAmountOrderEntity.PayPoints != 0 && receiveAmountOrderEntity.PayPoints != null)
                                    {
                                        string sourceId       = "20"; //积分抵扣
                                        var    IntegralDetail = new VipIntegralDetailEntity()
                                        {
                                            Integral         = -Convert.ToInt32(receiveAmountOrderEntity.PayPoints),
                                            IntegralSourceID = sourceId,
                                            ObjectId         = receiveAmountOrderEntity.OrderId.ToString()
                                        };
                                        if (IntegralDetail.Integral != 0)
                                        {
                                            //变动前积分
                                            string OldIntegral = (vipInfo.Integration ?? 0).ToString();
                                            //变动积分
                                            string ChangeIntegral      = (IntegralDetail.Integral ?? 0).ToString();
                                            var    vipIntegralDetailId = vipIntegralBll.AddIntegral(ref vipInfo, unitInfo, IntegralDetail, loggingSessionInfo);
                                            //发送微信积分变动通知模板消息
                                            if (!string.IsNullOrWhiteSpace(vipIntegralDetailId))
                                            {
                                                var CommonBLL = new CommonBLL();
                                                CommonBLL.PointsChangeMessage(OldIntegral, vipInfo, ChangeIntegral, vipInfo.WeiXinUserId, loggingSessionInfo);
                                            }
                                        }
                                    }
                                    //if (receiveAmountOrderEntity.CouponUsePay != 0 || receiveAmountOrderEntity.CouponUsePay != null)
                                    //{
                                    //    //更新使用记录
                                    //    var couponUseBll = new CouponUseBLL(loggingSessionInfo);
                                    //    var couponUseEntity = new CouponUseEntity()
                                    //    {
                                    //        CouponUseID = Guid.NewGuid(),
                                    //        CouponID = rp.CouponId,
                                    //        VipID = vipInfo.VIPID,
                                    //        UnitID = rp.UnitId,
                                    //        OrderID = orderId.ToString(),
                                    //        Comment = "商城使用电子券",
                                    //        CustomerID = CurrentUserInfo.ClientID,
                                    //        CreateBy = CurrentUserInfo.UserID,
                                    //        CreateTime = DateTime.Now,
                                    //        LastUpdateBy = CurrentUserInfo.UserID,
                                    //        LastUpdateTime = DateTime.Now,
                                    //        IsDelete = 0
                                    //    };
                                    //    couponUseBll.Create(couponUseEntity);

                                    //    var couponBll = new CouponBLL(CurrentUserInfo);
                                    //    var couponEntity = couponBll.GetByID(rp.CouponId);

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

                                    //    //停用该优惠券
                                    //    couponEntity.Status = 1;
                                    //    couponBll.Update(couponEntity);
                                    //}

                                    //处理余额
                                    if (receiveAmountOrderEntity.AmountAcctPay != null && receiveAmountOrderEntity.AmountAcctPay != 0)
                                    {
                                        var vipAmountDetailBll = new VipAmountDetailBLL(loggingSessionInfo);

                                        var vipAmountEntity = vipAmountBll.QueryByEntity(new VipAmountEntity()
                                        {
                                            VipId = vipInfo.VIPID, VipCardCode = vipInfo.VipCode
                                        }, null).FirstOrDefault();
                                        if (vipAmountEntity != null)
                                        {
                                            var detailInfo = new VipAmountDetailEntity()
                                            {
                                                Amount         = -receiveAmountOrderEntity.AmountAcctPay,
                                                AmountSourceId = "1",
                                                ObjectId       = receiveAmountOrderEntity.OrderId.ToString()
                                            };
                                            var vipAmountDetailId = vipAmountBll.AddVipAmount(vipInfo, unitInfo, ref vipAmountEntity, detailInfo, loggingSessionInfo);
                                            if (!string.IsNullOrWhiteSpace(vipAmountDetailId))
                                            {//发送微信账户余额变动模板消息
                                                var CommonBLL = new CommonBLL();
                                                CommonBLL.BalanceChangedMessage(receiveAmountOrderEntity.OrderNo, vipAmountEntity, detailInfo, vipInfo.WeiXinUserId, vipInfo.VIPID, loggingSessionInfo);
                                            }
                                        }
                                    }


                                    //收款订单积分奖励

                                    vipIntegralBll.OrderReward(receiveAmountOrderEntity, null);


                                    var paymentDetail = new T_Payment_detailEntity()
                                    {
                                        Payment_Id        = Guid.NewGuid().ToString(),
                                        Inout_Id          = receiveAmountOrderEntity.OrderId.ToString(),
                                        UnitCode          = unitInfo == null ? "" : unitInfo.unit_code,
                                        Payment_Type_Id   = tPaymentType.Payment_Type_Id,
                                        Payment_Type_Code = tPaymentType.Payment_Type_Code,
                                        Payment_Type_Name = tPaymentType.Payment_Type_Name,
                                        Price             = receiveAmountOrderEntity.TransAmount,
                                        Total_Amount      = receiveAmountOrderEntity.TotalAmount,
                                        Pay_Points        = receiveAmountOrderEntity.PayPoints,
                                        CustomerId        = loggingSessionInfo.ClientID
                                    };
                                    paymentDetailBll.Create(paymentDetail);
                                }
                            }
                        }
                        context.Response.Write("SUCCESS");
                    }
                }
            }
            catch (Exception ex)
            {
                Loggers.Exception(new ExceptionLogInfo(ex));
                context.Response.Write("ERROR:" + ex.Message);
            }
        }
예제 #20
0
        const int MEMBER_HAVECARDNOTIPS    = 320; //领取成功 不提示 但跳到实体卡
        #endregion

        protected override AuthCodeLoginRD ProcessRequest(DTO.Base.APIRequest <AuthCodeLoginRP> pRequest)
        {
            var vipCardVipMappingBLL = new VipCardVipMappingBLL(CurrentUserInfo);

            //参数验证
            if (string.IsNullOrEmpty(pRequest.Parameters.Mobile))
            {
                throw new APIException("请求参数中缺少Mobile或值为空.")
                      {
                          ErrorCode = ERROR_LACK_MOBILE
                      };
            }
            if (pRequest.Parameters.VipSource.HasValue == false)
            {
                pRequest.Parameters.VipSource = 1;
                //throw new APIException("请求参数中缺少VipSource或值为空.") { ErrorCode = ERROR_LACK_VIP_SOURCE };
            }
            //
            AuthCodeLoginRD rd         = new AuthCodeLoginRD();
            var             bll        = new VipBLL(this.CurrentUserInfo);
            var             codebll    = new RegisterValidationCodeBLL(base.CurrentUserInfo);
            VipEntity       vipByID    = null; //根据VIP ID查找出来的VIP记录
            VipEntity       vipByPhone = null; //根据手机号查找出来的VIP记录


            //var list = codebll.QueryByEntity(new RegisterValidationCodeEntity()
            //{
            //    Mobile = pRequest.Parameters.Mobile
            //}, null);
            //bool b = false;
            //if (list != null)
            //{
            //    foreach (var entity in list)
            //    {
            //        if (entity == null)
            //            throw new APIException("未找到此手机的验证信息") {ErrorCode = ERROR_AUTHCODE_NOTEXISTS};
            //        //if (entity.IsValidated.Value == 1)
            //        //    throw new APIException("此验证码已被使用") {ErrorCode = ERROR_AUTHCODE_WAS_USED};
            //        //if (entity.Expires.Value < DateTime.Now)
            //        //    throw new APIException("此验证码已失效") {ErrorCode = ERROR_AUTHCODE_INVALID};
            //        if (entity.Code == pRequest.Parameters.AuthCode)
            //            b = true;
            //    }
            //}
            //if (!b)
            //{
            //    throw new APIException("验证码不正确.") { ErrorCode = ERROR_AUTHCODE_NOT_EQUALS };
            //}

            #region 验证验证码
            var entity = codebll.GetByMobile(pRequest.Parameters.Mobile);
            if (entity == null)
            {
                throw new APIException("未找到此手机的验证信息")
                      {
                          ErrorCode = ERROR_AUTHCODE_NOTEXISTS
                      }
            }
            ;
            if (entity.IsValidated.Value == 1)
            {
                throw new APIException("此验证码已被使用")
                      {
                          ErrorCode = ERROR_AUTHCODE_WAS_USED
                      }
            }
            ;
            if (entity.Expires.Value < DateTime.Now)
            {
                throw new APIException("此验证码已失效")
                      {
                          ErrorCode = ERROR_AUTHCODE_INVALID
                      }
            }
            ;
            if (entity.Code != pRequest.Parameters.AuthCode)
            {
                throw new APIException("验证码不正确.")
                      {
                          ErrorCode = ERROR_AUTHCODE_NOT_EQUALS
                      }
            }
            ;
            #endregion

            #region 获取会员权益
            var customerBasicSettingBll = new CustomerBasicSettingBLL(CurrentUserInfo);
            var memberBenefit           = customerBasicSettingBll.GetMemberBenefits(pRequest.CustomerID);
            var bllPrize = new LPrizesBLL(CurrentUserInfo);
            #endregion
            //自定义没有实体卡,有实体卡时变为1
            int HaveVipcard = 0;
            //要发送给rabbitmq的信息
            var           eventService = new EventService();
            EventContract vipMsg       = null;

            switch (pRequest.Parameters.VipSource.Value)
            {
            case 3:     //来源是微信时,做自动合并
            {
                #region 根据手机号查找下,看下是否存在同样手机号的VIP记录
                {
                    List <IWhereCondition> wheres = new List <IWhereCondition>();
                    wheres.Add(new MoreThanCondition()
                        {
                            FieldName = "status", Value = 0, IncludeEquals = false
                        });                                                                                                //潜在或者正式会员
                    wheres.Add(new EqualsCondition()
                        {
                            FieldName = "phone", Value = pRequest.Parameters.Mobile
                        });
                    wheres.Add(new EqualsCondition()
                        {
                            FieldName = "clientid", Value = pRequest.CustomerID
                        });
                    var result = bll.Query(wheres.ToArray(), null);
                    if (result != null && result.Length > 0)
                    {
                        vipByPhone = result[0];
                    }
                    if (vipByPhone != null && vipByPhone.VipSourceId == "3" && vipByPhone.Status.Value >= 2)
                    {
                        throw new APIException("会员已经注册")
                              {
                                  ErrorCode = ERROR_MEMBER_REGISTERED
                              };
                    }
                }
                #endregion

                #region 根据VIP ID查找下,看下是否存在该VIP的记录
                if (!string.IsNullOrEmpty(pRequest.UserID))
                {
                    List <IWhereCondition> wheres = new List <IWhereCondition>();
                    //wheres.Add(new MoreThanCondition() { FieldName = "status", Value = 0, IncludeEquals = false });
                    wheres.Add(new MoreThanCondition()
                        {
                            FieldName = "status", Value = 0, IncludeEquals = true
                        });
                    wheres.Add(new EqualsCondition()
                        {
                            FieldName = "vipid", Value = pRequest.UserID
                        });
                    wheres.Add(new EqualsCondition()
                        {
                            FieldName = "clientid", Value = pRequest.CustomerID
                        });
                    var result = bll.Query(wheres.ToArray(), null);
                    if (result != null && result.Length > 0)
                    {
                        vipByID = result[0];
                    }
                }
                else
                {        //如果前端未指定VIP ID则后台指定
                    pRequest.UserID = Guid.NewGuid().ToString("N");
                }
                //判断用户是从点击领取过来的 还是从点击绑定实体卡过来的
                int?RegisterType = 0;
                if (pRequest.Parameters.registerType != null)
                {
                    RegisterType = pRequest.Parameters.registerType;
                }

                //当手机号不为空时需要查询是否存在实体卡
                if (!string.IsNullOrEmpty(pRequest.Parameters.Mobile) && (!string.IsNullOrEmpty(pRequest.UserID) || !string.IsNullOrEmpty(vipByPhone.VIPID)))
                {
                    List <IWhereCondition> wheres = new List <IWhereCondition>();
                    wheres.Add(new EqualsCondition()
                        {
                            FieldName = "phone", Value = pRequest.Parameters.Mobile
                        });
                    wheres.Add(new EqualsCondition()
                        {
                            FieldName = "clientid", Value = pRequest.CustomerID
                        });
                    wheres.Add(new DirectCondition("VipID!='" + pRequest.UserID + "'"));
                    var vipInfo = bll.Query(wheres.ToArray(), null);
                    //若是从绑定实体卡进入,进行实体卡的判断,并不注册成功
                    if (RegisterType == 2)
                    {
                        if (vipInfo == null || vipInfo.Length == 0)
                        {
                            throw new APIException("未检测到实体卡")
                                  {
                                      ErrorCode = MEMBER_HAVENOCARD
                                  };
                        }
                        else
                        {
                            vipCardVipMappingBLL.BindVipCard(vipByID.VIPID, vipByID.VipCode, vipByID.CouponInfo);
                            HaveVipcard = 1;        //需要给绑定实体卡的提示
                        }
                    }
                    else
                    {
                        vipCardVipMappingBLL.BindVipCard(vipByID.VIPID, vipByID.VipCode, vipByID.CouponInfo);
                        //若是从"点击领取"进入则进行判断有没有实体卡   有没有实体卡都进行领卡成功的提示
                        if (vipInfo != null && vipInfo.Length > 0)
                        {
                            HaveVipcard = 1;        //需要给绑定实体卡的提示
                        }
                        else
                        {
                            HaveVipcard = 2;        //注册成功但没有实体卡
                        }
                    }
                }

                if (vipByID == null && vipByPhone == null) //根据vipid查不出记录,并且根据手机号也查不出记录 新增一条vip
                {                                          //如果不存在则首先创建一条VIP记录,补充记录
                    vipByID = new VipEntity()
                    {
                        Phone            = pRequest.Parameters.Mobile,
                        VipName          = pRequest.Parameters.Mobile,
                        UserName         = pRequest.Parameters.Mobile,
                        VipRealName      = pRequest.Parameters.VipRealName,
                        VIPID            = pRequest.UserID,
                        Status           = 2,
                        ClientID         = pRequest.CustomerID,
                        VipCode          = "Vip" + bll.GetNewVipCode(pRequest.CustomerID),
                        VipSourceId      = pRequest.Parameters.VipSource.ToString(),
                        WeiXinUserId     = string.IsNullOrWhiteSpace(pRequest.UserID) ? Guid.NewGuid().ToString("N") : pRequest.UserID,
                        RegistrationTime = DateTime.Now
                    };
                    bll.Create(vipByID);
                    #region 注册会员触点活动奖励
                    //bllPrize.CheckIsWinnerForShare(CurrentUserInfo.UserID, "", "Reg");

                    RedisContactBLL redisContactBll = new RedisContactBLL();
                    redisContactBll.SetRedisContact(new RedisOpenAPIClient.Models.CC.CC_Contact()
                        {
                            CustomerId  = CurrentUserInfo.ClientID,
                            ContactType = "Reg",
                            VipId       = CurrentUserInfo.UserID
                        });

                    #endregion
                }
                else if (vipByID != null)
                {
                    VipEntity vipUpdateInfo       = new VipEntity();
                    List <IWhereCondition> wheres = new List <IWhereCondition>();
                    //wheres.Add(new MoreThanCondition() { FieldName = "status", Value = 0, IncludeEquals = false });
                    wheres.Add(new MoreThanCondition()
                        {
                            FieldName = "status", Value = 0, IncludeEquals = true
                        });
                    wheres.Add(new EqualsCondition()
                        {
                            FieldName = "vipid", Value = pRequest.UserID
                        });
                    wheres.Add(new EqualsCondition()
                        {
                            FieldName = "clientid", Value = pRequest.CustomerID
                        });
                    var result = bll.Query(wheres.ToArray(), null);
                    if (result != null && result.Length > 0)
                    {
                        vipUpdateInfo = result[0];
                    }
                    vipUpdateInfo.Phone = pRequest.Parameters.Mobile;
                    if (!string.IsNullOrEmpty(pRequest.Parameters.VipRealName))
                    {
                        vipUpdateInfo.VipRealName = pRequest.Parameters.VipRealName;
                    }
                    vipUpdateInfo.Status           = 2;
                    vipUpdateInfo.RegistrationTime = DateTime.Now;
                    bll.Update(vipUpdateInfo);
                    #region 注册会员触点活动奖励
                    //bllPrize.CheckIsWinnerForShare(CurrentUserInfo.UserID, "", "Reg");
                    RedisContactBLL redisContactBll = new RedisContactBLL();
                    redisContactBll.SetRedisContact(new RedisOpenAPIClient.Models.CC.CC_Contact()
                        {
                            CustomerId  = CurrentUserInfo.ClientID,
                            ContactType = "Reg",
                            VipId       = CurrentUserInfo.UserID
                        });
                    #endregion

                    #region 会员金矿、注册集客奖励
                    bll.SetOffActionReg(vipByID);
                    #endregion
                }

                #endregion

                #region 根据VIP ID及手机号查询出的结果,尝试自动合并会员 (因目前会员注册不自动绑卡,实现用户自行选择绑卡业务故将绑卡业务注释掉)
                //if (vipByPhone == null)
                //{//如果未有相同手机号的用户,则无须绑定,直接使用VIP ID对应的VIP记录作为当前注册用户的记录
                //    rd.MemberInfo = new MemberInfo()
                //    {
                //        Mobile = vipByID.Phone
                //        ,
                //        VipID = vipByID.VIPID
                //        ,
                //        Name = vipByID.UserName
                //        ,
                //        VipName = vipByID.VipName
                //        ,
                //        VipNo = vipByID.VipCode
                //        ,
                //        MemberBenefits = memberBenefit
                //        ,
                //        IsActivate = vipByID.IsActivate.HasValue && vipByID.IsActivate.Value == 1 ? true : false
                //    };
                //    //处理绑卡业务 add by Henry 2015/10/28
                //    vipCardVipMappingBLL.BindVipCard(vipByID.VIPID, vipByID.VipCode, vipByID.CouponInfo);
                //}
                //else
                //{//否则调用存储过程,做自动会员合并

                //    //如果会员已经注册过,并且来源是微信的则表示该帐号已经被注册过不能再次绑定
                //    if (vipByPhone.VipSourceId == "3" && vipByPhone.Status.Value >= 2)
                //    {
                //        throw new APIException("会员已经注册") { ErrorCode = ERROR_MEMBER_REGISTERED };
                //    }
                //    //否则做会员合并
                //    if (!bll.MergeVipInfo(pRequest.CustomerID, pRequest.UserID, pRequest.Parameters.Mobile))
                //    {
                //        throw new APIException("自动绑定会员信息失败") { ErrorCode = ERROR_AUTO_MERGE_MEMBER_FAILED };
                //    }

                //    //合并成功后重新读取信息
                //    List<IWhereCondition> wheres = new List<IWhereCondition>();
                //    wheres.Add(new MoreThanCondition() { FieldName = "status", Value = 0, IncludeEquals = false });
                //    wheres.Add(new EqualsCondition() { FieldName = "vipid", Value = pRequest.UserID });
                //    wheres.Add(new EqualsCondition() { FieldName = "clientid", Value = pRequest.CustomerID });
                //    var result = bll.Query(wheres.ToArray(), null);
                //    vipByID = result[0];
                //    rd.MemberInfo = new MemberInfo()
                //    {
                //        Mobile = vipByID.Phone
                //        ,
                //        VipID = vipByID.VIPID
                //        ,
                //        Name = vipByID.UserName
                //        ,
                //        VipName = vipByID.VipName
                //        ,
                //        VipNo = vipByID.VipCode
                //        ,
                //        MemberBenefits = memberBenefit
                //        ,
                //        IsActivate = vipByID.IsActivate.HasValue && vipByID.IsActivate.Value == 1 ? true : false
                //    };
                //    //处理绑卡业务 add by Henry 2015/10/28
                //    vipCardVipMappingBLL.BindVipCard(vipByID.VIPID, vipByID.VipCode, vipByID.CouponInfo);
                //}
                #endregion
            }
                //注册会员信息发布到rabbitmq
                vipMsg = new EventContract
                {
                    Operation  = OptEnum.Create,
                    EntityType = EntityTypeEnum.Vip,
                    Id         = pRequest.UserID
                };
                eventService.PublishMsg(vipMsg);

                break;

            default:    //其他来源则为自动注册
            {
                #region 根据手机号查找下,看下是否存在同样手机号的VIP记录
                {
                    List <IWhereCondition> wheres = new List <IWhereCondition>();
                    wheres.Add(new MoreThanCondition()
                        {
                            FieldName = "status", Value = 0, IncludeEquals = false
                        });
                    wheres.Add(new EqualsCondition()
                        {
                            FieldName = "phone", Value = pRequest.Parameters.Mobile
                        });
                    wheres.Add(new EqualsCondition()
                        {
                            FieldName = "clientid", Value = pRequest.CustomerID
                        });
                    var result = bll.Query(wheres.ToArray(), null);
                    if (result != null && result.Length > 0)
                    {
                        vipByPhone = result[0];
                    }
                    if (vipByPhone != null && vipByPhone.Status.Value >= 2)
                    {
                        throw new APIException("会员已经注册")
                              {
                                  ErrorCode = ERROR_MEMBER_REGISTERED
                              };
                    }
                }
                #endregion

                #region 没有找到相同电话的会员则自动注册
                if (vipByPhone == null)
                {        //没有找到相同电话的会员则自动注册
                    vipByPhone = new VipEntity()
                    {
                        Phone            = pRequest.Parameters.Mobile,
                        VipName          = pRequest.Parameters.Mobile,
                        UserName         = pRequest.Parameters.Mobile,
                        VipRealName      = pRequest.Parameters.VipRealName,
                        VIPID            = string.IsNullOrWhiteSpace(pRequest.UserID) ? Guid.NewGuid().ToString("N") : pRequest.UserID,
                        Status           = 2, //状态为注册
                        VipCode          = "Vip" + bll.GetNewVipCode(pRequest.CustomerID),
                        ClientID         = pRequest.CustomerID,
                        VipSourceId      = pRequest.Parameters.VipSource.ToString(),
                        WeiXinUserId     = string.IsNullOrWhiteSpace(pRequest.UserID) ? Guid.NewGuid().ToString("N") : pRequest.UserID,
                        RegistrationTime = DateTime.Now
                    };
                    bll.Create(vipByPhone);
                    #region 注册会员触点活动奖励
                    //bllPrize.CheckIsWinnerForShare(CurrentUserInfo.UserID, "", "Reg");
                    RedisContactBLL redisContactBll = new RedisContactBLL();
                    redisContactBll.SetRedisContact(new RedisOpenAPIClient.Models.CC.CC_Contact()
                        {
                            CustomerId  = CurrentUserInfo.ClientID,
                            ContactType = "Reg",
                            VipId       = CurrentUserInfo.UserID
                        });
                    #endregion
                }
                #endregion

                #region

                decimal         EndAmount    = 0;
                VipAmountBLL    AmountBLL    = new VipAmountBLL(this.CurrentUserInfo);
                VipAmountEntity amountEntity = AmountBLL.GetByID(vipByPhone.VIPID);
                if (amountEntity != null)
                {
                    EndAmount = amountEntity.EndAmount.HasValue ? amountEntity.EndAmount ?? 0 : 0;
                }

                #endregion

                #region 返回用户信息
                rd.MemberInfo = new MemberInfo()
                {
                    Mobile = vipByPhone.Phone
                    ,
                    VipID = vipByPhone.VIPID
                    ,
                    Name = vipByPhone.UserName
                    ,
                    VipName = vipByPhone.VipName
                    ,
                    VipRealName = vipByPhone.VipRealName
                    ,
                    VipNo = vipByPhone.VipCode
                    ,
                    MemberBenefits = memberBenefit
                    ,
                    IsActivate = false
                    ,
                    Integration = vipByPhone.Integration ?? 0
                    ,
                    Balance = EndAmount
                };


                #endregion
            }

                //注册会员信息发布到rabbitmq
                vipMsg = new EventContract
                {
                    Operation  = OptEnum.Create,
                    EntityType = EntityTypeEnum.Vip,
                    Id         = rd.MemberInfo.VipID
                };
                eventService.PublishMsg(vipMsg);
                break;
            }



            T_LEventsRegVipLogBLL lEventRegVipLogBll = new T_LEventsRegVipLogBLL(CurrentUserInfo);
            if (!string.IsNullOrEmpty(pRequest.Parameters.CTWEventId))
            {
                lEventRegVipLogBll.CTWRegOrFocusLog(pRequest.Parameters.CTWEventId, pRequest.UserID, "", CurrentUserInfo, "Reg");
            }
            //如果是通过优惠券进来的就有couponId 新注册的需要加记录
            if (!string.IsNullOrEmpty(pRequest.Parameters.couponId))
            {
                lEventRegVipLogBll.CouponRegOrFocusLog(pRequest.Parameters.couponId, pRequest.UserID, "", CurrentUserInfo, "Reg");
            }

            //当手机号不为空时需要查询是否存在实体卡
            //if (!string.IsNullOrEmpty(pRequest.Parameters.Mobile) && (!string.IsNullOrEmpty(pRequest.UserID) || !string.IsNullOrEmpty(vipByPhone.VIPID)))
            //{
            //    List<IWhereCondition> wheres = new List<IWhereCondition>();
            //    wheres.Add(new EqualsCondition() { FieldName = "phone", Value = pRequest.Parameters.Mobile });
            //    wheres.Add(new EqualsCondition() { FieldName = "clientid", Value = pRequest.CustomerID });
            //    wheres.Add(new DirectCondition("VipID!='" + pRequest.UserID + "'"));
            //    var vipInfo = bll.Query(wheres.ToArray(), null);
            //    if (vipInfo != null && vipInfo.Length > 0)
            //    {
            //        throw new APIException("检测到会员相关实体卡") { ErrorCode = MEMBER_HAVECARD };
            //    }
            //    else
            //    {
            //        //如果会员当前没有实体卡,则默认绑定等级为1的卡
            //        vipCardVipMappingBLL.BindVipCard(vipByID.VIPID, vipByID.VipCode, vipByID.CouponInfo);
            //        throw new APIException("未检测到实体卡") { ErrorCode = MEMBER_HAVENOCARD };
            //    }
            //}
            //判定是否有可绑卡的定义  1=有可绑卡
            if (HaveVipcard == 1 || HaveVipcard == 2)
            {
                //有积分的话给相应领取成功的积分提示
                var contactEventBLL = new ContactEventBLL(CurrentUserInfo);
                int sendIntegral    = 0;
                if (!string.IsNullOrEmpty(pRequest.Parameters.CTWEventId))
                {
                    sendIntegral = contactEventBLL.GetContactEventIntegral(CurrentUserInfo.ClientID, "Reg", "Point", 1);
                }
                else
                {
                    sendIntegral = contactEventBLL.GetContactEventIntegral(CurrentUserInfo.ClientID, "Reg", "Point", 0);
                }
                if (sendIntegral > 0)
                {
                    if (pRequest.Parameters.registerType != 2 && HaveVipcard == 2)
                    {
                        throw new APIException("恭喜您领取成功并获得" + sendIntegral + "注册积分")
                              {
                                  ErrorCode = MEMBER_GETSUCCESS
                              };                                                                                       //领取成功不跳转跳转到实体卡
                    }
                    else if (pRequest.Parameters.registerType == 2 && HaveVipcard == 1)
                    {
                        throw new APIException("恭喜您领取成功并获得" + sendIntegral + "注册积分")
                              {
                                  ErrorCode = MEMBER_HAVECARD_Integral
                              };                                                                                              //检测到有相关实体卡前端不提示领取成功 并跳到实体卡列表
                    }
                    else
                    {
                        throw new APIException("恭喜您领取成功并获得" + sendIntegral + "注册积分")
                              {
                                  ErrorCode = MEMBER_HAVECARD
                              };                                                                                     //领取成功,提示领取成功,并跳到相关实体卡
                    }
                }
                else
                {
                    if (pRequest.Parameters.registerType != 2 && HaveVipcard == 2)
                    {
                        throw new APIException("领取成功")
                              {
                                  ErrorCode = MEMBER_GETSUCCESS
                              };                                                         //领取成功不跳转跳转到实体卡
                    }
                    else if (pRequest.Parameters.registerType == 2 && HaveVipcard == 1)
                    {
                        throw new APIException("检测到有相关实体卡")
                              {
                                  ErrorCode = MEMBER_HAVECARD
                              };                                                            //检测到有相关实体卡前端不提示领取成功 并跳到实体卡列表
                    }
                    else if (pRequest.Parameters.registerType != 2 && HaveVipcard == 1)
                    {
                        throw new APIException("领取成功")
                              {
                                  ErrorCode = MEMBER_HAVECARD
                              };                                                       //领取成功有实体卡,并跳转
                    }
                    else
                    {
                        throw new APIException("检测到有相关实体卡")
                              {
                                  ErrorCode = MEMBER_HAVECARD
                              };                                                            //领取成功,提示领取成功,并跳到相关实体卡
                    }
                }
            }

            #region 将验证码设置为已验证
            //entity.IsValidated = 1;
            //codebll.Update(entity);
            #endregion


            return(rd);

            //AuthCodeLoginRD rd = new AuthCodeLoginRD();
            //rd.MemberInfo = new MemberInfo();
            //var codebll = new RegisterValidationCodeBLL(base.CurrentUserInfo);
            //var entity = codebll.GetByMobile(pRequest.Parameters.Mobile);
            //if (entity == null)
            //    throw new APIException("未找到此手机的验证信息") { ErrorCode = ERROR_AUTHCODE_NOTEXISTS };
            //if (entity.IsValidated.Value == 1)
            //    throw new APIException("此验证码已失效") { ErrorCode = ERROR_AUTHCODE_FAILURE };
            //if (entity.Expires.Value < DateTime.Now)
            //    throw new APIException("此验证码已失效") { ErrorCode = ERROR_AUTHCODE_FAILURE };
            //var vipbll = new VipBLL(base.CurrentUserInfo);
            //var vipinfo = vipbll.GetByMobile(pRequest.Parameters.Mobile, pRequest.CustomerID);

            //#region VIP来源更新
            //switch (pRequest.Parameters.VipSource.Value)
            //{
            //    case 4:
            //    case 9:
            //        vipinfo.VipSourceId = pRequest.Parameters.VipSource.ToString();
            //        vipbll.Update(vipinfo);
            //        break;
            //}
            //#endregion

            //if (string.IsNullOrEmpty(vipinfo.ClientID))
            //{
            //    vipinfo.ClientID = pRequest.CustomerID;
            //    vipbll.Update(vipinfo);
            //}
            //rd.MemberInfo.Mobile = vipinfo.Phone;
            //rd.MemberInfo.Name = vipinfo.UserName;
            //rd.MemberInfo.VipID = vipinfo.VIPID;
            //rd.MemberInfo.VipName = vipinfo.VipName;
            //var customerBasicSettingBll = new CustomerBasicSettingBLL(CurrentUserInfo);
            //rd.MemberInfo.MemberBenefits = customerBasicSettingBll.GetMemberBenefits(pRequest.CustomerID);
            //entity.IsValidated = 1;
            //codebll.Update(entity);
            //return rd;
        }
    }
}
예제 #21
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);
        }
예제 #22
0
        /// <summary>
        /// 批量审核
        /// </summary>
        /// <param name="OrderID"></param>
        public int BatchCheckOrder(List <string> OrderIdList, string Remark, LoggingSessionInfo LoggingSessionInfo)
        {
            var UpdateOrderList = new List <InoutInfo>();

            foreach (var item in OrderIdList)
            {
                var result = this._currentDAO.GetByID(item);
                if (result != null)
                {
                    var Entity = new InoutInfo()
                    {
                        order_id    = result.order_id,
                        Field2      = result.Field2,
                        carrier_id  = result.carrier_id,
                        Field1      = result.Field1,
                        status      = "500",
                        status_desc = "未发货"
                    };
                    UpdateOrderList.Add(Entity);
                }
            }
            //更新订单状态
            int Num = this._currentDAO.BatchChangeOrderStatus(UpdateOrderList);

            if (Num > 0)
            {//添加状态操作记录
                var inoutStatus = new TInoutStatusBLL(LoggingSessionInfo);
                foreach (var itemes in UpdateOrderList)
                {
                    var info = new TInoutStatusEntity()
                    {
                        InoutStatusID = Guid.Parse(Utils.NewGuid()),
                        OrderID       = itemes.order_id,
                        CustomerID    = LoggingSessionInfo.ClientID,
                        Remark        = Remark,
                        OrderStatus   = 500,
                        StatusRemark  = "订单状态从未审核变为未发货[操作人:" + LoggingSessionInfo.CurrentUser.User_Name + "]"
                    };
                    //执行
                    inoutStatus.Create(info);

                    #region 审核成功,并且已支付,调用RabbitMQ发送给ERP

                    if (itemes.Field1 == "0")
                    {
                        continue;
                    }
                    try
                    {
                        var msg = new EventContract
                        {
                            Operation  = OptEnum.Update,
                            EntityType = EntityTypeEnum.Order,
                            Id         = itemes.order_id
                        };
                        var eventService = new EventService();
                        eventService.PublishMsg(msg);
                    }
                    catch (Exception)
                    {
                        throw new Exception("RabbitMQ Error");
                    }

                    #endregion
                }
                //
                Num = UpdateOrderList.Count();
            }
            return(Num);
        }
        public void AutoSetOrderNotPayCache()
        {
            foreach (var customer in _CustomerIDList)
            {
                _T_loggingSessionInfo.ClientID = customer.Key;
                _T_loggingSessionInfo.CurrentLoggingManager.Connection_String = customer.Value;

                //
                _T_InoutBLL    = new T_InoutBLL(_T_loggingSessionInfo);
                _Inout3Service = new InoutService(_T_loggingSessionInfo);
                var inoutStatus = new TInoutStatusBLL(_T_loggingSessionInfo);
                _VipBLL = new VipBLL(_T_loggingSessionInfo);

                //
                // var t_InoutList = new List<string>();
                try
                {
                    List <IWhereCondition> complexCondition = new List <IWhereCondition>();
                    string[] statusArr = { "620", "610", "600" };
                    complexCondition.Add(new InCondition <string>()
                    {
                        FieldName = "Field7", Values = statusArr
                    });
                    complexCondition.Add(
                        new DirectCondition(
                            " CONVERT(NVARCHAR(10),complete_date,120) = CONVERT(NVARCHAR(10),DATEADD(day, -1, GETDATE()),120)"));

                    var t_InoutEntitys = _T_InoutBLL.Query(complexCondition.ToArray(), null);
                    if (t_InoutEntitys == null || t_InoutEntitys.Count() <= 0)
                    {
                    }
                    //
                    //   roleList = roleEntities.Select(it => it.role_id).ToList();

                    foreach (var t_InoutInfo in t_InoutEntitys)
                    {
                        TInoutStatusEntity info = new TInoutStatusEntity();
                        info.InoutStatusID = Guid.Parse(Utils.NewGuid());
                        info.OrderID       = t_InoutInfo.order_id;
                        info.CustomerID    = _T_loggingSessionInfo.ClientID;
                        info.Remark        = string.Empty;
                        info.OrderStatus   = 700;

                        string statusDesc = GetStatusDesc("700");//变更后的状态名称

                        try
                        {
                            info.StatusRemark = "订单状态从" + t_InoutInfo.status_desc + "变为" + statusDesc + "[操作人:自动]";
                            _Inout3Service.UpdateOrderDeliveryStatus(t_InoutInfo.order_id, "700", Utils.GetNow());
                        }
                        catch
                        {
                            continue;
                        }

                        inoutStatus.Create(info);

                        #region 支付成功,调用RabbitMQ发送给ERP

                        try
                        {
                            var msg = new EventContract
                            {
                                Operation  = OptEnum.Update,
                                EntityType = EntityTypeEnum.Order,
                                Id         = t_InoutInfo.order_id
                            };
                            var eventService = new EventService();
                            eventService.PublishMsg(msg);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception(ex.Message);
                        }

                        #endregion
                    }
                }
                catch
                {
                    // ignored
                }
            }
        }
예제 #24
0
        /// <summary>
        /// 会员微信注册绑卡
        /// </summary>
        /// <param name="vipId"></param>
        /// <param name="vipCode"></param>
        /// <param name="unitId">会籍店</param>
        public void BindVipCard(string vipId, string vipCode, string unitId)
        {
            var vipCardVipMappingBLL      = new VipCardVipMappingBLL(CurrentUserInfo);
            var sysVipCardTypeBLL         = new SysVipCardTypeBLL(CurrentUserInfo);
            var vipCardBLL                = new VipCardBLL(CurrentUserInfo);
            var vipCardStatusChangeLogBLL = new VipCardStatusChangeLogBLL(CurrentUserInfo);

            UnitService unitServer = new UnitService(CurrentUserInfo);

            if (string.IsNullOrEmpty(unitId))
            {
                unitId = unitServer.GetUnitByUnitTypeForWX("总部", null).Id; //获取总部门店标识
            }
            //根据vipid查询VipCardVipMapping,判断是否有绑卡,没绑卡默认给等级1的卡
            var vipCardMappingInfo = vipCardVipMappingBLL.QueryByEntity(new VipCardVipMappingEntity()
            {
                VIPID = vipId
            }, null).FirstOrDefault();

            if (vipCardMappingInfo == null)
            {
                //判断商户是否有付费的会员卡,有付费会员卡时,不自动绑卡
                List <IWhereCondition> freeCardCon = new List <IWhereCondition> {
                };
                freeCardCon.Add(new EqualsCondition()
                {
                    FieldName = "CustomerID", Value = CurrentUserInfo.ClientID
                });
                freeCardCon.Add(new DirectCondition("VipCardLevel=1"));
                var orderBys = new OrderBy[1];
                orderBys[0] = new OrderBy()
                {
                    FieldName = "VipCardLevel", Direction = OrderByDirections.Asc
                };
                var freeCardTypeInfo = sysVipCardTypeBLL.Query(freeCardCon.ToArray(), orderBys).FirstOrDefault();
                if (freeCardTypeInfo != null)
                {
                    //查询最低等级的会员卡类型
                    var vipCardTypeInfo = sysVipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity()
                    {
                        CustomerID = CurrentUserInfo.ClientID, Category = 0, VipCardLevel = 1
                    }, new OrderBy[] { new OrderBy()
                                       {
                                           FieldName = "vipcardlevel", Direction = OrderByDirections.Asc
                                       } }).FirstOrDefault();
                    if (vipCardTypeInfo != null)
                    {
                        //查询此类型会员卡是否存在
                        var vipCardInfo = vipCardBLL.QueryByEntity(new VipCardEntity()
                        {
                            VipCardTypeID = vipCardTypeInfo.VipCardTypeID, VipCardStatusId = 0, MembershipUnit = ""
                        }, null).FirstOrDefault();
                        //不存在,制卡
                        if (vipCardInfo == null)
                        {
                            vipCardInfo                 = new VipCardEntity();
                            vipCardInfo.VipCardID       = Guid.NewGuid().ToString();
                            vipCardInfo.VipCardTypeID   = vipCardTypeInfo.VipCardTypeID;
                            vipCardInfo.VipCardTypeName = vipCardTypeInfo.VipCardTypeName;
                            vipCardInfo.VipCardCode     = vipCode;
                            vipCardInfo.VipCardStatusId = 1;//正常
                            vipCardInfo.MembershipUnit  = unitId;
                            vipCardInfo.MembershipTime  = DateTime.Now;
                            vipCardInfo.CustomerID      = CurrentUserInfo.ClientID;
                            vipCardBLL.Create(vipCardInfo);
                        }
                        else//存在更新成现在的
                        {
                            vipCardInfo.VipCardStatusId = 1;//正常
                            vipCardInfo.MembershipUnit  = unitId;
                            vipCardInfo.MembershipTime  = DateTime.Now;
                            vipCardInfo.VipCardTypeID   = vipCardTypeInfo.VipCardTypeID;
                            vipCardBLL.Update(vipCardInfo);
                            //存在导入的卡时,更新当前会员的VipCode
                            var vipbll = new VipBLL(CurrentUserInfo);
                            List <IWhereCondition> wheres = new List <IWhereCondition>();
                            wheres.Add(new MoreThanCondition()
                            {
                                FieldName = "status", Value = 0
                            });
                            wheres.Add(new EqualsCondition()
                            {
                                FieldName = "vipid", Value = vipId
                            });
                            wheres.Add(new EqualsCondition()
                            {
                                FieldName = "clientid", Value = CurrentUserInfo.ClientID
                            });
                            var VipInfo = vipbll.Query(wheres.ToArray(), null).FirstOrDefault();
                            if (VipInfo != null && !string.IsNullOrEmpty(VipInfo.VIPID))
                            {
                                VipInfo.VipCode = vipCardInfo.VipCardCode;
                                //更新VipCode信息
                                vipbll.Update(VipInfo);
                            }
                        }
                        //新增会员卡操作状态信息
                        var vipCardStatusChangeLogEntity = new VipCardStatusChangeLogEntity()
                        {
                            LogID           = Guid.NewGuid().ToString().Replace("-", ""),
                            VipCardStatusID = vipCardInfo.VipCardStatusId,
                            VipCardID       = vipCardInfo.VipCardID,
                            Action          = "注册",
                            UnitID          = unitId,
                            CustomerID      = CurrentUserInfo.ClientID
                        };
                        vipCardStatusChangeLogBLL.Create(vipCardStatusChangeLogEntity);

                        //绑定会员卡和会员
                        var vipCardVipMappingEntity = new VipCardVipMappingEntity()
                        {
                            MappingID  = Guid.NewGuid().ToString().Replace("-", ""),
                            VIPID      = vipId,
                            VipCardID  = vipCardInfo.VipCardID,
                            CustomerID = CurrentUserInfo.ClientID
                        };
                        vipCardVipMappingBLL.Create(vipCardVipMappingEntity);
                        //开卡礼
                        var vipCardUpgradeRewardBll        = new VipCardUpgradeRewardBLL(CurrentUserInfo);
                        var vipCardUpgradeRewardEntityList = vipCardUpgradeRewardBll.QueryByEntity(new VipCardUpgradeRewardEntity()
                        {
                            VipCardTypeID = vipCardTypeInfo.VipCardTypeID
                        }, null);
                        var redisVipMappingCouponBLL = new JIT.CPOS.BS.BLL.RedisOperationBLL.Coupon.RedisVipMappingCouponBLL();
                        if (vipCardUpgradeRewardEntityList.Length > 0)
                        {
                            foreach (var vipCardUpgradeRewardEntity in vipCardUpgradeRewardEntityList)
                            {
                                for (int i = 0; i < vipCardUpgradeRewardEntity.CouponNum; i++)
                                {
                                    redisVipMappingCouponBLL.SetVipMappingCoupon(new CC_Coupon()
                                    {
                                        CustomerId   = CurrentUserInfo.ClientID,
                                        CouponTypeId = vipCardUpgradeRewardEntity.CouponTypeId.ToString()
                                    }, vipCardUpgradeRewardEntity.CardUpgradeRewardId.ToString(), vipId, "OpenVipCard");
                                }
                            }
                        }
                    }
                    else
                    {
                        throw new APIException("系统未创建会员卡类型")
                              {
                                  ErrorCode = ERROR_CODES.INVALID_BUSINESS
                              }
                    };
                }
            }
            else //更新旧卡 需要确认旧卡是否为卡体系内的卡
            {
                var oldVipCardInfo = vipCardBLL.QueryByEntity(new VipCardEntity()
                {
                    VipCardID = vipCardMappingInfo.VipCardID, CustomerID = CurrentUserInfo.ClientID
                }, null).FirstOrDefault();
                int oldVipCardTypeID = oldVipCardInfo.VipCardTypeID ?? 0;
                //查询最低等级的会员卡类型
                var vipCardTypeInfo = sysVipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity()
                {
                    CustomerID = CurrentUserInfo.ClientID, Category = 0, VipCardLevel = 1
                }, new OrderBy[] { new OrderBy()
                                   {
                                       FieldName = "vipcardlevel", Direction = OrderByDirections.Asc
                                   } }).FirstOrDefault();
                if (vipCardTypeInfo == null)
                {
                    throw new APIException("系统未创建会员卡类型体系")
                          {
                              ErrorCode = ERROR_CODES.INVALID_BUSINESS
                          };
                }
                if (oldVipCardInfo != null)
                {
                    //旧卡不为空时,确认当前VipCardTypeID是否属于卡体系
                    var curvipCardTypeInfo = sysVipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity()
                    {
                        CustomerID = CurrentUserInfo.ClientID, Category = 0, VipCardTypeID = oldVipCardInfo.VipCardTypeID
                    }, new OrderBy[] { new OrderBy()
                                       {
                                           FieldName = "VipCardTypeID", Direction = OrderByDirections.Asc
                                       } }).FirstOrDefault();
                    if (curvipCardTypeInfo == null)         //若为空  则更新为当前信息
                    {
                        oldVipCardInfo.VipCardStatusId = 1; //正常
                        oldVipCardInfo.MembershipUnit  = unitId;
                        oldVipCardInfo.MembershipTime  = DateTime.Now;
                        oldVipCardInfo.VipCardTypeID   = vipCardTypeInfo.VipCardTypeID;
                        vipCardBLL.Update(oldVipCardInfo);
                        //存在导入的卡时,更新当前会员的VipCode
                        var vipbll = new VipBLL(CurrentUserInfo);
                        List <IWhereCondition> wheres = new List <IWhereCondition>();
                        wheres.Add(new MoreThanCondition()
                        {
                            FieldName = "status", Value = 0
                        });
                        wheres.Add(new EqualsCondition()
                        {
                            FieldName = "vipid", Value = vipId
                        });
                        wheres.Add(new EqualsCondition()
                        {
                            FieldName = "clientid", Value = CurrentUserInfo.ClientID
                        });
                        var VipInfo = vipbll.Query(wheres.ToArray(), null).FirstOrDefault();
                        if (VipInfo != null && !string.IsNullOrEmpty(VipInfo.VIPID))
                        {
                            VipInfo.VipCode = oldVipCardInfo.VipCardCode;
                            //更新VipCode信息
                            vipbll.Update(VipInfo);
                        }
                        //开卡礼
                        var vipCardUpgradeRewardBll        = new VipCardUpgradeRewardBLL(CurrentUserInfo);
                        var vipCardUpgradeRewardEntityList = vipCardUpgradeRewardBll.QueryByEntity(new VipCardUpgradeRewardEntity()
                        {
                            VipCardTypeID = vipCardTypeInfo.VipCardTypeID
                        }, null);
                        var redisVipMappingCouponBLL = new JIT.CPOS.BS.BLL.RedisOperationBLL.Coupon.RedisVipMappingCouponBLL();
                        if (vipCardUpgradeRewardEntityList.Length > 0)
                        {
                            foreach (var vipCardUpgradeRewardEntity in vipCardUpgradeRewardEntityList)
                            {
                                for (int i = 0; i < vipCardUpgradeRewardEntity.CouponNum; i++)
                                {
                                    redisVipMappingCouponBLL.SetVipMappingCoupon(new CC_Coupon()
                                    {
                                        CustomerId   = CurrentUserInfo.ClientID,
                                        CouponTypeId = vipCardUpgradeRewardEntity.CouponTypeId.ToString()
                                    }, vipCardUpgradeRewardEntity.CardUpgradeRewardId.ToString(), vipId, "OpenVipCard");
                                }
                            }
                        }
                    }
                }
                //老卡操作状态信息
                var oldVipCardStatusChangeLogEntity = new VipCardStatusChangeLogEntity()
                {
                    LogID           = Guid.NewGuid().ToString().Replace("-", ""),
                    VipCardStatusID = oldVipCardInfo.VipCardStatusId,
                    VipCardID       = oldVipCardInfo.VipCardID,
                    Action          = "注册",
                    UnitID          = unitId,
                    CustomerID      = CurrentUserInfo.ClientID
                };
                vipCardStatusChangeLogBLL.Create(oldVipCardStatusChangeLogEntity);
            }
            //记录会员信息改变,并且把旧的会员的标识也放在契约里
            var eventService = new EventService();
            var vipMsg       = new EventContract
            {
                Operation  = OptEnum.Update,
                EntityType = EntityTypeEnum.Vip,
                Id         = vipId,
            };

            eventService.PublishMsg(vipMsg);
        }
예제 #25
0
        /// <summary>
        /// 支付完成时注册绑卡   (目前可用于绑卡列表处的绑卡升级处理)
        /// </summary>
        /// <param name="vipId"></param>
        /// <param name="vipCode"></param>
        /// <param name="unitId"></param>
        /// <param name="ObjecetTypeId">卡类型Id</param>
        /// <param name="OrderType">订单类型 SalesCard=销售 Recharge=充值</param>
        /// <param name="OperationType">操作类型 1-手动 2-自动</param>
        /// <returns></returns>
        public string BindVirtualItem(string vipId, string vipCode, string unitId, int ObjecetTypeId, string OrderType = "SalesCard", int OperationType = 1, string orderId = "")
        {
            var vipCardVipMappingBLL      = new VipCardVipMappingBLL(CurrentUserInfo);
            var sysVipCardTypeBLL         = new SysVipCardTypeBLL(CurrentUserInfo);
            var vipCardBLL                = new VipCardBLL(CurrentUserInfo);
            var vipCardStatusChangeLogBLL = new VipCardStatusChangeLogBLL(CurrentUserInfo);

            string ObjectNo = string.Empty;//卡号或券号

            try
            {
                UnitService unitServer = new UnitService(CurrentUserInfo);
                if (string.IsNullOrEmpty(unitId))
                {
                    unitId = unitServer.GetUnitByUnitTypeForWX("总部", null).Id; //获取总部门店标识
                }
                //根据vipid查询VipCardVipMapping,判断是否有绑卡
                var vipCardMappingInfo = vipCardVipMappingBLL.QueryByEntity(new VipCardVipMappingEntity()
                {
                    VIPID = vipId
                }, null).FirstOrDefault();

                //判断商户是否有付费的会员卡,有付费会员卡时,不自动绑卡
                //List<IWhereCondition> freeCardCon = new List<IWhereCondition> { };
                //freeCardCon.Add(new EqualsCondition() { FieldName = "CustomerID", Value = CurrentUserInfo.ClientID });
                //freeCardCon.Add(new DirectCondition("Prices>0"));
                //var freeCardTypeInfo = sysVipCardTypeBLL.Query(freeCardCon.ToArray(), null).FirstOrDefault();
                //if (freeCardTypeInfo == null)
                //{
                ////查询最低等级的会员卡类型
                //var vipCardTypeInfo = sysVipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity() { CustomerID = CurrentUserInfo.ClientID, Category = 0 }, new OrderBy[] { new OrderBy() { FieldName = "vipcardlevel", Direction = OrderByDirections.Asc } }).FirstOrDefault();
                //if (vipCardTypeInfo != null)
                //{


                if (vipCardMappingInfo == null)//绑卡
                {
                    //最低等级卡类型
                    var vipCardTypeInfo = sysVipCardTypeBLL.QueryByEntity(new SysVipCardTypeEntity()
                    {
                        CustomerID = CurrentUserInfo.ClientID, Category = 0, VipCardLevel = 1
                    }, new OrderBy[] { new OrderBy()
                                       {
                                           FieldName = "vipcardlevel", Direction = OrderByDirections.Asc
                                       } }).FirstOrDefault();
                    if (vipCardTypeInfo == null)
                    {
                        throw new APIException("系统未创建会员卡类型")
                              {
                                  ErrorCode = ERROR_CODES.INVALID_BUSINESS
                              };
                    }
                    //查询此类型会员卡是否存在
                    var vipCardInfo = vipCardBLL.QueryByEntity(new VipCardEntity()
                    {
                        VipCardTypeID = vipCardTypeInfo.VipCardTypeID, VipCardStatusId = 0, MembershipUnit = ""
                    }, null).FirstOrDefault();
                    //不存在,制卡
                    if (vipCardInfo == null)
                    {
                        vipCardInfo               = new VipCardEntity();
                        vipCardInfo.VipCardID     = Guid.NewGuid().ToString();
                        vipCardInfo.VipCardTypeID = vipCardTypeInfo.VipCardTypeID;
                        //vipCardInfo.VipCardTypeName = vipCardTypeInfo.VipCardTypeName;
                        vipCardInfo.VipCardCode     = vipCode;
                        vipCardInfo.VipCardStatusId = 1;//正常
                        vipCardInfo.MembershipUnit  = unitId;
                        vipCardInfo.MembershipTime  = DateTime.Now;
                        vipCardInfo.CustomerID      = CurrentUserInfo.ClientID;
                        vipCardBLL.Create(vipCardInfo);
                    }
                    ObjectNo = vipCardInfo.VipCardCode;
                    //绑定会员卡和会员
                    var vipCardVipMappingEntity = new VipCardVipMappingEntity()
                    {
                        MappingID  = Guid.NewGuid().ToString().Replace("-", ""),
                        VIPID      = vipId,
                        VipCardID  = vipCardInfo.VipCardID,
                        CustomerID = CurrentUserInfo.ClientID
                    };
                    vipCardVipMappingBLL.Create(vipCardVipMappingEntity);
                    vipCardMappingInfo = vipCardVipMappingEntity;
                    //新增会员卡操作状态信息
                    var vipCardStatusChangeLogEntity = new VipCardStatusChangeLogEntity()
                    {
                        LogID           = Guid.NewGuid().ToString().Replace("-", ""),
                        VipCardStatusID = vipCardInfo.VipCardStatusId,
                        VipCardID       = vipCardInfo.VipCardID,
                        Action          = "注册",
                        UnitID          = unitId,
                        CustomerID      = CurrentUserInfo.ClientID
                    };
                    vipCardStatusChangeLogBLL.Create(vipCardStatusChangeLogEntity);
                }

                #region 老卡业务处理

                ObjectNo = vipCode;
                //老卡信息获取
                var oldVipCardInfo = vipCardBLL.QueryByEntity(new VipCardEntity()
                {
                    VipCardID = vipCardMappingInfo.VipCardID
                }, null).FirstOrDefault();

                //老卡卡类型ID
                int oldVipCardTypeID = 0;
                if (oldVipCardInfo != null)
                {
                    //获取老卡的类型
                    var oldVipCardType = sysVipCardTypeBLL.GetByID(oldVipCardInfo.VipCardTypeID);
                    //获取即将升级卡的类型
                    var newVipCardType = sysVipCardTypeBLL.GetByID(ObjecetTypeId);
                    if (newVipCardType.VipCardLevel > oldVipCardType.VipCardLevel)
                    {
                        //老卡卡类型ID
                        oldVipCardTypeID = oldVipCardInfo.VipCardTypeID ?? 0;
                        //更新卡信息
                        oldVipCardInfo.VipCardTypeID = ObjecetTypeId;
                        vipCardBLL.Update(oldVipCardInfo);
                        //老卡操作状态信息
                        var oldVipCardStatusChangeLogEntity = new VipCardStatusChangeLogEntity()
                        {
                            LogID           = Guid.NewGuid().ToString().Replace("-", ""),
                            VipCardStatusID = oldVipCardInfo.VipCardStatusId,
                            VipCardID       = oldVipCardInfo.VipCardID,
                            Action          = "升级处理",
                            UnitID          = unitId,
                            CustomerID      = CurrentUserInfo.ClientID
                        };
                        vipCardStatusChangeLogBLL.Create(oldVipCardStatusChangeLogEntity);

                        //入升级日志
                        var vipCardGradeChangeLogBll = new VipCardGradeChangeLogBLL(CurrentUserInfo);
                        var vipCardUpgradeRuleBll    = new VipCardUpgradeRuleBLL(CurrentUserInfo);
                        var vipCardUpgradeRuleEntity = vipCardUpgradeRuleBll.QueryByEntity(new VipCardUpgradeRuleEntity()
                        {
                            CustomerID = CurrentUserInfo.ClientID, VipCardTypeID = ObjecetTypeId
                        }, null).FirstOrDefault();
                        var VipCardGradeChangeLogEntity = new VipCardGradeChangeLogEntity()
                        {
                            ChangeLogID           = Guid.NewGuid().ToString().Replace("-", ""),
                            VipCardUpgradeRuleId  = vipCardUpgradeRuleEntity.VipCardUpgradeRuleId,
                            OrderType             = OrderType,
                            VipCardID             = oldVipCardInfo.VipCardID,
                            ChangeBeforeVipCardID = oldVipCardInfo.VipCardID,
                            ChangeBeforeGradeID   = oldVipCardTypeID,
                            NowGradeID            = oldVipCardInfo.VipCardTypeID,
                            ChangeReason          = "upgrade",
                            OperationType         = OperationType,
                            ChangeTime            = DateTime.Now,
                            UnitID     = unitId,
                            OrderId    = orderId,
                            CustomerID = CurrentUserInfo.ClientID,
                        };
                        vipCardGradeChangeLogBll.Create(VipCardGradeChangeLogEntity);

                        //开卡礼
                        var vipCardUpgradeRewardBll        = new VipCardUpgradeRewardBLL(CurrentUserInfo);
                        var vipCardUpgradeRewardEntityList = vipCardUpgradeRewardBll.QueryByEntity(new VipCardUpgradeRewardEntity()
                        {
                            VipCardTypeID = ObjecetTypeId
                        }, null);
                        var redisVipMappingCouponBLL = new JIT.CPOS.BS.BLL.RedisOperationBLL.Coupon.RedisVipMappingCouponBLL();
                        if (vipCardUpgradeRewardEntityList.Length > 0)
                        {
                            foreach (var vipCardUpgradeRewardEntity in vipCardUpgradeRewardEntityList)
                            {
                                for (int i = 0; i < vipCardUpgradeRewardEntity.CouponNum; i++)
                                {
                                    redisVipMappingCouponBLL.SetVipMappingCoupon(new CC_Coupon()
                                    {
                                        CustomerId   = CurrentUserInfo.ClientID,
                                        CouponTypeId = vipCardUpgradeRewardEntity.CouponTypeId.ToString()
                                    }, vipCardUpgradeRewardEntity.CardUpgradeRewardId.ToString(), vipId, "OpenVipCard");
                                }
                            }
                        }
                        //消费升级
                        if (OperationType == 2)
                        {
                            //群发消息表
                            var InnerGroupNewsBll    = new InnerGroupNewsBLL(CurrentUserInfo);
                            var innerGroupNewsEntity = new InnerGroupNewsEntity()
                            {
                                GroupNewsId        = Guid.NewGuid().ToString().Replace("-", ""),
                                SentType           = 2,
                                NoticePlatformType = 1,
                                BusType            = 3,
                                Title      = "升级提醒",
                                Text       = "升级成功",
                                CustomerID = CurrentUserInfo.ClientID
                            };
                            InnerGroupNewsBll.Create(innerGroupNewsEntity);
                            //消息和用户关系表
                            var newsUserMappingBll    = new NewsUserMappingBLL(CurrentUserInfo);
                            var newsUserMappingEntity = new NewsUserMappingEntity()
                            {
                                MappingID   = Guid.NewGuid().ToString().Replace("-", ""),
                                UserID      = vipId,
                                GroupNewsID = innerGroupNewsEntity.GroupNewsId,
                                CustomerId  = CurrentUserInfo.ClientID,
                                HasRead     = 0
                            };
                            newsUserMappingBll.Create(newsUserMappingEntity);
                        }
                    }
                }
                #endregion
            }
            catch { throw new APIException("升级失败!")
                          {
                              ErrorCode = ERROR_CODES.INVALID_BUSINESS
                          }; };

            //记录会员信息改变,并且把旧的会员的标识也放在契约里
            var eventService = new EventService();
            var vipMsg       = new EventContract
            {
                Operation  = OptEnum.Update,
                EntityType = EntityTypeEnum.Vip,
                Id         = vipId,
            };
            eventService.PublishMsg(vipMsg);

            return(ObjectNo);
        }
예제 #26
0
        public void Deal(EventContract msg)
        {
            var     bus = MqBusMgr.GetInstance();
            OptEnum operation;

            Enum.TryParse(msg.Operation.ToString(), out operation);
            var orderContract = new OrderContract()
            {
                Operation = operation,
                OrderId   = msg.Id
            };

            if (msg.Operation != Zmind.EventBus.Contract.OptEnum.Delete)
            {
                var orderFacade = new T_InoutFacade();
                var result      = orderFacade.GetOrderByOrderId(msg.Id);
                if (result == null)
                {
                    return;
                }

                var orderStatus = (EnumOrderStatus)Enum.Parse(typeof(EnumOrderStatus), result.Field7);
                if (orderStatus != EnumOrderStatus.PendingPay)
                {
                    //return;
                }
                orderContract.OrderNo            = result.order_no;
                orderContract.OrderType          = GetEnumOrderType(result.order_type_id);
                orderContract.OrderReason        = GetEnumOrderReason(result.order_reason_id);
                orderContract.OrderDate          = result.order_date ?? String.Empty;
                orderContract.RequestDate        = result.reserveDay ?? String.Empty;
                orderContract.RequestDateQuantum = result.reserveQuantum ?? String.Empty;
                orderContract.CompleteDate       = result.complete_date ?? String.Empty;
                orderContract.CreateUnit         = result.unit_id ?? String.Empty;
                orderContract.TotalAmount        = result.total_amount;
                orderContract.DiscountRate       = result.discount_rate;
                orderContract.ActualAmount       = result.actual_amount;
                orderContract.ReceivePoints      = result.receive_points;
                orderContract.PayPoints          = result.pay_points;
                orderContract.Remark             = result.remark ?? String.Empty;
                orderContract.Status             = orderStatus;
                orderContract.TotalQty           = result.total_qty;
                orderContract.TotalRetail        = result.total_retail;
                orderContract.KeepTheChange      = result.keep_the_change;
                orderContract.WipingZero         = result.wiping_zero;
                orderContract.VipNo         = result.vip_no ?? String.Empty;
                orderContract.CreateTime    = result.create_time ?? String.Empty;
                orderContract.CreateUserId  = result.create_user_id ?? String.Empty;
                orderContract.ApproveTime   = result.approve_time ?? String.Empty;
                orderContract.ApproveUserId = result.approve_user_id ?? String.Empty;
                orderContract.SendUserId    = result.send_user_id ?? String.Empty;
                orderContract.SendTime      = result.send_time ?? String.Empty;
                orderContract.AccpectUserId = result.accpect_user_id ?? String.Empty;
                orderContract.AccpectTime   = result.accpect_time ?? String.Empty;
                orderContract.ModifyUserId  = result.modify_user_id ?? String.Empty;
                orderContract.ModifyTime    = result.modify_time ?? String.Empty;
                orderContract.DataFrom      =
                    (EnumOrderDataFrom)Enum.Parse(typeof(EnumOrderDataFrom), result.data_from_id ?? _dataFrom);
                orderContract.SalesUnt          = result.sales_unit_id ?? String.Empty;
                orderContract.PurchaseUnit      = result.purchase_unit_id ?? String.Empty;
                orderContract.SalesWarehouse    = result.sales_warehouse_id ?? String.Empty;
                orderContract.PurchaseWarehouse = result.purchase_warehouse_id ?? String.Empty;
                orderContract.IsPay             = (EnumIsPay)int.Parse(result.Field1);
                orderContract.TrackingNumber    = result.Field2 ?? String.Empty;
                orderContract.BalancePayment    = result.Field3 ?? String.Empty;
                orderContract.Address           = result.Field4 ?? String.Empty;
                orderContract.Phone             = result.Field6 ?? String.Empty;
                orderContract.Delivery          = (EnumDelivery)int.Parse(result.Field8);
                orderContract.DeliveryDateTime  = result.Field9 ?? String.Empty;
                orderContract.UserName          = result.Field14 ?? String.Empty;
                orderContract.CashBack          = result.ReturnCash;
                orderContract.DetailList        = new List <OrderDetail>();

                #region 明细数据

                var orderDetailFacade = new T_InoutDetailFacade();
                var itemFacade        = new T_ItemFacade();

                var         resultList = orderDetailFacade.GetOrderDetailListByOrderId(msg.Id);
                OrderDetail tmpDetail;

                foreach (var detialEntity in resultList)
                {
                    var item = itemFacade.GetItemBySkuId(detialEntity.sku_id);

                    tmpDetail = new OrderDetail();
                    tmpDetail.OrderDetailId  = detialEntity.order_detail_id;
                    tmpDetail.SKUID          = detialEntity.sku_id;
                    tmpDetail.UnitId         = orderContract.CreateUnit;
                    tmpDetail.OrderQty       = detialEntity.order_qty;
                    tmpDetail.EnterQty       = detialEntity.enter_qty;
                    tmpDetail.EnterPrice     = detialEntity.enter_price;
                    tmpDetail.EnterAmount    = detialEntity.enter_amount;
                    tmpDetail.StdPrice       = detialEntity.std_price;
                    tmpDetail.RetailPrice    = detialEntity.retail_price;
                    tmpDetail.RetailAmount   = detialEntity.retail_amount;
                    tmpDetail.PlanPrice      = detialEntity.plan_price;
                    tmpDetail.ReceiverPoints = detialEntity.receive_points;
                    tmpDetail.PayPoints      = detialEntity.pay_points;
                    tmpDetail.Remark         = detialEntity.remark;
                    tmpDetail.PosOrderCode   = detialEntity.pos_order_code;
                    tmpDetail.DisplayIndex   = detialEntity.display_index;
                    tmpDetail.CreateTime     = detialEntity.create_time;
                    tmpDetail.CreateUserId   = detialEntity.create_user_id;
                    tmpDetail.ModifyTime     = detialEntity.modify_time;
                    tmpDetail.ModifyUser     = detialEntity.modify_user_id;
                    tmpDetail.ReturnCash     = detialEntity.ReturnCash;

                    if (item.ifservice == 1)
                    {
                        tmpDetail.SKUID = ConfigMgr.VirtualGoodsSkuId;
                    }

                    orderContract.DetailList.Add(tmpDetail);
                }
                #endregion
            }
            var json = new JavaScriptSerializer().Serialize(orderContract);//测试用,抓对象的json格式
            bus.Publish <IZmindToXgx>(orderContract);
        }
예제 #27
0
 public bool TryGetEventContract(string title, out EventContract contract)
 {
     return(EventContracts.TryGetValue(title, out contract));
 }
예제 #28
0
 public void updateInfoContract(EventContract info)
 {
     _info             = info;
     _title.text       = _info.nameEvent;
     _description.text = _info.detailEvent;
 }
예제 #29
0
        protected override EmptyResponseData ProcessRequest(DTO.Base.APIRequest <UpdateVipCardTypeSystemRP> pRequest)
        {
            var rd   = new EmptyResponseData();
            var para = pRequest.Parameters;
            var loggingSessionInfo   = new SessionManager().CurrentUserLoginInfo;
            var entitySysVipCardType = new SysVipCardTypeEntity();
            var bllSysVipCardType    = new SysVipCardTypeBLL(loggingSessionInfo);
            //卡分润规则
            var bllVipCardProfitRule = new VipCardProfitRuleBLL(loggingSessionInfo);
            //续费充值方式
            var VipCardReRechargeProfitRuleService = new VipCardReRechargeProfitRuleBLL(loggingSessionInfo);

            //编辑会员卡等级
            try
            {
                var SysVipCardTypeInfo = bllSysVipCardType.QueryByEntity(new SysVipCardTypeEntity()
                {
                    CustomerID = loggingSessionInfo.ClientID, VipCardTypeID = para.VipCardTypeID, IsDelete = 0
                }, null).FirstOrDefault();
                switch (para.OperateType)
                {
                //如果为1编辑会员卡等级信息
                case 1:
                    if (SysVipCardTypeInfo != null)
                    {
                        //获取当前会员信息
                        List <IWhereCondition> wheres = new List <IWhereCondition>();
                        wheres.Add(new EqualsCondition()
                        {
                            FieldName = "Category", Value = 0
                        });
                        wheres.Add(new EqualsCondition()
                        {
                            FieldName = "CustomerID", Value = loggingSessionInfo.ClientID
                        });
                        wheres.Add(new EqualsCondition()
                        {
                            FieldName = "VipCardTypeName", Value = para.VipCardTypeName
                        });
                        wheres.Add(new DirectCondition("VipCardLevel!='" + SysVipCardTypeInfo.VipCardLevel + "'"));
                        var ExistVipCardTypeResult = bllSysVipCardType.Query(wheres.ToArray(), null).FirstOrDefault();
                        if (ExistVipCardTypeResult != null)
                        {
                            throw new APIException("会员卡名称不能重复!")
                                  {
                                      ErrorCode = ERROR_CODES.INVALID_BUSINESS
                                  };
                        }
                        SysVipCardTypeInfo.VipCardTypeID   = para.VipCardTypeID;
                        SysVipCardTypeInfo.Category        = 0;
                        SysVipCardTypeInfo.VipCardTypeName = para.VipCardTypeName;
                        SysVipCardTypeInfo.VipCardLevel    = SysVipCardTypeInfo.VipCardLevel;
                        SysVipCardTypeInfo.IsPassword      = SysVipCardTypeInfo.IsPassword;
                        if (SysVipCardTypeInfo.VipCardLevel == 1)    //如果等级为1默认可充值
                        {
                            SysVipCardTypeInfo.Isprepaid = 1;
                        }
                        else
                        {
                            SysVipCardTypeInfo.Isprepaid = para.IsPrepaid;
                        }
                        SysVipCardTypeInfo.IsOnlineSales = para.IsOnlineSales;
                        SysVipCardTypeInfo.PicUrl        = para.PicUrl;
                        SysVipCardTypeInfo.CustomerID    = loggingSessionInfo.ClientID;
                        if (SysVipCardTypeInfo.VipCardLevel == 1)
                        {
                            SysVipCardTypeInfo.Prices           = 0;
                            SysVipCardTypeInfo.ExchangeIntegral = 0;
                            SysVipCardTypeInfo.IsExtraMoney     = 2;
                        }
                    }
                    //如果IsOnlineSales为0则需要逻辑删除分润规则数据
                    if (SysVipCardTypeInfo.IsOnlineSales == 0)
                    {
                        var VipCardProfitRuleInfo = bllVipCardProfitRule.QueryByEntity(new VipCardProfitRuleEntity()
                        {
                            VipCardTypeID = SysVipCardTypeInfo.VipCardTypeID, CustomerID = loggingSessionInfo.ClientID
                        }, null);
                        if (VipCardProfitRuleInfo.Length > 0)
                        {
                            bllVipCardProfitRule.Delete(VipCardProfitRuleInfo);
                        }
                    }

                    if (SysVipCardTypeInfo.Isprepaid == 0)     //不可充值
                    {
                        var VipCardUpgradeRuleService = new VipCardUpgradeRuleBLL(loggingSessionInfo);
                        //升级规则信息 永远只有一条信息
                        var CardUpgradeRuleEntity = VipCardUpgradeRuleService.QueryByEntity(new VipCardUpgradeRuleEntity()
                        {
                            VipCardTypeID = SysVipCardTypeInfo.VipCardTypeID
                        }, null);
                        if (CardUpgradeRuleEntity != null && CardUpgradeRuleEntity.FirstOrDefault() != null) //如果有设置了升级条件
                        {
                            if (CardUpgradeRuleEntity.FirstOrDefault().IsBuyUpgrade == 1)                    //消费升级+不可充值==>逻辑删除 会员卡销售激励规则
                            {
                                var Ids = bllVipCardProfitRule.QueryByEntity(new VipCardProfitRuleEntity()
                                {
                                    CustomerID = loggingSessionInfo.ClientID, VipCardTypeID = SysVipCardTypeInfo.VipCardTypeID
                                }, null).Select(m => m.CardBuyToProfitRuleId.Value.ToString()).ToArray();
                                if (Ids.Length > 0)
                                {
                                    bllVipCardProfitRule.Delete(Ids);
                                }
                            }
                        }

                        //将所有梯度信息 逻辑删除
                        string[] ProfitRuleIds = bllVipCardProfitRule.GetRechargeProfitRuleByIsPrepaid(loggingSessionInfo.ClientID, SysVipCardTypeInfo.VipCardTypeID);
                        if (ProfitRuleIds.Length > 0)
                        {
                            VipCardReRechargeProfitRuleService.Delete(ProfitRuleIds);
                        }
                    }
                    bllSysVipCardType.Update(SysVipCardTypeInfo);
                    //修改虚拟商品
#warning 商品代码注释 Bear
                    ItemService _ItemService = new ItemService(loggingSessionInfo);
                    _ItemService.SaveCardToOffenTItem(loggingSessionInfo, SysVipCardTypeInfo);
                    break;

                //如果为2编辑升级规则信息
                case 2:
                    var bllVipCardUpgradeRule = new VipCardUpgradeRuleBLL(loggingSessionInfo);
                    //升级类型不能为空 (1=购卡升级;2=充值升级;3=消费升级;)
                    if (para.UpGradeType != 0)
                    {
                        VipCardUpgradeRuleEntity vipCardUpgradeRuleEntity = new VipCardUpgradeRuleEntity();
                        if (para.OperateObjectID != null)
                        {
                            var VipCardUpgradeRuleInfo = bllVipCardUpgradeRule.QueryByEntity(new VipCardUpgradeRuleEntity()
                            {
                                CustomerID = loggingSessionInfo.ClientID, VipCardUpgradeRuleId = new Guid(para.OperateObjectID), VipCardTypeID = para.VipCardTypeID
                            }, null).FirstOrDefault();
                            if (VipCardUpgradeRuleInfo != null)
                            {
                                //先置为0 再进行更新
                                SysVipCardTypeInfo.IsExtraMoney           = 2;
                                SysVipCardTypeInfo.Prices                 = 0;
                                SysVipCardTypeInfo.ExchangeIntegral       = 0;
                                VipCardUpgradeRuleInfo.OnceRechargeAmount = 0;
                                VipCardUpgradeRuleInfo.OnceBuyAmount      = 0;
                                VipCardUpgradeRuleInfo.BuyAmount          = 0;
                                switch (para.UpGradeType)
                                {
                                case 1:
                                    VipCardUpgradeRuleInfo.IsPurchaseUpgrade = 1;
                                    //金额和积分 与可补差价在卡等级表里面
                                    SysVipCardTypeInfo.VipCardTypeID    = para.VipCardTypeID;
                                    SysVipCardTypeInfo.IsExtraMoney     = para.IsExtraMoney;
                                    SysVipCardTypeInfo.Prices           = para.Prices;
                                    SysVipCardTypeInfo.ExchangeIntegral = para.ExchangeIntegral;
                                    //充值升级归零
                                    VipCardUpgradeRuleInfo.IsRecharge = 0;
                                    //消费升级置零
                                    VipCardUpgradeRuleInfo.IsBuyUpgrade = 0;
                                    break;

                                case 2:
                                    VipCardUpgradeRuleInfo.IsPurchaseUpgrade  = 0;
                                    VipCardUpgradeRuleInfo.IsRecharge         = 1;
                                    VipCardUpgradeRuleInfo.IsBuyUpgrade       = 0;
                                    VipCardUpgradeRuleInfo.OnceRechargeAmount = para.OnceRechargeAmount;
                                    break;

                                case 3:
                                    VipCardUpgradeRuleInfo.IsPurchaseUpgrade = 0;
                                    VipCardUpgradeRuleInfo.IsRecharge        = 0;
                                    VipCardUpgradeRuleInfo.IsBuyUpgrade      = 1;
                                    VipCardUpgradeRuleInfo.OnceBuyAmount     = para.OnceBuyAmount;
                                    VipCardUpgradeRuleInfo.BuyAmount         = para.BuyAmount;
                                    //如果该卡为不可充值 那么就默认删除
                                    var syscardentity = bllSysVipCardType.GetByID(para.VipCardTypeID);
                                    if (syscardentity != null && syscardentity.Isprepaid == 0)         //消费升级 {不可充值} 默认删除该卡的激励规则
                                    {
                                        var Ids = bllVipCardProfitRule.QueryByEntity(new VipCardProfitRuleEntity()
                                        {
                                            CustomerID = loggingSessionInfo.ClientID, VipCardTypeID = para.VipCardTypeID
                                        }, null).Select(m => m.CardBuyToProfitRuleId.Value.ToString()).ToArray();
                                        if (Ids.Length > 0)
                                        {
                                            bllVipCardProfitRule.Delete(Ids);
                                        }
                                    }
                                    break;
                                }
                                //更新卡等级部分信息
                                bllSysVipCardType.Update(SysVipCardTypeInfo);
                                //修改虚拟商品
                                ItemService _ItemServices = new ItemService(loggingSessionInfo);
                                _ItemServices.SaveCardToOffenTItem(loggingSessionInfo, SysVipCardTypeInfo);
                                bllVipCardUpgradeRule.Update(VipCardUpgradeRuleInfo);
                            }
                        }
                        else
                        {
                            //先置为0 再进行更新
                            SysVipCardTypeInfo.IsExtraMoney             = 2;
                            SysVipCardTypeInfo.Prices                   = 0;
                            SysVipCardTypeInfo.ExchangeIntegral         = 0;
                            vipCardUpgradeRuleEntity.OnceRechargeAmount = 0;
                            vipCardUpgradeRuleEntity.OnceBuyAmount      = 0;
                            vipCardUpgradeRuleEntity.BuyAmount          = 0;
                            switch (para.UpGradeType)
                            {
                            case 1:
                                vipCardUpgradeRuleEntity.IsPurchaseUpgrade = 1;
                                vipCardUpgradeRuleEntity.VipCardTypeID     = para.VipCardTypeID;
                                //金额和积分 与可补差价在卡等级表里面
                                SysVipCardTypeInfo.VipCardTypeID    = para.VipCardTypeID;
                                SysVipCardTypeInfo.IsExtraMoney     = para.IsExtraMoney;
                                SysVipCardTypeInfo.Prices           = para.Prices;
                                SysVipCardTypeInfo.ExchangeIntegral = para.ExchangeIntegral;
                                //充值升级归零
                                vipCardUpgradeRuleEntity.IsRecharge = 0;
                                //消费升级置零
                                vipCardUpgradeRuleEntity.IsBuyUpgrade = 0;
                                break;

                            case 2:
                                vipCardUpgradeRuleEntity.IsPurchaseUpgrade  = 0;
                                vipCardUpgradeRuleEntity.IsRecharge         = 1;
                                vipCardUpgradeRuleEntity.IsBuyUpgrade       = 0;
                                vipCardUpgradeRuleEntity.OnceRechargeAmount = para.OnceRechargeAmount;
                                break;

                            case 3:          //消费升级
                                vipCardUpgradeRuleEntity.IsPurchaseUpgrade = 0;
                                vipCardUpgradeRuleEntity.IsRecharge        = 0;
                                vipCardUpgradeRuleEntity.IsBuyUpgrade      = 1;
                                vipCardUpgradeRuleEntity.OnceBuyAmount     = para.OnceBuyAmount;
                                vipCardUpgradeRuleEntity.BuyAmount         = para.BuyAmount;
                                break;
                            }
                            //更新卡等级部分信息
                            bllSysVipCardType.Update(SysVipCardTypeInfo);
                            //修改虚拟商品
                            ItemService _ItemServices = new ItemService(loggingSessionInfo);
                            _ItemServices.SaveCardToOffenTItem(loggingSessionInfo, SysVipCardTypeInfo);
                            //添加卡升级规则
                            vipCardUpgradeRuleEntity.VipCardUpgradeRuleId = Guid.NewGuid();
                            vipCardUpgradeRuleEntity.CustomerID           = loggingSessionInfo.ClientID;
                            bllVipCardUpgradeRule.Create(vipCardUpgradeRuleEntity);
                        }
                    }
                    else
                    {
                        throw new APIException("升级类型不能为空!")
                              {
                                  ErrorCode = ERROR_CODES.INVALID_BUSINESS
                              };
                    }

                    break;

                //如果为3编辑基本权益信息
                case 3:
                    var bllVipCardRule    = new VipCardRuleBLL(loggingSessionInfo);
                    var entityVipCardRule = new VipCardRuleEntity();
                    var VipCardRuleInfo   = bllVipCardRule.QueryByEntity(new VipCardRuleEntity()
                    {
                        CustomerID = loggingSessionInfo.ClientID, RuleID = Convert.ToInt32(para.OperateObjectID), VipCardTypeID = para.VipCardTypeID
                    }, null).FirstOrDefault();
                    if (VipCardRuleInfo != null)
                    {
                        entityVipCardRule.RuleID               = Convert.ToInt32(para.OperateObjectID);
                        entityVipCardRule.VipCardTypeID        = para.VipCardTypeID;
                        entityVipCardRule.CardDiscount         = para.CardDiscount * 10;
                        entityVipCardRule.PaidGivePoints       = para.PaidGivePoints;
                        entityVipCardRule.PaidGivePercetPoints = para.PaidGivePercetPoints;
                        entityVipCardRule.CustomerID           = loggingSessionInfo.ClientID;
                        bllVipCardRule.Update(entityVipCardRule);
                    }
                    break;
                }

                try
                {
                    var msg = new EventContract
                    {
                        Operation  = OptEnum.Update,
                        EntityType = EntityTypeEnum.VipCardType,
                        Id         = SysVipCardTypeInfo.VipCardTypeID.ToString()
                    };
                    var eventService = new EventService();
                    eventService.PublishMsg(msg);
                }
                catch (Exception)
                {
                    throw new Exception("RabbitMQ Error");
                }
            }
            catch (APIException ex)
            {
                throw ex;
            }

            return(rd);
        }
예제 #30
0
        public void updateVipCardByType(string vipId, int vipCardTypeId, string changeReason, string remark, string vipCode, IDbTransaction pTran)
        {
            var vipCardVipMappingBLL      = new VipCardVipMappingBLL(CurrentUserInfo);
            var sysVipCardTypeBLL         = new SysVipCardTypeBLL(CurrentUserInfo);
            var vipCardBLL                = new VipCardBLL(CurrentUserInfo);
            var vipCardStatusChangeLogBLL = new VipCardStatusChangeLogBLL(CurrentUserInfo);

            UnitService unitServer = new UnitService(CurrentUserInfo);
            string      unitId     = unitServer.GetUnitByUnitTypeForWX("总部", null).Id; //获取总部门店标识

            VipCardEntity vipCardInfo = vipCardBLL.GetVipCardByVipMapping(vipId);

            //更新卡信息
            vipCardInfo.VipCardTypeID = vipCardTypeId;
            vipCardBLL.Update(vipCardInfo, pTran);

            //var vipCardInfo = vipCardBLL.QueryByEntity(new VipCardEntity() { VipCardTypeID = vipCardTypeId, VipCardStatusId = 0, MembershipUnit = "" }, null).FirstOrDefault();

            //不存在,制卡
            //if (vipCardInfo == null)
            //{
            //    vipCardInfo = new VipCardEntity();
            //    vipCardInfo.VipCardID = Guid.NewGuid().ToString();
            //    vipCardInfo.VipCardTypeID = vipCardTypeId;
            //    vipCardInfo.VipCardTypeName = vipCardTypeName;
            //    vipCardInfo.VipCardCode = vipCode;
            //    vipCardInfo.VipCardStatusId = 1;//正常
            //    vipCardInfo.MembershipUnit = unitId;
            //    vipCardInfo.MembershipTime = DateTime.Now;
            //    vipCardInfo.CustomerID = CurrentUserInfo.ClientID;
            //    vipCardBLL.Create(vipCardInfo, pTran);
            //}

            //新增会员卡操作状态信息
            var vipCardStatusChangeLogEntity = new VipCardStatusChangeLogEntity()
            {
                LogID           = Guid.NewGuid().ToString().Replace("-", ""),
                VipCardStatusID = vipCardInfo.VipCardStatusId,
                VipCardID       = vipCardInfo.VipCardID,
                Action          = "升级",
                Reason          = changeReason,
                Remark          = remark,
                UnitID          = unitId,
                CustomerID      = CurrentUserInfo.ClientID
            };

            vipCardStatusChangeLogBLL.Create(vipCardStatusChangeLogEntity, pTran);


            var vipCardVipMappingEntity = vipCardVipMappingBLL.QueryByEntity(new VipCardVipMappingEntity()
            {
                VipCardID = vipCardInfo.VipCardID
            }, null).FirstOrDefault();

            vipCardVipMappingEntity.LastUpdateTime = DateTime.Now;

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

            //记录会员信息改变,并且把旧的会员的标识也放在契约里
            var eventService = new EventService();
            var vipMsg       = new EventContract
            {
                Operation  = OptEnum.Update,
                EntityType = EntityTypeEnum.Vip,
                Id         = vipId,
            };

            eventService.PublishMsg(vipMsg);
        }