From f1842bf9b5bb69b5078a215c02cb16b7e33f893a Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期一, 08 一月 2024 14:38:46 +0800
Subject: [PATCH] Merge branch 'master' of http://192.168.5.5:10010/r/aps/crm

---
 api/v1/system_set.go |  116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 116 insertions(+), 0 deletions(-)

diff --git a/api/v1/system_set.go b/api/v1/system_set.go
new file mode 100644
index 0000000..53403e8
--- /dev/null
+++ b/api/v1/system_set.go
@@ -0,0 +1,116 @@
+package v1
+
+import (
+	"aps_crm/constvar"
+	"aps_crm/model"
+	"aps_crm/model/request"
+	"aps_crm/pkg/contextx"
+	"aps_crm/pkg/ecode"
+	"aps_crm/service"
+	"github.com/gin-gonic/gin"
+	"gorm.io/gorm"
+)
+
+type SystemSetApi struct{}
+
+// GetSystemSet
+//
+//	@Tags		绯荤粺璁剧疆
+//	@Summary	鑾峰彇绯荤粺璁剧疆
+//	@Produce	application/json
+//	@Success	200		{object}	contextx.Response{data=map[string]interface{}}	"鎴愬姛"
+//	@Router		/api/system/getSystemSet [get]
+func (slf SystemSetApi) GetSystemSet(c *gin.Context) {
+	ctx, ok := contextx.NewContext(c, nil)
+	if !ok {
+		return
+	}
+	systemSet, err := service.GetSystemSet()
+	if err != nil {
+		ctx.FailWithMsg(ecode.UnknownErr, "鏌ヨ澶辫触")
+		return
+	}
+	constvar.SystemSet["CRM"] = systemSet
+	ctx.OkWithDetailed(constvar.SystemSet)
+}
+
+// SaveSystemSet
+//
+//	@Tags		绯荤粺璁剧疆
+//	@Summary	淇濆瓨绯荤粺璁剧疆
+//	@Produce	application/json
+//	@Param		object	body		request.SaveSystemSet	true	"鏌ヨ鍙傛暟"
+//	@Success	200		{object}	contextx.Response{}	"鎴愬姛"
+//	@Router		/api/system/saveSystemSet [post]
+func (slf SystemSetApi) SaveSystemSet(c *gin.Context) {
+	var params request.SaveSystemSet
+	ctx, ok := contextx.NewContext(c, &params)
+	if !ok {
+		return
+	}
+	err := model.WithTransaction(func(db *gorm.DB) error {
+		err := model.NewSystemSetSearch().SetOrm(db).DeleteAll()
+		if err != nil {
+			return err
+		}
+		err = model.NewSystemSetSearch().SetOrm(db).CreateBatch(params.Sets)
+		return err
+	})
+	if err != nil {
+		ctx.FailWithMsg(ecode.UnknownErr, "淇濆瓨澶辫触")
+		return
+	}
+	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
+	}
+	m := make(map[string]string)
+	systemSet, err := service.GetSystemSet()
+	if err != nil {
+		ctx.FailWithMsg(ecode.UnknownErr, "鏌ヨ澶辫触")
+		return
+	}
+	switch constvar.ModeType(modeType) {
+	case constvar.BjdMode:
+		value := systemSet["鎶ヤ环鍗曟槸鍚﹀繀椤诲叧鑱旈攢鍞満浼�"].((map[string]interface{}))["value"]
+		if value == "鏄�" {
+			m["Xsjh"] = "yes"
+		} else {
+			m["Xsjh"] = "no"
+		}
+	case constvar.XsmxMode:
+		value := systemSet["閿�鍞槑缁嗗崟鏄惁蹇呴』鍏宠仈鎶ヤ环鍗�"].((map[string]interface{}))["value"]
+		if value == "鏄�" {
+			m["Bjd"] = "yes"
+		} else {
+			m["Bjd"] = "no"
+		}
+		value = systemSet["閿�鍞槑缁嗗崟鏄惁蹇呴』鍏宠仈涓氬姟鏈轰細"].((map[string]interface{}))["value"]
+		if value == "鏄�" {
+			m["Ywjh"] = "yes"
+		} else {
+			m["Ywjh"] = "no"
+		}
+	default:
+		ctx.FailWithMsg(ecode.UnknownErr, "鍙傛暟閿欒")
+		return
+	}
+	ctx.OkWithDetailed(m)
+}

--
Gitblit v1.8.0