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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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) 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, data map[string]interface{}) ([]*model.SaleChance, int64, int) {
    // get contact list
    contacts, total, err := model.NewSaleChanceSearch().SetPage(page, pageSize).SetSearchMap(data).FindAll()
    if err != nil {
        return nil, 0, ecode.SaleChanceListErr
    }
    return contacts, total, ecode.OK
}
 
// push
func (SaleChanceService) PushSaleChance(id, step int) int {
    // check saleChange exist
    errCode := CheckSaleChangeExist(id)
    if errCode != ecode.OK {
        return errCode
    }
    // check step
    _, err := model.NewSaleStageSearch().SetId(step).Find()
    if err != nil {
        return ecode.SaleStageNotExist
    }
 
    // push saleChange
    err = model.NewSaleChanceSearch().SetId(id).Update(&model.SaleChance{SaleStageId: step})
    if err != nil {
        return ecode.SaleChanceUpdateErr
    }
 
    return ecode.OK
}
 
func (SaleChanceService) DeleteSaleChance(ids []int) int {
    // delete client
    err := model.NewSaleChanceSearch().SetIds(ids).Delete()
    if err != nil {
        return ecode.SaleChanceDeleteErr
    }
    return ecode.OK
}