123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package user
- import (
- "context"
- "encoding/json"
- "fmt"
- "git.getensh.com/common/gopkgs/database"
- "git.getensh.com/common/gopkgs/logger"
- "go.uber.org/zap"
- "google.golang.org/grpc/status"
- "gorm.io/gorm"
- "property-company/errors"
- dbmodel "property-company/model"
- pb_v1 "property-company/pb/v1"
- )
- //
- func CompanyUserDel(ctx context.Context, req *pb_v1.CompanyUserDelRequest) (reply *pb_v1.CompanyUserDelReply, err error) {
- reply = &pb_v1.CompanyUserDelReply{}
- // 捕获各个task中的异常并返回给调用者
- defer func() {
- if r := recover(); r != nil {
- err = fmt.Errorf("%+v", r)
- e := &status.Status{}
- if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
- logger.Error("err",
- zap.String("system_err", err.Error()),
- zap.Stack("stacktrace"))
- }
- }
- }()
- if req.Id < 1 || req.Cid < 1 {
- return nil, errors.ParamsError
- }
- p := &dbmodel.TUser{}
- where := map[string]interface{}{
- "id": req.Id,
- "cid": req.Cid,
- }
- src := &dbmodel.TUser{}
- err = src.Find(database.DB(), where)
- if err != nil && err != gorm.ErrRecordNotFound {
- return nil, errors.DataBaseError
- }
- if src.ID == 0 {
- return nil, errors.ErrRecordNotFound
- }
- if src.Super {
- return nil, status.Error(10003, "初始用户不能删除")
- }
- reply.Origin = &pb_v1.CompanyUserUpdateRequest{
- Id: req.Id,
- UserName: src.User,
- Email: src.Email,
- Phone: src.Phone,
- Cid: src.Cid,
- }
- err = p.Delete(database.DB(), where)
- if err != nil {
- return nil, errors.DataBaseError
- }
- return reply, nil
- }
|