package service import ( "aps_crm/model" "aps_crm/model/request" "aps_crm/pkg/ecode" ) type SaleStageService struct{} func (SaleStageService) AddSaleStage(saleStage *model.SaleStage) int { err := model.NewSaleStageSearch().Create(saleStage) if err != nil { return ecode.SaleStageExist } return ecode.OK } func (SaleStageService) DeleteSaleStage(id int) int { _, err := model.NewSaleStageSearch().SetId(id).Find() if err != nil { return ecode.SaleStageNotExist } err = model.NewSaleStageSearch().SetId(id).Delete() if err != nil { return ecode.SaleStageNotExist } return ecode.OK } func (SaleStageService) GetSaleStageList() ([]*model.SaleStage, int) { list, err := model.NewSaleStageSearch().FindAll() if err != nil { return nil, ecode.SaleStageListErr } return list, ecode.OK } func (SaleStageService) UpdateSaleStage(saleStages []*request.UpdateSaleStage) int { for _, v := range saleStages { // check saleStage exist _, err := model.NewSaleStageSearch().SetId(v.Id).Find() if err != nil { return ecode.SaleStageNotExist } err = model.NewSaleStageSearch().SetId(v.Id).Updates(map[string]interface{}{ "name": v.Name, }) if err != nil { return ecode.SaleStageSetErr } } return ecode.OK } func (SaleStageService) GetSaleStageDetail(id int) (*model.SaleStage, int) { saleStage, err := model.NewSaleStageSearch().SetId(id).Find() if err != nil { return nil, ecode.SaleStageNotExist } return saleStage, ecode.OK }