Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
main
Branches (1)
main
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
The license selected for the repository is subject to the license used by the main branch of the repository.
main
Branches (1)
main
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
main
Branches (1)
main
backend-basic-code
/
controller
/
attribute_controller.go
backend-basic-code
/
controller
/
attribute_controller.go
attribute_controller.go 3.37 KB
Copy Edit Raw Blame History
lysimportant authored 2025年03月04日 10:41 +08:00 . base code
package controller
import (
"encoding/json"
"fmt"
"service/components"
"service/modules"
"service/utils"
"strconv"
"time"
"github.com/gin-gonic/gin"
)
// AddAttributeController 添加商品的展示属性
func AddAttributeController(ctx *gin.Context) {
var cc modules.Attribute
ctx.ShouldBind(&cc)
count := modules.GetAttributeByNameAndTypeService(cc)
if count != 0 {
utils.HandleFailResponse(ctx, cc.Name+" 标签已存在", nil)
return
}
fmt.Println("cc: ", cc, count)
cc.Uid = 1
cc.CreatedAt = time.Now()
err := modules.AddAttributeService(&cc)
if err != nil {
utils.HandleFailResponse(ctx, "增加商品售卖属性失败", nil)
return
}
utils.HandleSuccessResponse(ctx, "添加成功!!", nil)
}
// GetAllAttributeController 获取商品的所有展示属性
func GetAllAttributeController(ctx *gin.Context) {
_type := ctx.Query("type")
display := ctx.DefaultQuery("display", "1")
cc, err := modules.GetAllAttributeService(_type, display)
var parent []modules.Attribute
var children []modules.Attribute
if err != nil {
utils.HandleFailResponse(ctx, "查询失败", nil)
return
}
for _, attribute := range cc {
if attribute.IsParent == 0 {
parent = append(parent, attribute)
} else {
children = append(children, attribute)
}
}
finally := make([]modules.Attribute, len(parent))
for i := 0; i < len(parent); i++ {
finally[i] = parent[i]
for j := 0; j < len(children); j++ {
if parent[i].Id == children[j].IsParent {
finally[i].Children = append(finally[i].Children, &children[j])
}
}
}
for i := 0; i < len(finally); i++ {
for j := 0; j < len(finally[i].Children); j++ {
for k := 0; k < len(children); k++ {
if finally[i].Children[j].Id == children[k].IsParent {
finally[i].Children[j].Children = append(finally[i].Children[j].Children, &children[k])
}
}
}
}
utils.HandleSuccessResponse(ctx, "查询商品属性成功", finally)
}
func PatchAttributeController() gin.HandlerFunc {
return func(ctx *gin.Context) {
raw, _ := ctx.GetRawData()
var data map[string]any
err := json.Unmarshal(raw, &data)
if err != nil {
utils.HandleFailResponse(ctx, "数据绑定失败", nil)
return
}
if data["value"] == nil {
fmt.Println("更新显示和隐藏", data["display"])
err = components.DB.Model(modules.Attribute{}).
Where("id = ?", data["id"]).
Update("display", data["display"]).Error
} else {
err = components.DB.Model(modules.Attribute{}).
Where("id = ?", data["id"]).
Update("name", data["value"]).Error
id, _ := strconv.Atoi(fmt.Sprintf("%v", data["id"]))
if id >= 99 && id <= 105 {
err = components.DB.Model(&modules.File{}).
Where("attribute = ?", data["name"]).
Updates(map[string]interface{}{
"attribute": data["value"],
}).Error
if err != nil {
utils.HandleFailResponse(ctx, "更新文件类失败", nil)
return
}
}
}
if err != nil {
utils.HandleFailResponse(ctx, "更新失败", err.Error())
return
}
utils.HandleSuccessResponse(ctx, "更新成功", nil)
}
}
// DeleteAttributeController 删除商品的展示属性
func DeleteAttributeController(ctx *gin.Context) {
c := new(modules.Attribute)
ctx.ShouldBind(c)
fmt.Println("c: ", c)
err := modules.DeleteAttributeService(c)
if err != nil {
utils.HandleFailResponse(ctx, "属性删除失败!", nil)
return
}
utils.HandleSuccessResponse(ctx, "属性删除成功~", nil)
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

给前端提供的API数据管理的后端基础模板
Cancel

Releases

No release

Contributors

All

Language(Optional)

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/init-project-base/backend-basic-code.git
git@gitee.com:init-project-base/backend-basic-code.git
init-project-base
backend-basic-code
提供API服务的后端基础模板
main
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /