Exemplo n.º 1
0
        static CelebHelper()
        {
            //改为从DB中读取活动起止日期
            GamePrizeInfo prizeInfo = CelebHelper.GetPrizeInfor("FirstPrize");

            if (prizeInfo != null)
            {
                CelebHelper.ActivityStartDate = prizeInfo.ActivityStartDate;
                CelebHelper.ActivityEndDate   = prizeInfo.ActivityEndDate;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 开始做蛋糕
        /// </summary>
        public void StartDoCake()
        {
            PrintJson("-2", "您帐号在微信上未授权!");
            return;

            //改为从DB中读取活动起止日期
            GamePrizeInfo gprizeInfo = CelebHelper.GetPrizeInfor("FirstPrize");

            if (gprizeInfo != null)
            {
                CelebHelper.ActivityStartDate = gprizeInfo.ActivityStartDate;
                CelebHelper.ActivityEndDate   = gprizeInfo.ActivityEndDate;
            }

            bool   isLogin = WebUserAuth.IsAuthenticated;
            string code    = WEBRequest.GetFormString("code");

            if (code.IsEmpty())
            {
                PrintJson("-2", "您帐号在微信上未授权!");
                return;
            }
            if (DateTime.Now < CelebHelper.ActivityStartDate)
            {
                PrintJson("-3", "您来得太早了,<br/>活动还未开始!");
                return;
            }
            if (DateTime.Now > CelebHelper.ActivityEndDate)
            {
                PrintJson("-3", "您来得太晚了,<br/>活动已结束了!");
                return;
            }
            string ExtendOpenId = WEBRequest.GetFormString("ExtendKey"); //推广人OpenId
            Guid?  userId       = WebUserAuth.UserId;
            bool   isSelfUser   = true;                                  //是否自已在做蛋糕

            if (ExtendOpenId.IsNotEmpty())
            {
                isSelfUser = false;
                if (!CheckUserIsExists(ExtendOpenId))
                {
                    PrintJson("-2", "对不起,该邀请码无效!");
                    return;
                }
            }

            string HostOpenId = GetCurrentOpenId(code);

            //判断OpenId为空
            if (HostOpenId.IsEmpty())
            {
                PrintJson("-2", "您帐号在微信上未授权!");
                return;
            }
            bool isDoCake = false;

            if (ExtendOpenId.IsNotEmpty())
            {
                //帮好友做蛋糕
                isDoCake = CheckUserHasDoCake(ExtendOpenId, HostOpenId);
            }
            else
            {
                isDoCake = CheckUserHasDoCake(HostOpenId, HostOpenId);
            }
            if (isDoCake)
            {
                string errMsg = "您已经做过蛋糕了!";
                if (isSelfUser == false)
                {
                    errMsg = "您已帮好友做过一次蛋糕!";
                }
                PrintJson("-1", errMsg);
                return;
            }

            ThirdLoginSDK sdk = new ThirdLoginSDK();

            sdk.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);
            //获取微信上用户信息
            TuanDai.WXApiWeb.Common.ThirdLoginSDK.WXOAuthUser wxUserInfo = sdk.GetWXUserSubscribeInfor(code);
            if (wxUserInfo == null || wxUserInfo.nickname.IsEmpty())
            {
                PrintJson("-2", "您帐号获取微信授权失败!");
                return;
            }

            string strSQL       = "";
            bool   IsAddSuccess = false;

            //给自已做蛋糕
            if (isSelfUser)
            {
                GamePrizeInfo prizeInfo = CelebHelper.GetPrizeInfor("RedPacket");
                if (prizeInfo == null)
                {
                    PrintJson("-4", "对不起,该活动参与人数已满,<br/>下次再参与吧!");
                    return;
                }

                #region 写入做蛋糕记录
//                using (SqlConnection connection = CelebHelper.OpenConnection(2))
//                {
//                    UserBLL userbll = new UserBLL();
//                    UserBasicInfoInfo userInfo = null;
//                    if (isLogin)
//                    {
//                        userInfo = userbll.GetUserBasicInfoModelById(userId.Value);
//                    }
//                    strSQL = @"insert into Activity_ThreeYearGame_Record(Id,UserId,UserName,NickName,WXOpenId,AddDate,CakeNum,ExpirationDate,GetPrizeDate)
//                               values(@Id,@UserId,@UserName,@NickName,@WXOpenId,@AddDate,@CakeNum,@ExpirationDate,@GetPrizeDate)";

//                    DynamicParameters dyParams = new DynamicParameters();
//                    dyParams.Add("@Id", Guid.NewGuid());
//                    if (userInfo != null)
//                    {
//                        dyParams.Add("@UserId", userInfo.Id);
//                        dyParams.Add("@UserName", userInfo.UserName);
//                        dyParams.Add("@NickName", userInfo.NickName);
//                        dyParams.Add("@ExpirationDate", null);//已登录时,奖品就已发送至团宝箱,这里没过期时间
//                    }
//                    else
//                    {
//                        dyParams.Add("@UserId", null);
//                        dyParams.Add("@UserName", "");
//                        dyParams.Add("@NickName", "");
//                        dyParams.Add("@ExpirationDate", CelebHelper.GetPrizeEndDate);
//                    }
//                    dyParams.Add("@WXOpenId", HostOpenId);
//                    dyParams.Add("@AddDate", DateTime.Now);
//                    dyParams.Add("@CakeNum", 0);
//                    if (userInfo != null)
//                        dyParams.Add("@GetPrizeDate", DateTime.Now);
//                    else
//                        dyParams.Add("@GetPrizeDate", null);

//                    IsAddSuccess = connection.Execute(strSQL, dyParams) > 0;

//                    //登录后将奖品自动插入我的团宝箱
//                    if (IsAddSuccess && userInfo != null)
//                    {
//                        CelebHelper.AddToMyPrize(prizeInfo, WebUserAuth.UserId.Value, false);
//                    }
//                }
                #endregion
            }

            //往做蛋糕好友表中添加一笔
            AddOneFriendDataDelegate addFriend = new AddOneFriendDataDelegate(AddOneFriendData);
            if (isSelfUser)
            {
                //自已做蛋糕
                addFriend.Invoke(HostOpenId, HostOpenId, isLogin, wxUserInfo);
            }
            else
            {
                //好友做蛋糕
                addFriend.Invoke(ExtendOpenId, HostOpenId, isLogin, wxUserInfo);
            }
            string showMsg = "";
            if (isSelfUser)
            {
                showMsg = "<p>恭喜您,参与成功!</p><p>获得<span class=\"c-ffde00\">10元</span>投资红包!</p><p style=\"text-align:center\">(详见\"我的奖品\")</p>";
            }
            else
            {
                string friendNickName = GetFriendNickName(ExtendOpenId);
                showMsg = string.Format("<p>恭喜您!成功帮好友“{0}”做蛋糕!</p>", friendNickName.IsEmpty() ? "他" : friendNickName);
            }

            PrintJson("1", showMsg);
        }