Esempio n. 1
0
        /// <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);
        }