| | |
| | | import ( |
| | | "aps_crm/model" |
| | | "aps_crm/pkg/ecode" |
| | | "aps_crm/pkg/mysqlx" |
| | | ) |
| | | |
| | | type ClientService struct{} |
| | | |
| | | func (ClientService) AddClient(client *model.Client) int { |
| | | err := model.NewClientSearch(nil).Create(client) |
| | | if err != nil { |
| | | return ecode.ClientExist |
| | | func (ClientService) AddClient(client *model.Client, sId int) int { |
| | | if sId == 0 { |
| | | err := model.NewClientSearch(nil).Create(client) |
| | | if err != nil { |
| | | return ecode.ClientExist |
| | | } |
| | | } else { |
| | | tx := mysqlx.GetDB().Begin() |
| | | err := model.NewClientSearch(tx).Create(client) |
| | | if err != nil { |
| | | tx.Rollback() |
| | | return ecode.ClientExist |
| | | } |
| | | |
| | | err = model.NewSalesLeadsSearch(tx).SetId(sId).Delete() |
| | | if err != nil { |
| | | tx.Rollback() |
| | | return ecode.ClientExist |
| | | } |
| | | tx.Commit() |
| | | } |
| | | |
| | | return ecode.OK |
| | | } |
| | | |