public IActionResult CheckSignIn(UserType userType = UserType.Consumer)
        {
            var scoreBiz = new ScoreExBiz();
            var result   = scoreBiz.CheckInSendIntergral(UserID, userType.ToString());

            return(Success(result));
        }
        public async Task <IActionResult> CollectArticleOrQuestionSendIntergral(CollectArticleOrQuestionSendIntergralRequest request)
        {
            if (string.IsNullOrWhiteSpace(request.UserID))
            {
                request.UserID = UserID;
            }
            var isExist = new CollectionBiz().IsCollectTheTarget(request.UserID, request.TargetGuid);

            if (!isExist)
            {
                return(Failed(ErrorCode.DataBaseError, "该文章或问题还未收藏!"));
            }
            var scoreBiz = new ScoreExBiz();
            // 收藏1个问题可得3积分,每天9积分为上限
            var recordModelList = await scoreBiz.GetToDaysIntergralRecordByCondition(request.UserID, SendIntergralEnum.收藏文章或问题送积分.ToString());

            if (recordModelList == null || recordModelList.Count < 3)
            {
                if (!InsertIntergral(3, SendIntergralEnum.收藏文章或问题送积分, request.UserType))
                {
                    Logger.Error($"收藏文章或问题送积分失败!{JsonConvert.SerializeObject(request)}");
                }
            }
            //else
            //{
            //    //var totalIntergral = recordModelList.Select(a => a.Variation).Sum()>9;
            //    return Failed(ErrorCode.DataBaseError, "今日收藏文章或问题送积分次数已满!");
            //}
            return(Success());
        }
        public IActionResult RegisterSendIntergral(string Phone, UserType userType = UserType.Consumer)
        {
            //注册送积分 判断注册日期是否大于一天
            var userModel = new ConsumerBiz().GetModelByPhone(Phone).Result;

            if (userModel == null)
            {
                return(Success());
                //return Failed(ErrorCode.DataBaseError, "找不到该用户信息,请检查!");
            }
            var scoreModel = new ScoreExBiz().GetIntergralRecordByCondition(UserID, SendIntergralEnum.注冊送积分.ToString()).Result;

            if (scoreModel != null)
            {
                return(Success());
                //return Failed(ErrorCode.DataBaseError, "注册已送积分,该次无法赠送积分!");
            }
            TimeSpan interval          = DateTime.Now - userModel.CreationDate;
            var      isRegisteRightNow = interval.TotalHours < 24;

            if (!isRegisteRightNow)
            {
                return(Success());
                //return Failed(ErrorCode.UserData, "用户注册时间过久,注册送积分失败,请联系管理员!");
            }
            if (!InsertIntergral(150, SendIntergralEnum.注冊送积分, userType))
            {
                Common.Helper.Logger.Error($"注册送积分失败-RegisterSendIntergral({Phone})");
            }
            return(Success());
            //var isSucc = InsertIntergral(150, SendIntergralEnum.注冊送积分, userType);
            //return isSucc ? Success() : Failed(ErrorCode.DataBaseError, "注册送积分失败!");
        }
        [HttpGet, Produces(typeof(ResponseDto))]//, AllowAnonymous
        public async Task <IActionResult> CheckInSendIntergral(string userID, UserType userType = UserType.Consumer)
        {
            if (string.IsNullOrWhiteSpace(userID))
            {
                userID = UserID;
            }
            var scoreBiz = new ScoreExBiz();

            if (scoreBiz.CheckInSendIntergral(UserID, userType.ToString()))
            {
                return(Failed(ErrorCode.SystemException, "今日已签到"));
            }
            var theRightIntergral = 0;
            //连续签到 判断 一个月为期,首日签到1积分,连续签到递增1积分,
            //连续签到上限为7积分,连续签到8,9,10天均为7个积分,若中断则重新计算,一个月最多得189分
            var recordModel = await scoreBiz.GetCheckInSendIntergralRecord(UserID, SendIntergralEnum.连续签到送积分.ToString(), userType);

            if (recordModel != null && (DateTime.Now.Date - recordModel.CreationDate.Date).Days.Equals(1))
            {
                //满勤的情况
                var modelList = await scoreBiz.GetModelListByCondition(UserID, userType.ToString(), 30);

                theRightIntergral = recordModel.Variation < 7 ? recordModel.Variation + 1 : modelList.Where(a => a.Variation.Equals(7)).ToList().Count > 23 && modelList.Where(a => a.Variation.Equals(1)).ToList().Count == 1 && modelList[modelList.Count - 1].Variation == 1 ? 1 : 7;
            }
            else
            {
                theRightIntergral = 1;
            }
            var isSucc = InsertIntergral(theRightIntergral, SendIntergralEnum.连续签到送积分, userType);

            return(isSucc ? Success() : Failed(ErrorCode.DataBaseError, "签到积分插入错误"));
        }
        public IActionResult ImprovePersonalInformationToSendIntergral(UserType userType = UserType.Consumer)
        {
            var scoreModel = new ScoreExBiz().GetIntergralRecordByCondition(UserID, SendIntergralEnum.完善个人信息送积分.ToString()).Result;

            if (scoreModel != null)
            {
                return(Success());//Failed(ErrorCode.Empty, "完善个人信息积分已送,该次无法赠送积分!");
            }

            var uModel = new UserBiz().GetUser(UserID);

            if (uModel == null || !uModel.Enable)
            {
                return(Success());                                 //Failed(ErrorCode.DataBaseError, "用户状态不可用。");
            }
            var accModel = new AccessoryBiz().GetAccessoryModelByGuid(uModel.PortraitGuid);
            var outDto   = new GetUserInfoResponseDto
            {
                Portrait       = $"{accModel?.BasePath}{accModel?.RelativePath}", // +"/" 格式确认,
                NickName       = uModel.NickName,
                Gender         = uModel.Gender,
                Birthday       = uModel.Birthday,
                UserName       = uModel.UserName,
                IdentityNumber = uModel.IdentityNumber,
                Phone          = uModel.Phone
            };
            var result = false;

            PropertyInfo[] properties = outDto.GetType().GetProperties();
            foreach (var item in properties)
            {
                if (string.IsNullOrWhiteSpace(item.GetValue(outDto)?.ToString()))
                {
                    result = true;
                }
            }
            if (result)
            {
                return(Success());//Failed(ErrorCode.DataBaseError, "信息未完善,送积分失败!");
            }
            //完善个人信息,获50积分
            if (!InsertIntergral(50, SendIntergralEnum.完善个人信息送积分, userType))
            {
                Logger.Error($"完善个人信息送积分失败!{JsonConvert.SerializeObject(new { UserId = UserID })}");
            }
            return(Success());//isSucc ? Success() : Failed(ErrorCode.DataBaseError, "完善个人信息送积分失败!");
        }
        /// <summary>
        /// 积分操作(只是Consumer)
        /// </summary>
        /// <param name="variation"></param>
        /// <param name="reasonEnum"></param>
        /// <param name="userType"></param>
        /// <returns></returns>
        private bool InsertIntergral(int variation, SendIntergralEnum reasonEnum, UserType userType = UserType.Consumer)
        {
            var scoreBiz = new ScoreExBiz();
            var model    = new ScoreModel
            {
                ScoreGuid     = Guid.NewGuid().ToString("N"),
                Variation     = variation,
                Reason        = reasonEnum.ToString(),
                UserGuid      = UserID,
                UserTypeGuid  = string.IsNullOrWhiteSpace(userType.ToString()) ? "Consumer" : userType.ToString(),
                OrgGuid       = "",
                PlatformType  = "CloudDoctor",
                CreatedBy     = UserID,
                CreationDate  = DateTime.Now,
                LastUpdatedBy = UserID,
            };

            return(scoreBiz.InsertScore(model));
        }
        public async Task <IActionResult> ShareToSendIntergral(UserType userType = UserType.Consumer)
        {
            var scoreBiz = new ScoreExBiz();
            //每天分享内容1次即可获5积分,每天30分为上限
            var recordModelList = await scoreBiz.GetToDaysIntergralRecordByCondition(UserID, SendIntergralEnum.分享送积分.ToString());

            if (recordModelList == null || recordModelList.Count < 6)
            {
                if (!InsertIntergral(5, SendIntergralEnum.分享送积分, userType))
                {
                    Logger.Error($"分享送积分失败-{JsonConvert.SerializeObject(new { UserId = UserID })}");
                }
            }
            //else
            //{
            //    //var totalIntergral = recordModelList.Select(a => a.Variation).Sum()>30;
            //    return Failed(ErrorCode.DataBaseError, "今日分享送积分次数已满!");
            //}
            return(Success());
        }
        [HttpGet, Produces(typeof(ResponseDto <GetUserSignInDataCurrentMonthResponse>))]//,AllowAnonymous
        public async Task <IActionResult> GetUserSignInDataCurrentMonthAsync(GetUserSignInDataCurrentMonthRequest request)
        {
            if (string.IsNullOrWhiteSpace(request.UserID))
            {
                request.UserID = UserID;
            }
            var scoreBiz = new ScoreExBiz();
            GetUserSignInDataCurrentMonthResponse response = new GetUserSignInDataCurrentMonthResponse();
            var recordModel = await scoreBiz.GetCheckInSendIntergralRecord(request.UserID, SendIntergralEnum.连续签到送积分.ToString(), request.UserType);

            if (recordModel != null)
            {
                TimeSpan interval = DateTime.Now.Date - recordModel.CreationDate.Date;
                if (interval.Days.Equals(1) || interval.Days.Equals(0))
                {
                    var checkInInfoList = new List <GetUserSignInDataCurrentMonthResponse.CheckInInfo>();
                    if (recordModel.Variation < 7)
                    {
                        var modelListLessThan7 = await scoreBiz.GetModelListByCondition(request.UserID, request.UserType.ToString(), recordModel.Variation);

                        return(Success(GetResponseData(modelListLessThan7)));
                    }
                    var modelList = await scoreBiz.GetModelListByCondition(request.UserID, request.UserType.ToString(), 30);

                    var conditionModel = modelList.Take(7).Where(a => a.Variation.Equals(6)).ToList().Count == 0 ? modelList.Take(14).Where(a => a.Variation.Equals(6)).ToList().Count == 0 ? modelList.Take(21).Where(a => a.Variation.Equals(6)).ToList().Count == 0 ? modelList.Take(28).Where(a => a.Variation.Equals(6)).ToList().Count == 0 ? modelList.Where(a => a.Variation.Equals(6)).ToList() : modelList.Take(28).Where(a => a.Variation.Equals(6)).ToList() : modelList.Take(21).Where(a => a.Variation.Equals(6)).ToList() : modelList.Take(14).Where(a => a.Variation.Equals(6)).ToList() : modelList.Take(7).Where(a => a.Variation.Equals(6)).ToList();
                    if (conditionModel.Count != 1)
                    {
                        return(Failed(ErrorCode.DataBaseError, "数据有误,请联系管理员!"));
                    }
                    var dataIndex     = modelList.FindIndex(a => a.ScoreGuid.Equals(conditionModel[0].ScoreGuid));
                    var realModelList = modelList.Take(dataIndex + 6).ToList();
                    return(Success(GetResponseData(realModelList)));
                }
            }
            //重新签到
            var newModelList = new List <ScoreModel>();

            return(Success(GetResponseData(newModelList)));
        }