12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package Wx
- import (
- "context"
- "wechat-api/ent/wx"
- "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"
- )
- type UpdateWxLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewUpdateWxLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateWxLogic {
- return &UpdateWxLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- func (l *UpdateWxLogic) UpdateWx(req *types.WxInfo) (resp *types.BaseMsgResp, err error) {
- isAdmin := l.ctx.Value("isAdmin").(bool)
- if isAdmin {
- err = l.svcCtx.DB.Wx.UpdateOneID(*req.Id).
- SetNotNilCallback(req.Callback).
- SetNotNilAgentID(req.AgentId).
- SetNotNilOrganizationID(req.OrganizationId).
- SetNotNilAPIBase(req.ApiBase).
- SetNotNilAPIKey(req.ApiKey).
- Exec(l.ctx)
- } else {
- organizationId := l.ctx.Value("organizationId").(uint64)
- err = l.svcCtx.DB.Wx.UpdateOneID(*req.Id).
- Where(wx.OrganizationID(organizationId)).
- SetNotNilAgentID(req.AgentId).
- Exec(l.ctx)
- }
- if err != nil {
- return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
- }
- return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
- }
|