liujiandao
2024-03-26 1c17ff16fd13e4d8bbab75d8a728cf18465b20e0
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
81
package service
 
import (
    "aps_crm/constvar"
    "aps_crm/model"
    "aps_crm/pkg/ecode"
    "aps_crm/pkg/mysqlx"
)
 
type FeeManageService struct{}
 
func (FeeManageService) AddServiceFeeManage(serviceFeeManage *model.ServiceFeeManage) int {
 
    tx := mysqlx.GetDB().Begin()
 
    err := model.NewClientSearch(tx).Create(serviceFeeManage.Client)
    if err != nil {
        tx.Rollback()
        return ecode.ClientExist
    }
 
    serviceFeeManage.ClientId = serviceFeeManage.Client.Id
    err = model.NewServiceFeeManageSearch(tx).Create(serviceFeeManage)
    if err != nil {
        tx.Rollback()
        return ecode.ServiceFeeManageExist
    }
 
    tx.Commit()
 
    return ecode.OK
}
 
func (FeeManageService) UpdateServiceFeeManage(serviceFeeManage *model.ServiceFeeManage) int {
    // check serviceFeeManage exist
    _, err := model.NewServiceFeeManageSearch(nil).SetId(serviceFeeManage.Id).Find()
    if err != nil {
        return ecode.ServiceFeeManageNotExist
    }
 
    tx := mysqlx.GetDB().Begin()
 
    err = model.NewServiceFeeManageSearch(tx).SetId(serviceFeeManage.Id).Update(serviceFeeManage)
    if err != nil {
        tx.Rollback()
        return ecode.ServiceFeeManageSetErr
    }
 
    // update client
    err = model.NewClientSearch(tx).SetId(serviceFeeManage.ClientId).Update(serviceFeeManage.Client)
    if err != nil {
        tx.Rollback()
        return ecode.ClientUpdateErr
    }
 
    tx.Commit()
 
    return ecode.OK
}
 
func (FeeManageService) DeleteServiceFeeManage(ids []int) int {
    // delete client
    err := model.NewServiceFeeManageSearch(nil).SetIds(ids).Delete()
    if err != nil {
        return ecode.ServiceFeeManageDeleteErr
    }
    return ecode.OK
}
 
func (FeeManageService) GetServiceFeeManageList(page, pageSize int, queryClass constvar.ServiceFeeQueryClass, keywordType constvar.ServiceFeeKeywordType, keyword string) ([]*model.ServiceFeeManage, int64, int) {
    // get contact list
    contacts, total, err := model.NewServiceFeeManageSearch(nil).
        SetQueryClass(queryClass).
        SetKeywordType(keywordType).
        SetKeyword(keyword).
        SetPage(page, pageSize).FindAll()
    if err != nil {
        return nil, 0, ecode.ServiceFeeManageListErr
    }
    return contacts, total, ecode.OK
}