package service import ( "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) DeleteServiceFeeManage(id int) int { _, err := model.NewServiceFeeManageSearch(nil).SetId(id).Find() if err != nil { return ecode.ServiceFeeManageNotExist } err = model.NewServiceFeeManageSearch(nil).SetId(id).Delete() if err != nil { return ecode.ServiceFeeManageNotExist } 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) GetServiceFeeManageList(page, pageSize int, keyword string) ([]*model.ServiceFeeManage, int64, int) { // get contact list contacts, total, err := model.NewServiceFeeManageSearch(nil).SetKeyword(keyword).SetPage(page, pageSize).FindAll() if err != nil { return nil, 0, ecode.ServiceFeeManageListErr } return contacts, total, ecode.OK }