|
package service
|
|
import (
|
"aps_crm/model"
|
"aps_crm/model/request"
|
"aps_crm/pkg/ecode"
|
)
|
|
type AccountIdService struct{}
|
|
func (AccountIdService) AddAccountId(accountId *model.AccountId) int {
|
err := model.NewAccountIdSearch().Create(accountId)
|
if err != nil {
|
return ecode.AccountIdExist
|
}
|
|
return ecode.OK
|
}
|
|
func (AccountIdService) DeleteAccountId(id int) int {
|
_, err := model.NewAccountIdSearch().SetId(id).Find()
|
if err != nil {
|
return ecode.AccountIdNotExist
|
}
|
|
err = model.NewAccountIdSearch().SetId(id).Delete()
|
if err != nil {
|
return ecode.AccountIdNotExist
|
}
|
return ecode.OK
|
}
|
|
func (AccountIdService) GetAccountIdList() ([]*model.AccountId, int) {
|
list, err := model.NewAccountIdSearch().FindAll()
|
if err != nil {
|
return nil, ecode.AccountIdListErr
|
}
|
|
return list, ecode.OK
|
}
|
|
func (AccountIdService) UpdateAccountId(accountIds []*request.UpdateAccountId) int {
|
for _, v := range accountIds {
|
// check accountId exist
|
_, err := model.NewAccountIdSearch().SetId(v.Id).Find()
|
if err != nil {
|
return ecode.AccountIdNotExist
|
}
|
|
err = model.NewAccountIdSearch().SetId(v.Id).Updates(map[string]interface{}{
|
"name": v.Name,
|
})
|
if err != nil {
|
return ecode.AccountIdSetErr
|
}
|
}
|
|
return ecode.OK
|
}
|
|
func (AccountIdService) GetAccountIdDetail(id int) (*model.AccountId, int) {
|
accountId, err := model.NewAccountIdSearch().SetId(id).Find()
|
if err != nil {
|
return nil, ecode.AccountIdNotExist
|
}
|
|
return accountId, ecode.OK
|
}
|