Beispiel #1
0
        /// <summary>
        /// 投资 ,调用此方法之前必须做冻结 (M_td_frozen) 操作
        /// </summary>
        /// <param name="p">必须参数 OrdId,invest_time,investment_amount,investment_amount,targetid</param>
        /// <param name="usrCustId">up.UsrCustId</param>
        /// <param name="borrUsrCustId">dt.Rows[0]["BorrUsrCustId"].ToString()</param>
        /// <param name="isinterest">0 代金券   1 加息劵</param>
        /// <param name="vocheramttemp">优惠金额</param>
        /// <param name="rewardsids">附带参数,用于代金券或加息劵编号</param>
        /// <param name="frozenidNo">冻结号</param>
        /// <param name="isWeb">是否是网页端生成</param>
        /// <returns></returns>
        public static M_InitiativeTender InitiativeTender(M_Bid_records p, string usrCustId, string borrUsrCustId, int isinterest, decimal vocheramttemp, string rewardsids, string frozenidNo, bool isWeb = true)
        {
            M_InitiativeTender m = new M_InitiativeTender();

            m.Version       = "20";
            m.CmdId         = "InitiativeTender";
            m.MerCustId     = Utils.GetMerCustID();
            m.OrdId         = p.OrdId.ToString();
            m.OrdDate       = p.invest_time.ToString("yyyyMMdd");
            m.TransAmt      = p.investment_amount.ToString("0.00");
            m.UsrCustId     = usrCustId;
            m.MaxTenderRate = "0.20";
            TenderJosnPro mtp = new TenderJosnPro();

            mtp.BorrowerCustId = borrUsrCustId;
            //mtp.BorrowerAmt =decimal.Parse(dt.Rows[0]["borrowing_balance"].ToString()).ToString("0.00");
            mtp.BorrowerAmt = p.investment_amount.ToString("0.00");
            // mtp.BorrowerRate = decimal.Parse( dt.Rows[0]["loan_management_fee"].ToString()).ToString("0.00");
            mtp.BorrowerRate  = "1.00"; //风控范围
            mtp.ProId         = p.targetid.ToString();
            m.BorrowerDetails = "[" + FastJSON.toJOSN(mtp) + "]";

            #region 此处判断优惠类型
            if (isinterest == 0)  //代金券
            {
                TenderAccPro reqExt = new TenderAccPro();
                reqExt.AcctId    = Utils.GetMERDT();
                reqExt.VocherAmt = vocheramttemp.ToString("0.00");
                if (rewardsids.Length > 0)
                {
                    m.ReqExt = "{" + "\"Vocher\":" + FastJSON.toJOSN(reqExt) + "}";
                }
            }
            #endregion
            m.IsFreeze    = "Y";
            m.FreezeOrdId = frozenidNo;
            //Mt.RetUrl = "http://localhost:17745/investment_success_" + targetid.ToString() + ".html";
            m.RetUrl = Utils.GetRe_url((isWeb ? "" : "Home/") + "investment_success" + (isWeb ? "_" : "/") + p.targetid.ToString() + (isWeb ? ".html" : ""));
            //Mt.RetUrl = Utils.GetRe_url("Home/investment_success/" + targetid.ToString());
            m.BgRetUrl = Utils.GetRe_url("Thirdparty/BG_investment_success");
            // Mt.BgRetUrl = Utils.GetRe_url("666Thirdparty/BG_investment_success");
            m.MerPriv = rewardsids;
            LogInfo.WriteLog("优惠券使用的id:" + rewardsids);

            StringBuilder chkVal = new StringBuilder();
            chkVal.Append(m.Version);
            chkVal.Append(m.CmdId);
            chkVal.Append(m.MerCustId);
            chkVal.Append(m.OrdId);
            chkVal.Append(m.OrdDate);
            chkVal.Append(m.TransAmt);
            chkVal.Append(m.UsrCustId);
            chkVal.Append(m.MaxTenderRate);
            chkVal.Append(m.BorrowerDetails);
            chkVal.Append(m.IsFreeze);
            chkVal.Append(m.FreezeOrdId);
            chkVal.Append(m.RetUrl);
            chkVal.Append(m.BgRetUrl);
            chkVal.Append(m.MerPriv);
            chkVal.Append(m.ReqExt);
            string chkv = chkVal.ToString();
            LogInfo.WriteLog(chkv);

            //私钥文件的位置(这里是放在了站点的根目录下)
            string merKeyFile = AppDomain.CurrentDomain.BaseDirectory + Utils.GetMerPr();
            //需要指定提交字符串的长度
            int           len        = Encoding.UTF8.GetBytes(chkv).Length;
            StringBuilder sbChkValue = new StringBuilder(256);
            //加签
            int ret = DllInterop.SignMsg(Utils.GetMerId(), merKeyFile, chkv, len, sbChkValue);
            m.ChkValue = sbChkValue.ToString();
            LogInfo.WriteLog("加签字符:" + ret.ToString() + "投标chkv字符:" + chkv);
            LogInfo.WriteLog("投标提交表单报文:" + FastJSON.toJOSN(m));
            if (ret == 0)
            {
                return(m);
            }
            return(null);
        }
Beispiel #2
0
        public ActionResult Index(RequestParam <RequestTender> reqst)
        {
            LoggerHelper.Info(JsonHelper.Entity2Json(reqst));
            ResultInfo <string> res = new ResultInfo <string>("99999");
            var usrId    = ConvertHelper.ParseValue(reqst.body.userId, 0);
            var targetId = ConvertHelper.ParseValue(reqst.body.targetId, 0);
            var bds      = string.Empty;

            B_borrowing_target b_borrowing_target = new B_borrowing_target();
            var            m_borrowing_target     = b_borrowing_target.GetModel(targetId);
            B_member_table b_member_table         = new B_member_table();
            var            m_member_table         = b_member_table.GetModel(usrId);


            if (m_borrowing_target == null || m_member_table == null)
            {
                res.code    = "1000000010";
                res.message = Settings.Instance.GetErrorMsg(res.code);
                return(View(res));
            }
            if (!string.IsNullOrWhiteSpace(reqst.body.bonusIds))
            {
                bds = reqst.body.bonusIds;
            }
            if (!string.IsNullOrWhiteSpace(reqst.body.addRateIds))
            {
                if (!string.IsNullOrWhiteSpace(bds))
                {
                    bds += ",";
                }
                bds = reqst.body.addRateIds;
            }
            var         investAmount = ConvertHelper.ParseValue(reqst.body.investAmount, 0M);
            BorrowLogic _logic       = new BorrowLogic();
            var         ent          = _logic.SelectBorrowDetail(targetId);

            if (usrId <= 0)
            {
                res.code    = "1000000015";
                res.message = Settings.Instance.GetErrorMsg(res.code);
                return(View(res));
            }
            if (targetId <= 0)
            {
                res.code    = "1000000014";
                res.message = Settings.Instance.GetErrorMsg(res.code);
                return(View(res));
            }
            if (investAmount < 100)
            {
                res.code    = "2000000000";
                res.message = Settings.Instance.GetErrorMsg(res.code);
                return(View(res));
            }
            if (m_borrowing_target.minimum > 0 && investAmount < m_borrowing_target.minimum)
            {
                res.code    = "2000000008";
                res.message = Settings.Instance.GetErrorMsg(res.code);
                return(View(res));
            }
            if (m_borrowing_target.maxmum > 0 && investAmount > m_borrowing_target.maxmum)
            {
                res.code    = "2000000009";
                res.message = Settings.Instance.GetErrorMsg(res.code);
                return(View(res));
            }

            if (reqst.body.typeId == 6)//新手标判定
            {
                if (!string.IsNullOrWhiteSpace(bds))
                {
                    res.code    = "2000000010";
                    res.message = Settings.Instance.GetErrorMsg(res.code);
                    return(View(res));
                }
                if (m_member_table.useridentity != 5)
                {
                    if (Convert.ToDateTime(m_member_table.Registration_time.ToString("yyyy-MM-dd")).AddDays(30) < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")))
                    {
                        res.code    = "2000000011";
                        res.message = Settings.Instance.GetErrorMsg(res.code);
                        return(View(res));
                    }
                    B_Bid_records b_Bid_records = new B_Bid_records();
                    int           investedCount = b_Bid_records.GetInvestCount(reqst.body.userId, reqst.body.targetId);
                    if (investedCount >= 3)
                    {
                        res.code    = "2000000012";
                        res.message = Settings.Instance.GetErrorMsg(res.code);
                        return(View(res));
                    }
                    if (ent.start_time != null && ent.start_time.Value < Convert.ToDateTime("2016-12-01 00:00:00"))
                    {
                        res.code    = "2999999999";
                        res.message = Settings.Instance.GetErrorMsg(res.code);
                        return(View(res));
                    }
                    if (ent.project_type_id != null && ent.project_type_id.Value != 6)
                    {
                        res.code    = "2999999999";
                        res.message = Settings.Instance.GetErrorMsg(res.code);
                        return(View(res));
                    }
                }
            }
            try
            {
                decimal        vocheramttemp = GetUseRewards(bds, usrId);
                B_member_table b             = new B_member_table();
                M_member_table user          = new M_member_table();
                user = b.GetModel(reqst.body.userId);
                InvestmentParameters mp = new InvestmentParameters
                {
                    Amount            = investAmount,
                    Circle            = ConvertHelper.ParseValue(ent.life_of_loan, 0),
                    CircleType        = ConvertHelper.ParseValue(ent.unit_day, 0),
                    NominalYearRate   = ConvertHelper.ParseValue(ent.annual_interest_rate, 0D),
                    OverheadsRate     = 0f,
                    RepaymentMode     = ConvertHelper.ParseValue(ent.payment_options, 0),
                    RewardRate        = 0f,
                    IsThirtyDayMonth  = false,
                    InvestDate        = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd")),
                    ReleaseDate       = DateTime.Parse(ent.release_date.ToString()).ToString("yyyy-MM-dd"),
                    Investmentenddate = DateTime.Parse(DateTime.Parse(ent.repayment_date.ToString()).ToString("yyyy-MM-dd")),
                    Payinterest       = ConvertHelper.ParseValue(ent.month_payment_date, 0),
                    InvestObject      = 1
                };
                //追加  加息券
                if (!string.IsNullOrWhiteSpace(bds))
                {
                    B_UserAct bUserAct     = new B_UserAct();
                    var       addRateModel = bUserAct.GetAddRateModel(bds);
                    if (addRateModel != null)// add rate of year
                    {
                        mp.NominalYearRate = mp.NominalYearRate + Convert.ToDouble(addRateModel.Amt.Value);
                    }
                }
                List <InvestmentReceiveRecordInfo> records = InvestCalculator.CalculateReceiveRecord(mp);
                StringBuilder sb = new StringBuilder("");
                if (records != null && records.Any())
                {
                    int i = 1;
                    foreach (var item in records)
                    {
                        sb.AppendFormat("{0},{1},{2},{3},{4},{5},{6},{7}|", i, item.interestvalue_date, item.NominalReceiveDate, item.Balance, item.Interest, item.Principal, item.TotalInstallments, item.TotalDays);
                        i = i + 1;
                    }
                }
                var     orderId      = Settings.Instance.OrderCode;
                var     frozenidNo   = Settings.Instance.OrderCode;
                decimal frozenAmount = 0.00M;

                var xf = ((records != null && records.Any()) ? records.Sum(t => t.Interest) : 0M);
                //LoggerHelper.Error("利息:" + xf + " ------- " + JsonHelper.Entity2Json(records));
                string invitationCode = string.Empty;
                using (InvitationLogic invitationLogic = new InvitationLogic())
                {
                    var invitationModel = invitationLogic.GetUserInvited(usrId);
                    if (invitationModel != null)
                    {
                        invitationCode = invitationModel.invcode;
                    }
                }
                var resVal = _logic.SubmitTender(usrId, targetId, investAmount, bds, invitationCode, orderId
                                                 , xf, frozenidNo
                                                 , investAmount - frozenAmount
                                                 , ((records != null && records.Any()) ? records.Count : 0), sb.ToString());
                if (resVal < 200)
                {
                    switch (resVal)
                    {
                    case -100:
                    {
                        res.code = "2000000001";
                    }
                    break;

                    case -101:
                    {
                        res.code = "2000000008";
                    }
                    break;

                    case -200:
                    {
                        res.code = "2000000002";
                    }
                    break;

                    case -300:
                    {
                        res.code = "2000000003";
                    }
                    break;

                    case -400:
                    {
                        res.code = "2000000004";
                    }
                    break;

                    case -500:
                    {
                        res.code = "2000000007";
                    }
                    break;

                    case -600:
                    {
                        res.code = "2000000006";
                    }
                    break;
                    }
                }
                else
                {
                    LoggerHelper.Error("SubmitTender!!!!!!!!!!!!!!!投资开始");
                    LoggerHelper.Info("投资开始");
                    #region 投资成功
                    M_InitiativeTender Mt = new M_InitiativeTender();
                    Mt.Version       = "20";
                    Mt.CmdId         = "InitiativeTender";
                    Mt.MerCustId     = Settings.Instance.MerCustId;
                    Mt.OrdId         = orderId;
                    Mt.OrdDate       = mp.InvestDate.ToString("yyyyMMdd");
                    Mt.TransAmt      = investAmount.ToString("0.00");
                    Mt.UsrCustId     = user.UsrCustId;
                    Mt.MaxTenderRate = "0.20";

                    TenderJosnPro mtp = new TenderJosnPro();
                    mtp.BorrowerCustId = b.GetModel(ConvertHelper.ParseValue(ent.borrower_registerid, 0)).UsrCustId;
                    mtp.BorrowerAmt    = investAmount.ToString("0.00");

                    // mtp.BorrowerRate = decimal.Parse( dt.Rows[0]["loan_management_fee"].ToString()).ToString("0.00");

                    mtp.BorrowerRate = "1.00"; //风控范围

                    mtp.ProId = targetId.ToString();

                    Mt.BorrowerDetails = "[" + FastJSON.toJOSN(mtp) + "]";

                    #region 此处判断优惠类型

                    #endregion
                    Mt.IsFreeze = "Y";

                    Mt.FreezeOrdId = frozenidNo;

                    Mt.RetUrl = Settings.Instance.GetCallbackUrl("/MemberCenter/InvestSubmit/CallbackRetUrl");

                    Mt.BgRetUrl = Settings.Instance.GetCallbackUrl("/MemberCenter/InvestSubmit/CallbackBgRetUrl");

                    if (!string.IsNullOrWhiteSpace(reqst.body.bonusIds))
                    {
                        Mt.MerPriv = bds;
                        TenderAccPro ret = new TenderAccPro();
                        ret.AcctId    = ChuanglitouP2P.Common.Utils.GetMERDT();
                        ret.VocherAmt = vocheramttemp.ToString("0.00");
                        Mt.ReqExt     = "{" + "\"Vocher\":" + FastJSON.toJOSN(ret) + "}";
                    }
                    else
                    {
                        Mt.MerPriv = reqst.body.addRateIds;
                    }

                    //append device code to comment fields for make sure it be transfered back
                    string temp = Mt.MerPriv;
                    AppendDeviceFlag(reqst.header.appId.ToString(), ref temp);
                    Mt.MerPriv = temp;

                    LoggerHelper.Info("优惠券使用的id:" + bds);
                    StringBuilder chkVal = new StringBuilder();
                    chkVal.Append(Mt.Version);
                    chkVal.Append(Mt.CmdId);
                    chkVal.Append(Mt.MerCustId);
                    chkVal.Append(Mt.OrdId);
                    chkVal.Append(Mt.OrdDate);
                    chkVal.Append(Mt.TransAmt);
                    chkVal.Append(Mt.UsrCustId);
                    chkVal.Append(Mt.MaxTenderRate);
                    chkVal.Append(Mt.BorrowerDetails);
                    chkVal.Append(Mt.IsFreeze);
                    chkVal.Append(Mt.FreezeOrdId);
                    chkVal.Append(Mt.RetUrl);
                    chkVal.Append(Mt.BgRetUrl);
                    chkVal.Append(Mt.MerPriv);
                    chkVal.Append(Mt.ReqExt);

                    string chkv = chkVal.ToString();
                    LoggerHelper.Info("投资:" + chkv);
                    //私钥文件的位置(这里是放在了站点的根目录下)
                    string merKeyFile = AppDomain.CurrentDomain.BaseDirectory + Settings.Instance.MerPr;
                    //需要指定提交字符串的长度
                    int           len        = Encoding.UTF8.GetBytes(chkv).Length;
                    StringBuilder sbChkValue = new StringBuilder(256);
                    //加签
                    int str = DllInterop.SignMsg(Settings.Instance.MerId, merKeyFile, chkv, len, sbChkValue);

                    LoggerHelper.Info(str);

                    Mt.ChkValue = sbChkValue.ToString();
                    if (str == 0)
                    {
                        var strz = new StringBuilder();

                        strz.Append(" <form id=\"formauto\" name=\"formauto\"  action=\"" + Settings.Instance.ChinapnrUrl + "\" method=\"post\">");

                        strz.Append("<input id=\"Version\"  name=\"Version\"  type=\"hidden\"  value=\"" + Mt.Version + "\" />");

                        strz.Append("<input id=\"CmdId\"  name=\"CmdId\"    type=\"hidden\"  value=\"" + Mt.CmdId + "\" />");

                        strz.Append("<input id=\"MerCustId\" name=\"MerCustId\"   type=\"hidden\"  value=\"" + Mt.MerCustId + "\" />");

                        strz.Append("<input id=\"OrdId\" name=\"OrdId\" type=\"hidden\"  value=\"" + Mt.OrdId + "\" />");

                        strz.Append("<input id=\"OrdDate\" name=\"OrdDate\" type=\"hidden\"  value=\"" + Mt.OrdDate + "\" />");

                        strz.Append("<input id=\"TransAmt\" name=\"TransAmt\" type=\"hidden\"  value=\"" + Mt.TransAmt + "\" />");

                        strz.Append("<input id=\"UsrCustId\"  name=\"UsrCustId\" type=\"hidden\"  value=\"" + Mt.UsrCustId + "\" />");

                        strz.Append("<input id=\"MaxTenderRate\"   name=\"MaxTenderRate\" type=\"hidden\"  value=\"" + Mt.MaxTenderRate + "\" />");

                        strz.Append("<input id=\"BorrowerDetails\" name=\"BorrowerDetails\" type=\"hidden\"  value=" + Mt.BorrowerDetails + " />");

                        strz.Append("<input id=\"IsFreeze\" name=\"IsFreeze\" type=\"hidden\"  value=\"" + Mt.IsFreeze + "\" />");
                        strz.Append("<input id=\"FreezeOrdId\" name=\"FreezeOrdId\" type=\"hidden\"  value=\"" + Mt.FreezeOrdId + "\" />");
                        strz.Append("<input id=\"RetUrl\" name=\"RetUrl\" type=\"hidden\"  value=\"" + Mt.RetUrl + "\" />");
                        strz.Append("<input id=\"BgRetUrl\" name=\"BgRetUrl\" type=\"hidden\"  value=\"" + Mt.BgRetUrl + "\" />");
                        strz.Append("<input id=\"MerPriv\" name=\"MerPriv\" type=\"hidden\"  value=\"" + Mt.MerPriv + "\" />");
                        strz.Append("<input id=\"ReqExt\" name=\"ReqExt\" type=\"hidden\"  value=" + Mt.ReqExt + " >");
                        strz.Append("<input id=\"ChkValue\" name=\"ChkValue\" type=\"hidden\"  value=\"" + Mt.ChkValue + "\" />");
                        strz.Append(" </form>");
                        strz.Append("<script type=\"text/javascript\">document.getElementById('formauto').submit();</script>");

                        LoggerHelper.Info("投资表单:" + strz.ToString());
                        res.code = "1";
                        res.body = strz.ToString();
                    }
                    else
                    {
                        res.code = "5000000000";
                    }
                    #endregion
                }
                res.message = Settings.Instance.GetErrorMsg(res.code);
                return(View(res));
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(ex.ToString());
                LoggerHelper.Error(JsonHelper.Entity2Json(reqst));
                res.code    = "500";
                res.message = Settings.Instance.GetErrorMsg(res.code);
                return(View(res));
            }
        }