package main

import (
	"strings"

	"github.com/shopspring/decimal"
	"github.com/sirupsen/logrus"
	"github.com/spf13/viper"
	"gogs.daxia.dev/huanan/pkg.daxia.dev/db"
	"nn.daxia.dev/model"
)

func main() {
	viper.Set("gormlog", true)
	viper.AddConfigPath("conf")
	viper.AddConfigPath("configs/qznn")

	viper.SetConfigName("config")
	viper.SetConfigType("yaml")

	viper.AutomaticEnv()
	viper.SetEnvPrefix("web")
	viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))

	// 从环境变量总读取
	err := viper.ReadInConfig()
	if err != nil {
		logrus.Fatal(err)
	}

	db.InitTest()

	createUser()

	//createDBTable()
}

func createUser() {
	var err error

	err = db.GetDB().Create(&model.User{
		Pid:           0,
		Name:          "test1",
		Nickname:      "test1",
		Mobile:        "1888888888",
		AccountType:   0,
		Status:        1,
		Balance:       decimal.NewFromInt(100),
		FZBalance:     decimal.NewFromInt(0),
		HeadImg:       "",
		Token:         "8bc766ae05120ad091e8e52c29e23c1e",
		City:          "shenzhen",
		ParentTree:    "group",
		ParentTreeStr: "",
	}).Error

	if err != nil {
		logrus.Fatal(err)
	}
}
