yinbentan
2024-09-26 2030ec81f18f4ec9ea1800f13046acafff6d50f7
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
package service
 
import (
    "aps_crm/model"
    "aps_crm/pkg/ecode"
)
 
type ContractService struct{}
 
func (ContractService) AddContract(contract *model.Contract) int {
    err := model.NewContractSearch().Create(contract)
    if err != nil {
        return ecode.ContractExist
    }
 
    return ecode.OK
}
 
func (ContractService) UpdateContract(contract *model.Contract) int {
    // check contract exist
    _, err := model.NewContractSearch().SetId(contract.Id).Find()
    if err != nil {
        return ecode.ContractNotExist
    }
 
    err = model.NewContractSearch().SetId(contract.Id).Update(contract)
    if err != nil {
        return ecode.ContractSetErr
    }
 
    return ecode.OK
}
 
func (ContractService) GetContractList(page, pageSize int, data map[string]interface{}, keyword string) ([]*model.Contract, int64, int) {
    // get contact list
    contacts, total, err := model.NewContractSearch().SetPage(page, pageSize).SetSearchMap(data).SetKeyword(keyword).FindAll()
    if err != nil {
        return nil, 0, ecode.ContractListErr
    }
    return contacts, total, ecode.OK
}
 
func (ContractService) DeleteContract(id int) int {
    // delete client
    err := model.NewContractSearch().SetId(id).Delete()
    if err != nil {
        return ecode.ContractDeleteErr
    }
    return ecode.OK
}