Example #1
0
        //拒绝
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            // ChkAdminLevel("users", DTEnums.ActionEnum.Delete.ToString()); //检查权限

            //删除关系记录
            //旅游团表的bookcount-1
            BLL.redpacket_guid bll = new BLL.redpacket_guid();
            for (int i = 0; i < rptList.Items.Count; i++)
            {
                int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value);
                CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId");
                if (cb.Checked)
                {
                    bll.Delete(id,this.redpacket_id);
                }
            }

            JscriptMsg("拒绝成功啦!", Utils.CombUrlTxt("apply.aspx", "group_id={0}&keywords={1}&property={2}&redpacket_id={3}&channel_id={4}",
            this.group_id.ToString(), this.keywords, this.property, this.redpacket_id.ToString(), this.channel_id.ToString()), "Success");
        }
        private void redpacket_used(HttpContext context)
        {
            string unique_code = DTRequest.GetQueryString("code");
            StringBuilder sb = new StringBuilder();
            if (string.IsNullOrEmpty(unique_code) || unique_code == "unsafe string")
            {
                sb.Append("  <dl><dt></dt><dd>此消费码不存在,验证无效!</dd></dl>");
                context.Response.Write(sb.ToString());
                return;
            }
            BLL.redpacket bll_redpacket = new BLL.redpacket();
            int count = 0;
            DataSet ds_redpacket = bll_redpacket.GetRedPacketList_WebService(1, 1, "unique_code='" + unique_code + "'", "status desc", out count);
            if (ds_redpacket == null || count == 0)
            {
                sb.Append("  <dl><dt></dt><dd>此消费码不存在,验证无效!</dd></dl>");
                context.Response.Write(sb.ToString());
                return;
            }
            //验证红包状态
            if (int.Parse(ds_redpacket.Tables[0].Rows[0]["status"].ToString()) != 1)
            {
                sb.Append("  <dl><dt></dt><dd>此消费码状态不符合,请检查消费码状态!</dd></dl>");
                context.Response.Write(sb.ToString());
                return;
            }
            //验证是否过期
            string start_date =ds_redpacket.Tables[0].Rows[0]["start_date"].ToString();
            string end_date=ds_redpacket.Tables[0].Rows[0]["end_date"].ToString();
            if (DateTime.Now < DateTime.Parse(start_date) || DateTime.Now > DateTime.Parse(end_date))
            {
                sb.Append("  <dl><dt></dt><dd>不在红包有效期内,请检查红包有限期!</dd></dl>");
                context.Response.Write(sb.ToString());
                return;
            }

            int guid_id = 0;
            int redpacket_id = 0;
            int.TryParse(ds_redpacket.Tables[0].Rows[0]["guid_id"].ToString(), out  guid_id);
            int.TryParse(ds_redpacket.Tables[0].Rows[0]["redpacket_id"].ToString(), out  redpacket_id);
            if (guid_id == 0 || redpacket_id == 0)
            {
                sb.Append("  <dl><dt></dt><dd>数据异常,请联系管理员!</dd></dl>");
                context.Response.Write(sb.ToString());
                return;
            }

            BLL.redpacket_guid bll_redpacket_guid = new BLL.redpacket_guid();
            if (bll_redpacket_guid.UpdateField(guid_id, redpacket_id, "status=2"))
            {
                sb.Append("  <dl><dt></dt><dd>消费成功!</dd></dl>");
            }
            else
            {
                sb.Append("  <dl><dt></dt><dd>消费失败!</dd></dl>");
            }
            context.Response.Write(sb.ToString());
            return;
        }
        public void GetRedPacketShare(int userId, int redpacketId, string version, string equType, string equName)
        {
            //redpacketId 红包ID   userId导游ID
            string json = string.Empty;
            BLL.redpacket_guid bll_redpacket_guid = new BLL.redpacket_guid();
            try
            {
                if (bll_redpacket_guid.UpdateField(userId, redpacketId, "status=1"))
                { json = "{\"status\":\"true\"}"; }
                else
                { json = "{\"status\":\"false\"}"; }

            }
            catch (Exception ex)
            {
                json = "{\"status\":\"false\",\"data\":\"" + ex.Message + "\"}";
            }
            WriteWebServiceLog(version, equType, equName, "GetRedPacketShare", "");
            Context.Response.Write(json);
            Context.Response.End();
        }
        public void GetRedPacketBuy(int userId, int redpacketId, string version, string equType, string equName)
        {
            //redpacketId 红包ID   userId导游ID
            string json = string.Empty;
            BLL.redpacket_guid bll_redpacket_guid = new BLL.redpacket_guid();
            try
            {
                string onlyCode = ""; //唯一码
                lock (this.SyncRoot)
                {
                    try
                    {
                        Random r = new Random();
                        string str = r.Next(100000, 999999).ToString();
                        int number = bll_redpacket.GetOnlyCodeNumber();
                        onlyCode = str + number.ToString();//.PadLeft(6, '0');

                    }
                    catch (Exception ex)
                    {
                        json = "{\"status\":\"false\",\"data\":\"" + ex.Message + "\"}";
                    }
                    if (bll_redpacket_guid.Exists(userId, redpacketId))
                    { json = "{\"status\":\"false\",\"data\":\"不可重复抢购!\"}"; }
                    else
                    {

                        Model.redpacket model_redpacket = bll_redpacket.GetRedPacketModel(redpacketId);

                        if (model_redpacket.total_count > model_redpacket.book_count)
                        {

                            //将抢购人数+1
                            //bll_redpacket.UpdateField(redpacketId, "book_count=" + (model_redpacket.book_count + 1));
                            //向关系表中加入一条报名记录
                            //groupGuideManager.SignUp(userId, travelId);
                            Model.redpacket_guid model_redpacket_guid = new Model.redpacket_guid();
                            //唯一码
                            model_redpacket_guid.unique_code = onlyCode;
                            model_redpacket_guid.redpacket_id = redpacketId;
                            model_redpacket_guid.guid_id = userId;
                            model_redpacket_guid.status = 0;//0为抢购成功!
                            model_redpacket_guid.apply_time = DateTime.Now;

                            int count = bll_redpacket_guid.Add(model_redpacket_guid);
                            if (count > 0) { json = "{\"status\":\"true\",\"data\":\"\"}"; }
                            else { json = "{\"status\":\"false\",\"data\":\"抢购失败!\"}"; }
                        }
                        else
                        {
                            //更新状态为结束
                            bll_redpacket.UpdateField(redpacketId, "status=0");
                            json = "{\"status\":\"false\",\"data\":\"该抢购报名名额已满\"}";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                json = "{\"status\":\"false\",\"data\":\"" + ex.Message + "\"}";
            }
            WriteWebServiceLog(version, equType, equName, "GetRedPacketBuy", "");
            Context.Response.Write(json);
            Context.Response.End();
        }