Merge branch 'master' of https://git.yunzer.cn/hero920103/go-platform
This commit is contained in:
commit
01426eda44
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
go-platform.zip
|
||||
server.exe
|
||||
58
controllers/api_software_upgrade.go
Normal file
58
controllers/api_software_upgrade.go
Normal file
@ -0,0 +1,58 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"server/models"
|
||||
"server/services"
|
||||
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// ApiSoftwareUpgradeController 开放接口:客户端检查更新(无需登录)
|
||||
type ApiSoftwareUpgradeController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// Check GET /api/softwareupgrade/check?code=desktop-app(可选 version 由客户端自行比对 latestVersion)
|
||||
func (c *ApiSoftwareUpgradeController) Check() {
|
||||
code := strings.TrimSpace(c.GetString("code"))
|
||||
if code == "" {
|
||||
c.Data["json"] = map[string]interface{}{"code": 400, "msg": "缺少参数 code(产品标识)"}
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
}
|
||||
|
||||
var row models.SystemSoftwareUpgrade
|
||||
err := models.Orm.QueryTable(new(models.SystemSoftwareUpgrade)).
|
||||
Filter("code", code).
|
||||
Filter("status", 1).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&row)
|
||||
if err != nil {
|
||||
c.Data["json"] = map[string]interface{}{"code": 404, "msg": "产品不存在或已停用"}
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
}
|
||||
|
||||
latest := strings.TrimSpace(row.LatestVersion)
|
||||
if latest == "" {
|
||||
latest = "0.0.0"
|
||||
}
|
||||
|
||||
scheme, host := services.PublicRequestBaseURL(&c.Controller)
|
||||
dl := services.ResolveSoftwareDownloadURL(scheme, host, row.DownloadURL, row.FileID)
|
||||
|
||||
data := map[string]interface{}{
|
||||
"latestVersion": latest,
|
||||
"downloadUrl": dl,
|
||||
"forceUpdate": row.ForceUpdate == 1,
|
||||
"releaseNotes": "",
|
||||
}
|
||||
if row.ReleaseNotes != nil {
|
||||
data["releaseNotes"] = *row.ReleaseNotes
|
||||
}
|
||||
|
||||
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "success", "data": data}
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
363
controllers/platform_complaint.go
Normal file
363
controllers/platform_complaint.go
Normal file
@ -0,0 +1,363 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"server/models"
|
||||
"server/pkg/jwtutil"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
type PlatformComplaintController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (c *PlatformComplaintController) platformClaims() (*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 != "platform" {
|
||||
return nil, fmt.Errorf("无权访问")
|
||||
}
|
||||
return claims, nil
|
||||
}
|
||||
|
||||
func (c *PlatformComplaintController) jsonErr(httpStatus, bizCode int, msg string) {
|
||||
c.Ctx.Output.SetStatus(httpStatus)
|
||||
c.Data["json"] = map[string]interface{}{"code": bizCode, "msg": msg}
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
func (c *PlatformComplaintController) ok(data interface{}) {
|
||||
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "success", "data": data}
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
func categoryNameMap(ids []uint64) map[uint64]string {
|
||||
m := make(map[uint64]string)
|
||||
if len(ids) == 0 {
|
||||
return m
|
||||
}
|
||||
seen := make(map[uint64]bool)
|
||||
var uniq []uint64
|
||||
for _, id := range ids {
|
||||
if id > 0 && !seen[id] {
|
||||
seen[id] = true
|
||||
uniq = append(uniq, id)
|
||||
}
|
||||
}
|
||||
if len(uniq) == 0 {
|
||||
return m
|
||||
}
|
||||
var cats []models.ComplaintCategory
|
||||
_, _ = models.Orm.QueryTable(new(models.ComplaintCategory)).
|
||||
Filter("id__in", uniq).
|
||||
Filter("delete_time__isnull", true).
|
||||
All(&cats)
|
||||
for _, x := range cats {
|
||||
m[x.ID] = x.Name
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// List GET /platform/complaint/list?page=1&pageSize=20&categoryId=&status=&keyword=
|
||||
func (c *PlatformComplaintController) List() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
page, _ := c.GetInt("page", 1)
|
||||
pageSize, _ := c.GetInt("pageSize", 20)
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
if pageSize < 1 {
|
||||
pageSize = 20
|
||||
}
|
||||
if pageSize > 200 {
|
||||
pageSize = 200
|
||||
}
|
||||
var categoryID uint64
|
||||
if s := strings.TrimSpace(c.GetString("categoryId")); s != "" {
|
||||
if v, err := strconv.ParseUint(s, 10, 64); err == nil {
|
||||
categoryID = v
|
||||
}
|
||||
}
|
||||
statusStr := strings.TrimSpace(c.GetString("status"))
|
||||
keyword := strings.TrimSpace(c.GetString("keyword"))
|
||||
|
||||
qs := models.Orm.QueryTable(new(models.PlatformComplaint)).Filter("delete_time__isnull", true)
|
||||
if categoryID > 0 {
|
||||
qs = qs.Filter("category_id", categoryID)
|
||||
}
|
||||
if statusStr != "" {
|
||||
if st, err := strconv.Atoi(statusStr); err == nil {
|
||||
qs = qs.Filter("status", st)
|
||||
}
|
||||
}
|
||||
if keyword != "" {
|
||||
cond := orm.NewCondition().
|
||||
Or("title__icontains", keyword).
|
||||
Or("content__icontains", keyword).
|
||||
Or("contact_name__icontains", keyword).
|
||||
Or("contact_phone__icontains", keyword).
|
||||
Or("contact_email__icontains", keyword)
|
||||
qs = qs.SetCond(cond)
|
||||
}
|
||||
|
||||
total, _ := qs.Count()
|
||||
var rows []models.PlatformComplaint
|
||||
_, err := qs.OrderBy("-id").Limit(pageSize, (page-1)*pageSize).All(&rows)
|
||||
if err != nil {
|
||||
c.jsonErr(500, 500, "获取失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
ids := make([]uint64, 0, len(rows))
|
||||
for _, r := range rows {
|
||||
ids = append(ids, r.CategoryID)
|
||||
}
|
||||
names := categoryNameMap(ids)
|
||||
list := make([]map[string]interface{}, 0, len(rows))
|
||||
for _, r := range rows {
|
||||
list = append(list, map[string]interface{}{
|
||||
"id": r.ID,
|
||||
"categoryId": r.CategoryID,
|
||||
"categoryName": names[r.CategoryID],
|
||||
"title": r.Title,
|
||||
"content": r.Content,
|
||||
"contactName": r.ContactName,
|
||||
"contactPhone": r.ContactPhone,
|
||||
"contactEmail": r.ContactEmail,
|
||||
"status": r.Status,
|
||||
"replyContent": r.ReplyContent,
|
||||
"replyTime": r.ReplyTime,
|
||||
"tid": r.Tid,
|
||||
"remark": r.Remark,
|
||||
"createTime": r.CreateTime,
|
||||
"updateTime": r.UpdateTime,
|
||||
})
|
||||
}
|
||||
c.ok(map[string]interface{}{
|
||||
"list": list,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"pageSize": pageSize,
|
||||
})
|
||||
}
|
||||
|
||||
// Detail GET /platform/complaint/:id
|
||||
func (c *PlatformComplaintController) Detail() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
c.jsonErr(400, 400, "无效ID")
|
||||
return
|
||||
}
|
||||
var row models.PlatformComplaint
|
||||
err = models.Orm.QueryTable(new(models.PlatformComplaint)).
|
||||
Filter("id", id).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&row)
|
||||
if err != nil {
|
||||
c.jsonErr(404, 404, "记录不存在")
|
||||
return
|
||||
}
|
||||
names := categoryNameMap([]uint64{row.CategoryID})
|
||||
c.ok(map[string]interface{}{
|
||||
"id": row.ID,
|
||||
"categoryId": row.CategoryID,
|
||||
"categoryName": names[row.CategoryID],
|
||||
"title": row.Title,
|
||||
"content": row.Content,
|
||||
"contactName": row.ContactName,
|
||||
"contactPhone": row.ContactPhone,
|
||||
"contactEmail": row.ContactEmail,
|
||||
"status": row.Status,
|
||||
"replyContent": row.ReplyContent,
|
||||
"replyTime": row.ReplyTime,
|
||||
"tid": row.Tid,
|
||||
"remark": row.Remark,
|
||||
"createTime": row.CreateTime,
|
||||
"updateTime": row.UpdateTime,
|
||||
})
|
||||
}
|
||||
|
||||
type complaintPayload struct {
|
||||
CategoryID *uint64 `json:"categoryId"`
|
||||
Title *string `json:"title"`
|
||||
Content *string `json:"content"`
|
||||
ContactName *string `json:"contactName"`
|
||||
ContactPhone *string `json:"contactPhone"`
|
||||
ContactEmail *string `json:"contactEmail"`
|
||||
Status *int8 `json:"status"`
|
||||
ReplyContent *string `json:"replyContent"`
|
||||
Tid *uint64 `json:"tid"`
|
||||
Remark *string `json:"remark"`
|
||||
}
|
||||
|
||||
// Create POST /platform/complaint
|
||||
func (c *PlatformComplaintController) Create() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
body, _ := io.ReadAll(c.Ctx.Request.Body)
|
||||
var p complaintPayload
|
||||
if err := json.Unmarshal(body, &p); err != nil {
|
||||
c.jsonErr(400, 400, "参数错误")
|
||||
return
|
||||
}
|
||||
if p.CategoryID == nil || *p.CategoryID == 0 || p.Title == nil || strings.TrimSpace(*p.Title) == "" ||
|
||||
p.Content == nil || strings.TrimSpace(*p.Content) == "" {
|
||||
c.jsonErr(400, 400, "分类、标题、内容不能为空")
|
||||
return
|
||||
}
|
||||
row := models.PlatformComplaint{
|
||||
CategoryID: *p.CategoryID,
|
||||
Title: strings.TrimSpace(*p.Title),
|
||||
Content: strings.TrimSpace(*p.Content),
|
||||
Status: 0,
|
||||
}
|
||||
if p.ContactName != nil {
|
||||
row.ContactName = p.ContactName
|
||||
}
|
||||
if p.ContactPhone != nil {
|
||||
row.ContactPhone = p.ContactPhone
|
||||
}
|
||||
if p.ContactEmail != nil {
|
||||
row.ContactEmail = p.ContactEmail
|
||||
}
|
||||
if p.Tid != nil {
|
||||
row.Tid = p.Tid
|
||||
}
|
||||
if p.Status != nil {
|
||||
row.Status = *p.Status
|
||||
}
|
||||
if p.Remark != nil {
|
||||
row.Remark = p.Remark
|
||||
}
|
||||
id, err := models.Orm.Insert(&row)
|
||||
if err != nil {
|
||||
c.jsonErr(500, 500, "创建失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
c.ok(map[string]interface{}{"id": id})
|
||||
}
|
||||
|
||||
// Update POST /platform/complaint/:id
|
||||
func (c *PlatformComplaintController) Update() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
c.jsonErr(400, 400, "无效ID")
|
||||
return
|
||||
}
|
||||
body, _ := io.ReadAll(c.Ctx.Request.Body)
|
||||
var p complaintPayload
|
||||
if err := json.Unmarshal(body, &p); err != nil {
|
||||
c.jsonErr(400, 400, "参数错误")
|
||||
return
|
||||
}
|
||||
up := map[string]interface{}{}
|
||||
if p.CategoryID != nil && *p.CategoryID > 0 {
|
||||
up["category_id"] = *p.CategoryID
|
||||
}
|
||||
if p.Title != nil {
|
||||
up["title"] = strings.TrimSpace(*p.Title)
|
||||
}
|
||||
if p.Content != nil {
|
||||
up["content"] = strings.TrimSpace(*p.Content)
|
||||
}
|
||||
if p.ContactName != nil {
|
||||
up["contact_name"] = p.ContactName
|
||||
}
|
||||
if p.ContactPhone != nil {
|
||||
up["contact_phone"] = p.ContactPhone
|
||||
}
|
||||
if p.ContactEmail != nil {
|
||||
up["contact_email"] = p.ContactEmail
|
||||
}
|
||||
if p.Status != nil {
|
||||
up["status"] = *p.Status
|
||||
}
|
||||
if p.ReplyContent != nil {
|
||||
s := strings.TrimSpace(*p.ReplyContent)
|
||||
up["reply_content"] = s
|
||||
if s != "" {
|
||||
now := time.Now()
|
||||
up["reply_time"] = now
|
||||
}
|
||||
}
|
||||
if p.Tid != nil {
|
||||
up["tid"] = p.Tid
|
||||
}
|
||||
if p.Remark != nil {
|
||||
up["remark"] = p.Remark
|
||||
}
|
||||
if len(up) == 0 {
|
||||
c.jsonErr(400, 400, "无更新字段")
|
||||
return
|
||||
}
|
||||
n, err := models.Orm.QueryTable(new(models.PlatformComplaint)).
|
||||
Filter("id", id).
|
||||
Filter("delete_time__isnull", true).
|
||||
Update(up)
|
||||
if err != nil {
|
||||
c.jsonErr(500, 500, "更新失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if n == 0 {
|
||||
c.jsonErr(404, 404, "记录不存在")
|
||||
return
|
||||
}
|
||||
c.ok(nil)
|
||||
}
|
||||
|
||||
// Delete DELETE /platform/complaint/:id
|
||||
func (c *PlatformComplaintController) Delete() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
c.jsonErr(400, 400, "无效ID")
|
||||
return
|
||||
}
|
||||
now := time.Now()
|
||||
n, err := models.Orm.QueryTable(new(models.PlatformComplaint)).
|
||||
Filter("id", id).
|
||||
Filter("delete_time__isnull", true).
|
||||
Update(map[string]interface{}{"delete_time": now})
|
||||
if err != nil {
|
||||
c.jsonErr(500, 500, "删除失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if n == 0 {
|
||||
c.jsonErr(404, 404, "记录不存在")
|
||||
return
|
||||
}
|
||||
c.ok(nil)
|
||||
}
|
||||
203
controllers/platform_complaint_category.go
Normal file
203
controllers/platform_complaint_category.go
Normal file
@ -0,0 +1,203 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"server/models"
|
||||
"server/pkg/jwtutil"
|
||||
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
type PlatformComplaintCategoryController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (c *PlatformComplaintCategoryController) platformClaims() (*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 != "platform" {
|
||||
return nil, fmt.Errorf("无权访问")
|
||||
}
|
||||
return claims, nil
|
||||
}
|
||||
|
||||
func (c *PlatformComplaintCategoryController) jsonErr(httpStatus, bizCode int, msg string) {
|
||||
c.Ctx.Output.SetStatus(httpStatus)
|
||||
c.Data["json"] = map[string]interface{}{"code": bizCode, "msg": msg}
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
func (c *PlatformComplaintCategoryController) ok(data interface{}) {
|
||||
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "success", "data": data}
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
// List GET /platform/complaintCategory/list
|
||||
func (c *PlatformComplaintCategoryController) List() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
var rows []models.ComplaintCategory
|
||||
_, err := models.Orm.QueryTable(new(models.ComplaintCategory)).
|
||||
Filter("delete_time__isnull", true).
|
||||
OrderBy("sort", "id").
|
||||
All(&rows)
|
||||
if err != nil {
|
||||
c.jsonErr(500, 500, "获取失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
c.ok(rows)
|
||||
}
|
||||
|
||||
// SelectList GET /platform/complaintCategory/select — 仅启用,供下拉
|
||||
func (c *PlatformComplaintCategoryController) SelectList() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
var rows []models.ComplaintCategory
|
||||
_, err := models.Orm.QueryTable(new(models.ComplaintCategory)).
|
||||
Filter("delete_time__isnull", true).
|
||||
Filter("status", 1).
|
||||
OrderBy("sort", "id").
|
||||
All(&rows)
|
||||
if err != nil {
|
||||
c.jsonErr(500, 500, "获取失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
c.ok(rows)
|
||||
}
|
||||
|
||||
type complaintCategoryPayload struct {
|
||||
Name *string `json:"name"`
|
||||
Code *string `json:"code"`
|
||||
Sort *int `json:"sort"`
|
||||
Status *int8 `json:"status"`
|
||||
}
|
||||
|
||||
// Create POST /platform/complaintCategory
|
||||
func (c *PlatformComplaintCategoryController) Create() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
body, _ := io.ReadAll(c.Ctx.Request.Body)
|
||||
var p complaintCategoryPayload
|
||||
if err := json.Unmarshal(body, &p); err != nil || p.Name == nil || strings.TrimSpace(*p.Name) == "" {
|
||||
c.jsonErr(400, 400, "分类名称不能为空")
|
||||
return
|
||||
}
|
||||
sort := 0
|
||||
if p.Sort != nil {
|
||||
sort = *p.Sort
|
||||
}
|
||||
st := int8(1)
|
||||
if p.Status != nil {
|
||||
st = *p.Status
|
||||
}
|
||||
row := models.ComplaintCategory{
|
||||
Name: strings.TrimSpace(*p.Name),
|
||||
Code: p.Code,
|
||||
Sort: sort,
|
||||
Status: st,
|
||||
}
|
||||
id, err := models.Orm.Insert(&row)
|
||||
if err != nil {
|
||||
c.jsonErr(500, 500, "创建失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
c.ok(map[string]interface{}{"id": id})
|
||||
}
|
||||
|
||||
// Update POST /platform/complaintCategory/:id
|
||||
func (c *PlatformComplaintCategoryController) Update() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
c.jsonErr(400, 400, "无效ID")
|
||||
return
|
||||
}
|
||||
body, _ := io.ReadAll(c.Ctx.Request.Body)
|
||||
var p complaintCategoryPayload
|
||||
if err := json.Unmarshal(body, &p); err != nil {
|
||||
c.jsonErr(400, 400, "参数错误")
|
||||
return
|
||||
}
|
||||
up := map[string]interface{}{}
|
||||
if p.Name != nil {
|
||||
up["name"] = strings.TrimSpace(*p.Name)
|
||||
}
|
||||
if p.Code != nil {
|
||||
up["code"] = strings.TrimSpace(*p.Code)
|
||||
}
|
||||
if p.Sort != nil {
|
||||
up["sort"] = *p.Sort
|
||||
}
|
||||
if p.Status != nil {
|
||||
up["status"] = *p.Status
|
||||
}
|
||||
if len(up) == 0 {
|
||||
c.jsonErr(400, 400, "无更新字段")
|
||||
return
|
||||
}
|
||||
n, err := models.Orm.QueryTable(new(models.ComplaintCategory)).
|
||||
Filter("id", id).
|
||||
Filter("delete_time__isnull", true).
|
||||
Update(up)
|
||||
if err != nil {
|
||||
c.jsonErr(500, 500, "更新失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if n == 0 {
|
||||
c.jsonErr(404, 404, "记录不存在")
|
||||
return
|
||||
}
|
||||
c.ok(nil)
|
||||
}
|
||||
|
||||
// Delete DELETE /platform/complaintCategory/:id
|
||||
func (c *PlatformComplaintCategoryController) Delete() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
c.jsonErr(400, 400, "无效ID")
|
||||
return
|
||||
}
|
||||
now := time.Now()
|
||||
n, err := models.Orm.QueryTable(new(models.ComplaintCategory)).
|
||||
Filter("id", id).
|
||||
Filter("delete_time__isnull", true).
|
||||
Update(map[string]interface{}{"delete_time": now})
|
||||
if err != nil {
|
||||
c.jsonErr(500, 500, "删除失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if n == 0 {
|
||||
c.jsonErr(404, 404, "记录不存在")
|
||||
return
|
||||
}
|
||||
c.ok(nil)
|
||||
}
|
||||
@ -23,13 +23,15 @@ type PlatformFileController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
const fileUploadMaxBytes = 50 * 1024 * 1024
|
||||
const fileUploadMaxMB = 200
|
||||
const fileUploadMaxBytes = fileUploadMaxMB * 1024 * 1024
|
||||
|
||||
var fileTypeByCategory = map[string]uint8{
|
||||
"image": 1,
|
||||
"document": 2,
|
||||
"video": 3,
|
||||
"audio": 4,
|
||||
"appsupgrade": 2,
|
||||
}
|
||||
|
||||
var allowedExtByCategory = map[string][]string{
|
||||
@ -37,6 +39,8 @@ var allowedExtByCategory = map[string][]string{
|
||||
"document": {"pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "txt"},
|
||||
"video": {"mp4", "webm", "mov"},
|
||||
"audio": {"mp3", "wav", "ogg"},
|
||||
// 安装包 / 软件升级(上传时 cate 选 appsupgrade 分类即可,扩展名在此放行)
|
||||
"appsupgrade": {"zip", "exe", "dmg", "msi", "msix", "apk", "deb", "rpm", "7z", "tar", "gz", "pkg"},
|
||||
}
|
||||
|
||||
func (c *PlatformFileController) platformClaims() (*jwtutil.Claims, error) {
|
||||
@ -90,7 +94,10 @@ func detectFileType(ext string) uint8 {
|
||||
for cat, exts := range allowedExtByCategory {
|
||||
for _, e := range exts {
|
||||
if e == ext {
|
||||
return fileTypeByCategory[cat]
|
||||
if t, ok := fileTypeByCategory[cat]; ok {
|
||||
return t
|
||||
}
|
||||
return 2
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -472,7 +479,7 @@ func (c *PlatformFileController) UploadFile() {
|
||||
defer fh.Close()
|
||||
|
||||
if header != nil && header.Size > fileUploadMaxBytes {
|
||||
c.jsonErr(400, 400, "文件大小不能超过50MB")
|
||||
c.jsonErr(400, 400, fmt.Sprintf("文件大小不能超过%dMB", fileUploadMaxMB))
|
||||
return
|
||||
}
|
||||
|
||||
@ -497,7 +504,7 @@ func (c *PlatformFileController) UploadFile() {
|
||||
}
|
||||
if n > fileUploadMaxBytes {
|
||||
_ = os.Remove(tmpPath)
|
||||
c.jsonErr(400, 400, "文件大小不能超过50MB")
|
||||
c.jsonErr(400, 400, fmt.Sprintf("文件大小不能超过%dMB", fileUploadMaxMB))
|
||||
return
|
||||
}
|
||||
sum, err := md5HashFile(tmpPath)
|
||||
|
||||
323
controllers/platform_software_upgrade.go
Normal file
323
controllers/platform_software_upgrade.go
Normal file
@ -0,0 +1,323 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"server/models"
|
||||
"server/pkg/jwtutil"
|
||||
"server/services"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
type PlatformSoftwareUpgradeController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (c *PlatformSoftwareUpgradeController) platformClaims() (*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 != "platform" {
|
||||
return nil, fmt.Errorf("无权访问")
|
||||
}
|
||||
return claims, nil
|
||||
}
|
||||
|
||||
func (c *PlatformSoftwareUpgradeController) jsonErr(httpStatus, bizCode int, msg string) {
|
||||
c.Ctx.Output.SetStatus(httpStatus)
|
||||
c.Data["json"] = map[string]interface{}{"code": bizCode, "msg": msg}
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
func (c *PlatformSoftwareUpgradeController) ok(data interface{}) {
|
||||
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "success", "data": data}
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
func (c *PlatformSoftwareUpgradeController) backfillDownloadURL(productID uint64) {
|
||||
var row models.SystemSoftwareUpgrade
|
||||
err := models.Orm.QueryTable(new(models.SystemSoftwareUpgrade)).
|
||||
Filter("id", productID).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&row)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if row.FileID == nil || *row.FileID == 0 {
|
||||
return
|
||||
}
|
||||
if row.DownloadURL != nil && strings.TrimSpace(*row.DownloadURL) != "" {
|
||||
return
|
||||
}
|
||||
scheme, host := services.PublicRequestBaseURL(&c.Controller)
|
||||
u := services.ResolveSoftwareDownloadURL(scheme, host, nil, row.FileID)
|
||||
if u == "" {
|
||||
return
|
||||
}
|
||||
_, _ = models.Orm.QueryTable(new(models.SystemSoftwareUpgrade)).
|
||||
Filter("id", productID).
|
||||
Update(map[string]interface{}{"download_url": u})
|
||||
}
|
||||
|
||||
func (c *PlatformSoftwareUpgradeController) rowToMap(row *models.SystemSoftwareUpgrade) map[string]interface{} {
|
||||
scheme, host := services.PublicRequestBaseURL(&c.Controller)
|
||||
resolved := services.ResolveSoftwareDownloadURL(scheme, host, row.DownloadURL, row.FileID)
|
||||
return map[string]interface{}{
|
||||
"id": row.ID,
|
||||
"name": row.Name,
|
||||
"code": row.Code,
|
||||
"latestVersion": row.LatestVersion,
|
||||
"fileId": row.FileID,
|
||||
"downloadUrl": row.DownloadURL,
|
||||
"resolvedDownloadUrl": resolved,
|
||||
"forceUpdate": row.ForceUpdate,
|
||||
"releaseNotes": row.ReleaseNotes,
|
||||
"status": row.Status,
|
||||
"sort": row.Sort,
|
||||
"createTime": row.CreateTime,
|
||||
"updateTime": row.UpdateTime,
|
||||
}
|
||||
}
|
||||
|
||||
// List GET /platform/softwareupgrade/list
|
||||
func (c *PlatformSoftwareUpgradeController) List() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
page, _ := c.GetInt("page", 1)
|
||||
pageSize, _ := c.GetInt("pageSize", 20)
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
if pageSize < 1 {
|
||||
pageSize = 20
|
||||
}
|
||||
if pageSize > 200 {
|
||||
pageSize = 200
|
||||
}
|
||||
keyword := strings.TrimSpace(c.GetString("keyword"))
|
||||
qs := models.Orm.QueryTable(new(models.SystemSoftwareUpgrade)).Filter("delete_time__isnull", true)
|
||||
if keyword != "" {
|
||||
cond := orm.NewCondition().Or("name__icontains", keyword).Or("code__icontains", keyword)
|
||||
qs = qs.SetCond(cond)
|
||||
}
|
||||
total, _ := qs.Count()
|
||||
var rows []models.SystemSoftwareUpgrade
|
||||
_, err := qs.OrderBy("sort", "-id").Limit(pageSize, (page-1)*pageSize).All(&rows)
|
||||
if err != nil {
|
||||
c.jsonErr(500, 500, "获取失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
list := make([]map[string]interface{}, 0, len(rows))
|
||||
for i := range rows {
|
||||
list = append(list, c.rowToMap(&rows[i]))
|
||||
}
|
||||
c.ok(map[string]interface{}{
|
||||
"list": list, "total": total, "page": page, "pageSize": pageSize,
|
||||
})
|
||||
}
|
||||
|
||||
// Detail GET /platform/softwareupgrade/:id
|
||||
func (c *PlatformSoftwareUpgradeController) Detail() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
c.jsonErr(400, 400, "无效ID")
|
||||
return
|
||||
}
|
||||
var row models.SystemSoftwareUpgrade
|
||||
err = models.Orm.QueryTable(new(models.SystemSoftwareUpgrade)).
|
||||
Filter("id", id).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&row)
|
||||
if err != nil {
|
||||
c.jsonErr(404, 404, "记录不存在")
|
||||
return
|
||||
}
|
||||
c.ok(c.rowToMap(&row))
|
||||
}
|
||||
|
||||
type softwareUpgradePayload struct {
|
||||
Name *string `json:"name"`
|
||||
Code *string `json:"code"`
|
||||
LatestVersion *string `json:"latestVersion"`
|
||||
FileID *uint64 `json:"fileId"`
|
||||
DownloadURL *string `json:"downloadUrl"`
|
||||
ForceUpdate *int8 `json:"forceUpdate"`
|
||||
ReleaseNotes *string `json:"releaseNotes"`
|
||||
Status *int8 `json:"status"`
|
||||
Sort *int `json:"sort"`
|
||||
}
|
||||
|
||||
// Create POST /platform/softwareupgrade
|
||||
func (c *PlatformSoftwareUpgradeController) Create() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
body, _ := io.ReadAll(c.Ctx.Request.Body)
|
||||
var p softwareUpgradePayload
|
||||
if err := json.Unmarshal(body, &p); err != nil {
|
||||
c.jsonErr(400, 400, "参数错误")
|
||||
return
|
||||
}
|
||||
if p.Name == nil || strings.TrimSpace(*p.Name) == "" || p.Code == nil || strings.TrimSpace(*p.Code) == "" {
|
||||
c.jsonErr(400, 400, "名称与产品标识 code 不能为空")
|
||||
return
|
||||
}
|
||||
v := "0.0.0"
|
||||
if p.LatestVersion != nil && strings.TrimSpace(*p.LatestVersion) != "" {
|
||||
v = strings.TrimSpace(*p.LatestVersion)
|
||||
}
|
||||
row := models.SystemSoftwareUpgrade{
|
||||
Name: strings.TrimSpace(*p.Name),
|
||||
Code: strings.TrimSpace(*p.Code),
|
||||
LatestVersion: v,
|
||||
DownloadURL: p.DownloadURL,
|
||||
ForceUpdate: 0,
|
||||
Status: 1,
|
||||
Sort: 0,
|
||||
}
|
||||
if p.ForceUpdate != nil {
|
||||
row.ForceUpdate = *p.ForceUpdate
|
||||
}
|
||||
if p.ReleaseNotes != nil {
|
||||
row.ReleaseNotes = p.ReleaseNotes
|
||||
}
|
||||
if p.Status != nil {
|
||||
row.Status = *p.Status
|
||||
}
|
||||
if p.Sort != nil {
|
||||
row.Sort = *p.Sort
|
||||
}
|
||||
if p.FileID != nil && *p.FileID > 0 {
|
||||
row.FileID = p.FileID
|
||||
}
|
||||
id, err := models.Orm.Insert(&row)
|
||||
if err != nil {
|
||||
if strings.Contains(strings.ToLower(err.Error()), "duplicate") {
|
||||
c.jsonErr(400, 400, "产品标识 code 已存在")
|
||||
return
|
||||
}
|
||||
c.jsonErr(500, 500, "创建失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
c.backfillDownloadURL(uint64(id))
|
||||
c.ok(map[string]interface{}{"id": id})
|
||||
}
|
||||
|
||||
// Update POST /platform/softwareupgrade/:id
|
||||
func (c *PlatformSoftwareUpgradeController) Update() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
c.jsonErr(400, 400, "无效ID")
|
||||
return
|
||||
}
|
||||
body, _ := io.ReadAll(c.Ctx.Request.Body)
|
||||
var p softwareUpgradePayload
|
||||
if err := json.Unmarshal(body, &p); err != nil {
|
||||
c.jsonErr(400, 400, "参数错误")
|
||||
return
|
||||
}
|
||||
up := map[string]interface{}{}
|
||||
if p.Name != nil {
|
||||
up["name"] = strings.TrimSpace(*p.Name)
|
||||
}
|
||||
if p.Code != nil {
|
||||
up["code"] = strings.TrimSpace(*p.Code)
|
||||
}
|
||||
if p.LatestVersion != nil {
|
||||
up["latest_version"] = strings.TrimSpace(*p.LatestVersion)
|
||||
}
|
||||
if p.FileID != nil {
|
||||
if *p.FileID == 0 {
|
||||
up["file_id"] = nil
|
||||
} else {
|
||||
up["file_id"] = *p.FileID
|
||||
}
|
||||
}
|
||||
if p.DownloadURL != nil {
|
||||
up["download_url"] = strings.TrimSpace(*p.DownloadURL)
|
||||
}
|
||||
if p.ForceUpdate != nil {
|
||||
up["force_update"] = *p.ForceUpdate
|
||||
}
|
||||
if p.ReleaseNotes != nil {
|
||||
up["release_notes"] = *p.ReleaseNotes
|
||||
}
|
||||
if p.Status != nil {
|
||||
up["status"] = *p.Status
|
||||
}
|
||||
if p.Sort != nil {
|
||||
up["sort"] = *p.Sort
|
||||
}
|
||||
if len(up) == 0 {
|
||||
c.jsonErr(400, 400, "无更新字段")
|
||||
return
|
||||
}
|
||||
n, err := models.Orm.QueryTable(new(models.SystemSoftwareUpgrade)).
|
||||
Filter("id", id).
|
||||
Filter("delete_time__isnull", true).
|
||||
Update(up)
|
||||
if err != nil {
|
||||
c.jsonErr(500, 500, "更新失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if n == 0 {
|
||||
c.jsonErr(404, 404, "记录不存在")
|
||||
return
|
||||
}
|
||||
c.backfillDownloadURL(id)
|
||||
c.ok(nil)
|
||||
}
|
||||
|
||||
// Delete DELETE /platform/softwareupgrade/:id
|
||||
func (c *PlatformSoftwareUpgradeController) Delete() {
|
||||
if _, err := c.platformClaims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
c.jsonErr(400, 400, "无效ID")
|
||||
return
|
||||
}
|
||||
now := time.Now()
|
||||
n, err := models.Orm.QueryTable(new(models.SystemSoftwareUpgrade)).
|
||||
Filter("id", id).
|
||||
Filter("delete_time__isnull", true).
|
||||
Update(map[string]interface{}{"delete_time": now})
|
||||
if err != nil {
|
||||
c.jsonErr(500, 500, "删除失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if n == 0 {
|
||||
c.jsonErr(404, 404, "记录不存在")
|
||||
return
|
||||
}
|
||||
c.ok(nil)
|
||||
}
|
||||
45
docs/sql/yz_complaint.sql
Normal file
45
docs/sql/yz_complaint.sql
Normal file
@ -0,0 +1,45 @@
|
||||
-- 投诉建议「产品分类」:区分用户针对哪类产品提建议
|
||||
-- 请在目标库手动执行(utf8mb4)
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `yz_system_complaint_category` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(64) NOT NULL COMMENT '分类名称,如:官网、租户后台、小程序',
|
||||
`code` varchar(32) DEFAULT NULL COMMENT '可选编码,便于程序识别',
|
||||
`sort` int NOT NULL DEFAULT 0 COMMENT '排序,越小越靠前',
|
||||
`status` tinyint NOT NULL DEFAULT 1 COMMENT '1启用 0禁用',
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
||||
`delete_time` datetime DEFAULT NULL COMMENT '软删',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_delete_time` (`delete_time`),
|
||||
KEY `idx_status` (`status`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='投诉建议-产品分类';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `yz_system_platform_complaint` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
`category_id` bigint unsigned NOT NULL COMMENT '产品分类ID',
|
||||
`title` varchar(200) NOT NULL COMMENT '标题',
|
||||
`content` text NOT NULL COMMENT '建议/投诉内容',
|
||||
`contact_name` varchar(64) DEFAULT NULL COMMENT '联系人',
|
||||
`contact_phone` varchar(32) DEFAULT NULL COMMENT '联系电话',
|
||||
`contact_email` varchar(128) DEFAULT NULL COMMENT '联系邮箱',
|
||||
`status` tinyint NOT NULL DEFAULT 0 COMMENT '0待处理 1处理中 2已回复 3已关闭',
|
||||
`reply_content` text COMMENT '平台回复内容',
|
||||
`reply_time` datetime DEFAULT NULL COMMENT '回复时间',
|
||||
`tid` bigint unsigned DEFAULT NULL COMMENT '可选:关联租户ID',
|
||||
`remark` varchar(512) DEFAULT NULL COMMENT '管理员内部备注',
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
||||
`delete_time` datetime DEFAULT NULL COMMENT '软删',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_category_id` (`category_id`),
|
||||
KEY `idx_status` (`status`),
|
||||
KEY `idx_delete_time` (`delete_time`),
|
||||
KEY `idx_tid` (`tid`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='平台端-投诉建议';
|
||||
|
||||
-- 可选:示例分类(执行完建表后按需取消注释)
|
||||
-- INSERT INTO `yz_system_complaint_category` (`name`,`code`,`sort`,`status`) VALUES
|
||||
-- ('官网','site',0,1),
|
||||
-- ('租户后台','tenant_admin',10,1),
|
||||
-- ('小程序','miniapp',20,1);
|
||||
21
docs/sql/yz_software_upgrade.sql
Normal file
21
docs/sql/yz_software_upgrade.sql
Normal file
@ -0,0 +1,21 @@
|
||||
-- 软件升级产品(客户端拉取版本与下载地址)
|
||||
-- 安装包建议上传到文件管理,分类使用「appsupgrade」(或任意分类,记录 file_id 即可)
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `yz_system_software_upgrade` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(128) NOT NULL COMMENT '软件显示名称',
|
||||
`code` varchar(64) NOT NULL COMMENT '客户端唯一标识,与 check 接口 code 一致',
|
||||
`latest_version` varchar(32) NOT NULL DEFAULT '0.0.0' COMMENT '当前发布的最新版本号',
|
||||
`file_id` bigint unsigned DEFAULT NULL COMMENT '关联 yz_system_files.id,安装包',
|
||||
`download_url` varchar(512) DEFAULT NULL COMMENT '完整下载地址;为空则用 file_id 对应 src 拼公开 URL',
|
||||
`force_update` tinyint NOT NULL DEFAULT 0 COMMENT '1 建议强制更新',
|
||||
`release_notes` varchar(2000) DEFAULT NULL COMMENT '更新说明',
|
||||
`status` tinyint NOT NULL DEFAULT 1 COMMENT '1 启用 0 停用',
|
||||
`sort` int NOT NULL DEFAULT 0,
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
||||
`delete_time` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_code` (`code`),
|
||||
KEY `idx_status_delete` (`status`,`delete_time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='软件升级产品';
|
||||
23
docs/服务端启动命令.md
Normal file
23
docs/服务端启动命令.md
Normal file
@ -0,0 +1,23 @@
|
||||
启动
|
||||
systemctl daemon-reload
|
||||
systemctl start go-api
|
||||
|
||||
查看是否成功
|
||||
systemctl status go-api
|
||||
|
||||
启动:systemctl start go-api
|
||||
停止:systemctl stop go-api
|
||||
重启:systemctl restart go-api
|
||||
查看状态:systemctl status go-api
|
||||
|
||||
|
||||
后台直接启动
|
||||
cd /www/wwwroot/api.yunzer.cn
|
||||
nohup go run main.go &
|
||||
|
||||
查看是否运行成功
|
||||
tail -f go.log
|
||||
|
||||
|
||||
下次要重启
|
||||
pkill go && cd /www/wwwroot/api.yunzer.cn && nohup go run main.go &
|
||||
@ -179,6 +179,10 @@ func shouldSkipLogging(method, url string) bool {
|
||||
if strings.HasPrefix(url, "/platform/login/getGeetest") || strings.HasPrefix(url, "/platform/login/getOpenVerify") {
|
||||
return true
|
||||
}
|
||||
// 客户端高频版本检查
|
||||
if strings.HasPrefix(url, "/api/softwareupgrade/check") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
19
models/complaint_category.go
Normal file
19
models/complaint_category.go
Normal file
@ -0,0 +1,19 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// ComplaintCategory 投诉建议产品分类 yz_system_complaint_category
|
||||
type ComplaintCategory struct {
|
||||
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
||||
Name string `orm:"column(name);size(64)" json:"name"`
|
||||
Code *string `orm:"column(code);size(32);null" json:"code"`
|
||||
Sort int `orm:"column(sort);default(0)" json:"sort"`
|
||||
Status int8 `orm:"column(status);default(1)" json:"status"`
|
||||
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"createTime"`
|
||||
UpdateTime *time.Time `orm:"column(update_time);auto_now;type(datetime);null" json:"updateTime"`
|
||||
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"deleteTime"`
|
||||
}
|
||||
|
||||
func (c *ComplaintCategory) TableName() string {
|
||||
return "yz_system_complaint_category"
|
||||
}
|
||||
@ -49,6 +49,9 @@ func Init(_ string) {
|
||||
new(SystemModules),
|
||||
new(PlatformLoginVerify),
|
||||
new(TenantSiteSetting),
|
||||
new(ComplaintCategory),
|
||||
new(PlatformComplaint),
|
||||
new(SystemSoftwareUpgrade),
|
||||
)
|
||||
|
||||
// 创建全局 Ormer
|
||||
|
||||
26
models/platform_complaint.go
Normal file
26
models/platform_complaint.go
Normal file
@ -0,0 +1,26 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// PlatformComplaint 平台投诉建议 yz_system_platform_complaint
|
||||
type PlatformComplaint struct {
|
||||
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
||||
CategoryID uint64 `orm:"column(category_id)" json:"categoryId"`
|
||||
Title string `orm:"column(title);size(200)" json:"title"`
|
||||
Content string `orm:"column(content);type(text)" json:"content"`
|
||||
ContactName *string `orm:"column(contact_name);size(64);null" json:"contactName"`
|
||||
ContactPhone *string `orm:"column(contact_phone);size(32);null" json:"contactPhone"`
|
||||
ContactEmail *string `orm:"column(contact_email);size(128);null" json:"contactEmail"`
|
||||
Status int8 `orm:"column(status);default(0)" json:"status"`
|
||||
ReplyContent *string `orm:"column(reply_content);type(text);null" json:"replyContent"`
|
||||
ReplyTime *time.Time `orm:"column(reply_time);type(datetime);null" json:"replyTime"`
|
||||
Tid *uint64 `orm:"column(tid);null" json:"tid"`
|
||||
Remark *string `orm:"column(remark);size(512);null" json:"remark"`
|
||||
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"createTime"`
|
||||
UpdateTime *time.Time `orm:"column(update_time);auto_now;type(datetime);null" json:"updateTime"`
|
||||
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"deleteTime"`
|
||||
}
|
||||
|
||||
func (p *PlatformComplaint) TableName() string {
|
||||
return "yz_system_platform_complaint"
|
||||
}
|
||||
24
models/system_software_upgrade.go
Normal file
24
models/system_software_upgrade.go
Normal file
@ -0,0 +1,24 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// SystemSoftwareUpgrade 软件升级产品 yz_system_software_upgrade
|
||||
type SystemSoftwareUpgrade struct {
|
||||
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
||||
Name string `orm:"column(name);size(128)" json:"name"`
|
||||
Code string `orm:"column(code);size(64);unique" json:"code"`
|
||||
LatestVersion string `orm:"column(latest_version);size(32)" json:"latestVersion"`
|
||||
FileID *uint64 `orm:"column(file_id);null" json:"fileId"`
|
||||
DownloadURL *string `orm:"column(download_url);size(512);null" json:"downloadUrl"`
|
||||
ForceUpdate int8 `orm:"column(force_update);default(0)" json:"forceUpdate"`
|
||||
ReleaseNotes *string `orm:"column(release_notes);size(2000);null" json:"releaseNotes"`
|
||||
Status int8 `orm:"column(status);default(1)" json:"status"`
|
||||
Sort int `orm:"column(sort);default(0)" json:"sort"`
|
||||
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"createTime"`
|
||||
UpdateTime *time.Time `orm:"column(update_time);auto_now;type(datetime);null" json:"updateTime"`
|
||||
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"deleteTime"`
|
||||
}
|
||||
|
||||
func (m *SystemSoftwareUpgrade) TableName() string {
|
||||
return "yz_system_software_upgrade"
|
||||
}
|
||||
57
pkg/versionutil/compare.go
Normal file
57
pkg/versionutil/compare.go
Normal file
@ -0,0 +1,57 @@
|
||||
package versionutil
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Compare 比较语义化版本号(按段数字比较,如 1.10.0 > 1.9.0)。不支持复杂 pre-release 规则。
|
||||
// 返回 -1 表示 a < b,0 表示相等,1 表示 a > b。
|
||||
func Compare(a, b string) int {
|
||||
pa := parseParts(a)
|
||||
pb := parseParts(b)
|
||||
maxLen := len(pa)
|
||||
if len(pb) > maxLen {
|
||||
maxLen = len(pb)
|
||||
}
|
||||
for i := 0; i < maxLen; i++ {
|
||||
var xa, xb int64
|
||||
if i < len(pa) {
|
||||
xa = pa[i]
|
||||
}
|
||||
if i < len(pb) {
|
||||
xb = pb[i]
|
||||
}
|
||||
if xa < xb {
|
||||
return -1
|
||||
}
|
||||
if xa > xb {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func parseParts(s string) []int64 {
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "" {
|
||||
return []int64{0}
|
||||
}
|
||||
if i := strings.IndexByte(s, '-'); i >= 0 {
|
||||
s = s[:i]
|
||||
}
|
||||
parts := strings.Split(s, ".")
|
||||
out := make([]int64, 0, len(parts))
|
||||
for _, p := range parts {
|
||||
p = strings.TrimSpace(p)
|
||||
n, err := strconv.ParseInt(p, 10, 64)
|
||||
if err != nil {
|
||||
n = 0
|
||||
}
|
||||
out = append(out, n)
|
||||
}
|
||||
if len(out) == 0 {
|
||||
return []int64{0}
|
||||
}
|
||||
return out
|
||||
}
|
||||
@ -1,7 +1,13 @@
|
||||
package api
|
||||
|
||||
// Register 注册移动端 / 开放 API(api)路由。
|
||||
// 按 /api/* 规则补充具体接口。
|
||||
func Register() {
|
||||
}
|
||||
import (
|
||||
"server/controllers"
|
||||
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// Register 注册移动端 / 开放 API(api)路由。
|
||||
func Register() {
|
||||
// 客户端检查更新(无需登录)
|
||||
beego.Router("/api/softwareupgrade/check", &controllers.ApiSoftwareUpgradeController{}, "get:Check")
|
||||
}
|
||||
|
||||
@ -95,6 +95,20 @@ func Register() {
|
||||
beego.Router("/platform/modules", &controllers.PlatformModulesController{}, "post:Add")
|
||||
beego.Router("/platform/modules/:id", &controllers.PlatformModulesController{}, "get:GetDetail;put:Edit;delete:Delete")
|
||||
|
||||
// 投诉建议(yz_system_complaint_category / yz_system_platform_complaint)
|
||||
beego.Router("/platform/complaintCategory/list", &controllers.PlatformComplaintCategoryController{}, "get:List")
|
||||
beego.Router("/platform/complaintCategory/select", &controllers.PlatformComplaintCategoryController{}, "get:SelectList")
|
||||
beego.Router("/platform/complaintCategory", &controllers.PlatformComplaintCategoryController{}, "post:Create")
|
||||
beego.Router("/platform/complaintCategory/:id", &controllers.PlatformComplaintCategoryController{}, "post:Update;delete:Delete")
|
||||
beego.Router("/platform/complaint/list", &controllers.PlatformComplaintController{}, "get:List")
|
||||
beego.Router("/platform/complaint", &controllers.PlatformComplaintController{}, "post:Create")
|
||||
beego.Router("/platform/complaint/:id", &controllers.PlatformComplaintController{}, "get:Detail;post:Update;delete:Delete")
|
||||
|
||||
// 软件升级产品(yz_system_software_upgrade)
|
||||
beego.Router("/platform/softwareupgrade/list", &controllers.PlatformSoftwareUpgradeController{}, "get:List")
|
||||
beego.Router("/platform/softwareupgrade", &controllers.PlatformSoftwareUpgradeController{}, "post:Create")
|
||||
beego.Router("/platform/softwareupgrade/:id", &controllers.PlatformSoftwareUpgradeController{}, "get:Detail;post:Update;delete:Delete")
|
||||
|
||||
// 租户站点设置(yz_tenant_site_setting)
|
||||
beego.Router("/platform/normalInfos", &controllers.SiteSettingsController{}, "get:GetNormalInfos")
|
||||
beego.Router("/platform/saveNormalInfos", &controllers.SiteSettingsController{}, "post:SaveNormalInfos")
|
||||
|
||||
@ -16,11 +16,12 @@ import (
|
||||
// 初始化路由(精简版)
|
||||
func init() {
|
||||
// 全局 CORS 处理 + 预检请求
|
||||
// 注意:Allow-Origin 为 * 时不能同时设置 Allow-Credentials: true,否则浏览器会拒绝带 Authorization 的预检(上传/接口跨域常见现象)。
|
||||
// 当前 JWT 走 Header、前端 axios withCredentials=false,无需携带 Cookie,故不返回 Allow-Credentials。
|
||||
beego.InsertFilter("*", beego.BeforeRouter, func(ctx *context.Context) {
|
||||
ctx.Output.Header("Access-Control-Allow-Origin", "*")
|
||||
ctx.Output.Header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS")
|
||||
ctx.Output.Header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization")
|
||||
ctx.Output.Header("Access-Control-Allow-Credentials", "true")
|
||||
ctx.Output.Header("Access-Control-Max-Age", "86400")
|
||||
|
||||
if ctx.Input.Method() == "OPTIONS" {
|
||||
|
||||
60
services/software_upgrade_url.go
Normal file
60
services/software_upgrade_url.go
Normal file
@ -0,0 +1,60 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"server/models"
|
||||
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// PublicRequestBaseURL 根据请求拼出对外访问的根(用于把 /uploads/... 拼成完整下载地址)
|
||||
func PublicRequestBaseURL(c *beego.Controller) (scheme, host string) {
|
||||
scheme = "http"
|
||||
if c.Ctx.Request.TLS != nil {
|
||||
scheme = "https"
|
||||
}
|
||||
if strings.EqualFold(strings.TrimSpace(c.Ctx.Request.Header.Get("X-Forwarded-Proto")), "https") {
|
||||
scheme = "https"
|
||||
}
|
||||
host = strings.TrimSpace(c.Ctx.Request.Host)
|
||||
return scheme, host
|
||||
}
|
||||
|
||||
// ResolveSoftwareDownloadURL 优先使用自定义 download_url;否则根据 file_id 读附件 src 拼完整 URL
|
||||
func ResolveSoftwareDownloadURL(scheme, host string, downloadURL *string, fileID *uint64) string {
|
||||
if downloadURL != nil {
|
||||
u := strings.TrimSpace(*downloadURL)
|
||||
if u != "" {
|
||||
return u
|
||||
}
|
||||
}
|
||||
if fileID == nil || *fileID == 0 {
|
||||
return ""
|
||||
}
|
||||
var f models.SystemFile
|
||||
err := models.Orm.QueryTable(new(models.SystemFile)).
|
||||
Filter("id", *fileID).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&f)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
src := strings.TrimSpace(f.Src)
|
||||
if src == "" {
|
||||
return ""
|
||||
}
|
||||
if strings.HasPrefix(strings.ToLower(src), "http://") || strings.HasPrefix(strings.ToLower(src), "https://") {
|
||||
return src
|
||||
}
|
||||
if host == "" {
|
||||
return src
|
||||
}
|
||||
if !strings.HasPrefix(src, "/") {
|
||||
src = "/" + src
|
||||
}
|
||||
if scheme == "" {
|
||||
scheme = "http"
|
||||
}
|
||||
return scheme + "://" + host + src
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user