public List <string> GetShareImage(int user_id, string appid) { try { dm_userEntity dm_UserEntity = GetEntityByCache(user_id); if (dm_UserEntity.IsEmpty()) { throw new Exception("用户信息异常!"); } if (dm_UserEntity.headpic.IsEmpty()) { throw new Exception("您先上传个人头像!"); } List <string> shareList = new List <string>(); string basePath = System.AppDomain.CurrentDomain.BaseDirectory.TrimEnd("\\".ToCharArray()); string newPath1 = "/Resource/ShareImage/Share" + user_id + "1.jpg"; string newPath2 = "/Resource/ShareImage/Share" + user_id + "2.jpg"; string newPath3 = "/Resource/ShareImage/Share" + user_id + "3.jpg"; dm_basesettingEntity dm_BasesettingEntity = dm_BaseSettingService.GetEntityByCache(appid); if (File.Exists(basePath + newPath1) && File.Exists(basePath + newPath2) && File.Exists(basePath + newPath3)) { shareList.Add(dm_BasesettingEntity.qianzhui_image + newPath1); shareList.Add(dm_BasesettingEntity.qianzhui_image + newPath2); shareList.Add(dm_BasesettingEntity.qianzhui_image + newPath3); } else { Bitmap qrCode = QRCodeHelper.Generate3(dm_UserEntity.invitecode, 200, 200, basePath + dm_UserEntity.headpic); //背景图片,海报背景 string path1 = basePath + @"/Resource/ShareImage/1.jpg"; string path2 = basePath + @"/Resource/ShareImage/2.jpg"; string path3 = basePath + @"/Resource/ShareImage/3.jpg"; GeneralShareImage(basePath + newPath1, path1, qrCode); shareList.Add(dm_BasesettingEntity.qianzhui_image + newPath1); GeneralShareImage(basePath + newPath2, path2, qrCode); shareList.Add(dm_BasesettingEntity.qianzhui_image + newPath2); GeneralShareImage(basePath + newPath3, path3, qrCode); shareList.Add(dm_BasesettingEntity.qianzhui_image + newPath3); } return(shareList); } catch (Exception ex) { if (ex is ExceptionEx) { throw; } throw ExceptionEx.ThrowServiceException(ex); } }
public void ApplyAccountCash(int user_id, decimal price, string remark) { IRepository db = null; try { dm_userEntity dm_UserEntity = dm_UserIBLL.GetEntity(user_id);//不从缓存取,此处需要验证账户余额 if (dm_UserEntity.IsEmpty()) { throw new Exception("用户信息异常!"); } if (price > dm_UserEntity.accountprice) { throw new Exception("账户余额不足!"); } else { dm_UserEntity.accountprice -= price; dm_UserEntity.Modify(user_id); #region 增加提现记录 dm_apply_cashrecordEntity dm_Apply_CashrecordEntity = new dm_apply_cashrecordEntity(); dm_Apply_CashrecordEntity.user_id = user_id; dm_Apply_CashrecordEntity.createtime = DateTime.Now; dm_Apply_CashrecordEntity.paytype = 0; dm_Apply_CashrecordEntity.price = price; dm_Apply_CashrecordEntity.currentprice = dm_UserEntity.accountprice; dm_Apply_CashrecordEntity.remark = remark; dm_Apply_CashrecordEntity.status = 0; #endregion db = BaseRepository("dm_data").BeginTrans(); db.Update(dm_UserEntity); db.Insert(dm_Apply_CashrecordEntity); db.Commit(); } } catch (Exception ex) { if (db != null) { db.Rollback(); } if (ex is ExceptionEx) { throw; } else { throw ExceptionEx.ThrowServiceException(ex); } } }
private dm_userEntity CalculateComission(int?user_id, decimal?commission, decimal?currentaccount) { dm_userEntity calculateComissionEntity = calculateComissionEntities.Where((dm_userEntity t) => t.id == user_id).FirstOrDefault(); if (calculateComissionEntity.IsEmpty()) { calculateComissionEntity = new dm_userEntity { id = user_id, accountprice = currentaccount + commission }; calculateComissionEntities.Add(calculateComissionEntity); } else { dm_userEntity dm_userEntity = calculateComissionEntity; dm_userEntity.accountprice += commission; } return(calculateComissionEntity); }
public void ResetUserStatistic(int UserID) { try { dm_userEntity userEntity = this.BaseRepository("dm_data").FindEntity <dm_userEntity>(UserID); if (!userEntity.IsEmpty()) { string excuteStatistic = string.Format("CALL ResetStatistic({0},{1},{2});", UserID, userEntity.partnersstatus, userEntity.partners ?? 0); this.BaseRepository("dm_data").ExecuteBySql(excuteStatistic); } } catch (Exception ex) { if (ex is ExceptionEx) { throw; } throw ExceptionEx.ThrowServiceException(ex); } }
public void 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); } } }
/// <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); } } }
public dynamic SignIn(int userid) { IRepository db = null; try { dm_userEntity dm_UserEntity = GetEntityByCache(userid); if (dm_UserEntity.IsEmpty()) { throw new Exception("用户信息异常!"); } dm_basesettingEntity dm_BasesettingEntity = dm_BaseSettingService.GetEntityByCache(dm_UserEntity.appid); if (dm_BasesettingEntity.IsEmpty()) { throw new Exception("获取基础配置信息异常!"); } int?currentIntegral = 0; int signCount = 0; dm_intergraldetailEntity dm_IntergraldetailEntity = dM_IntergralDetailService.GetLastSignData(userid); if (dm_IntergraldetailEntity == null) { currentIntegral = dm_BasesettingEntity.firstsign; signCount = 1; } else { if (dm_IntergraldetailEntity.createtime.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd")) { throw new Exception("今日已签到!"); } if (dm_IntergraldetailEntity.createtime.ToString("yyyy-MM-dd") == DateTime.Now.AddDays(-1.0).ToString("yyyy-MM-dd")) { int?todayIntegral = dm_IntergraldetailEntity.stepvalue + dm_BasesettingEntity.signscrement; currentIntegral = ((todayIntegral > dm_BasesettingEntity.signcapping) ? dm_BasesettingEntity.signcapping : todayIntegral); signCount = int.Parse(dm_IntergraldetailEntity.remark) + 1; } else { currentIntegral = dm_BasesettingEntity.firstsign; signCount = 1; } } dm_UserEntity.integral += currentIntegral; dm_UserEntity.Modify(dm_UserEntity.id); db = BaseRepository("dm_data").BeginTrans(); db.Update(dm_UserEntity); db.Insert(new dm_intergraldetailEntity { currentvalue = dm_UserEntity.integral, stepvalue = currentIntegral, user_id = userid, title = "签到奖励", remark = signCount.ToString(), type = 2, createtime = DateTime.Now }); db.Commit(); return(new { CurrentIntegral = currentIntegral, SignCount = signCount }); } catch (Exception ex) { if (db != null) { db.Rollback(); } if (ex is ExceptionEx) { throw; } throw ExceptionEx.ThrowServiceException(ex); } }
public dm_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); } } } }
/// <summary> /// 更改会员上级并重置两个会员的统计数据 /// </summary> /// <param name="UserID">需要设置上级的会员ID</param> /// <param name="ParentID">需要设置到的会员ID</param> public void UpdateUserParent(int UserID, int ParentID) { try { dm_user_relationEntity dm_User_RelationEntity = GetEntityByUserID(UserID); if (dm_User_RelationEntity.IsEmpty()) { throw new Exception("当前会员信息异常!"); } int old_ParentUserID = dm_User_RelationEntity.parent_id; dm_user_relationEntity dm_User_ParentRelationEntity = GetEntityByUserID(UserID); if (dm_User_ParentRelationEntity.IsEmpty()) { throw new Exception("上级会员信息异常!"); } if (dm_User_RelationEntity.parent_id == ParentID) { throw new Exception("当前用户已属于该邀请人,无需重复设置!"); } if (dm_User_ParentRelationEntity.parent_id == UserID) { throw new Exception("用户关系无法双向绑定!"); } if (dm_User_RelationEntity.partners_id != dm_User_ParentRelationEntity.partners_id) { throw new Exception("当前设置关系不在同一团队,无法操作!"); } dm_userEntity parentUserEntity = this.BaseRepository("dm_data").FindEntity <dm_userEntity>(ParentID); dm_User_RelationEntity.parent_id = ParentID; dm_User_RelationEntity.parent_nickname = parentUserEntity.nickname; dm_User_RelationEntity.Modify(dm_User_RelationEntity.id); this.BaseRepository("dm_data").Update(dm_User_RelationEntity); #region 重置统计信息 string excuteStatistic = ""; if (!parentUserEntity.IsEmpty()) { excuteStatistic += string.Format("CALL ResetStatistic({0},{1},{2});", ParentID, parentUserEntity.partnersstatus, parentUserEntity.partners ?? 0); } dm_userEntity oldParentUserEntity = this.BaseRepository("dm_data").FindEntity <dm_userEntity>(old_ParentUserID); if (!oldParentUserEntity.IsEmpty()) { excuteStatistic += string.Format("CALL ResetStatistic({0},{1},{2});", old_ParentUserID, oldParentUserEntity.partnersstatus, oldParentUserEntity.partners ?? 0); } if (!excuteStatistic.IsEmpty()) { this.BaseRepository("dm_data").ExecuteBySql(excuteStatistic); } #endregion } catch (Exception ex) { if (ex is ExceptionEx) { throw; } throw ExceptionEx.ThrowServiceException(ex); } }
/// <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); } } }
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); } } }