package service
|
|
import (
|
"aps_crm/model"
|
"aps_crm/model/request"
|
"aps_crm/pkg/ecode"
|
)
|
|
type ClientStatusService struct{}
|
|
func (ClientStatusService) AddClientStatus(clientStatus *model.ClientStatus) int {
|
err := model.NewClientStatusSearch().Create(clientStatus)
|
if err != nil {
|
return ecode.ClientStatusExist
|
}
|
|
return ecode.OK
|
}
|
|
func (ClientStatusService) DeleteClientStatus(id int) int {
|
_, err := model.NewClientStatusSearch().SetId(id).First()
|
if err != nil {
|
return ecode.ClientStatusNotExist
|
}
|
|
err = model.NewClientStatusSearch().SetId(id).Delete()
|
if err != nil {
|
return ecode.ClientStatusNotExist
|
}
|
return ecode.OK
|
}
|
|
func (ClientStatusService) GetClientStatusList() ([]*model.ClientStatus, int) {
|
list, err := model.NewClientStatusSearch().FindAll()
|
if err != nil {
|
return nil, ecode.ClientStatusListErr
|
}
|
|
return list, ecode.OK
|
}
|
|
func (ClientStatusService) UpdateClientStatus(clientStatuses []request.UpdateClientStatus) int {
|
for _, v := range clientStatuses {
|
// check clientStatus exist
|
_, err := model.NewClientStatusSearch().SetId(v.Id).First()
|
if err != nil {
|
return ecode.ClientStatusNotExist
|
}
|
|
err = model.NewClientStatusSearch().SetId(v.Id).Updates(map[string]interface{}{
|
"name": v.Name,
|
})
|
if err != nil {
|
return ecode.ClientStatusSetErr
|
}
|
}
|
|
return ecode.OK
|
}
|