create_credit_balance_logic.go 1.1 KB

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