123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package company
- import (
- "context"
- "encoding/json"
- "fmt"
- "git.getensh.com/common/gopkgs/database"
- "gorm.io/gorm"
- "property-company/consts"
- "property-company/errors"
- dbmodel "property-company/model"
- pb_v1 "property-company/pb/v1"
- "time"
- "git.getensh.com/common/gopkgs/logger"
- "go.uber.org/zap"
- "google.golang.org/grpc/status"
- )
- //
- func CompanyApprove(ctx context.Context, req *pb_v1.CompanyApproveRequest) (reply *pb_v1.CompanyApproveReply, err error) {
- reply = &pb_v1.CompanyApproveReply{}
- // 捕获各个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 < 0 {
- return nil, errors.ParamsError
- }
- now := time.Now()
- p := &dbmodel.TCompany{}
- where := map[string]interface{}{
- "id":req.Id,
- }
- values := map[string]interface{}{
- "updated_at":now,
- "approved_at":now,
- "approve_status":consts.ApproveStatusSuccess,
- "feedback":req.Feedback,
- }
- err = p.Find(database.DB(), where)
- if err != nil {
- if err != gorm.ErrRecordNotFound {
- return nil, errors.DataBaseError
- }
- }
- if p.ID == 0 {
- return nil, errors.ErrRecordNotFound
- }
- if p.ApproveStatus == consts.ApproveStatusSuccess || p.ApproveStatus == consts.ApproveStatusFail {
- return nil, errors.ApproveStatusError
- }
- if !req.Status {
- values["approve_status"] = consts.ApproveStatusFail
- // 审批未通过,重复标志设未null,可以再次添加同账号或同社会信用码
- values["uniq_flag"] = nil
- }
- db := database.DB().Begin()
- err = p.Update(db, where, values)
- if err != nil {
- db.Rollback()
- return nil, errors.DataBaseError
- }
- if !req.Status {
- user := dbmodel.TUser{}
- where := map[string]interface{}{
- "user":p.User,
- }
- err = user.Delete(db, where)
- if err != nil {
- db.Rollback()
- return nil, errors.DataBaseError
- }
- }
- db.Commit()
- return reply, nil
- }
|