public override void Update(Guid id, object columData)
        {
            //账期不一致不可修改
            var old = this.Single(id);

            if (old == null)
            {
                throw new Exception("不存在记录");
            }

            if (old.CreateDate < MemoryData.Current.LastTime)
            {
                throw new Exception("配置数据,员工等级,工作组已发生变化,不可修改");
            }

            var currentSettle = new SettleBatchService(this.Context).GetOrGenCurrent();

            if (old.SettleNum != currentSettle.Num)
            {
                throw new Exception("已结算记录不可修改");
            }

            var     type   = columData.GetType();
            Guid    roomID = (Guid)(type.GetProperty(nameof(old.RoomID))?.GetValue(columData) ?? old.RoomID);
            decimal minC;
            var     result = this.CheckRomm(roomID, out minC);

            if (!result.Success)
            {
                throw new Exception(result.Message);
            }

            decimal amount  = (decimal)(type.GetProperty(nameof(old.Amount))?.GetValue(columData) ?? old.Amount);
            Guid    staffID = (Guid)(type.GetProperty(nameof(old.StaffID))?.GetValue(columData) ?? old.StaffID);
            //消费记录本人
            var staff = MemoryData.Current.Staffs.First(p => p.ID == staffID);
            //工作组管理员
            var managers = this._workGroupService.GetManagers(staff.ID);

            //如果没有达到最低消费,与该id关联的所有消费全部删除,否则只修改本记录即可
            try
            {
                this.Context.Context.Ado.BeginTran();
                base.Update(id, columData);
                this.Context.Context.Deleteable <Royalty>(p => p.ConsumeDataID == id).ExecuteCommand();
                if (amount >= minC)
                {
                    //增加消费记录
                    AddRoy(old.ID, staff, managers, currentSettle.Num);
                }
                this.Context.Context.Ado.CommitTran();
            }
            catch (Exception e)
            {
                this.Context.Context.Ado.RollbackTran();
                throw e;
            }
        }
Exemple #2
0
        public OperateResult Settlement()
        {
            var currentSettle = new SettleBatchService(this.Context).GetOrGenCurrent();

            var data = new RoyaltyService().Statistics(currentSettle.Num);

            var settleBatchService = new SettleBatchService(this.Context);

            try
            {
                this.Context.Context.Ado.BeginTran();

                //1.将计算数据写入
                this.Context.RoyaltySettles.InsertRange(data.Select(item => new RoyaltySettle
                {
                    ID         = Guid.NewGuid(),
                    CreateDate = DateTime.Now,
                    ModifyDate = DateTime.Now,
                    IsExpend   = false,
                    IsSelf     = false,
                    SettleNum  = currentSettle.Num,
                    StaffID    = item.StaffID,
                    State      = (int)DataState.Normal,
                    Json       = item.Items.LogJson()
                }).ToArray());

                //2.当前账期结束
                settleBatchService.Update(currentSettle.ID, new
                {
                    IsHistory = true,
                    EndTime   = DateTime.Now
                });
                //3.开始新的账期
                settleBatchService.GetOrGenCurrent();

                this.Context.Context.Ado.CommitTran();
                return(new OperateResult());
            }
            catch (Exception e)
            {
                this.Context.Context.Ado.RollbackTran();
                throw e;
            }
        }
        public override Guid Insert(ConsumeData entity)
        {
            if (entity.ID == new Guid())
            {
                entity.ID = Guid.NewGuid();
            }

            decimal minC;
            var     result = this.CheckRomm(entity.RoomID, out minC);

            if (!result.Success)
            {
                throw new Exception(result.Message);
            }

            var currentSettle = new SettleBatchService(this.Context).GetOrGenCurrent();

            entity.SettleNum = currentSettle.Num;
            //消费记录本人
            var staff = MemoryData.Current.Staffs.First(p => p.ID == entity.StaffID);
            //工作组管理员
            var managers = this._workGroupService.GetManagers(staff.ID);

            try
            {
                this.Context.Context.Ado.BeginTran();
                var consumeDataID = base.Insert(entity);
                if (entity.Amount >= minC)
                {
                    //增加消费记录
                    AddRoy(entity.ID, staff, managers, currentSettle.Num);
                }
                this.Context.Context.Ado.CommitTran();
                return(entity.ID);
            }
            catch (Exception e)
            {
                this.Context.Context.Ado.RollbackTran();
                throw e;
            }
        }