fix
wangpengfei
2023-08-15 c60d971f9bf50e364cc50f0699249217ef9bbb6b
fix

fix the bug that update the contact when updating the client
6个文件已修改
61 ■■■■■ 已修改文件
api/v1/client.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/client.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/client.go 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/client.go
@@ -166,7 +166,7 @@
    client.Id = params.Id
    errCode = clientService.UpdateClient(client)
    errCode = clientService.UpdateClient(client, params.ContactId)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
docs/docs.go
@@ -13025,6 +13025,10 @@
                "contact": {
                    "$ref": "#/definitions/request.Contact"
                },
                "contact_id": {
                    "description": "联系人ID",
                    "type": "integer"
                },
                "country_id": {
                    "type": "integer"
                },
@@ -14176,6 +14180,10 @@
                },
                "contact": {
                    "$ref": "#/definitions/request.Contact"
                },
                "contact_id": {
                    "description": "联系人ID",
                    "type": "integer"
                },
                "country_id": {
                    "type": "integer"
@@ -15701,6 +15709,10 @@
                },
                "contact": {
                    "$ref": "#/definitions/request.Contact"
                },
                "contact_id": {
                    "description": "联系人ID",
                    "type": "integer"
                },
                "country_id": {
                    "type": "integer"
@@ -17414,6 +17426,10 @@
                "contact": {
                    "$ref": "#/definitions/request.Contact"
                },
                "contact_id": {
                    "description": "联系人ID",
                    "type": "integer"
                },
                "country_id": {
                    "type": "integer"
                },
docs/swagger.json
@@ -13013,6 +13013,10 @@
                "contact": {
                    "$ref": "#/definitions/request.Contact"
                },
                "contact_id": {
                    "description": "联系人ID",
                    "type": "integer"
                },
                "country_id": {
                    "type": "integer"
                },
@@ -14164,6 +14168,10 @@
                },
                "contact": {
                    "$ref": "#/definitions/request.Contact"
                },
                "contact_id": {
                    "description": "联系人ID",
                    "type": "integer"
                },
                "country_id": {
                    "type": "integer"
@@ -15689,6 +15697,10 @@
                },
                "contact": {
                    "$ref": "#/definitions/request.Contact"
                },
                "contact_id": {
                    "description": "联系人ID",
                    "type": "integer"
                },
                "country_id": {
                    "type": "integer"
@@ -17402,6 +17414,10 @@
                "contact": {
                    "$ref": "#/definitions/request.Contact"
                },
                "contact_id": {
                    "description": "联系人ID",
                    "type": "integer"
                },
                "country_id": {
                    "type": "integer"
                },
docs/swagger.yaml
@@ -2058,6 +2058,9 @@
        type: integer
      contact:
        $ref: '#/definitions/request.Contact'
      contact_id:
        description: 联系人ID
        type: integer
      country_id:
        type: integer
      detail_address:
@@ -2828,6 +2831,9 @@
        type: integer
      contact:
        $ref: '#/definitions/request.Contact'
      contact_id:
        description: 联系人ID
        type: integer
      country_id:
        type: integer
      detail_address:
@@ -3895,6 +3901,9 @@
        type: integer
      contact:
        $ref: '#/definitions/request.Contact'
      contact_id:
        description: 联系人ID
        type: integer
      country_id:
        type: integer
      detail_address:
@@ -5042,6 +5051,9 @@
        type: integer
      contact:
        $ref: '#/definitions/request.Contact'
      contact_id:
        description: 联系人ID
        type: integer
      country_id:
        type: integer
      detail_address:
model/request/client.go
@@ -19,6 +19,7 @@
    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
}
service/client.go
@@ -44,7 +44,7 @@
    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 {
@@ -67,13 +67,21 @@
        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()