package service
|
|
import (
|
"aps_crm/constvar"
|
"aps_crm/model"
|
"aps_crm/pkg/ecode"
|
"aps_crm/pkg/mysqlx"
|
)
|
|
type FeeManageService struct{}
|
|
func (FeeManageService) AddServiceFeeManage(serviceFeeManage *model.ServiceFeeManage) int {
|
|
tx := mysqlx.GetDB().Begin()
|
|
err := model.NewClientSearch(tx).Create(serviceFeeManage.Client)
|
if err != nil {
|
tx.Rollback()
|
return ecode.ClientExist
|
}
|
|
serviceFeeManage.ClientId = serviceFeeManage.Client.Id
|
err = model.NewServiceFeeManageSearch(tx).Create(serviceFeeManage)
|
if err != nil {
|
tx.Rollback()
|
return ecode.ServiceFeeManageExist
|
}
|
|
tx.Commit()
|
|
return ecode.OK
|
}
|
|
func (FeeManageService) UpdateServiceFeeManage(serviceFeeManage *model.ServiceFeeManage) int {
|
// check serviceFeeManage exist
|
_, err := model.NewServiceFeeManageSearch(nil).SetId(serviceFeeManage.Id).Find()
|
if err != nil {
|
return ecode.ServiceFeeManageNotExist
|
}
|
|
tx := mysqlx.GetDB().Begin()
|
|
err = model.NewServiceFeeManageSearch(tx).SetId(serviceFeeManage.Id).Update(serviceFeeManage)
|
if err != nil {
|
tx.Rollback()
|
return ecode.ServiceFeeManageSetErr
|
}
|
|
// update client
|
err = model.NewClientSearch(tx).SetId(serviceFeeManage.ClientId).Update(serviceFeeManage.Client)
|
if err != nil {
|
tx.Rollback()
|
return ecode.ClientUpdateErr
|
}
|
|
tx.Commit()
|
|
return ecode.OK
|
}
|
|
func (FeeManageService) DeleteServiceFeeManage(ids []int) int {
|
// delete client
|
err := model.NewServiceFeeManageSearch(nil).SetIds(ids).Delete()
|
if err != nil {
|
return ecode.ServiceFeeManageDeleteErr
|
}
|
return ecode.OK
|
}
|
|
func (FeeManageService) GetServiceFeeManageList(page, pageSize int, queryClass constvar.ServiceFeeQueryClass, keywordType constvar.ServiceFeeKeywordType, keyword string) ([]*model.ServiceFeeManage, int64, int) {
|
// get contact list
|
contacts, total, err := model.NewServiceFeeManageSearch(nil).
|
SetQueryClass(queryClass).
|
SetKeywordType(keywordType).
|
SetKeyword(keyword).
|
SetPage(page, pageSize).FindAll()
|
if err != nil {
|
return nil, 0, ecode.ServiceFeeManageListErr
|
}
|
return contacts, total, ecode.OK
|
}
|