package service
|
|
import (
|
"aps_crm/model"
|
"aps_crm/pkg/ecode"
|
)
|
|
type ContractService struct{}
|
|
func (ContractService) AddContract(contract *model.Contract) int {
|
err := model.NewContractSearch().Create(contract)
|
if err != nil {
|
return ecode.ContractExist
|
}
|
|
return ecode.OK
|
}
|
|
func (ContractService) UpdateContract(contract *model.Contract) int {
|
// check contract exist
|
_, err := model.NewContractSearch().SetId(contract.Id).Find()
|
if err != nil {
|
return ecode.ContractNotExist
|
}
|
|
err = model.NewContractSearch().SetId(contract.Id).Update(contract)
|
if err != nil {
|
return ecode.ContractSetErr
|
}
|
|
return ecode.OK
|
}
|
|
func (ContractService) GetContractList(page, pageSize int, data map[string]interface{}) ([]*model.Contract, int64, int) {
|
// get contact list
|
contacts, total, err := model.NewContractSearch().SetPage(page, pageSize).SetSearchMap(data).FindAll()
|
if err != nil {
|
return nil, 0, ecode.ContractListErr
|
}
|
return contacts, total, ecode.OK
|
}
|
|
func (ContractService) DeleteContract(id int) int {
|
// delete client
|
err := model.NewContractSearch().SetId(id).Delete()
|
if err != nil {
|
return ecode.ContractDeleteErr
|
}
|
return ecode.OK
|
}
|