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
60
61
62
63
64
package service
 
import (
    "aps_crm/model"
    "aps_crm/model/request"
    "aps_crm/pkg/ecode"
)
 
type InvoiceTypeService struct{}
 
func NewInvoiceTypeService() InvoiceTypeService {
    return InvoiceTypeService{}
}
 
func (InvoiceTypeService) AddInvoiceType(invoiceType *model.InvoiceType) int {
    err := model.NewInvoiceTypeSearch().Create(invoiceType)
    if err != nil {
        return ecode.DBErr
    }
 
    return ecode.OK
}
 
func (InvoiceTypeService) DeleteInvoiceType(id int) int {
    err := model.NewInvoiceTypeSearch().SetId(id).Delete()
    if err != nil {
        return ecode.DBErr
    }
    return ecode.OK
}
 
func (InvoiceTypeService) GetInvoiceTypeList() ([]*model.InvoiceType, int64, int) {
    list, total, err := model.NewInvoiceTypeSearch().Find()
    if err != nil {
        return nil, 0, ecode.DBErr
    }
 
    return list, total, ecode.OK
}
 
func (InvoiceTypeService) UpdateInvoiceTypes(InvoiceTypes []*request.UpdateInvoiceType) int {
    for _, v := range InvoiceTypes {
        // check InvoiceType exist
        _, err := model.NewInvoiceTypeSearch().SetId(v.Id).First()
        if err != nil {
            return ecode.DBErr
        }
 
        err = model.NewInvoiceTypeSearch().SetId(v.Id).Updates(map[string]interface{}{})
        if err != nil {
            return ecode.DBErr
        }
    }
 
    return ecode.OK
}
 
func (InvoiceTypeService) UpdateInvoiceType(invoiceType *model.InvoiceType) int {
    err := model.NewInvoiceTypeSearch().SetId(invoiceType.Id).Update(invoiceType)
    if err != nil {
        return ecode.DBErr
    }
    return ecode.OK
}