public dm_userEntity GetEntityByCache(int id)
 {
     try
     {
         string        cacheKey      = "UserInfo" + id.ToString();
         dm_userEntity dm_UserEntity = redisCache.Read <dm_userEntity>(cacheKey, 7L);
         if (dm_UserEntity == null)
         {
             dm_UserEntity = GetEntity(id);
             if (dm_UserEntity != null)
             {
                 redisCache.Write(cacheKey, dm_UserEntity, 7L);
             }
         }
         return(dm_UserEntity);
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         throw ExceptionEx.ThrowServiceException(ex);
     }
 }
        public List <string> GetShareImage(int user_id, string appid)
        {
            try
            {
                dm_userEntity dm_UserEntity = GetEntityByCache(user_id);
                if (dm_UserEntity.IsEmpty())
                {
                    throw new Exception("用户信息异常!");
                }
                if (dm_UserEntity.headpic.IsEmpty())
                {
                    throw new Exception("您先上传个人头像!");
                }

                List <string> shareList = new List <string>();

                string basePath = System.AppDomain.CurrentDomain.BaseDirectory.TrimEnd("\\".ToCharArray());

                string newPath1 = "/Resource/ShareImage/Share" + user_id + "1.jpg";
                string newPath2 = "/Resource/ShareImage/Share" + user_id + "2.jpg";
                string newPath3 = "/Resource/ShareImage/Share" + user_id + "3.jpg";

                dm_basesettingEntity dm_BasesettingEntity = dm_BaseSettingService.GetEntityByCache(appid);

                if (File.Exists(basePath + newPath1) && File.Exists(basePath + newPath2) && File.Exists(basePath + newPath3))
                {
                    shareList.Add(dm_BasesettingEntity.qianzhui_image + newPath1);
                    shareList.Add(dm_BasesettingEntity.qianzhui_image + newPath2);
                    shareList.Add(dm_BasesettingEntity.qianzhui_image + newPath3);
                }
                else
                {
                    Bitmap qrCode = QRCodeHelper.Generate3(dm_UserEntity.invitecode, 200, 200, basePath + dm_UserEntity.headpic);

                    //背景图片,海报背景
                    string path1 = basePath + @"/Resource/ShareImage/1.jpg";
                    string path2 = basePath + @"/Resource/ShareImage/2.jpg";
                    string path3 = basePath + @"/Resource/ShareImage/3.jpg";
                    GeneralShareImage(basePath + newPath1, path1, qrCode);
                    shareList.Add(dm_BasesettingEntity.qianzhui_image + newPath1);
                    GeneralShareImage(basePath + newPath2, path2, qrCode);
                    shareList.Add(dm_BasesettingEntity.qianzhui_image + newPath2);
                    GeneralShareImage(basePath + newPath3, path3, qrCode);
                    shareList.Add(dm_BasesettingEntity.qianzhui_image + newPath3);
                }

                return(shareList);
            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                throw ExceptionEx.ThrowServiceException(ex);
            }
        }
Example #3
0
        public void ApplyAccountCash(int user_id, decimal price, string remark)
        {
            IRepository db = null;

            try
            {
                dm_userEntity dm_UserEntity = dm_UserIBLL.GetEntity(user_id);//不从缓存取,此处需要验证账户余额
                if (dm_UserEntity.IsEmpty())
                {
                    throw new Exception("用户信息异常!");
                }
                if (price > dm_UserEntity.accountprice)
                {
                    throw new Exception("账户余额不足!");
                }
                else
                {
                    dm_UserEntity.accountprice -= price;
                    dm_UserEntity.Modify(user_id);

                    #region 增加提现记录
                    dm_apply_cashrecordEntity dm_Apply_CashrecordEntity = new dm_apply_cashrecordEntity();
                    dm_Apply_CashrecordEntity.user_id      = user_id;
                    dm_Apply_CashrecordEntity.createtime   = DateTime.Now;
                    dm_Apply_CashrecordEntity.paytype      = 0;
                    dm_Apply_CashrecordEntity.price        = price;
                    dm_Apply_CashrecordEntity.currentprice = dm_UserEntity.accountprice;
                    dm_Apply_CashrecordEntity.remark       = remark;
                    dm_Apply_CashrecordEntity.status       = 0;
                    #endregion

                    db = BaseRepository("dm_data").BeginTrans();
                    db.Update(dm_UserEntity);
                    db.Insert(dm_Apply_CashrecordEntity);

                    db.Commit();
                }
            }
            catch (Exception ex)
            {
                if (db != null)
                {
                    db.Rollback();
                }
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }
Example #4
0
 public dm_userEntity Register(dm_userEntity dm_UserEntity, string VerifiCode, string appid)
 {
     try
     {
         return(dM_UserService.Register(dm_UserEntity, VerifiCode, appid));
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         throw ExceptionEx.ThrowBusinessException(ex);
     }
 }
Example #5
0
 public dm_userEntity Login(dm_userEntity entity)
 {
     try
     {
         return(dM_UserService.Login(entity));
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         throw ExceptionEx.ThrowBusinessException(ex);
     }
 }
Example #6
0
 public void SaveEntity(int keyValue, dm_userEntity entity)
 {
     try
     {
         dM_UserService.SaveEntity(keyValue, entity);
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         throw ExceptionEx.ThrowBusinessException(ex);
     }
 }
Example #7
0
 /// <summary>
 /// 手机号快捷登录
 /// </summary>
 /// <param name="dm_UserEntity"></param>
 /// <param name="ParentInviteCode"></param>
 /// <param name="appid"></param>
 /// <returns></returns>
 public dm_userEntity QuickLogin(dm_userEntity dm_UserEntity, string ParentInviteCode, string appid)
 {
     try
     {
         return(dM_UserService.QuickLogin(dm_UserEntity, ParentInviteCode, appid));
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         throw ExceptionEx.ThrowBusinessException(ex);
     }
 }
Example #8
0
 /// <summary>
 /// 手机号+验证码注册
 /// </summary>
 /// <param name="dm_UserEntity"></param>
 /// <param name="VerifiCode"></param>
 /// <param name="ParentInviteCode"></param>
 /// <param name="appid"></param>
 /// <param name="SmsMessageID"></param>
 /// <returns></returns>
 public dm_userEntity Register(dm_userEntity dm_UserEntity, string VerifiCode, string ParentInviteCode, string appid, string SmsMessageID)
 {
     try
     {
         return(dM_UserService.Register(dm_UserEntity, VerifiCode, ParentInviteCode, appid, SmsMessageID));
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         throw ExceptionEx.ThrowBusinessException(ex);
     }
 }
 public dm_userEntity Login(dm_userEntity entity)
 {
     try
     {
         entity.pwd = Md5Helper.Encrypt(entity.pwd, 16);
         return(BaseRepository("dm_data").FindEntity((dm_userEntity t) => t.phone == entity.phone && t.appid == entity.appid && t.pwd == entity.pwd));
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         throw ExceptionEx.ThrowServiceException(ex);
     }
 }
Example #10
0
        public void CheckCertificationRecord(dm_certifica_recordEntity entity)
        {
            IRepository db = null;

            try
            {
                if (entity.realstatus == 1)
                {
                    dm_certifica_recordEntity dm_Certifica_RecordEntity = GetEntity(entity.id);

                    dm_userEntity dm_UserEntity = new dm_userEntity();
                    dm_UserEntity.isreal       = 1;
                    dm_UserEntity.id           = dm_Certifica_RecordEntity.user_id;
                    dm_UserEntity.realname     = dm_Certifica_RecordEntity.realname;
                    dm_UserEntity.frontcard    = dm_Certifica_RecordEntity.frontcard;
                    dm_UserEntity.facecard     = dm_Certifica_RecordEntity.facecard;
                    dm_UserEntity.identitycard = dm_Certifica_RecordEntity.cardno;

                    db = this.BaseRepository("dm_data").BeginTrans();
                    db.Update(dm_UserEntity);
                    entity.Modify(entity.id);
                    db.Update(entity);

                    db.Commit();
                }
                else if (entity.realstatus == 2)
                {
                    this.BaseRepository("dm_data").Update <dm_certifica_recordEntity>(entity);
                }
            }
            catch (Exception ex)
            {
                if (db != null)
                {
                    db.Rollback();
                }
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }
        /// <summary>
        /// 自动分配京东pid
        /// </summary>
        public dm_userEntity AutoAssignJDPID(dm_userEntity dm_UserEntity)
        {
            IRepository db = null;

            try
            {
                dm_pidEntity dm_PidEntity = this.BaseRepository("dm_data").FindEntity <dm_pidEntity>("select * from dm_pid where usestate=0 and type=2 limit 1", null);
                if (dm_PidEntity == null)
                {
                    throw new Exception("无可用京东PID,请联系客服!");
                }
                string site_id = dm_PidEntity.pids.Split('_')[1];
                dm_UserEntity.Modify(dm_UserEntity.id);
                dm_UserEntity.jd_site = site_id;
                dm_UserEntity.jd_pid  = dm_PidEntity.pid;

                dm_PidEntity.user_id  = dm_UserEntity.id;
                dm_PidEntity.usestate = 1;
                dm_PidEntity.usetime  = DateTime.Now;

                db = this.BaseRepository("dm_data").BeginTrans();
                db.Update(dm_UserEntity);
                db.Update(dm_PidEntity);

                db.Commit();

                return(dm_UserEntity);
            }
            catch (Exception ex)
            {
                if (db != null)
                {
                    db.Rollback();
                }

                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }
 /// <summary>
 /// 自动分配拼多多pid
 /// </summary>
 /// <param name="dm_UserEntity"></param>
 /// <returns></returns>
 public dm_userEntity AutoAssignPDDPID(dm_userEntity dm_UserEntity)
 {
     try
     {
         return(dM_PidService.AutoAssignPDDPID(dm_UserEntity));
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowBusinessException(ex);
         }
     }
 }
Example #13
0
        public void CheckAppPartnersRecord(dm_apply_partners_recordEntity entity)
        {
            IRepository db = null;

            try
            {
                if (entity.status == 1)
                {
                    dm_apply_partners_recordEntity dm_Apply_Partners_RecordEntity = GetEntity(entity.id);

                    dm_userEntity dm_UserEntity = new dm_userEntity();
                    dm_UserEntity.partnersstatus = 2;
                    dm_UserEntity.partners       = 20000 + dm_Apply_Partners_RecordEntity.user_id;
                    dm_UserEntity.id             = dm_Apply_Partners_RecordEntity.user_id;

                    dm_Apply_Partners_RecordEntity.status = entity.status;

                    db = this.BaseRepository("dm_data").BeginTrans();
                    db.Update(dm_UserEntity);
                    entity.Modify(entity.id);
                    db.Update(entity);

                    db.Commit();
                }
            }
            catch (Exception ex)
            {
                if (db != null)
                {
                    db.Rollback();
                }

                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }
Example #14
0
        private dm_userEntity CalculateComission(int?user_id, decimal?commission, decimal?currentaccount)
        {
            dm_userEntity calculateComissionEntity = calculateComissionEntities.Where((dm_userEntity t) => t.id == user_id).FirstOrDefault();

            if (calculateComissionEntity.IsEmpty())
            {
                calculateComissionEntity = new dm_userEntity
                {
                    id           = user_id,
                    accountprice = currentaccount + commission
                };
                calculateComissionEntities.Add(calculateComissionEntity);
            }
            else
            {
                dm_userEntity dm_userEntity = calculateComissionEntity;
                dm_userEntity.accountprice += commission;
            }
            return(calculateComissionEntity);
        }
 public void ResetUserStatistic(int UserID)
 {
     try
     {
         dm_userEntity userEntity = this.BaseRepository("dm_data").FindEntity <dm_userEntity>(UserID);
         if (!userEntity.IsEmpty())
         {
             string excuteStatistic = string.Format("CALL ResetStatistic({0},{1},{2});", UserID, userEntity.partnersstatus, userEntity.partners ?? 0);
             this.BaseRepository("dm_data").ExecuteBySql(excuteStatistic);
         }
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         throw ExceptionEx.ThrowServiceException(ex);
     }
 }
 public void SaveEntity(int keyValue, dm_userEntity entity)
 {
     try
     {
         if (keyValue > 0)
         {
             entity.Modify(keyValue);
             BaseRepository("dm_data").Update(entity);
         }
         else
         {
             BaseRepository("dm_data").Insert(entity);
         }
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         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);
            }
        }
        public void ExcuteSubCommission(string appid)
        {
            IRepository db = null;

            try
            {
                int upMonth = int.Parse(DateTime.Now.AddMonths(-1).ToString("yyyyMM"));
                IEnumerable <dm_orderEntity>     orderList            = BaseRepository("dm_data").FindList((dm_orderEntity t) => t.order_receive_month == (int?)upMonth && t.rebate_status == (int?)0 && t.order_type_new == (int?)2 && t.appid == appid);
                IEnumerable <UserRelationEntity> userRelationEntities = BaseRepository("dm_data").FindList <UserRelationEntity>("select ur.user_id,ur.parent_id,ur.partners_id,u.partnersstatus,u.userlevel,u.accountprice from dm_user_relation ur LEFT JOIN dm_user u on ur.user_id=u.id");
                dm_basesettingEntity             dm_BasesettingEntity = dm_BaseSettingService.GetEntityByCache(appid);
                decimal               pay_comission                          = default(decimal);
                decimal               pay_one_comission2                     = default(decimal);
                decimal               pay_two_comission2                     = default(decimal);
                decimal               one_partners_comission2                = default(decimal);
                decimal               two_partners_comission2                = default(decimal);
                dm_userEntity         calculateComissionEntity2              = null;
                dm_userEntity         calculateComissionEntity_one2          = null;
                dm_userEntity         calculateComissionEntity_two2          = null;
                dm_userEntity         calculateComissionEntity_one_partners2 = null;
                dm_userEntity         calculateComissionEntity_two_partners2 = null;
                UserRelationEntity    pay_user           = null;
                UserRelationEntity    one_user           = null;
                UserRelationEntity    two_user2          = null;
                UserRelationEntity    one_partners_user  = null;
                UserRelationEntity    two_partners_user2 = null;
                List <dm_orderEntity> update_orderList   = new List <dm_orderEntity>();
                foreach (dm_orderEntity item in orderList)
                {
                    pay_user = userRelationEntities.Where((UserRelationEntity t) => t.user_id == item.userid).FirstOrDefault();
                    if (!pay_user.IsEmpty())
                    {
                        if (pay_user.userlevel == 0)
                        {
                            pay_comission = ConvertComission(item.estimated_effect * (decimal)dm_BasesettingEntity.shopping_pay_junior);
                        }
                        else if (pay_user.userlevel == 1)
                        {
                            pay_comission = ConvertComission(item.estimated_effect * (decimal)dm_BasesettingEntity.shopping_pay_middle);
                        }
                        else if (pay_user.userlevel == 2)
                        {
                            pay_comission = ConvertComission(item.estimated_effect * (decimal)dm_BasesettingEntity.shopping_pay_senior);
                        }
                        if (pay_comission > 0m)
                        {
                            calculateComissionEntity2 = CalculateComission(pay_user.user_id, pay_comission, pay_user.accountprice);
                            dm_AccountdetailEntities.Add(GeneralAccountDetail(pay_user.user_id, 1, "订单返佣", "您的订单" + item.order_status.ToString() + "佣金已到账,请查收!", pay_comission, calculateComissionEntity2.accountprice));
                        }
                        if (pay_user.parent_id != -1 && pay_comission > 0m)
                        {
                            one_user = userRelationEntities.Where((UserRelationEntity t) => t.user_id == pay_user.parent_id).FirstOrDefault();
                            if (!one_user.IsEmpty())
                            {
                                pay_one_comission2 = ConvertComission(pay_comission * (decimal)dm_BasesettingEntity.shopping_one);
                                if (pay_one_comission2 > 0m)
                                {
                                    calculateComissionEntity_one2 = CalculateComission(one_user.user_id, pay_one_comission2, one_user.accountprice);
                                    dm_AccountdetailEntities.Add(GeneralAccountDetail(one_user.user_id, 2, "粉丝订单返佣", "您的下级订单提成已到账,请查收!", pay_one_comission2, calculateComissionEntity_one2.accountprice));
                                }
                                if (one_user.parent_id != -1)
                                {
                                    two_user2 = userRelationEntities.Where((UserRelationEntity t) => t.user_id == one_user.parent_id).FirstOrDefault();
                                    if (!two_user2.IsEmpty())
                                    {
                                        pay_two_comission2 = ConvertComission(pay_comission * (decimal)dm_BasesettingEntity.shopping_two);
                                        if (pay_two_comission2 > 0m)
                                        {
                                            calculateComissionEntity_two2 = CalculateComission(two_user2.user_id, pay_two_comission2, two_user2.accountprice);
                                            dm_AccountdetailEntities.Add(GeneralAccountDetail(two_user2.user_id, 3, "粉丝订单返佣", "您的下下级订单提成已到账,请查收!", pay_two_comission2, calculateComissionEntity_two2.accountprice));
                                        }
                                    }
                                }
                            }
                        }
                        if (pay_user.partners_id > 0 && pay_comission > 0m)
                        {
                            one_partners_user = userRelationEntities.Where((UserRelationEntity t) => t.partners_id == pay_user.partners_id && t.partnersstatus == 1).FirstOrDefault();
                            if (!one_partners_user.IsEmpty())
                            {
                                one_partners_comission2 = ConvertComission(pay_comission * (decimal)dm_BasesettingEntity.shopping_one_partners);
                                if (one_partners_comission2 > 0m)
                                {
                                    calculateComissionEntity_one_partners2 = CalculateComission(one_partners_user.user_id, one_partners_comission2, one_partners_user.accountprice);
                                    dm_AccountdetailEntities.Add(GeneralAccountDetail(one_partners_user.user_id, 4, "团队订单返佣", "您的团队有订单已结算,提成已到账,请查收!", one_partners_comission2, calculateComissionEntity_one_partners2.accountprice));
                                }
                                if (one_partners_user.parent_id != -1)
                                {
                                    two_partners_user2 = userRelationEntities.Where((UserRelationEntity t) => t.user_id == one_partners_user.parent_id).FirstOrDefault();
                                    if (!two_partners_user2.IsEmpty())
                                    {
                                        two_partners_comission2 = ConvertComission(pay_comission * (decimal)dm_BasesettingEntity.shopping_two_partners);
                                        if (two_partners_comission2 > 0m)
                                        {
                                            calculateComissionEntity_two_partners2 = CalculateComission(two_partners_user2.user_id, two_partners_comission2, two_partners_user2.accountprice);
                                            dm_AccountdetailEntities.Add(GeneralAccountDetail(two_partners_user2.user_id, 5, "下级团队订单返佣", "您的下级团队有订单已结算,提成已到账,请查收!", two_partners_comission2, calculateComissionEntity_two_partners2.accountprice));
                                        }
                                    }
                                }
                            }
                        }
                        update_orderList.Add(new dm_orderEntity
                        {
                            id             = item.id,
                            rebate_status  = 1,
                            order_type_new = 4
                        });
                    }
                }
                if (dm_AccountdetailEntities.Count > 0)
                {
                    //清除当前结算用户的缓存信息
                    foreach (var item in calculateComissionEntities)
                    {
                        item.Modify(item.id);
                    }
                    db = BaseRepository("dm_data").BeginTrans();
                    db.Insert(dm_AccountdetailEntities);
                    db.Update(calculateComissionEntities);
                    db.Update(update_orderList);
                    db.Commit();
                }
            }
            catch (Exception ex)
            {
                db?.Rollback();
                if (ex is ExceptionEx)
                {
                    throw;
                }
                throw ExceptionEx.ThrowServiceException(ex);
            }
        }
Example #19
0
        public void ApplyChangeGood(dm_intergralchangerecordEntity dm_IntergralchangerecordEntity, dm_userEntity dm_UserEntity)
        {
            IRepository db = BaseRepository("dm_data").BeginTrans();

            try
            {
                DM_IntergralChangeGoodService dM_IntergralChangeGoodService = new DM_IntergralChangeGoodService();
                dm_intergralchangegoodEntity  dm_IntergralchangegoodEntity  = dM_IntergralChangeGoodService.GetEntity(dm_IntergralchangerecordEntity.goodid.ToInt());
                if (dm_IntergralchangegoodEntity == null)
                {
                    throw new Exception("该商品不存在!");
                }
                if (!(dm_UserEntity.integral >= dm_IntergralchangegoodEntity.needintergral))
                {
                    throw new Exception("账户积分不足!");
                }
                db.Insert(dm_IntergralchangerecordEntity);
                dm_UserEntity.integral -= dm_IntergralchangegoodEntity.needintergral;
                dm_UserEntity.Modify(dm_UserEntity.id);
                db.Update(dm_UserEntity);
                db.Commit();
            }
            catch (Exception ex)
            {
                db.Rollback();
                if (ex is ExceptionEx)
                {
                    throw;
                }
                throw ExceptionEx.ThrowServiceException(ex);
            }
        }
Example #20
0
        public IEnumerable <dm_task_person_settingEntity> GetPersonProcess(int user_id, string appid)
        {
            try
            {
                IEnumerable <dm_task_person_settingEntity> person_SettingEntities = GetListByCache(appid, 0);
                foreach (var item in person_SettingEntities)
                {
                    //每日签到任务
                    if (item.s_type == 1)
                    {
                        //获取今日是否签到
                        dm_intergraldetailEntity dm_IntergraldetailEntity = dm_IntergralDetailService.GetLastSignData(user_id);
                        if (dm_IntergraldetailEntity.IsEmpty())
                        {
                            item.finishcount  = 0;
                            item.finishstatus = 0;
                            item.btntext      = "签到";
                        }
                        else
                        {
                            item.finishcount  = dm_IntergraldetailEntity.createtime.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd") ? 1 : 0;
                            item.finishstatus = item.finishcount == 1 ? 2 : 0;
                            item.btntext      = item.finishstatus == 0 ? "签到" : "已完成";
                        }
                    }
                    else if (item.s_type == 2)
                    {//邀请粉丝任务
                        dm_userEntity dm_UserEntity = dm_UserService.GetEntityByCache(user_id);
                        item.finishcount  = (int)dm_UserEntity.mychildcount;
                        item.finishstatus = GetFinishStatus(item.finishcount, item.needcount, user_id, item.id);
                        item.remark      += string.Format("({0}/{1})", item.finishcount, item.needcount);

                        item.btntext = getBtnText(item.finishstatus, item.s_type);
                    }
                    else if (item.s_type == 4)
                    {//购物任务
                        dm_user_relationEntity dm_User_RelationEntity = dm_UserRelationService.GetEntityByUserID(user_id);
                        item.finishcount  = dm_User_RelationEntity.ordercount;
                        item.finishstatus = GetFinishStatus(item.finishcount, item.needcount, user_id, item.id);

                        item.remark += string.Format("({0}/{1})", item.finishcount, item.needcount);

                        item.btntext = getBtnText(item.finishstatus, item.s_type);
                    }
                    else if (item.s_type == 6)
                    {
                        item.finishstatus = GetFinishStatus(item.finishcount, item.needcount, user_id, item.id);
                        item.finishcount  = 0;//浏览任务此字段无意义

                        item.btntext = item.finishstatus == 2 ? "已完成" : "去浏览";
                    }
                }
                return(person_SettingEntities);
            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }
Example #21
0
        public void ReceiveAwards(int user_id, int?task_id)
        {
            IRepository db = null;

            try
            {
                #region 获取任务记录
                dm_task_person_settingEntity dm_Task_Person_SettingEntity = GetEntity(task_id);
                #endregion
                if (dm_Task_Person_SettingEntity.s_type == 1)
                {
                    dm_UserService.SignIn(user_id);
                }
                else
                {
                    dm_userEntity dm_UserEntity = dm_UserService.GetEntityByCache(user_id);

                    if (dm_Task_Person_SettingEntity.s_type == 4)
                    {
                        dm_user_relationEntity dm_User_RelationEntity = dm_UserRelationService.GetEntityByUserID(user_id);
                        if (dm_User_RelationEntity.ordercount < dm_Task_Person_SettingEntity.needcount)
                        {
                            throw new Exception("请完成购物任务后再来领取!");
                        }
                    }
                    else if (dm_Task_Person_SettingEntity.s_type == 2)
                    {
                        if (dm_UserEntity.mychildcount < dm_Task_Person_SettingEntity.needcount)
                        {
                            throw new Exception("请完成邀请任务后再来领取!");
                        }
                    }

                    dm_task_person_recordEntity dm_Task_Person_RecordEntity = dm_Task_Person_RecordService.GetMyPersonRecord(user_id, task_id);
                    if (dm_Task_Person_RecordEntity.IsEmpty())
                    {
                        #region 增加任务领取记录
                        dm_Task_Person_RecordEntity            = new dm_task_person_recordEntity();
                        dm_Task_Person_RecordEntity.user_id    = user_id;
                        dm_Task_Person_RecordEntity.task_id    = task_id;
                        dm_Task_Person_RecordEntity.createtime = DateTime.Now;
                        dm_Task_Person_RecordEntity.status     = 1;
                        #endregion


                        db = BaseRepository("dm_data").BeginTrans();
                        //积分任务
                        if (dm_Task_Person_SettingEntity.rewardtype == 0)
                        {
                            #region 增加积分变更明细
                            int stepvalue = int.Parse(dm_Task_Person_SettingEntity.rewardcount.ToString());//积分无小数
                            dm_intergraldetailEntity dm_IntergraldetailEntity = new dm_intergraldetailEntity();
                            dm_IntergraldetailEntity.type         = 4;
                            dm_IntergraldetailEntity.profitLoss   = 1;
                            dm_IntergraldetailEntity.user_id      = user_id;
                            dm_IntergraldetailEntity.createtime   = DateTime.Now;
                            dm_IntergraldetailEntity.currentvalue = dm_UserEntity.integral + stepvalue;
                            dm_IntergraldetailEntity.stepvalue    = stepvalue;
                            dm_IntergraldetailEntity.title        = dm_Task_Person_SettingEntity.title;
                            dm_IntergraldetailEntity.remark       = dm_Task_Person_SettingEntity.remark;
                            dm_IntergraldetailEntity.Create();

                            dm_UserEntity.integral = dm_IntergraldetailEntity.currentvalue;
                            #endregion
                            db.Insert(dm_UserEntity);
                        }
                        else
                        { //余额任务
                            #region 增加余额变更明细
                            dm_accountdetailEntity dm_AccountdetailEntity = new dm_accountdetailEntity();
                            dm_AccountdetailEntity.user_id      = user_id;
                            dm_AccountdetailEntity.type         = 10;
                            dm_AccountdetailEntity.profitLoss   = CommonHelper.GetProfitLoss(10);
                            dm_AccountdetailEntity.createtime   = DateTime.Now;
                            dm_AccountdetailEntity.currentvalue = dm_UserEntity.accountprice + dm_Task_Person_SettingEntity.rewardcount;
                            dm_AccountdetailEntity.stepvalue    = dm_Task_Person_SettingEntity.rewardcount;
                            dm_AccountdetailEntity.title        = dm_Task_Person_SettingEntity.title;
                            dm_AccountdetailEntity.remark       = dm_Task_Person_SettingEntity.remark;
                            dm_AccountdetailEntity.Create();
                            #endregion

                            dm_UserEntity.accountprice = dm_AccountdetailEntity.currentvalue;
                            db.Insert(dm_AccountdetailEntity);
                        }

                        dm_UserEntity.Modify(user_id);
                        db.Update(dm_UserEntity);
                        db.Insert(dm_Task_Person_RecordEntity);

                        db.Commit();
                    }
                    else
                    {
                        throw new Exception("该任务已领取!");
                    }
                }
            }
            catch (Exception ex)
            {
                if (db != null)
                {
                    db.Rollback();
                }

                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }
Example #22
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);
                }
            }
        }
Example #23
0
        public void CancelByReleasePerson(int task_id)
        {
            IRepository db = null;

            try
            {
                DM_Task_ReviceService dm_Task_ReviceService = new DM_Task_ReviceService();

                IEnumerable <dm_task_reviceEntity> dm_Task_ReviceEntities = dm_Task_ReviceService.GetReviceListByTaskID(task_id);
                if (dm_Task_ReviceEntities.Where(t => t.status == 1).Count() > 0)
                {
                    throw new Exception("存在正在进行中的记录,当前任务无法取消!");
                }
                if (dm_Task_ReviceEntities.Where(t => t.status == 2).Count() > 0)
                {
                    throw new Exception("当前存在未审核的资料,任务无法取消,请审核之后重试!");
                }
                dm_taskEntity dm_TaskEntity = GetEntity(task_id);
                if (dm_TaskEntity.task_status == 2)
                {
                    throw new Exception("该任务已取消!");
                }
                if (dm_TaskEntity.task_status == 1 || dm_TaskEntity.finishcount == dm_TaskEntity.needcount)
                {
                    throw new Exception("该任务已完成!");
                }
                if (dm_TaskEntity.finishcount > dm_TaskEntity.needcount)
                {
                    throw new Exception("错误码:1001--任务存在异常记录,请联系管理员!");
                }

                //取消任务
                dm_TaskEntity.task_status = 2;
                dm_userEntity dm_UserEntity = dm_UserService.GetEntity(dm_TaskEntity.user_id);

                #region 存在两种退款  1、全部退  2部分退
                decimal caclePrice = 0;
                if (dm_TaskEntity.finishcount == 0)
                {//全部退
                    caclePrice = dm_TaskEntity.totalcommission;
                }
                else
                {//部分退
                    caclePrice = Math.Round((dm_TaskEntity.needcount - dm_TaskEntity.finishcount) * dm_TaskEntity.singlecommission, 2);
                }
                dm_UserEntity.accountprice += caclePrice;
                #endregion

                dm_accountdetailEntity dm_AccountdetailEntity = new dm_accountdetailEntity
                {
                    createtime   = DateTime.Now,
                    remark       = "取消发布任务" + dm_TaskEntity.task_no,
                    stepvalue    = caclePrice,
                    currentvalue = dm_UserEntity.accountprice,
                    title        = "取消发布任务",
                    type         = 13,
                    profitLoss   = CommonHelper.GetProfitLoss(13),
                    user_id      = dm_TaskEntity.user_id
                };

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

                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }
Example #24
0
 public void ApplyChangeGood(dm_intergralchangerecordEntity dm_IntergralchangerecordEntity, dm_userEntity dm_UserEntity)
 {
     try
     {
         dM_IntergralChangeRecordService.ApplyChangeGood(dm_IntergralchangerecordEntity, dm_UserEntity);
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         throw ExceptionEx.ThrowBusinessException(ex);
     }
 }
Example #25
0
        public void RebutTaskByWeb(int id, string remark)
        {
            IRepository db = null;

            try
            {
                /*
                 * 1、修改任务状态为取消
                 * 2、修改账户余额
                 * 3、增加消息通知
                 */
                dm_taskEntity dm_TaskEntity = GetEntity(id);
                if (dm_TaskEntity.task_status != -2)
                {
                    throw new Exception("当前任务状态无法驳回!");
                }
                dm_TaskEntity.task_status = 2;

                dm_userEntity dm_UserEntity = dm_UserService.GetEntity(dm_TaskEntity.user_id);
                if (dm_UserEntity.IsEmpty())
                {
                    throw new Exception("用户信息异常!");
                }

                dm_UserEntity.accountprice += dm_TaskEntity.totalcommission;

                dm_accountdetailEntity dm_AccountdetailEntity = new dm_accountdetailEntity
                {
                    createtime   = DateTime.Now,
                    remark       = remark + "(" + dm_TaskEntity.task_no + ")",
                    stepvalue    = dm_TaskEntity.totalcommission,
                    currentvalue = dm_UserEntity.accountprice,
                    title        = "任务驳回",
                    type         = 23,
                    profitLoss   = CommonHelper.GetProfitLoss(23),
                    user_id      = dm_TaskEntity.user_id
                };

                dm_messagerecordEntity dm_MessagerecordEntity = new dm_messagerecordEntity
                {
                    createtime     = DateTime.Now,
                    user_id        = dm_TaskEntity.user_id,
                    isread         = 0,
                    messagetitle   = "任务驳回通知",
                    messagetype    = 4,
                    messagecontent = remark
                };

                db = this.BaseRepository("dm_data").BeginTrans();
                db.Update(dm_TaskEntity);
                db.Update(dm_UserEntity);
                db.Insert(dm_AccountdetailEntity);
                db.Insert(dm_MessagerecordEntity);
                db.Commit();
            }
            catch (Exception ex)
            {
                if (db != null)
                {
                    db.Rollback();
                }
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }
Example #26
0
        /// <summary>
        /// 支付回调中开通代理(并完成返佣)
        /// </summary>
        /// <param name="dm_Alipay_RecordEntity"></param>
        public void OpenAgent(dm_alipay_recordEntity dm_Alipay_RecordEntity)
        {
            IRepository db = null;

            try
            {
                /*
                 * 根据外部交易单号获取订单记录
                 * 更改用户状态并完成返利
                 * 1、一级代理返利(代理等级为初级、高级、合伙人才可得到2021-01-06)
                 * 2、二级代理返利(代理等级为初级、高级、合伙人才可得到2021-01-06)
                 * 3、三级代理返利(代理等级为初级、高级、合伙人才可得到2021-01-06)
                 * 3、一级合伙人(不校验代理等级,可能为后台开通)
                 * 4、二级合伙人(不校验代理等级,可能为后台开通)
                 */
                dm_alipay_recordEntity dm_Alipay_RecordEntity_old = this.BaseRepository("dm_data").FindEntity <dm_alipay_recordEntity>(t => t.out_trade_no == dm_Alipay_RecordEntity.out_trade_no);

                ///如果老的记录是已支付状态则不需要再执行修改和返利
                if (!dm_Alipay_RecordEntity_old.alipay_status.IsEmpty() && dm_Alipay_RecordEntity_old.alipay_status.ToUpper() == "TRADE_SUCCESS")
                {
                    return;
                }

                if (dm_Alipay_RecordEntity_old.templateid == 99)//余额充值
                {
                    dm_userEntity dm_UserEntity = dM_UserService.GetEntity(dm_Alipay_RecordEntity_old.user_id);
                    if (dm_UserEntity.IsEmpty())
                    {
                        throw new Exception("用户信息异常!");
                    }
                    ///修改账户余额
                    dm_UserEntity.accountprice += dm_Alipay_RecordEntity_old.total_amount;//充值成功后的账户余额
                    dm_UserEntity.Modify(dm_UserEntity.id);

                    dm_accountdetailEntity dm_AccountdetailEntity = GeneralAccountDetail(dm_Alipay_RecordEntity_old.user_id, 21, "余额充值", "账户充值", (decimal)dm_Alipay_RecordEntity_old.total_amount, dm_UserEntity.accountprice);

                    dm_Alipay_RecordEntity.Modify(dm_Alipay_RecordEntity_old.id);

                    db = BaseRepository("dm_data").BeginTrans();
                    db.Update(dm_UserEntity);
                    db.Insert(dm_AccountdetailEntity);
                    db.Update(dm_Alipay_RecordEntity);//优化支付成功未更改支付状态  造成金额多次修改
                    db.Commit();

                    CacheHelper.UpdateUserInfo(dm_UserEntity);
                }
                else
                {//代理开通
                    dm_AccountdetailEntities.Clear();
                    calculateComissionEntities.Clear();

                    decimal one_agent_commission = 0, two_agent_commission = 0, three_agent_commission = 0, one_partners_commission = 0, two_partners_commission = 0;

                    dm_userEntity currentUser = null, one_User = null, two_User = null, three_User = null, one_partners = null, two_partners = null;

                    string one_tip = "", two_tip = "", three_tip = "", one_parners_tip = "", two_parners_tip = "";

                    if (dm_Alipay_RecordEntity_old.IsEmpty())
                    {
                        throw new Exception("根据外部交易单号未能查询到支付记录,当前传入外部交易单号" + dm_Alipay_RecordEntity.out_trade_no);
                    }
                    dm_Alipay_RecordEntity.Modify(dm_Alipay_RecordEntity_old.id);//更改交易信息


                    #region 获取上下级关系
                    IEnumerable <dm_user_relationEntity> userRelationList = dM_UserRelationService.GetParentRelation(dm_Alipay_RecordEntity_old.user_id);
                    #endregion

                    #region 获取上下级关系的用户信息
                    IEnumerable <dm_userEntity> userList = dM_UserService.GetParentUser(dm_Alipay_RecordEntity_old.user_id);
                    #endregion

                    #region 更改当前用户等级
                    currentUser = userList.Where(t => t.id == dm_Alipay_RecordEntity_old.user_id).FirstOrDefault();
                    if (currentUser.IsEmpty())
                    {
                        throw new Exception("用户信息异常!");
                    }
                    //初级代理
                    if (dm_Alipay_RecordEntity_old.templateid == 1)
                    {
                        currentUser.userlevel = 1;
                    }
                    //高级代理
                    else if (dm_Alipay_RecordEntity_old.templateid == 2)
                    {
                        currentUser.userlevel = 2;
                    }
                    //升级代理
                    else if (dm_Alipay_RecordEntity_old.templateid == 3)
                    {
                        currentUser.userlevel = 2;
                    }
                    calculateComissionEntities.Add(currentUser);
                    #endregion

                    #region 增加开通代理消息记录
                    dm_messagerecordEntity dm_MessagerecordEntity = new dm_messagerecordEntity();
                    dm_MessagerecordEntity.user_id        = dm_Alipay_RecordEntity_old.user_id;
                    dm_MessagerecordEntity.messagetitle   = "开通代理";
                    dm_MessagerecordEntity.messagecontent = "代理开通成功,发展下级可享受永久提成!";
                    dm_MessagerecordEntity.messagetype    = 1;
                    dm_MessagerecordEntity.createtime     = DateTime.Now;
                    dm_MessagerecordEntity.isread         = 0;
                    #endregion

                    dm_basesettingEntity dm_BasesettingEntity = dM_BaseSettingService.GetEntityByCache(currentUser.appid);

                    dm_basesetting_tipEntity dm_Basesetting_TipEntity = dm_Basesetting_TipService.GetEntityByAppID(currentUser.appid);

                    #region 更改一级账户余额及明细

                    /*2021-03-06
                     * 1、业务逻辑调整  等级分佣时如果有普通用户将不再断层,仍然会执行三级分佣
                     * 2、增加普通用户返佣比例设置,增加普通用户返佣比例说明*/
                    dm_user_relationEntity dm_User_RelationEntity_one = userRelationList.Where(t => t.user_id == dm_Alipay_RecordEntity_old.user_id).FirstOrDefault();
                    if (!dm_User_RelationEntity_one.IsEmpty())
                    {
                        one_User = userList.Where(t => t.id == dm_User_RelationEntity_one.parent_id).FirstOrDefault();
                        if (!one_User.IsEmpty())
                        {
                            if (one_User.userlevel == 0 || one_User.userlevel == 1 || one_User.userlevel == 2 || one_User.partnersstatus == 2)
                            {//高级代理或合伙人才能享受代理提成  2021-01-03 业务逻辑调整 上级只要是付费用户都可以返佣金
                                #region 开通会员一级返佣计算
                                if (one_User.userlevel != 0)
                                {//非普通用户
                                    one_agent_commission = ConvertComission(dm_BasesettingEntity.openagent_one * dm_Alipay_RecordEntity_old.total_amount);
                                }
                                else
                                {
                                    one_agent_commission = ConvertComission(dm_BasesettingEntity.opengent_general_member * dm_Alipay_RecordEntity_old.total_amount);
                                }

                                if (one_agent_commission > 0)
                                {
                                    string general_member_one_tip = "";
                                    if (one_User.userlevel == 0)
                                    {
                                        decimal real_opengent_general_member_one = ConvertComission(dm_BasesettingEntity.openagent_one * dm_Alipay_RecordEntity_old.total_amount);
                                        if (real_opengent_general_member_one > 0)
                                        {
                                            general_member_one_tip = dm_Basesetting_TipEntity.opengent_general_tip.Replace("[升级预估佣金]", real_opengent_general_member_one.ToString());
                                        }
                                    }

                                    one_tip  = GetText(dm_Basesetting_TipEntity, dm_Alipay_RecordEntity_old.templateid, 1);
                                    one_User = CalculateComission(one_User.id, one_agent_commission, one_User.accountprice);
                                    dm_AccountdetailEntities.Add(GeneralAccountDetail(one_User.id, 6, one_tip, "您的" + one_tip + "《" + currentUser.nickname + "》开通代理成功,奖励已到账,继续努力哟!" + general_member_one_tip, one_agent_commission, one_User.accountprice));
                                }
                                #endregion

                                #region 更改二级账户余额及明细
                                dm_user_relationEntity dm_User_RelationEntity_two = userRelationList.Where(t => t.user_id == one_User.id).FirstOrDefault();
                                if (!dm_User_RelationEntity_two.IsEmpty())
                                {
                                    two_User = userList.Where(t => t.id == dm_User_RelationEntity_two.parent_id).FirstOrDefault();
                                    if (!two_User.IsEmpty())
                                    {
                                        if (two_User.userlevel == 0 || two_User.userlevel == 1 || two_User.userlevel == 2 || two_User.partnersstatus == 2)
                                        {
                                            #region 开通会员二级返佣比例
                                            if (two_User.userlevel != 0)
                                            {
                                                two_agent_commission = ConvertComission(dm_BasesettingEntity.openagent_two * dm_Alipay_RecordEntity_old.total_amount);
                                            }
                                            else
                                            {
                                                two_agent_commission = ConvertComission(dm_BasesettingEntity.opengent_general_member * dm_Alipay_RecordEntity_old.total_amount);
                                            }
                                            if (two_agent_commission > 0)
                                            {
                                                string general_member_tow_tip = "";
                                                if (two_User.userlevel == 0)
                                                {
                                                    decimal real_opengent_general_member_two = ConvertComission(dm_BasesettingEntity.openagent_two * dm_Alipay_RecordEntity_old.total_amount);
                                                    if (real_opengent_general_member_two > 0)
                                                    {
                                                        general_member_tow_tip = dm_Basesetting_TipEntity.opengent_general_tip.Replace("[升级预估佣金]", real_opengent_general_member_two.ToString());
                                                    }
                                                }
                                                two_tip  = GetText(dm_Basesetting_TipEntity, dm_Alipay_RecordEntity_old.templateid, 2);
                                                two_User = CalculateComission(two_User.id, two_agent_commission, two_User.accountprice);
                                                dm_AccountdetailEntities.Add(GeneralAccountDetail(two_User.id, 7, two_tip, "您的" + two_tip + "《" + currentUser.nickname + "》开通代理成功,奖励已到账,继续努力哟!" + general_member_tow_tip, two_agent_commission, two_User.accountprice));
                                            }
                                            #endregion

                                            #region 更改三级账户余额及明细
                                            dm_user_relationEntity dm_User_RelationEntity_three = userRelationList.Where(t => t.user_id == two_User.id).FirstOrDefault();
                                            if (!dm_User_RelationEntity_three.IsEmpty())
                                            {
                                                three_User = userList.Where(t => t.id == dm_User_RelationEntity_three.parent_id).FirstOrDefault();
                                                if (!three_User.IsEmpty())
                                                {
                                                    if (three_User.userlevel == 0 || three_User.userlevel == 1 || three_User.userlevel == 2 || three_User.partnersstatus == 2)
                                                    {
                                                        #region 开通会员三级返佣比例
                                                        if (three_User.userlevel != 0)
                                                        {
                                                            three_agent_commission = ConvertComission(dm_BasesettingEntity.openagent_three * dm_Alipay_RecordEntity_old.total_amount);
                                                        }
                                                        else
                                                        {
                                                            three_agent_commission = ConvertComission(dm_BasesettingEntity.opengent_general_member * dm_Alipay_RecordEntity_old.total_amount);
                                                        }

                                                        if (three_agent_commission > 0)
                                                        {
                                                            string general_member_three_tip = "";
                                                            if (three_User.userlevel == 0)
                                                            {
                                                                decimal real_opengent_general_member_three = ConvertComission(dm_BasesettingEntity.openagent_three * dm_Alipay_RecordEntity_old.total_amount);
                                                                if (real_opengent_general_member_three > 0)
                                                                {
                                                                    general_member_three_tip = dm_Basesetting_TipEntity.opengent_general_tip.Replace("[升级预估佣金]", real_opengent_general_member_three.ToString());
                                                                }
                                                            }

                                                            three_tip  = GetText(dm_Basesetting_TipEntity, dm_Alipay_RecordEntity_old.templateid, 3);
                                                            three_User = CalculateComission(three_User.id, three_agent_commission, three_User.accountprice);
                                                            dm_AccountdetailEntities.Add(GeneralAccountDetail(three_User.id, 22, three_tip, "您的" + three_tip + "《" + currentUser.nickname + "》开通代理成功,奖励已到账,继续努力哟!" + general_member_three_tip, three_agent_commission, three_User.accountprice));
                                                        }
                                                        #endregion
                                                    }
                                                }
                                            }
                                            #endregion
                                        }
                                    }
                                }
                                #endregion
                            }
                        }
                    }

                    #endregion

                    #region 获取当前用户所属合伙人(一级合伙人)
                    one_partners = dM_UserService.GetUserByPartnersID(dm_User_RelationEntity_one.partners_id);
                    if (!one_partners.IsEmpty())
                    {
                        one_partners_commission = ConvertComission(dm_BasesettingEntity.openagent_one_partners * dm_Alipay_RecordEntity_old.total_amount);
                        if (one_partners_commission > 0)
                        {
                            one_parners_tip = GetText(dm_Basesetting_TipEntity, dm_Alipay_RecordEntity_old.templateid, 4);
                            one_partners    = CalculateComission(one_partners.id, one_partners_commission, one_partners.accountprice);
                            dm_AccountdetailEntities.Add(GeneralAccountDetail(one_partners.id, 8, one_parners_tip, "您的" + one_parners_tip + "《" + currentUser.nickname + "》开通代理成功,奖励已到账,继续努力哟!", one_partners_commission, one_partners.accountprice));
                        }

                        #region 二级合伙人
                        dm_user_relationEntity dm_User_RelationEntity_one_partners = dM_UserRelationService.GetEntityByUserID(one_partners.id);
                        two_partners = dM_UserService.GetEntityByCache(dm_User_RelationEntity_one_partners.parent_id);
                        if (!two_partners.IsEmpty())
                        {
                            if (two_partners.partnersstatus == 2)
                            {//二级用户为合伙人时才进行返利
                                two_partners_commission = ConvertComission(dm_BasesettingEntity.openagent_two_partners * dm_Alipay_RecordEntity_old.total_amount);
                                if (two_partners_commission > 0)
                                {
                                    two_parners_tip = GetText(dm_Basesetting_TipEntity, dm_Alipay_RecordEntity_old.templateid, 5);
                                    two_partners    = CalculateComission(two_partners.id, two_partners_commission, two_partners.accountprice);
                                    dm_AccountdetailEntities.Add(GeneralAccountDetail(two_partners.id, 9, two_parners_tip, "您的" + two_parners_tip + "《" + currentUser.nickname + "》开通代理成功,奖励已到账,继续努力哟!", two_partners_commission, two_partners.accountprice));
                                }
                            }
                        }
                        #endregion
                    }
                    #endregion


                    if (calculateComissionEntities.Count > 0)
                    {
                        //必须加上这个变量,用于清除当前返利账户的余额
                        foreach (var item in calculateComissionEntities)
                        {
                            item.Modify(item.id);
                        }
                        db = BaseRepository("dm_data").BeginTrans();
                        db.Update(dm_Alipay_RecordEntity);     //修改原有的支付宝支付记录
                        db.Insert(dm_MessagerecordEntity);     //增加消息记录
                        db.Insert(dm_AccountdetailEntities);   //增加账户余额明细
                        db.Update(calculateComissionEntities); //批量修改用户信息
                        db.Commit();

                        CacheHelper.UpdateUserInfo(currentUser);
                    }
                }
            }
            catch (Exception ex)
            {
                if (db != null)
                {
                    db.Rollback();
                }
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }
Example #27
0
        public dm_task_reviceEntity ReviceTask(dm_task_reviceEntity dm_Task_ReviceEntity, string appid)
        {
            lock (_object)
            {
                IRepository db = null;
                try
                {
                    dm_basesettingEntity dm_BasesettingEntity = dM_BaseSettingService.GetEntityByCache(appid);
                    if (dm_BasesettingEntity.IsEmpty())
                    {
                        throw new Exception("配置信息获取错误!");
                    }

                    dm_taskEntity dm_TaskEntity = dm_TaskService.GetEntity(dm_Task_ReviceEntity.task_id);
                    if (dm_TaskEntity.IsEmpty())
                    {
                        throw new Exception("任务id错误!");
                    }
                    if (dm_TaskEntity.task_status == -2)
                    {
                        throw new Exception("任务正在审核中,暂时无法接受!");
                    }
                    if (dm_TaskEntity.task_status == 1)
                    {
                        throw new Exception("您来晚了一步,当前任务已抢光!");
                    }
                    if (dm_TaskEntity.task_status == 2)
                    {
                        throw new Exception("当前任务已取消,您可接受其他任务!");
                    }
                    if (dm_TaskEntity.task_status == 3)
                    {
                        throw new Exception("当前任务已下架,您可接受其他任务!");
                    }

                    if (dm_TaskEntity.revicecount >= dm_TaskEntity.needcount)
                    {
                        throw new Exception("您来晚了一步,当前任务已抢光!");
                    }

                    /*一个任务可重复接受  2020-07-27*/
                    dm_task_reviceEntity reviceEntity = GetReviceEntity(dm_Task_ReviceEntity.user_id, dm_Task_ReviceEntity.task_id);
                    if (!reviceEntity.IsEmpty())
                    {
                        //throw new Exception("请勿重复接受该任务!");
                        throw new Exception("您已接受该任务,请勿重复接受!!");
                    }

                    dm_userEntity dm_UserEntity = dM_UserService.GetEntity(dm_Task_ReviceEntity.user_id);
                    if (dm_UserEntity.userlevel != 1 && dm_UserEntity.userlevel != 2)
                    {
                        throw new Exception("当前等级无法接受任务,请升级后重试!");
                    }

                    //判断当前未在审核状态的任务数量
                    int noFinishCount = BaseRepository("dm_data").IQueryable <dm_task_reviceEntity>(t => (t.status == 1 || t.status == 2) && t.user_id == dm_Task_ReviceEntity.user_id).Count();
                    if (noFinishCount >= dm_BasesettingEntity.revicetaskcountlimit)
                    {
                        throw new Exception("同时接单任务数已达到上限,请先完成其他任务后再来接单!");
                    }


                    dm_Task_ReviceEntity.revice_time = DateTime.Now;
                    dm_Task_ReviceEntity.status      = 1;
                    dm_Task_ReviceEntity.Create();

                    dm_TaskEntity.revicecount += 1;
                    dm_TaskEntity.Modify(dm_TaskEntity.id);

                    db = BaseRepository("dm_data").BeginTrans();
                    db.Update(dm_TaskEntity);
                    db.Insert(dm_Task_ReviceEntity);
                    db.Commit();

                    return(dm_Task_ReviceEntity);
                }
                catch (Exception ex)
                {
                    if (db != null)
                    {
                        db.Rollback();
                    }
                    if (ex is ExceptionEx)
                    {
                        throw;
                    }
                    else
                    {
                        throw ExceptionEx.ThrowServiceException(ex);
                    }
                }
            }
        }
        public dynamic SignIn(int userid)
        {
            IRepository db = null;

            try
            {
                dm_userEntity dm_UserEntity = GetEntityByCache(userid);
                if (dm_UserEntity.IsEmpty())
                {
                    throw new Exception("用户信息异常!");
                }
                dm_basesettingEntity dm_BasesettingEntity = dm_BaseSettingService.GetEntityByCache(dm_UserEntity.appid);
                if (dm_BasesettingEntity.IsEmpty())
                {
                    throw new Exception("获取基础配置信息异常!");
                }
                int?currentIntegral = 0;
                int signCount       = 0;
                dm_intergraldetailEntity dm_IntergraldetailEntity = dM_IntergralDetailService.GetLastSignData(userid);
                if (dm_IntergraldetailEntity == null)
                {
                    currentIntegral = dm_BasesettingEntity.firstsign;
                    signCount       = 1;
                }
                else
                {
                    if (dm_IntergraldetailEntity.createtime.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd"))
                    {
                        throw new Exception("今日已签到!");
                    }
                    if (dm_IntergraldetailEntity.createtime.ToString("yyyy-MM-dd") == DateTime.Now.AddDays(-1.0).ToString("yyyy-MM-dd"))
                    {
                        int?todayIntegral = dm_IntergraldetailEntity.stepvalue + dm_BasesettingEntity.signscrement;
                        currentIntegral = ((todayIntegral > dm_BasesettingEntity.signcapping) ? dm_BasesettingEntity.signcapping : todayIntegral);
                        signCount       = int.Parse(dm_IntergraldetailEntity.remark) + 1;
                    }
                    else
                    {
                        currentIntegral = dm_BasesettingEntity.firstsign;
                        signCount       = 1;
                    }
                }
                dm_UserEntity.integral += currentIntegral;
                dm_UserEntity.Modify(dm_UserEntity.id);
                db = BaseRepository("dm_data").BeginTrans();
                db.Update(dm_UserEntity);
                db.Insert(new dm_intergraldetailEntity
                {
                    currentvalue = dm_UserEntity.integral,
                    stepvalue    = currentIntegral,
                    user_id      = userid,
                    title        = "签到奖励",
                    remark       = signCount.ToString(),
                    type         = 2,
                    createtime   = DateTime.Now
                });
                db.Commit();
                return(new
                {
                    CurrentIntegral = currentIntegral,
                    SignCount = signCount
                });
            }
            catch (Exception ex)
            {
                if (db != null)
                {
                    db.Rollback();
                }
                if (ex is ExceptionEx)
                {
                    throw;
                }
                throw ExceptionEx.ThrowServiceException(ex);
            }
        }
 public dm_userEntity Register(dm_userEntity dm_UserEntity, string VerifiCode, string appid)
 {
     lock (lockObject)
     {
         IRepository db        = BaseRepository("dm_data").BeginTrans();
         int         parent_id = 0;
         int?        id        = 0;
         try
         {
             parent_id = DecodeInviteCode(VerifiCode);
             if (parent_id <= 0)
             {
                 throw new Exception("邀请码错误!");
             }
             dm_userEntity parent_user_entity = GetEntity(parent_id.ToInt());
             if (parent_user_entity == null)
             {
                 throw new Exception("您的邀请人用户异常!");
             }
             dm_user_relationEntity dm_Parent_User_RelationEntity = dm_UserRelationService.GetEntityByUserID(parent_id);
             dm_userEntity          dm_UserEntity_exist           = GetEntityByPhone(dm_UserEntity.phone, appid);
             if (dm_UserEntity_exist != null)
             {
                 throw new Exception("该手机号已注册!");
             }
             dm_basesettingEntity dm_BasesettingEntity = dm_BaseSettingService.GetEntityByCache(appid);
             dm_UserEntity.pwd   = Md5Helper.Encrypt(dm_UserEntity.pwd, 16);
             dm_UserEntity.token = Guid.NewGuid().ToString();
             BaseRepository("dm_data").Insert(dm_UserEntity);
             dm_userEntity updateEntity = new dm_userEntity();
             id = (updateEntity.id = BaseRepository("dm_data").FindObject("SELECT LAST_INSERT_ID();").ToInt());
             updateEntity.invitecode = EncodeInviteCode(updateEntity.id);
             updateEntity.integral   = dm_BasesettingEntity.new_people;
             updateEntity.Create();
             db.Update(updateEntity);
             db.Insert(new dm_intergraldetailEntity
             {
                 createtime   = DateTime.Now,
                 currentvalue = updateEntity.integral,
                 title        = "新用户注册奖励",
                 stepvalue    = dm_BasesettingEntity.new_people,
                 type         = 1,
                 user_id      = id
             });
             parent_user_entity.integral += dm_BasesettingEntity.new_people_parent;
             db.Update(parent_user_entity);
             db.Insert(new dm_intergraldetailEntity
             {
                 createtime   = DateTime.Now,
                 currentvalue = parent_user_entity.integral,
                 title        = "邀请好友奖励",
                 stepvalue    = dm_BasesettingEntity.new_people_parent,
                 type         = 3,
                 user_id      = parent_id
             });
             dm_user_relationEntity dm_User_RelationEntity = new dm_user_relationEntity
             {
                 user_id     = id,
                 parent_id   = parent_id,
                 partners_id = dm_Parent_User_RelationEntity.partners_id,
                 createtime  = DateTime.Now
             };
             db.Insert(dm_User_RelationEntity);
             db.Commit();
             return(GetEntity(id.ToInt()));
         }
         catch (Exception ex)
         {
             db.Rollback();
             Log      log = LogFactory.GetLogger("workflowapi");
             string[] obj = new string[6]
             {
                 "上下级绑定失败,当前用户",
                 null,
                 null,
                 null,
                 null,
                 null
             };
             int?num2 = id;
             obj[1] = num2.ToString();
             obj[2] = ",上级用户";
             num2   = parent_id;
             obj[3] = num2.ToString();
             obj[4] = ex.Message;
             obj[5] = ex.StackTrace;
             log.Error(string.Concat(obj));
             if (ex is ExceptionEx)
             {
                 throw;
             }
             throw ExceptionEx.ThrowServiceException(ex);
         }
     }
 }
Example #30
0
        public dm_task_reviceEntity AuditTask(int revice_id)
        {
            lock (_object)
            {
                IRepository db = null;
                try
                {
                    /*
                     * 任务审核(任务审核成功)
                     * 1、更改任务接受表的状态
                     * 2、更改任务主表的完成数量
                     * 3、向任务接受人发送消息记录
                     * 4、执行返佣
                     */

                    decimal do_task_commission = 0, one_agent_commission = 0, two_agent_commission = 0, one_partners_commission = 0, two_partners_commission = 0;

                    dm_userEntity currentUser = null, one_User = null, two_User = null, one_partners = null, two_partners = null;
                    string        currentNickName = "";

                    dm_task_reviceEntity dm_Task_ReviceEntity = GetEntity(revice_id);
                    if (dm_Task_ReviceEntity.status == 4)
                    {
                        throw new Exception("该任务已取消,审核失败!");
                    }
                    if (dm_Task_ReviceEntity.status == 1)
                    {
                        throw new Exception("该任务未提交资料,审核失败!");
                    }
                    if (dm_Task_ReviceEntity.status == 3)
                    {
                        throw new Exception("该任务已审核通过,请勿重复审核!");
                    }
                    dm_Task_ReviceEntity.status     = 3;
                    dm_Task_ReviceEntity.check_time = DateTime.Now;

                    #region 修改任务主表数据
                    dm_taskEntity dm_TaskEntity = dm_TaskService.GetEntity(dm_Task_ReviceEntity.task_id);
                    if (dm_TaskEntity.task_status == 2)
                    {
                        throw new Exception("该任务已取消,审核失败!");
                    }
                    dm_TaskEntity.finishcount += 1;
                    if (dm_TaskEntity.finishcount >= dm_TaskEntity.needcount)
                    {
                        dm_TaskEntity.task_status = 1;
                    }
                    dm_TaskEntity.Modify(dm_TaskEntity.id);
                    #endregion

                    if (dm_TaskEntity.isactivity == 0)
                    {
                        #region 任务审核消息
                        dm_messagerecordEntity dm_MessagerecordEntity = new dm_messagerecordEntity
                        {
                            isread         = 0,
                            user_id        = dm_Task_ReviceEntity.user_id,
                            messagetitle   = "任务审核通过",
                            messagecontent = "您接受的任务编号:" + dm_TaskEntity.task_no + "已审核通过,请及时查看!",
                            messagetype    = 3,
                            createtime     = DateTime.Now
                        };
                        #endregion

                        #region 执行返佣
                        /*做任务人根据等级返佣金*/
                        /*上级从服务费中计算佣金*/
                        //获取上下级关系
                        IEnumerable <dm_user_relationEntity> userRelationList = dM_UserRelationService.GetParentRelation(dm_Task_ReviceEntity.user_id);

                        ///获取上下级关系的用户信息
                        IEnumerable <dm_userEntity> userList = dM_UserService.GetParentUser(dm_Task_ReviceEntity.user_id);

                        #region 做任务人返佣
                        currentUser     = userList.Where(t => t.id == dm_Task_ReviceEntity.user_id).FirstOrDefault();
                        currentNickName = currentUser.nickname;//记录下接单人的昵称  防止丢失
                        if (currentUser.IsEmpty())
                        {
                            throw new Exception("用户信息异常!");
                        }
                        if (currentUser.userlevel == 0)
                        {
                            throw new Exception("用户等级异常,返佣失败!");
                        }
                        else if (currentUser.userlevel == 1)
                        {
                            do_task_commission = dm_TaskEntity.juniorcommission;
                        }
                        else if (currentUser.userlevel == 2)
                        {
                            do_task_commission = dm_TaskEntity.seniorcommission;
                        }
                        else
                        {
                            throw new Exception("用户无等级,返佣失败!");
                        }

                        dm_basesettingEntity dm_BasesettingEntity = dM_BaseSettingService.GetEntityByCache(dm_TaskEntity.appid);

                        dm_basesetting_tipEntity dm_Basesetting_TipEntity = dm_Basesetting_TipService.GetEntityByAppID(dm_TaskEntity.appid);

                        if (do_task_commission > 0)
                        {
                            dm_Task_ReviceEntity.comissionamount = do_task_commission;
                            currentUser = CalculateComission(currentUser.id, do_task_commission, currentUser.accountprice);
                            dm_AccountdetailEntities.Add(GeneralAccountDetail(currentUser.id, 14, dm_Basesetting_TipEntity.task_do_tip, "您接受的任务编号" + dm_TaskEntity.task_no + "已返佣到账,请及时查收!", do_task_commission, currentUser.accountprice));
                        }
                        #endregion
                        dm_Task_ReviceEntity.Modify(dm_Task_ReviceEntity.id);//由于需要修改任务所得佣金  故修改放到此处

                        #region 更改一级账户余额及明细
                        dm_user_relationEntity dm_User_RelationEntity_one = userRelationList.Where(t => t.user_id == dm_Task_ReviceEntity.user_id).FirstOrDefault();
                        if (!dm_User_RelationEntity_one.IsEmpty())
                        {
                            one_User = userList.Where(t => t.id == dm_User_RelationEntity_one.parent_id).FirstOrDefault();
                            if (!one_User.IsEmpty())
                            {
                                if (one_User.userlevel == 1 || one_User.userlevel == 2 || one_User.partnersstatus == 2)
                                {//做任务人为代理身份才会返佣
                                    one_agent_commission = ConvertComission(dm_BasesettingEntity.task_one * dm_TaskEntity.servicefee);
                                    if (one_agent_commission > 0)
                                    {
                                        one_User = CalculateComission(one_User.id, one_agent_commission, one_User.accountprice);
                                        dm_AccountdetailEntities.Add(GeneralAccountDetail(one_User.id, 15, dm_Basesetting_TipEntity.task_one_tip, "您的" + dm_Basesetting_TipEntity.task_one_tip + "《" + currentNickName + "》任务已完成,奖励已发放到您的账户,继续努力哟!", one_agent_commission, one_User.accountprice));
                                    }

                                    #region 更改二级账户余额及明细
                                    dm_user_relationEntity dm_User_RelationEntity_two = userRelationList.Where(t => t.user_id == one_User.id).FirstOrDefault();
                                    if (!dm_User_RelationEntity_two.IsEmpty())
                                    {
                                        two_User = userList.Where(t => t.id == dm_User_RelationEntity_two.parent_id).FirstOrDefault();
                                        if (!two_User.IsEmpty())
                                        {
                                            if (two_User.userlevel == 1 || two_User.userlevel == 2 || two_User.partnersstatus == 2)
                                            {
                                                two_agent_commission = ConvertComission(dm_BasesettingEntity.task_two * dm_TaskEntity.servicefee);
                                                if (two_agent_commission > 0)
                                                {
                                                    two_User = CalculateComission(two_User.id, two_agent_commission, two_User.accountprice);
                                                    dm_AccountdetailEntities.Add(GeneralAccountDetail(two_User.id, 16, dm_Basesetting_TipEntity.task_two_tip, "您的" + dm_Basesetting_TipEntity.task_two_tip + "《" + currentNickName + "》任务已完成,奖励已发放到您的账户,继续努力哟!", two_agent_commission, two_User.accountprice));
                                                }
                                            }
                                        }
                                    }
                                    #endregion
                                }
                            }
                        }
                        #endregion

                        #region 获取当前用户所属合伙人(一级合伙人)
                        one_partners = dM_UserService.GetUserByPartnersID(dm_User_RelationEntity_one.partners_id);
                        if (!one_partners.IsEmpty())
                        {
                            one_partners_commission = ConvertComission(dm_BasesettingEntity.task_one_partners * dm_TaskEntity.servicefee);
                            if (one_partners_commission > 0)
                            {
                                one_partners = CalculateComission(one_partners.id, one_partners_commission, one_partners.accountprice);
                                dm_AccountdetailEntities.Add(GeneralAccountDetail(one_partners.id, 17, dm_Basesetting_TipEntity.task_parners_one_tip, "您的" + dm_Basesetting_TipEntity.task_parners_one_tip + "《" + currentNickName + "》任务已完成,奖励已发放到您的账户,继续努力哟!", one_partners_commission, one_partners.accountprice));
                            }

                            #region 二级合伙人
                            dm_user_relationEntity dm_User_RelationEntity_one_partners = dM_UserRelationService.GetEntityByUserID(one_partners.id);
                            two_partners = dM_UserService.GetEntityByCache(dm_User_RelationEntity_one_partners.parent_id);
                            //two_partners = dM_UserService.GetUserByPartnersID(dm_User_RelationEntity_one_partners.partners_id);
                            if (!two_partners.IsEmpty())
                            {
                                if (two_partners.partnersstatus == 2)
                                {//二级用户为合伙人时才进行返利
                                    two_partners_commission = ConvertComission(dm_BasesettingEntity.task_two_partners * dm_TaskEntity.servicefee);
                                    if (two_partners_commission > 0)
                                    {
                                        two_partners = CalculateComission(two_partners.id, two_partners_commission, two_partners.accountprice);
                                        dm_AccountdetailEntities.Add(GeneralAccountDetail(two_partners.id, 18, dm_Basesetting_TipEntity.task_parners_two_tip, "您的" + dm_Basesetting_TipEntity.task_parners_two_tip + "《" + currentNickName + "》任务已完成,奖励已发放到您的账户,继续努力哟!", two_partners_commission, two_partners.accountprice));
                                    }
                                }
                            }
                            #endregion
                        }
                        #endregion
                        #endregion

                        if (calculateComissionEntities.Count > 0)
                        {
                            //必须加上这个变量,用于清除当前返利账户的余额
                            foreach (var item in calculateComissionEntities)
                            {
                                item.Modify(item.id);
                            }
                            db = BaseRepository("dm_data").BeginTrans();
                            db.Update(dm_Task_ReviceEntity);       //更改接单表信息
                            db.Update(dm_TaskEntity);              //更改任务主表信息
                            db.Insert(dm_MessagerecordEntity);     //增加任务审核消息(发给接受任务的人)
                            db.Insert(dm_MessagerecordEntity);     //增加消息记录
                            db.Insert(dm_AccountdetailEntities);   //增加账户余额明细
                            db.Update(calculateComissionEntities); //批量修改用户信息
                            db.Commit();
                        }
                    }
                    else
                    {
                        currentUser = dM_UserService.GetEntity(dm_Task_ReviceEntity.user_id);
                        if (currentUser.IsEmpty())
                        {
                            throw new Exception("用户信息异常!");
                        }

                        dm_activity_manageEntity dm_Activity_ManageEntity = new dm_activity_manageService().GetActivityInfo();
                        if (dm_Activity_ManageEntity.IsEmpty())
                        {
                            throw new Exception(CommonConfig.NoActivityTip);
                        }

                        dm_activity_recordEntity dm_Activity_RecordEntity = new dm_activity_recordService().GetEntityByUserID((int)dm_Task_ReviceEntity.user_id, dm_Activity_ManageEntity.f_id);
                        if (dm_Activity_RecordEntity.IsEmpty())
                        {
                            throw new Exception("未找到对应的加入活动任务信息!");
                        }

                        if (dm_Activity_ManageEntity.ActivityType == 0)
                        {
                            #region 初始用红包类型的任务
                            #region 活动账户增加金额
                            currentUser.activityprice += dm_TaskEntity.singlecommission;
                            #endregion

                            /*判断当前所有任务是否都已完成*/
                            List <dm_task_reviceEntity> dm_Task_ReviceEntities = this.BaseRepository("dm_data").FindList <dm_task_reviceEntity>(t => t.user_id == dm_Task_ReviceEntity.user_id && t.status != 3 && t.status != 4 && t.activitycode == dm_Activity_ManageEntity.f_id).ToList();
                            if (dm_Task_ReviceEntities.Count() <= 0 || (dm_Task_ReviceEntities.Count() == 1 && dm_Task_ReviceEntities[0].id == dm_Task_ReviceEntity.id))
                            {//活动任务已全部完成
                                currentUser.accountprice += currentUser.activityprice;
                                dm_AccountdetailEntities.Add(new dm_accountdetailEntity
                                {
                                    createtime   = DateTime.Now,
                                    remark       = "活动奖励" + dm_Activity_ManageEntity.ActivityCode,
                                    stepvalue    = currentUser.activityprice,
                                    currentvalue = currentUser.accountprice,
                                    title        = "活动奖励",
                                    type         = 24,
                                    user_id      = dm_Task_ReviceEntity.user_id,
                                    profitLoss   = 1
                                });

                                #region  级用户返利
                                dm_user_relationEntity parnetUserRelation = dM_UserRelationService.GetEntityByUserID(dm_Task_ReviceEntity.user_id);
                                if (!parnetUserRelation.IsEmpty())
                                {
                                    one_User = dM_UserService.GetEntity(parnetUserRelation.parent_id);
                                    if (!one_User.IsEmpty())
                                    {
                                        decimal next_user_activity_commission = Math.Round((decimal)currentUser.activityprice * 0.2M, 2);
                                        one_User.accountprice += next_user_activity_commission;

                                        dm_AccountdetailEntities.Add(new dm_accountdetailEntity
                                        {
                                            createtime   = DateTime.Now,
                                            remark       = "活动奖励" + dm_Activity_ManageEntity.ActivityCode,
                                            stepvalue    = next_user_activity_commission,
                                            currentvalue = one_User.accountprice,
                                            title        = "下级完成活动任务奖励",
                                            type         = 25,
                                            user_id      = one_User.id,
                                            profitLoss   = 1
                                        });
                                    }
                                }
                                #endregion

                                dm_Activity_RecordEntity.finishtime = DateTime.Now;//设置活动任务完成时间
                            }


                            db = BaseRepository("dm_data").BeginTrans();
                            db.Update(currentUser);
                            db.Update(dm_TaskEntity);
                            db.Update(dm_Task_ReviceEntity);
                            if (dm_AccountdetailEntities.Count > 0)
                            {
                                db.Insert(dm_AccountdetailEntities);
                            }
                            if (!one_User.IsEmpty())
                            {
                                db.Update(one_User);
                            }
                            db.Update(dm_Activity_RecordEntity);
                            db.Commit();
                            #endregion
                        }
                        else
                        {
                            List <dm_task_reviceEntity> dm_Task_ReviceEntities = this.BaseRepository("dm_data").FindList <dm_task_reviceEntity>(t => t.user_id == dm_Task_ReviceEntity.user_id && t.status != 3 && t.status != 4 && t.activitycode == dm_Activity_ManageEntity.f_id).ToList();

                            db = BaseRepository("dm_data").BeginTrans();
                            db.Update(dm_TaskEntity);
                            db.Update(dm_Task_ReviceEntity);

                            if (dm_Task_ReviceEntities.Count() <= 0 || (dm_Task_ReviceEntities.Count() == 1 && dm_Task_ReviceEntities[0].id == dm_Task_ReviceEntity.id))
                            {//活动任务已全部完成
                                decimal?activityprice = dm_Activity_ManageEntity.RewardPrice;
                                currentUser.accountprice += activityprice;
                                //currentUser.activityprice += activityprice;

                                dm_AccountdetailEntities.Add(new dm_accountdetailEntity
                                {
                                    createtime   = DateTime.Now,
                                    remark       = "活动奖励" + dm_Activity_ManageEntity.ActivityCode,
                                    stepvalue    = activityprice,
                                    currentvalue = currentUser.accountprice,
                                    title        = "活动奖励",
                                    type         = 24,
                                    user_id      = dm_Task_ReviceEntity.user_id,
                                    profitLoss   = 1
                                });

                                dm_Activity_RecordEntity.finishtime = DateTime.Now;//设置活动任务完成时间

                                db.Update(currentUser);
                                if (dm_AccountdetailEntities.Count > 0)
                                {
                                    db.Insert(dm_AccountdetailEntities);
                                }
                                db.Update(dm_Activity_RecordEntity);
                            }
                            db.Commit();
                        }
                    }

                    return(dm_Task_ReviceEntity);
                }
                catch (Exception ex)
                {
                    if (db != null)
                    {
                        db.Rollback();
                    }
                    if (ex is ExceptionEx)
                    {
                        throw;
                    }
                    else
                    {
                        throw ExceptionEx.ThrowServiceException(ex);
                    }
                }
            }
        }