Exemplo n.º 1
0
        /// <summary>
        /// 插入中奖记录
        /// </summary>
        /// <returns></returns>
        public bool AddWXLotteryRecordV1(WXLotteryRecordV1 model)
        {
            WebsiteInfo websiteInfo = GetWebsiteInfoModelFromDataBase();
            var         award       = model.WXAward;

            switch (award.AwardsType)
            {
            case 1:    //给用户增加积分
                var isSyncYike = new BLLJIMP.BLLCommRelation().ExistRelation(BLLJIMP.Enums.CommRelationType.SyncYike, WebsiteOwner, "");
                Open.EZRproSDK.Client zrClient = new Open.EZRproSDK.Client();
                if (isSyncYike)
                {
                    var resp = zrClient.BonusUpdate(GetCurrentUserInfo().Ex2, Convert.ToInt32(award.Value), "中奖加积分");
                }
                else if (websiteInfo.IsUnionHongware == 1)
                {
                    Open.HongWareSDK.Client hongWareClient = new Open.HongWareSDK.Client(GetCurrentUserInfo().WebsiteOwner);
                    var hongWareMemberInfo = hongWareClient.GetMemberInfo(GetCurrentUserInfo().WXOpenId);
                    if (hongWareMemberInfo.member != null)
                    {
                        hongWareClient.UpdateMemberScore(hongWareMemberInfo.member.mobile, GetCurrentUserInfo().WXOpenId, float.Parse(award.Value));
                    }
                }
                //else
                //{
                string tempMsg = "";
                new BLLUser().AddUserScoreDetail(GetCurrUserID(), CommonPlatform.Helper.EnumStringHelper.ToString(Enums.ScoreDefineType.Lottery), WebsiteOwner
                                                 , out tempMsg, Convert.ToInt32(award.Value), "中奖加积分", "", false);
                //}
                break;

            case 2:    //给用户增加优惠券

                new BLLCardCoupon().SendCardCoupon(int.Parse(model.WXAward.Value), model.UserId);

                break;

            default:
                break;
            }


            return(Add(model));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 驿氪会员数据回传
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string EZRproCallBackMemberAPI(HttpContext context)
        {
            string result = string.Empty;

            if (context.Request["token"] != "74F2EBA1C83264DEC0ACD7E8D2CAB50CBF767535")
            {
                return(JsonConvert.SerializeObject(new
                {
                    Status = false,
                    Msg = "错误:token",
                    StatusCode = 0,
                    Result = 0
                }));
            }

            Open.EZRproSDK.Entity.MemberCallBackReq info = new Open.EZRproSDK.Entity.MemberCallBackReq();
            info = bll.ConvertRequestToModel <Open.EZRproSDK.Entity.MemberCallBackReq>(info);
            var args = context.Request["Args"];

            TologTemp("MemberInfo ConvertRequestToModel:" + JsonConvert.SerializeObject(info));
            TologTemp("args:" + args);

            TologTemp("AppId:" + context.Request["AppId"]);
            TologTemp("Sign:" + context.Request["Sign"]);

            info.Args = JsonConvert.DeserializeObject <Open.EZRproSDK.Entity.MemberInfo>(args);

            TologTemp("args ok");

            var client = new Open.EZRproSDK.Client();

            result = client.CallBackMemberInfo(info);


            TologTemp("result:" + result);

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 抽奖
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string Scratch(HttpContext context)
        {
            try
            {
                if (!bll.IsLogin)
                {
                    return("请先登录");
                }
                string id = context.Request["id"];
                if (string.IsNullOrEmpty(id))
                {
                    return("id必传");
                }

                /*
                 * 检查是否是签到抽奖,是则:
                 * 1.当前是否是在周日,不在周日则不能抽奖
                 * 2.如果在周日,检查是否一周内有签到记录,否则不能抽奖
                 *
                 */

                var signInModel = new BLLJIMP.BLLSignIn().Get <SignInAddress>(string.Format(" WebsiteOwner='{0}' AND Type='Sign' ", currentUserInfo.WebsiteOwner));
                if (signInModel != null && signInModel.LotteryId == id)
                {
                    var dt = DateTime.Now;

                    if (dt.DayOfWeek != DayOfWeek.Sunday)
                    {
                        return("周日才可以抽奖");
                    }

                    //获取本周签到记录,倒退七天是否有七条
                    var signInCount = bll.GetCount <SignInLog>(string.Format("  cast(SignInDate as date) between '{0}' and '{1}' and  WebsiteOwner = '{2}' and UserID = '{3}' ",
                                                                             dt.AddDays(-6).ToString("yyyy-MM-dd"),
                                                                             dt.ToString("yyyy-MM-dd"),
                                                                             currentUserInfo.WebsiteOwner,
                                                                             currentUserInfo.UserID
                                                                             ));

                    if (signInCount < 7)
                    {
                        return("一周连续签到才可以抽奖");
                    }
                }

                #region 检查是否可以继续
                ScratchJsonModel apiResult = new ScratchJsonModel();
                apiResult.awardName = "谢谢参与";
                WXLotteryV1 model = bll.Get <WXLotteryV1>(string.Format("LotteryID={0}", id));
                if (model == null)
                {
                    goto outoff;
                }
                apiResult.awardId = model.LotteryID;
                apiResult.isStart = model.Status == 1 ? true : false;
                if (model.StartTime != null)
                {
                    apiResult.startTime = model.StartTime.Value.ToString("yyyy/MM/dd HH:mm:ss");
                    if (model.StartTime <= DateTime.Now)//已经到了开奖时间了
                    {
                        if (model.Status == 1)
                        {
                            apiResult.isStart = true;
                        }
                        else
                        {
                            apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.NotStart;
                            apiResult.awardName = "刮奖未开启";
                            apiResult.isStart   = false;
                        }
                    }
                    else//开奖时间还没到
                    {
                        apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.NotStart;
                        apiResult.awardName = "未到刮奖时间";
                        apiResult.isStart   = false;
                        goto outoff;
                    }
                }

                //检查结束时间
                if (model.EndTime != null)
                {
                    apiResult.startTime = model.EndTime.Value.ToString("yyyy/MM/dd HH:mm:ss");
                    if (model.EndTime.Value <= DateTime.Now)
                    {
                        apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.IsEnd;
                        apiResult.awardName = "已结束";
                        apiResult.isStart   = false;
                        goto outoff;
                    }
                }

                if (context.Request["hideAward"] != "1")
                {
                    apiResult.winRecord = bll.GetWXLotteryRecordList(model.LotteryID, currentUserInfo.UserID);
                }
                if (model.WinLimitType.Equals(0))
                {
                    var lotteryRecord = bll.GetWXLotteryRecordV1(currentUserInfo.UserID, model.LotteryID);
                    if (lotteryRecord != null)
                    {
                        if (context.Request["hideAward"] != "1")
                        {
                            WXLotteryLogV1 logWinLimit = new WXLotteryLogV1();
                            logWinLimit.LotteryId  = model.LotteryID;
                            logWinLimit.UserId     = currentUserInfo.UserID;
                            logWinLimit.InsertDate = DateTime.Now;
                            logWinLimit.IP         = Common.MySpider.GetClientIP();
                            if (bll.AddWXLotteryLogV1(logWinLimit))//下一步
                            {
                            }

                            apiResult.awardName = string.Format("{0}", lotteryRecord.WXAwardName);
                            apiResult.isAward   = true;

                            //告诉前端你已经中过奖了
                            apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.LotteryHaveRecord;; //LotteryHaveRecord
                        }
                        goto outoff;
                    }
                }

                if (!apiResult.isStart)
                {
                    apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.NotStart;
                    apiResult.awardName = "刮奖未开启";
                    apiResult.isStart   = false;
                    goto outoff;
                }
                #endregion

                #region 内定中奖
                List <WXLotteryWinningDataV1> winData = bll.GetList <WXLotteryWinningDataV1>(string.Format("LotteryId={0}", model.LotteryID));
                if (winData.SingleOrDefault(p => p.UserId.Equals(currentUserInfo.UserID)) != null)
                {
                    //给默认中奖者中奖
                    WXLotteryRecordV1 record = new WXLotteryRecordV1();
                    record.InsertDate = DateTime.Now;
                    record.LotteryId  = model.LotteryID;
                    record.Token      = "0";
                    record.WXAwardsId = winData.Single(p => p.UserId.Equals(currentUserInfo.UserID)).WXAwardsId;
                    record.UserId     = currentUserInfo.UserID;
                    record.IsGetPrize = 0;
                    if (bll.AddWXLotteryRecordV1(record))
                    {
                        apiResult.awardName = string.Format("{0}", winData.Single(p => p.UserId.Equals(currentUserInfo.UserID)).WXAwardName);
                        apiResult.isAward   = true;
                    }

                    goto outoff;
                }
                //设置默认中奖
                #endregion

                #region 外部积分读取
                var isSyncYike = new BLLJIMP.BLLCommRelation().ExistRelation(BLLJIMP.Enums.CommRelationType.SyncYike, currentUserInfo.WebsiteOwner, "");

                Open.EZRproSDK.Client zrClient = new Open.EZRproSDK.Client();

                if (isSyncYike)
                {
                    var getBonusResp = zrClient.GetBonus(currentUserInfo.Ex1, currentUserInfo.Ex2, currentUserInfo.Phone);
                    if (getBonusResp != null)
                    {
                        currentUserInfo.TotalScore = getBonusResp.Bonus;
                    }
                    else
                    {
                        currentUserInfo.TotalScore = 0;
                    }
                }
                #endregion


                #region 使用宏巍积分

                Open.HongWareSDK.Client hongWareClient = new Open.HongWareSDK.Client(websiteInfo.WebsiteOwner);
                if (websiteInfo.IsUnionHongware == 1)
                {
                    var hongWareMemberInfo = hongWareClient.GetMemberInfo(currentUserInfo.WXOpenId);
                    if (hongWareMemberInfo.member != null)
                    {
                        currentUserInfo.TotalScore = hongWareMemberInfo.member.point;
                    }
                    else
                    {
                        currentUserInfo.TotalScore = 0;
                    }
                }
                #endregion

                string tempMsg = "";
                #region 抽奖限制 总共多少次或每天几次  用购买的刮奖次数除外

                #region 总共多少次
                if (model.LuckLimitType.Equals(0))//总共多少次
                {
                    int count = bll.GetWXLotteryLogCountV1(model.LotteryID, currentUserInfo.UserID);
                    if (count >= model.MaxCount)
                    {
                        //判读是否够积分
                        if (model.UsePoints > 0)
                        {
                            if (currentUserInfo.TotalScore >= model.UsePoints)
                            {
                                //扣积分
                                if (isSyncYike)
                                {
                                    var resp = zrClient.BonusUpdate(currentUserInfo.Ex2, -model.UsePoints, "抽奖减少积分");
                                }
                                else
                                {
                                    bllUser.AddUserScoreDetail(currentUserInfo.UserID, EnumStringHelper.ToString(ScoreDefineType.Lottery), bllUser.WebsiteOwner, out tempMsg, -model.UsePoints, "抽奖减少积分", "", false);
                                }
                            }
                            else
                            {
                                if (currentUserInfo.LotteryCount == 0)
                                {
                                    apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.IntegralProblem;
                                    apiResult.awardName = "积分不足";
                                    apiResult.isStart   = false;
                                    goto outoff;
                                }
                                else
                                {
                                    //剩余刮奖次数减1
                                    if (bll.Update(currentUserInfo, string.Format(" LotteryCount-=1"), string.Format("AutoId={0}", currentUserInfo.AutoID)) <= 0)
                                    {
                                        apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.IntegralProblem;
                                        apiResult.awardName = "谢谢参与";
                                        apiResult.isStart   = false;
                                        goto outoff;
                                    }
                                }
                            }
                        }
                        else
                        {
                            apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.CountIsOver;
                            apiResult.awardName = "谢谢参与";
                            goto outoff;
                        }
                    }
                }
                #endregion

                #region 每天多少次
                else
                {
                    //判读一天有没有超出
                    int count = bll.GetWXLotteryLogCountV1(model.LotteryID, currentUserInfo.UserID, DateTime.Now);
                    if (count >= model.MaxCount)
                    {
                        //判读是否够积分
                        if (model.UsePoints > 0)
                        {
                            if (currentUserInfo.TotalScore >= model.UsePoints)
                            {
                                if (isSyncYike)
                                {
                                    var resp = zrClient.BonusUpdate(currentUserInfo.Ex2, -model.UsePoints, "抽奖减少积分");
                                }
                                else
                                {
                                    //扣积分
                                    bllUser.AddUserScoreDetail(currentUserInfo.UserID, EnumStringHelper.ToString(ScoreDefineType.Lottery), bllUser.WebsiteOwner, out tempMsg, -model.UsePoints, "抽奖减少积分", "", false);
                                }
                            }
                            else
                            {
                                if (currentUserInfo.LotteryCount == 0)
                                {
                                    apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.IntegralProblem;
                                    apiResult.awardName = "积分不足";
                                    apiResult.isStart   = false;
                                    goto outoff;
                                }
                                else
                                {
                                    //剩余刮奖次数减1
                                    if (bll.Update(currentUserInfo, string.Format(" LotteryCount-=1"), string.Format("AutoId={0}", currentUserInfo.AutoID)) <= 0)
                                    {
                                        apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.IntegralProblem;
                                        apiResult.awardName = "谢谢参与";
                                        apiResult.isStart   = false;
                                        goto outoff;
                                    }
                                }
                            }
                        }
                        else
                        {
                            apiResult.errorCode = (int)BLLJIMP.Enums.APIErrCode.CountIsOver;
                            apiResult.awardName = "谢谢参与";
                            goto outoff;
                        }
                    }
                }
                #endregion

                #endregion

                WXLotteryLogV1 log = new WXLotteryLogV1();
                log.LotteryId  = model.LotteryID;
                log.UserId     = currentUserInfo.UserID;
                log.InsertDate = DateTime.Now;
                log.IP         = Common.MySpider.GetClientIP();
                if (bll.AddWXLotteryLogV1(log))//下一步
                {
                    #region 奖池生成
                    List <AwardModel> awardModelList = new List <AwardModel>();                                                             //奖池
                    List <WXAwardsV1> awardsList     = bll.GetAwardsListV1(model.LotteryID).Where(p => p.WinCount < p.PrizeCount).ToList(); //奖品列表 //已经中完的不参与
                    foreach (var item in awardsList)
                    {
                        for (int i = 1; i <= item.Probability; i++)
                        {
                            AwardModel m = new AwardModel();
                            m.AwardID    = item.AutoID;
                            m.PrizeName  = item.PrizeName;
                            m.AwardsType = item.AwardsType;
                            m.Img        = item.Img;
                            m.Value      = item.Value;
                            awardModelList.Add(m);
                        }
                    }
                    if (awardsList.Sum(p => p.Probability) < 100)//总中奖概率小于100 补足
                    {
                        for (int i = 1; i <= (100 - (awardsList.Sum(p => p.Probability))); i++)
                        {
                            AwardModel m = new AwardModel();
                            m.AwardID   = 0;
                            m.PrizeName = "谢谢参与";
                            awardModelList.Add(m);
                        }
                    }
                    #endregion
                    //打乱数组顺序
                    awardModelList = GetRandomList <AwardModel>(awardModelList);
                    Random rand  = new Random();
                    int    index = rand.Next(0, awardModelList.Count);

                    #region 抽奖
                    if (awardModelList[index].AwardID > 0)//随机数中奖
                    {
                        string sqlUpdate = string.Format(" Update ZCJ_WXAwardsV1  Set WinCount+=1  where AutoID={0} And WinCount<PrizeCount ", awardModelList[index].AwardID);
                        if (ZentCloud.ZCBLLEngine.BLLBase.ExecuteSql(sqlUpdate) > 0)
                        {
                            int token = rand.Next(1111, 9999);
                            //插入中奖记录
                            WXLotteryRecordV1 record = new WXLotteryRecordV1();
                            record.InsertDate = DateTime.Now;
                            record.LotteryId  = model.LotteryID;
                            record.Token      = token.ToString();
                            record.WXAwardsId = awardModelList[index].AwardID;
                            record.UserId     = currentUserInfo.UserID;
                            record.IsGetPrize = 0;
                            if (bll.AddWXLotteryRecordV1(record))
                            {
                                apiResult.awardName  = string.Format("{0}", awardModelList[index].PrizeName);
                                apiResult.isAward    = true;
                                apiResult.awardsType = awardModelList[index].AwardsType;
                                apiResult.img        = awardModelList[index].Img;
                                apiResult.value      = awardModelList[index].Value;

                                if (apiResult.awardsType == 2)
                                {
                                    BLLJIMP.BLLCardCoupon bllCardCoupon = new BLLJIMP.BLLCardCoupon();

                                    var coupon = bllCardCoupon.GetCardCoupon(int.Parse(apiResult.value));
                                    apiResult.cardcoupon_name  = coupon.Name;
                                    apiResult.cardcoupon_type  = coupon.CardCouponType;
                                    apiResult.cardcoupon_start = coupon.ValidFrom == null ? "" : coupon.ValidFrom.Value.ToShortDateString();
                                    apiResult.cardcoupon_end   = coupon.ValidTo == null ? "" : coupon.ValidTo.Value.ToShortDateString();
                                    if (coupon.ExpireTimeType == "1")
                                    {
                                        apiResult.cardcoupon_start = DateTime.Now.ToShortDateString();
                                        apiResult.cardcoupon_end   = DateTime.Now.AddDays(Convert.ToInt32(coupon.ExpireDay)).ToShortDateString();
                                    }
                                }
                                if (apiResult.awardsType == 1 || apiResult.awardsType == 2)
                                {
                                    //中奖记录标记为已经领奖
                                    WXLotteryRecordV1 rec = bll.Get <WXLotteryRecordV1>(string.Format(" UserId='{0}' And LotteryId={1} And WXAwardsId={2} And Token='{3}'", record.UserId, record.LotteryId, record.WXAwardsId, record.Token));
                                    if (rec != null)
                                    {
                                        rec.IsGetPrize = 1;
                                        bll.Update(rec);
                                    }
                                }

                                goto outoff;
                            }
                            else
                            {
                                goto outoff;
                            }
                        }
                        else
                        {
                            goto outoff;
                        }

                        //}
                        //else
                        //{   //#region 虽然随机数中奖,但是奖项数量已经达到上限,重新随机抽奖
                        //    //if (reCount >= 5)
                        //    //{
                        //    goto outoff;
                        //    //}
                        //    //reCount++;
                        //    //goto start;
                        //}
                    }
                    else
                    {
                        //随机数未中奖
                    }
                    #endregion
                }
outoff:
                if (!string.IsNullOrEmpty(context.Request["callback"]))
                {
                    return(string.Format("{0}({1})", context.Request["callback"], Common.JSONHelper.ObjectToJson(apiResult)));
                }
                return(Common.JSONHelper.ObjectToJson(apiResult));
            }
            catch (Exception ex)
            {
                return(ex.ToString());
            }
        }