public void SaveEntity(int?keyValue, dm_accountdetailEntity entity)
 {
     try
     {
         dM_AccountDetailService.SaveEntity(keyValue, entity);
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         throw ExceptionEx.ThrowBusinessException(ex);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 审核提现记录
        /// </summary>
        /// <param name="id">提现记录id</param>
        public void CheckApplyCashRecord(int id, int paytype)
        {
            IRepository db = null;

            try
            {
                dm_apply_cashrecordEntity dm_Apply_CashrecordEntity = GetEntity(id);
                if (dm_Apply_CashrecordEntity.IsEmpty())
                {
                    throw new Exception("提现记录不存在!");
                }

                dm_Apply_CashrecordEntity.paytype = paytype;
                dm_Apply_CashrecordEntity.status  = 1;

                dm_accountdetailEntity dm_AccountdetailEntity = new dm_accountdetailEntity();
                dm_AccountdetailEntity.currentvalue = dm_AccountdetailEntity.currentvalue;
                dm_AccountdetailEntity.stepvalue    = dm_Apply_CashrecordEntity.price;
                dm_AccountdetailEntity.type         = 11;
                dm_AccountdetailEntity.title        = "提现";
                dm_AccountdetailEntity.remark       = "账户余额提现";
                dm_AccountdetailEntity.user_id      = dm_Apply_CashrecordEntity.user_id;
                dm_AccountdetailEntity.createtime   = DateTime.Now;

                db = BaseRepository("dm_data").BeginTrans();
                db.Update(dm_Apply_CashrecordEntity);
                db.Insert(dm_AccountdetailEntity);
                db.Commit();
            }
            catch (Exception ex)
            {
                if (db != null)
                {
                    db.Rollback();
                }
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowServiceException(ex);
                }
            }
        }
 public void SaveEntity(int?keyValue, dm_accountdetailEntity 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);
     }
 }
Ejemplo n.º 4
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);
                }
            }
        }
Ejemplo n.º 5
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);
                }
            }
        }
Ejemplo n.º 6
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);
                }
            }
        }
Ejemplo n.º 7
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);
                }
            }
        }
Ejemplo n.º 8
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);
                }
            }
        }
Ejemplo n.º 9
0
        public void ApplyAccountCash(int user_id, decimal price, string remark, string appid)
        {
            IRepository db = null;

            try
            {
                lock (sign)
                {
                    dm_userEntity        dm_UserEntity        = dm_UserIBLL.GetEntity(user_id);//不从缓存取,此处需要验证账户余额
                    dm_basesettingEntity dm_BasesettingEntity = dm_BaseSettingService.GetEntityByCache(appid);
                    if (dm_UserEntity.IsEmpty())
                    {
                        throw new Exception("用户信息异常!");
                    }
                    //if (dm_UserEntity.isreal == 0)  未实名认证也可以提现(2021-01-11)
                    //    throw new Exception("您的账号未实名,禁止提现!");
                    if (dm_UserEntity.zfb.IsEmpty())
                    {
                        throw new Exception("支付宝账号未绑定,禁止提现!");
                    }
                    if (price < dm_BasesettingEntity.cashrecord_min_price)
                    {
                        throw new Exception(string.Format("最低提现金额不得小于{0}元!", dm_BasesettingEntity.cashrecord_min_price));
                    }

                    if (price > dm_UserEntity.accountprice)
                    {
                        throw new Exception("账户余额不足!");
                    }
                    else
                    {
                        decimal predict_price = price;
                        if (dm_BasesettingEntity.cashrecord_fee > 0)
                        {
                            price = price * (1 - dm_BasesettingEntity.cashrecord_fee / 100);
                        }
                        if (price <= 0)
                        {
                            throw new Exception("提现数据异常,请联系官方客服!");
                        }

                        dm_UserEntity.accountprice -= predict_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.predict_price = predict_price;
                        dm_Apply_CashrecordEntity.currentprice  = dm_UserEntity.accountprice;
                        dm_Apply_CashrecordEntity.remark        = remark;
                        dm_Apply_CashrecordEntity.status        = 0;
                        #endregion

                        #region 增加余额变更明细(2020-08-20)
                        dm_accountdetailEntity dm_AccountdetailEntity = new dm_accountdetailEntity();
                        dm_AccountdetailEntity.currentvalue = dm_Apply_CashrecordEntity.currentprice;
                        dm_AccountdetailEntity.stepvalue    = dm_Apply_CashrecordEntity.price;
                        dm_AccountdetailEntity.type         = 11;
                        dm_AccountdetailEntity.profitLoss   = CommonHelper.GetProfitLoss(11);
                        dm_AccountdetailEntity.title        = "提现";
                        dm_AccountdetailEntity.remark       = "账户余额提现";
                        dm_AccountdetailEntity.user_id      = dm_Apply_CashrecordEntity.user_id;
                        dm_AccountdetailEntity.createtime   = DateTime.Now;
                        #endregion

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

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