From f26ee7ab795bb21be7d31dc2cca1e7a206ef4b8b Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期五, 22 十二月 2023 14:09:00 +0800 Subject: [PATCH] 系统设置修改 --- constvar/const.go | 11 +++ service/system_set_service.go | 6 - api/v1/code.go | 27 --------- router/index.go | 1 api/v1/system_set.go | 62 ++++++++++++++++++++ model/system_set.go | 15 +++- 6 files changed, 87 insertions(+), 35 deletions(-) diff --git a/api/v1/code.go b/api/v1/code.go index aea8034..941623b 100644 --- a/api/v1/code.go +++ b/api/v1/code.go @@ -102,39 +102,12 @@ id, err = model.NewFollowRecordSearch().MaxAutoIncr() case constvar.CodeStandardTypeQuotation: id, err = model.NewQuotationSearch(nil).MaxAutoIncr() - //鎶ヤ环鍗曟槸鍚﹀繀椤诲叧鑱旈攢鍞満浼� - first, err := model.NewSystemSetSearch().SetName("鎶ヤ环鍗曟槸鍚﹀繀椤诲叧鑱旈攢鍞満浼�").First() - if err == nil { - if first.Value == "鏄�" { - c.Writer.Header().Set("Xsjh", "yes") - } else { - c.Writer.Header().Set("Xsjh", "no") - } - } case constvar.CodeStandardTypeSaleTotalOrder: id, err = model.NewMasterOrderSearch().MaxAutoIncr() case constvar.CodeStandardTypeSaleSuborder: id, err = model.NewSubOrderSearch(nil).MaxAutoIncr() case constvar.CodeStandardTypeSaleDetail: id, err = model.NewSalesDetailsSearch().MaxAutoIncr() - //閿�鍞槑缁嗗崟鏄惁蹇呴』鍏宠仈鎶ヤ环鍗� - first, err := model.NewSystemSetSearch().SetName("閿�鍞槑缁嗗崟鏄惁蹇呴』鍏宠仈鎶ヤ环鍗�").First() - if err == nil { - if first.Value == "鏄�" { - c.Writer.Header().Set("Bjd", "yes") - } else { - c.Writer.Header().Set("Bjd", "no") - } - } - //閿�鍞槑缁嗗崟鏄惁蹇呴』鍏宠仈涓氬姟鏈轰細 - first, err = model.NewSystemSetSearch().SetName("閿�鍞槑缁嗗崟鏄惁蹇呴』鍏宠仈涓氬姟鏈轰細").First() - if err == nil { - if first.Value == "鏄�" { - c.Writer.Header().Set("Ywjh", "yes") - } else { - c.Writer.Header().Set("Ywjh", "no") - } - } case constvar.CodeStandardTypeSaleReturnGoods: id, err = model.NewSalesReturnSearch().MaxAutoIncr() case constvar.CodeStandardTypeSaleRefund: diff --git a/api/v1/system_set.go b/api/v1/system_set.go index 2b758bd..4625727 100644 --- a/api/v1/system_set.go +++ b/api/v1/system_set.go @@ -62,3 +62,65 @@ } ctx.Ok() } + +// UseSystemSet +// +// @Tags 绯荤粺璁剧疆 +// @Summary 浣跨敤绯荤粺璁剧疆 +// @Produce application/json +// @Param modeType path string true "鏌ヨ鍙傛暟" +// @Success 200 {object} response.ListResponse +// @Router /api/system/useSystemSet/{modeType} [get] +func (slf *SystemSetApi) UseSystemSet(c *gin.Context) { + ctx, ok := contextx.NewContext(c, nil) + if !ok { + return + } + modeType := c.Param("modeType") + if modeType == "" { + ctx.FailWithMsg(ecode.UnknownErr, "鍙傛暟閿欒") + return + } + switch constvar.ModeType(modeType) { + case constvar.BjdMode: + all, err := model.NewSystemSetSearch().SetModeType(modeType).FindAll() + if err == nil { + for _, set := range all { + //鎶ヤ环鍗曟槸鍚﹀繀椤诲叧鑱旈攢鍞満浼� + if set.Name == "鎶ヤ环鍗曟槸鍚﹀繀椤诲叧鑱旈攢鍞満浼�" { + if set.Value == "鏄�" { + c.Writer.Header().Set("Xsjh", "yes") + } else { + c.Writer.Header().Set("Xsjh", "no") + } + } + } + } + case constvar.XsmxMode: + all, err := model.NewSystemSetSearch().SetModeType(modeType).FindAll() + if err == nil { + for _, set := range all { + //閿�鍞槑缁嗗崟鏄惁蹇呴』鍏宠仈鎶ヤ环鍗� + if set.Name == "閿�鍞槑缁嗗崟鏄惁蹇呴』鍏宠仈鎶ヤ环鍗�" { + if set.Value == "鏄�" { + c.Writer.Header().Set("Bjd", "yes") + } else { + c.Writer.Header().Set("Bjd", "no") + } + } + //閿�鍞槑缁嗗崟鏄惁蹇呴』鍏宠仈涓氬姟鏈轰細 + if set.Name == "閿�鍞槑缁嗗崟鏄惁蹇呴』鍏宠仈涓氬姟鏈轰細" { + if set.Value == "鏄�" { + c.Writer.Header().Set("Ywjh", "yes") + } else { + c.Writer.Header().Set("Ywjh", "no") + } + } + } + } + default: + ctx.FailWithMsg(ecode.UnknownErr, "鍙傛暟閿欒") + return + } + ctx.Ok() +} diff --git a/constvar/const.go b/constvar/const.go index 341e137..c81270e 100644 --- a/constvar/const.go +++ b/constvar/const.go @@ -208,6 +208,14 @@ SystemType = 2 ) +// ModeType 妯″潡绫诲瀷 +type ModeType string + +const ( + BjdMode ModeType = "bjd" + XsmxMode ModeType = "xsmx" +) + var SystemSet = map[string]interface{}{ "CRM": map[string]interface{}{ "鎶ヤ环鍗曟槸鍚﹀繀椤诲叧鑱旈攢鍞満浼�": map[string]interface{}{ @@ -217,6 +225,7 @@ "1": "鏄�", "2": "鍚�", }, + "modeType": "bjd", }, "閿�鍞槑缁嗗崟鏄惁蹇呴』鍏宠仈鎶ヤ环鍗�": map[string]interface{}{ "value": "鏄�", @@ -225,6 +234,7 @@ "1": "鏄�", "2": "鍚�", }, + "modeType": "xsmx", }, "閿�鍞槑缁嗗崟鏄惁蹇呴』鍏宠仈涓氬姟鏈轰細": map[string]interface{}{ "value": "鏄�", @@ -233,6 +243,7 @@ "1": "鏄�", "2": "鍚�", }, + "modeType": "xsmx", }, }, } diff --git a/model/system_set.go b/model/system_set.go index a64dd01..40a20da 100644 --- a/model/system_set.go +++ b/model/system_set.go @@ -8,10 +8,10 @@ type ( SystemSet struct { - Id int `json:"id" gorm:"column:id;primaryKey;autoIncrement;not null"` - Name string `json:"name" gorm:"type:varchar(255);comment:鍚嶇О"` - Value string `json:"value" gorm:"type:varchar(255);comment:鍊�"` - SystemType string `json:"systemType" gorm:"type:varchar(255);comment:绯荤粺绫诲瀷"` + Id int `json:"id" gorm:"column:id;primaryKey;autoIncrement;not null"` + Name string `json:"name" gorm:"type:varchar(255);comment:鍚嶇О"` + Value string `json:"value" gorm:"type:varchar(255);comment:鍊�"` + ModeType string `json:"modeType" gorm:"type:varchar(255);comment:妯″潡绫诲瀷"` } SystemSetSearch struct { SystemSet @@ -40,6 +40,10 @@ slf.Name = name return slf } +func (slf *SystemSetSearch) SetModeType(modeType string) *SystemSetSearch { + slf.ModeType = modeType + return slf +} func (slf *SystemSetSearch) build() *gorm.DB { var db = slf.Orm.Table(slf.TableName()) @@ -50,6 +54,9 @@ if slf.Name != "" { db = db.Where("name = ?", slf.Name) } + if slf.ModeType != "" { + db = db.Where("mode_type = ?", slf.ModeType) + } return db } diff --git a/router/index.go b/router/index.go index 9f70e7d..2758b73 100644 --- a/router/index.go +++ b/router/index.go @@ -207,6 +207,7 @@ { systemSetGroup.GET("getSystemSet", systemSetApi.GetSystemSet) systemSetGroup.POST("saveSystemSet", systemSetApi.SaveSystemSet) + systemSetGroup.GET("useSystemSet/:modeType", systemSetApi.UseSystemSet) } return Router diff --git a/service/system_set_service.go b/service/system_set_service.go index eba7035..924e7aa 100644 --- a/service/system_set_service.go +++ b/service/system_set_service.go @@ -12,10 +12,8 @@ } crmMap := constvar.SystemSet[`CRM`].(map[string]interface{}) for _, set := range all { - if set.SystemType == "CRM" { - if _, ok := crmMap[set.Name]; ok { - crmMap[set.Name].(map[string]interface{})["value"] = set.Value - } + if _, ok := crmMap[set.Name]; ok { + crmMap[set.Name].(map[string]interface{})["value"] = set.Value } } return crmMap, nil -- Gitblit v1.8.0