/// <summary> /// 获取实体 /// </summary> public Model.redpacket_guid GetRedPacketGuidModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 * from dt_redpacket_guid "); strSql.Append(" where id=@id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4)}; parameters[0].Value = id; Model.redpacket_guid model = new Model.redpacket_guid(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { #region DATA if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["guid_id"] != null && ds.Tables[0].Rows[0]["guid_id"].ToString() != "") { model.guid_id = int.Parse(ds.Tables[0].Rows[0]["guid_id"].ToString()); } if (ds.Tables[0].Rows[0]["redpacket_id"] != null && ds.Tables[0].Rows[0]["redpacket_id"].ToString() != "") { model.redpacket_id = int.Parse(ds.Tables[0].Rows[0]["redpacket_id"].ToString()); } if (ds.Tables[0].Rows[0]["status"] != null && ds.Tables[0].Rows[0]["status"].ToString() != "") { model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString()); } if (ds.Tables[0].Rows[0]["unique_code"] != null && ds.Tables[0].Rows[0]["unique_code"].ToString() != "") { model.unique_code = ds.Tables[0].Rows[0]["unique_code"].ToString(); } if (ds.Tables[0].Rows[0]["apply_time"] != null && ds.Tables[0].Rows[0]["apply_time"].ToString() != "") { model.apply_time = DateTime.Parse(ds.Tables[0].Rows[0]["apply_time"].ToString()); } if (ds.Tables[0].Rows[0]["remark1"] != null && ds.Tables[0].Rows[0]["remark1"].ToString() != "") { model.remark1 = ds.Tables[0].Rows[0]["remark1"].ToString(); } if (ds.Tables[0].Rows[0]["remark2"] != null && ds.Tables[0].Rows[0]["remark2"].ToString() != "") { model.remark2 = int.Parse(ds.Tables[0].Rows[0]["remark2"].ToString()); } #endregion return model; } else { return null; } }
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(); }