| 
									
										
										
										
											2025-09-21 18:27:25 +08:00
										 |  |  | package admin_promotion | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"context" | 
					
						
							|  |  |  | 	"time" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-30 17:44:18 +08:00
										 |  |  | 	"tydata-server/app/main/api/internal/svc" | 
					
						
							|  |  |  | 	"tydata-server/app/main/api/internal/types" | 
					
						
							|  |  |  | 	"tydata-server/common/ctxdata" | 
					
						
							|  |  |  | 	"tydata-server/common/xerr" | 
					
						
							| 
									
										
										
										
											2025-09-21 18:27:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/pkg/errors" | 
					
						
							|  |  |  | 	"github.com/zeromicro/go-zero/core/logx" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type UpdatePromotionLinkLogic struct { | 
					
						
							|  |  |  | 	logx.Logger | 
					
						
							|  |  |  | 	ctx    context.Context | 
					
						
							|  |  |  | 	svcCtx *svc.ServiceContext | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func NewUpdatePromotionLinkLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePromotionLinkLogic { | 
					
						
							|  |  |  | 	return &UpdatePromotionLinkLogic{ | 
					
						
							|  |  |  | 		Logger: logx.WithContext(ctx), | 
					
						
							|  |  |  | 		ctx:    ctx, | 
					
						
							|  |  |  | 		svcCtx: svcCtx, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (l *UpdatePromotionLinkLogic) UpdatePromotionLink(req *types.UpdatePromotionLinkReq) error { | 
					
						
							|  |  |  | 	// 获取当前用户ID | 
					
						
							|  |  |  | 	adminUserId, getUidErr := ctxdata.GetUidFromCtx(l.ctx) | 
					
						
							|  |  |  | 	if getUidErr != nil { | 
					
						
							|  |  |  | 		return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "更新推广链接, 获取用户信息失败, %+v", getUidErr) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 获取链接信息 | 
					
						
							|  |  |  | 	link, err := l.svcCtx.AdminPromotionLinkModel.FindOne(l.ctx, req.Id) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return errors.Wrapf(err, "更新推广链接, 获取链接信息失败, %+v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 验证用户权限 | 
					
						
							|  |  |  | 	if link.AdminUserId != adminUserId { | 
					
						
							|  |  |  | 		return errors.Wrapf(xerr.NewErrMsg("无权限修改此链接"), "更新推广链接, 无权限修改此链接, %+v", link) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 更新链接信息 | 
					
						
							|  |  |  | 	link.Name = *req.Name | 
					
						
							|  |  |  | 	link.UpdateTime = time.Now() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_, err = l.svcCtx.AdminPromotionLinkModel.Update(l.ctx, nil, link) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新推广链接, 更新链接信息失败, %+v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } |