Files
customer-server/service/account_service.go

93 lines
2.5 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Package service - 客服账号服务
// 功能:客服账号的增删改查、状态切换
package service
import (
"context"
"customer-server/dao"
"customer-server/model/dto"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/util/gconv"
)
var (
AccountService = new(accountService)
)
type accountService struct{}
// Add 添加客服账号
// 参数: ctx - 上下文req - 添加客服账号请求
// 返回: res - 添加成功后的客服账号IDerr - 错误信息
// 功能: 创建新的客服账号记录
func (s *accountService) Add(ctx context.Context, req *dto.AddAccountReq) (res *dto.AddAccountRes, err error) {
// 检查账号名称是否已存在
count, err := dao.Account.Count(ctx, &dto.ListAccountReq{
AccountCode: req.AccountCode,
})
if err != nil {
return
}
if count > 0 {
err = gerror.Newf("客服账号名称已存在:%s", req.AccountName)
return
}
// 插入数据库
id, err := dao.Account.Insert(ctx, req)
if err != nil {
return
}
res = &dto.AddAccountRes{Id: id}
return
}
// Update 更新客服账号
// 参数: ctx - 上下文req - 更新客服账号请求
// 返回: err - 错误信息
// 功能: 更新客服账号信息
func (s *accountService) Update(ctx context.Context, req *dto.UpdateAccountReq) (err error) {
_, err = dao.Account.Update(ctx, req)
return
}
// Delete 删除客服账号
// 参数: ctx - 上下文req - 删除客服账号请求
// 返回: err - 错误信息
// 功能: 逻辑删除客服账号记录
func (s *accountService) Delete(ctx context.Context, req *dto.DeleteAccountReq) (err error) {
_, err = dao.Account.Delete(ctx, req)
return
}
// Get 获取单个客服账号
// 参数: ctx - 上下文req - 获取客服账号请求
// 返回: res - 客服账号信息err - 错误信息
// 功能: 根据ID获取单个客服账号详情
func (s *accountService) Get(ctx context.Context, req *dto.GetAccountReq) (res *dto.AccountVO, err error) {
r, err := dao.Account.GetById(ctx, req)
if err != nil {
return
}
err = gconv.Struct(r, &res)
return
}
// List 获取客服账号列表
// 参数: ctx - 上下文req - 列表查询请求
// 返回: res - 客服账号列表及分页信息err - 错误信息
// 功能: 分页查询客服账号记录
func (s *accountService) List(ctx context.Context, req *dto.ListAccountReq) (res *dto.ListAccountRes, err error) {
list, total, err := dao.Account.List(ctx, req)
if err != nil {
return
}
res = &dto.ListAccountRes{
Total: total,
}
err = gconv.Struct(list, &res.List)
return
}