This commit is contained in:
hero920103 committed 2026-10-19 01:13:17 +08:00
1 parent 5718a00e31
commit 1850ac640e
226 files changed
+37772 -12071

No files matched your search

+22 -23
View File
@@ -9,6 +9,7 @@ import (
"time"
"server/models"
"server/pkg/identity"
"server/pkg/jwtutil"
beego "github.com/beego/beego/v2/server/web"
@@ -20,22 +21,7 @@ type BackendErpCustomerController struct {
}
func (c *BackendErpCustomerController) customerClaims() (*jwtutil.Claims, error) {
auth := c.Ctx.Request.Header.Get("Authorization")
if auth == "" {
return nil, fmt.Errorf("未登录")
}
parts := strings.SplitN(auth, " ", 2)
if len(parts) != 2 || parts[0] != "Bearer" {
return nil, fmt.Errorf("认证信息格式错误")
}
claims, err := jwtutil.ParseToken(parts[1])
if err != nil {
return nil, fmt.Errorf("无效的token")
}
if claims.UserType != "backend" {
return nil, fmt.Errorf("无权访问")
}
return claims, nil
return identity.Claims(c.Ctx.Request.Header.Get("Authorization"), identity.EndBackend)
}
func (c *BackendErpCustomerController) customerJsonErr(httpStatus, bizCode int, msg string) {
@@ -76,13 +62,16 @@ type customerFormPayload struct {
BankAccount string `json:"bank_account"`
RegisteredAddress string `json:"registered_address"`
RegisteredPhone string `json:"registered_phone"`
CreditLimit float64 `json:"credit_limit"`
PaymentDays int `json:"payment_days"`
}
// List GET /backend/erp/customer/list
func (c *BackendErpCustomerController) List() {
claims, err := c.customerClaims()
if err != nil {
c.customerJsonErr(401, 401, err.Error())
code := identity.Status(err)
c.customerJsonErr(code, code, err.Error())
return
}
@@ -158,7 +147,8 @@ func (c *BackendErpCustomerController) List() {
func (c *BackendErpCustomerController) Detail() {
claims, err := c.customerClaims()
if err != nil {
c.customerJsonErr(401, 401, err.Error())
code := identity.Status(err)
c.customerJsonErr(code, code, err.Error())
return
}
@@ -189,7 +179,8 @@ func (c *BackendErpCustomerController) Detail() {
func (c *BackendErpCustomerController) ConvertToSupplier() {
claims, err := c.customerClaims()
if err != nil {
c.customerJsonErr(401, 401, err.Error())
code := identity.Status(err)
c.customerJsonErr(code, code, err.Error())
return
}
id, _ := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
@@ -228,7 +219,8 @@ func (c *BackendErpCustomerController) ConvertToSupplier() {
func (c *BackendErpCustomerController) Create() {
claims, err := c.customerClaims()
if err != nil {
c.customerJsonErr(401, 401, err.Error())
code := identity.Status(err)
c.customerJsonErr(code, code, err.Error())
return
}
@@ -278,6 +270,8 @@ func (c *BackendErpCustomerController) Create() {
BankAccount: strings.TrimSpace(p.BankAccount),
RegisteredAddress: strings.TrimSpace(p.RegisteredAddress),
RegisteredPhone: strings.TrimSpace(p.RegisteredPhone),
CreditLimit: p.CreditLimit,
PaymentDays: p.PaymentDays,
OwnerUserID: fmt.Sprintf("%d", claims.UserID),
OwnerUserName: resolveUserName(claims),
CreateUserID: fmt.Sprintf("%d", claims.UserID),
@@ -320,7 +314,8 @@ func (c *BackendErpCustomerController) Create() {
func (c *BackendErpCustomerController) Update() {
claims, err := c.customerClaims()
if err != nil {
c.customerJsonErr(401, 401, err.Error())
code := identity.Status(err)
c.customerJsonErr(code, code, err.Error())
return
}
@@ -375,6 +370,8 @@ func (c *BackendErpCustomerController) Update() {
customer.BankAccount = strings.TrimSpace(p.BankAccount)
customer.RegisteredAddress = strings.TrimSpace(p.RegisteredAddress)
customer.RegisteredPhone = strings.TrimSpace(p.RegisteredPhone)
customer.CreditLimit = p.CreditLimit
customer.PaymentDays = p.PaymentDays
customer.UpdateTime = time.Now()
if p.RegisterTime != "" {
@@ -412,7 +409,8 @@ func (c *BackendErpCustomerController) Update() {
func (c *BackendErpCustomerController) Delete() {
claims, err := c.customerClaims()
if err != nil {
c.customerJsonErr(401, 401, err.Error())
code := identity.Status(err)
c.customerJsonErr(code, code, err.Error())
return
}
@@ -459,7 +457,8 @@ func (c *BackendErpCustomerController) Delete() {
func (c *BackendErpCustomerController) ToggleStatus() {
claims, err := c.customerClaims()
if err != nil {
c.customerJsonErr(401, 401, err.Error())
code := identity.Status(err)
c.customerJsonErr(code, code, err.Error())
return
}