protected void rpGroupEvents_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { GroupPurchaseEvent groupEvent = e.Item.DataItem as GroupPurchaseEvent; if (groupEvent != null) { HtmlContainerControl liGroupItem = e.Item.Controls[1] as HtmlContainerControl; Label lblEventStatus = liGroupItem.FindControl("lblEventStatus") as Label; //判断当前团购活动状态,并标记页面颜色 switch (GroupPurchaseEvent.CheckGroupPurchaseEventStatus(groupEvent)) { case GroupEventStatus.EVENT_SUCCESS: liGroupItem.Attributes["class"] += " list-group-item-success"; lblEventStatus.Text = "团购成功"; break; case GroupEventStatus.EVENT_GOING: liGroupItem.Attributes["class"] += " list-group-item-info"; lblEventStatus.Text = "团购进行中"; break; case GroupEventStatus.EVENT_FAIL: liGroupItem.Attributes["class"] += " list-group-item-danger"; lblEventStatus.Text = "团购失败"; break; } } } }
protected void dlOrderDetail_ItemDataBound(object sender, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item) { OrderDetail od = e.Item.DataItem as OrderDetail; if (od != null && od.GroupPurchaseEvent != null) { HyperLink hlGroupPurchaseEventStatus = e.Item.FindControl("hlGroupPurchaseEventStatus") as HyperLink; hlGroupPurchaseEventStatus.NavigateUrl = Request.Url.AbsolutePath + "?GroupEventID=" + od.GroupPurchaseEvent.ID; hlGroupPurchaseEventStatus.ToolTip = "查看此团购活动的所有订单"; //查询此用户的当前订单项对应的团购活动状态,需要判断活动中已支付人数是否符合要求、此用户是否支付 switch (GroupPurchaseEvent.CheckGroupPurchaseEventStatus(od.GroupPurchaseEvent, od.ProductOrder.Purchaser)) { case GroupEventStatus.EVENT_SUCCESS: hlGroupPurchaseEventStatus.CssClass = "label label-success"; hlGroupPurchaseEventStatus.Text = "<i class=\"fa fa-group fa-fw\"></i>团购成功"; break; case GroupEventStatus.EVENT_GOING: hlGroupPurchaseEventStatus.CssClass = "label label-info"; hlGroupPurchaseEventStatus.Text = "<i class=\"fa fa-group fa-fw\"></i>团购进行中"; break; case GroupEventStatus.EVENT_FAIL: hlGroupPurchaseEventStatus.CssClass = "label label-danger"; hlGroupPurchaseEventStatus.Text = "<i class=\"fa fa-group fa-fw\"></i>团购失败"; break; } } } }
/// <summary> /// 根据OpenID查询用户参加的所有团购活动 /// </summary> /// <param name="conn"></param> /// <param name="openID"></param> /// <param name="isLoadGroupEventMember">是否加载团购活动成员</param> /// <returns></returns> public static List <GroupPurchaseEvent> FindGroupPurchaseEventByOpenID(SqlConnection conn, string openID, bool isLoadGroupEventMember) { List <GroupPurchaseEvent> groupEventList = new List <GroupPurchaseEvent>(); GroupPurchaseEvent groupEvent = null; try { using (SqlCommand cmdGroup = conn.CreateCommand()) { SqlParameter paramID = cmdGroup.CreateParameter(); paramID.ParameterName = "@GroupMember"; paramID.SqlDbType = System.Data.SqlDbType.NVarChar; paramID.SqlValue = openID; cmdGroup.Parameters.Add(paramID); cmdGroup.CommandText = "select * from GroupPurchaseEvent where Id in (select GroupEventID from GroupPurchaseEventMember where GroupMember = @GroupMember)"; using (SqlDataReader sdr = cmdGroup.ExecuteReader()) { while (sdr.Read()) { groupEvent = new GroupPurchaseEvent(); groupEvent.ID = int.Parse(sdr["Id"].ToString()); groupEvent.Organizer = WeChatUserDAO.FindUserByOpenID(conn, sdr["Organizer"].ToString(), false); groupEvent.LaunchDate = DateTime.Parse(sdr["LaunchDate"].ToString()); groupEvent.GroupPurchase = GroupPurchase.FindGroupPurchaseByID(conn, int.Parse(sdr["GroupID"].ToString()), false, false); groupEvent.IsNotify = bool.Parse(sdr["IsNotify"].ToString()); if (isLoadGroupEventMember) { groupEvent.GroupPurchaseEventMembers = groupEvent.FindGroupPurchaseEventMembers(conn); } else { groupEvent.GroupPurchaseEventMembers = null; } groupEventList.Add(groupEvent); } } } } catch (Exception ex) { Log.Error("根据OpenID查询用户参加的所有团购活动", ex.ToString()); throw ex; } return(groupEventList); }
/// <summary> /// 查询未通知用户的团购活动 /// </summary> /// <param name="conn"></param> /// <param name="isLoadGroupEventMember"></param> /// <returns></returns> public static List <GroupPurchaseEvent> FindGroupPurchaseEventForNotify(SqlConnection conn, bool isLoadGroupEventMember) { List <GroupPurchaseEvent> groupEventList = new List <GroupPurchaseEvent>(); GroupPurchaseEvent groupEvent; try { using (SqlCommand cmdGroup = conn.CreateCommand()) { cmdGroup.CommandText = "select * from GroupPurchaseEvent where IsNotify = 0"; using (SqlDataReader sdr = cmdGroup.ExecuteReader()) { while (sdr.Read()) { groupEvent = new GroupPurchaseEvent(); groupEvent.ID = int.Parse(sdr["Id"].ToString()); groupEvent.Organizer = WeChatUserDAO.FindUserByOpenID(conn, sdr["Organizer"].ToString(), false); groupEvent.LaunchDate = DateTime.Parse(sdr["LaunchDate"].ToString()); groupEvent.GroupPurchase = GroupPurchase.FindGroupPurchaseByID(conn, int.Parse(sdr["GroupID"].ToString()), false, false); groupEvent.IsNotify = bool.Parse(sdr["IsNotify"].ToString()); if (isLoadGroupEventMember) { groupEvent.GroupPurchaseEventMembers = groupEvent.FindGroupPurchaseEventMembers(conn); } else { groupEvent.GroupPurchaseEventMembers = null; } groupEventList.Add(groupEvent); } } } } catch (Exception ex) { Log.Error("查询所有团购活动", ex.ToString()); throw ex; } return(groupEventList); }
/// <summary> /// 根据ID查询指定的团购活动 /// </summary> /// <param name="id">团购活动ID</param> /// <param name="isLoadGroupEventMember">是否加载团购活动成员</param> /// <returns></returns> public static GroupPurchaseEvent FindGroupPurchaseEventByID(int id, bool isLoadGroupEventMember) { GroupPurchaseEvent groupEvent = null; try { using (SqlConnection conn = new SqlConnection(Config.ConnStr)) { conn.Open(); groupEvent = FindGroupPurchaseEventByID(conn, id, isLoadGroupEventMember); } } catch (Exception ex) { Log.Error("根据ID查询指定团购活动", ex.ToString()); throw ex; } return(groupEvent); }
/// <summary> /// 更新团购活动的通知状态 /// </summary> /// <param name="groupEvent"></param> public static void UpdateGroupPurchaseEventNotify(GroupPurchaseEvent groupEvent) { try { using (SqlConnection conn = new SqlConnection(Config.ConnStr)) { conn.Open(); using (SqlCommand cmdUpdateGroupEvent = conn.CreateCommand()) { SqlParameter paramID = cmdUpdateGroupEvent.CreateParameter(); paramID.ParameterName = "@ID"; paramID.SqlDbType = System.Data.SqlDbType.Int; paramID.SqlValue = groupEvent.ID; cmdUpdateGroupEvent.Parameters.Add(paramID); SqlParameter paramIsNotify = cmdUpdateGroupEvent.CreateParameter(); paramIsNotify.ParameterName = "@IsNotify"; paramIsNotify.SqlDbType = System.Data.SqlDbType.Bit; paramIsNotify.SqlValue = groupEvent.IsNotify; cmdUpdateGroupEvent.Parameters.Add(paramIsNotify); //更新团购活动表 cmdUpdateGroupEvent.CommandText = "Update GroupPurchaseEvent set IsNotify = @IsNotify where Id = @ID"; Log.Debug("更新团购活动表", cmdUpdateGroupEvent.CommandText); if (cmdUpdateGroupEvent.ExecuteNonQuery() != 1) { throw new Exception("更新团购活动表"); } } } } catch (Exception ex) { Log.Error("GroupPurchaseEvent:UpdateGroupPurchaseEventNotify", ex.ToString()); throw ex; } }
protected void Page_Load(object sender, EventArgs e) { WeChatUser wxUser = Session["WxUser"] as WeChatUser; try { if (!string.IsNullOrEmpty(Request.QueryString["EventID"])) { int eventID; if (int.TryParse(Request.QueryString["EventID"], out eventID)) { GroupPurchaseEvent groupEvent; groupEvent = GroupPurchaseEvent.FindGroupPurchaseEventByID(eventID); if (groupEvent != null) { //显示团购活动对应的团购信息 this.lblGroupName.Text = groupEvent.GroupPurchase.Name; this.lblGroupDesc.Text = groupEvent.GroupPurchase.Description; FruitImg mainImg = groupEvent.GroupPurchase.Product.FruitImgList.Find(img => img.MainImg); if (mainImg != default(FruitImg)) { this.imgProdImg.ImageUrl = "images/" + mainImg.ImgName; } else { this.imgProdImg.ImageUrl = "images/" + Config.DefaultImg; } this.lblRequiredNumber.Text = groupEvent.GroupPurchase.RequiredNumber.ToString(); this.lblProdPrice.Text = groupEvent.GroupPurchase.Product.FruitPrice.ToString(); this.lblProdPriceUnit.Text = groupEvent.GroupPurchase.Product.FruitUnit; this.lblGroupPrice.Text = groupEvent.GroupPurchase.GroupPrice.ToString(); this.lblGroupPriceUnit.Text = groupEvent.GroupPurchase.Product.FruitUnit; this.lblEventStardDate.Text = groupEvent.GroupPurchase.StartDate.ToString(); this.lblEventEndDate.Text = groupEvent.GroupPurchase.EndDate.ToString(); //查询此团购活动中已支付的成员 List <GroupPurchaseEventMember> paidEventMembers = groupEvent.GroupPurchaseEventMembers.FindAll(member => member.IsPaid); //此团购活动还缺的人数 int leftNumber; if (groupEvent.GroupPurchaseEventMembers != null) { if (groupEvent.GroupPurchase.RequiredNumber > paidEventMembers.Count) { leftNumber = groupEvent.GroupPurchase.RequiredNumber - paidEventMembers.Count; } else { leftNumber = 0; } } else { leftNumber = groupEvent.GroupPurchase.RequiredNumber; } if (leftNumber > 0) { this.lblLeftNumber.Text = leftNumber.ToString(); } else { this.divLeftNumber.Visible = false; } //只显示已支付成功的团购活动成员头像和列表 if (paidEventMembers != null) { string strEventMemberList = string.Empty, strEventMemberHeadImg = string.Empty; //团购活动的成员 paidEventMembers.ForEach(member => { strEventMemberHeadImg += string.Format("<img src='{0}'/>", member.GroupMember.HeadImgUrl); strEventMemberList += string.Format("<div class='col-xs-12 user-portrait {3}'><img src='{0}'/> 【{1}】 {2} {4}{5}</div>", member.GroupMember.HeadImgUrl, member.GroupMember.NickName, member.JoinDate.ToString(), !member.IsPaid ? "text-muted" : string.Empty, (member.GroupMember.OpenID == member.GroupPurchaseEvent.Organizer.OpenID) ? "开团" : "参团", !member.IsPaid ? "(未支付)" : string.Empty); }); //尚缺的团购活动成员头像 for (int i = 0; i < leftNumber; i++) { strEventMemberHeadImg += "<span class='empty-user-portrait'>?</span>"; if ((groupEvent.GroupPurchaseEventMembers.Count + i + 1) % 8 == 0) { strEventMemberHeadImg += "<br/>"; } } this.divGroupEventMemberHeadImg.InnerHtml = strEventMemberHeadImg; this.divGroupEventMember.InnerHtml = strEventMemberList; } DateTime nowTime = DateTime.Now; if (nowTime >= groupEvent.GroupPurchase.StartDate && nowTime <= groupEvent.GroupPurchase.EndDate) { //如果已支付成员数未达到要求人数,则允许新用户加入团购活动,否则不允许加入 if (paidEventMembers.Count < groupEvent.GroupPurchase.RequiredNumber) { this.divShareGroupEvent.Visible = true; this.divJoinGroupEvent.Visible = true; } else { this.divShareGroupEvent.Visible = false; this.divJoinGroupEvent.Visible = false; this.divCountDown.InnerHtml = "团购已经结束,欢迎下次参加!"; } } else { this.divShareGroupEvent.Visible = false; this.divJoinGroupEvent.Visible = false; if (nowTime < groupEvent.GroupPurchase.StartDate) { this.divCountDown.InnerHtml = "团购还未开始,敬请期待!"; } else { this.divCountDown.InnerHtml = "团购已经结束,欢迎下次参加!"; } } //把团购活动对象序列化为JSON对象,格式化其中的日期属性 JsonConvert.DefaultSettings = new Func <JsonSerializerSettings>(() => { JsonSerializerSettings jSetting = new JsonSerializerSettings(); jSetting.DateFormatHandling = DateFormatHandling.MicrosoftDateFormat; jSetting.DateFormatString = "yyyy-MM-dd HH:mm:ss"; jSetting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; return(jSetting); }); string strGroupEvent = JsonConvert.SerializeObject(groupEvent); //设置团购商品信息,用于添加入购物车 ScriptManager.RegisterStartupScript(Page, this.GetType(), "jsGroupEvent", string.Format("var groupEvent={0};", strGroupEvent), true); } else { throw new Exception("不能找到ID对应的团购活动"); } } else { throw new Exception("团购活动ID错误"); } } else { throw new Exception("请指定团购ID"); } } catch (Exception ex) { this.lblMsg.Text = ex.Message; this.lblMsg.Visible = true; this.divContainer.Visible = false; } }
/// <summary> /// 检查指定团购活动的状态 /// 1,成功:团购活动在有效期内达到规定人数,且活动相关订单都支付成功 /// 2,进行中:团购活动在有效期内,已支付的成员数尚未达到规定人数 /// 3,失败:团购活动超过有效期,已支付的成员数尚未达到规定人数 /// </summary> /// <param name="groupEvent">团购活动</param> /// <param name="wxUser">可选,当指定团购活动中的用户时,要进一步判断此用户是否支付成功,其支付顺序是否在要求人数内,再决定对此用户来说团购活动是否成功</param> /// <returns></returns> public static GroupEventStatus CheckGroupPurchaseEventStatus(GroupPurchaseEvent groupEvent, WeChatUser wxUser = null) { GroupEventStatus eventStatus; DateTime nowTime = DateTime.Now; if (groupEvent != null) { if (groupEvent.LaunchDate >= groupEvent.GroupPurchase.StartDate && groupEvent.LaunchDate <= groupEvent.GroupPurchase.EndDate) { if (groupEvent.GroupPurchaseEventMembers != null && groupEvent.GroupPurchaseEventMembers.Count >= groupEvent.GroupPurchase.RequiredNumber) { //已支付的团购成员 List <GroupPurchaseEventMember> membersPaid = groupEvent.GroupPurchaseEventMembers.FindAll(member => member.IsPaid); //如果已支付的成员数达到团购要求的成员数 if (membersPaid.Count >= groupEvent.GroupPurchase.RequiredNumber) { //如果没有指定用户,则对于管理员来说,此团购活动成功 if (wxUser == null) { eventStatus = GroupEventStatus.EVENT_SUCCESS; } else { //如果指定的用户支付成功 if (membersPaid.Exists(member => member.GroupMember.OpenID == wxUser.OpenID)) { //再判断此用户是第几个支付成功的,按先后顺序,如果此用户在要求人数以内支付成功,则此团购活动成功,否则团购活动失败 int theMemberPaidIndex = membersPaid.FindIndex(member => member.GroupMember.OpenID == wxUser.OpenID); if (theMemberPaidIndex + 1 <= groupEvent.GroupPurchase.RequiredNumber) { eventStatus = GroupEventStatus.EVENT_SUCCESS; } else { //如果指定的用户虽然支付成功,但按先后顺序,已超过了要求人数,则对于此用户来说,此团购活动失败 eventStatus = GroupEventStatus.EVENT_FAIL; } } else { //如果指定的用户未支付成功,由于此团购已支付人数已达到要求,则对于此用户来说,此团购活动失败 eventStatus = GroupEventStatus.EVENT_FAIL; } } } else { //如果已支付的成员数未达到要求人数,则根据当前时间是否在活动有效期内,决定团购是否进行中或失败 if (nowTime >= groupEvent.GroupPurchase.StartDate && nowTime <= groupEvent.GroupPurchase.EndDate) { eventStatus = GroupEventStatus.EVENT_GOING; } else { eventStatus = GroupEventStatus.EVENT_FAIL; } } } else { if (nowTime >= groupEvent.GroupPurchase.StartDate && nowTime <= groupEvent.GroupPurchase.EndDate) { eventStatus = GroupEventStatus.EVENT_GOING; } else { eventStatus = GroupEventStatus.EVENT_FAIL; } } } else { eventStatus = GroupEventStatus.EVENT_FAIL; } } else { throw new Exception("团购活动对象为NULL"); } return(eventStatus); }
/// <summary> /// 增加团购活动 /// </summary> /// <param name="groupEvent">团购活动对象</param> /// <returns></returns> public static GroupPurchaseEvent AddGroupPurchaseEvent(GroupPurchaseEvent groupEvent) { try { using (SqlConnection conn = new SqlConnection(Config.ConnStr)) { conn.Open(); SqlTransaction trans = conn.BeginTransaction(); try { using (SqlCommand cmdAddGroupEvent = conn.CreateCommand()) { cmdAddGroupEvent.Transaction = trans; SqlParameter paramGroupID = cmdAddGroupEvent.CreateParameter(); paramGroupID.ParameterName = "@GroupID"; paramGroupID.SqlDbType = System.Data.SqlDbType.Int; paramGroupID.SqlValue = groupEvent.GroupPurchase.ID; cmdAddGroupEvent.Parameters.Add(paramGroupID); SqlParameter paramOrganizer = cmdAddGroupEvent.CreateParameter(); paramOrganizer.ParameterName = "@Organizer"; paramOrganizer.SqlDbType = System.Data.SqlDbType.NVarChar; paramOrganizer.SqlValue = groupEvent.Organizer; cmdAddGroupEvent.Parameters.Add(paramOrganizer); SqlParameter paramLaunchDate = cmdAddGroupEvent.CreateParameter(); paramLaunchDate.ParameterName = "@LaunchDate"; paramLaunchDate.SqlDbType = System.Data.SqlDbType.DateTime; paramLaunchDate.SqlValue = groupEvent.LaunchDate; cmdAddGroupEvent.Parameters.Add(paramLaunchDate); SqlParameter paramIsNotify = cmdAddGroupEvent.CreateParameter(); paramIsNotify.ParameterName = "@IsNotify"; paramIsNotify.SqlDbType = System.Data.SqlDbType.Bit; paramIsNotify.SqlValue = groupEvent.LaunchDate; cmdAddGroupEvent.Parameters.Add(paramIsNotify); foreach (SqlParameter param in cmdAddGroupEvent.Parameters) { if (param.Value == null) { param.Value = DBNull.Value; } } //插入订单表 cmdAddGroupEvent.CommandText = "INSERT INTO [dbo].[GroupPurchaseEvent] ([GroupID], [Organizer], [LaunchDate], [IsNotify]) VALUES (@GroupID,@Organizer,@LaunchDate,@IsNotify);select SCOPE_IDENTITY() as 'NewGroupEventID'"; Log.Debug("插入团购活动表", cmdAddGroupEvent.CommandText); var newGroupEventID = cmdAddGroupEvent.ExecuteScalar(); //新增的订单ID if (newGroupEventID != DBNull.Value) { groupEvent.ID = int.Parse(newGroupEventID.ToString()); } else { throw new Exception("插入团购活动错误"); } } using (SqlCommand cmdAddGroupEventMember = conn.CreateCommand()) { cmdAddGroupEventMember.Transaction = trans; SqlParameter paramGroupEventID = cmdAddGroupEventMember.CreateParameter(); paramGroupEventID.ParameterName = "@GroupEventID"; paramGroupEventID.SqlDbType = System.Data.SqlDbType.Int; paramGroupEventID.SqlValue = groupEvent.ID; cmdAddGroupEventMember.Parameters.Add(paramGroupEventID); SqlParameter paramGroupMember = cmdAddGroupEventMember.CreateParameter(); paramGroupMember.ParameterName = "@GroupMember"; paramGroupMember.SqlDbType = System.Data.SqlDbType.NVarChar; cmdAddGroupEventMember.Parameters.Add(paramGroupMember); SqlParameter paramJoinDate = cmdAddGroupEventMember.CreateParameter(); paramJoinDate.ParameterName = "@JoinDate"; paramJoinDate.SqlDbType = System.Data.SqlDbType.DateTime; cmdAddGroupEventMember.Parameters.Add(paramJoinDate); groupEvent.GroupPurchaseEventMembers.ForEach(member => { paramGroupMember.SqlValue = member.GroupMember.OpenID; paramJoinDate.SqlValue = member.JoinDate; //插入团购活动成员表 cmdAddGroupEventMember.CommandText = "INSERT INTO [dbo].[GroupPurchaseEventMember] ([GroupEventID], [GroupMember], [JoinDate]) VALUES (@GroupEventID,@GroupMember,@JoinDate);select SCOPE_IDENTITY() as 'NewGroupEventMemberID'"; var newGroupEventMemberID = cmdAddGroupEventMember.ExecuteScalar(); //新增的订单详情ID if (newGroupEventMemberID != DBNull.Value) { member.ID = int.Parse(newGroupEventMemberID.ToString()); } else { throw new Exception("插入团购活动成员表错误"); } }); } trans.Commit(); } catch (Exception ex) { trans.Rollback(); throw ex; } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } } } catch (Exception ex) { Log.Error("GroupPurchaseEvent:AddGroupPurchaseEvent", ex.ToString()); throw ex; } return(groupEvent); }
/// <summary> /// 团购状态变动事件处理函数,通知管理员和所有团购活动成员 /// </summary> /// <param name="sender"></param> /// <param name="gpe"></param> /// <returns></returns> public static void GroupPurchaseEventNotify(object sender, GroupPurchaseEvent.GroupPurchaseEventEventArgs gpe) { if (sender == null || gpe == null) { throw new ArgumentNullException("sender或事件参数对象不能为null"); } JsonData jRet; try { GroupPurchaseEvent groupEvent = sender as GroupPurchaseEvent; List <string> adminReceivers, userReceivers; JsonData jTmplMsg = new JsonData(), jTmplMsgData = new JsonData(), jTmplMsgDataValue; //给管理员发送模板消息 jTmplMsg["touser"] = string.Empty; jTmplMsg["url"] = @"http://mahui.me/admin/ManageGroupPurchase.aspx"; jTmplMsg["topcolor"] = MSG_HEAD_COLOR; //从管理员角度看此团购活动是否成功,即已支付人数是否满足要求 switch (groupEvent.GroupEventStatus) { case GroupEventStatus.EVENT_SUCCESS: jTmplMsg["template_id"] = TMPL_GROUP_PURCHASE_EVENT_SUCCESS; jTmplMsgDataValue = new JsonData(); jTmplMsgDataValue["value"] = string.Format("团购活动“{0}#{1}”已成功,请尽快发货", groupEvent.GroupPurchase.Name, groupEvent.ID); jTmplMsgDataValue["color"] = MSG_BODY_COLOR; jTmplMsgData["first"] = jTmplMsgDataValue; jTmplMsgDataValue = new JsonData(); jTmplMsgDataValue["value"] = groupEvent.GroupPurchase.Name; jTmplMsgDataValue["color"] = MSG_BODY_COLOR; jTmplMsgData["keyword1"] = jTmplMsgDataValue; jTmplMsgDataValue = new JsonData(); jTmplMsgDataValue["value"] = string.Format("团购价:{0}元", groupEvent.GroupPurchase.GroupPrice.ToString("C")); jTmplMsgDataValue["color"] = MSG_HEAD_COLOR; jTmplMsgData["keyword2"] = jTmplMsgDataValue; jTmplMsgDataValue = new JsonData(); jTmplMsgDataValue["value"] = string.Format("团购有效期:{0}~{1}", groupEvent.GroupPurchase.StartDate, groupEvent.GroupPurchase.EndDate); jTmplMsgDataValue["color"] = MSG_BODY_COLOR; jTmplMsgData["keyword3"] = jTmplMsgDataValue; break; case GroupEventStatus.EVENT_FAIL: jTmplMsg["template_id"] = TMPL_GROUP_PURCHASE_EVENT_FAIL; jTmplMsgDataValue = new JsonData(); jTmplMsgDataValue["value"] = string.Format("团购活动“{0}#{1}”已失效,请尽快退款", groupEvent.GroupPurchase.Name, groupEvent.ID); jTmplMsgDataValue["color"] = MSG_BODY_COLOR; jTmplMsgData["first"] = jTmplMsgDataValue; jTmplMsgDataValue = new JsonData(); jTmplMsgDataValue["value"] = string.Format("团购价:{0}元", groupEvent.GroupPurchase.GroupPrice.ToString("C")); jTmplMsgDataValue["color"] = MSG_HEAD_COLOR; jTmplMsgData["keyword1"] = jTmplMsgDataValue; jTmplMsgDataValue = new JsonData(); jTmplMsgDataValue["value"] = groupEvent.GroupPurchase.Name; jTmplMsgDataValue["color"] = MSG_BODY_COLOR; jTmplMsgData["keyword2"] = jTmplMsgDataValue; jTmplMsgDataValue = new JsonData(); jTmplMsgDataValue["value"] = string.Format("团购有效期:{0}~{1}", groupEvent.GroupPurchase.StartDate, groupEvent.GroupPurchase.EndDate); jTmplMsgDataValue["color"] = MSG_BODY_COLOR; jTmplMsgData["keyword3"] = jTmplMsgDataValue; break; } jTmplMsgDataValue = new JsonData(); jTmplMsgDataValue["value"] = ""; jTmplMsgDataValue["color"] = MSG_BODY_COLOR; jTmplMsgData["remark"] = jTmplMsgDataValue; jTmplMsg["data"] = jTmplMsgData; adminReceivers = new List <string>(Config.WxTmplMsgReceiver.ToArray()); jRet = SendTmplMsg(adminReceivers, jTmplMsg); //查询此团购活动中的所有订单,并根据每个订单是否支付,来确定此用户的团购活动状态 List <ProductOrder> poList = groupEvent.FindOrderByGroupEventID(); poList.ForEach(po => { jTmplMsg["touser"] = string.Empty; jTmplMsg["url"] = string.Format("http://mahui.me/GroupPurchaseEvent.aspx?EventID={0}", groupEvent.ID); jTmplMsg["topcolor"] = MSG_HEAD_COLOR; //从每个团购活动成员角度看活动状态,即已支付人数是否符合要求,此成员本人是否支付。根据每个成员的团购活动状态,发送不同的微信模板消息 switch (GroupPurchaseEvent.CheckGroupPurchaseEventStatus(groupEvent, po.Purchaser)) { case GroupEventStatus.EVENT_SUCCESS: jTmplMsg["template_id"] = TMPL_GROUP_PURCHASE_EVENT_SUCCESS; jTmplMsgDataValue = new JsonData(); jTmplMsgDataValue["value"] = string.Format("您的拼团“{0}#{1}”已成功,请注意查收发货消息。", groupEvent.GroupPurchase.Name, groupEvent.ID); jTmplMsgDataValue["color"] = MSG_BODY_COLOR; jTmplMsgData["first"] = jTmplMsgDataValue; jTmplMsgDataValue = new JsonData(); jTmplMsgDataValue["value"] = po.OrderDetails; jTmplMsgDataValue["color"] = MSG_BODY_COLOR; jTmplMsgData["keyword1"] = jTmplMsgDataValue; jTmplMsgDataValue = new JsonData(); jTmplMsgDataValue["value"] = string.Format("{0}元", po.OrderPrice.ToString("C")); jTmplMsgDataValue["color"] = MSG_HEAD_COLOR; jTmplMsgData["keyword2"] = jTmplMsgDataValue; jTmplMsgDataValue = new JsonData(); jTmplMsgDataValue["value"] = po.OrderDate.ToString(); jTmplMsgDataValue["color"] = MSG_BODY_COLOR; jTmplMsgData["keyword3"] = jTmplMsgDataValue; jTmplMsgDataValue = new JsonData(); jTmplMsgDataValue["value"] = string.Format("订单号:{0}\n点击详情查看团购活动", po.OrderID.Substring(18)); jTmplMsgDataValue["color"] = MSG_BODY_COLOR; jTmplMsgData["remark"] = jTmplMsgDataValue; break; case GroupEventStatus.EVENT_FAIL: jTmplMsg["template_id"] = TMPL_GROUP_PURCHASE_EVENT_FAIL; jTmplMsgDataValue = new JsonData(); jTmplMsgDataValue["value"] = string.Format("您的拼团“{0}#{1}”失败,我们将尽快退款给您。", groupEvent.GroupPurchase.Name, groupEvent.ID); jTmplMsgDataValue["color"] = MSG_BODY_COLOR; jTmplMsgData["first"] = jTmplMsgDataValue; jTmplMsgDataValue = new JsonData(); jTmplMsgDataValue["value"] = string.Format("{0}元", po.OrderPrice.ToString("C")); jTmplMsgDataValue["color"] = MSG_HEAD_COLOR; jTmplMsgData["keyword1"] = jTmplMsgDataValue; jTmplMsgDataValue = new JsonData(); jTmplMsgDataValue["value"] = po.OrderDetails; jTmplMsgDataValue["color"] = MSG_BODY_COLOR; jTmplMsgData["keyword2"] = jTmplMsgDataValue; jTmplMsgDataValue = new JsonData(); jTmplMsgDataValue["value"] = po.OrderID.Substring(18); jTmplMsgDataValue["color"] = MSG_BODY_COLOR; jTmplMsgData["keyword3"] = jTmplMsgDataValue; jTmplMsgDataValue = new JsonData(); jTmplMsgDataValue["value"] = "点击详情查看团购活动"; jTmplMsgDataValue["color"] = MSG_BODY_COLOR; jTmplMsgData["remark"] = jTmplMsgDataValue; break; } jTmplMsg["data"] = jTmplMsgData; userReceivers = new List <string>(new string[] { po.Purchaser.OpenID }); jRet.Add(SendTmplMsg(userReceivers, jTmplMsg)); }); } catch (Exception ex) { Log.Error("GroupPurchaseEventSuccessOnOrderStateChanged", ex.Message); throw ex; } }