init: 后端框架脚手架 (Go + Gin + GORM + MySQL)

- 项目目录结构:backend/ deploy/ schema/ migrations/
- 数据库 Schema:所有建表 SQL,含 hotel_id 多租户隔离
- Go 后端:config、model、handler、service、middleware、router
- 认证:账号密码登录 + JWT(Access + Refresh Token)
- 许可证:HMAC-SHA256 激活码生成 + 设备绑定验证
- 业务模块:商品、仓库、往来单位、入库、出库、库存、盘点
- 库存事务:入库/出库审核时原子更新库存 + 流水记录
- 数据导入:Excel/CSV 批量导入商品、往来单位
- Docker Compose:本地 MySQL + Adminer

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-04-04 01:24:53 +08:00
commit 0e42f0e417
39 changed files with 2989 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
package config
import (
"log"
"github.com/spf13/viper"
)
type Config struct {
Server ServerConfig
Database DatabaseConfig
JWT JWTConfig
License LicenseConfig
}
type ServerConfig struct {
Port string
Mode string // debug | release
}
type DatabaseConfig struct {
DSN string
}
type JWTConfig struct {
Secret string
AccessExpireMin int // Access Token 有效分钟数
RefreshExpireH int // Refresh Token 有效小时数
}
type LicenseConfig struct {
HMACSecret string // 许可证签名密钥
}
var C Config
func Load() {
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.AddConfigPath("./config")
// 环境变量覆盖(生产部署时使用)
viper.AutomaticEnv()
// 默认值
viper.SetDefault("server.port", "8080")
viper.SetDefault("server.mode", "debug")
viper.SetDefault("jwt.access_expire_min", 60)
viper.SetDefault("jwt.refresh_expire_h", 168) // 7天
if err := viper.ReadInConfig(); err != nil {
log.Println("[config] no config file found, using defaults and env vars")
}
if err := viper.Unmarshal(&C); err != nil {
log.Fatalf("[config] failed to unmarshal config: %v", err)
}
}
+15
View File
@@ -0,0 +1,15 @@
server:
port: "8080"
mode: "debug" # debug | release
database:
# 格式: user:pass@tcp(host:port)/dbname?charset=utf8mb4&parseTime=True&loc=Local
dsn: "root:password@tcp(127.0.0.1:3306)/jiu_db?charset=utf8mb4&parseTime=True&loc=Local"
jwt:
secret: "change-this-to-a-random-secret-in-production"
access_expire_min: 60
refresh_expire_h: 168
license:
hmac_secret: "change-this-license-secret-in-production"