Exemple #1
0
        /// <summary>
        /// 评价医生
        /// </summary>
        /// <param name="userId">用户GUID</param>
        /// <param name="doctorGuid">医生GUID</param>
        /// <param name="score">评价分数</param>
        private void GetScoreFromAddCommentForDoctor(string userId, string doctorGuid, int score)
        {
            try
            {
                var scoreRulesBiz = new ScoreRulesBiz();
                var count         = new CommentBiz().CountUserHasCommentTargetOneDayAsync(userId, doctorGuid, DateTime.Now).Result;
                if (count > 1)
                {
                    return;
                }
                switch (score)
                {
                case 5:

                    scoreRulesBiz.AddScoreByRules(doctorGuid, Common.EnumDefine.ActionEnum.Praise5, Common.EnumDefine.UserType.Doctor);
                    break;

                case 4:
                    scoreRulesBiz.AddScoreByRules(doctorGuid, Common.EnumDefine.ActionEnum.Praise4, Common.EnumDefine.UserType.Doctor);
                    break;

                case 3:
                    scoreRulesBiz.AddScoreByRules(doctorGuid, Common.EnumDefine.ActionEnum.Praise3, Common.EnumDefine.UserType.Doctor);
                    break;

                case 2:
                    scoreRulesBiz.AddScoreByRules(doctorGuid, Common.EnumDefine.ActionEnum.Praise2, Common.EnumDefine.UserType.Doctor);
                    break;

                case 1:
                    var sd = scoreRulesBiz.AddScoreByRules(doctorGuid, Common.EnumDefine.ActionEnum.Praise1, Common.EnumDefine.UserType.Doctor);
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Common.Helper.Logger.Error($"action:{nameof(GetScoreFromAddCommentForDoctor)}  userId:{userId}  doctorGuid:{doctorGuid}  score:{score}  message:{ex.Message}");
            }
        }
        public IActionResult Login([FromBody] LoginRequestDto request)
        {
            var biz   = new AccountBiz();
            var query = biz.GetUserByPhone(request.Phone);

            var model = query.FirstOrDefault(m => string.Equals(m.Password, CryptoHelper.AddSalt(m.UserGuid, request.Password), StringComparison.OrdinalIgnoreCase));

            if (model == null)
            {
                return(Failed(ErrorCode.InvalidIdPassword));
            }

            // 启用XMPP的情况下,就检查用户IM账号是否存在
            if (enableXmpp)
            {
                var status = Client.QueryStatusAsync(model.UserGuid);
                status.Wait();

                // 如果不存在,则注册该用户的IM账号
                if (status.Result == IMStatus.NotExist)
                {
                    RegisterIM(model);
                }
            }

            if (!string.IsNullOrWhiteSpace(request.OpenId) && request.OpenId != model.WechatOpenid)
            {
                model.WechatOpenid    = request.OpenId;
                model.LastUpdatedDate = DateTime.Now;
                var upRes = biz.UpdateUser(model);
                Logger.Debug($"用户登录时,更新用户({model.UserGuid}) openid 结果:请求参数{JsonConvert.SerializeObject(request)}  更新结果-{upRes.ToString()}");
            }

            var scoreBiz = new ScoreRulesBiz();

            scoreBiz.AddScoreByRules(model.UserGuid, ActionEnum.Login, request.UserType);

            var response = new LoginResponseDto
            {
                UserId   = model.UserGuid,
                NickName = model.NickName,
                Token    = CreateToken(model.UserGuid, request.UserType, request.Days > 0 ? request.Days : 999),
                Xmpp     = httpBind,
                Domain   = domain,
                RabbitMQ = rabbitMQws
            };

            return(Success(response));
        }
        public async Task <IActionResult> EnterpriseWeChatDoctorLogin([FromBody] DoctorLoginRequestDto request)
        {
            string typeSecret = string.Empty;

            if (request.Type == 0)
            {
                typeSecret = PlatformSettings.EnterpriseWeChatMobileSecret;
            }
            else
            {
                typeSecret = PlatformSettings.EnterpriseWeChatPCAgentid;
            }
            DoctorLoginResponseDto response = null;
            var result = await GetEnterpriseWeChatUserInfo(request.Code, typeSecret);

            if (result == null)
            {
                return(Failed(ErrorCode.Empty, "未找到对应用户信息"));
            }
            if (result.extattr == null || result.extattr.attrs == null || result.extattr.attrs.Length == 0)
            {
                return(Failed(ErrorCode.Empty, "未找到对应用户工号信息"));
            }
            var jobNumber = result.extattr.attrs.FirstOrDefault(a => a.name == "工号");

            if (jobNumber == null || string.IsNullOrEmpty(jobNumber.value))
            {
                return(Failed(ErrorCode.Empty, "用户工号信息为空"));
            }
            //根据工号找到对应的医生
            var doctor = await new DoctorBiz().GetByJobNumberDoctor(jobNumber.value);

            if (doctor == null)
            {
                return(Failed(ErrorCode.Empty, "未找到对应工号的医生"));
            }
            var biz   = new AccountBiz();
            var model = biz.GetUserById(doctor.DoctorGuid);

            if (model == null)
            {
                return(Failed(ErrorCode.Empty, "未找到对应的医生"));
            }
            //更新医生表企业微信用户Id
            if (doctor.WechatOpenid != result.userid)
            {
                doctor.WechatOpenid    = result.userid;
                doctor.LastUpdatedBy   = UserID;
                doctor.LastUpdatedDate = DateTime.Now;
                var resultUpdate = await new DoctorBiz().UpdateAsync(doctor);
            }
            // 启用XMPP的情况下,就检查用户IM账号是否存在
            if (enableXmpp)
            {
                var status = Client.QueryStatusAsync(model.UserGuid);
                status.Wait();

                // 如果不存在,则注册该用户的IM账号
                if (status.Result == IMStatus.NotExist)
                {
                    RegisterIM(model);
                }
            }

            var scoreBiz = new ScoreRulesBiz();
            await scoreBiz.AddScoreByRules(model.UserGuid, ActionEnum.Login, request.UserType);

            var resultDoctor = await new ReviewRecordBiz().GetLatestReviewRecordByTargetGuidAsync(doctor.DoctorGuid, Models.Manager.ReviewRecordModel.TypeEnum.Doctors.ToString());

            response = new DoctorLoginResponseDto
            {
                UserId          = model.UserGuid,
                NickName        = model.NickName,
                Token           = CreateToken(model.UserGuid, request.UserType, request.Days > 0 ? request.Days : 999),
                Xmpp            = httpBind,
                Domain          = domain,
                RabbitMQ        = rabbitMQws,
                RegisterState   = doctor?.Status,
                WhetherRegister = true,
                ApprovalMessage = resultDoctor?.RejectReason
            };
            return(Success(response));
        }
        public IActionResult Register([FromBody] PhonePasswordCodeRequestDto request)
        {
            var accountBiz = new AccountBiz();

            if (!accountBiz.VerifyCode(request.Phone, request.Code))
            {
                return(Failed(ErrorCode.VerificationCode, "手机验证码错误"));
            }

            var userID       = Guid.NewGuid().ToString("N");
            var saltPassword = CryptoHelper.AddSalt(userID, request.Password);

            if (string.IsNullOrEmpty(saltPassword))
            {
                return(Failed(ErrorCode.SystemException, "密码加盐失败"));
            }

            var biz  = new AccountBiz();
            var list = biz.GetUserByPhone(request.Phone);

            if (list.Any())
            {
                return(Failed(ErrorCode.DuplicatePhone, "该手机号已经注册"));
            }
            #region 获取用户是否有推荐关注公众号记录,若有,则将推荐人设为平台账户推荐人
            var recommendUser = TryGetSubscriptionRecommendUser(request.OpenId);
            if (!string.IsNullOrWhiteSpace(recommendUser))
            {
                request.Referrer = recommendUser;
            }
            #endregion
            var userModel = new UserModel
            {
                UserGuid      = userID,
                WechatOpenid  = request.OpenId,
                NickName      = userID.Substring(0, 6),
                UserName      = userID.Substring(0, 6),
                Phone         = request.Phone,
                Password      = saltPassword,
                Birthday      = new DateTime(2000, 1, 1),
                RecommendGuid = request.Referrer,
                CreatedBy     = userID,
                LastUpdatedBy = userID,
                OrgGuid       = "guodan"
            };

            var consumerModel = new ConsumerModel
            {
                ConsumerGuid  = userID,
                CreatedBy     = userID,
                LastUpdatedBy = userID
            };

            var registerModel = new RegisterModel
            {
                PlatformType = request.PlatformType,
                Parameters   = request.Parameters
            };

            var result = biz.Register(userModel, consumerModel, registerModel);

            if (result == null)
            {
                return(Failed(ErrorCode.DuplicatePhone));
            }

            if (result.Value)
            {
                var message = string.Empty;
                if (enableXmpp && !RegisterIM(userModel)) // 启用XMPP的情况下,才执行注册
                {
                    message = $"register im account failed. user id: {userID}, user phone: {request.Phone}";
                    Logger.Error(message);
                }

                var scoreBiz = new ScoreRulesBiz();
                scoreBiz.AddScoreByRules(userID, ActionEnum.Registered, UserType.Consumer);

                if (!string.IsNullOrEmpty(request.Referrer))
                {
                    scoreBiz.AddScoreByRules(request.Referrer, ActionEnum.RecommendRegistered, UserType.Doctor);
                    scoreBiz.AddScoreByRules(request.Referrer, ActionEnum.RecommendRegistered, UserType.Consumer);
                }

                return(Success(userID, message));
            }
            else
            {
                return(Failed(ErrorCode.DataBaseError));
            }
        }