| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package product
- import (
- "context"
- "time"
- "perms-system-server/internal/consts"
- authHelper "perms-system-server/internal/logic/auth"
- "perms-system-server/internal/response"
- "perms-system-server/internal/svc"
- "perms-system-server/internal/types"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type UpdateProductLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
- func NewUpdateProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateProductLogic {
- return &UpdateProductLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx,
- }
- }
- func (l *UpdateProductLogic) UpdateProduct(req *types.UpdateProductReq) error {
- if err := authHelper.RequireSuperAdmin(l.ctx); err != nil {
- return err
- }
- product, err := l.svcCtx.SysProductModel.FindOne(l.ctx, req.Id)
- if err != nil {
- return response.ErrNotFound("产品不存在")
- }
- product.Name = req.Name
- product.Remark = req.Remark
- if req.Status == consts.StatusEnabled || req.Status == consts.StatusDisabled {
- product.Status = req.Status
- }
- product.UpdateTime = time.Now().Unix()
- if err := l.svcCtx.SysProductModel.Update(l.ctx, product); err != nil {
- return err
- }
- l.svcCtx.UserDetailsLoader.CleanByProduct(l.ctx, product.Code)
- return nil
- }
|