Commit 88b12c87 authored by shajiaiming's avatar shajiaiming

fix

parent 02f90c5a
...@@ -2,10 +2,11 @@ package models ...@@ -2,10 +2,11 @@ package models
import ( import (
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
"bwallet/pkg/setting"
) )
type Auth struct { type Auth struct {
ID int `gorm:"primary_key" json:"id"` Uid int `gorm:"primary_key" json:"uid"`
Username string `json:"username"` Username string `json:"username"`
Password string `json:"password"` Password string `json:"password"`
Group string `json:"group"` Group string `json:"group"`
...@@ -13,17 +14,17 @@ type Auth struct { ...@@ -13,17 +14,17 @@ type Auth struct {
} }
func (a Auth) TableName() string { func (a Auth) TableName() string {
return "coin_user" return setting.DatabaseSetting.Name_Manage + ".gli_admin"
} }
func CheckAuth(username, password string) (bool, error) { func CheckAuth(username, password string) (bool, error) {
var auth Auth var auth Auth
err := db.Select("id").Where(Auth{Username: username, Password: password}).First(&auth).Error err := db.Select("uid").Where(Auth{Username: username, Password: password}).First(&auth).Error
if err != nil && err != gorm.ErrRecordNotFound { if err != nil && err != gorm.ErrRecordNotFound {
return false, err return false, err
} }
if auth.ID > 0 { if auth.Uid > 0 {
return true, nil return true, nil
} }
...@@ -32,7 +33,7 @@ func CheckAuth(username, password string) (bool, error) { ...@@ -32,7 +33,7 @@ func CheckAuth(username, password string) (bool, error) {
func CheckToken(token string) (bool, error) { func CheckToken(token string) (bool, error) {
var auth Auth var auth Auth
err := db.Select("id").Where("access_token = ?", token).First(&auth).Error err := db.Select("uid").Where("access_token = ?", token).First(&auth).Error
if err != nil { if err != nil {
return false, err return false, err
} }
......
...@@ -2,6 +2,7 @@ package models ...@@ -2,6 +2,7 @@ package models
import ( import (
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
"bwallet/pkg/setting"
) )
type Chain struct { type Chain struct {
...@@ -16,7 +17,7 @@ type Chain struct { ...@@ -16,7 +17,7 @@ type Chain struct {
} }
func (c Chain) TableName() string { func (c Chain) TableName() string {
return "wallet_chain" return setting.DatabaseSetting.Name_Sources + ".wallet_chain"
} }
/** /**
......
...@@ -2,6 +2,7 @@ package models ...@@ -2,6 +2,7 @@ package models
import ( import (
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
"bwallet/pkg/setting"
) )
type Coin struct { type Coin struct {
...@@ -32,10 +33,9 @@ type Coin struct { ...@@ -32,10 +33,9 @@ type Coin struct {
} }
func (c Coin) TableName() string { func (c Coin) TableName() string {
return "wallet_coin" return setting.DatabaseSetting.Name_Sources + ".wallet_coin"
} }
/** /**
* 通过id检查币种是否存在 * 通过id检查币种是否存在
* @param id * @param id
......
...@@ -27,7 +27,7 @@ func Setup() { ...@@ -27,7 +27,7 @@ func Setup() {
setting.DatabaseSetting.User, setting.DatabaseSetting.User,
setting.DatabaseSetting.Password, setting.DatabaseSetting.Password,
setting.DatabaseSetting.Host, setting.DatabaseSetting.Host,
setting.DatabaseSetting.Name)) setting.DatabaseSetting.Name_Sources))
if err != nil { if err != nil {
log.Fatalf("models.Setup err: %v", err) log.Fatalf("models.Setup err: %v", err)
......
...@@ -2,6 +2,7 @@ package models ...@@ -2,6 +2,7 @@ package models
import ( import (
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
"bwallet/pkg/setting"
) )
type Wallet struct { type Wallet struct {
...@@ -16,7 +17,7 @@ type Wallet struct { ...@@ -16,7 +17,7 @@ type Wallet struct {
} }
func (w Wallet) TableName() string { func (w Wallet) TableName() string {
return "coin_platform" return setting.DatabaseSetting.Name_Sources + ".coin_platform"
} }
func ExistWalletById(id int) (bool, error) { func ExistWalletById(id int) (bool, error) {
......
...@@ -41,12 +41,14 @@ type Server struct { ...@@ -41,12 +41,14 @@ type Server struct {
var ServerSetting = &Server{} var ServerSetting = &Server{}
type Database struct { type Database struct {
Type string Type string
User string User string
Password string Password string
Host string Host string
Name string Name_Sources string
TablePrefix string Name_Manage string
Name_Coin string
TablePrefix string
} }
var DatabaseSetting = &Database{} var DatabaseSetting = &Database{}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment