예제 #1
0
        /// <summary>
        /// 判断二维码是否有效
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string CheckSn(string sn, string openid)
        {
            //验证二维码是否有效
            var       code = RedPack.Confusion(sn); //解码
            string    sql  = string.Format(@"SELECT a.State,b.IsPreSend,b.IsRealSend ,b.OpenId FROM Hfh_RedPackQrCode a 
                                        LEFT   JOIN  Hfh_RedPackSendRecord b ON b.QrcId = a.QrcId
                                        WHERE a.state = 1 and  a.Code = '{0}'", code);
            DataTable dt   = SqlHelper2.ExecuteDataTable(sql);

            if (dt.Rows.Count == 1)
            {
                //var state = Convert.ToInt16(dt.Rows[0]["State"]).ToString();
                var IsPreSend  = dt.Rows[0]["IsPreSend"] == null ? "0" : dt.Rows[0]["IsPreSend"].ToString();
                var IsRealSend = dt.Rows[0]["IsRealSend"] == null ? "0" : dt.Rows[0]["IsRealSend"].ToString();
                var sendopenid = dt.Rows[0]["OpenId"] == null ? "" : dt.Rows[0]["OpenId"].ToString();
                if (IsRealSend == "1")
                {
                    return("二维码已失效:红包已成功发送");
                }
                else
                {
                    if (IsPreSend == "1")
                    {
                        if (sendopenid == openid)
                        {
                            return("请关注公众号领取红包");
                        }
                        else
                        {
                            return("二维码已失效:红包已被他人领取");
                        }
                    }
                    else
                    {
                        return("succ");
                    }
                }
            }
            else
            {
                return("fail");
            }
        }