package service
|
|
import (
|
"aps_crm/model"
|
"aps_crm/pkg/ecode"
|
)
|
|
type QuotationService struct{}
|
|
func (QuotationService) AddQuotation(quotation *model.Quotation) int {
|
err := model.NewQuotationSearch().Create(quotation)
|
if err != nil {
|
return ecode.QuotationExist
|
}
|
|
return ecode.OK
|
}
|
|
func (QuotationService) DeleteQuotation(id int) int {
|
_, err := model.NewQuotationSearch().SetId(id).Find()
|
if err != nil {
|
return ecode.QuotationNotExist
|
}
|
|
err = model.NewQuotationSearch().SetId(id).Delete()
|
if err != nil {
|
return ecode.QuotationNotExist
|
}
|
return ecode.OK
|
}
|
|
func (QuotationService) UpdateQuotation(quotation *model.Quotation) int {
|
// check quotation exist
|
_, err := model.NewQuotationSearch().SetId(quotation.Id).Find()
|
if err != nil {
|
return ecode.QuotationNotExist
|
}
|
|
err = model.NewQuotationSearch().SetId(quotation.Id).Update(quotation)
|
if err != nil {
|
return ecode.QuotationSetErr
|
}
|
|
return ecode.OK
|
}
|
|
func (QuotationService) GetQuotationList(page, pageSize int, keyword string) ([]*model.Quotation, int64, int) {
|
// get contact list
|
contacts, total, err := model.NewQuotationSearch().SetKeyword(keyword).SetPage(page, pageSize).FindAll()
|
if err != nil {
|
return nil, 0, ecode.QuotationListErr
|
}
|
return contacts, total, ecode.OK
|
}
|