add
wangpengfei
2023-07-18 5fac03fb857cf9a160e1736a25de2c5f95f5e44f
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
package service
 
import (
    "aps_crm/model"
    "aps_crm/pkg/ecode"
)
 
type QuotationService struct{}
 
func (QuotationService) AddQuotation(quotation *model.Quotation) int {
    err := model.NewQuotationSearch().Create(quotation)
    if err != nil {
        return ecode.QuotationExist
    }
 
    return ecode.OK
}
 
func (QuotationService) DeleteQuotation(id int) int {
    _, err := model.NewQuotationSearch().SetId(id).Find()
    if err != nil {
        return ecode.QuotationNotExist
    }
 
    err = model.NewQuotationSearch().SetId(id).Delete()
    if err != nil {
        return ecode.QuotationNotExist
    }
    return ecode.OK
}
 
func (QuotationService) GetQuotationList() ([]*model.Quotation, int) {
    list, err := model.NewQuotationSearch().FindAll()
    if err != nil {
        return nil, ecode.QuotationListErr
    }
 
    return list, ecode.OK
}
 
func (QuotationService) UpdateQuotation(quotation *model.Quotation) int {
    // check quotation exist
    _, err := model.NewQuotationSearch().SetId(quotation.Id).Find()
    if err != nil {
        return ecode.QuotationNotExist
    }
 
    err = model.NewQuotationSearch().SetId(quotation.Id).Update(quotation)
    if err != nil {
        return ecode.QuotationSetErr
    }
 
    return ecode.OK
}