public void SaveEntity(int?keyValue, dm_messagerecordEntity entity)
 {
     try
     {
         dM_MessageRecordService.SaveEntity(keyValue, entity);
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         throw ExceptionEx.ThrowBusinessException(ex);
     }
 }
 public void SaveEntity(int?keyValue, dm_messagerecordEntity entity)
 {
     try
     {
         if (keyValue > 0)
         {
             entity.Modify(keyValue);
             BaseRepository("dm_data").Update(entity);
         }
         else
         {
             entity.Create();
             BaseRepository("dm_data").Insert(entity);
         }
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         throw ExceptionEx.ThrowServiceException(ex);
     }
 }
Пример #3
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);
                }
            }
        }
Пример #4
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);
                }
            }
        }
Пример #5
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);
                    }
                }
            }
        }
Пример #6
0
        public dm_task_reviceEntity CancelByRevicePerson(int revice_id, int IsPubCancel = 0)
        {
            IRepository db = null;

            try
            {
                /* 取消任务
                 * 1、更改接受任务表的任务状态
                 * 2、修改任务主表的接单人数
                 * 3、向任务发布人增加取消任务通知
                 */
                dm_task_reviceEntity dm_Task_ReviceEntity = GetEntity(revice_id);
                #region 更改接受任务表状态
                if (dm_Task_ReviceEntity.IsEmpty())
                {
                    throw new Exception("接受任务记录异常!");
                }
                if (dm_Task_ReviceEntity.status == 2)
                {
                    throw new Exception("任务正在审核中,取消任务失败!");
                }
                if (dm_Task_ReviceEntity.status == 3)
                {
                    throw new Exception("任务已完成,取消任务失败!");
                }
                if (dm_Task_ReviceEntity.status == 4)
                {
                    throw new Exception("任务已取消,请勿重复提交!");
                }

                dm_taskEntity dm_TaskEntity = dm_TaskService.GetEntity(dm_Task_ReviceEntity.task_id);
                if (dm_TaskEntity.isactivity == 1)
                {
                    throw new Exception("活动任务不能取消哟!");
                }

                if (IsPubCancel == 1)
                {
                    DateTime diffTime = ((DateTime)dm_Task_ReviceEntity.revice_time).AddHours(dm_TaskEntity.task_time_limit);
                    if (DateTime.Now < diffTime)
                    {
                        throw new Exception("该用户提交资料未超过设定时间,无法取消任务,您可在" + diffTime.ToString("yyyy-MM-dd HH:mm:ss") + "重试操作!");
                    }
                }


                dm_Task_ReviceEntity.status     = 4;
                dm_Task_ReviceEntity.canceltime = DateTime.Now;
                dm_Task_ReviceEntity.Modify(dm_Task_ReviceEntity.id);
                #endregion

                #region 修改任务主表数据
                dm_TaskEntity.revicecount -= 1;
                dm_TaskEntity.Modify(dm_TaskEntity.id);
                #endregion

                #region 增加消息记录
                dm_messagerecordEntity dm_MessagerecordEntity = new dm_messagerecordEntity
                {
                    isread         = 0,
                    user_id        = dm_TaskEntity.user_id,
                    messagetitle   = "接单人取消",
                    messagecontent = "您发布的任务编号:" + dm_TaskEntity.task_no + "接单人已取消,请及时查看!",
                    messagetype    = 2,
                    createtime     = DateTime.Now
                };
                #endregion

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

                db.Commit();

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

                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }
Пример #7
0
        /// <summary>
        /// 支付回调中开通代理(并完成返佣)
        /// </summary>
        /// <param name="dm_Alipay_RecordEntity"></param>
        public void OpenAgent(dm_alipay_recordEntity dm_Alipay_RecordEntity)
        {
            IRepository db = null;

            try
            {
                dm_AccountdetailEntities.Clear();
                calculateComissionEntities.Clear();

                /*
                 * 根据外部交易单号获取订单记录
                 * 更改用户状态并完成返利
                 * 1、一级代理返利(代理等级为高级才可得到)
                 * 2、二级代理返利(代理等级为高级才可得到)
                 * 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);

                decimal 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;

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

                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.templateid == 3)
                {
                    currentUser.userlevel = 2;
                }
                currentUser.Modify(currentUser.id);//必须加上这句,不然不会清除缓存
                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);

                #region 更改一级账户余额及明细
                dm_user_relationEntity dm_User_RelationEntity_one = userRelationList.Where(t => t.user_id == dm_Alipay_RecordEntity_old.user_id).FirstOrDefault();
                one_User = userList.Where(t => t.id == dm_User_RelationEntity_one.parent_id).FirstOrDefault();
                if (!one_User.IsEmpty())
                {
                    if (one_User.userlevel == 2)
                    {//高级代理才能享受代理提成
                        one_agent_commission = ConvertComission(dm_BasesettingEntity.openagent_one * dm_Alipay_RecordEntity_old.total_amount);
                        if (one_agent_commission > 0)
                        {
                            one_User = CalculateComission(one_User.id, one_agent_commission, one_User.accountprice);
                            dm_AccountdetailEntities.Add(GeneralAccountDetail(one_User.id, 6, "下级开通代理", "您的下级《" + currentUser.nickname + "》开通代理成功,奖励已到账,继续努力哟!", one_agent_commission, one_User.accountprice));
                        }

                        #region 更改二级账户余额及明细
                        dm_user_relationEntity dm_User_RelationEntity_two = userRelationList.Where(t => t.user_id == one_User.id).FirstOrDefault();
                        two_User = userList.Where(t => t.id == dm_User_RelationEntity_two.parent_id).FirstOrDefault();
                        if (!two_User.IsEmpty())
                        {
                            two_agent_commission = ConvertComission(dm_BasesettingEntity.openagent_two * dm_Alipay_RecordEntity_old.total_amount);
                            if (two_agent_commission > 0)
                            {
                                two_User = CalculateComission(two_User.id, two_agent_commission, two_User.accountprice);
                                dm_AccountdetailEntities.Add(GeneralAccountDetail(two_User.id, 7, "二级开通代理", "您的二级《" + currentUser.nickname + "》开通代理成功,奖励已到账,继续努力哟!", 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.openagent_one_partners * dm_Alipay_RecordEntity_old.total_amount);
                    if (one_partners_commission > 0)
                    {
                        one_partners = CalculateComission(one_partners.id, one_partners_commission, one_partners.accountprice);
                        dm_AccountdetailEntities.Add(GeneralAccountDetail(one_partners.id, 8, "团队成员开通代理", "您的团队成员《" + 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())
                    {
                        two_partners_commission = ConvertComission(dm_BasesettingEntity.openagent_two_partners * dm_Alipay_RecordEntity_old.total_amount);
                        if (two_partners_commission > 0)
                        {
                            two_partners = CalculateComission(two_partners.id, two_partners_commission, two_partners.accountprice);
                            dm_AccountdetailEntities.Add(GeneralAccountDetail(two_partners.id, 9, "下级团队成员开通代理", "您的下级团队成员《" + 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();
                }
            }
            catch (Exception ex)
            {
                if (db != null)
                {
                    db.Rollback();
                }
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }