Example #1
0
        /// <summary>
        /// 密码修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <ValidateResult> UpdateUserPwd(UserLoginRequest model)
        {
            var userInfo       = ContextContainer.GetValue <UserInfo>(ContextExtensionTypes.CurrentUserInfo);
            var validateResult = new ValidateResult();

            try
            {
                var       crmRequestHelper = new CrmRequestHelper();
                XDocument fetchXdoc        = null;
                fetchXdoc = await _repository.GetUserPwd(model);

                var entities = await crmRequestHelper.ExecuteAsync(_crmService, "mcs_userkeys", fetchXdoc);

                if (entities.Results.Count > 0)
                {
                    var res    = entities.Results[0];
                    var entity = new CrmExecuteEntity("mcs_userkeys", res.Id);
                    model.pwd = EncrypHelper.encrypt(model.pwd);
                    if (!string.IsNullOrEmpty(model.pwd))
                    {
                        entity.Attributes.Add("mcs_hashvalue", model.pwd);
                    }
                    //c端用户实体
                    await _crmService.Update(entity, userInfo?.systemuserid);

                    #region 组装数据返回
                    validateResult.Result      = true;
                    validateResult.Description = "操作成功";
                }
                else
                {
                    validateResult.Result      = false;
                    validateResult.Description = "操作失败";
                }

                #endregion
            }
            catch (Exception e)
            {
                validateResult.Result      = false;
                validateResult.Description = e.Message;
            }

            return(validateResult);
        }
Example #2
0
        /// <summary>
        /// 账户登陆
        /// </summary>
        /// <param name="dealerListRequest"></param>
        /// <returns></returns>
        public async Task <ValidateResult <CrmEntity> > LoginAccount(UserLoginRequest request)
        {
            try
            {
                //密码加密MD5
                request.pwd = EncrypHelper.encrypt(request.pwd);
                var       validateResult   = new ValidateResult <CrmEntity>();
                var       crmRequestHelper = new CrmRequestHelper();
                XDocument fetchXdoc        = null;
                fetchXdoc = await _repository.LoginAccount(request);

                var entities = await crmRequestHelper.ExecuteAsync(_crmService, entityName, fetchXdoc);

                if (entities.Results.Count > 0)
                {
                    LoginLog(request, entities.Results[0].Id, (int)UserEnum.LoginlogEnum.成功);
                    validateResult.Result = true;
                    validateResult.Data   = entities.Results[0];
                }
                else
                {
                    fetchXdoc = await _repository.GetUser(request);

                    var ent = await crmRequestHelper.ExecuteAsync(_crmService, entityName, fetchXdoc);

                    LoginLog(request, ent.Results[0].Id, (int)UserEnum.LoginlogEnum.失败);
                    validateResult.Result      = false;
                    validateResult.Description = "账号密码错误!";
                }
                return(validateResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #3
0
        /// <summary>
        /// 修改新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <ValidateResult> AddUser(UserAddRequest model)
        {
            var userInfo       = ContextContainer.GetValue <UserInfo>(ContextExtensionTypes.CurrentUserInfo);
            var validateResult = new ValidateResult();

            try
            {
                //C端用户ID
                Guid id = Guid.NewGuid();
                //用户会员实体ID
                Guid memberid = Guid.NewGuid();

                var member = new CrmExecuteEntity("mcs_member", memberid);
                var entity = new CrmExecuteEntity(entityName, id);
                if (!string.IsNullOrEmpty(model.account))
                {
                    member.Attributes.Add("mcs_mobilephonemask", model.account);
                    member.Attributes.Add("mcs_mobile", model.account);
                    entity.Attributes.Add("mcs_phone", model.account);
                }
                if (!string.IsNullOrEmpty(model.birthday))
                {
                    entity.Attributes.Add("mcs_birthday", DateTime.Parse(model.birthday).ToUniversalTime());
                }
                if (!string.IsNullOrEmpty(model.company))
                {
                    entity.Attributes.Add("company", model.company);
                }
                if (!string.IsNullOrEmpty(model.description))
                {
                    entity.Attributes.Add("mcs_description", model.description);
                }
                if (model.gender != null)
                {
                    entity.Attributes.Add("mcs_gender", model.gender);
                }
                if (model.marriagestatus != null)
                {
                    entity.Attributes.Add("mcs_marriagestatus", model.marriagestatus);
                }
                if (!string.IsNullOrEmpty(model.mcs_cardid))
                {
                    entity.Attributes.Add("mcs_cardid", model.mcs_cardid);
                }
                if (!string.IsNullOrEmpty(model.mcs_email))
                {
                    entity.Attributes.Add("mcs_email", model.mcs_email);
                    member.Attributes.Add("mcs_email", model.mcs_email);
                }
                if (!string.IsNullOrEmpty(model.name))
                {
                    entity.Attributes.Add("mcs_name", model.name);
                }
                if (!string.IsNullOrEmpty(model.nickname))
                {
                    member.Attributes.Add("mcs_name", model.nickname);
                    member.Attributes.Add("mcs_nickname", model.nickname);
                    entity.Attributes.Add("mcs_nickname", model.nickname);
                }
                if (!string.IsNullOrEmpty(model.profession))
                {
                    entity.Attributes.Add("mcs_profession", model.profession);
                }
                if (!string.IsNullOrEmpty(model.signature))
                {
                    entity.Attributes.Add("mcs_signature", model.signature);
                }
                entity.Attributes.Add("mcs_memberid", new CrmEntityReference("mcs_member", memberid));

                member.Attributes.Add("mcs_userid", id.ToString());

                //添加会员实例
                var mcs_memberinstanceid = ContextContainer.GetValue <Guid>(ContextExtensionTypes.MemberInstanceId);
                if (mcs_memberinstanceid != Guid.Empty)
                {
                    member.Attributes.Add("mcs_memberinstanceid", new CrmEntityReference("mcs_memberinstance", mcs_memberinstanceid));
                }

                ////查询潜客是否存在
                //Guid contactEntityId = Guid.Empty;
                //for (int i = 0; i < 10; i++)
                //{
                //    if (contactEntityId == Guid.Empty)
                //    {
                //        XDocument cfetchXdoc = await _repository.GetContactByMobilePhone(model.account);
                //        var centities = await new CrmRequestHelper().ExecuteAsync(_crmService, "contact", cfetchXdoc);
                //        if (centities.Results != null && centities.Results.Count > 0)
                //        {
                //            contactEntityId = centities.Results[0].Id;
                //            member.Attributes.Add("mcs_customerid", new CrmEntityReference("contact", contactEntityId));
                //            break;
                //        }
                //    }
                //}
                //创建会员
                await _crmService.Create(member, userInfo?.systemuserid);

                //c端用户实体
                await _crmService.Create(entity, userInfo?.systemuserid);

                ///用户密码
                Guid userkeyid = Guid.NewGuid();
                entity            = new CrmExecuteEntity("mcs_userkeys", userkeyid);
                model.userkey.pwd = EncrypHelper.encrypt(model.userkey.pwd);
                entity.Attributes.Add("mcs_userid", new CrmEntityReference(entityName, id));
                entity.Attributes.Add("mcs_hashvalue", model.userkey.pwd);
                entity.Attributes.Add("mcs_keytype", model.userkey.keytype);
                entity.Attributes.Add("mcs_status", model.userkey.status);
                entity.Attributes.Add("mcs_certificationtype", model.userkey.certificationtype);
                await _crmService.Create(entity, userInfo?.systemuserid);

                //用户登陆
                Guid loginnamekeyid = Guid.NewGuid();
                entity = new CrmExecuteEntity("mcs_loginname", loginnamekeyid);
                entity.Attributes.Add("mcs_userid", new CrmEntityReference(entityName, id));
                entity.Attributes.Add("mcs_logintype", model.logintype);
                entity.Attributes.Add("mcs_name", model.account);
                entity.Attributes.Add("mcs_status", 1);
                await _crmService.Create(entity, userInfo?.systemuserid);

                ///唯一线索
                Guid leadid = Guid.NewGuid();
                entity = new CrmExecuteEntity("lead", leadid);
                entity.Attributes.Add("lastname", model.nickname);
                entity.Attributes.Add("mobilephone", model.phone);
                entity.Attributes.Add("mcs_userid", id.ToString());
                var       crmRequestHelper = new CrmRequestHelper();
                XDocument fetchXdoc        = null;
                fetchXdoc = await _repository.GetBehavior(_behavior);

                var entities = await crmRequestHelper.ExecuteAsync(_crmService, "mcs_behavior", fetchXdoc);

                if (entities.Results.Count > 0)
                {
                    entity.Attributes.Add("mcs_behaviorid", new CrmEntityReference("mcs_behavior", entities.Results[0].Id));
                }
                await _crmService.Create(entity, userInfo?.systemuserid);

                ///问题选择
                foreach (var item in model.quests)
                {
                    if (!string.IsNullOrEmpty(item.securityquestion) && !string.IsNullOrEmpty(item.answer))
                    {
                        Guid usersecurityquestionid = Guid.NewGuid();
                        entity = new CrmExecuteEntity("mcs_usersecurityquestion", usersecurityquestionid);
                        entity.Attributes.Add("mcs_userid", new CrmEntityReference(entityName, id));
                        entity.Attributes.Add("mcs_securityquestionid", new CrmEntityReference("mcs_securityquestion", Guid.Parse(item.securityquestion)));
                        entity.Attributes.Add("mcs_answer", item.answer);
                        await _crmService.Create(entity, userInfo?.systemuserid);
                    }
                }

                //积分充值接口调用
                //await IntegralCreate(IntegralReg_Key, id.ToString());

                #region 组装数据返回
                validateResult.Result      = true;
                validateResult.Description = "操作成功";
                #endregion
            }
            catch (Exception e)
            {
                validateResult.Result      = false;
                validateResult.Description = e.Message;
            }

            return(validateResult);
        }