Exemplo n.º 1
0
        /// <summary>
        /// 无效投资标的处理
        /// </summary>
        /// <param name="investor_registerid">投资用户id</param>
        /// <param name="bid_records_id">投资记录id</param>
        /// <param name="OrdId">投资订单号</param>
        /// <param name="OrdDate">投资订单日期</param>
        /// <param name="UsrCustId">客户号</param>
        /// <param name="FreezeOrdId">冻结订单号</param>
        /// <param name="TransAmt">交易金额</param>
        /// <param name="FreezeTrxId">冻结唯一标识</param>
        /// <param name="MerPriv">优惠券字符串</param>
        /// <param name="QueryTransType">查询类型   LOANS:放款交易查询 REPAYMENT:还款交易查询 TENDER:投标交易查询 CASH:取现交易查询     FREEZE:冻结解冻交易查询     </param>
        public void setRecords_Lost(string investor_registerid, string bid_records_id, string OrdId, string OrdDate, string UsrCustId, string FreezeOrdId, string TransAmt, string FreezeTrxId, string MerPriv, string QueryTransType = "TENDER")
        {
            TransStat ts = new TransStat();
            bool      d  = ts.checktrans(OrdId, OrdDate, QueryTransType);

            if (d == false)
            {
                string sql = "update hx_UserAct set UseState=0,AmtProid=0 where UseState=3 and AmtProid=" + bid_records_id + "and registerid=" + investor_registerid;
                DbHelperSQL.RunSql(sql);
                sql = "delete hx_Bid_records where OrdId ='" + OrdId + "' and ordstate=0 and bid_records_id=" + bid_records_id;
                DbHelperSQL.RunSql(sql);
            }
            else
            {//TODO 此处有bug,自动查询的更新冻结表时缺少 FreezeTrxId 值,放款时没有该值会报错。 考虑注释该逻辑,等待汇付异步回调????
                B_usercenter BUC = new B_usercenter();
                //取得投标记录使用的优惠券
                string AmtProid = BUC.GetBid_AmtProid(int.Parse(bid_records_id));
                int    de       = BUC.ReInvest_success(UsrCustId, FreezeOrdId, TransAmt, FreezeTrxId, OrdId, AmtProid);
                if (de > 0)
                {
                    string    sql = "select targetid,bid_records_id, borrowing_title,investor_registerid ,username,mobile,invitationcode,investment_amount,life_of_loan,unit_day,borrowing_balance,bonusAmt  from  V_hx_Bid_records_borrowing_target where OrdId='" + OrdId + "'";
                    DataTable dt  = DbHelperSQL.GET_DataTable_List(sql);
                    if (dt.Rows.Count > 0)
                    {
                        decimal investAmt  = decimal.Parse(dt.Rows[0]["investment_amount"].ToString());
                        int     registerid = int.Parse(dt.Rows[0]["investor_registerid"].ToString());
                        string  targetid   = dt.Rows[0]["targetid"].ToString();

                        #region 待提取为公共方法
                        #region MyRegion  系统消息
                        DateTime            dti = DateTime.Now;
                        M_td_System_message pm  = new M_td_System_message();
                        pm.MReg     = registerid;
                        pm.Mstate   = 0;
                        pm.MTitle   = "投资成功";
                        pm.MContext = "尊敬的用户" + dt.Rows[0]["username"].ToString() + ":您好!恭喜您成功投资了项目【" + dt.Rows[0]["borrowing_title"].ToString() + "】,投资金额是:" + investAmt + "。如有问题可咨询创利投的客服!谢谢!";
                        pm.PubTime  = dti;
                        pm.Mtype    = 1;
                        B_usercenter.AddMessage(pm);
                        #endregion

                        #region MyRegion                                        //短信通知
                        string        contxt = Utils.GetMSMEmailContext(15, 1); // 获取注册成功邮件内容
                        StringBuilder sbsms  = new StringBuilder(contxt);
                        sbsms = sbsms.Replace("#USERANEM#", dt.Rows[0]["username"].ToString());
                        sbsms = sbsms.Replace("#PID#", targetid);
                        sbsms = sbsms.Replace("#MONEY#", investAmt.ToString());
                        string          mobile  = dt.Rows[0]["mobile"].ToString();
                        M_td_SMS_record psms    = new M_td_SMS_record();
                        B_td_SMS_record osms    = new B_td_SMS_record();
                        int             smstype = (int)Enum.Parse(typeof(EnumSMSType), EnumSMSType.投资成功.ToString());
                        psms.phone_number = mobile;
                        psms.sendtime     = DateTime.Now;
                        psms.senduserid   = registerid;
                        psms.smstype      = smstype;
                        psms.smscontext   = sbsms.ToString();
                        psms.orderid      = SendSMS.Send_SMS(mobile, sbsms.ToString());
                        psms.vcode        = "";
                        osms.Add(psms);
                        #endregion

                        #region 远程调用生成合同??? 稍后替换为本地方法调用  微信端可远程调用
                        string postString = "action=MUserPDF&data=" + targetid.ToString() + "&uc=" + registerid.ToString() + "&OrdId=" + OrdId;
                        string sr         = Utils.PostWebRequest(Utils.GetRemote_url("pdf/index"), postString, Encoding.UTF8);
                        #endregion

                        #region  道合作 第一投标调用接口???
                        B_member_table bmt = new B_member_table();
                        M_member_table mmt = new M_member_table();
                        mmt = bmt.GetModel(registerid);
                        if (mmt.Tid != null && mmt.Channelsource == 1)
                        {
                            if (B_usercenter.GetInvestCountByUserid(mmt.registerid) == 1)
                            {
                                string ret3 = Utils.GetCoopAPI(mmt.Tid, investAmt.ToString("0.00"), 2);
                                LogInfo.WriteLog("前台渠道合作第一次返回结果:" + ret3 + "  用户id:" + mmt.registerid + " 订单id " + OrdId);
                            }
                        }
                        #endregion
                        #endregion 待提取为公共方法

                        //发放奖励
                        ActFacade act = new ActFacade();
                        act.SendBonusAfterInvest(dt, EnumCommon.E_hx_ActivityTable.E_ActTargetPlatform.web);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 投资成功,汇付后台主动通知
        /// </summary>
        /// <returns></returns>
        public ActionResult CallbackBgRetUrl()
        {
            int                id       = 0;
            string             srt      = "";
            ReInitiativeTender p        = new ReInitiativeTender();
            B_usercenter       BUC      = new B_usercenter();
            string             OrdId    = "";
            int                useridc  = 0;
            string             targetid = "0";

            id = DNTRequest.GetInt("id", 0);
            LoggerHelper.Info("主动通知后台有响应成功!");
            p.CmdId       = DNTRequest.GetString("CmdId");
            p.RespCode    = DNTRequest.GetString("RespCode");
            p.RespDesc    = HttpUtility.UrlDecode(DNTRequest.GetString("RespDesc"));
            p.MerCustId   = DNTRequest.GetString("MerCustId");
            p.OrdId       = DNTRequest.GetString("OrdId");
            p.OrdDate     = DNTRequest.GetString("OrdDate");
            p.TransAmt    = DNTRequest.GetString("TransAmt");
            p.UsrCustId   = DNTRequest.GetString("UsrCustId");
            p.TrxId       = DNTRequest.GetString("TrxId");
            p.IsFreeze    = DNTRequest.GetString("IsFreeze");
            p.FreezeOrdId = DNTRequest.GetString("FreezeOrdId");
            p.FreezeTrxId = DNTRequest.GetString("FreezeTrxId");
            p.RetUrl      = HttpUtility.UrlDecode(DNTRequest.GetString("RetUrl"));
            p.BgRetUrl    = HttpUtility.UrlDecode(DNTRequest.GetString("BgRetUrl"));
            string merp = DNTRequest.GetString("MerPriv");

            if (merp.Length > 0)
            {
                p.MerPriv = HttpUtility.UrlDecode(merp);
            }
            else
            {
                p.MerPriv = merp;
            }

            p.RespExt  = HttpUtility.UrlDecode(DNTRequest.GetString("RespExt"));
            p.ChkValue = DNTRequest.GetString("ChkValue");
            StringBuilder chkVal = new StringBuilder();

            chkVal.Append(p.CmdId);
            chkVal.Append(p.RespCode);
            chkVal.Append(p.MerCustId);
            chkVal.Append(p.OrdId);
            chkVal.Append(p.OrdDate);
            chkVal.Append(p.TransAmt);
            chkVal.Append(p.UsrCustId);
            chkVal.Append(p.TrxId);
            chkVal.Append(p.IsFreeze);
            chkVal.Append(p.FreezeOrdId);
            chkVal.Append(p.FreezeTrxId);
            chkVal.Append(p.RetUrl);
            chkVal.Append(p.BgRetUrl);
            chkVal.Append(p.MerPriv);
            chkVal.Append(p.RespExt);
            string chkv = chkVal.ToString();

            //私钥文件的位置(这里是放在了站点的根目录下)

            string merKeyFile = AppDomain.CurrentDomain.BaseDirectory + Settings.Instance.PgPubk;

            int ret = DllInterop.VeriSignMsg(merKeyFile, chkv, chkv.Length, p.ChkValue);

            LoggerHelper.Info("投标后台主动投标返回报文:" + JsonHelper.Entity2Json(p));

            string sql = "";

            merp = p.MerPriv;
            string deviceKey = PickoutDeviceFlag(ref merp);//pick out device code from comment field

            p.MerPriv = merp;
            int invcount = 0; //记录用户是否是首次投资

            #region 验签
            if (ret == 0)
            {
                if (p.RespCode == "000" || p.RespCode == "534" || p.RespCode == "360" || p.RespCode == "099")//p.RespCode == "322" ||
                {
                    string cachename = p.OrdId + "Invest" + p.UsrCustId;

                    if (Settings.Instance.GeTThirdCache(cachename) == 0)
                    {
                        Settings.Instance.SetThirdCache(cachename);
                        if (p.FreezeTrxId != "")
                        {
                            sql = "select ordstate  from hx_Bid_records  where ordstate =0 and  OrdId='" + p.OrdId + "'";
                            LoggerHelper.Info("CallbackBgRetUrl===p.OrdId:" + p.OrdId);
                            LoggerHelper.Info("sql :" + sql);
                            DataTable dts = DbHelper.Query(sql).Tables[0];

                            if (dts.Rows.Count > 0)
                            {
                                //同步处理用户金额
                                int d = BUC.ReInvest_success(p.UsrCustId, p.FreezeOrdId, p.TransAmt, p.FreezeTrxId, p.OrdId, p.MerPriv);
                                LoggerHelper.Info("后台投标:id" + id.ToString() + "返回唯一冻结标识:" + p.FreezeTrxId + "事务执行结果:" + d.ToString());

                                if (d > 0)
                                {
                                    sql = "select targetid,bid_records_id, borrowing_title,investor_registerid ,username,mobile,invitationcode,investment_amount,life_of_loan,unit_day,borrowing_balance,bonusAmt  from  V_hx_Bid_records_borrowing_target where OrdId='" + p.OrdId + "'";

                                    DataTable dt = DbHelper.Query(sql).Tables[0];

                                    if (dt.Rows.Count > 0)
                                    {
                                        decimal invdesc = decimal.Parse(dt.Rows[0]["investment_amount"].ToString());

                                        OrdId   = p.OrdId;
                                        useridc = int.Parse(dt.Rows[0]["investor_registerid"].ToString());

                                        targetid = dt.Rows[0]["targetid"].ToString();

                                        LoggerHelper.Info(" /*此处加入活动*/:" + targetid);
                                        //参与所有活动规则
                                        if (!string.IsNullOrWhiteSpace(deviceKey))
                                        {
                                            using (ActFacade actFacade = new ActFacade())
                                            {
                                                actFacade.SendBonusAfterInvest(dt, Utils.GetDevicePlatformCode(deviceKey));
                                            }
                                        }
                                        #region MyRegion  邀请注册奖历 投资成功奖励 --已过期
                                        //invcount = B_usercenter.GetIsNews(useridc);
                                        //ActTable act = new ActTable();
                                        //#region 首次投资活动奖励
                                        //if (invcount == 1)
                                        //{
                                        //    //首次投资活动奖励
                                        //    act.UsrFirstInvest(useridc, decimal.Parse(p.TransAmt), 3, 1);

                                        //}

                                        /////续投用户
                                        //if (invcount >= 2)
                                        //{
                                        //    act.UsrFirstInvest(useridc, decimal.Parse(p.TransAmt), 3, 6);
                                        //}

                                        //#region 所有用户
                                        ////所有用户
                                        //act.UsrFirstInvest(useridc, decimal.Parse(p.TransAmt), 3, 5);

                                        //#endregion


                                        //#region 投标最大的用户
                                        ////投标最大的用户
                                        //decimal borrowing_balance = decimal.Parse(dt.Rows[0]["borrowing_balance"].ToString());
                                        //DataTable dmax = B_usercenter.Topinvestor(int.Parse(targetid));
                                        //if (dmax.Rows.Count > 0)
                                        //{
                                        //    decimal amtc = decimal.Parse(dmax.Rows[0]["InvCount_Amt"].ToString());
                                        //    if (borrowing_balance == amtc)
                                        //    {
                                        //        act.UsrFirstInvest(int.Parse(dmax.Rows[0]["investor_registerid"].ToString()), decimal.Parse(dmax.Rows[0]["maxamt"].ToString()), 3, 4);
                                        //    }
                                        //}
                                        //#endregion

                                        //#region 每标首投用户
                                        ////每标首投用户
                                        //if (B_usercenter.TopNum(targetid) == 1)
                                        //{
                                        //    act.UsrFirstInvest(useridc, decimal.Parse(p.TransAmt), 3, 3);
                                        //}
                                        //#endregion

                                        //#endregion


                                        //#region 渠道合作 第一投标调用接口

                                        //B_member_table bmt = new B_member_table();
                                        //M_member_table mmt = new M_member_table();

                                        //mmt = bmt.GetModel(int.Parse(dt.Rows[0]["investor_registerid"].ToString()));


                                        //if (mmt.Tid != null && mmt.Channelsource == 1)
                                        //{
                                        //    if (B_usercenter.GetIsNews(mmt.registerid) == 1)
                                        //    {
                                        //        string ret3 = Utils.GetCoopAPI(mmt.Tid, invdesc.ToString("0.00"), 2);

                                        //        LoggerHelper.Info("渠道合作第一次返回结果:" + ret3 + "  用户id:" + mmt.registerid + " 订单id " + p.OrdId);
                                        //    }

                                        //}
                                        //#endregion



                                        /*此处注册奖励业务*/

                                        ////注册奖历

                                        //B_bonus_account bb = new B_bonus_account();
                                        //M_bonus_account mb = new M_bonus_account();

                                        //M_bonus_account_water mbaw = new M_bonus_account_water();
                                        //B_bonus_account_water bbaw = new B_bonus_account_water();

                                        //string invcode = dt.Rows[0]["invitationcode"].ToString();
                                        //string uid = dt.Rows[0]["investor_registerid"].ToString();



                                        //LoggerHelper.Info(" /*验证码*/:" + invcode);
                                        //if (invcode != null && invcode != "")
                                        //{

                                        //    DateTime dte = DateTime.Now;

                                        //    string codesql = "SELECT invcode,Invpeopleid,invpersonid from  hx_td_Userinvitation where invcode='" + invcode + "' and invpersonid=" + uid + " ";//查询本人是否已经被邀请注册过

                                        //    LoggerHelper.Info("codesql2:" + 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)
                                        //        {

                                        //            //受邀好友首次成功投资
                                        //            #region 首次投资活动奖励

                                        //            ACTInvitation aci = new ACTInvitation();

                                        //            #region 受邀好友首次成功投资给予活动奖励
                                        //            if (invcount == 1) //受邀好友首次成功投资给予活动奖励
                                        //            {
                                        //                hx_UserAct hut = aci.YaoAmtAct(uuid, int.Parse(dtcode.Rows[0]["invpersonid"].ToString()), -1, 4, 1, 1, 0, 5);
                                        //                if (hut != null)
                                        //                {
                                        //                    mbaw.bonus_account_id = hut.UserAct;
                                        //                    mbaw.membertable_registerid = uuid;
                                        //                    mbaw.income = decimal.Parse(hut.Amt.ToString());
                                        //                    mbaw.expenditure = 0.00M;
                                        //                    mbaw.time_of_occurrence = DateTime.Now;
                                        //                    mbaw.award_description = "邀请好友首次投资成功" + hut.Amt.ToString() + "元奖励";
                                        //                    mbaw.water_type = 0;
                                        //                    bbaw.Add(mbaw);
                                        //                }

                                        //            }


                                        //            #endregion


                                        //            #region 受邀用户续投奖励
                                        //            ///受邀用户续投奖励
                                        //            if (invcount >= 2)
                                        //            {
                                        //                if (py.LostInvitation == 0)
                                        //                {
                                        //                    //这里需要取出受邀用户奖总数

                                        //                    int biyaoUsrid = int.Parse(dt.Rows[0]["invpersonid"].ToString());

                                        //                    decimal totAmt = B_usercenter.GetInviUserTotalAmt(uuid, biyaoUsrid);

                                        //                    hx_UserAct hut = aci.YaoAmtAct(uuid, biyaoUsrid, decimal.Parse(p.TransAmt), 4, 2, 1, totAmt, 5);

                                        //                    if (hut != null)
                                        //                    {
                                        //                        mbaw.bonus_account_id = hut.UserAct;
                                        //                        mbaw.membertable_registerid = uuid;
                                        //                        mbaw.income = decimal.Parse(hut.Amt.ToString());
                                        //                        mbaw.expenditure = 0.00M;
                                        //                        mbaw.time_of_occurrence = DateTime.Now;
                                        //                        mbaw.award_description = "受邀用户续投奖励" + hut.Amt.ToString() + "元奖励";
                                        //                        mbaw.water_type = 0;
                                        //                        bbaw.Add(mbaw);
                                        //                    }

                                        //                }

                                        //            }
                                        //            #endregion

                                        //            /*
                                        //            int bbid = bb.Add(mb);
                                        //            if (bbid > 0) //奖励记录成功后插入明细记录
                                        //            {
                                        //                mbaw.bonus_account_id = bbid;
                                        //                mbaw.membertable_registerid = uuid;
                                        //                mbaw.income = mb.amount_of_reward;
                                        //                mbaw.expenditure = 0.00M;
                                        //                mbaw.time_of_occurrence = mb.entry_time;
                                        //                // mbaw.
                                        //                mbaw.award_description = "邀请投资成功10元奖励";
                                        //                mbaw.water_type = 0;
                                        //                bbaw.Add(mbaw);

                                        //                DbHelperSQL.RunSql(" update hx_td_Userinvitation  set InvitesStates=1  where invcode='" + invcode + "' and invpersonid=" + uid + " and  InvitesStates=2 ");
                                        //                LoggerHelper.Info(" 后台更新数据邀请状态 update hx_td_Userinvitation  set InvitesStates=1  where invcode='" + invcode + "' and invpersonid=" + uid + " and  InvitesStates=2 ");
                                        //            }*/



                                        //        }
                                        //    }
                                        //}


                                        //#endregion
                                        #endregion


                                        #region MyRegion  系统消息
                                        DateTime dti = DateTime.Now;

                                        M_td_System_message pm = new M_td_System_message();
                                        pm.MReg     = int.Parse(dt.Rows[0]["investor_registerid"].ToString());
                                        pm.Mstate   = 0;
                                        pm.MTitle   = "投资成功";
                                        pm.MContext = "尊敬的用户" + dt.Rows[0]["username"].ToString() + ":您好!恭喜您成功投资了项目【" + dt.Rows[0]["borrowing_title"].ToString() + "】,投资金额是:" + dt.Rows[0]["investment_amount"].ToString() + "。如有问题可咨询创利投的客服!谢谢!";
                                        pm.PubTime  = dti;
                                        pm.Mtype    = 1;
                                        B_usercenter.AddMessage(pm);
                                        #endregion



                                        #region MyRegion//短信通知

                                        MemberLogic _logic    = new MemberLogic();
                                        var         smsEntity = _logic.GetSmsEmailEntity(1, 15); // 短信通知



                                        StringBuilder sbsms = new StringBuilder(smsEntity.SEContext);

                                        sbsms = sbsms.Replace("#USERANEM#", dt.Rows[0]["username"].ToString());

                                        sbsms = sbsms.Replace("#PID#", dt.Rows[0]["targetid"].ToString());

                                        sbsms = sbsms.Replace("#MONEY#", dt.Rows[0]["investment_amount"].ToString());


                                        string mobile = dt.Rows[0]["mobile"].ToString();

                                        M_td_SMS_record psms    = new M_td_SMS_record();
                                        B_td_SMS_record osms    = new B_td_SMS_record();
                                        int             smstype = (int)Enum.Parse(typeof(EnumSMSType), EnumSMSType.投资成功.ToString());
                                        psms.phone_number = mobile;
                                        psms.sendtime     = DateTime.Now;
                                        psms.senduserid   = int.Parse(dt.Rows[0]["investor_registerid"].ToString());
                                        psms.smstype      = smstype;
                                        psms.smscontext   = sbsms.ToString();
                                        psms.orderid      = SendSMS.Send(mobile, sbsms.ToString());
                                        psms.vcode        = "";

                                        osms.Add(psms);
                                        #endregion
                                    }
                                    //远程调用生成合同

                                    //var values = new NameValueCollection
                                    //{
                                    //    {"action","MUserPDF"},
                                    //    {"data",targetid},
                                    //    {"uc",useridc.ToString()},
                                    //    {"OrdId",OrdId}
                                    //};
                                    //HttpHelper.Post(Settings.Instance.SiteDomain + "/pdf", values);
                                }
                            }
                            else
                            {
                            }
                            srt = "RECV_ORD_ID_" + p.OrdId;
                        }
                    }/*缓存检查结束位置*/
                }
                else
                {
                }
            }

            #endregion
            return(Content(srt));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 投资成功,汇付后台主动通知
        /// </summary>
        /// <returns></returns>
        public ActionResult BG_investment_success()
        {
            int                id  = 0;
            string             srt = "";
            ReInitiativeTender p   = new ReInitiativeTender();

            id = DNTRequest.GetInt("id", 0);
            string log = "";

            log          += "主动通知后台有响应成功!接收到的项目id=" + id;
            p.CmdId       = DNTRequest.GetString("CmdId");
            p.RespCode    = DNTRequest.GetString("RespCode");
            p.RespDesc    = HttpUtility.UrlDecode(DNTRequest.GetString("RespDesc"));
            p.MerCustId   = DNTRequest.GetString("MerCustId");
            p.OrdId       = DNTRequest.GetString("OrdId");
            p.OrdDate     = DNTRequest.GetString("OrdDate");
            p.TransAmt    = DNTRequest.GetString("TransAmt");
            p.UsrCustId   = DNTRequest.GetString("UsrCustId");
            p.TrxId       = DNTRequest.GetString("TrxId");
            p.IsFreeze    = DNTRequest.GetString("IsFreeze");
            p.FreezeOrdId = DNTRequest.GetString("FreezeOrdId");
            p.FreezeTrxId = DNTRequest.GetString("FreezeTrxId");
            p.RetUrl      = HttpUtility.UrlDecode(DNTRequest.GetString("RetUrl"));
            p.BgRetUrl    = HttpUtility.UrlDecode(DNTRequest.GetString("BgRetUrl"));
            string merp = DNTRequest.GetString("MerPriv");

            if (merp.Length > 0)
            {
                p.MerPriv = HttpUtility.UrlDecode(merp);
            }
            else
            {
                p.MerPriv = merp;
            }

            p.RespExt  = HttpUtility.UrlDecode(DNTRequest.GetString("RespExt"));
            p.ChkValue = DNTRequest.GetString("ChkValue");
            StringBuilder chkVal = new StringBuilder();

            chkVal.Append(p.CmdId);
            chkVal.Append(p.RespCode);
            chkVal.Append(p.MerCustId);
            chkVal.Append(p.OrdId);
            chkVal.Append(p.OrdDate);
            chkVal.Append(p.TransAmt);
            chkVal.Append(p.UsrCustId);
            chkVal.Append(p.TrxId);
            chkVal.Append(p.IsFreeze);
            chkVal.Append(p.FreezeOrdId);
            chkVal.Append(p.FreezeTrxId);
            chkVal.Append(p.RetUrl);
            chkVal.Append(p.BgRetUrl);
            chkVal.Append(p.MerPriv);
            chkVal.Append(p.RespExt);
            string chkv = chkVal.ToString();

            //私钥文件的位置(这里是放在了站点的根目录下)
            string merKeyFile = AppDomain.CurrentDomain.BaseDirectory + Utils.GetPgPubk();
            int    ret        = DllInterop.VeriSignMsg(merKeyFile, chkv, chkv.Length, p.ChkValue);

            log += "<br>投标后台主动投标返回报文:" + FastJSON.toJOSN(p);
            string sql = "";

            int invcount = 0; //记录用户是否是首次投资

            #region 验签
            if (ret == 0)
            {
                if (p.RespCode == "000" || p.RespCode == "322" || p.RespCode == "534" || p.RespCode == "360" || p.RespCode == "099")
                {
                    string cachename = p.OrdId + "InvestWeb" + p.UsrCustId;

                    if (Utils.GeTThirdCache(cachename) == 0)
                    {
                        Utils.SetThirdCache(cachename);
                        if (p.FreezeTrxId != "")
                        {
                            sql = "select ordstate  from hx_Bid_records  where ordstate =0 and  OrdId='" + p.OrdId + "'";
                            DataTable dts = DbHelperSQL.GET_DataTable_List(sql);

                            if (dts.Rows.Count > 0)
                            {
                                //同步处理用户金额
                                B_usercenter BUC = new B_usercenter();
                                int          d   = BUC.ReInvest_success(p.UsrCustId, p.FreezeOrdId, p.TransAmt, p.FreezeTrxId, p.OrdId, p.MerPriv);
                                log += "<br>后台投标:id" + id.ToString() + "返回唯一冻结标识:" + p.FreezeTrxId + "事务执行结果:" + d.ToString();
                                if (d > 0)
                                {
                                    sql = "select targetid,bid_records_id, borrowing_title,investor_registerid ,username,mobile,invitationcode,investment_amount,life_of_loan,unit_day,borrowing_balance,bonusAmt from  V_hx_Bid_records_borrowing_target where OrdId='" + p.OrdId + "'";
                                    DataTable dt = DbHelperSQL.GET_DataTable_List(sql);
                                    if (dt.Rows.Count > 0)
                                    {
                                        decimal investAmt  = decimal.Parse(dt.Rows[0]["investment_amount"].ToString());
                                        string  OrdId      = p.OrdId;
                                        int     registerid = int.Parse(dt.Rows[0]["investor_registerid"].ToString());
                                        ViewBag.userid = registerid;
                                        string targetid = dt.Rows[0]["targetid"].ToString();

                                        #region 待提取为公共方法
                                        #region MyRegion  系统消息
                                        DateTime            dti = DateTime.Now;
                                        M_td_System_message pm  = new M_td_System_message();
                                        pm.MReg     = registerid;
                                        pm.Mstate   = 0;
                                        pm.MTitle   = "投资成功";
                                        pm.MContext = "尊敬的用户" + dt.Rows[0]["username"].ToString() + ":您好!恭喜您成功投资了项目【" + dt.Rows[0]["borrowing_title"].ToString() + "】,投资金额是:" + investAmt + "。如有问题可咨询创利投的客服!谢谢!";
                                        pm.PubTime  = dti;
                                        pm.Mtype    = 1;
                                        B_usercenter.AddMessage(pm);
                                        #endregion

                                        #region MyRegion                                        //短信通知
                                        string        contxt = Utils.GetMSMEmailContext(15, 1); // 获取注册成功邮件内容
                                        StringBuilder sbsms  = new StringBuilder(contxt);
                                        sbsms = sbsms.Replace("#USERANEM#", dt.Rows[0]["username"].ToString());
                                        sbsms = sbsms.Replace("#PID#", targetid);
                                        sbsms = sbsms.Replace("#MONEY#", investAmt.ToString());
                                        string          mobile  = dt.Rows[0]["mobile"].ToString();
                                        M_td_SMS_record psms    = new M_td_SMS_record();
                                        B_td_SMS_record osms    = new B_td_SMS_record();
                                        int             smstype = (int)Enum.Parse(typeof(EnumSMSType), EnumSMSType.投资成功.ToString());
                                        psms.phone_number = mobile;
                                        psms.sendtime     = DateTime.Now;
                                        psms.senduserid   = registerid;
                                        psms.smstype      = smstype;
                                        psms.smscontext   = sbsms.ToString();
                                        psms.orderid      = SendSMS.Send_SMS(mobile, sbsms.ToString());
                                        psms.vcode        = "";
                                        osms.Add(psms);
                                        #endregion

                                        #region 远程调用生成合同??? 稍后替换为本地方法调用  微信端可远程调用
                                        string postString = "action=MUserPDF&data=" + targetid.ToString() + "&uc=" + registerid.ToString() + "&OrdId=" + OrdId;
                                        string sr         = Utils.PostWebRequest(Utils.GetRemote_url("pdf/index"), postString, Encoding.UTF8);
                                        #endregion

                                        #region  道合作 第一投标调用接口???
                                        B_member_table bmt = new B_member_table();
                                        M_member_table mmt = new M_member_table();
                                        mmt = bmt.GetModel(registerid);
                                        if (mmt.Tid != null && mmt.Channelsource == 1)
                                        {
                                            if (B_usercenter.GetInvestCountByUserid(mmt.registerid) == 1)
                                            {
                                                string ret3 = Utils.GetCoopAPI(mmt.Tid, investAmt.ToString("0.00"), 2);
                                                log += "<br>前台渠道合作第一次返回结果:" + ret3 + "  用户id:" + mmt.registerid + " 订单id " + OrdId;
                                            }
                                        }
                                        #endregion
                                        #endregion 待提取为公共方法

                                        //发放奖励
                                        ActFacade act = new ActFacade();
                                        act.SendBonusAfterInvest(dt, EnumCommon.E_hx_ActivityTable.E_ActTargetPlatform.web);

                                        #region  线 投资六月专享标一元抢Iphone 2016年9月11日 9点 至2016年9月30日
                                        if (false)
                                        {
                                            DateTime nowdate   = DateTime.Now;
                                            DateTime startdate = new DateTime(2016, 09, 11, 9, 00, 00);
                                            DateTime enddate   = new DateTime(2016, 09, 30, 23, 59, 59);

                                            if (nowdate > startdate && nowdate < enddate)
                                            {
                                                log += "<br>PC端【一元抢Iphone】";
                                                log += "<br>标的期限:" + dt.Rows[0]["life_of_loan"].ToString();
                                                if (dt.Rows[0]["unit_day"].ToString() == "1" && dt.Rows[0]["life_of_loan"].ToString() == "6")//是否六月标
                                                {
                                                    log += "<br>用户注册时间:" + mmt.Registration_time.ToString();
                                                    if (mmt.Registration_time > new DateTime(2016, 09, 11, 0, 0, 0))
                                                    {
                                                        B_GrabIphone gi = new B_GrabIphone();

                                                        bool isCount = gi.Exists(mmt.registerid);//查询是否存在该用户
                                                        log += "<br> 用户ID:" + mmt.registerid + ";查询是否存在该用户:" + isCount;
                                                        if (isCount != true)
                                                        {
                                                            M_GrabIphone model = new M_GrabIphone();
                                                            model.RegrsterID       = mmt.registerid;
                                                            model.Color            = "";
                                                            model.Addtime          = nowdate;
                                                            model.LuckDrawState    = 0;
                                                            model.WinningState     = 0;
                                                            model.WinningTime      = nowdate;
                                                            model.TargetID         = int.Parse(dt.Rows[0]["targetid"].ToString());
                                                            model.BidRecordsID     = int.Parse(dt.Rows[0]["bid_records_id"].ToString());
                                                            model.InvestmentAmount = dt.Rows[0]["investment_amount"].ToString();
                                                            gi.Add(model);                                                                                                 //增加一条数据
                                                            int ljcount = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["GrabIphone"].ToString()); //获取启动抽奖人数
                                                            List <M_GrabIphone> giList = gi.GetModelList(ljcount, "LuckDrawState=0", "ID");                                //获取当前阶段投资人数
                                                            if (giList != null)
                                                            {
                                                                log += "<br>当前阶段投资人数:" + giList.Count;

                                                                if (giList.Count >= ljcount)
                                                                {
                                                                    bool bo = gi.UpdateLuckDrawState();//批量更新抽奖状态
                                                                    log += "<br> 批量更新抽奖状态:" + bo;
                                                                    if (bo == true)
                                                                    {
                                                                        int          count      = giList.Count;
                                                                        int          index      = new Random().Next(count);
                                                                        M_GrabIphone randowitem = giList[index];

                                                                        if (randowitem != null)
                                                                        {
                                                                            log += "<br> 获奖用户ID:" + randowitem.RegrsterID;
                                                                            bool co = gi.Update("", 1, DateTime.Now, randowitem.RegrsterID);//更新中奖用户状态
                                                                            log += "<br> 更新中奖用户状态:" + co;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        #endregion
                                    }
                                }
                            }
                            srt = "RECV_ORD_ID_" + p.OrdId;
                        }
                    }/*缓存检查结束位置*/
                }
            }
            LogInfo.WriteLog(log);
            #endregion
            return(Content(srt));
        }
Exemplo n.º 4
0
        /// <summary>
        /// 投资成功,汇付回调页面
        /// </summary>
        /// <returns></returns>
        public ActionResult CallbackRetUrl()
        {
            ViewBag.UserId = 0;
            ReInitiativeTender p = new ReInitiativeTender();
            B_usercenter       BUC = new B_usercenter();
            string             OrdId = "", sql = "";
            int    useridc  = 0;
            string targetid = "0";

            p.CmdId       = DNTRequest.GetString("CmdId");
            p.RespCode    = DNTRequest.GetString("RespCode");
            p.RespDesc    = HttpUtility.UrlDecode(DNTRequest.GetString("RespDesc"));
            p.MerCustId   = DNTRequest.GetString("MerCustId");
            p.OrdId       = DNTRequest.GetString("OrdId");
            p.OrdDate     = DNTRequest.GetString("OrdDate");
            p.TransAmt    = DNTRequest.GetString("TransAmt");
            p.UsrCustId   = DNTRequest.GetString("UsrCustId");
            p.TrxId       = DNTRequest.GetString("TrxId");
            p.IsFreeze    = DNTRequest.GetString("IsFreeze");
            p.FreezeOrdId = DNTRequest.GetString("FreezeOrdId");
            p.FreezeTrxId = DNTRequest.GetString("FreezeTrxId");
            p.RetUrl      = HttpUtility.UrlDecode(DNTRequest.GetString("RetUrl"));
            p.BgRetUrl    = HttpUtility.UrlDecode(DNTRequest.GetString("BgRetUrl"));
            string merp = DNTRequest.GetString("MerPriv");

            if (merp.Length > 0)
            {
                p.MerPriv = HttpUtility.UrlDecode(merp);
            }
            else
            {
                p.MerPriv = merp;
            }
            p.RespExt  = HttpUtility.UrlDecode(DNTRequest.GetString("RespExt"));
            p.ChkValue = DNTRequest.GetString("ChkValue");
            StringBuilder chkVal = new StringBuilder();

            chkVal.Append(p.CmdId);
            chkVal.Append(p.RespCode);
            chkVal.Append(p.MerCustId);
            chkVal.Append(p.OrdId);
            chkVal.Append(p.OrdDate);
            chkVal.Append(p.TransAmt);
            chkVal.Append(p.UsrCustId);
            chkVal.Append(p.TrxId);
            chkVal.Append(p.IsFreeze);
            chkVal.Append(p.FreezeOrdId);
            chkVal.Append(p.FreezeTrxId);
            chkVal.Append(p.RetUrl);
            chkVal.Append(p.BgRetUrl);
            chkVal.Append(p.MerPriv);
            chkVal.Append(p.RespExt);

            //   LoggerHelper.Info("投标RespCode" + p.RespCode + "RespExt:" + p.RespExt);
            string chkv = chkVal.ToString();

            //私钥文件的位置(这里是放在了站点的根目录下)
            string merKeyFile = AppDomain.CurrentDomain.BaseDirectory + Settings.Instance.PgPubk;

            int ret = DllInterop.VeriSignMsg(merKeyFile, chkv, chkv.Length, p.ChkValue);

            // LoggerHelper.Info("验签:" + ret.ToString());

            LoggerHelper.Info("前台主动投标返回报文:" + JsonHelper.Entity2Json(p));
            int invcount = 0; //记录用户是否为首次投资,汲及到邀请人的操作

            merp = p.MerPriv;
            string deviceKey = PickoutDeviceFlag(ref merp);//pick out device code from comment field

            p.MerPriv = merp;
            int registerid = 0;

            #region 验签
            if (ret == 0)
            {
                if (p.RespCode == "000" || p.RespCode == "534" || p.RespCode == "360" || p.RespCode == "099")//p.RespCode == "322" ||
                {
                    string cachename = p.OrdId + "Invest" + p.UsrCustId;

                    //LoggerHelper.Info("cachename:" + cachename);
                    if (Settings.Instance.GeTThirdCache(cachename) == 0)
                    {
                        Settings.Instance.SetThirdCache(cachename);
                        if (p.FreezeTrxId != "")
                        {
                            sql = "select ordstate  from hx_Bid_records  where ordstate =0 and  OrdId='" + p.OrdId + "'";
                            LoggerHelper.Info("CallbackRetUrl===p.OrdId:" + p.OrdId);
                            DataTable dts = DbHelper.Query(sql).Tables[0];
                            if (dts.Rows.Count > 0)
                            {
                                //同步处理用户金额
                                int d = BUC.ReInvest_success(p.UsrCustId, p.FreezeOrdId, p.TransAmt, p.FreezeTrxId, p.OrdId, p.MerPriv);
                                LoggerHelper.Info("返回唯一冻结标识:" + p.FreezeTrxId + "事务执行结果:" + d);
                                if (d > 0)
                                {
                                    sql = "select targetid,bid_records_id, borrowing_title,investor_registerid ,username,mobile,invitationcode,investment_amount,life_of_loan,unit_day,borrowing_balance,bonusAmt,registerid  from  V_hx_Bid_records_borrowing_target where OrdId='" + p.OrdId + "'";
                                    DataTable dt = DbHelper.Query(sql).Tables[0];
                                    if (dt.Rows.Count > 0)
                                    {
                                        decimal invdesc = decimal.Parse(dt.Rows[0]["investment_amount"].ToString());
                                        OrdId      = p.OrdId;
                                        useridc    = int.Parse(dt.Rows[0]["investor_registerid"].ToString());
                                        targetid   = dt.Rows[0]["targetid"].ToString();
                                        registerid = Convert.ToInt32(dt.Rows[0]["registerid"]);
                                        LoggerHelper.Info(" /*此处加入活动*/:" + targetid + " DeviceKey:" + deviceKey);
                                        //参与所有活动规则
                                        if (!string.IsNullOrWhiteSpace(deviceKey))
                                        {
                                            using (ActFacade actFacade = new ActFacade())
                                            {
                                                actFacade.SendBonusAfterInvest(dt, Utils.GetDevicePlatformCode(deviceKey));
                                            }
                                        }
                                        ViewBag.UserId = Convert.ToInt32(dt.Rows[0]["registerid"]);
                                        #region MyRegion  系统消息
                                        DateTime            dti = DateTime.Now;
                                        M_td_System_message pm  = new M_td_System_message();
                                        pm.MReg     = int.Parse(dt.Rows[0]["investor_registerid"].ToString());
                                        pm.Mstate   = 0;
                                        pm.MTitle   = "投资成功";
                                        pm.MContext = "尊敬的用户" + dt.Rows[0]["username"].ToString() + ":您好!恭喜您成功投资了项目【" + dt.Rows[0]["borrowing_title"].ToString() + "】,投资金额是:" + dt.Rows[0]["investment_amount"].ToString() + "。如有问题可咨询创利投的客服!谢谢!";
                                        pm.PubTime  = dti;
                                        pm.Mtype    = 1;
                                        B_usercenter.AddMessage(pm);
                                        #endregion

                                        #region MyRegion//短信通知

                                        MemberLogic _logic    = new MemberLogic();
                                        var         smsEntity = _logic.GetSmsEmailEntity(1, 15); // 短信通知



                                        StringBuilder sbsms = new StringBuilder(smsEntity.SEContext);
                                        sbsms = sbsms.Replace("#USERANEM#", dt.Rows[0]["username"].ToString());
                                        sbsms = sbsms.Replace("#PID#", dt.Rows[0]["targetid"].ToString());
                                        sbsms = sbsms.Replace("#MONEY#", dt.Rows[0]["investment_amount"].ToString());
                                        string          mobile  = dt.Rows[0]["mobile"].ToString();
                                        M_td_SMS_record psms    = new M_td_SMS_record();
                                        B_td_SMS_record osms    = new B_td_SMS_record();
                                        int             smstype = (int)Enum.Parse(typeof(EnumSMSType), EnumSMSType.投资成功.ToString());
                                        psms.phone_number = mobile;
                                        psms.sendtime     = DateTime.Now;
                                        psms.senduserid   = int.Parse(dt.Rows[0]["investor_registerid"].ToString());
                                        psms.smstype      = smstype;
                                        psms.smscontext   = sbsms.ToString();
                                        psms.orderid      = SendSMS.Send(mobile, sbsms.ToString());
                                        psms.vcode        = "";

                                        osms.Add(psms);
                                        #endregion
                                    }
                                }
                            }
                        }
                    }
                }/*缓存检查结束位置*/
            }
            #endregion
            return(View(p));
        }