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, ¶ms)
|
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)
|
}
|