package service import ( "aps_crm/model" "aps_crm/model/request" "aps_crm/pkg/ecode" ) type BankAccountService struct{} func NewBankAccountService() BankAccountService { return BankAccountService{} } func (BankAccountService) AddBankAccount(bankAccount *model.BankAccount) int { err := model.NewBankAccountSearch().Create(bankAccount) if err != nil { return ecode.DBErr } return ecode.OK } func (BankAccountService) DeleteBankAccount(id int) int { err := model.NewBankAccountSearch().SetId(id).Delete() if err != nil { return ecode.DBErr } return ecode.OK } func (BankAccountService) GetBankAccountList() ([]*model.BankAccount, int64, int) { list, total, err := model.NewBankAccountSearch().Find() if err != nil { return nil, 0, ecode.DBErr } return list, total, ecode.OK } func (BankAccountService) UpdateBankAccounts(BankAccounts []*request.UpdateBankAccount) int { for _, v := range BankAccounts { // check BankAccount exist _, err := model.NewBankAccountSearch().SetId(v.Id).First() if err != nil { return ecode.DBErr } err = model.NewBankAccountSearch().SetId(v.Id).Updates(map[string]interface{}{}) if err != nil { return ecode.DBErr } } return ecode.OK } func (BankAccountService) UpdateBankAccount(bankAccount *model.BankAccount) int { err := model.NewBankAccountSearch().SetId(bankAccount.Id).Update(bankAccount) if err != nil { return ecode.DBErr } return ecode.OK }