/// <summary> /// 是否激活红包 /// </summary> /// <param name="companyID">公司ID</param> /// <returns></returns> public string IsActive(string companyID) { HF.Cloud.BLL.Common.Logger.Error("IsActive获取的参数companyID:" + companyID); string resultStr = ""; //查看当前公司有没有红包记录 long companyIdLong = 0;//公司ID if (long.TryParse(companyID, out companyIdLong) && !string.IsNullOrEmpty(companyID)) { //查看当前公司是否有红包记录 T_HongBaoEL honBaoEL = new T_HongBaoEL(); honBaoEL.CompanyID = companyIdLong; DataTable dt_HongBao = honBaoEL.ExecDT(33); if (dt_HongBao != null && dt_HongBao.Rows.Count > 0) { resultStr = "have"; } else { resultStr = "no"; } } else { resultStr = "error"; } return(resultStr); }
/// <summary> /// 红包开关 /// </summary> /// <param name="companyId">公司ID</param> /// <returns></returns> public string OpenRedBag(string companyID) { HF.Cloud.BLL.Common.Logger.Error("OpenRedBag 获取到的参数CompanyID:" + companyID); //查看时间,过期则不可打开 //if(DateTime.Now.ToString()<"2018-02-16 23:12:12:123") //{ //} string resultStr = ""; long companyIdLong = 0;//公司ID if (long.TryParse(companyID, out companyIdLong)) { //1通过公司id在用户表中看当前公司够5个人不够 SB_UserEL userEL = new SB_UserEL(); userEL.CompanyID = companyIdLong; DataTable dt_User = userEL.ExecDT(44); //1.1够5个人则开始在红包表里面添加红包数据 if (dt_User != null && dt_User.Rows.Count >= 5) { //2 查看已经发了多少钱,发过的总数大于1000停止发送 DataTable dt_HongBalAllVa = DbHelperSQL.Query("select sum(HongBaoValue) as AllValue from T_HongBao where Valid=1").Tables[0]; string allValueStr = dt_HongBalAllVa.Rows[0][0].ToString(); //2.1已经发送的总金额小于900的话继续发 if (string.IsNullOrEmpty(allValueStr) || double.Parse(allValueStr) < 850) { T_HongBaoEL hongBaoEl = new T_HongBaoEL(); //查看红包表是否已经存在记录,存在则不添加红包记录 hongBaoEl.CompanyID = companyIdLong; DataTable dt_HongBao = hongBaoEl.ExecDT(33); if (dt_HongBao == null || dt_HongBao.Rows.Count < 1) { //3发红包表添加记录 //3.1生成公司红包金额10-100随机数,红包个数是金额的0.5-1倍 Random ran = new Random(); //3.1.1红包金额,取下不取上 int comAllValue = ran.Next(10, 100); //3.1.2人数 int comNumber = (int)Math.Floor(ran.Next(5, 10) * 0.1 * comAllValue); HF.Cloud.BLL.Common.Logger.Error("OpenRedBag方法红包总金额是:" + comAllValue + "---总人数:" + comNumber); //3.2通过总金额和人数获取评分后的红包值 List <Double> listHongV = HongBao.GetRedBagList(double.Parse(comAllValue.ToString()), comNumber, 1.00); //3.3通过获取到的红包值列表,给红包表添加记录 for (int i = 0; i < listHongV.Count; i++) { //ID,CompanyID,HongBaoValue,GetUserID,IsGet, //CreateTime,GiveOutTime,Valid //HF.Cloud.BLL.Common.Logger.Error("OpenRedBag方法获得的红包值listHongV是:" + listHongV[i]); hongBaoEl.CompanyID = companyIdLong; //hongBaoEl.HongBaoValue = decimal.Round((decimal)listHongV[i],2); hongBaoEl.HongBaoValue = decimal.Parse(listHongV[i].ToString()); hongBaoEl.IsGet = 1; hongBaoEl.CreateTime = DateTime.Now.ToString(); hongBaoEl.GiveOutTime = ""; hongBaoEl.Valid = 1; int ra; hongBaoEl.ExecNonQuery(1, out ra); } HF.Cloud.BLL.Common.Logger.Error("OpenRedBag方法生成的红包个数:" + listHongV.Count); resultStr = "success"; } else //已经激活不能再次激活 { resultStr = "actived"; } } else //2.2红包奖金池已经用完额度 { resultStr = "empty"; } } else//1.2不够5个人则提示人数不够 { resultStr = "notenough"; } } else { resultStr = "error"; } HF.Cloud.BLL.Common.Logger.Error("OpenRedBag 结果:" + resultStr); return(resultStr); }
/// <summary> /// 领红包 /// </summary> /// <param name="session">用户sesison</param> /// <param name="companyID">发红包的公司ID</param> ///<param name="formID">用户提交submit表单的formID</param> /// <returns></returns> public string GetRedBag(string session, string companyID, string formID) { HF.Cloud.BLL.Common.Logger.Error("GetRedBag获取的参数session:" + session + "---companyID" + companyID + "---formID" + formID); string resultStr = ""; //查看当前公司有没有红包记录 long companyIdLong = 0;//公司ID if (long.TryParse(companyID, out companyIdLong) && !string.IsNullOrEmpty(companyID) && !string.IsNullOrEmpty(session)) { UserBLL userBLL = new UserBLL(); //通过session获取UserID // long userID = userBLL.GetUserIDBySession(session); T_HongBaoEL honBaoEL = new T_HongBaoEL(); honBaoEL.CompanyID = companyIdLong; //查看是否领取过当前公司的红包 honBaoEL.GetUserSession_True = session.Substring(22, 28);//只获取openid,只有openID是唯一的 DataTable dt_GetHongBao = honBaoEL.ExecDT(32); //如果领取过就返回领取的金额(不能再次领取) if (dt_GetHongBao != null && dt_GetHongBao.Rows.Count > 0) { resultStr = dt_GetHongBao.Rows[0]["HongBaoValue"].ToString(); } else//没有记录的话就领取红包 { //获取当前公司未领取的红包 DataTable dt_HongBao = honBaoEL.ExecDT(31); if (dt_HongBao != null && dt_HongBao.Rows.Count > 0) { //获取红包值 decimal hongBaoValueDecimal = (decimal)dt_HongBao.Rows[0]["HongBaoValue"]; decimal dt_decimal_100 = hongBaoValueDecimal * 100; int dt_decimal_int = Decimal.ToInt32(dt_decimal_100); int sHonBao = dt_decimal_int; HF.Cloud.BLL.Common.Logger.Error("GetRedBag获取的红包值hongBaoValueDecimal:" + hongBaoValueDecimal); //修改当前的红包记录的状态为已经领取 honBaoEL.ID = (long)dt_HongBao.Rows[0]["ID"]; honBaoEL.GetUserSession_True = session.Substring(22, 28);//只获取openid,只有openID是唯一的 honBaoEL.IsGet = 0; honBaoEL.GiveOutTime = DateTime.Now.ToString(); int ra; long exResult = honBaoEL.ExecNonQuery(21, out ra); if (ra > 0) { //从session中解析openid string str_openid = session.Substring(22, 28); //调用接口发红包 string sendResult = SendRedBag(formID, str_openid, hongBaoValueDecimal, companyID); if (sendResult == "success")//红包发送成功 { resultStr = hongBaoValueDecimal.ToString(); } else { resultStr = "error"; } } else { resultStr = "error"; } } else//红包已经领完了 { resultStr = "null"; } } } return(resultStr); }