fix
wangpengfei
2023-08-09 d204c9732f7b406a1487d11c79f6c121eea75850
fix

check contact status when updating client, if there is an id then update, if id is zero then create
1个文件已修改
27 ■■■■■ 已修改文件
service/client.go 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/client.go
@@ -51,10 +51,37 @@
    }
    // update client
    if len(client.Contacts) == 0 {
    err := model.NewClientSearch(nil).SetId(client.Id).Update(client)
    if err != nil {
        return ecode.ClientUpdateErr
    }
    } else {
        tx := mysqlx.GetDB().Begin()
        err := model.NewClientSearch(tx).SetId(client.Id).Update(client)
        if err != nil {
            tx.Rollback()
            return ecode.ClientUpdateErr
        }
        for _, contact := range client.Contacts {
            contact.ClientId = client.Id
            if contact.Id == 0 {
                err := model.NewContactSearch(tx).Create(&contact)
                if err != nil {
                    tx.Rollback()
                    return ecode.ClientUpdateErr
                }
            } else {
                err = model.NewContactSearch(tx).SetId(contact.Id).Update(&contact)
                if err != nil {
                    tx.Rollback()
                    return ecode.ClientUpdateErr
                }
            }
        }
        tx.Commit()
    }
    return ecode.OK
}