예제 #1
0
    /// <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);
    }
예제 #2
0
    /// <summary>
    /// 查询指定团购活动ID包含的所有订单,用于检测活动成员是否全部支付成功。不需要加载订单明细,以及订单明细项对应的团购活动
    /// </summary>
    /// <param name="conn"></param>
    /// <returns></returns>
    public List <ProductOrder> FindOrderByGroupEventID(SqlConnection conn)
    {
        List <ProductOrder> poList = new List <ProductOrder>();
        ProductOrder        po;

        try
        {
            using (SqlCommand cmdOrder = conn.CreateCommand())
            {
                cmdOrder.CommandText = "select * from ProductOrder where Id in (select ProductOrder.Id from ProductOrder left join OrderDetail on ProductOrder.Id = OrderDetail.PoID where OrderDetail.GroupEventID=@EventID) order by Id";

                SqlParameter paramEventID = cmdOrder.CreateParameter();
                paramEventID.ParameterName = "@EventID";
                paramEventID.SqlDbType     = System.Data.SqlDbType.Int;
                paramEventID.SqlValue      = this.ID;
                cmdOrder.Parameters.Add(paramEventID);

                using (SqlDataReader sdrOrder = cmdOrder.ExecuteReader())
                {
                    while (sdrOrder.Read())
                    {
                        po = new ProductOrder();

                        ProductOrder.SDR2PO(po, sdrOrder);

                        po.Purchaser = WeChatUserDAO.FindUserByOpenID(conn, sdrOrder["OpenID"].ToString(), false);
                        if (sdrOrder["AgentOpenID"] != DBNull.Value)
                        {
                            po.Agent = WeChatUserDAO.FindUserByOpenID(conn, sdrOrder["AgentOpenID"].ToString(), false);
                        }

                        poList.Add(po);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }

        return(poList);
    }
예제 #3
0
    /// <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);
    }
예제 #4
0
    /// <summary>
    /// 查询团购活动成员
    /// </summary>
    /// <param name="conn"></param>
    /// <returns></returns>
    public List <GroupPurchaseEventMember> FindGroupPurchaseEventMembers(SqlConnection conn)
    {
        List <GroupPurchaseEventMember> groupEventMemberList = new List <GroupPurchaseEventMember>();

        try
        {
            //查询团购活动关联的所有订单,用于检测此用户是否全部支付成功
            List <ProductOrder> poList = this.FindOrderByGroupEventID(conn);

            using (SqlCommand cmdGroupID = conn.CreateCommand())
            {
                SqlParameter paramID = cmdGroupID.CreateParameter();
                paramID.ParameterName = "@GroupEventID";
                paramID.SqlDbType     = System.Data.SqlDbType.Int;
                paramID.SqlValue      = this.ID;
                cmdGroupID.Parameters.Add(paramID);

                cmdGroupID.CommandText = "select * from GroupPurchaseEventMember where GroupEventID = @GroupEventID order by Id";

                using (SqlDataReader sdr = cmdGroupID.ExecuteReader())
                {
                    GroupPurchaseEventMember eventMember;

                    while (sdr.Read())
                    {
                        eventMember                    = new GroupPurchaseEventMember();
                        eventMember.ID                 = int.Parse(sdr["Id"].ToString());
                        eventMember.GroupMember        = WeChatUserDAO.FindUserByOpenID(conn, sdr["GroupMember"].ToString(), false);
                        eventMember.JoinDate           = DateTime.Parse(sdr["JoinDate"].ToString());
                        eventMember.GroupPurchaseEvent = this;

                        //检查当前成员是否有未支付、未撤单的订单,必须全部订单支付成功才认为此用户参加的团购活动支付成功
                        int memberAllPO = 0, notPaidPO = 0, cancelledPO = 0;
                        poList.ForEach(po =>
                        {
                            if (po.Purchaser.OpenID == eventMember.GroupMember.OpenID)
                            {
                                //计算团购活动里的所有订单数量
                                memberAllPO++;
                            }

                            if (po.Purchaser.OpenID == eventMember.GroupMember.OpenID &&
                                !po.IsCancel &&
                                po.TradeState != TradeState.SUCCESS &&
                                po.TradeState != TradeState.CASHPAID &&
                                po.TradeState != TradeState.AP_TRADE_FINISHED &&
                                po.TradeState != TradeState.AP_TRADE_SUCCESS)
                            {
                                //计算团购活动里的未支付订单数量
                                notPaidPO++;
                            }

                            if (po.Purchaser.OpenID == eventMember.GroupMember.OpenID &&
                                po.IsCancel)
                            {
                                //计算团购活动里的取消订单数量
                                cancelledPO++;
                            }
                        });

                        //设置当前成员的支付标记,如果不存在未支付的订单,并且订单没有被全部取消,则认为此团购成员已支付
                        if (notPaidPO == 0 && cancelledPO < memberAllPO)
                        {
                            eventMember.IsPaid = true;
                        }
                        else
                        {
                            eventMember.IsPaid = false;
                        }

                        groupEventMemberList.Add(eventMember);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Log.Error("查询指定团购活动中的所有用户", ex.ToString());
            throw ex;
        }

        return(groupEventMemberList);
    }
예제 #5
0
    public static void SendMsgOnMemberPoints(object sender, ProductOrder.MemberPointsCalculatedEventArgs e)
    {
        if (sender == null || !(sender is ProductOrder) || e == null)
        {
            throw new ArgumentNullException("sender或事件参数对象不能为null");
        }

        ProductOrder po = sender as ProductOrder;

        JsonData jRet;

        try
        {
            List <string> listReceiver;
            JsonData      jTmplMsg, jTmplMsgData, jTmplMsgDataValue;

            //给订单的下单人发送积分通知消息
            listReceiver = new List <string>(new string[] { po.Purchaser.OpenID });
            //构造模板消息
            jTmplMsg     = new JsonData();
            jTmplMsgData = new JsonData();

            jTmplMsg["touser"]      = string.Empty;
            jTmplMsg["template_id"] = TMPL_MEMBER_POINTS_NOTIFY;
            jTmplMsg["url"]         = @"http://mahui.me/UserCenter.aspx";
            jTmplMsg["topcolor"]    = MSG_HEAD_COLOR;

            jTmplMsgDataValue          = new JsonData();
            jTmplMsgDataValue["value"] = "您的FruitU会员积分信息变更如下";
            jTmplMsgDataValue["color"] = MSG_BODY_COLOR;
            jTmplMsgData["first"]      = jTmplMsgDataValue;

            jTmplMsgDataValue          = new JsonData();
            jTmplMsgDataValue["value"] = po.Purchaser.NickName;
            jTmplMsgDataValue["color"] = MSG_BODY_COLOR;
            jTmplMsgData["keyword1"]   = jTmplMsgDataValue;

            jTmplMsgDataValue          = new JsonData();
            jTmplMsgDataValue["value"] = "微信用户";
            jTmplMsgDataValue["color"] = MSG_BODY_COLOR;
            jTmplMsgData["keyword2"]   = jTmplMsgDataValue;

            jTmplMsgDataValue          = new JsonData();
            jTmplMsgDataValue["value"] = string.Format("本次消费增加{0}积分,使用{1}积分", e.increasedMemberPoints, e.usedMemberPoints);
            jTmplMsgDataValue["color"] = MSG_BODY_COLOR;
            jTmplMsgData["keyword3"]   = jTmplMsgDataValue;

            jTmplMsgDataValue          = new JsonData();
            jTmplMsgDataValue["value"] = string.Format("{0}积分(={1}元)", e.newMemberPoints, (decimal)e.newMemberPoints / Config.MemberPointsExchangeRate);
            jTmplMsgDataValue["color"] = MSG_HEAD_COLOR;
            jTmplMsgData["keyword4"]   = jTmplMsgDataValue;

            jTmplMsgDataValue          = new JsonData();
            jTmplMsgDataValue["value"] = "在FruitU页面中分享给好友或朋友圈,好友消费后您有100积分(5元)奖励哦,现在就分享吧!";
            jTmplMsgDataValue["color"] = MSG_BODY_COLOR;
            jTmplMsgData["remark"]     = jTmplMsgDataValue;

            jTmplMsg["data"] = jTmplMsgData;

            //发送模板消息
            jRet = SendTmplMsg(listReceiver, jTmplMsg);


            //如果此订单有推荐人,且推荐人获得了积分奖励,则也给推荐人发送积分奖励消息
            if (po.Agent != null && !string.IsNullOrEmpty(po.Agent.OpenID) && po.Purchaser.OpenID != po.Agent.OpenID && e.agentNewMemberPoints != -1)
            {
                WeChatUser wxAgent = WeChatUserDAO.FindUserByOpenID(po.Agent.OpenID);
                if (wxAgent != null)
                {
                    listReceiver = new List <string>(new string[] { po.Agent.OpenID });

                    //构造模板消息
                    jTmplMsg     = new JsonData();
                    jTmplMsgData = new JsonData();

                    jTmplMsg["touser"]      = string.Empty;
                    jTmplMsg["template_id"] = TMPL_MEMBER_POINTS_NOTIFY;
                    jTmplMsg["url"]         = @"http://mahui.me/UserCenter.aspx";
                    jTmplMsg["topcolor"]    = MSG_HEAD_COLOR;

                    jTmplMsgDataValue          = new JsonData();
                    jTmplMsgDataValue["value"] = string.Format("您推荐好友“{0}”消费,获得了积分奖励哦!", po.Purchaser.NickName);
                    jTmplMsgDataValue["color"] = MSG_BODY_COLOR;
                    jTmplMsgData["first"]      = jTmplMsgDataValue;

                    jTmplMsgDataValue          = new JsonData();
                    jTmplMsgDataValue["value"] = wxAgent.NickName;
                    jTmplMsgDataValue["color"] = MSG_BODY_COLOR;
                    jTmplMsgData["keyword1"]   = jTmplMsgDataValue;

                    jTmplMsgDataValue          = new JsonData();
                    jTmplMsgDataValue["value"] = "微信用户";
                    jTmplMsgDataValue["color"] = MSG_BODY_COLOR;
                    jTmplMsgData["keyword2"]   = jTmplMsgDataValue;

                    jTmplMsgDataValue          = new JsonData();
                    jTmplMsgDataValue["value"] = string.Format("本次推荐奖励{0}积分", 100);
                    jTmplMsgDataValue["color"] = MSG_BODY_COLOR;
                    jTmplMsgData["keyword3"]   = jTmplMsgDataValue;

                    jTmplMsgDataValue          = new JsonData();
                    jTmplMsgDataValue["value"] = string.Format("{0}积分(={1}元)", e.agentNewMemberPoints, (decimal)e.agentNewMemberPoints / Config.MemberPointsExchangeRate);
                    jTmplMsgDataValue["color"] = MSG_HEAD_COLOR;
                    jTmplMsgData["keyword4"]   = jTmplMsgDataValue;

                    jTmplMsgDataValue          = new JsonData();
                    jTmplMsgDataValue["value"] = "如有疑问,请及时与FruitU微信客服联系";
                    jTmplMsgDataValue["color"] = MSG_BODY_COLOR;
                    jTmplMsgData["remark"]     = jTmplMsgDataValue;

                    jTmplMsg["data"] = jTmplMsgData;

                    //发送模板消息
                    jRet = SendTmplMsg(listReceiver, jTmplMsg);
                }
            }
        }
        catch (Exception ex)
        {
            Log.Error("SendMsgOnMemberPoints", ex.Message);
            throw ex;
        }

        if (jRet != null)
        {
            Log.Info("SendMsgOnMemberPoints", jRet.ToJson());
        }
    }