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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 
package service
 
import (
    "aps_crm/model"
    "aps_crm/model/request"
    "aps_crm/pkg/ecode"
)
 
type CurrencyService struct{}
 
func (CurrencyService) AddCurrency(currency *model.Currency) int {
    err := model.NewCurrencySearch().Create(currency)
    if err != nil {
        return ecode.CurrencyExist
    }
 
    return ecode.OK
}
 
func (CurrencyService) DeleteCurrency(id int) int {
    _, err := model.NewCurrencySearch().SetId(id).Find()
    if err != nil {
        return ecode.CurrencyNotExist
    }
 
    err = model.NewCurrencySearch().SetId(id).Delete()
    if err != nil {
        return ecode.CurrencyNotExist
    }
    return ecode.OK
}
 
func (CurrencyService) GetCurrencyList() ([]*model.Currency, int) {
    list, err := model.NewCurrencySearch().FindAll()
    if err != nil {
        return nil, ecode.CurrencyListErr
    }
 
    return list, ecode.OK
}
 
func (CurrencyService) UpdateCurrency(currencys []*request.UpdateCurrency) int {
    for _, v := range currencys {
        // check currency exist
        _, err := model.NewCurrencySearch().SetId(v.Id).Find()
        if err != nil {
            return ecode.CurrencyNotExist
        }
 
        err = model.NewCurrencySearch().SetId(v.Id).Updates(map[string]interface{}{
            "name": v.Name,
        })
        if err != nil {
            return ecode.CurrencySetErr
        }
    }
 
    return ecode.OK
}
 
func (CurrencyService) GetCurrencyDetail(id int) (*model.Currency, int) {
    currency, err := model.NewCurrencySearch().SetId(id).Find()
    if err != nil {
        return nil, ecode.CurrencyNotExist
    }
 
    return currency, ecode.OK
}