Ejemplo n.º 1
0
        public IWsModel <ReqAccount, ResAccount> AccountSimple([FromBody] WsModel <ReqAccount, ResAccount> model)
        {
            if (model == null)
            {
                return(new WsModel <ReqAccount, ResAccount>().Fail(ErrorCode.PARAM_NULL, "参数为空"));
            }
            if (model.Request == null)
            {
                return(model.Fail(ErrorCode.PARAM_NULL, "参数为空"));
            }
            if (string.IsNullOrWhiteSpace(model.Request.OpenId))
            {
                return(model.Fail(ErrorCode.PARAM_NULL, "参数OpenId为空"));
            }
            // var  wxlog=  WxLogFactory.GetWxLogger(typeof(QueryAccountService));
            //Account account = new DbsAccount().ById(model.Request.AccountId);
            Account account = new DbsAccount().ByOpenId(model.Request.OpenId, ValidityState.Enabled);

            if (account == null)
            {
                return(model.Fail(ErrorCode.DB_NOTEXISTED, "用户不存在"));
            }
            LogDebug($"找到用户{account.Name}");
            LogInfo($"找到用户{account.Name}");
            LogError($"找到用户{account.Name}");
            var res = new ResAccount(account);

            return(model.Ok(res));
        }
Ejemplo n.º 2
0
        public IWsModel <ReqAddAccount, ResAccount> UpdateAccount([FromBody] WsModel <ReqAddAccount, ResAccount> model)
        {
            if (model == null)
            {
                return(new WsModel <ReqAddAccount, ResAccount>().Fail(ErrorCode.PARAM_NULL, "参数为空"));
            }
            if (model.Request == null)
            {
                return(model.Fail(ErrorCode.PARAM_NULL, "参数为空"));
            }
            if (string.IsNullOrWhiteSpace(model.Request.OpenId))
            {
                return(model.Fail(ErrorCode.PARAM_NULL, "参数为空"));
            }
            var retAccount = new DbsAccount().GetAccount(model.Request.OpenId);

            if (retAccount == null)
            {
                return(model.Fail(ErrorCode.DB_NOTEXISTED, "数据不存在"));
            }
            if (AlterModel(ref retAccount, model.Request))
            {
                var result = new DbaAccount().UpdateAccount(retAccount);
                if (result == 0)
                {
                    return(model.Fail(ErrorCode.DB_SAVE_FAILED, "修改失败"));
                }
            }
            var ret = new ResAccount(retAccount);

            return(model.Ok(ret));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取用户信息包含公司信息
        /// </summary>
        /// <param name="openid"></param>
        /// <returns></returns>
        public ResAccount GetAccountInfo(string openid, ValidityState state)
        {
            using (var dbs = WxDbFactory.GetDbContext("hch_dbs").MyDB)
            {
                ResAccount ret = dbs.Single <ResAccount>("SELECT acc.*,c.`Name`as CorporationName FROM ( SELECT * FROM Account WHERE OpenId=@openid and State=@state) AS acc INNER JOIN Corporation as c ON c.Id= acc.corporation where c.State=@state ", new { openid = openid, state = state });
                //var q = dbs.From<Account>().LeftJoin<Corporation>((a, c) => a.Corporation == c.Id).Where<Account>(a => a.Id == openid).Select<Account, Corporation>((x, c) => new { x,CorporationName=c.Name });
                //var ret = dbs.Single<dynamic>(q);

                //foreach (dynamic item in accret)
                //{
                //    string id = item.Id;

                //}
                return(ret);
            }
        }
Ejemplo n.º 4
0
        public IWsModel <ReqAddAccount, ResAccount> AddAccount([FromBody] WsModel <ReqAddAccount, ResAccount> model)
        {
            if (model == null)
            {
                return(new WsModel <ReqAddAccount, ResAccount>().Fail(ErrorCode.PARAM_NULL, "参数为空"));
            }
            if (model.Request == null)
            {
                return(model.Fail(ErrorCode.PARAM_NULL, "参数为空"));
            }
            if (!model.Request.Valid4AddAccount())
            {
                return(model.Fail(ErrorCode.PARAM_NULL, "参数为空"));
            }
            var dbs = new DbsAccount();

            if (dbs.GetAccount(model.Request.OpenId) != null)
            {
                return(model.Fail(ErrorCode.DB_EXISTED, "数据已存在"));
            }
            //验证公司是否存在
            if (dbs.GetCorporationInfo(model.Request.Corporation, ValidityState.Enabled) == null)
            {
                return(model.Fail(ErrorCode.DB_NOTEXISTED, "公司不存在"));
            }
            var account = new Account(model.Request.Wechat, model.Request.WechatName, model.Request.OpenId, model.Request.Corporation, model.Request.Sex, model.Request.Email, model.Request.Phone, model.Request.Name, ValidityState.Disabled, Identity.Staff, model.Request.Logo, DateTime.Now);
            var result  = new DbaAccount().AddAccount(account);

            if (result == 0)
            {
                return(model.Fail(ErrorCode.DB_SAVE_FAILED, "添加失败"));
            }
            var ret = new ResAccount(account);

            return(model.Ok(ret));
        }