update_credit_balance_logic.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package credit_balance
  2. import (
  3. "context"
  4. "wechat-api/internal/svc"
  5. "wechat-api/internal/types"
  6. "wechat-api/internal/utils/dberrorhandler"
  7. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type UpdateCreditBalanceLogic struct {
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. logx.Logger
  14. }
  15. func NewUpdateCreditBalanceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateCreditBalanceLogic {
  16. return &UpdateCreditBalanceLogic{
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. Logger: logx.WithContext(ctx),
  20. }
  21. }
  22. func (l *UpdateCreditBalanceLogic) UpdateCreditBalance(req *types.CreditBalanceInfo) (*types.BaseMsgResp, error) {
  23. err := l.svcCtx.DB.CreditBalance.UpdateOneID(*req.Id).
  24. SetNotNilUserID(req.UserId).
  25. SetNotNilBalance(req.Balance).
  26. SetNotNilStatus(req.Status).
  27. SetNotNilOrganizationID(req.OrganizationId).
  28. Exec(l.ctx)
  29. if err != nil {
  30. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  31. }
  32. return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
  33. }