public void SaveEntity(int?keyValue, dm_user_relationEntity entity)
 {
     try
     {
         if (keyValue > 0)
         {
             entity.Modify(keyValue);
             BaseRepository("dm_data").Update(entity);
         }
         else
         {
             entity.Create();
             BaseRepository("dm_data").Insert(entity);
         }
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         throw ExceptionEx.ThrowServiceException(ex);
     }
 }
示例#2
0
        /// <summary>
        /// 发布任务
        /// </summary>
        /// <param name="entity"></param>
        public void ReleaseTask(dm_taskEntity entity)
        {
            IRepository db = null;

            try
            {
                if (entity.singlecommission <= 0)
                {
                    throw new Exception("任务佣金不能小于0!");
                }
                if (entity.needcount <= 0)
                {
                    throw new Exception("任务参与数不能小于0!");
                }
                dm_userEntity dm_UserEntity = dm_UserService.GetEntity(entity.user_id);

                entity.totalcommission = entity.singlecommission * entity.needcount;//需要从用户账户扣除的金额
                if (dm_UserEntity.accountprice < entity.totalcommission)
                {
                    throw new Exception("账户余额不足,请充值后重新发布!");
                }

                dm_user_relationEntity dm_User_RelationEntity = dm_UserRelationService.GetEntityByUserID(entity.user_id);
                if (dm_User_RelationEntity.IsEmpty())
                {
                    throw new Exception("用户数据异常!");
                }

                dm_basesettingEntity dm_BaseSettingEntity = dm_BaseSettingService.GetEntityByCache(entity.appid);
                entity.seniorcommission = Math.Round((entity.singlecommission * dm_BaseSettingEntity.task_do_senior) / 100, 2);  //高级代理佣金
                entity.juniorcommission = Math.Round((entity.singlecommission * dm_BaseSettingEntity.task_do_junior) / 100, 2);  //初级代理佣金
                entity.servicefee       = Math.Round((entity.singlecommission * dm_BaseSettingEntity.task_servicefee) / 100, 2); //任务服务费(奖励在服务费中分发)
                entity.task_no          = DateTime.Now.ToString("yyyyMMddHHmmssfff") + entity.user_id.ToString().PadLeft(6, '0');
                entity.sort             = GetSort(dm_User_RelationEntity, entity.totalcommission);

                if (dm_BaseSettingEntity.taskchecked == 1)
                {
                    entity.task_status = -2;
                }
                else
                {
                    entity.task_status = 0;
                }

                entity.Create();
                dm_UserEntity.accountprice -= entity.totalcommission;
                dm_UserEntity.Modify(dm_UserEntity.id);
                dm_User_RelationEntity.taskcount += 1;
                dm_User_RelationEntity.Modify(dm_User_RelationEntity.id);


                dm_accountdetailEntity dm_AccountdetailEntity = new dm_accountdetailEntity
                {
                    createtime   = DateTime.Now,
                    remark       = "发布任务扣除" + entity.task_no,
                    stepvalue    = entity.totalcommission,
                    currentvalue = dm_UserEntity.accountprice,
                    title        = "发布任务",
                    type         = 12,
                    profitLoss   = CommonHelper.GetProfitLoss(12),
                    user_id      = entity.user_id
                };

                db = BaseRepository("dm_data").BeginTrans();
                db.Insert(entity);
                db.Update(dm_UserEntity);
                db.Insert(dm_AccountdetailEntity);
                db.Update(dm_User_RelationEntity);
                db.Commit();
            }
            catch (Exception ex)
            {
                if (db != null)
                {
                    db.Rollback();
                }

                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }
        /// <summary>
        /// 更改会员上级并重置两个会员的统计数据
        /// </summary>
        /// <param name="UserID">需要设置上级的会员ID</param>
        /// <param name="ParentID">需要设置到的会员ID</param>
        public void UpdateUserParent(int UserID, int ParentID)
        {
            try
            {
                dm_user_relationEntity dm_User_RelationEntity = GetEntityByUserID(UserID);


                if (dm_User_RelationEntity.IsEmpty())
                {
                    throw new Exception("当前会员信息异常!");
                }
                int old_ParentUserID = dm_User_RelationEntity.parent_id;

                dm_user_relationEntity dm_User_ParentRelationEntity = GetEntityByUserID(UserID);
                if (dm_User_ParentRelationEntity.IsEmpty())
                {
                    throw new Exception("上级会员信息异常!");
                }

                if (dm_User_RelationEntity.parent_id == ParentID)
                {
                    throw new Exception("当前用户已属于该邀请人,无需重复设置!");
                }

                if (dm_User_ParentRelationEntity.parent_id == UserID)
                {
                    throw new Exception("用户关系无法双向绑定!");
                }

                if (dm_User_RelationEntity.partners_id != dm_User_ParentRelationEntity.partners_id)
                {
                    throw new Exception("当前设置关系不在同一团队,无法操作!");
                }

                dm_userEntity parentUserEntity = this.BaseRepository("dm_data").FindEntity <dm_userEntity>(ParentID);

                dm_User_RelationEntity.parent_id       = ParentID;
                dm_User_RelationEntity.parent_nickname = parentUserEntity.nickname;
                dm_User_RelationEntity.Modify(dm_User_RelationEntity.id);
                this.BaseRepository("dm_data").Update(dm_User_RelationEntity);

                #region 重置统计信息
                string excuteStatistic = "";
                if (!parentUserEntity.IsEmpty())
                {
                    excuteStatistic += string.Format("CALL ResetStatistic({0},{1},{2});", ParentID, parentUserEntity.partnersstatus, parentUserEntity.partners ?? 0);
                }


                dm_userEntity oldParentUserEntity = this.BaseRepository("dm_data").FindEntity <dm_userEntity>(old_ParentUserID);
                if (!oldParentUserEntity.IsEmpty())
                {
                    excuteStatistic += string.Format("CALL ResetStatistic({0},{1},{2});", old_ParentUserID, oldParentUserEntity.partnersstatus, oldParentUserEntity.partners ?? 0);
                }

                if (!excuteStatistic.IsEmpty())
                {
                    this.BaseRepository("dm_data").ExecuteBySql(excuteStatistic);
                }
                #endregion
            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                throw ExceptionEx.ThrowServiceException(ex);
            }
        }