zhangqian
2023-10-13 13194e787d51e4ce07dfc35341d536fb5db7aaa3
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
package service
 
import (
    "aps_crm/model"
    "aps_crm/model/request"
    "aps_crm/pkg/ecode"
)
 
type ClientStatusService struct{}
 
func (ClientStatusService) AddClientStatus(clientStatus *model.ClientStatus) int {
    err := model.NewClientStatusSearch().Create(clientStatus)
    if err != nil {
        return ecode.ClientStatusExist
    }
 
    return ecode.OK
}
 
func (ClientStatusService) DeleteClientStatus(id int) int {
    _, err := model.NewClientStatusSearch().SetId(id).First()
    if err != nil {
        return ecode.ClientStatusNotExist
    }
 
    err = model.NewClientStatusSearch().SetId(id).Delete()
    if err != nil {
        return ecode.ClientStatusNotExist
    }
    return ecode.OK
}
 
func (ClientStatusService) GetClientStatusList() ([]*model.ClientStatus, int) {
    list, err := model.NewClientStatusSearch().FindAll()
    if err != nil {
        return nil, ecode.ClientStatusListErr
    }
 
    return list, ecode.OK
}
 
func (ClientStatusService) UpdateClientStatus(clientStatuses []request.UpdateClientStatus) int {
    for _, v := range clientStatuses {
        // check clientStatus exist
        _, err := model.NewClientStatusSearch().SetId(v.Id).First()
        if err != nil {
            return ecode.ClientStatusNotExist
        }
 
        err = model.NewClientStatusSearch().SetId(v.Id).Updates(map[string]interface{}{
            "name": v.Name,
        })
        if err != nil {
            return ecode.ClientStatusSetErr
        }
    }
 
    return ecode.OK
}