1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- // Copyright 2019 githup.com. All rights reserved.
- // Use of this source code is governed by githup.com.
- package user
- import (
- "context"
- "github.com/jaryhe/gopkgs/database"
- "github.com/jaryhe/gopkgs/logger"
- "github.com/jinzhu/gorm"
- "go.uber.org/zap"
- "smart-enterprise-management/errors"
- dbmodel "smart-enterprise-management/model"
- pb_v1 "smart-enterprise-management/pb/v1"
- "time"
- )
- func PhoneUpdate(ctx context.Context, req *pb_v1.PhoneUpdateRequest)(reply *pb_v1.PhoneUpdateReply, err error) {
- p := &dbmodel.TCompany{}
- where := map[string]interface{}{
- "business_contact_phone":req.Phone,
- }
- // 状态判断
- err = p.Find(database.DB(), where, nil)
- if err != nil && err != gorm.ErrRecordNotFound{
- logger.Error("PhoneUpdate",
- zap.String("err", err.Error()))
- return nil, errors.DataBaseError
- }
- if p.Id > 0 {
- return nil, errors.PhoneExist
- }
- p = &dbmodel.TCompany{}
- where = map[string]interface{}{
- "id":req.Id,
- }
- // 状态判断
- err = p.Find(database.DB(), where, nil)
- if err != nil {
- logger.Error("PhoneUpdate",
- zap.String("err", err.Error()))
- return nil, errors.DataBaseError
- }
- if p.Id == 0 {
- return nil, errors.NoRecordError
- }
- reply = &pb_v1.PhoneUpdateReply{}
- values := map[string]interface{}{
- "business_contact_phone":req.Phone,
- "updated_at":time.Now(),
- }
- err = p.Update(database.DB(), where, values)
- if err != nil {
- return nil, errors.DataBaseError
- }
- return reply, nil
- }
|