示例#1
0
 public JsonResult AddUserPoint(int id = 0, int points = 0, int taskType = 0, string pointDesc = "")
 {
     if (taskType > 0)//关联任务的
     {
         UserTaskLogBll userTaskBll = new UserTaskLogBll();
         int            point       = userTaskBll.UserTaskLogAdd(id, taskType, pointDesc);
         if (point > 0)
         {
             return(Json(new { code = 1, msg = "操作成功增加" + point + "分" }));
         }
         else
         {
             return(Json(new { code = -100, msg = "未知错误" }));
         }
     }
     else
     {
         if (points == 0)
         {
             return(Json(new { code = -1, msg = "改动积分不能为0" }));
         }
         if (string.IsNullOrEmpty(pointDesc))
         {
             return(Json(new { code = -1, msg = "请添加积分备注" }));
         }
         int row = user.AddUserPoint(id, points, pointDesc);
         if (row > 0)
         {
             return(Json(new { code = 1, msg = "操作成功" }));
         }
         return(Json(new { code = -100, msg = "未知错误" }));
     }
 }
示例#2
0
        public virtual void DoTask(int uid, PointsEnum pointsEnum, out int points)
        {
            points = 0;
            UserTaskLogBll userTaskLog = new UserTaskLogBll();

            Dictionary <string, string> userTaskInfo = TaskHelper.GetEveryDayTask(uid);
            int taskKey = (int)pointsEnum;

            if (userTaskInfo != null)
            {
                if (!userTaskInfo.ContainsKey(taskKey.ToString()))//没有任务状态
                {
                    userTaskInfo = TaskHelper.GetEveryDayTask(uid, true);
                }
                if (userTaskInfo != null && userTaskInfo.ContainsKey(taskKey.ToString()) && userTaskInfo[taskKey.ToString()] == "-1")//未做过
                {
                    userTaskLog.UserTaskLogAdd(uid, taskKey);
                    TaskHelper.SetEveryDayTask(uid, taskKey, 0);
                }
            }
        }
示例#3
0
        /// <summary>
        /// 签到任务
        /// </summary>
        /// <returns></returns>
        public JsonResult EveryDaySign()
        {
            PublicUserModel loginUser = this.GetLoginUser();
            int             result    = 0;
            string          msg       = string.Empty;
            int             taskKey   = 0;
            int             timeOut   = 4;//四小时时间
            DateTime        nowTime   = DateTime.Now;

            //  return Json(new { status = nowTime.ToString(), msg = msg });
            #region 判断时间
            if (nowTime.Hour >= 8 && nowTime.Hour < 8 + timeOut)
            {
                taskKey = (int)PointsEnum.EveryDay_Sign_8;
            }
            else if (nowTime.Hour >= 15 && nowTime.Hour < 15 + timeOut)
            {
                taskKey = (int)PointsEnum.EveryDay_Sign_16;
            }
            #endregion


            if (taskKey > 0)
            {
                int addResult = 0;
                Dictionary <string, string> userTaskInfo = TaskHelper.GetEveryDayTask(loginUser.UserID);
                if (userTaskInfo != null)
                {
                    if (!userTaskInfo.ContainsKey(taskKey.ToString()))//没有任务状态
                    {
                        //   logger.Error("1",new Exception("重写了!" + loginUser.UserID));
                        userTaskInfo = TaskHelper.GetEveryDayTask(loginUser.UserID, true);
                    }
                    if (userTaskInfo != null)
                    {
                        //    logger.Error("2",new Exception("成功了!" + loginUser.UserID + " | " + taskKey + ":" + userTaskInfo[taskKey.ToString()]));
                        if (userTaskInfo.ContainsKey(taskKey.ToString()) && userTaskInfo[taskKey.ToString()] == "-1")//未做过
                        {
                            addResult = userTaskBll.UserTaskLogAdd(loginUser.UserID, taskKey);
                            TaskHelper.SetEveryDayTask(loginUser.UserID, taskKey, 0);
                        }
                        else
                        {
                            //     logger.Error("3",new Exception("失败!" + loginUser.UserID + " | " + addResult));

                            addResult = -2;
                        }
                    }
                }
                if (addResult > 0)
                {
                    result = userTaskBll.UserTaskLogDraw(loginUser.UserID, taskKey);
                    #region 结果
                    if (result <= 0)
                    {
                        logger.Debug("result:" + result);
                        switch (result)
                        {
                        case -1:
                            msg = "任务不存在";
                            break;

                        case -2:
                        case -3:
                            msg = "今日已签到";
                            break;

                        default:
                            msg = "未知错误";
                            break;
                        }
                    }
                    else
                    {
                        msg = "成功领取+" + result + "积分";
                    }
                    #endregion
                }
                else
                {
                    #region 结果

                    switch (addResult)
                    {
                    case -1:
                        msg = "任务不存在";
                        break;

                    case -2:
                    case -3:
                        msg = "今日已签到"; logger.Debug("addResult:" + addResult);
                        break;

                    default:
                        msg = "未知错误";
                        break;
                    }
                    #endregion
                }
            }
            else
            {
                result = -1;
                msg    = "领取时间未到";
            }
            return(Json(new { status = result, msg = msg }));
        }
示例#4
0
        public ApiResponse DaySign()
        {
            int      userId        = GetCurrentUserId();
            int      result        = 0;
            int      gainPoints    = 0;
            string   gainPointsMsg = "";
            int      taskKey       = 0;
            int      timeOut       = 4;//四小时时间
            DateTime nowTime       = DateTime.Now;

            #region 判断时间
            if (nowTime.Hour >= 8 && nowTime.Hour < 8 + timeOut)
            {
                taskKey = (int)PointsEnum.EveryDay_Sign_8;
            }
            else if (nowTime.Hour >= 15 && nowTime.Hour < 15 + timeOut)
            {
                taskKey = (int)PointsEnum.EveryDay_Sign_16;
            }
            #endregion


            if (taskKey > 0)
            {
                int addResult = 0;
                Dictionary <string, string> userTaskInfo = TaskHelper.GetEveryDayTask(userId);
                if (userTaskInfo != null)
                {
                    if (!userTaskInfo.ContainsKey(taskKey.ToString()))//没有任务状态
                    {
                        userTaskInfo = TaskHelper.GetEveryDayTask(userId, true);
                    }
                    if (userTaskInfo != null)
                    {
                        if (userTaskInfo.ContainsKey(taskKey.ToString()) && userTaskInfo[taskKey.ToString()] == "-1")//未做过
                        {
                            addResult = userTaskLog.UserTaskLogAdd(userId, taskKey);
                            TaskHelper.SetEveryDayTask(userId, taskKey, 0);
                        }
                    }
                }
                if (addResult > 0)
                {
                    result = userTaskLog.UserTaskLogDraw(userId, taskKey);
                    #region 结果
                    if (result <= 0)
                    {
                        switch (result)
                        {
                        case -1:
                            return(new ApiResponse(Metas.Task_Null));

                        case -2:
                        case -3:
                            return(new ApiResponse(Metas.Sign_EXISTS));

                        default:
                            return(new ApiResponse(Metas.Sign_EXISTS));
                        }
                    }
                    else
                    {
                        gainPoints    = result;
                        gainPointsMsg = "成功领取+" + result + "积分";
                    }
                    #endregion
                }
                else
                {
                    #region 结果

                    switch (addResult)
                    {
                    case -1:
                        return(new ApiResponse(Metas.Task_Null));

                    case -2:
                    case -3:
                        return(new ApiResponse(Metas.Sign_EXISTS));

                    default:
                        return(new ApiResponse(Metas.Sign_EXISTS));
                    }
                    #endregion
                }
            }
            else
            {
                return(new ApiResponse(Metas.Appointed_Time));

                gainPointsMsg = "";
            }
            var response = new
            {
                GainPoints    = gainPoints,
                GainPointsMsg = gainPointsMsg
            };
            return(new ApiResponse(Metas.SUCCESS, response));
        }