fix
fix the bug that update the contact when updating the client
| | |
| | | |
| | | client.Id = params.Id |
| | | |
| | | errCode = clientService.UpdateClient(client) |
| | | errCode = clientService.UpdateClient(client, params.ContactId) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | |
| | | "contact": { |
| | | "$ref": "#/definitions/request.Contact" |
| | | }, |
| | | "contact_id": { |
| | | "description": "联系人ID", |
| | | "type": "integer" |
| | | }, |
| | | "country_id": { |
| | | "type": "integer" |
| | | }, |
| | |
| | | }, |
| | | "contact": { |
| | | "$ref": "#/definitions/request.Contact" |
| | | }, |
| | | "contact_id": { |
| | | "description": "联系人ID", |
| | | "type": "integer" |
| | | }, |
| | | "country_id": { |
| | | "type": "integer" |
| | |
| | | }, |
| | | "contact": { |
| | | "$ref": "#/definitions/request.Contact" |
| | | }, |
| | | "contact_id": { |
| | | "description": "联系人ID", |
| | | "type": "integer" |
| | | }, |
| | | "country_id": { |
| | | "type": "integer" |
| | |
| | | "contact": { |
| | | "$ref": "#/definitions/request.Contact" |
| | | }, |
| | | "contact_id": { |
| | | "description": "联系人ID", |
| | | "type": "integer" |
| | | }, |
| | | "country_id": { |
| | | "type": "integer" |
| | | }, |
| | |
| | | "contact": { |
| | | "$ref": "#/definitions/request.Contact" |
| | | }, |
| | | "contact_id": { |
| | | "description": "联系人ID", |
| | | "type": "integer" |
| | | }, |
| | | "country_id": { |
| | | "type": "integer" |
| | | }, |
| | |
| | | }, |
| | | "contact": { |
| | | "$ref": "#/definitions/request.Contact" |
| | | }, |
| | | "contact_id": { |
| | | "description": "联系人ID", |
| | | "type": "integer" |
| | | }, |
| | | "country_id": { |
| | | "type": "integer" |
| | |
| | | }, |
| | | "contact": { |
| | | "$ref": "#/definitions/request.Contact" |
| | | }, |
| | | "contact_id": { |
| | | "description": "联系人ID", |
| | | "type": "integer" |
| | | }, |
| | | "country_id": { |
| | | "type": "integer" |
| | |
| | | "contact": { |
| | | "$ref": "#/definitions/request.Contact" |
| | | }, |
| | | "contact_id": { |
| | | "description": "联系人ID", |
| | | "type": "integer" |
| | | }, |
| | | "country_id": { |
| | | "type": "integer" |
| | | }, |
| | |
| | | type: integer |
| | | contact: |
| | | $ref: '#/definitions/request.Contact' |
| | | contact_id: |
| | | description: 联系人ID |
| | | type: integer |
| | | country_id: |
| | | type: integer |
| | | detail_address: |
| | |
| | | type: integer |
| | | contact: |
| | | $ref: '#/definitions/request.Contact' |
| | | contact_id: |
| | | description: 联系人ID |
| | | type: integer |
| | | country_id: |
| | | type: integer |
| | | detail_address: |
| | |
| | | type: integer |
| | | contact: |
| | | $ref: '#/definitions/request.Contact' |
| | | contact_id: |
| | | description: 联系人ID |
| | | type: integer |
| | | country_id: |
| | | type: integer |
| | | detail_address: |
| | |
| | | type: integer |
| | | contact: |
| | | $ref: '#/definitions/request.Contact' |
| | | contact_id: |
| | | description: 联系人ID |
| | | type: integer |
| | | country_id: |
| | | type: integer |
| | | detail_address: |
| | |
| | | LatestServiceTime string `json:"latest_service_time"` // 最晚服务时间 |
| | | Contact Contact `json:"contact"` |
| | | SalesLeadsId int `json:"sales_leads_id"` // 销售线索ID |
| | | ContactId int `json:"contact_id"` // 联系人ID |
| | | Address |
| | | Business |
| | | } |
| | |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (ClientService) UpdateClient(client *model.Client) int { |
| | | func (ClientService) UpdateClient(client *model.Client, conId int) int { |
| | | // check client exist |
| | | errCode := CheckClientExist(client.Id) |
| | | if errCode != ecode.OK { |
| | |
| | | |
| | | for _, contact := range client.Contacts { |
| | | contact.ClientId = client.Id |
| | | if contact.Id == 0 { |
| | | err := model.NewContactSearch(tx).Create(&contact) |
| | | |
| | | // check isFirst |
| | | errCode = setFirstContact(tx, &contact) |
| | | if errCode != ecode.OK { |
| | | return errCode |
| | | } |
| | | |
| | | if conId == 0 { |
| | | err = model.NewContactSearch(tx).Create(&contact) |
| | | if err != nil { |
| | | tx.Rollback() |
| | | return ecode.ClientUpdateErr |
| | | } |
| | | } else { |
| | | contact.Id = conId |
| | | err = model.NewContactSearch(tx).SetId(contact.Id).Update(&contact) |
| | | if err != nil { |
| | | tx.Rollback() |