liujiandao
2024-01-11 40e540f8ca398fee68f4520dbebd6db6fe2e164c
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
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)
}