fix: zero value failed to update

This commit is contained in:
zchengo
2022-12-23 20:21:36 +08:00
parent 8de3ccdebd
commit 7fecd6ba7f
5 changed files with 55 additions and 18 deletions
+3 -2
View File
@@ -35,6 +35,7 @@ func (c *CustomerService) Create(param *models.CustomerCreateParam) int {
// 更新客户
func (c *CustomerService) Update(param *models.CustomerUpdateParam) int {
customer := models.Customer{
Id: param.Id,
Name: param.Name,
Source: param.Source,
Phone: param.Phone,
@@ -47,8 +48,8 @@ func (c *CustomerService) Update(param *models.CustomerUpdateParam) int {
Status: param.Status,
Updated: time.Now().Unix(),
}
err := global.Db.Model(&models.Customer{}).Where("id = ?", param.Id).Updates(&customer).Error
if err != nil {
db := global.Db.Model(&customer).Select("*").Omit("id", "creator", "created")
if err := db.Updates(&customer).Error; err != nil {
return response.ErrCodeFailed
}
return response.ErrCodeSuccess