初始
This commit is contained in:
140
internal/app/test/logic/testContactInfo/test_contact_info.go
Normal file
140
internal/app/test/logic/testContactInfo/test_contact_info.go
Normal file
@ -0,0 +1,140 @@
|
||||
// ==========================================================================
|
||||
// GFast自动生成logic操作代码。
|
||||
// 生成日期:2023-09-01 17:36:18
|
||||
// 生成路径: internal/app/test/logic/test_contact_info.go
|
||||
// 生成人:yqq
|
||||
// desc:业主方联系人关联
|
||||
// company:云南奇讯科技有限公司
|
||||
// ==========================================================================
|
||||
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/test"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
|
||||
ct "github.com/tiger1103/gfast/v3/internal/app/system/logic/context"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/test/dao"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/test/model"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/test/model/do"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/test/service"
|
||||
"github.com/tiger1103/gfast/v3/library/liberr"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterTestContactInfo(New())
|
||||
}
|
||||
|
||||
func New() *sTestContactInfo {
|
||||
return &sTestContactInfo{}
|
||||
}
|
||||
|
||||
type sTestContactInfo struct{}
|
||||
|
||||
func (s *sTestContactInfo) List(ctx context.Context, req *test.TestContactInfoSearchReq) (listRes *test.TestContactInfoSearchRes, err error) {
|
||||
listRes = new(test.TestContactInfoSearchRes)
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
m := dao.TestContactInfo.Ctx(ctx).WithAll()
|
||||
if req.Id != "" {
|
||||
m = m.Where(dao.TestContactInfo.Columns().Id+" = ?", req.Id)
|
||||
}
|
||||
//1、判断当前用户是否查看所有数据,如果不是获取到手机号来查询数据
|
||||
user := ct.New().GetLoginUser(ctx)
|
||||
if user.IsData == "2" {
|
||||
m = m.Where(dao.TestContactInfo.Columns().Creator+" = ?", user.Mobile)
|
||||
}
|
||||
if req.OwenerId != "" {
|
||||
m = m.Where(dao.TestContactInfo.Columns().OwenerId+" = ?", gconv.Uint(req.OwenerId))
|
||||
}
|
||||
if req.ContactName != "" {
|
||||
m = m.Where(dao.TestContactInfo.Columns().ContactName+" like ?", "%"+req.ContactName+"%")
|
||||
}
|
||||
if req.ContactPost != "" {
|
||||
m = m.Where(dao.TestContactInfo.Columns().ContactPost+" like ?", "%"+req.ContactPost+"%")
|
||||
}
|
||||
if req.ContactPhone != "" {
|
||||
m = m.Where(dao.TestContactInfo.Columns().ContactPhone+" = ?", req.ContactPhone)
|
||||
}
|
||||
listRes.Total, err = m.Count()
|
||||
liberr.ErrIsNil(ctx, err, "获取总行数失败")
|
||||
if req.PageNum == 0 {
|
||||
req.PageNum = 1
|
||||
}
|
||||
listRes.CurrentPage = req.PageNum
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = consts.PageSize
|
||||
}
|
||||
order := "id asc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
var res []*model.TestContactInfoInfoRes
|
||||
err = m.Fields(test.TestContactInfoSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||||
listRes.List = make([]*model.TestContactInfoListRes, len(res))
|
||||
for k, v := range res {
|
||||
listRes.List[k] = &model.TestContactInfoListRes{
|
||||
Id: v.Id,
|
||||
OwenerId: v.OwenerId,
|
||||
LinkedOwenerId: v.LinkedOwenerId,
|
||||
ContactName: v.ContactName,
|
||||
ContactPost: v.ContactPost,
|
||||
ContactPhone: v.ContactPhone,
|
||||
Creator: v.Creator,
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sTestContactInfo) GetById(ctx context.Context, id uint) (res *model.TestContactInfoInfoRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
err = dao.TestContactInfo.Ctx(ctx).WithAll().Where(dao.TestContactInfo.Columns().Id, id).Scan(&res)
|
||||
liberr.ErrIsNil(ctx, err, "获取信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sTestContactInfo) Add(ctx context.Context, req *test.TestContactInfoAddReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
if req.WxOrPc == "1" {
|
||||
req.Creator = ct.New().GetLoginUser(ctx).Mobile
|
||||
}
|
||||
_, err = dao.TestContactInfo.Ctx(ctx).Insert(do.TestContactInfo{
|
||||
OwenerId: req.OwenerId,
|
||||
ContactName: req.ContactName,
|
||||
ContactPost: req.ContactPost,
|
||||
ContactPhone: req.ContactPhone,
|
||||
Creator: req.Creator,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "添加失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sTestContactInfo) Edit(ctx context.Context, req *test.TestContactInfoEditReq) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
if req.WxOrPc == "1" {
|
||||
req.Creator = ct.New().GetLoginUser(ctx).Mobile
|
||||
}
|
||||
_, err = dao.TestContactInfo.Ctx(ctx).WherePri(req.Id).Update(do.TestContactInfo{
|
||||
OwenerId: req.OwenerId,
|
||||
ContactName: req.ContactName,
|
||||
ContactPost: req.ContactPost,
|
||||
ContactPhone: req.ContactPhone,
|
||||
Creator: req.Creator,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sTestContactInfo) Delete(ctx context.Context, ids []uint) (err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
_, err = dao.TestContactInfo.Ctx(ctx).Delete(dao.TestContactInfo.Columns().Id+" in (?)", ids)
|
||||
liberr.ErrIsNil(ctx, err, "删除失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user