コード例 #1
0
        static CelebHelper()
        {
            //改为从DB中读取活动起止日期
            GamePrizeInfo prizeInfo = CelebHelper.GetPrizeInfor("FirstPrize");

            if (prizeInfo != null)
            {
                CelebHelper.ActivityStartDate = prizeInfo.ActivityStartDate;
                CelebHelper.ActivityEndDate   = prizeInfo.ActivityEndDate;
            }
        }
コード例 #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);
        }
コード例 #3
0
        /// <summary>
        /// 发送奖品到团宝箱中
        /// </summary>
        /// <param name="prizeInfo"></param>
        /// <param name="userId"></param>
        /// <param name="IsAutoGet">是否自动领取</param>
        public static void AddToMyPrize(GamePrizeInfo prizeInfo, Guid userId, bool IsAutoGet)
        {
            string strSQL        = "";
            int    pStatus       = 0;
            Guid   prizeRecordId = Guid.NewGuid();
            bool   isAddPrize    = false;

            #region 写入中奖记录

//            using (SqlConnection connection = OpenConnection(2))
//            {
//                strSQL = " select WXOpenId from Activity_ThreeYearGame_Record where UserId=@UserId";
//                DynamicParameters dyParams = new DynamicParameters();
//                dyParams.Add("@UserId", userId);
//                string wxOpenId = connection.Query<string>(strSQL, dyParams).FirstOrDefault().ToText();

//                strSQL = @"insert into Activity_ThreeYearGame_WinRecord(Id,UserId,PrizeId,PrizeType,PrizeName,PrizeAmount,AddDate, WXOpenId)
//                               values(@Id,@UserId,@PrizeId,@PrizeType,@PrizeName,@PrizeAmount,@AddDate,@WXOpenId)";

//                dyParams = new DynamicParameters();
//                dyParams.Add("@Id", prizeRecordId);
//                dyParams.Add("@UserId", userId);
//                dyParams.Add("@PrizeId", prizeInfo.Id);
//                dyParams.Add("@PrizeType", prizeInfo.PrizeType);
//                dyParams.Add("@PrizeName", prizeInfo.PrizeName);
//                dyParams.Add("@PrizeAmount", prizeInfo.PrizeValue);
//                dyParams.Add("@AddDate", DateTime.Now);
//                dyParams.Add("@WXOpenId", wxOpenId);
//                isAddPrize = connection.Execute(strSQL, dyParams) > 0;
//                connection.Close();
//            }
            #endregion

            #region 插入团宝箱
            //if (isAddPrize)
            //{
            //    using (SqlConnection connection = OpenConnection(1))
            //    {
            //        try
            //        {

            //            //DynamicParameters dyParam = new DynamicParameters();
            //            //dyParam.Add("@UserId", userId);
            //            //dyParam.Add("@Type", prizeInfo.PrizeType);
            //            //dyParam.Add("@SubTypeId", prizeInfo.PrizeType == 9 ? 1: 20);
            //            //dyParam.Add("@ActivityCode", "201500714_" + prizeRecordId.ToString());//为了插入数据不重复,此处为两个值串联

            //            //dyParam.Add("@PrizeName", prizeInfo.PrizeName);
            //            //dyParam.Add("@PrizeValue", prizeInfo.PrizeValue);
            //            //if (prizeInfo.TargetProductId.HasValue)
            //            //    dyParam.Add("@TargetProductId", prizeInfo.TargetProductId.Value);
            //            //else
            //            //    dyParam.Add("@TargetProductId", null);
            //            //if(prizeInfo.PrizeType==3)
            //            //    dyParam.Add("@Description", "团贷网三周年庆典-单笔投资满1000元即可使用10元,过期时间为:" + DateTime.Today.AddMonths(1).AddDays(-1).ToString("yyyy/MM/dd"));
            //            //else
            //            //    dyParam.Add("@Description", "团贷网三周年庆典");

            //            ////0赠送失败,1赠送成功,-1提现券无库存
            //            //dyParam.Add("@outStatus", 0, System.Data.DbType.Int32, System.Data.ParameterDirection.Output);

            //            ////调用此过程必须要用到事务
            //            //connection.Execute("p_sendUserPrize", dyParam,null, null, CommandType.StoredProcedure);
            //            //pStatus = dyParam.Get<int>("@outStatus");
            //        }
            //        catch (Exception ex)
            //        {

            //        }
            //        finally
            //        {
            //            connection.Close();
            //            connection.Dispose();
            //        }
            //    }
            //}
            #endregion

            #region 更新奖品数量
            //if (pStatus == 1)
            //{
            //    using (SqlConnection connection = OpenConnection(2))
            //    {
            //        //写入成功时,更新奖品领用数量
            //        strSQL = " update Activity_ThreeYearGame_Prize set UsePrizeNum=isnull(UsePrizeNum,0)+1 where Id=@Id";
            //        DynamicParameters dyParam = new DynamicParameters();
            //        dyParam.Add("@Id", prizeInfo.Id);
            //        connection.Execute(strSQL, dyParam);
            //        connection.Close();
            //    }
            //}
            #endregion
        }