0e42f0e417
- 项目目录结构: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>
72 lines
1.8 KiB
Go
72 lines
1.8 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/wangjia/jiu/backend/internal/middleware"
|
|
"github.com/wangjia/jiu/backend/internal/service"
|
|
)
|
|
|
|
type LicenseHandler struct {
|
|
svc *service.LicenseService
|
|
}
|
|
|
|
func NewLicenseHandler(svc *service.LicenseService) *LicenseHandler {
|
|
return &LicenseHandler{svc: svc}
|
|
}
|
|
|
|
// Activate POST /api/v1/license/activate
|
|
func (h *LicenseHandler) Activate(c *gin.Context) {
|
|
var req struct {
|
|
LicenseKey string `json:"license_key" binding:"required"`
|
|
DeviceID string `json:"device_id" binding:"required"`
|
|
}
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
lic, err := h.svc.Activate(req.LicenseKey, req.DeviceID)
|
|
if err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"data": lic})
|
|
}
|
|
|
|
// Verify GET /api/v1/license/verify
|
|
func (h *LicenseHandler) Verify(c *gin.Context) {
|
|
hotelID := middleware.GetHotelID(c)
|
|
deviceID := c.Query("device_id")
|
|
if deviceID == "" {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "device_id required"})
|
|
return
|
|
}
|
|
|
|
lic, err := h.svc.Verify(hotelID, deviceID)
|
|
if err != nil {
|
|
c.JSON(http.StatusForbidden, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"data": lic})
|
|
}
|
|
|
|
// Deactivate POST /api/v1/license/deactivate
|
|
func (h *LicenseHandler) Deactivate(c *gin.Context) {
|
|
hotelID := middleware.GetHotelID(c)
|
|
var req struct {
|
|
DeviceID string `json:"device_id" binding:"required"`
|
|
}
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
if err := h.svc.Deactivate(hotelID, req.DeviceID); err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"message": "deactivated"})
|
|
}
|