Exemplo n.º 1
0
        public JsonResult SignUp(SignUpViewModel model)
        {
            SysClientUser user = new SysClientUser();

            user.UserName       = model.UserName;
            user.PasswordHash   = model.Password;
            user.FirstName      = model.FirstName;
            user.LastName       = model.LastName;
            user.FavoriteColors = model.Colors == null ? null : string.Join(",", model.Colors);
            // user.FavoriteRetailers = model.Retailers == null ? null : string.Join(",", model.Retailers);
            user.Address = model.Address;
            var relay = new AspNetIdentiyAuthorizeRelay <SysClientUser>(CurrentDb);

            if (relay.UserExists(user.UserName.Trim()))
            {
                return(Json("text/html", ResultType.Failure, "This account already exists"));
            }

            bool r = relay.CreateUser(user);

            if (!r)
            {
                return(Json("text/html", ResultType.Failure, "Failure"));
            }

            CurrentDb.SaveChanges();


            SignIn(model.UserName, model.Password, false);



            return(Json(ResultType.Success, "Success"));
        }
Exemplo n.º 2
0
        public LoginResultModel(SysClientUser sysClientUser, string deviceId)
        {
            DateTime nowDate = DateTime.Now;

            this.UserId        = sysClientUser.Id;
            this.UserName      = sysClientUser.UserName;
            this.FullName      = sysClientUser.FullName;
            this.AccountType   = sysClientUser.ClientAccountType;
            this.MerchantId    = sysClientUser.MerchantId;
            this.MerchantCode  = sysClientUser.ClientCode;
            this.IsTestAccount = sysClientUser.IsTestAccount;
            this.DeviceId      = deviceId;
            var posMachine = CurrentDb.PosMachine.Where(m => m.DeviceId == deviceId).FirstOrDefault();


            if (posMachine == null)
            {
                this.PosMachineStatus = Enumeration.MerchantPosMachineStatus.NotMatch;
                return;
            }



            this.PosMachineId = posMachine.Id;

            var merchant = CurrentDb.Merchant.Where(m => m.Id == sysClientUser.MerchantId).FirstOrDefault();


            if (merchant == null)
            {
                this.PosMachineStatus = Enumeration.MerchantPosMachineStatus.NotMatch;
                return;
            }

            var merchantPosMachine = CurrentDb.MerchantPosMachine.Where(m => m.PosMachineId == posMachine.Id && m.MerchantId == sysClientUser.MerchantId).FirstOrDefault();


            if (merchantPosMachine == null)
            {
                this.PosMachineStatus = Enumeration.MerchantPosMachineStatus.NotMatch;
                return;
            }


            this.PosMachineStatus = merchantPosMachine.Status;

            if (merchantPosMachine.Status == Enumeration.MerchantPosMachineStatus.NoActive)
            {
                this.OrderInfo = BizFactory.Merchant.GetDepositRentOrder(merchant.Id, posMachine.Id);
            }
            else if (merchantPosMachine.Status == Enumeration.MerchantPosMachineStatus.Rentdue)
            {
                this.OrderInfo = BizFactory.Merchant.GetRentOrder(merchant.Id, posMachine.Id);
            }
        }
Exemplo n.º 3
0
        public LoginResultModel(SysClientUser sysClientUser, string fuselageNumber)
        {
            this.UserId      = sysClientUser.Id;
            this.UserName    = sysClientUser.UserName;
            this.FullName    = sysClientUser.FullName;
            this.AccountType = sysClientUser.ClientAccountType;
            this.MerchantId  = sysClientUser.MerchantId;

            var posMachine = CurrentDb.PosMachine.Where(m => m.FuselageNumber == fuselageNumber && m.MerchantId == sysClientUser.MerchantId).FirstOrDefault();

            if (posMachine != null)
            {
                this.PosMachineStatus = posMachine.Status;
            }
        }
Exemplo n.º 4
0
        private ClientUserModel GetClientUserModel(int userId)
        {
            ClientUserModel model = new ClientUserModel();
            SysClientUser   user  = CurrentDb.SysClientUser.Where(m => m.Id == userId).FirstOrDefault();

            model.Id                = user.Id;
            model.UserName          = user.UserName;
            model.PhoneNumber       = user.PhoneNumber;
            model.Email             = user.Email;
            model.FirstName         = user.FirstName;
            model.LastName          = user.LastName;
            model.FavoriteColors    = user.FavoriteColors;
            model.FavoriteRetailers = user.FavoriteRetailers;

            return(model);
        }
Exemplo n.º 5
0
        public APIResponse AddChildAccount(AddChildAccountModel model)
        {
            var token = CurrentDb.SysSmsSendHistory.Where(m => m.Token == model.Token && m.ValidCode == model.ValidCode && m.IsUse == false && m.ExpireTime >= DateTime.Now).FirstOrDefault();

            if (token == null)
            {
                return(ResponseResult(ResultType.Failure, ResultCode.Failure, "验证码错误"));
            }


            var isExists = CurrentDb.SysClientUser.Where(m => m.UserName == model.AccountPhone).FirstOrDefault();

            if (isExists != null)
            {
                return(ResponseResult(ResultType.Failure, ResultCode.Failure, "该手机号码已经存在"));
            }

            token.IsUse = true;

            SysClientUser sysClientUser = new SysClientUser();

            sysClientUser.UserName             = model.AccountPhone;
            sysClientUser.FullName             = model.AccountFullName;
            sysClientUser.PhoneNumber          = model.AccountPhone;
            sysClientUser.PasswordHash         = PassWordHelper.HashPassword(model.AccountPassword);
            sysClientUser.SecurityStamp        = Guid.NewGuid().ToString();
            sysClientUser.PhoneNumberConfirmed = true;
            sysClientUser.MerchantId           = model.MerchantId;
            sysClientUser.RegisterTime         = DateTime.Now;
            sysClientUser.ClientAccountType    = Enumeration.ClientAccountType.SubAccount;
            sysClientUser.Status     = Enumeration.UserStatus.Normal;
            sysClientUser.CreateTime = DateTime.Now;
            sysClientUser.Creator    = model.UserId;
            CurrentDb.SysClientUser.Add(sysClientUser);
            CurrentDb.SaveChanges();


            APIResult result = new APIResult()
            {
                Result = ResultType.Success, Code = ResultCode.Success, Message = "添加成功"
            };

            return(new APIResponse(result));
        }
Exemplo n.º 6
0
        public CustomJsonResult AddChildAccount(int operater, int userId, string fullName, string phoneNumber)
        {
            CustomJsonResult result = new CustomJsonResult();

            using (TransactionScope ts = new TransactionScope())
            {
                var masterAccount = CurrentDb.SysClientUser.Where(m => m.Id == userId).FirstOrDefault();
                var subAccount    = new SysClientUser();
                subAccount.UserName          = Guid.NewGuid().ToString().Replace("-", "");
                subAccount.PasswordHash      = PassWordHelper.HashPassword("888888");
                subAccount.SecurityStamp     = Guid.NewGuid().ToString();
                subAccount.RegisterTime      = this.DateTime;
                subAccount.CreateTime        = this.DateTime;
                subAccount.Creator           = operater;
                subAccount.ClientAccountType = Enumeration.ClientAccountType.SubAccount;
                subAccount.MerchantId        = masterAccount.MerchantId;
                subAccount.FullName          = fullName;
                subAccount.PhoneNumber       = phoneNumber;
                subAccount.Status            = Enumeration.UserStatus.Normal;

                CurrentDb.SysClientUser.Add(subAccount);
                CurrentDb.SaveChanges();

                var clientCode = CurrentDb.SysClientCode.Where(m => m.Id == subAccount.Id).FirstOrDefault();
                if (clientCode == null)
                {
                    return(new CustomJsonResult(ResultType.Failure, "开户失败,原因获取不到商户代码 "));
                }

                subAccount.ClientCode = clientCode.Code;
                subAccount.UserName   = clientCode.Code;


                CurrentDb.SaveChanges();
                ts.Complete();

                result      = new CustomJsonResult(ResultType.Success, "开户成功");
                result.Data = subAccount;
            }

            return(result);
        }
Exemplo n.º 7
0
        public CustomJsonResult LoginByMinProgram(RopOwnLoginByMinProgram rop)
        {
            var result = new CustomJsonResult();
            var ret    = new RetOwnLoginByMinProgram();

            var merch = CurrentDb.Merch.Where(m => m.Id == rop.MerchId && m.WxMpAppId == rop.AppId).FirstOrDefault();

            if (merch == null)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "商户信息认证失败"));
            }

            var wxAppInfoConfig = new WxAppInfoConfig();

            wxAppInfoConfig.AppId               = merch.WxMpAppId;
            wxAppInfoConfig.AppSecret           = merch.WxMpAppSecret;
            wxAppInfoConfig.PayMchId            = merch.WxPayMchId;
            wxAppInfoConfig.PayKey              = merch.WxPayKey;
            wxAppInfoConfig.PayResultNotifyUrl  = merch.WxPayResultNotifyUrl;
            wxAppInfoConfig.NotifyEventUrlToken = merch.WxPaNotifyEventUrlToken;


            var wxUserInfoByMinProram = SdkFactory.Wx.GetUserInfoByMinProramJsCode(wxAppInfoConfig, rop.EncryptedData, rop.Iv, rop.Code);

            if (wxUserInfoByMinProram == null)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "获取微信用户信息失败"));
            }

            var wxUserInfo = CurrentDb.WxUserInfo.Where(m => m.OpenId == wxUserInfoByMinProram.openId).FirstOrDefault();

            if (wxUserInfo == null)
            {
                string sysClientUserId = GuidUtil.New();

                var sysClientUser = new SysClientUser();

                sysClientUser.Id            = sysClientUserId;
                sysClientUser.UserName      = string.Format("wx{0}", Guid.NewGuid().ToString().Replace("-", ""));
                sysClientUser.PasswordHash  = PassWordHelper.HashPassword("888888");
                sysClientUser.SecurityStamp = Guid.NewGuid().ToString();
                sysClientUser.RegisterTime  = DateTime.Now;
                sysClientUser.Nickname      = wxUserInfoByMinProram.nickName;
                sysClientUser.Sex           = wxUserInfoByMinProram.gender;
                sysClientUser.Province      = wxUserInfoByMinProram.province;
                sysClientUser.City          = wxUserInfoByMinProram.city;
                sysClientUser.Country       = wxUserInfoByMinProram.country;
                sysClientUser.Avatar        = wxUserInfoByMinProram.avatarUrl;
                sysClientUser.IsVip         = false;
                sysClientUser.CreateTime    = DateTime.Now;
                sysClientUser.Creator       = sysClientUserId;
                sysClientUser.BelongSite    = Enumeration.BelongSite.Client;
                CurrentDb.SysClientUser.Add(sysClientUser);
                CurrentDb.SaveChanges();

                wxUserInfo              = new WxUserInfo();
                wxUserInfo.Id           = GuidUtil.New();
                wxUserInfo.MerchId      = rop.MerchId;
                wxUserInfo.AppId        = rop.AppId;
                wxUserInfo.ClientUserId = sysClientUser.Id;
                wxUserInfo.OpenId       = wxUserInfoByMinProram.openId;
                wxUserInfo.CreateTime   = DateTime.Now;
                wxUserInfo.Creator      = sysClientUserId;
                CurrentDb.WxUserInfo.Add(wxUserInfo);
                CurrentDb.SaveChanges();
            }
            else
            {
                var sysClientUser = CurrentDb.SysClientUser.Where(m => m.Id == wxUserInfo.ClientUserId).FirstOrDefault();
                if (sysClientUser != null)
                {
                    sysClientUser.Nickname = wxUserInfoByMinProram.nickName;
                    sysClientUser.Sex      = wxUserInfoByMinProram.gender;
                    sysClientUser.Province = wxUserInfoByMinProram.province;
                    sysClientUser.City     = wxUserInfoByMinProram.city;
                    sysClientUser.Country  = wxUserInfoByMinProram.country;
                    sysClientUser.Avatar   = wxUserInfoByMinProram.avatarUrl;
                }
                CurrentDb.SaveChanges();
            }

            var tokenInfo = new TokenInfo();

            ret.Token        = GuidUtil.New();
            tokenInfo.UserId = wxUserInfo.ClientUserId;

            SSOUtil.SetTokenInfo(ret.Token, tokenInfo, new TimeSpan(1, 0, 0));

            result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "登录成功", ret);

            return(result);
        }
Exemplo n.º 8
0
        public WxUserInfo CheckedUser(string pOperater, WxUserInfo pWxUserInfo)
        {
            WxUserInfo mod_UserInfo = null;

            LogUtil.Info(string.Format("开始检测用户信息:{0}", JsonConvert.SerializeObject(pWxUserInfo)));
            lock (goSettlelock)
            {
                try
                {
                    using (TransactionScope ts = new TransactionScope())
                    {
                        mod_UserInfo = CurrentDb.WxUserInfo.Where(m => m.OpenId == pWxUserInfo.OpenId).FirstOrDefault();
                        if (mod_UserInfo == null)
                        {
                            var sysClientUser = new SysClientUser();
                            sysClientUser.Id            = GuidUtil.New();
                            sysClientUser.UserName      = string.Format("wx{0}", Guid.NewGuid().ToString().Replace("-", ""));
                            sysClientUser.PasswordHash  = PassWordHelper.HashPassword("888888");
                            sysClientUser.SecurityStamp = Guid.NewGuid().ToString();
                            sysClientUser.RegisterTime  = this.DateTime;
                            sysClientUser.CreateTime    = this.DateTime;
                            sysClientUser.Creator       = pOperater;
                            sysClientUser.Type          = Enumeration.UserType.Client;
                            sysClientUser.Status        = Enumeration.UserStatus.Normal;
                            CurrentDb.SysClientUser.Add(sysClientUser);
                            CurrentDb.SaveChanges();

                            mod_UserInfo             = new WxUserInfo();
                            mod_UserInfo.Id          = GuidUtil.New();
                            mod_UserInfo.ClientId    = sysClientUser.Id;
                            mod_UserInfo.OpenId      = pWxUserInfo.OpenId;
                            mod_UserInfo.AccessToken = pWxUserInfo.AccessToken;
                            mod_UserInfo.ExpiresIn   = pWxUserInfo.ExpiresIn;
                            if (pWxUserInfo.Nickname != null)
                            {
                                mod_UserInfo.Nickname = pWxUserInfo.Nickname;
                            }
                            if (pWxUserInfo.Sex != null)
                            {
                                mod_UserInfo.Sex = pWxUserInfo.Sex;
                            }

                            if (pWxUserInfo.Province != null)
                            {
                                mod_UserInfo.Province = pWxUserInfo.Province;
                            }

                            if (pWxUserInfo.City != null)
                            {
                                mod_UserInfo.City = pWxUserInfo.City;
                            }

                            if (pWxUserInfo.Country != null)
                            {
                                mod_UserInfo.Country = pWxUserInfo.Country;
                            }

                            if (pWxUserInfo.HeadImgUrl != null)
                            {
                                mod_UserInfo.HeadImgUrl = pWxUserInfo.HeadImgUrl;
                            }

                            if (pWxUserInfo.UnionId != null)
                            {
                                mod_UserInfo.UnionId = pWxUserInfo.UnionId;
                            }
                            mod_UserInfo.CreateTime = this.DateTime;
                            mod_UserInfo.Creator    = pOperater;
                            CurrentDb.WxUserInfo.Add(mod_UserInfo);
                            CurrentDb.SaveChanges();

                            var fund = new Fund();
                            fund.Id               = GuidUtil.New();
                            fund.ClientId         = sysClientUser.Id;
                            fund.CurrentBalance   = 0;
                            fund.AvailableBalance = 0;
                            fund.LockBalance      = 0;
                            fund.CreateTime       = this.DateTime;
                            fund.Creator          = pOperater;
                            CurrentDb.Fund.Add(fund);
                            CurrentDb.SaveChanges();
                        }
                        else
                        {
                            mod_UserInfo.AccessToken = pWxUserInfo.AccessToken;
                            mod_UserInfo.ExpiresIn   = pWxUserInfo.ExpiresIn;

                            if (pWxUserInfo.Nickname != null)
                            {
                                mod_UserInfo.Nickname = pWxUserInfo.Nickname;
                            }
                            if (pWxUserInfo.Sex != null)
                            {
                                mod_UserInfo.Sex = pWxUserInfo.Sex;
                            }

                            if (pWxUserInfo.Province != null)
                            {
                                mod_UserInfo.Province = pWxUserInfo.Province;
                            }

                            if (pWxUserInfo.City != null)
                            {
                                mod_UserInfo.City = pWxUserInfo.City;
                            }

                            if (pWxUserInfo.Country != null)
                            {
                                mod_UserInfo.Country = pWxUserInfo.Country;
                            }

                            if (pWxUserInfo.HeadImgUrl != null)
                            {
                                mod_UserInfo.HeadImgUrl = pWxUserInfo.HeadImgUrl;
                            }

                            if (pWxUserInfo.UnionId != null)
                            {
                                mod_UserInfo.UnionId = pWxUserInfo.UnionId;
                            }
                            mod_UserInfo.MendTime = this.DateTime;
                            mod_UserInfo.Mender   = pOperater;
                        }



                        CurrentDb.SaveChanges();

                        ts.Complete();
                    }
                    LogUtil.Info(string.Format("结束检测用户信息:{0}", pWxUserInfo.OpenId));
                }
                catch (Exception ex)
                {
                    LogUtil.Error("检查微信用户系统发生异常", ex);
                }
            }

            return(mod_UserInfo);
        }
        public CustomJsonResult Run()
        {
            CustomJsonResult result = new CustomJsonResult();


            int operater = 0;

            using (TransactionScope ts = new TransactionScope())
            {
                var posMachines = CurrentDb.PosMachine.Where(m => m.IsUse == false).ToList();

                Log.InfoFormat("准备生成商户账号{0}个", posMachines.Count());

                for (int i = 0; i < posMachines.Count; i++)
                {
                    var sysClientUser = new SysClientUser();
                    sysClientUser.UserName          = Guid.NewGuid().ToString().Replace("-", "");
                    sysClientUser.PasswordHash      = PassWordHelper.HashPassword("888888");
                    sysClientUser.SecurityStamp     = Guid.NewGuid().ToString();
                    sysClientUser.RegisterTime      = this.DateTime;
                    sysClientUser.CreateTime        = this.DateTime;
                    sysClientUser.Creator           = operater;
                    sysClientUser.ClientAccountType = Enumeration.ClientAccountType.MasterAccount;
                    sysClientUser.Status            = Enumeration.UserStatus.Normal;

                    CurrentDb.SysClientUser.Add(sysClientUser);
                    CurrentDb.SaveChanges();

                    var clientCode = CurrentDb.SysClientCode.Where(m => m.Id == sysClientUser.Id).FirstOrDefault();
                    if (clientCode == null)
                    {
                        Log.WarnFormat("生成商户账号{0}个", i + 1);
                        throw new Exception("客户代码已经用完,请马上生成客户代码");
                    }

                    sysClientUser.ClientCode = clientCode.Code;
                    sysClientUser.UserName   = clientCode.Code;

                    var merchant = new Merchant();
                    merchant.ClientCode = clientCode.Code;
                    merchant.UserId     = sysClientUser.Id;
                    merchant.CreateTime = this.DateTime;
                    merchant.Creator    = operater;
                    merchant.Status     = Enumeration.MerchantStatus.WaitFill;
                    CurrentDb.Merchant.Add(merchant);
                    CurrentDb.SaveChanges();

                    sysClientUser.MerchantId = merchant.Id;


                    posMachines[i].IsUse          = true;
                    posMachines[i].LastUpdateTime = this.DateTime;
                    posMachines[i].Mender         = operater;
                    CurrentDb.SaveChanges();

                    var bankCard = new BankCard();
                    bankCard.MerchantId = merchant.Id;
                    bankCard.UserId     = merchant.UserId;
                    bankCard.CreateTime = this.DateTime;
                    bankCard.Creator    = operater;
                    CurrentDb.BankCard.Add(bankCard);
                    CurrentDb.SaveChanges();

                    var merchantPosMachine = new MerchantPosMachine();
                    merchantPosMachine.PosMachineId = posMachines[i].Id;
                    merchantPosMachine.BankCardId   = bankCard.Id;
                    merchantPosMachine.UserId       = sysClientUser.Id;
                    merchantPosMachine.MerchantId   = merchant.Id;
                    merchantPosMachine.Status       = Enumeration.MerchantPosMachineStatus.NoActive;
                    merchantPosMachine.CreateTime   = this.DateTime;
                    merchantPosMachine.Creator      = operater;
                    merchantPosMachine.Deposit      = posMachines[i].Deposit;
                    merchantPosMachine.Rent         = posMachines[i].Rent;
                    CurrentDb.MerchantPosMachine.Add(merchantPosMachine);
                    CurrentDb.SaveChanges();

                    var fund = new Fund();
                    fund.UserId     = sysClientUser.Id;
                    fund.Arrearage  = 0;
                    fund.Balance    = 0;
                    fund.CreateTime = this.DateTime;
                    fund.Creator    = operater;
                    fund.MerchantId = merchant.Id;
                    CurrentDb.Fund.Add(fund);
                    CurrentDb.SaveChanges();



                    var orderToDepositRent = new OrderToDepositRent();
                    orderToDepositRent.MerchantId   = merchant.Id;
                    orderToDepositRent.PosMachineId = posMachines[i].Id;
                    orderToDepositRent.UserId       = sysClientUser.Id;
                    orderToDepositRent.CreateTime   = this.DateTime;
                    orderToDepositRent.Creator      = 0;
                    orderToDepositRent.SubmitTime   = this.DateTime;
                    orderToDepositRent.ProductType  = Enumeration.ProductType.PosMachineDepositRent;
                    orderToDepositRent.ProductName  = Enumeration.ProductType.PosMachineDepositRent.GetCnName();
                    orderToDepositRent.ProductId    = (int)Enumeration.ProductType.PosMachineDepositRent;

                    orderToDepositRent.Deposit = posMachines[i].Deposit;

                    CalculateRent calculateRent = new CalculateRent(merchantPosMachine.Rent);

                    orderToDepositRent.RentMonths  = 3;
                    orderToDepositRent.MonthlyRent = calculateRent.MonthlyRent;
                    orderToDepositRent.RentVersion = calculateRent.Version;
                    orderToDepositRent.RentTotal   = calculateRent.GetRent(orderToDepositRent.RentMonths);

                    orderToDepositRent.Price = posMachines[i].Deposit + orderToDepositRent.RentTotal;

                    orderToDepositRent.Status = Enumeration.OrderStatus.WaitPay;
                    CurrentDb.OrderToDepositRent.Add(orderToDepositRent);
                    CurrentDb.SaveChanges();
                    orderToDepositRent.Sn = Sn.Build(SnType.DepositRent, orderToDepositRent.Id);


                    CurrentDb.SaveChanges();

                    Log.InfoFormat("生成商户账号:{0},对应POS机DeviceId:{1}", clientCode.Code, posMachines[i].DeviceId);
                }

                ts.Complete();

                Log.InfoFormat("生成商户账号{0}个", posMachines.Count());
            }

            return(result);
        }
Exemplo n.º 10
0
        public CustomJsonResult OpenAccount(int operater, Merchant merchant, MerchantPosMachine merchantPosMachine, BankCard bankCard)
        {
            CustomJsonResult result = new CustomJsonResult();

            using (TransactionScope ts = new TransactionScope())
            {
                var sysClientUser = new SysClientUser();
                sysClientUser.UserName          = Guid.NewGuid().ToString().Replace("-", "");
                sysClientUser.PasswordHash      = PassWordHelper.HashPassword("888888");
                sysClientUser.SecurityStamp     = Guid.NewGuid().ToString();
                sysClientUser.RegisterTime      = this.DateTime;
                sysClientUser.CreateTime        = this.DateTime;
                sysClientUser.Creator           = operater;
                sysClientUser.ClientAccountType = Enumeration.ClientAccountType.MasterAccount;
                sysClientUser.Status            = Enumeration.UserStatus.Normal;

                CurrentDb.SysClientUser.Add(sysClientUser);
                CurrentDb.SaveChanges();

                var clientCode = CurrentDb.SysClientCode.Where(m => m.Id == sysClientUser.Id).FirstOrDefault();
                if (clientCode == null)
                {
                    return(new CustomJsonResult(ResultType.Failure, "开户失败,原因获取不到商户代码 "));
                }

                sysClientUser.ClientCode = clientCode.Code;
                sysClientUser.UserName   = clientCode.Code;

                merchant.ClientCode = clientCode.Code;
                merchant.UserId     = sysClientUser.Id;

                if (string.IsNullOrEmpty(merchant.Area))
                {
                    merchant.Area     = null;
                    merchant.AreaCode = null;
                }


                merchant.CreateTime = this.DateTime;
                merchant.Creator    = operater;
                merchant.Status     = Enumeration.MerchantStatus.WaitFill;
                CurrentDb.Merchant.Add(merchant);
                CurrentDb.SaveChanges();

                sysClientUser.MerchantId = merchant.Id;


                var posMachine = CurrentDb.PosMachine.Where(m => m.Id == merchantPosMachine.PosMachineId).FirstOrDefault();
                if (posMachine == null)
                {
                    return(new CustomJsonResult(ResultType.Failure, "开户失败,找不到POS机"));
                }

                if (posMachine.IsUse)
                {
                    return(new CustomJsonResult(ResultType.Failure, "开户失败,POS机已经被使用"));
                }

                posMachine.IsUse          = true;
                posMachine.LastUpdateTime = this.DateTime;
                posMachine.Mender         = operater;
                CurrentDb.SaveChanges();

                bankCard.MerchantId = merchant.Id;
                bankCard.UserId     = merchant.UserId;
                bankCard.CreateTime = this.DateTime;
                bankCard.Creator    = operater;
                CurrentDb.BankCard.Add(bankCard);
                CurrentDb.SaveChanges();

                merchantPosMachine.BankCardId = bankCard.Id;
                merchantPosMachine.UserId     = sysClientUser.Id;
                merchantPosMachine.MerchantId = merchant.Id;
                merchantPosMachine.Status     = Enumeration.MerchantPosMachineStatus.NoActive;
                merchantPosMachine.CreateTime = this.DateTime;
                merchantPosMachine.Creator    = operater;
                merchantPosMachine.Deposit    = posMachine.Deposit;
                merchantPosMachine.Rent       = posMachine.Rent;
                CurrentDb.MerchantPosMachine.Add(merchantPosMachine);


                Fund fund = new Fund();
                fund.UserId     = sysClientUser.Id;
                fund.Arrearage  = 0;
                fund.Balance    = 0;
                fund.CreateTime = this.DateTime;
                fund.Creator    = operater;
                fund.MerchantId = merchant.Id;
                CurrentDb.Fund.Add(fund);

                //暂定在这里开启
                BizFactory.BizProcessesAudit.Add(operater, Enumeration.BizProcessesAuditType.MerchantAudit, merchant.Id, Enumeration.MerchantAuditStatus.WaitPrimaryAudit, "");


                CurrentDb.SaveChanges();
                ts.Complete();

                result = new CustomJsonResult(ResultType.Success, "开户成功");
            }

            return(result);
        }
        public CustomJsonResult CreateAccount(int operater, string token, string validCode, string userName, string password, string deviceId)
        {
            CustomJsonResult result = new CustomJsonResult();

            using (TransactionScope ts = new TransactionScope())
            {
                var code = CurrentDb.SysSmsSendHistory.Where(m => m.Token == token && m.ValidCode == validCode && m.IsUse == false && m.ExpireTime >= DateTime.Now).FirstOrDefault();
                if (code == null)
                {
                    return(new CustomJsonResult(ResultType.Failure, "验证码错误"));
                }

                code.IsUse = true;

                var isExists = CurrentDb.SysUser.Where(m => m.UserName == userName).FirstOrDefault();

                if (isExists != null)
                {
                    return(new CustomJsonResult(ResultType.Failure, "账号已经存在"));
                }

                var sysClientUser = new SysClientUser();
                sysClientUser.UserName          = userName;
                sysClientUser.PhoneNumber       = userName;
                sysClientUser.PasswordHash      = PassWordHelper.HashPassword(password);
                sysClientUser.SecurityStamp     = Guid.NewGuid().ToString();
                sysClientUser.RegisterTime      = this.DateTime;
                sysClientUser.CreateTime        = this.DateTime;
                sysClientUser.Creator           = operater;
                sysClientUser.ClientAccountType = Enumeration.ClientAccountType.MasterAccount;
                sysClientUser.Status            = Enumeration.UserStatus.Normal;
                sysClientUser.Type = Enumeration.UserType.Client;

                CurrentDb.SysClientUser.Add(sysClientUser);
                CurrentDb.SaveChanges();

                var clientCode = CurrentDb.SysClientCode.Where(m => m.Id == sysClientUser.Id).FirstOrDefault();

                var merchant = new Merchant();
                merchant.ClientCode = clientCode.Code;
                merchant.UserId     = sysClientUser.Id;
                merchant.CreateTime = this.DateTime;
                merchant.Creator    = operater;
                merchant.Status     = Enumeration.MerchantStatus.WaitFill;
                CurrentDb.Merchant.Add(merchant);
                CurrentDb.SaveChanges();

                sysClientUser.ClientCode = clientCode.Code;
                sysClientUser.MerchantId = merchant.Id;

                var posMachine = CurrentDb.PosMachine.Where(m => m.DeviceId == deviceId).FirstOrDefault();

                if (posMachine == null)
                {
                    return(new CustomJsonResult(ResultType.Failure, "POS机未登记,请联系客服"));

                    //posMachine = new PosMachine();
                    //posMachine.DeviceId = deviceId;
                    //posMachine.Creator = operater;
                    //posMachine.CreateTime = this.DateTime;
                    //CurrentDb.PosMachine.Add(posMachine);
                    //CurrentDb.SaveChanges();
                }
                else
                {
                    if (posMachine.IsUse)
                    {
                        return(new CustomJsonResult(ResultType.Failure, "POS机已被注册"));
                    }

                    if (posMachine.SalesmanId == null)
                    {
                        return(new CustomJsonResult(ResultType.Failure, "POS机未出库,请联系客服"));
                    }

                    posMachine.IsUse          = false;
                    posMachine.Mender         = operater;
                    posMachine.LastUpdateTime = this.DateTime;
                    CurrentDb.SaveChanges();
                }

                var bankCard = new BankCard();
                bankCard.MerchantId = merchant.Id;
                bankCard.UserId     = merchant.UserId;
                bankCard.CreateTime = this.DateTime;
                bankCard.Creator    = operater;
                CurrentDb.BankCard.Add(bankCard);
                CurrentDb.SaveChanges();

                CalculateServiceFee calculateServiceFee = new CalculateServiceFee();

                var merchantPosMachine = new MerchantPosMachine();
                merchantPosMachine.BankCardId       = bankCard.Id;
                merchantPosMachine.UserId           = sysClientUser.Id;
                merchantPosMachine.MerchantId       = merchant.Id;
                merchantPosMachine.PosMachineId     = posMachine.Id;
                merchantPosMachine.Deposit          = calculateServiceFee.Deposit;
                merchantPosMachine.MobileTrafficFee = calculateServiceFee.MobileTrafficFee;
                merchantPosMachine.Status           = Enumeration.MerchantPosMachineStatus.NoActive;
                merchantPosMachine.CreateTime       = this.DateTime;
                merchantPosMachine.Creator          = operater;
                CurrentDb.MerchantPosMachine.Add(merchantPosMachine);
                CurrentDb.SaveChanges();

                var orderToServiceFee = new OrderToServiceFee();
                orderToServiceFee.MerchantId       = merchant.Id;
                orderToServiceFee.PosMachineId     = posMachine.Id;
                orderToServiceFee.UserId           = sysClientUser.Id;
                orderToServiceFee.SubmitTime       = this.DateTime;
                orderToServiceFee.Type             = Enumeration.OrderType.PosMachineServiceFee;
                orderToServiceFee.TypeName         = Enumeration.OrderType.PosMachineServiceFee.GetCnName();
                orderToServiceFee.Deposit          = calculateServiceFee.Deposit;
                orderToServiceFee.MobileTrafficFee = calculateServiceFee.MobileTrafficFee;
                orderToServiceFee.PriceVersion     = calculateServiceFee.Version;
                orderToServiceFee.Price            = calculateServiceFee.Deposit + calculateServiceFee.MobileTrafficFee;
                orderToServiceFee.Status           = Enumeration.OrderStatus.WaitPay;
                orderToServiceFee.CreateTime       = this.DateTime;
                orderToServiceFee.Creator          = operater;
                CurrentDb.OrderToServiceFee.Add(orderToServiceFee);
                CurrentDb.SaveChanges();

                SnModel snModel = Sn.Build(SnType.OrderToServiceFee, orderToServiceFee.Id);
                orderToServiceFee.Sn = snModel.Sn;
                orderToServiceFee.TradeSnByWechat = snModel.TradeSnByWechat;
                orderToServiceFee.TradeSnByAlipay = snModel.TradeSnByAlipay;



                var sysItemCacheUpdateTime = new SysItemCacheUpdateTime();

                sysItemCacheUpdateTime.Name           = sysClientUser.UserName;
                sysItemCacheUpdateTime.Type           = Enumeration.SysItemCacheType.User;
                sysItemCacheUpdateTime.ReferenceId    = sysClientUser.Id;
                sysItemCacheUpdateTime.Creator        = operater;
                sysItemCacheUpdateTime.CreateTime     = this.DateTime;
                sysItemCacheUpdateTime.Mender         = operater;
                sysItemCacheUpdateTime.LastUpdateTime = this.DateTime;

                CurrentDb.SysItemCacheUpdateTime.Add(sysItemCacheUpdateTime);
                CurrentDb.SaveChanges();


                var fund = new Fund();

                fund.UserId     = sysClientUser.Id;
                fund.MerchantId = merchant.Id;
                fund.Balance    = 0;
                fund.Creator    = operater;
                fund.CreateTime = this.DateTime;
                CurrentDb.Fund.Add(fund);
                CurrentDb.SaveChanges();


                var lllegalQueryScore = new LllegalQueryScore();
                lllegalQueryScore.UserId     = sysClientUser.Id;
                lllegalQueryScore.MerchantId = merchant.Id;
                lllegalQueryScore.Score      = 50;
                lllegalQueryScore.Creator    = operater;
                lllegalQueryScore.CreateTime = this.DateTime;
                CurrentDb.LllegalQueryScore.Add(lllegalQueryScore);
                CurrentDb.SaveChanges();


                var lllegalQueryScoreTrans = new LllegalQueryScoreTrans();
                lllegalQueryScoreTrans.UserId      = sysClientUser.Id;
                lllegalQueryScoreTrans.ChangeScore = lllegalQueryScore.Score;
                lllegalQueryScoreTrans.Score       = lllegalQueryScore.Score;
                lllegalQueryScoreTrans.Type        = Enumeration.LllegalQueryScoreTransType.IncreaseByInit;
                lllegalQueryScoreTrans.Description = string.Format("初始违章查询积分:{0}", lllegalQueryScore.Score);
                lllegalQueryScoreTrans.Creator     = operater;
                lllegalQueryScoreTrans.CreateTime  = this.DateTime;
                CurrentDb.LllegalQueryScoreTrans.Add(lllegalQueryScoreTrans);
                CurrentDb.SaveChanges();
                lllegalQueryScoreTrans.Sn = Sn.Build(SnType.LllegalQueryScoreTrans, lllegalQueryScoreTrans.Id).Sn;
                CurrentDb.SaveChanges();


                ts.Complete();

                result = new CustomJsonResult(ResultType.Success, "注册成功");
            }

            return(result);
        }