zhangqian
2023-08-07 4b63908ad085bc570623f7b0c0fd397b2ae7a80d
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/pkg/ecode"
)
 
type SaleChanceService struct{}
 
func (SaleChanceService) AddSaleChance(saleChange *model.SaleChance) int {
    err := model.NewSaleChanceSearch().Create(saleChange)
    if err != nil {
        return ecode.SaleChanceExist
    }
    return ecode.OK
}
 
func (SaleChanceService) DeleteSaleChance(id int) int {
    // check saleChange exist
    _, err := model.NewSaleChanceSearch().SetId(id).Find()
    if err != nil {
        return ecode.SaleChanceNotExist
    }
 
    // delete saleChange
    err = model.NewSaleChanceSearch().SetId(id).Delete()
    if err != nil {
        return ecode.SaleChanceDeleteErr
    }
    return ecode.OK
}
 
func (SaleChanceService) UpdateSaleChance(saleChange *model.SaleChance) int {
    // update saleChange
    err := model.NewSaleChanceSearch().SetId(saleChange.Id).Update(saleChange)
    if err != nil {
        return ecode.SaleChanceUpdateErr
    }
 
    return ecode.OK
}
 
// CheckSaleChangeExist check saleChange exist
func CheckSaleChangeExist(id int) int {
    tmp, err := model.NewSaleChanceSearch().SetId(id).Find()
    if err != nil {
        return ecode.SaleChanceNotExist
    }
 
    if tmp.Id == 0 {
        return ecode.SaleChanceNotExist
    }
 
    return ecode.OK
}
 
func (SaleChanceService) GetSaleChanceList(page, pageSize int, keyword string) ([]*model.SaleChance, int64, int) {
    // get contact list
    contacts, total, err := model.NewSaleChanceSearch().SetKeyword(keyword).SetPage(page, pageSize).FindAll()
    if err != nil {
        return nil, 0, ecode.SaleChanceListErr
    }
    return contacts, total, ecode.OK
}