liujiandao
2023-12-22 dd97f2626579ca8be69b9b6d68ce9d592b62eb6a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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)
    switch constvar.ModeType(modeType) {
    case constvar.BjdMode:
        all, err := model.NewSystemSetSearch().SetModeType(modeType).FindAll()
        if err != nil {
            ctx.FailWithMsg(ecode.UnknownErr, "查询系统设置错误")
            return
        }
        for _, set := range all {
            //报价单是否必须关联销售机会
            if set.Name == "报价单是否必须关联销售机会" {
                if set.Value == "是" {
                    m["Xsjh"] = "yes"
                } else {
                    m["Xsjh"] = "no"
                    //c.Writer.Header().Set("Xsjh", "no")
                }
            }
        }
    case constvar.XsmxMode:
        all, err := model.NewSystemSetSearch().SetModeType(modeType).FindAll()
        if err != nil {
            ctx.FailWithMsg(ecode.UnknownErr, "查询系统设置错误")
            return
        }
        for _, set := range all {
            //销售明细单是否必须关联报价单
            if set.Name == "销售明细单是否必须关联报价单" {
                if set.Value == "是" {
                    m["Bjd"] = "yes"
                } else {
                    m["Bjd"] = "no"
                    //c.Writer.Header().Set("Bjd", "no")
                }
            }
            //销售明细单是否必须关联业务机会
            if set.Name == "销售明细单是否必须关联业务机会" {
                if set.Value == "是" {
                    m["Ywjh"] = "yes"
                } else {
                    m["Ywjh"] = "no"
                    //c.Writer.Header().Set("Ywjh", "no")
                }
            }
        }
    default:
        ctx.FailWithMsg(ecode.UnknownErr, "参数错误")
        return
    }
    ctx.OkWithDetailed(m)
}