public bool SendCash(int actID, int Registerid) { bool t = false; chuangtouEntities ef = new chuangtouEntities(); hx_ActivityTable hat = new ActFacade().GetActivityModel(actID); //GetActTableInfo(ActTypeId, ActUser, 1); if (hat != null) { //判是否过期 if (hat.ActStarttime <= DateTime.Now && DateTime.Now <= hat.ActEndtime) { string ActRule = hat.ActRule; List <MAmtList> mlist = new List <MAmtList>(); JavaScriptSerializer js = new JavaScriptSerializer(); //MActCash mc = new MActCash(); Mcoupon mcp = new Mcoupon(); mcp = js.Deserialize <Mcoupon>(ActRule); //mlist = js.Deserialize<List<MAmtList>>(ActRule); //检查分发奖励是否超过顶限,如果超过直接跳过 //int TopNum = B_usercenter.GetTopNum(hat.ActID); //项目已经发放的金额 //decimal totalAmt = B_usercenter.GetTopAmtCount(hat.ActID); //第一次投资获取对应奖励 decimal actamt = mcp.cash;//GetActAmt(mc, InvestAmt, TopNum); //if (mc.TopAmt > totalAmt && mc.TopNum > TopNum) //{ t = true; if (actamt > 0)//大于 0里写入对应的奖励数据 { hx_UserAct hua = new hx_UserAct(); hua.ActTypeId = hat.ActTypeId; hua.registerid = Registerid; hua.RewTypeID = hat.RewTypeID; hua.ActID = hat.ActID; hua.Amt = actamt; hua.Uselower = 0.00M; hua.Usehight = 0.00M; hua.AmtEndtime = DateTime.Parse(hat.ActEndtime.ToString()).AddMonths(1); hua.AmtUses = 1; //没指定情况下默认为单独使用 hua.UseState = 5; //现金未转账 hua.UseTime = DateTime.Now; hua.AmtProid = 0; //未使用默认为0 hua.ISSmsOne = 0; hua.IsSmsThree = 0; hua.isSmsFifteen = 0; hua.IsSmsSeven = 0; hua.isSmsSixteen = 0; hua.OrderID = decimal.Parse(Utils.Createcode()); hua.Createtime = DateTime.Now; hua.Title = hat.ActName; hua.UseLifeLoan = ""; ef.hx_UserAct.Add(hua); int i = ef.SaveChanges(); if (i > 0) { //录入成功,后进行转账操作 //1.获取用户对向 M_member_table p = new M_member_table(); B_member_table o = new B_member_table(); p = o.GetModel(Registerid); if (p != null) { //2.调用商户向用户转账接口 Transfer tf = new Transfer(); ReTransfer retf = tf.ToUserTransfer(p.UsrCustId, actamt, hua.OrderID.ToString(), hua.ActID.ToString(), "/Thirdparty/ToUserTransfer"); if (retf != null) { if (retf.RespCode == "000") { //3.事务处理操作账户及插入流水 #region 验签缓存处理 string cachename = retf.OrdId + "ToUserTransfer" + retf.InCustId; if (Utils.GeTThirdCache(cachename) == 0) { Utils.SetThirdCache(cachename); B_usercenter BUC = new B_usercenter(); int ic = BUC.UpateActToUserTransfer(retf, 0); //用户余更新 if (ic > 0) { string sql = "SELECT registerid,username,mobile from hx_member_table where UsrCustId='" + retf.InCustId + "'"; DataTable dt = DbHelperSQL.GET_DataTable_List(sql); if (dt.Rows.Count > 0) { /*短信接口*/ #region 流水信息 B_usercenter ors = new B_usercenter(); decimal di = ors.GetUsridAvailable_balance(int.Parse(dt.Rows[0]["registerid"].ToString())); // di = di + decimal.Parse(hua.Amt.ToString()); StringBuilder strSql = new StringBuilder(); strSql.Append("insert into hx_Capital_account_water("); strSql.Append("membertable_registerid,income,expenditure,time_of_occurrence,account_balance,types_Finance,createtime,keyid,remarks)"); strSql.Append(" values ("); strSql.Append("" + int.Parse(dt.Rows[0]["registerid"].ToString()) + "," + decimal.Parse(hua.Amt.ToString()) + ",0,'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," + di + "," + (int)Enum.Parse(typeof(EnumTypesFinance), EnumTypesFinance.现金奖励.ToString()) + ",'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',0,'" + "现金奖励" + "')"); DbHelperSQL.RunSql(strSql.ToString()); strSql.Clear(); #endregion #region 奖励流水 M_bonus_account_water mbaw = new M_bonus_account_water(); B_bonus_account_water bbaw = new B_bonus_account_water(); DateTime dte = DateTime.Now; mbaw.bonus_account_id = int.Parse(hua.ActID.ToString()); mbaw.membertable_registerid = int.Parse(dt.Rows[0]["registerid"].ToString()); mbaw.income = decimal.Parse(retf.TransAmt); mbaw.expenditure = 0.00M; mbaw.time_of_occurrence = DateTime.Now; mbaw.award_description = hat.ActName + "奖励已汇入个人账户"; mbaw.water_type = 0; bbaw.Add(mbaw); #endregion #region MyRegion 系统消息 DateTime dti = DateTime.Now; M_td_System_message pm = new M_td_System_message(); pm.MReg = int.Parse(dt.Rows[0]["registerid"].ToString()); pm.Mstate = 0; pm.MTitle = hat.ActName; pm.MContext = "尊敬的用户" + dt.Rows[0]["username"].ToString() + ":您好!恭喜您成功" + hat.ActName + ",现金奖励 " + retf.TransAmt + "元。如有问题可咨询创利投的客服!"; pm.PubTime = dti; B_usercenter.AddMessage(pm); #endregion } } t = true; } #endregion } } } } } //} } } return(t); }
public ActionResult BgUsrPay() { string str = ""; ReUsrAcctPay m = new ReUsrAcctPay(); m.CmdId = DNTRequest.GetString("CmdId"); m.RespCode = DNTRequest.GetString("RespCode"); m.RespDesc = HttpUtility.UrlDecode(DNTRequest.GetString("RespDesc")); m.OrdId = DNTRequest.GetString("OrdId"); m.UsrCustId = DNTRequest.GetString("UsrCustId"); m.MerCustId = DNTRequest.GetString("MerCustId"); m.TransAmt = DNTRequest.GetString("TransAmt"); m.InAcctId = DNTRequest.GetString("InAcctId"); m.InAcctType = DNTRequest.GetString("InAcctType"); m.RetUrl = HttpUtility.UrlDecode(DNTRequest.GetString("RetUrl")); m.BgRetUrl = HttpUtility.UrlDecode(DNTRequest.GetString("BgRetUrl")); m.MerPriv = DNTRequest.GetString("MerPriv"); m.ChkValue = DNTRequest.GetString("ChkValue"); StringBuilder chkVal = new StringBuilder(); chkVal.Append(m.CmdId); chkVal.Append(m.RespCode); chkVal.Append(m.OrdId); chkVal.Append(m.UsrCustId); chkVal.Append(m.MerCustId); chkVal.Append(m.TransAmt); chkVal.Append(m.InAcctId); chkVal.Append(m.InAcctType); chkVal.Append(m.RetUrl); chkVal.Append(m.BgRetUrl); chkVal.Append(m.MerPriv); string chkv = chkVal.ToString(); string logstr = "RECV_ORD_ID_" + m.OrdId; //私钥文件的位置(这里是放在了站点的根目录下) string merKeyFile = AppDomain.CurrentDomain.BaseDirectory + Utils.GetPgPubk(); int ret = DllInterop.VeriSignMsg(merKeyFile, chkv, chkv.Length, m.ChkValue); LogInfo.WriteLog("用户向平台商户号转账返回信息:" + FastJSON.toJOSN(m)); if (ret == 0) { if (m.RespCode == "000") { string cachename = m.OrdId + "BgUsrPay" + m.UsrCustId; if (Utils.GeTThirdCache(cachename) == 0) { Utils.SetThirdCache(cachename); string sql = "update hx_member_table set available_balance=available_balance-" + m.TransAmt + " where UsrCustId='" + m.UsrCustId + "'"; DbHelperSQL.RunSql(sql); #region 流水信息 sql = "SELECT registerid,username,mobile from hx_member_table where UsrCustId='" + m.UsrCustId + "'"; System.Data.DataTable dt = DbHelperSQL.GET_DataTable_List(sql); if (dt.Rows.Count > 0) { B_usercenter ors = new B_usercenter(); decimal di = ors.GetUsridAvailable_balance(int.Parse(dt.Rows[0]["registerid"].ToString())); // di = di + decimal.Parse(hua.Amt.ToString()); StringBuilder strSql = new StringBuilder(); strSql.Append("insert into hx_Capital_account_water("); strSql.Append("membertable_registerid,income,expenditure,time_of_occurrence,account_balance,types_Finance,createtime,keyid,remarks)"); strSql.Append(" values ("); strSql.Append("" + int.Parse(dt.Rows[0]["registerid"].ToString()) + ",0," + decimal.Parse(m.TransAmt) + ",'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," + (di - decimal.Parse(m.TransAmt)) + "," + (int)Enum.Parse(typeof(EnumTypesFinance), EnumTypesFinance.用户向平台划账.ToString()) + ",'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',0,'" + "用户向平台划账" + "')"); DbHelperSQL.RunSql(strSql.ToString()); strSql.Clear(); } #endregion //Response.Write(logstr + "转账成功!"); LogInfo.WriteLog(logstr + "用户向平台商户号转账成功:" + sql); } } } else { LogInfo.WriteLog(m.UsrCustId + "用户向平台商户号转账后台失败:"); } return(Content(logstr)); }
public ActionResult PlatformToUserMoney(string UsrCustId = "", decimal money = 0) { string keypassword = ConfigurationManager.AppSettings["RechargePassWord"].ToString(); string password = DNTRequest.GetFormString("pssword"); if (string.IsNullOrEmpty(UsrCustId)) { return(Content(StringAlert.Alert("客户号不可以为空!"), "text/html")); } if (money <= 0) { return(Content(StringAlert.Alert("转账金额错误!"), "text/html")); } if (String.IsNullOrEmpty(password)) { return(Content(StringAlert.Alert("密码不能为空!"), "text/html")); } if (keypassword != password) { return(Content(StringAlert.Alert("充值密码不正确"), "text/html")); } M_Transfer m = new M_Transfer(); m.Version = "10"; m.CmdId = "Transfer"; m.OrdId = Utils.Createcode(); m.OutCustId = Utils.GetMerCustID(); m.OutAcctId = "MDT000001"; m.TransAmt = money.ToString("0.00"); m.InCustId = Utils.CheckSQLHtml(UsrCustId); m.BgRetUrl = Utils.GetRe_url("admin/Thirdparty/BgToUserTransfer"); StringBuilder chkVal = new StringBuilder(); chkVal.Append(m.Version); chkVal.Append(m.CmdId); chkVal.Append(m.OrdId); chkVal.Append(m.OutCustId); chkVal.Append(m.OutAcctId); chkVal.Append(m.TransAmt); chkVal.Append(m.InCustId); chkVal.Append(m.RetUrl); chkVal.Append(m.BgRetUrl); chkVal.Append(m.MerPriv); string chkv = chkVal.ToString(); LogInfo.WriteLog("加签chkv字符:" + chkv); //私钥文件的位置(这里是放在了站点的根目录下) string merKeyFile = AppDomain.CurrentDomain.BaseDirectory + Utils.GetMerPr(); //需要指定提交字符串的长度 int len = Encoding.UTF8.GetBytes(chkv).Length; StringBuilder sbChkValue = new StringBuilder(256); //加签 int str = DllInterop.SignMsg(Utils.GetMerId(), merKeyFile, chkv, len, sbChkValue); LogInfo.WriteLog("加签字符:" + str.ToString()); m.ChkValue = sbChkValue.ToString(); LogInfo.WriteLog("提交信息:" + FastJSON.toJOSN(m)); LogInfo.WriteLog("ChkValue:" + m.ChkValue); string _resultStr = ""; using (var client = new WebClient()) { var values = new NameValueCollection(); values.Add("Version", m.Version); values.Add("CmdId", m.CmdId); values.Add("OrdId", m.OrdId); values.Add("OutCustId", m.OutCustId); values.Add("OutAcctId", m.OutAcctId); values.Add("TransAmt", m.TransAmt); values.Add("InCustId", m.InCustId); values.Add("InAcctId", m.InAcctId); values.Add("RetUrl", m.RetUrl); values.Add("BgRetUrl", m.BgRetUrl); values.Add("MerPriv", m.MerPriv); values.Add("ChkValue", m.ChkValue); string url = Utils.GetChinapnrUrl(); //同步发送form表单请求 byte[] result = client.UploadValues(url, "POST", values); var retStr = Encoding.UTF8.GetString(result); // Response.Write(retStr); LogInfo.WriteLog("自动扣款转账(商户用)返回报文" + retStr); ReTransfer reg = new ReTransfer(); var retloan = (ReTransfer)FastJSON.ToObject(retStr, reg); StringBuilder builder = new StringBuilder(); builder.Append(retloan.CmdId); builder.Append(retloan.RespCode); builder.Append(retloan.OrdId); builder.Append(retloan.OutCustId); builder.Append(retloan.OutAcctId); builder.Append(retloan.TransAmt); builder.Append(retloan.InCustId); builder.Append(retloan.InAcctId); builder.Append(retloan.RetUrl); builder.Append(retloan.BgRetUrl); builder.Append(retloan.MerPriv); var msg = builder.ToString(); LogInfo.WriteLog("返回参数:" + msg); //验签 string pgPubkFile = AppDomain.CurrentDomain.BaseDirectory + Utils.GetPgPubk(); int ret = DllInterop.VeriSignMsg(pgPubkFile, msg, msg.Length, retloan.ChkValue); LogInfo.WriteLog("验签ret:" + ret.ToString()); if (ret == 0) { if (retloan.RespCode == "000") { //_resultStr = retloan.RespCode.ToString() + " <br> " + HttpUtility.UrlDecode(retloan.RespDesc) + "<br>转账成功"; #region 流水信息 string sql = "SELECT registerid,username,mobile from hx_member_table where UsrCustId='" + retloan.InCustId + "'"; System.Data.DataTable dt = DbHelperSQL.GET_DataTable_List(sql); if (dt.Rows.Count > 0) { B_usercenter ors = new B_usercenter(); decimal di = ors.GetUsridAvailable_balance(int.Parse(dt.Rows[0]["registerid"].ToString())); // di = di + decimal.Parse(hua.Amt.ToString()); StringBuilder strSql = new StringBuilder(); strSql.Append("insert into hx_Capital_account_water("); strSql.Append("membertable_registerid,income,expenditure,time_of_occurrence,account_balance,types_Finance,createtime,keyid,remarks)"); strSql.Append(" values ("); strSql.Append("" + int.Parse(dt.Rows[0]["registerid"].ToString()) + "," + decimal.Parse(retloan.TransAmt) + ",0,'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," + (di + decimal.Parse(retloan.TransAmt)) + "," + (int)Enum.Parse(typeof(EnumTypesFinance), EnumTypesFinance.平台向用户划账.ToString()) + ",'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',0,'" + "平台向用户划账" + "')"); DbHelperSQL.RunSql(strSql.ToString()); strSql.Clear(); } #endregion _resultStr = "<br>转账成功"; } else { _resultStr = HttpUtility.UrlDecode(retloan.RespDesc); } } } ViewBag.str = _resultStr; return(View()); }
/// <summary> /// 邀请注册奖励活动 /// </summary> /// <param name="registerid">注册用户id</param> /// <param name="ActUser">面向用户 0不限 1首次投资用户 2非首投用户 3每标首投用户 4每标最大投资用户 5所有投资用户</param> protected internal void SendBonusForInviteAfterRegister(int registerid, string targetPlatform, int ActUser = 0) { #region MyRegion //邀请奖励处理逻辑,暂无邀请奖励 bool flag = true; if (flag) { if (registerid < 0) { return; } DateTime dte = DateTime.Now; string codesql = "SELECT invcode,Invpeopleid,invpersonid,invtime from hx_td_Userinvitation where invpersonid=" + registerid.ToString();//查询本人是否已经被邀请注册过 invcode='" + invcode + "' and LogInfo.WriteLog("codesql2:" + codesql); DataTable dtcode = DbHelperSQL.GET_DataTable_List(codesql); //邀请奖励处理逻辑 if (dtcode.Rows.Count > 0) { B_member_table oy = new B_member_table(); M_member_table py = new M_member_table(); //获取邀请用户id int invpeopleid = int.Parse(dtcode.Rows[0]["Invpeopleid"].ToString()); py = oy.GetModel(invpeopleid); if (py.useridentity != 4 && py.iD_number != "")//渠道用户不执行 { DateTime nowdate = DateTime.Now; DateTime startdate = new DateTime(2017, 1, 6, 0, 00, 00); DateTime enddate = new DateTime(2017, 3, 31, 23, 59, 59); DateTime invtime = Convert.ToDateTime(dtcode.Rows[0]["invtime"].ToString()); //邀请时间 #region 生成奖励,记录流水 //??待优化到奖励内部记录 if ((nowdate > startdate && nowdate < enddate) && (invtime > startdate && invtime < enddate)) { List <hx_UserAct> hut = InviteActBonus(py.registerid, targetPlatform, registerid, -1M, 0, 4, 1, 0, 5); string strlog = "用户:" + py.registerid + ",邀请奖励返回实体:" + hut.Count; if (hut.Count > 0) { foreach (hx_UserAct ua in hut) { if (ua.Amt != null && ua.Amt > 0) { string sql = "update hx_td_Userinvitation set Invitereward=" + ua.Amt + ",UserAct= " + ua.UserAct + " where invpersonid=" + int.Parse(dtcode.Rows[0]["invpersonid"].ToString()); strlog += ";更新邀请表:" + sql; DbHelperSQL.ExecuteSql(sql); #region MyRegion 记录奖励流水表 string awardDescription = string.Format("邀请好友注册成功,获得{0}{1}", Convert.ToDouble(ua.Amt.ToString()), GetBunusDescription(ua.RewTypeID)); AddBonusAccoutWater(ua.UserAct, py.registerid, decimal.Parse(ua.Amt.ToString()), awardDescription, registerid); #endregion strlog += ";" + awardDescription; #region MyRegion 发送系统消息 string MContext = string.Format("尊敬的用户:您邀请好友注册成功,获得{0}{1}如有问题可咨询创利投的客服!", ua.Amt.ToString(), GetBunusDescription(ua.RewTypeID)); AddSytemMessage(py.registerid, "邀请好友注册奖励", MContext); #endregion strlog += ";ua.RewTypeID:" + ua.RewTypeID; if (ua.RewTypeID == 1) { #region 资金流水信息 B_usercenter o = new B_usercenter(); decimal di = o.GetUsridAvailable_balance(py.registerid); //di = di + decimal.Parse(ua.Amt.ToString()); StringBuilder strSql = new StringBuilder(); strSql.Append("insert into hx_Capital_account_water("); strSql.Append("membertable_registerid,income,expenditure,time_of_occurrence,account_balance,types_Finance,createtime,keyid,remarks)"); strSql.Append(" values ("); strSql.Append("" + py.registerid + "," + decimal.Parse(ua.Amt.ToString()) + ",0,'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," + di + "," + (int)Enum.Parse(typeof(EnumTypesFinance), EnumTypesFinance.邀请奖励.ToString()) + ",'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',0,'" + awardDescription + "')"); strlog += ";邀请好友注册奖励流水语句:" + strSql.ToString(); DbHelperSQL.RunSql(strSql.ToString()); strSql.Clear(); #endregion } } } } LogInfo.WriteLog(strlog); } #endregion #region 11月活动,每邀请5位好友实名注册,奖励邀请人2%加息券一张 if ((nowdate > startdate && nowdate < enddate) && (invtime > startdate && invtime < enddate)) { string log = "11月活动用户" + invpeopleid + "每邀请5位好友,当前好友(" + registerid + ")实名注册奖励邀请人2%加息券一张: "; //查询活动期间内邀请人累计邀请实名注册人数 string strSQL = string.Format("select COUNT(mt.registerid) recount from hx_td_Userinvitation ut inner join hx_member_table mt on ut.invpersonid=mt.registerid where mt.iD_number <> '' and mt.useridentity <> 4 and mt.registration_time >= '{0}' and mt.registration_time <= '{1}' and ut.Invpeopleid={2}", startdate.ToString("yyyy-MM-dd HH:mm:ss"), enddate.ToString("yyyy-MM-dd HH:mm:ss"), invpeopleid); log += "查询活动期间邀请实名人数sql:" + strSQL; DataTable dtcount = DbHelperSQL.GET_DataTable_List(strSQL); if (dtcount.Rows.Count > 0) { int recount = int.Parse(dtcount.Rows[0]["recount"].ToString()); log += "<br>累计实名人数:" + recount; if (recount > 0) { if (recount % 5 == 0) { log += "<br>实名人数" + dtcount.Rows.Count + "人,执行奖励操作"; List <hx_UserAct> t = new List <hx_UserAct>(); hx_ActivityTable hat = new hx_ActivityTable(); hat = GetActTableInfo(4, targetPlatform, ActUser, 1, 1); //赋值11月活动RewTypeID为1 ,主要获取活动起止时间,真正发放奖励hua.RewTypeID是3 加息券 if (hat != null && hat.ActID > 0) { hx_UserAct hua = new hx_UserAct(); hua.ActTypeId = hat.ActTypeId; //活动类型id 1新人活动/2短期活动/3常规活动/4邀请活动/5系统赠送 hua.registerid = invpeopleid; //邀请人ID hua.RewTypeID = 3; //奖励类型id 1现金/2抵扣券/3加息券 hua.ActID = hat.ActID; hua.Amt = 2; //2%加息券 hua.Uselower = 100; hua.Usehight = 0; hua.AmtEndtime = DateTime.Now.Date.AddDays(31).AddSeconds(-1); // DateTime.Parse(hat.ActEndtime.ToString()); hua.AmtUses = 1; //使用要求 1单独使用,2组合使用 hua.UseState = 0; //使用状态 0 未使用 1 已使用 2已过期 3 锁定中 hua.AmtProid = 0; //未使用默认为0 hua.ISSmsOne = 0; hua.IsSmsThree = 0; hua.isSmsFifteen = 0; hua.IsSmsSeven = 0; hua.isSmsSixteen = 0; hua.Createtime = DateTime.Now; hua.Title = "11月活动每邀请5位好友送2%加息券"; hua.UseLifeLoan = "3-0"; ef.hx_UserAct.Add(hua); int i = ef.SaveChanges(); if (i > 0) { log += "<br>2%加息券奖励发放成功"; if (hua.Amt != null && hua.Amt > 0) { #region MyRegion 发送系统消息 string MContext = string.Format("尊敬的用户:您邀请{0}好友实名注册成功,获得{1}{2}如有问题可咨询创利投的客服!", recount, hua.Amt.ToString(), GetBunusDescription(hua.RewTypeID)); AddSytemMessage(registerid, "邀请好友注册奖励", MContext); #endregion } } } } } } LogInfo.WriteLog(log); } #endregion #region 11月活动,被邀请人实名注册,奖励2%加息券一张 if ((nowdate > startdate && nowdate < enddate) && (invtime > startdate && invtime < enddate)) { string log = "11月活动,被邀请人(" + registerid + ")实名注册奖励2%加息券一张: "; List <hx_UserAct> t = new List <hx_UserAct>(); hx_ActivityTable hat = new hx_ActivityTable(); hat = GetActTableInfo(4, targetPlatform, ActUser, 1, 1); //赋值11月活动RewTypeID为1 ,主要获取活动起止时间,真正发放奖励hua.RewTypeID是3 加息券 if (hat != null && hat.ActID > 0) { hx_UserAct hua = new hx_UserAct(); hua.ActTypeId = hat.ActTypeId; //活动类型id 1新人活动/2短期活动/3常规活动/4邀请活动/5系统赠送 hua.registerid = registerid; //注册人ID hua.RewTypeID = 3; //奖励类型id 1现金/2抵扣券/3加息券 hua.ActID = hat.ActID; hua.Amt = 2; //2%加息券 hua.Uselower = 100; hua.Usehight = 0; hua.AmtEndtime = DateTime.Now.Date.AddDays(31).AddSeconds(-1); // DateTime.Parse(hat.ActEndtime.ToString()); hua.AmtUses = 1; //使用要求 1单独使用,2组合使用 hua.UseState = 0; //使用状态 0 未使用 1 已使用 2已过期 3 锁定中 hua.AmtProid = 0; //未使用默认为0 hua.ISSmsOne = 0; hua.IsSmsThree = 0; hua.isSmsFifteen = 0; hua.IsSmsSeven = 0; hua.isSmsSixteen = 0; hua.Createtime = DateTime.Now; hua.Title = "11月活动实名注册送2%加息券"; hua.UseLifeLoan = "3-0"; //待添加加息券使用标的 ef.hx_UserAct.Add(hua); int i = ef.SaveChanges(); if (i > 0) { log += "<br>2%加息券奖励发放成功"; if (hua.Amt != null && hua.Amt > 0) { #region MyRegion 发送系统消息 string MContext = string.Format("尊敬的用户:您实名注册成功,获得{0}{1}如有问题可咨询创利投的客服!", hua.Amt.ToString(), GetBunusDescription(hua.RewTypeID)); AddSytemMessage(registerid, "邀请好友注册奖励", MContext); #endregion } } } LogInfo.WriteLog(log); } #endregion } } } #endregion }
/// <summary> /// 邀请奖历 投资成功奖励 /// </summary> /// <param name="dt"></param> protected internal void SendBonusForInviteAfterInvest(DataTable dt, string targetPlatform) //(int registerid, string invcode, int invcount, decimal investAmt, string userName, string borrowing_title, decimal bonusAmt) { if (dt.Rows.Count <= 0) { return; } //投资金额 decimal investAmt = decimal.Parse(dt.Rows[0]["investment_amount"].ToString()); int registerid = int.Parse(dt.Rows[0]["investor_registerid"].ToString()); //投资人ID int bid_records_id = int.Parse(dt.Rows[0]["bid_records_id"].ToString()); int life_of_loan = int.Parse(dt.Rows[0]["life_of_loan"].ToString()); int unit_day = int.Parse(dt.Rows[0]["unit_day"].ToString()); if (unit_day != 1) { life_of_loan = 0; } string borrowing_title = dt.Rows[0]["borrowing_title"].ToString(); string userName = dt.Rows[0]["username"].ToString(); string invcode = dt.Rows[0]["invitationcode"].ToString(); int targetid = int.Parse(dt.Rows[0]["targetid"].ToString());//标的ID //本次投标使用的奖励金额 decimal bonusAmt = decimal.Parse(dt.Rows[0]["bonusAmt"].ToString()); B_bonus_account_water bbaw = new B_bonus_account_water(); int invcount = B_usercenter.GetInvestCountByUserid(registerid);//投资次数 string uid = registerid.ToString(); LogInfo.WriteLog("投资人ID:" + registerid + "; /*邀请码*/:" + invcode); #region MyRegion 邀请奖历 投资成功奖励 暂不启用false 待重新梳理帐号fangjianmin if (invcode != null && invcode != "")// && false { DateTime dte = DateTime.Now; string codesql = "SELECT invcode,Invpeopleid,invpersonid,invtime from hx_td_Userinvitation where invcode='" + invcode + "' and invpersonid=" + uid + " ";//查询本人是否已经被邀请注册过 LogInfo.WriteLog("投资人ID:" + registerid + ";查询本人是否已经被邀请注册过:" + codesql); DataTable dtcode = DbHelperSQL.GET_DataTable_List(codesql); if (dtcode.Rows.Count > 0) { int uuid = int.Parse(dtcode.Rows[0]["Invpeopleid"].ToString()); //邀请用户id B_member_table oy = new B_member_table(); M_member_table py = new M_member_table(); //获取 邀请用户身份渠道用户不执行 py = oy.GetModel(uuid); if (py.useridentity != 4) { DateTime invtime = Convert.ToDateTime(dtcode.Rows[0]["invtime"].ToString()); //邀请时间 DateTime nowdate = DateTime.Now; DateTime startdate = new DateTime(2017, 1, 6, 0, 00, 00); DateTime enddate = new DateTime(2017, 3, 31, 23, 59, 59); if ((nowdate > startdate && nowdate < enddate) && (invtime > startdate && invtime < enddate)) { #region 1月6日活动,奖励邀请人首投满2000返现10元 if (!string.IsNullOrWhiteSpace(py.UsrCustId)) { B_borrowing_target bbt = new B_borrowing_target(); M_borrowing_target mbt = new M_borrowing_target(); mbt = bbt.GetModel(targetid); if (mbt.project_type_id != 6)//排除新手标 { string log = "用户" + registerid + "活动奖励邀请人首投满2000返现10元: "; decimal amtc = 0; DataTable dtstAmt = B_usercenter.GetInvestCountByUseridNew(registerid); if (dtstAmt.Rows.Count > 0) { log += "<br> 投资次数" + dtstAmt.Rows.Count + "次"; if (dtstAmt.Rows.Count == 1) { amtc = decimal.Parse(dtstAmt.Rows[0]["InvCount_Amt"].ToString()); log += "<br>投资金额" + amtc; if (amtc >= 2000) { hx_UserAct huact = InviteActCashNew(uuid, targetPlatform, amtc, 4, 1, 10, 5)[0]; if (huact != null && huact.ActID != null) { log += "<br>奖励发放成功"; #region MyRegion 奖励流水 string awardDescription = string.Format("邀请好友首投满2000成功,获得{0}{1}", Convert.ToDouble(huact.Amt.ToString()), GetBunusDescription(huact.RewTypeID)); AddBonusAccoutWater(huact.UserAct, uuid, decimal.Parse(huact.Amt.ToString()), awardDescription, registerid); //registerid 被邀请人 uuid邀请人 #endregion MyRegion 奖励流水 #region MyRegion 系统消息 string MContext = string.Format("尊敬的用户:邀请好友{0}首投{1}金额为{2},获得{3}{4}如有问题可咨询创利投的客服!", userName, borrowing_title, investAmt, decimal.Parse(huact.Amt.ToString()), GetBunusDescription(huact.RewTypeID)); AddSytemMessage(uuid, "邀请好友首投满2000成功奖励", MContext); #endregion #region 现金流水信息 if (huact.RewTypeID == 1) { B_usercenter o = new B_usercenter(); decimal di = o.GetUsridAvailable_balance(uuid); //di = di + decimal.Parse(huact.Amt.ToString()); StringBuilder strSql = new StringBuilder(); strSql.Append("insert into hx_Capital_account_water("); strSql.Append("membertable_registerid,income,expenditure,time_of_occurrence,account_balance,types_Finance,createtime,keyid,remarks)"); strSql.Append(" values ("); strSql.Append("" + uuid + "," + decimal.Parse(huact.Amt.ToString()) + ",0,'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," + di + "," + (int)Enum.Parse(typeof(EnumTypesFinance), EnumTypesFinance.邀请奖励.ToString()) + ",'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',0,'" + awardDescription + "')"); DbHelperSQL.RunSql(strSql.ToString()); strSql.Clear(); } #endregion } } } } LogInfo.WriteLog(log); } } #endregion #region 受邀好友首次成功投资给予活动奖励 常规邀请 //获取标的期限 life_of_loan = int.Parse(dt.Rows[0]["life_of_loan"].ToString()); unit_day = int.Parse(dt.Rows[0]["unit_day"].ToString()); int lol = 0; if (unit_day == 1) { lol = life_of_loan; } #region 邀请好友投资成功返现(奖励邀请人) if (!string.IsNullOrWhiteSpace(py.UsrCustId)) { hx_UserAct hut = InviteActBonus(uuid, targetPlatform, int.Parse(dtcode.Rows[0]["invpersonid"].ToString()), investAmt, 1, 4, 1, 0, 5, lol, "邀请好友投资成功返现")[0];// if (hut != null && hut.ActID != null) { #region MyRegion 奖励流水 string awardDescription = string.Format("邀请好友投资成功,获得{0}{1}", Convert.ToDouble(hut.Amt.ToString()), GetBunusDescription(hut.RewTypeID)); AddBonusAccoutWater(hut.UserAct, uuid, decimal.Parse(hut.Amt.ToString()), awardDescription, registerid); //registerid 被邀请人 uuid邀请人 #endregion MyRegion 奖励流水 #region MyRegion 系统消息 string MContext = string.Format("尊敬的用户:邀请好友{0}投资{1}金额为{2},获得{3}{4}如有问题可咨询创利投的客服!", userName, borrowing_title, investAmt, hut.Amt.ToString(), GetBunusDescription(hut.RewTypeID)); AddSytemMessage(uuid, "邀请好友投资成功奖励", MContext); #endregion #region 现金流水信息 if (hut.RewTypeID == 1) { B_usercenter o = new B_usercenter(); decimal di = o.GetUsridAvailable_balance(uuid); //di = di + decimal.Parse(hut.Amt.ToString()); StringBuilder strSql = new StringBuilder(); strSql.Append("insert into hx_Capital_account_water("); strSql.Append("membertable_registerid,income,expenditure,time_of_occurrence,account_balance,types_Finance,createtime,keyid,remarks)"); strSql.Append(" values ("); strSql.Append("" + uuid + "," + decimal.Parse(hut.Amt.ToString()) + ",0,'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," + di + "," + (int)Enum.Parse(typeof(EnumTypesFinance), EnumTypesFinance.邀请奖励.ToString()) + ",'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',0,'" + awardDescription + "')"); DbHelperSQL.RunSql(strSql.ToString()); strSql.Clear(); } #endregion } } #endregion #region 被邀请投资成功返现(奖励被邀请人) int byquuid = int.Parse(dtcode.Rows[0]["invpersonid"].ToString()); hx_UserAct byhut = InviteActBonus(byquuid, targetPlatform, 0, investAmt, 1, 4, 1, 0, 5, lol, "被邀请投资返现")[0];// if (byhut != null && byhut.ActID != null) { #region MyRegion 奖励流水 string awardDescription = string.Format("被邀请投资成功,获得{0}{1}", Convert.ToDouble(byhut.Amt.ToString()), GetBunusDescription(byhut.RewTypeID)); AddBonusAccoutWater(byhut.UserAct, byquuid, decimal.Parse(byhut.Amt.ToString()), awardDescription, registerid); //registerid 被邀请人 uuid邀请人 #endregion MyRegion 奖励流水 #region MyRegion 系统消息 string MContext = string.Format("尊敬的用户:被邀请投资{0}金额为{1},获得{2}{3}如有问题可咨询创利投的客服!", borrowing_title, investAmt, byhut.Amt.ToString(), GetBunusDescription(byhut.RewTypeID)); AddSytemMessage(byquuid, "被邀请投资成功奖励", MContext); #endregion #region 现金流水信息 if (byhut.RewTypeID == 1) { B_usercenter o = new B_usercenter(); decimal di = o.GetUsridAvailable_balance(byquuid); //di = di + decimal.Parse(byhut.Amt.ToString()); StringBuilder strSql = new StringBuilder(); strSql.Append("insert into hx_Capital_account_water("); strSql.Append("membertable_registerid,income,expenditure,time_of_occurrence,account_balance,types_Finance,createtime,keyid,remarks)"); strSql.Append(" values ("); strSql.Append("" + byquuid + "," + decimal.Parse(byhut.Amt.ToString()) + ",0,'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," + di + "," + (int)Enum.Parse(typeof(EnumTypesFinance), EnumTypesFinance.邀请奖励.ToString()) + ",'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',0,'" + awardDescription + "')"); DbHelperSQL.RunSql(strSql.ToString()); strSql.Clear(); } #endregion } #endregion #endregion } #region 这里现金返现 ??? 投资金额为-1 作了单独处理。注册?? RewTypeID-1 ??? //hx_UserAct ua = InviteActBonus(uuid, int.Parse(dtcode.Rows[0]["invpersonid"].ToString()), -1M, 1, 4, 1, 0, 5)[0];//??? #endregion //} //else if (invcount > 1) //{ // #region 受邀用户续投奖励 邀请活动正常续投 // int biyaoUsrid = int.Parse(dtcode.Rows[0]["invpersonid"].ToString()); // decimal totAmt = B_usercenter.GetInviUserTotalAmt(uuid, biyaoUsrid);//????这里需要取出受邀用户奖总数 // // hx_UserAct hut = aci.InviteActCash(uuid, biyaoUsrid, decimal.Parse(p.TransAmt), 4, 2, 1, totAmt, 5); // hx_UserAct hut = InviteActBonus(uuid, int.Parse(dtcode.Rows[0]["invpersonid"].ToString()), investAmt - bonusAmt, 1, 4, 1, totAmt, 5)[0];//???? // if (hut != null && hut.ActID != null) // { // #region MyRegion 奖励流水 // string awardDescription = string.Format("邀请好友续投成功获得{0}{1}", hut.Amt.ToString(), GetBunusDescription(hut.RewTypeID)); // AddBonusAccoutWater(hut.UserAct, uuid, decimal.Parse(hut.Amt.ToString()), awardDescription, registerid); //registerid 被邀请人 uuid邀请人 // #endregion MyRegion 奖励流水 // #region MyRegion 系统消息 // string MContext = string.Format("尊敬的用户:邀请好友续投{1}金额为{2},获得{3}{4}如有问题可咨询创利投的客服!", userName, borrowing_title, investAmt, hut.Amt.ToString(), GetBunusDescription(hut.RewTypeID)); // AddSytemMessage(uuid, "邀请好友续投奖励", MContext); // #endregion // #region 现金奖励 资金流水信息 // if (hut.RewTypeID == 1) // { // B_usercenter o = new B_usercenter(); // decimal di = o.GetUsridAvailable_balance(uuid); // // di = di + decimal.Parse(hut.Amt.ToString()); // StringBuilder strSql = new StringBuilder(); // strSql.Append("insert into hx_Capital_account_water("); // strSql.Append("membertable_registerid,income,expenditure,time_of_occurrence,account_balance,types_Finance,createtime,keyid,remarks)"); // strSql.Append(" values ("); // strSql.Append("" + uuid + "," + decimal.Parse(hut.Amt.ToString()) + ",0,'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," + di + "," + (int)Enum.Parse(typeof(EnumTypesFinance), EnumTypesFinance.邀请奖励.ToString()) + ",'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',0,'" + awardDescription + "')"); // LogInfo.WriteLog("续投奖励流水语句:" + strSql.ToString()); // DbHelperSQL.RunSql(strSql.ToString()); // strSql.Clear(); // } // #endregion // } // #endregion //} /* * DbHelperSQL.RunSql(" update hx_td_Userinvitation set InvitesStates=1 where invcode='" + invcode + "' and invpersonid=" + uid + " and InvitesStates=2 "); * LogInfo.WriteLog(" 后台更新数据邀请状态 update hx_td_Userinvitation set InvitesStates=1 where invcode='" + invcode + "' and invpersonid=" + uid + " and InvitesStates=2 "); */ } } } #endregion }
/// <summary> /// 常规活动 现金奖励 发放(奖励流水 资金流水 系统消息) /// </summary> /// <param name="registerid">用户id</param> /// <param name="investAmt">投资金额</param> /// <param name="hat">活动对象</param> /// <param name="bid_records_id">投标记录id</param> /// <returns>bool 是否发放成功</returns> private bool GeneralActCash(int Registerid, decimal InvestAmt, hx_ActivityTable hat, int bid_records_id, int lifeLoan = 0) { bool t = false; //hx_ActivityTable hat = GetActTableInfo(ActTypeId, ActUser, 1); if (hat != null) { B_member_table oy = new B_member_table(); //M_member_table investor = new M_member_table(); hx_member_table investor = new hx_member_table(); investor = ef.hx_member_table.Where(c => c.registerid == Registerid).FirstOrDefault(); //oy.GetModel(Registerid);//被推荐人 也就是投资人 DateTime dte = DateTime.Now; string codesql = "SELECT invcode,Invpeopleid,invpersonid,invtime from hx_td_Userinvitation where invpersonid=" + Registerid + " ";//查询本人是否已经被邀请注册过 DataTable dtcode = DbHelperSQL.GET_DataTable_List(codesql); //if (dtcode.Rows.Count > 0 || (investor != null && !string.IsNullOrWhiteSpace(investor.channel_invitedcode))) //{ int uuid = dtcode.Rows.Count > 0 ? int.Parse(dtcode.Rows[0]["Invpeopleid"].ToString()) : 0; //邀请用户id //用户等级为渠道 不参与活动 if (investor != null && investor.useridentity == 4) { return(t); } int investCount = B_usercenter.GetInvestCountByUserid(Registerid); //老渠道机制判断 (推荐人等级为4渠道用户,投资次数大于等于1次 时可参与活动 if (uuid != 0) { M_member_table py = new M_member_table(); py = oy.GetModel(uuid);//推荐人 if ((py != null && py.useridentity == 4) && investCount == 1) { return(t); } } //新渠道机制判断 using (ChannelAct channelAct = new ChannelAct()) { //按照渠道类型和投资次数判断是否参与此次活动 if (!channelAct.IsParticipateActivity(investor.channel_invitedcode, investCount)) { return(t); } } //if (((py != null && py.useridentity == 4) || !string.IsNullOrWhiteSpace(investor.channel_invitedcode)) && B_usercenter.GetInvestCountByUserid(Registerid) == 1) //{ // return t; //} //if (py.useridentity != 4)//渠道用户不执行 2016-11-8日添加 //{ string ActRule = hat.ActRule; List <MAmtList> mlist = new List <MAmtList>(); JavaScriptSerializer js = new JavaScriptSerializer(); MActCash mc = new MActCash(); mc = js.Deserialize <MActCash>(ActRule); //mlist = js.Deserialize<List<MAmtList>>(ActRule); //获取该活动对应的已经发放奖励的人次 int TopNum = B_usercenter.GetTopNum(hat.ActID); //获取该活动对应的已经发放奖励的总金额 decimal totalAmt = B_usercenter.GetTopAmtCount(hat.ActID); if (hat.ActUser == 7)//特殊回款复投奖励类型,根据规则修订奖励基数--投资金额 { InvestAmt = GetSepcialActAmt(Registerid, bid_records_id, InvestAmt, hat); } //根据投资金额计算对应现金奖励金额 decimal actamt = GetActAmt(mc, InvestAmt, TopNum, lifeLoan); //检查分发奖励是否超过人数顶限或者总金额上限,上限为0表示不限制,如果超过直接跳过 if ((mc.TopAmt > totalAmt || mc.TopAmt == 0) && (mc.TopNum > TopNum || mc.TopNum == 0)) { //t = true; if (actamt > 0)//大于 0里写入对应的奖励数据 { hx_UserAct hua = new hx_UserAct(); hua.ActTypeId = hat.ActTypeId; hua.registerid = Registerid; hua.RewTypeID = hat.RewTypeID; hua.ActID = hat.ActID; hua.Amt = actamt; hua.Uselower = 0.00M; hua.Usehight = 0.00M; hua.AmtEndtime = DateTime.Parse(hat.ActEndtime.ToString()).AddMonths(1); hua.AmtUses = 1; //没指定情况下默认为单独使用 hua.UseState = 5; //现金未转账 hua.UseTime = DateTime.Now; hua.AmtProid = bid_records_id; //未使用默认为0,对于现金奖励该字段存放获得该奖励的投资记录id hua.ISSmsOne = 0; hua.IsSmsThree = 0; hua.isSmsFifteen = 0; hua.IsSmsSeven = 0; hua.isSmsSixteen = 0; hua.OrderID = decimal.Parse(Utils.Createcode()); hua.Createtime = DateTime.Now; hua.Title = mc.ActName; hua.UseLifeLoan = ""; ef.hx_UserAct.Add(hua); int i = ef.SaveChanges(); if (i > 0) { //录入成功,后进行转账操作 1.获取用户对象 M_member_table p = new M_member_table(); B_member_table o = new B_member_table(); p = o.GetModel(Registerid); if (p != null) { //2.调用商户向用户转账接口 Transfer tf = new Transfer(); ReTransfer retf = tf.ToUserTransfer(p.UsrCustId, actamt, hua.OrderID.ToString(), hua.ActID.ToString(), "/Thirdparty/ToUserTransfer"); if (retf != null && retf.RespCode == "000") { //3.事务处理操作账户及插入流水 #region 验签缓存处理 string cachename = retf.OrdId + "ToUserTransfer" + retf.InCustId; if (Utils.GeTThirdCache(cachename) == 0) { Utils.SetThirdCache(cachename); B_usercenter BUC = new B_usercenter(); int ic = BUC.UpateActToUserTransfer(retf, bid_records_id); //用户余额更新 if (ic > 0) { string sql = "SELECT registerid,username,mobile from hx_member_table where UsrCustId='" + retf.InCustId + "'"; DataTable dt = DbHelperSQL.GET_DataTable_List(sql); if (dt.Rows.Count > 0) { #region 资金流水 B_usercenter ors = new B_usercenter(); decimal di = ors.GetUsridAvailable_balance(int.Parse(dt.Rows[0]["registerid"].ToString())); // di = di + decimal.Parse(hua.Amt.ToString()); StringBuilder strSql = new StringBuilder(); strSql.Append("insert into hx_Capital_account_water("); strSql.Append("membertable_registerid,income,expenditure,time_of_occurrence,account_balance,types_Finance,createtime,keyid,remarks)"); strSql.Append(" values ("); strSql.Append("" + int.Parse(dt.Rows[0]["registerid"].ToString()) + "," + decimal.Parse(hua.Amt.ToString()) + ",0,'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," + di + "," + (int)Enum.Parse(typeof(EnumTypesFinance), EnumTypesFinance.现金奖励.ToString()) + ",'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',0,'" + "现金奖励" + "')"); DbHelperSQL.RunSql(strSql.ToString()); strSql.Clear(); #endregion #region MyRegion 记录奖励流水表 string awardDescription = string.Format("{0},已汇入个人账户{1}{2}", hat.ActName, retf.TransAmt, GetBunusDescription(hat.RewTypeID)); AddBonusAccoutWater(int.Parse(hua.UserAct.ToString()), Registerid, decimal.Parse(retf.TransAmt), awardDescription); #endregion #region MyRegion 发送系统消息 string MContext = string.Format("尊敬的用户:您好!恭喜您成功参与{0},获得{1}{2}如有问题可咨询创利投的客服!", hat.ActName, retf.TransAmt, GetBunusDescription(hat.RewTypeID)); AddSytemMessage(Registerid, hat.ActName, MContext); #endregion string msg = string.Format("尊敬的客户您好,您已成功投资创利投金服,获得返利{0}元,请登录官网查看。客服热线:010-53732056。", actamt.ToString("0.00")); SendSMS.Send_SMS(dt.Rows[0]["mobile"].ToString(), msg); } } t = true; } #endregion } } } } //} } //} } return(t); }