package service import ( "aps_crm/constvar" "aps_crm/model" "aps_crm/pkg/ecode" ) type SalesLeadsService struct{} func (SalesLeadsService) AddSalesLeads(salesLeads *model.SalesLeads) int { err := model.NewSalesLeadsSearch(nil).Create(salesLeads) if err != nil { return ecode.SalesLeadsExist } return ecode.OK } func (SalesLeadsService) UpdateSalesLeads(salesLeads *model.SalesLeads) int { // update salesLeads err := model.NewSalesLeadsSearch(nil).SetId(salesLeads.Id).Update(salesLeads) if err != nil { return ecode.SalesLeadsUpdateErr } return ecode.OK } // CheckSalesLeadsExist check salesLeads exist func CheckSalesLeadsExist(id int) (int, *model.SalesLeads) { tmp, err := model.NewSalesLeadsSearch(nil).SetId(id).First() if err != nil { return ecode.SalesLeadsNotExist, nil } if tmp.Id == 0 { return ecode.SalesLeadsNotExist, nil } return ecode.OK, &tmp } func (SalesLeadsService) GetSalesLeadsList(page, pageSize int, data map[string]interface{}) ([]*model.SalesLeads, int64, int) { // get contact list contacts, total, err := model.NewSalesLeadsSearch(nil).SetPage(page, pageSize).SetSearchMap(data).FindAll() if err != nil { return nil, 0, ecode.SalesLeadsListErr } return contacts, total, ecode.OK } func (SalesLeadsService) Assign(ids []int, memberId int) int { // check salesLeads exist //errCode := CheckSalesLeadsExist(id) //if errCode != ecode.OK { // return errCode //} // update salesLeads err := model.NewSalesLeadsSearch(nil).SetIds(ids).UpdateMap(map[string]interface{}{ "member_id": memberId, }) if err != nil { return ecode.SalesLeadsUpdateErr } return ecode.OK } func (SalesLeadsService) DeleteSalesLeads(ids []int) int { // delete client err := model.NewSalesLeadsSearch(nil).SetIds(ids).Delete() if err != nil { return ecode.SalesLeadsDeleteErr } return ecode.OK } func (SalesLeadsService) PushSalesLeads(id int, step constvar.SalesStatus, txt string) int { // check salesLeads exist errCode, tmp := CheckSalesLeadsExist(id) if errCode != ecode.OK { return errCode } // check step if tmp.SalesStatus > step && step != constvar.SalesStatusFail { return ecode.SalesLeadsStatusErr } switch step { case constvar.SalesStatusFail: err := model.NewSalesLeadsSearch(nil).SetId(id).UpdateMap(map[string]interface{}{ "sales_status": constvar.SalesStatusFail, "reason": txt, }) if err != nil { return ecode.SalesLeadsUpdateErr } case constvar.SalesStatusIng: err := model.NewSalesLeadsSearch(nil).SetId(id).UpdateMap(map[string]interface{}{ "sales_status": constvar.SalesStatusIng, }) if err != nil { return ecode.SalesLeadsUpdateErr } return ecode.OK default: return ecode.SalesLeadsStatusErr } return ecode.OK }