package service
|
|
import (
|
"aps_crm/model"
|
"aps_crm/model/request"
|
"aps_crm/pkg/ecode"
|
)
|
|
type ClientTypeService struct{}
|
|
func (ClientTypeService) AddClientType(clientType *model.ClientType) int {
|
err := model.NewClientTypeSearch().Create(clientType)
|
if err != nil {
|
return ecode.ClientTypeExist
|
}
|
|
return ecode.OK
|
}
|
|
func (ClientTypeService) DeleteClientType(id int) int {
|
_, err := model.NewClientTypeSearch().SetId(id).First()
|
if err != nil {
|
return ecode.ClientTypeNotExist
|
}
|
|
err = model.NewClientTypeSearch().SetId(id).Delete()
|
if err != nil {
|
return ecode.ClientTypeNotExist
|
}
|
return ecode.OK
|
}
|
|
func (ClientTypeService) GetClientTypeList() ([]*model.ClientType, int) {
|
list, err := model.NewClientTypeSearch().FindAll()
|
if err != nil {
|
return nil, ecode.ClientTypeListErr
|
}
|
|
return list, ecode.OK
|
}
|
|
func (ClientTypeService) UpdateClientType(clientTypes []*request.UpdateClientType) int {
|
for _, v := range clientTypes {
|
// check clientType exist
|
_, err := model.NewClientTypeSearch().SetId(v.Id).First()
|
if err != nil {
|
return ecode.ClientTypeNotExist
|
}
|
|
err = model.NewClientTypeSearch().SetId(v.Id).Updates(map[string]interface{}{
|
"name": v.Name,
|
})
|
if err != nil {
|
return ecode.ClientTypeSetErr
|
}
|
}
|
|
return ecode.OK
|
}
|