|
@@ -6,11 +6,9 @@ import (
|
|
|
"github.com/suyuan32/simple-admin-core/rpc/types/core"
|
|
|
"github.com/zeromicro/go-zero/core/errorx"
|
|
|
|
|
|
+ "github.com/suyuan32/simple-admin-common/msg/errormsg"
|
|
|
"wechat-api/internal/svc"
|
|
|
"wechat-api/internal/types"
|
|
|
- "wechat-api/internal/utils/dberrorhandler"
|
|
|
-
|
|
|
- "github.com/suyuan32/simple-admin-common/msg/errormsg"
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
)
|
|
@@ -30,12 +28,18 @@ func NewCreateCreditBalanceLogic(ctx context.Context, svcCtx *svc.ServiceContext
|
|
|
}
|
|
|
|
|
|
func (l *CreateCreditBalanceLogic) CreateCreditBalance(req *types.CreditBalanceInfo) (*types.BaseMsgResp, error) {
|
|
|
+ userId := l.ctx.Value("userId").(string)
|
|
|
+
|
|
|
_, err := l.svcCtx.CoreRpc.GetDepartmentById(l.ctx, &core.IDReq{Id: *req.OrganizationId})
|
|
|
if err != nil {
|
|
|
return nil, errorx.NewAlreadyExistsError("租户不存在")
|
|
|
}
|
|
|
|
|
|
- _, err = l.svcCtx.DB.CreditBalance.Create().
|
|
|
+ tx, err := l.svcCtx.DB.Tx(context.Background())
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ _, err = tx.CreditBalance.Create().
|
|
|
SetNotNilUserID(req.UserId).
|
|
|
SetNotNilBalance(req.Balance).
|
|
|
SetNotNilStatus(tea.Int(1)).
|
|
@@ -43,8 +47,24 @@ func (l *CreateCreditBalanceLogic) CreateCreditBalance(req *types.CreditBalanceI
|
|
|
Save(l.ctx)
|
|
|
|
|
|
if err != nil {
|
|
|
- return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
|
|
|
+ l.Logger.Errorf("create credit_balance failed! err=%v\n", err)
|
|
|
+ _ = tx.Rollback()
|
|
|
+ }
|
|
|
+ _, err = tx.CreditUsage.Create().
|
|
|
+ SetNotNilUserID(req.UserId).
|
|
|
+ SetNotNilNumber(req.Balance).
|
|
|
+ SetNtype(2).
|
|
|
+ SetTable("").
|
|
|
+ SetNotNilOrganizationID(req.OrganizationId).
|
|
|
+ SetNid(0).
|
|
|
+ SetReason("后台管理员创建").
|
|
|
+ SetOperator(userId).
|
|
|
+ Save(l.ctx)
|
|
|
+ if err != nil {
|
|
|
+ l.Logger.Errorf("create credit_usage failed! err=%v\n", err)
|
|
|
+ _ = tx.Rollback()
|
|
|
}
|
|
|
+ _ = tx.Commit()
|
|
|
|
|
|
return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
|
|
|
}
|