Files
customer-server/dao/account_dao.go
2026-06-10 15:51:41 +08:00

92 lines
2.9 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 dao
import (
"context"
"customer-server/consts/public"
"customer-server/model/dto"
"customer-server/model/entity"
"gitea.redpowerfuture.com/red-future/common/db/gfdb"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
)
var Account = new(account)
type account struct{}
func (d *account) Insert(ctx context.Context, req *dto.AddAccountReq) (id int64, err error) {
var e *entity.Account
if err = gconv.Struct(req, &e); err != nil {
return
}
result, err := gfdb.DB(ctx).Model(ctx, public.TableNameAccount).Insert(e)
if err != nil {
return
}
return result.LastInsertId()
}
func (d *account) Update(ctx context.Context, req *dto.UpdateAccountReq) (rows int64, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAccount).Data(&req).Where(entity.AccountCol.Id, req.Id).OmitEmpty().Update()
if err != nil {
return
}
return r.RowsAffected()
}
func (d *account) Delete(ctx context.Context, req *dto.DeleteAccountReq) (rows int64, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAccount).Where(entity.AccountCol.Id, req.Id).Delete()
if err != nil {
return
}
return r.RowsAffected()
}
func (d *account) Count(ctx context.Context, req *dto.ListAccountReq) (count int, err error) {
count, err = gfdb.DB(ctx).Model(ctx, public.TableNameAccount).OmitEmpty().Where(entity.AccountCol.AccountCode, req.AccountCode).Count()
return
}
// GetById 根据ID查询客服账号
func (d *account) GetById(ctx context.Context, req *dto.GetAccountReq, fields ...string) (res *entity.Account, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAccount).Where(entity.AccountCol.Id, req.Id).Fields(fields).One()
if err != nil {
return
}
err = r.Struct(&res)
return
}
// List 获取客服账号列表
func (d *account) List(ctx context.Context, req *dto.ListAccountReq, fields ...string) (res []*entity.Account, total int, err error) {
model := gfdb.DB(ctx).Model(ctx, public.TableNameAccount).Fields(fields).OmitEmpty()
if !g.IsEmpty(req.Keyword) {
model.WhereLike(entity.AccountCol.AccountName, "%"+req.Keyword+"%")
}
model.Where(entity.AccountCol.AccountCode, req.AccountCode)
model.Where(entity.AccountCol.Status, req.Status)
model.Where(entity.AccountCol.Platform, req.Platform)
model.OrderDesc(entity.AccountCol.CreatedAt)
if req.Page != nil {
model.Page(int(req.Page.PageNum), int(req.Page.PageSize))
}
r, total, err := model.AllAndCount(false)
if err != nil {
return
}
err = r.Structs(&res)
return
}
// GetByAccountCode 根据客服账号编码查询不带租户id
func (d *account) GetByAccountCode(ctx context.Context, req *dto.GetByAccountCodeReq, fields ...string) (res *entity.Account, err error) {
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAccount).NoTenantId(ctx).Where(entity.AccountCol.AccountCode, req.AccountCode).Fields(fields).One()
if err != nil {
return
}
err = r.Struct(&res)
return
}