package logic import ( "app.yhyue.com/moapp/jyResourcesCenter/entity" "app.yhyue.com/moapp/jyResourcesCenter/rpc/internal/config" "context" "encoding/json" "fmt" "github.com/google/uuid" "time" "app.yhyue.com/moapp/jyResourcesCenter/rpc/internal/svc" "app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenter" "github.com/zeromicro/go-zero/core/logx" ) type EntAccountRecoveryLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewEntAccountRecoveryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EntAccountRecoveryLogic { return &EntAccountRecoveryLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } // EntAccountRecovery 权益收回 func (l *EntAccountRecoveryLogic) EntAccountRecovery(in *resourcesCenter.EntOperateReq) (*resourcesCenter.Response, error) { eCode, msg := func() (int64, string) { if config.ConfigJson.ProductMap[in.ResourceType] == nil || in.CompanyId == 0 || in.OperateAccountId == "" { return entity.ErrorCode, "参数异常" } var ( err error orm = entity.Engine.NewSession() balance = &entity.Balance{} ) _, err = orm.Table(AccountResources). Where("companyId=? AND resourceType=? AND number>0 AND endTime>= ? AND accountId = ?", in.CompanyId, in.ResourceType, time.Now().Format("2006-01-02"), in.OperateAccountId).Get(balance) if err != nil || balance == nil || balance.Id == 0 { return entity.ErrorCode, "账户查询异常" } if err = orm.Begin(); err != nil { return entity.ErrorCode, "数据库操作异常" } updateNumb, err := orm.Table(AccountResources).Cols("accountId"). Where(" id=?", balance.Id). Update(&map[string]interface{}{ "accountId": fmt.Sprintf("wait_%s", uuid.New().String()), }) if err != nil || updateNumb <= 0 { _ = orm.Rollback() return entity.ErrorCode, "回收异常" } jsonData, _ := json.Marshal(map[string]interface{}{"describe": "权益回收", "source": balance.Id}) updateNumb, err = orm.Table(ConsumeRecord).Insert(entity.Detailed{ AccountId: balance.AccountId, CompanyId: balance.CompanyId, EmpowerId: balance.EmpowerId, ResourceType: balance.ResourceType, Number: balance.Number, CreateTime: time.Now().Local(), UserType: 7, Remarks: string(jsonData), UserId: balance.AccountId, Name: balance.Name, }) if err != nil || updateNumb <= 0 { _ = orm.Rollback() return entity.ErrorCode, "新增流水异常" } _ = orm.Commit() return entity.SuccessCode, "操作成功" }() return &resourcesCenter.Response{ Code: eCode, Message: msg, }, nil }